001: /*
002: * Jacareto Copyright (c) 2002-2005
003: * Applied Computer Science Research Group, Darmstadt University of
004: * Technology, Institute of Mathematics & Computer Science,
005: * Ludwigsburg University of Education, and Computer Based
006: * Learning Research Group, Aachen University. All rights reserved.
007: *
008: * Jacareto is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation; either
011: * version 2 of the License, or (at your option) any later version.
012: *
013: * Jacareto is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public
019: * License along with Jacareto; if not, write to the Free
020: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021: *
022: */
023:
024: package jacareto.cleverphl.gui;
025:
026: import jacareto.cleverphl.CleverPHL;
027: import jacareto.system.Language;
028:
029: import java.awt.BorderLayout;
030: import java.awt.GridBagConstraints;
031: import java.awt.GridBagLayout;
032: import java.awt.Insets;
033: import java.awt.Point;
034: import java.awt.event.ActionEvent;
035: import java.awt.event.ActionListener;
036:
037: import javax.swing.JButton;
038: import javax.swing.JCheckBox;
039: import javax.swing.JDialog;
040: import javax.swing.JLabel;
041: import javax.swing.JPanel;
042: import javax.swing.JTextField;
043: import javax.swing.border.EmptyBorder;
044:
045: /**
046: * Dialog for setting the user defined name of a component.
047: *
048: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
049: * @version 1.01
050: */
051: public class SetUserDefinedNameDialog extends JDialog {
052: /** The CleverPHL instance. */
053: private CleverPHL cleverPHL;
054:
055: /** The text field for the Jacareto name. */
056: private JTextField jacaretoNameField;
057:
058: /** The text field for the user defined name. */
059: private JTextField userDefinedNameField;
060:
061: /** The user defined name. */
062: private String newUserDefinedName;
063:
064: /** Whether or not a recordable should be added to the record. */
065: private boolean isRecordableAdding;
066:
067: /** The checkbox which add a recordable to the record. */
068: private JCheckBox addRecordableCheckBox;
069:
070: /**
071: * Creates a dialog.
072: *
073: * @param cleverPHL the CleverPHL instance
074: * @param jacaretoName DOCUMENT ME!
075: * @param userDefinedName DOCUMENT ME!
076: */
077: public SetUserDefinedNameDialog(CleverPHL cleverPHL,
078: String jacaretoName, String userDefinedName) {
079: super (cleverPHL.getComponentsFrame(), true);
080: this .cleverPHL = cleverPHL;
081: setName(cleverPHL.getCustomization().getString(
082: "Components.JacaretoComponent", "JACARETO_COMPONENT"));
083:
084: Language language = cleverPHL.getLanguage();
085:
086: setTitle(language
087: .getString("CleverPHL.SetUserDefinedNameDialog.Title"));
088:
089: // The panel for the text fields.
090: JPanel textFieldPanel = new JPanel(new GridBagLayout());
091: GridBagConstraints c = new GridBagConstraints();
092: c.gridx = 0;
093: c.gridy = 0;
094: c.weightx = 40;
095: c.anchor = GridBagConstraints.WEST;
096: c.insets = new Insets(5, 5, 5, 5);
097:
098: JLabel jacaretoNameLabel = new JLabel(
099: language
100: .getString("CleverPHL.SetUserDefinedNameDialog.JacaretoName")
101: + ":");
102: textFieldPanel.add(jacaretoNameLabel, c);
103:
104: c.weightx = 60;
105: c.weighty = 40;
106: c.gridx = 1;
107: jacaretoNameField = new JTextField(30);
108:
109: if (jacaretoName != null) {
110: jacaretoNameField.setText(jacaretoName);
111: }
112:
113: jacaretoNameField.setEditable(false);
114: textFieldPanel.add(jacaretoNameField, c);
115:
116: c.gridx = 0;
117: c.gridy = 1;
118:
119: JLabel userDefinedNameLabel = new JLabel(
120: language
121: .getString("CleverPHL.SetUserDefinedNameDialog.UserDefinedName")
122: + ":");
123: textFieldPanel.add(userDefinedNameLabel, c);
124:
125: c.weightx = 60;
126: c.gridx = 1;
127: userDefinedNameField = new JTextField(30);
128:
129: if (userDefinedName != null) {
130: userDefinedNameField.setText(userDefinedName);
131: }
132:
133: textFieldPanel.add(userDefinedNameField, c);
134:
135: c.weighty = 20;
136: c.gridwidth = 2;
137: c.gridx = 0;
138: c.gridy = 2;
139: addRecordableCheckBox = new JCheckBox(
140: language
141: .getString("CleverPHL.SetUserDefinedNameDialog.AddRecordElement"));
142: addRecordableCheckBox.setSelected(true);
143: textFieldPanel.add(addRecordableCheckBox, c);
144:
145: // The panel with the two buttons
146: JPanel buttonPanel = new JPanel();
147: JButton okButton = new JButton(language.getString("General.Ok"));
148: okButton.addActionListener(new ActionListener() {
149: public void actionPerformed(ActionEvent e) {
150: newUserDefinedName = userDefinedNameField.getText();
151: isRecordableAdding = addRecordableCheckBox.isSelected();
152: dispose();
153: }
154: });
155:
156: JButton cancelButton = new JButton(language
157: .getString("General.Cancel"));
158: cancelButton.addActionListener(new ActionListener() {
159: public void actionPerformed(ActionEvent e) {
160: newUserDefinedName = null;
161: dispose();
162: }
163: });
164: buttonPanel.add(okButton);
165: buttonPanel.add(cancelButton);
166: buttonPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
167:
168: // Add all to the content pane
169: getContentPane().setLayout(new BorderLayout());
170: getContentPane().add(textFieldPanel, BorderLayout.NORTH);
171: getContentPane().add(buttonPanel, BorderLayout.CENTER);
172:
173: pack();
174: setResizable(false);
175:
176: Point ownerLoc = cleverPHL.getComponentsFrame().getLocation();
177: setLocation(((int) ownerLoc.getX()) + 30, ((int) ownerLoc
178: .getY()) + 30);
179:
180: newUserDefinedName = null;
181: isRecordableAdding = false;
182: setVisible(true);
183: }
184:
185: /**
186: * Returns the user defined name if the user has pressed ok, otherwise <code>null</code>.
187: *
188: * @return DOCUMENT ME!
189: */
190: public String getUserDefinedName() {
191: return newUserDefinedName;
192: }
193:
194: /**
195: * Returns whether or not a record element should be added to the record.
196: *
197: * @return DOCUMENT ME!
198: */
199: public boolean isRecordableAdding() {
200: return isRecordableAdding;
201: }
202: }
|