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.MouseClick;
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 clicks.
045: *
046: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
047: * @version 1.01
048: */
049: public class MouseClickEditor 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 click count. */
078: private IntegerTextField clickCountField;
079:
080: /** The text field for the modifiers. */
081: private IntegerTextField modifiersField;
082:
083: /**
084: * Create a new mouse event recordable editor.
085: *
086: * @param env the environment
087: */
088: public MouseClickEditor(Environment env) {
089: super (env);
090:
091: Language language = getLanguage();
092:
093: // The panel with the text fields
094: editorPanel = new JPanel();
095: editorPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
096: editorPanel.setLayout(new GridBagLayout());
097:
098: // The source field label
099: c = new GridBagConstraints();
100: c.gridx = 0;
101: c.gridy = 0;
102: c.weightx = 40;
103: c.ipadx = 5;
104: c.ipady = 5;
105: c.anchor = GridBagConstraints.WEST;
106:
107: JLabel sourceFieldLabel = new JLabel(language
108: .getString("Events.Event.Source")
109: + ":");
110: editorPanel.add(sourceFieldLabel, c);
111:
112: // The source field
113: c.gridx = 1;
114: c.weightx = 60;
115: sourceField = new JTextField("", 20);
116: sourceField.getDocument().addDocumentListener(
117: new TextValueListener() {
118: public void textValueChanged(DocumentEvent e) {
119: if (isUpdateOnChange && (getElement() != null)) {
120: ((MouseClick) getElement())
121: .setSourceName(sourceField
122: .getText());
123: }
124: }
125: });
126: editorPanel.add(sourceField, c);
127: sourceFieldLabel.setLabelFor(sourceField);
128:
129: // The root field label
130: c.gridx = 0;
131: c.gridy = 1;
132:
133: JLabel rootFieldLabel = new JLabel(language
134: .getString("Events.ComponentEvent.Root")
135: + ":");
136: editorPanel.add(rootFieldLabel, c);
137:
138: // The root field
139: c.gridx = 1;
140: rootField = new JTextField("", 20);
141: rootField.getDocument().addDocumentListener(
142: new TextValueListener() {
143: public void textValueChanged(DocumentEvent e) {
144: if (isUpdateOnChange && (getElement() != null)) {
145: ((MouseClick) getElement())
146: .setRootName(rootField.getText());
147: }
148: }
149: });
150: editorPanel.add(rootField, c);
151: rootFieldLabel.setLabelFor(rootField);
152:
153: // The x pos field label
154: c.gridx = 0;
155: c.gridy = 2;
156:
157: JLabel xPosFieldLabel = new JLabel(language
158: .getString("Events.MouseEvent.XPosition")
159: + ":");
160: editorPanel.add(xPosFieldLabel, c);
161:
162: // The x pos field
163: c.gridx = 1;
164: xPosField = new IntegerTextField(0, 5);
165: xPosField.getDocument().addDocumentListener(
166: new TextValueListener() {
167: public void textValueChanged(DocumentEvent e) {
168: if (isUpdateOnChange && (getElement() != null)) {
169: MouseClick mouseClick = (MouseClick) getElement();
170: int diffX = xPosField.getValue()
171: - mouseClick.getX();
172: mouseClick.setX(xPosField.getValue());
173: mouseClick.setRootX(mouseClick.getRootX()
174: + diffX);
175: rootXPosField.setValue(mouseClick
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: MouseClick mouseClick = (MouseClick) getElement();
200: int diffY = yPosField.getValue()
201: - mouseClick.getY();
202: mouseClick.setY(yPosField.getValue());
203: mouseClick.setRootY(mouseClick.getRootY()
204: + diffY);
205: rootYPosField.setValue(mouseClick
206: .getRootY());
207: }
208: }
209: });
210: editorPanel.add(yPosField, c);
211: yPosFieldLabel.setLabelFor(yPosField);
212:
213: // The root x pos field label
214: c.gridx = 0;
215: c.gridy = 4;
216:
217: JLabel rootXPosFieldLabel = new JLabel(language
218: .getString("Events.MouseEvent.RootXPosition")
219: + ":");
220: editorPanel.add(rootXPosFieldLabel, c);
221:
222: // The root x pos field
223: c.gridx = 1;
224: rootXPosField = new IntegerTextField(0, 5);
225: rootXPosField.setEditable(false);
226: editorPanel.add(rootXPosField, c);
227: rootXPosFieldLabel.setLabelFor(rootXPosField);
228:
229: // The root y pos field label
230: c.gridx = 0;
231: c.gridy = 5;
232:
233: JLabel rootYPosFieldLabel = new JLabel(language
234: .getString("Events.MouseEvent.RootYPosition")
235: + ":");
236: editorPanel.add(rootYPosFieldLabel, c);
237:
238: // The root y pos field
239: c.gridx = 1;
240: rootYPosField = new IntegerTextField(0, 5);
241: rootYPosField.setEditable(false);
242: editorPanel.add(rootYPosField, c);
243: rootYPosFieldLabel.setLabelFor(rootYPosField);
244:
245: // The click count field label
246: c.gridx = 0;
247: c.gridy = 6;
248:
249: JLabel clickCountFieldLabel = new JLabel(language
250: .getString("Events.MouseEvent.ClickCount")
251: + ":");
252: editorPanel.add(clickCountFieldLabel, c);
253:
254: // The click count field
255: c.gridx = 1;
256: clickCountField = new IntegerTextField(0, 5);
257: clickCountField.getDocument().addDocumentListener(
258: new TextValueListener() {
259: public void textValueChanged(DocumentEvent e) {
260: if (isUpdateOnChange && (getElement() != null)) {
261: ((MouseClick) getElement())
262: .setClickCount(clickCountField
263: .getValue());
264: }
265: }
266: });
267: editorPanel.add(clickCountField, c);
268: clickCountFieldLabel.setLabelFor(clickCountField);
269:
270: // The modifiers field label
271: c.gridx = 0;
272: c.gridy = 7;
273:
274: JLabel modifiersFieldLabel = new JLabel(language
275: .getString("Events.InputEvent.Modifiers")
276: + ":");
277: editorPanel.add(modifiersFieldLabel, c);
278:
279: // The modifiers field.
280: c.gridx = 1;
281: modifiersField = new IntegerTextField(0, 10);
282: modifiersField.getDocument().addDocumentListener(
283: new TextValueListener() {
284: public void textValueChanged(DocumentEvent e) {
285: if (isUpdateOnChange && (getElement() != null)) {
286: ((MouseClick) getElement())
287: .setModifiers(modifiersField
288: .getValue());
289: }
290: }
291: });
292: editorPanel.add(modifiersField, c);
293: modifiersFieldLabel.setLabelFor(modifiersField);
294: }
295:
296: /**
297: * Returns whether this editor is responsible for a given structure element. This editor is
298: * responsible for all event recordables.
299: *
300: * @param element the structure element
301: *
302: * @return <code>true</code> if <i>element</i> is a mouse event recordable and not
303: * <code>null</code>, otherwise <code>false</code>
304: */
305: public boolean handlesElement(StructureElement element) {
306: return (element != null) && (element instanceof MouseClick);
307: }
308:
309: /**
310: * Returns the actual structure element to be edited.
311: *
312: * @return DOCUMENT ME!
313: */
314: public StructureElement getElement() {
315: return element;
316: }
317:
318: /**
319: * Sets the element to edit.
320: *
321: * @param element DOCUMENT ME!
322: */
323: public void setElement(StructureElement element) {
324: this .element = element;
325:
326: MouseClick click = (MouseClick) element;
327: xPosField.setValue(click.getX());
328: yPosField.setValue(click.getY());
329: rootXPosField.setValue(click.getRootX());
330: rootYPosField.setValue(click.getRootY());
331: clickCountField.setValue(click.getClickCount());
332: modifiersField.setValue(click.getModifiers());
333: sourceField.setText(click.getSourceName());
334: sourceField.setCaretPosition(0);
335: rootField.setText(click.getRootName());
336: rootField.setCaretPosition(0);
337: }
338:
339: /**
340: * Returns the component of the editor.
341: *
342: * @return the editor component
343: */
344: public Component getComponent() {
345: return editorPanel;
346: }
347: }
|