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.struct.MouseChangedComponent;
027: import jacareto.struct.StructureElement;
028: import jacareto.system.Environment;
029: import jacareto.system.Language;
030:
031: import java.awt.Component;
032: import java.awt.GridBagConstraints;
033: import java.awt.GridBagLayout;
034:
035: import javax.swing.JLabel;
036: import javax.swing.JPanel;
037: import javax.swing.JTextField;
038: import javax.swing.border.EmptyBorder;
039:
040: /**
041: * An editor for "mouse changed component" elements.
042: *
043: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
044: * @version 1.01
045: */
046: public class MouseChangedComponentEditor extends Editor {
047: /** The element to edit. */
048: private StructureElement element;
049:
050: /** The panel. */
051: private JPanel editorPanel;
052:
053: /** The grid bag constraints. */
054: private GridBagConstraints c;
055:
056: /** The text field for the old component name. */
057: private JTextField oldComponentField;
058:
059: /** The text field for the new component name. */
060: private JTextField newComponentField;
061:
062: /**
063: * Create a new "mouse exited" recordable editor.
064: *
065: * @param env the environment
066: */
067: public MouseChangedComponentEditor(Environment env) {
068: super (env);
069:
070: Language language = getLanguage();
071:
072: // The panel with the text fields
073: editorPanel = new JPanel();
074: editorPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
075: editorPanel.setLayout(new GridBagLayout());
076:
077: // The old component field label
078: c = new GridBagConstraints();
079: c.gridx = 0;
080: c.gridy = 0;
081: c.weightx = 40;
082: c.ipadx = 5;
083: c.ipady = 5;
084: c.anchor = GridBagConstraints.WEST;
085:
086: JLabel oldComponentFieldLabel = new JLabel(
087: language
088: .getString("Structures.MouseChangedComponent.OldComponent")
089: + ":");
090: editorPanel.add(oldComponentFieldLabel, c);
091:
092: // The old component field
093: c.gridx = 1;
094: c.weightx = 60;
095: oldComponentField = new JTextField("", 20);
096: oldComponentField.setEditable(false);
097: editorPanel.add(oldComponentField, c);
098: oldComponentFieldLabel.setLabelFor(oldComponentField);
099:
100: // The new component field label
101: c.gridx = 0;
102: c.gridy = 1;
103:
104: JLabel newComponentFieldLabel = new JLabel(
105: language
106: .getString("Structures.MouseChangedComponent.NewComponent")
107: + ":");
108: editorPanel.add(newComponentFieldLabel, c);
109:
110: // The old component field
111: c.gridx = 1;
112: newComponentField = new JTextField("", 20);
113: newComponentField.setEditable(false);
114: editorPanel.add(newComponentField, c);
115: newComponentFieldLabel.setLabelFor(newComponentField);
116: }
117:
118: /**
119: * Returns whether this editor is responsible for a given structure element. This editor is
120: * responsible for all "mouse exited" elements.
121: *
122: * @param element the structure element
123: *
124: * @return <code>true</code> if <i>element</i> is a mouse event recordable and not
125: * <code>null</code>, otherwise <code>false</code>
126: */
127: public boolean handlesElement(StructureElement element) {
128: return (element != null)
129: && (element instanceof MouseChangedComponent);
130: }
131:
132: /**
133: * Returns the actual structure element to be edited.
134: *
135: * @return DOCUMENT ME!
136: */
137: public StructureElement getElement() {
138: return element;
139: }
140:
141: /**
142: * Sets the element to edit.
143: *
144: * @param element DOCUMENT ME!
145: */
146: public void setElement(StructureElement element) {
147: this .element = element;
148:
149: MouseChangedComponent changed = (MouseChangedComponent) element;
150: oldComponentField.setText(changed.getOldComponent());
151: oldComponentField.setCaretPosition(0);
152: newComponentField.setText(changed.getNewComponent());
153: newComponentField.setCaretPosition(0);
154: }
155:
156: /**
157: * Returns the component of the editor.
158: *
159: * @return the editor component
160: */
161: public Component getComponent() {
162: return editorPanel;
163: }
164: }
|