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.editor;
025:
026: import jacareto.starter.Starter;
027: import jacareto.struct.StructureElement;
028: import jacareto.system.Environment;
029: import jacareto.system.Language;
030: import jacareto.toolkit.event.TextValueListener;
031: import jacareto.toolkit.swing.LongTextField;
032:
033: import java.awt.Component;
034: import java.awt.GridBagConstraints;
035: import java.awt.GridBagLayout;
036: import java.awt.Insets;
037: import java.awt.event.ActionEvent;
038: import java.awt.event.ActionListener;
039:
040: import javax.swing.JCheckBox;
041: import javax.swing.JLabel;
042: import javax.swing.JPanel;
043: import javax.swing.JTextField;
044: import javax.swing.event.DocumentEvent;
045:
046: /**
047: * <p>
048: * An editor for starters. Because the class <code>Starter</code> is abstract, this class should be
049: * extended for the specific structure elements which inherit from <code>Starter</code>.
050: * </p>
051: *
052: * <p>
053: * If a subclass overwrites the method {@link #setElement(StructureElement)}, it should call the
054: * method of its superclass first.
055: * </p>
056: *
057: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
058: * @version 1.03
059: */
060: public class StarterEditor extends Editor {
061: /** The editor's component. */
062: protected JPanel editorPanel;
063:
064: /** The grid bag constraints. */
065: protected GridBagConstraints c;
066:
067: /** The structure element to edit. */
068: private StructureElement element;
069:
070: /** The text field for the name. */
071: private JTextField nameField;
072:
073: /** The text field for the classname. */
074: private JTextField classnameField;
075:
076: /** The text field for the classpath extension. */
077: private JTextField classpathExtField;
078:
079: /** The text field for the initializer classname. */
080: private JTextField initClassnameField;
081:
082: /** The text field for the start up duration. */
083: private LongTextField durationField;
084:
085: /** The checkbox for the detect duration attribute. */
086: private JCheckBox detectDurationCheckbox;
087:
088: /**
089: * Create a new starter editor.
090: *
091: * @param env the environment
092: */
093: public StarterEditor(Environment env) {
094: super (env);
095:
096: Language language = getLanguage();
097:
098: editorPanel = new JPanel();
099: editorPanel.setLayout(new GridBagLayout());
100:
101: // The name field label
102: c = new GridBagConstraints();
103: c.gridx = 0;
104: c.gridy = 0;
105: c.weightx = 30;
106:
107: //c.ipady = 3;
108: //c.ipadx = 5;
109: c.insets = new Insets(5, 5, 5, 5);
110: c.anchor = GridBagConstraints.WEST;
111:
112: JLabel nameFieldLabel = new JLabel(language
113: .getString("Starters.Starter.Attributes.Name")
114: + ":");
115: editorPanel.add(nameFieldLabel, c);
116:
117: // The name field
118: c.gridx = 1;
119: c.weightx = 60;
120: nameField = new JTextField(20);
121: nameField.getDocument().addDocumentListener(
122: new TextValueListener() {
123: public void textValueChanged(DocumentEvent e) {
124: if (isUpdateOnChange && (getElement() != null)) {
125: ((Starter) getElement()).setName(nameField
126: .getText());
127: }
128: }
129: });
130: editorPanel.add(nameField, c);
131: nameFieldLabel.setLabelFor(nameField);
132:
133: // The classname field label
134: c.gridx = 0;
135: c.gridy = 1;
136:
137: JLabel classnameFieldLabel = new JLabel(language
138: .getString("Starters.Starter.Attributes.Classname")
139: + ":");
140: editorPanel.add(classnameFieldLabel, c);
141:
142: // The classname field
143: c.gridx = 1;
144: classnameField = new JTextField(20);
145: classnameField.getDocument().addDocumentListener(
146: new TextValueListener() {
147: public void textValueChanged(DocumentEvent e) {
148: if (isUpdateOnChange && (getElement() != null)) {
149: ((Starter) getElement())
150: .setClassname(classnameField
151: .getText());
152: }
153: }
154: });
155: editorPanel.add(classnameField, c);
156: classnameFieldLabel.setLabelFor(classnameField);
157:
158: // The classpath extension field label
159: c.gridx = 0;
160: c.gridy = 2;
161:
162: JLabel classpathExtFieldLabel = new JLabel(
163: language
164: .getString("Starters.Starter.Attributes.ClassPathExtension")
165: + ":");
166: editorPanel.add(classpathExtFieldLabel, c);
167:
168: // The classpath ext field
169: c.gridx = 1;
170: classpathExtField = new JTextField(20);
171: classpathExtField.getDocument().addDocumentListener(
172: new TextValueListener() {
173: public void textValueChanged(DocumentEvent e) {
174: if (isUpdateOnChange && (getElement() != null)) {
175: ((Starter) getElement())
176: .setClassPathExtension(classpathExtField
177: .getText());
178: }
179: }
180: });
181: editorPanel.add(classpathExtField, c);
182: classpathExtFieldLabel.setLabelFor(classpathExtField);
183:
184: // The initializer classname field label
185: c.gridx = 0;
186: c.gridy = 3;
187:
188: JLabel initClassnameFieldLabel = new JLabel(language
189: .getString("Starters.Starter.Attributes.InitClassname")
190: + ":");
191: editorPanel.add(initClassnameFieldLabel, c);
192:
193: // The initializer classname field
194: c.gridx = 1;
195: initClassnameField = new JTextField(20);
196: initClassnameField.getDocument().addDocumentListener(
197: new TextValueListener() {
198: public void textValueChanged(DocumentEvent e) {
199: if (isUpdateOnChange && (getElement() != null)) {
200: ((Starter) getElement())
201: .setInitClassname(initClassnameField
202: .getText());
203: }
204: }
205: });
206: editorPanel.add(initClassnameField, c);
207: initClassnameFieldLabel.setLabelFor(initClassnameField);
208:
209: // The duration field label
210: c.gridx = 0;
211: c.gridy = 4;
212:
213: JLabel durationFieldLabel = new JLabel(language
214: .getString("Starters.Starter.Attributes.Duration")
215: + ":");
216: editorPanel.add(durationFieldLabel, c);
217:
218: // The duration field
219: c.gridx = 1;
220: durationField = new LongTextField(5);
221: durationField.getDocument().addDocumentListener(
222: new TextValueListener() {
223: public void textValueChanged(DocumentEvent e) {
224: if (isUpdateOnChange && (getElement() != null)) {
225: ((Starter) getElement())
226: .setDuration(durationField
227: .getValue());
228: }
229: }
230: });
231: editorPanel.add(durationField, c);
232: durationFieldLabel.setLabelFor(durationField);
233:
234: // The detect duration field label (empty)
235: c.gridx = 0;
236: c.gridy = 5;
237:
238: JLabel detectDurationFieldLabel = new JLabel("");
239: editorPanel.add(detectDurationFieldLabel, c);
240:
241: // The duration field
242: c.gridx = 1;
243: detectDurationCheckbox = new JCheckBox(
244: language
245: .getString("Starters.Starter.Attributes.DetectStartupDuration"));
246: detectDurationCheckbox.addActionListener(new ActionListener() {
247: public void actionPerformed(ActionEvent e) {
248: if (isUpdateOnChange && (getElement() != null)) {
249: ((Starter) getElement())
250: .setDetectDuration(detectDurationCheckbox
251: .isSelected());
252: durationField.setEnabled(!detectDurationCheckbox
253: .isSelected());
254: }
255: }
256: });
257: editorPanel.add(detectDurationCheckbox, c);
258: }
259:
260: /**
261: * Returns whether this editor is responsible for a given structure element. This editor is
262: * responsible for user recordables.
263: *
264: * @param element the structure element
265: *
266: * @return <code>true</code> if <i>element</i> is a starter recordable and not
267: * <code>null</code>, otherwise <code>false</code>
268: */
269: public boolean handlesElement(StructureElement element) {
270: return (element != null) && (element instanceof Starter);
271: }
272:
273: /**
274: * Returns the actual recordable to be edited.
275: *
276: * @return DOCUMENT ME!
277: */
278: public StructureElement getElement() {
279: return element;
280: }
281:
282: /**
283: * Sets the structure element to edit.
284: *
285: * @param element DOCUMENT ME!
286: */
287: public void setElement(StructureElement element) {
288: this .element = element;
289:
290: Starter starter = (Starter) element;
291: nameField.setText(starter.getName());
292: classnameField.setText(starter.getClassname());
293: initClassnameField.setText(starter.getInitClassname());
294: durationField.setValue(starter.getDuration());
295: detectDurationCheckbox.setSelected(starter.getDetectDuration());
296:
297: durationField.setEnabled(!detectDurationCheckbox.isSelected());
298:
299: String classpathext = starter.getClassPathExtension();
300:
301: if (classpathext == null) {
302: classpathext = "";
303: }
304:
305: classpathExtField.setText(classpathext);
306: }
307:
308: /**
309: * Returns the component of the editor.
310: *
311: * @return the editor component
312: */
313: public Component getComponent() {
314: return editorPanel;
315: }
316: }
|