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.MousePressedReleased;
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.IntegerTextField;
032:
033: import java.awt.Component;
034: import java.awt.GridBagConstraints;
035: import java.awt.GridBagLayout;
036:
037: import javax.swing.JLabel;
038: import javax.swing.JPanel;
039: import javax.swing.JTextField;
040: import javax.swing.border.EmptyBorder;
041: import javax.swing.event.DocumentEvent;
042:
043: /**
044: * An editor for "mouse pressed and released" structure elements.
045: *
046: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
047: * @version 1.01
048: */
049: public class MousePressedReleasedEditor extends Editor {
050: /** The element to edit. */
051: private StructureElement element;
052:
053: /** The panel. */
054: private JPanel editorPanel;
055:
056: /** The grid bag constraints. */
057: private GridBagConstraints c;
058:
059: /** The text field for the source name. */
060: private JTextField sourceField;
061:
062: /** The text field for the root name. */
063: private JTextField rootField;
064:
065: /** The text field for the x position. */
066: private IntegerTextField xPosField;
067:
068: /** The text field for the y position. */
069: private IntegerTextField yPosField;
070:
071: /** The text field for the root x position. */
072: private IntegerTextField rootXPosField;
073:
074: /** The text field for the root y position. */
075: private IntegerTextField rootYPosField;
076:
077: /** The text field for the modifiers. */
078: private IntegerTextField modifiersField;
079:
080: /**
081: * Create a new mouse event recordable editor.
082: *
083: * @param env the environment
084: */
085: public MousePressedReleasedEditor(Environment env) {
086: super (env);
087:
088: Language language = getLanguage();
089:
090: // The panel with the text fields
091: editorPanel = new JPanel();
092: editorPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
093: editorPanel.setLayout(new GridBagLayout());
094:
095: // The source field label
096: c = new GridBagConstraints();
097: c.gridx = 0;
098: c.gridy = 0;
099: c.weightx = 40;
100: c.ipadx = 5;
101: c.ipady = 5;
102: c.anchor = GridBagConstraints.WEST;
103:
104: JLabel sourceFieldLabel = new JLabel(language
105: .getString("Events.Event.Source")
106: + ":");
107: editorPanel.add(sourceFieldLabel, c);
108:
109: // The source field
110: c.gridx = 1;
111: c.weightx = 60;
112: sourceField = new JTextField("", 20);
113: sourceField.getDocument().addDocumentListener(
114: new TextValueListener() {
115: public void textValueChanged(DocumentEvent e) {
116: if (isUpdateOnChange && (getElement() != null)) {
117: ((MousePressedReleased) getElement())
118: .setSourceName(sourceField
119: .getText());
120: }
121: }
122: });
123: editorPanel.add(sourceField, c);
124: sourceFieldLabel.setLabelFor(sourceField);
125:
126: // The root field label
127: c.gridx = 0;
128: c.gridy = 1;
129:
130: JLabel rootFieldLabel = new JLabel(language
131: .getString("Events.ComponentEvent.Root")
132: + ":");
133: editorPanel.add(rootFieldLabel, c);
134:
135: // The root field
136: c.gridx = 1;
137: rootField = new JTextField("", 20);
138: rootField.getDocument().addDocumentListener(
139: new TextValueListener() {
140: public void textValueChanged(DocumentEvent e) {
141: if (isUpdateOnChange && (getElement() != null)) {
142: ((MousePressedReleased) getElement())
143: .setRootName(rootField.getText());
144: }
145: }
146: });
147: editorPanel.add(rootField, c);
148: rootFieldLabel.setLabelFor(rootField);
149:
150: // The x pos field label
151: c.gridx = 0;
152: c.gridy = 2;
153:
154: JLabel xPosFieldLabel = new JLabel(language
155: .getString("Events.MouseEvent.XPosition")
156: + ":");
157: editorPanel.add(xPosFieldLabel, c);
158:
159: // The x pos field
160: c.gridx = 1;
161: xPosField = new IntegerTextField(0, 5);
162: xPosField.getDocument().addDocumentListener(
163: new TextValueListener() {
164: public void textValueChanged(DocumentEvent e) {
165: if (isUpdateOnChange && (getElement() != null)) {
166: MousePressedReleased MousePressedReleased = (MousePressedReleased) getElement();
167: int diffX = xPosField.getValue()
168: - MousePressedReleased.getX();
169: MousePressedReleased.setX(xPosField
170: .getValue());
171: MousePressedReleased
172: .setRootX(MousePressedReleased
173: .getRootX()
174: + diffX);
175: rootXPosField.setValue(MousePressedReleased
176: .getRootX());
177: }
178: }
179: });
180: editorPanel.add(xPosField, c);
181: xPosFieldLabel.setLabelFor(xPosField);
182:
183: // The y pos field label
184: c.gridx = 0;
185: c.gridy = 3;
186:
187: JLabel yPosFieldLabel = new JLabel(language
188: .getString("Events.MouseEvent.YPosition")
189: + ":");
190: editorPanel.add(yPosFieldLabel, c);
191:
192: // The y pos field
193: c.gridx = 1;
194: yPosField = new IntegerTextField(0, 5);
195: yPosField.getDocument().addDocumentListener(
196: new TextValueListener() {
197: public void textValueChanged(DocumentEvent e) {
198: if (isUpdateOnChange && (getElement() != null)) {
199: MousePressedReleased MousePressedReleased = (MousePressedReleased) getElement();
200: int diffY = yPosField.getValue()
201: - MousePressedReleased.getY();
202: MousePressedReleased.setY(yPosField
203: .getValue());
204: MousePressedReleased
205: .setRootY(MousePressedReleased
206: .getRootY()
207: + diffY);
208: rootYPosField.setValue(MousePressedReleased
209: .getRootY());
210: }
211: }
212: });
213: editorPanel.add(yPosField, c);
214: yPosFieldLabel.setLabelFor(yPosField);
215:
216: // The root x pos field label
217: c.gridx = 0;
218: c.gridy = 4;
219:
220: JLabel rootXPosFieldLabel = new JLabel(language
221: .getString("Events.MouseEvent.RootXPosition")
222: + ":");
223: editorPanel.add(rootXPosFieldLabel, c);
224:
225: // The root x pos field
226: c.gridx = 1;
227: rootXPosField = new IntegerTextField(0, 5);
228: rootXPosField.setEditable(false);
229: editorPanel.add(rootXPosField, c);
230: rootXPosFieldLabel.setLabelFor(rootXPosField);
231:
232: // The root y pos field label
233: c.gridx = 0;
234: c.gridy = 5;
235:
236: JLabel rootYPosFieldLabel = new JLabel(language
237: .getString("Events.MouseEvent.RootYPosition")
238: + ":");
239: editorPanel.add(rootYPosFieldLabel, c);
240:
241: // The root y pos field
242: c.gridx = 1;
243: rootYPosField = new IntegerTextField(0, 5);
244: rootYPosField.setEditable(false);
245: editorPanel.add(rootYPosField, c);
246: rootYPosFieldLabel.setLabelFor(rootYPosField);
247:
248: // The modifiers field label
249: c.gridx = 0;
250: c.gridy = 6;
251:
252: JLabel modifiersFieldLabel = new JLabel(language
253: .getString("Events.InputEvent.Modifiers")
254: + ":");
255: editorPanel.add(modifiersFieldLabel, c);
256:
257: // The modifiers field.
258: c.gridx = 1;
259: modifiersField = new IntegerTextField(0, 10);
260: modifiersField.getDocument().addDocumentListener(
261: new TextValueListener() {
262: public void textValueChanged(DocumentEvent e) {
263: if (isUpdateOnChange && (getElement() != null)) {
264: ((MousePressedReleased) getElement())
265: .setModifiers(modifiersField
266: .getValue());
267: }
268: }
269: });
270: editorPanel.add(modifiersField, c);
271: modifiersFieldLabel.setLabelFor(modifiersField);
272: }
273:
274: /**
275: * Returns whether this editor is responsible for a given structure element. This editor is
276: * responsible for all event recordables.
277: *
278: * @param element the structure element
279: *
280: * @return <code>true</code> if <i>element</i> is a mouse event recordable and not
281: * <code>null</code>, otherwise <code>false</code>
282: */
283: public boolean handlesElement(StructureElement element) {
284: return (element != null)
285: && (element instanceof MousePressedReleased);
286: }
287:
288: /**
289: * Returns the actual structure element to be edited.
290: *
291: * @return DOCUMENT ME!
292: */
293: public StructureElement getElement() {
294: return element;
295: }
296:
297: /**
298: * Sets the element to edit.
299: *
300: * @param element DOCUMENT ME!
301: */
302: public void setElement(StructureElement element) {
303: this .element = element;
304:
305: MousePressedReleased mpr = (MousePressedReleased) element;
306: xPosField.setValue(mpr.getX());
307: yPosField.setValue(mpr.getY());
308: rootXPosField.setValue(mpr.getRootX());
309: rootYPosField.setValue(mpr.getRootY());
310: modifiersField.setValue(mpr.getModifiers());
311: sourceField.setText(mpr.getSourceName());
312: sourceField.setCaretPosition(0);
313: rootField.setText(mpr.getRootName());
314: rootField.setCaretPosition(0);
315: }
316:
317: /**
318: * Returns the component of the editor.
319: *
320: * @return the editor component
321: */
322: public Component getComponent() {
323: return editorPanel;
324: }
325: }
|