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.MouseMotion;
027: import jacareto.struct.StructureElement;
028: import jacareto.system.Environment;
029: import jacareto.system.Language;
030: import jacareto.toolkit.swing.IntegerTextField;
031:
032: import java.awt.Component;
033: import java.awt.GridBagConstraints;
034: import java.awt.GridBagLayout;
035:
036: import javax.swing.JLabel;
037: import javax.swing.JPanel;
038: import javax.swing.JTextField;
039: import javax.swing.border.EmptyBorder;
040:
041: /**
042: * An editor for mouse motions.
043: *
044: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
045: * @version 1.01
046: */
047: public class MouseMotionEditor extends Editor {
048: /** The element to edit. */
049: private StructureElement element;
050:
051: /** The panel. */
052: private JPanel editorPanel;
053:
054: /** The grid bag constraints. */
055: private GridBagConstraints c;
056:
057: /** The text field for the source name. */
058: private JTextField sourceField;
059:
060: /** The text field for the stop x position. */
061: private IntegerTextField startXField;
062:
063: /** The text field for the stop y position. */
064: private IntegerTextField startYField;
065:
066: /** The text field for the stop x position. */
067: private IntegerTextField stopXField;
068:
069: /** The text field for the stop y position. */
070: private IntegerTextField stopYField;
071:
072: /**
073: * Create a new mouse motion editor.
074: *
075: * @param env the environment
076: */
077: public MouseMotionEditor(Environment env) {
078: super (env);
079:
080: Language language = getLanguage();
081:
082: // The panel with the text fields
083: editorPanel = new JPanel();
084: editorPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
085: editorPanel.setLayout(new GridBagLayout());
086:
087: // The source field label
088: c = new GridBagConstraints();
089: c.gridx = 0;
090: c.gridy = 0;
091: c.weightx = 40;
092: c.ipadx = 5;
093: c.ipady = 5;
094: c.anchor = GridBagConstraints.WEST;
095:
096: JLabel sourceFieldLabel = new JLabel(language
097: .getString("Events.Event.Source")
098: + ":");
099: editorPanel.add(sourceFieldLabel, c);
100:
101: // The source field
102: c.gridx = 1;
103: c.weightx = 60;
104: sourceField = new JTextField("", 20);
105: sourceField.setEditable(false);
106: sourceField.setBackground(editorPanel.getBackground());
107: editorPanel.add(sourceField, c);
108: sourceFieldLabel.setLabelFor(sourceField);
109:
110: // The start x field label
111: c.gridx = 0;
112: c.gridy = 1;
113:
114: JLabel startXFieldLabel = new JLabel(language
115: .getString("Structures.MouseMotion.StartX")
116: + ":");
117: editorPanel.add(startXFieldLabel, c);
118:
119: // The start x field
120: c.gridx = 1;
121: startXField = new IntegerTextField(0, 5);
122: startXField.setEditable(false);
123: startXField.setBackground(editorPanel.getBackground());
124: editorPanel.add(startXField, c);
125: startXFieldLabel.setLabelFor(startXField);
126:
127: // The start y field label
128: c.gridx = 0;
129: c.gridy = 2;
130:
131: JLabel startYFieldLabel = new JLabel(language
132: .getString("Structures.MouseMotion.StartY")
133: + ":");
134: editorPanel.add(startYFieldLabel, c);
135:
136: // The start y field
137: c.gridx = 1;
138: startYField = new IntegerTextField(0, 5);
139: startYField.setEditable(false);
140: startYField.setBackground(editorPanel.getBackground());
141: editorPanel.add(startYField, c);
142: startYFieldLabel.setLabelFor(startYField);
143:
144: // The stop x field label
145: c.gridx = 0;
146: c.gridy = 3;
147:
148: JLabel stopXFieldLabel = new JLabel(language
149: .getString("Structures.MouseMotion.StopX")
150: + ":");
151: editorPanel.add(stopXFieldLabel, c);
152:
153: // The stop x field
154: c.gridx = 1;
155: stopXField = new IntegerTextField(0, 5);
156: stopXField.setEditable(false);
157: stopXField.setBackground(editorPanel.getBackground());
158: editorPanel.add(stopXField, c);
159: stopXFieldLabel.setLabelFor(stopXField);
160:
161: // The stop y field label
162: c.gridx = 0;
163: c.gridy = 4;
164:
165: JLabel stopYFieldLabel = new JLabel(language
166: .getString("Structures.MouseMotion.StopY")
167: + ":");
168: editorPanel.add(stopYFieldLabel, c);
169:
170: // The stop y field
171: c.gridx = 1;
172: stopYField = new IntegerTextField(0, 5);
173: stopYField.setEditable(false);
174: stopYField.setBackground(editorPanel.getBackground());
175: editorPanel.add(stopYField, c);
176: stopYFieldLabel.setLabelFor(stopYField);
177: }
178:
179: /**
180: * Returns whether this editor is responsible for a given structure element. This editor is
181: * responsible for all event recordables.
182: *
183: * @param element the structure element
184: *
185: * @return <code>true</code> if <i>element</i> is a mouse event recordable and not
186: * <code>null</code>, otherwise <code>false</code>
187: */
188: public boolean handlesElement(StructureElement element) {
189: return (element != null) && (element instanceof MouseMotion);
190: }
191:
192: /**
193: * Returns the actual structure element to be edited.
194: *
195: * @return DOCUMENT ME!
196: */
197: public StructureElement getElement() {
198: return element;
199: }
200:
201: /**
202: * Sets the element to edit.
203: *
204: * @param element DOCUMENT ME!
205: */
206: public void setElement(StructureElement element) {
207: this .element = element;
208:
209: MouseMotion motion = (MouseMotion) element;
210: startXField.setValue(motion.getStartX());
211: startYField.setValue(motion.getStartY());
212: stopXField.setValue(motion.getStopX());
213: stopYField.setValue(motion.getStopY());
214: sourceField.setText(motion.getSourceName());
215: sourceField.setCaretPosition(0);
216: }
217:
218: /**
219: * Returns the component of the editor.
220: *
221: * @return the editor component
222: */
223: public Component getComponent() {
224: return editorPanel;
225: }
226: }
|