001: /*
002: * ====================================================================
003: * The JRefactory License, Version 1.0
004: *
005: * Copyright (c) 2001 JRefactory. All rights reserved.
006: *
007: * Redistribution and use in source and binary forms, with or without
008: * modification, are permitted provided that the following conditions
009: * are met:
010: *
011: * 1. Redistributions of source code must retain the above copyright
012: * notice, this list of conditions and the following disclaimer.
013: *
014: * 2. Redistributions in binary form must reproduce the above copyright
015: * notice, this list of conditions and the following disclaimer in
016: * the documentation and/or other materials provided with the
017: * distribution.
018: *
019: * 3. The end-user documentation included with the redistribution,
020: * if any, must include the following acknowledgment:
021: * "This product includes software developed by the
022: * JRefactory (http://www.sourceforge.org/projects/jrefactory)."
023: * Alternately, this acknowledgment may appear in the software itself,
024: * if and wherever such third-party acknowledgments normally appear.
025: *
026: * 4. The names "JRefactory" must not be used to endorse or promote
027: * products derived from this software without prior written
028: * permission. For written permission, please contact seguin@acm.org.
029: *
030: * 5. Products derived from this software may not be called "JRefactory",
031: * nor may "JRefactory" appear in their name, without prior written
032: * permission of Chris Seguin.
033: *
034: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
035: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
036: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
037: * DISCLAIMED. IN NO EVENT SHALL THE CHRIS SEGUIN OR
038: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
039: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
040: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
041: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
042: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
043: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
044: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
045: * SUCH DAMAGE.
046: * ====================================================================
047: *
048: * This software consists of voluntary contributions made by many
049: * individuals on behalf of JRefactory. For more information on
050: * JRefactory, please see
051: * <http://www.sourceforge.org/projects/jrefactory>.
052: */
053: package org.acm.seguin.uml.refactor;
054:
055: import java.awt.GridBagConstraints;
056: import java.awt.GridBagLayout;
057: import javax.swing.JButton;
058: import javax.swing.JLabel;
059: import javax.swing.JTextField;
060: import org.acm.seguin.uml.UMLPackage;
061:
062: /**
063: * Prompts the user for a class name. The class name can then be used to rename
064: * a class, add an abstract parent, or add a child.
065: *
066: *@author Chris Seguin
067: *@created September 12, 2001
068: */
069: public abstract class ClassNameDialog extends RefactoringDialog {
070: // Instance Variables
071: private JTextField newName;
072:
073: /**
074: * Constructor for ClassNameDialog
075: *
076: *@param init The package where this operation is occuring
077: *@param startRow Description of Parameter
078: */
079: public ClassNameDialog(UMLPackage init, int startRow) {
080: super (init);
081:
082: // Set the window size and layout
083: setTitle(getWindowTitle());
084:
085: GridBagLayout gridbag = new GridBagLayout();
086: GridBagConstraints gbc = new GridBagConstraints();
087: getContentPane().setLayout(gridbag);
088: setSize(310, 120);
089:
090: // Add components
091: JLabel newNameLabel = new JLabel(getLabelText());
092: gbc.gridx = 1;
093: gbc.gridy = startRow;
094: gbc.gridwidth = 1;
095: gbc.gridheight = 1;
096: gridbag.setConstraints(newNameLabel, gbc);
097: getContentPane().add(newNameLabel);
098:
099: newName = new JTextField();
100: newName.setColumns(25);
101: gbc.gridx = 2;
102: gbc.gridy = startRow;
103: gbc.gridwidth = 2;
104: gbc.gridheight = 1;
105: gbc.fill = GridBagConstraints.HORIZONTAL;
106: gridbag.setConstraints(newName, gbc);
107: getContentPane().add(newName);
108:
109: JButton okButton = new JButton("OK");
110: gbc.gridx = 2;
111: gbc.gridy = startRow + 1;
112: gbc.gridwidth = 1;
113: gbc.gridheight = 1;
114: gbc.fill = GridBagConstraints.NONE;
115: gridbag.setConstraints(okButton, gbc);
116: okButton.addActionListener(this );
117: getContentPane().add(okButton);
118:
119: JButton cancelButton = new JButton("Cancel");
120: gbc.gridx = 3;
121: gbc.gridy = startRow + 1;
122: gbc.gridwidth = 1;
123: gbc.gridheight = 1;
124: gridbag.setConstraints(cancelButton, gbc);
125: cancelButton.addActionListener(this );
126: getContentPane().add(cancelButton);
127:
128: pack();
129:
130: org.acm.seguin.awt.CenterDialog.center(this , init);
131: }
132:
133: /**
134: * Gets the label for the text
135: *
136: *@return the text for the label
137: */
138: public abstract String getLabelText();
139:
140: /**
141: * Returns the window title
142: *
143: *@return the title
144: */
145: public abstract String getWindowTitle();
146:
147: /**
148: * Sets the className attribute of the ClassNameDialog object
149: *
150: *@param name The new className value
151: */
152: protected void setClassName(String name) {
153: newName.setText(name);
154: newName.setSelectionStart(0);
155: newName.setSelectionStart(name.length());
156: }
157:
158: /**
159: * Gets the ClassName attribute of the ClassNameDialog object Gets the
160: * ClassName attribute of the ClassNameDialog object
161: *
162: *@return The ClassName value
163: */
164: protected String getClassName() {
165: return newName.getText();
166: }
167: }
|