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.record.SetUserDefinedNameRecordable;
027: import jacareto.struct.StructureElement;
028: import jacareto.system.Environment;
029: import jacareto.toolkit.event.TextValueListener;
030:
031: import java.awt.Component;
032: import java.awt.GridBagConstraints;
033: import java.awt.GridBagLayout;
034: import java.awt.Insets;
035:
036: import javax.swing.JLabel;
037: import javax.swing.JPanel;
038: import javax.swing.JTextField;
039: import javax.swing.event.DocumentEvent;
040:
041: /**
042: * An editor for set user defined name recordables.
043: *
044: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
045: * @version 1.0
046: */
047: public class SetUserDefinedNameRecordableEditor extends Editor {
048: /** The structure element to edit. */
049: private StructureElement element;
050:
051: /** The editor's component. */
052: private JPanel editorPanel;
053:
054: /** The text field for the Jacareto name. */
055: private JTextField jacaretoNameField;
056:
057: /** The text field for the user defined name. */
058: private JTextField userDefinedNameField;
059:
060: /**
061: * Create a new editor.
062: *
063: * @param env the environment
064: */
065: public SetUserDefinedNameRecordableEditor(Environment env) {
066: super (env);
067: editorPanel = new JPanel(new GridBagLayout());
068:
069: GridBagConstraints c = new GridBagConstraints();
070: c.gridx = 0;
071: c.gridy = 0;
072: c.weightx = 40;
073: c.anchor = GridBagConstraints.WEST;
074: c.insets = new Insets(5, 5, 5, 5);
075:
076: JLabel jacaretoNameLabel = new JLabel(
077: language
078: .getString("CleverPHL.SetUserDefinedNameDialog.JacaretoName")
079: + ":");
080: editorPanel.add(jacaretoNameLabel, c);
081:
082: c.weightx = 60;
083: c.gridx = 1;
084: jacaretoNameField = new JTextField(30);
085: jacaretoNameField.getDocument().addDocumentListener(
086: new TextValueListener() {
087: public void textValueChanged(DocumentEvent e) {
088: if (isUpdateOnChange && (getElement() != null)) {
089: ((SetUserDefinedNameRecordable) getElement())
090: .setJacaretoName(jacaretoNameField
091: .getText());
092: }
093: }
094: });
095: editorPanel.add(jacaretoNameField, c);
096:
097: c.gridx = 0;
098: c.gridy = 1;
099:
100: JLabel userDefinedNameLabel = new JLabel(
101: language
102: .getString("CleverPHL.SetUserDefinedNameDialog.UserDefinedName")
103: + ":");
104: editorPanel.add(userDefinedNameLabel, c);
105:
106: c.gridx = 1;
107: userDefinedNameField = new JTextField(30);
108: userDefinedNameField.getDocument().addDocumentListener(
109: new TextValueListener() {
110: public void textValueChanged(DocumentEvent e) {
111: if (isUpdateOnChange && (getElement() != null)) {
112: ((SetUserDefinedNameRecordable) getElement())
113: .setUserDefinedName(userDefinedNameField
114: .getText());
115: }
116: }
117: });
118: editorPanel.add(userDefinedNameField, c);
119: }
120:
121: /**
122: * Returns whether this editor is responsible for a given structure element. This editor is
123: * responsible for set user defined name recordables.
124: *
125: * @param element the structure element
126: *
127: * @return <code>true</code> if <i>element</i> is a set user defined name recordable and not
128: * <code>null</code>, otherwise <code>false</code>
129: */
130: public boolean handlesElement(StructureElement element) {
131: return (element != null)
132: && (element instanceof SetUserDefinedNameRecordable);
133: }
134:
135: /**
136: * Returns the actual structure element to be edited.
137: *
138: * @return DOCUMENT ME!
139: */
140: public StructureElement getElement() {
141: return element;
142: }
143:
144: /**
145: * Sets the structure element to edit.
146: *
147: * @param element DOCUMENT ME!
148: */
149: public void setElement(StructureElement element) {
150: this .element = element;
151:
152: SetUserDefinedNameRecordable sRecordable = (SetUserDefinedNameRecordable) element;
153: jacaretoNameField.setText(sRecordable.getJacaretoName());
154: userDefinedNameField.setText(sRecordable.getUserDefinedName());
155: }
156:
157: /**
158: * Returns the component of the editor.
159: *
160: * @return the editor component
161: */
162: public Component getComponent() {
163: return editorPanel;
164: }
165: }
|