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.MouseEventRecordable;
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.event.ActionEvent;
034: import java.awt.event.ActionListener;
035: import java.awt.event.MouseEvent;
036:
037: import javax.swing.JComboBox;
038: import javax.swing.event.DocumentEvent;
039:
040: /**
041: * An editor for mouse events which are not mouse motions.
042: *
043: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
044: * @version 1.02
045: */
046: public class MouseEventRecordableEditor extends
047: InputEventRecordableEditor {
048: /** The text field for the x position. */
049: private IntegerTextField xPosField;
050:
051: /** The text field for the y position. */
052: private IntegerTextField yPosField;
053:
054: /** The text field for the root x position. */
055: private IntegerTextField rootXPosField;
056:
057: /** The text field for the root y position. */
058: private IntegerTextField rootYPosField;
059:
060: /** The text field for the click count. */
061: private IntegerTextField clickCountField;
062:
063: /** The popup Trigger box. */
064: private JComboBox popupTriggerBox;
065:
066: /** The type box. */
067: private JComboBox typeBox;
068:
069: /**
070: * Create a new mouse event recordable editor.
071: *
072: * @param env the environment
073: */
074: public MouseEventRecordableEditor(Environment env) {
075: super (env);
076:
077: Language language = getLanguage();
078:
079: // The type box
080: typeBox = addComboBoxRow(language
081: .getString("Events.MouseEvent.Type"));
082: typeBox.addItem(language
083: .getString("Events.MouseEvent.MousePressed"));
084: typeBox.addItem(language
085: .getString("Events.MouseEvent.MouseReleased"));
086: typeBox.addItem(language
087: .getString("Events.MouseEvent.MouseClicked"));
088: typeBox.addItem(language
089: .getString("Events.MouseEvent.MouseEntered"));
090: typeBox.addItem(language
091: .getString("Events.MouseEvent.MouseExited"));
092: typeBox.addItem(language
093: .getString("Events.MouseEvent.MouseMoved"));
094: typeBox.addItem(language
095: .getString("Events.MouseEvent.MouseDragged"));
096: typeBox.addActionListener(new ActionListener() {
097: public void actionPerformed(ActionEvent e) {
098: MouseEventRecordable mRecordable = (MouseEventRecordable) getElement();
099:
100: if (isUpdateOnChange && (mRecordable != null)) {
101: switch (typeBox.getSelectedIndex()) {
102: case 0:
103: mRecordable.setID(MouseEvent.MOUSE_PRESSED);
104:
105: break;
106:
107: case 1:
108: mRecordable.setID(MouseEvent.MOUSE_RELEASED);
109:
110: break;
111:
112: case 2:
113: mRecordable.setID(MouseEvent.MOUSE_CLICKED);
114:
115: break;
116:
117: case 3:
118: mRecordable.setID(MouseEvent.MOUSE_ENTERED);
119:
120: break;
121:
122: case 4:
123: mRecordable.setID(MouseEvent.MOUSE_EXITED);
124:
125: break;
126:
127: case 5:
128: mRecordable.setID(MouseEvent.MOUSE_MOVED);
129:
130: break;
131:
132: case 6:
133: mRecordable.setID(MouseEvent.MOUSE_DRAGGED);
134:
135: break;
136: }
137: }
138: }
139: });
140:
141: // The x pos field
142: xPosField = addIntegerTextFieldRow(language
143: .getString("Events.MouseEvent.XPosition"), 5);
144: xPosField.getDocument().addDocumentListener(
145: new TextValueListener() {
146: public void textValueChanged(DocumentEvent e) {
147: if (isUpdateOnChange && (getElement() != null)) {
148: MouseEventRecordable meRecordable = (MouseEventRecordable) getElement();
149: int diffX = xPosField.getValue()
150: - meRecordable.getX();
151: meRecordable.setX(xPosField.getValue());
152: meRecordable.setRootX(meRecordable
153: .getRootX()
154: + diffX);
155: rootXPosField.setValue(meRecordable
156: .getRootX());
157: }
158: }
159: });
160:
161: // The y pos field
162: yPosField = addIntegerTextFieldRow(language
163: .getString("Events.MouseEvent.YPosition"), 5);
164: yPosField.getDocument().addDocumentListener(
165: new TextValueListener() {
166: public void textValueChanged(DocumentEvent e) {
167: if (isUpdateOnChange && (getElement() != null)) {
168: MouseEventRecordable meRecordable = (MouseEventRecordable) getElement();
169: int diffY = yPosField.getValue()
170: - meRecordable.getY();
171: meRecordable.setY(yPosField.getValue());
172: meRecordable.setRootY(meRecordable
173: .getRootY()
174: + diffY);
175: rootYPosField.setValue(meRecordable
176: .getRootY());
177: }
178: }
179: });
180:
181: // The root x pos field
182: rootXPosField = addIntegerTextFieldRow(language
183: .getString("Events.MouseEvent.RootXPosition"), 5);
184: rootXPosField.setEditable(false);
185:
186: // The root y pos field
187: rootYPosField = addIntegerTextFieldRow(language
188: .getString("Events.MouseEvent.RootYPosition"), 5);
189: rootYPosField.setEditable(false);
190:
191: // The click count field
192: clickCountField = addIntegerTextFieldRow(language
193: .getString("Events.MouseEvent.ClickCount"), 5);
194: clickCountField.getDocument().addDocumentListener(
195: new TextValueListener() {
196: public void textValueChanged(DocumentEvent e) {
197: if (isUpdateOnChange && (getElement() != null)) {
198: ((MouseEventRecordable) getElement())
199: .setClickCount(clickCountField
200: .getValue());
201: }
202: }
203: });
204:
205: // The is popup trigger box
206: popupTriggerBox = addComboBoxRow(language
207: .getString("Events.MouseEvent.PopupTrigger"));
208: popupTriggerBox.addItem(language.getString("General.True"));
209: popupTriggerBox.addItem(language.getString("General.False"));
210: popupTriggerBox.addActionListener(new ActionListener() {
211: public void actionPerformed(ActionEvent e) {
212: if (isUpdateOnChange && (getElement() != null)) {
213: if (popupTriggerBox.getSelectedIndex() == 0) {
214: ((MouseEventRecordable) getElement())
215: .setConsumed(true);
216: } else {
217: ((MouseEventRecordable) getElement())
218: .setConsumed(false);
219: }
220: }
221: }
222: });
223: }
224:
225: /**
226: * Returns whether this editor is responsible for a given structure element. This editor is
227: * responsible for all event recordables.
228: *
229: * @param element the structure element
230: *
231: * @return <code>true</code> if <i>element</i> is a mouse event recordable and not
232: * <code>null</code>, otherwise <code>false</code>
233: */
234: public boolean handlesElement(StructureElement element) {
235: return (element != null)
236: && (element instanceof MouseEventRecordable);
237: }
238:
239: /**
240: * Sets the element to edit.
241: *
242: * @param element DOCUMENT ME!
243: */
244: public void setElement(StructureElement element) {
245: super .setElement(element);
246:
247: MouseEventRecordable mRecordable = (MouseEventRecordable) element;
248: xPosField.setValue(mRecordable.getX());
249: yPosField.setValue(mRecordable.getY());
250: rootXPosField.setValue(mRecordable.getRootX());
251: rootYPosField.setValue(mRecordable.getRootY());
252: clickCountField.setValue(mRecordable.getClickCount());
253:
254: if (mRecordable.isPopupTrigger()) {
255: popupTriggerBox.setSelectedIndex(0);
256: } else {
257: popupTriggerBox.setSelectedIndex(1);
258: }
259:
260: switch (mRecordable.getID()) {
261: case MouseEvent.MOUSE_PRESSED:
262: typeBox.setSelectedIndex(0);
263:
264: break;
265:
266: case MouseEvent.MOUSE_RELEASED:
267: typeBox.setSelectedIndex(1);
268:
269: break;
270:
271: case MouseEvent.MOUSE_CLICKED:
272: typeBox.setSelectedIndex(2);
273:
274: break;
275:
276: case MouseEvent.MOUSE_ENTERED:
277: typeBox.setSelectedIndex(3);
278:
279: break;
280:
281: case MouseEvent.MOUSE_EXITED:
282: typeBox.setSelectedIndex(4);
283:
284: break;
285:
286: case MouseEvent.MOUSE_MOVED:
287: typeBox.setSelectedIndex(5);
288:
289: break;
290:
291: case MouseEvent.MOUSE_DRAGGED:
292: typeBox.setSelectedIndex(6);
293:
294: break;
295: }
296: }
297: }
|