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.struct;
025:
026: import jacareto.parse.RecordTokenizer;
027: import jacareto.parse.RecordTokenizerState;
028: import jacareto.record.ListSelectionEventRecordable;
029: import jacareto.record.MouseEventRecordable;
030: import jacareto.system.Environment;
031:
032: import java.awt.event.MouseEvent;
033:
034: /**
035: * The selection of a list has changed
036: *
037: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
038: * @version 1.01
039: */
040: public class ListSelectionChange extends StructureElement {
041: /**
042: * Creates a new "list selection change" structure element.
043: *
044: * @param env the environment
045: * @param children the child structure elements
046: */
047: public ListSelectionChange(Environment env,
048: StructureElement[] children) {
049: super (env, children);
050: }
051:
052: /**
053: * Parses a record which is tokenized by the given record tokenizer.
054: *
055: * @param env DOCUMENT ME!
056: * @param recordTokenizer the record tokenizer
057: *
058: * @return a structure element, or <code>null</code> if this class cannot parse the record at
059: * the current position
060: */
061: public static StructureElement parse(Environment env,
062: RecordTokenizer recordTokenizer) {
063: StructureElement result = null;
064: StructureElement[] children = null;
065:
066: RecordTokenizerState rtState = recordTokenizer.saveState();
067:
068: // mouse pressed, list selection, mouse released, list selection, mouse clicked
069: try {
070: MouseEventRecordable mousePressed = (MouseEventRecordable) recordTokenizer
071: .next();
072: ListSelectionEventRecordable list1 = (ListSelectionEventRecordable) recordTokenizer
073: .next();
074: MouseEventRecordable mouseReleased = (MouseEventRecordable) recordTokenizer
075: .next();
076: ListSelectionEventRecordable list2 = (ListSelectionEventRecordable) recordTokenizer
077: .next();
078: MouseEventRecordable mouseClicked = (MouseEventRecordable) recordTokenizer
079: .next();
080:
081: boolean cond = true;
082: cond = cond
083: && (mousePressed.getID() == MouseEvent.MOUSE_PRESSED)
084: && (mouseReleased.getID() == MouseEvent.MOUSE_RELEASED)
085: && (mouseClicked.getID() == MouseEvent.MOUSE_CLICKED);
086:
087: if (cond) {
088: RecordTokenizerState beforeClick = recordTokenizer
089: .saveState();
090: MouseClick secondClick = (MouseClick) MouseClick.parse(
091: env, recordTokenizer);
092:
093: if ((secondClick != null)
094: && (secondClick.getClickedChild()
095: .getClickCount() != 2)) {
096: secondClick = null;
097: recordTokenizer.restoreState(beforeClick);
098: }
099:
100: StructureElement[] mouseChildren = new StructureElement[3];
101: mouseChildren[0] = mousePressed;
102: mouseChildren[1] = mouseReleased;
103: mouseChildren[2] = mouseClicked;
104:
105: MouseClick firstClick = new MouseClick(env,
106: mouseChildren);
107: children = new StructureElement[3];
108:
109: int index = 0;
110:
111: if (secondClick != null) {
112: MouseClick[] mClickChildren = new MouseClick[2];
113: mClickChildren[0] = firstClick;
114: mClickChildren[1] = secondClick;
115:
116: MultipleMouseClick mClick = new MultipleMouseClick(
117: env, mClickChildren);
118: children[index++] = mClick;
119: } else {
120: children[index++] = firstClick;
121: }
122:
123: children[index++] = list1;
124: children[index++] = list2;
125: } else {
126: throw new Exception();
127: }
128: } catch (Throwable t) {
129: recordTokenizer.restoreState(rtState);
130: }
131:
132: // mouse pressed, focus change, mouse released, list selection, (list selection), mouse clicked
133: if (children == null) {
134: try {
135: MouseEventRecordable mousePressed = (MouseEventRecordable) recordTokenizer
136: .next();
137: FocusChange focusChange = (FocusChange) FocusChange
138: .parse(env, recordTokenizer);
139: MouseEventRecordable mouseReleased = (MouseEventRecordable) recordTokenizer
140: .next();
141: ListSelectionEventRecordable list1 = (ListSelectionEventRecordable) recordTokenizer
142: .next();
143: ListSelectionEventRecordable list2 = null;
144:
145: StructureElement tmp = recordTokenizer.get(0);
146:
147: if ((tmp != null)
148: && tmp instanceof ListSelectionEventRecordable) {
149: list2 = (ListSelectionEventRecordable) tmp;
150: recordTokenizer.forward();
151: }
152:
153: MouseEventRecordable mouseClicked = (MouseEventRecordable) recordTokenizer
154: .next();
155:
156: boolean cond = true;
157: cond = cond && (focusChange != null);
158: cond = cond
159: && (mousePressed.getID() == MouseEvent.MOUSE_PRESSED)
160: && (mouseReleased.getID() == MouseEvent.MOUSE_RELEASED)
161: && (mouseClicked.getID() == MouseEvent.MOUSE_CLICKED);
162:
163: if (cond) {
164: StructureElement[] mouseChildren = new StructureElement[3];
165: mouseChildren[0] = mousePressed;
166: mouseChildren[1] = mouseReleased;
167: mouseChildren[2] = mouseClicked;
168:
169: if (list2 != null) {
170: children = new StructureElement[4];
171: } else {
172: children = new StructureElement[3];
173: }
174:
175: int index = 0;
176: children[index++] = new MouseClick(env,
177: mouseChildren);
178: children[index++] = focusChange;
179: children[index++] = list1;
180:
181: if (list2 != null) {
182: children[index++] = list2;
183: }
184: } else {
185: throw new Exception();
186: }
187: } catch (Throwable t) {
188: recordTokenizer.restoreState(rtState);
189: }
190: }
191:
192: // mouse pressed, list selection, focus change, mouse drag, mouse released, list selection
193: if (children == null) {
194: try {
195: MouseEventRecordable mousePressed = (MouseEventRecordable) recordTokenizer
196: .next();
197: ListSelectionEventRecordable list1 = (ListSelectionEventRecordable) recordTokenizer
198: .next();
199: FocusChange focusChange = (FocusChange) FocusChange
200: .parse(env, recordTokenizer);
201: MouseDrag mouseDrag = (MouseDrag) MouseDrag.parse(env,
202: recordTokenizer);
203: MouseEventRecordable mouseReleased = (MouseEventRecordable) recordTokenizer
204: .next();
205: ListSelectionEventRecordable list2 = (ListSelectionEventRecordable) recordTokenizer
206: .next();
207:
208: boolean cond = true;
209: cond = cond && (focusChange != null)
210: && (mouseDrag != null);
211: cond = cond
212: && (mousePressed.getID() == MouseEvent.MOUSE_PRESSED)
213: && (mouseReleased.getID() == MouseEvent.MOUSE_RELEASED);
214: cond = cond && (list1 != null) && (list2 != null);
215:
216: if (cond) {
217: children = new StructureElement[6];
218:
219: int index = 0;
220: children[index++] = mousePressed;
221: children[index++] = list1;
222: children[index++] = focusChange;
223: children[index++] = mouseDrag;
224: children[index++] = mouseReleased;
225: children[index++] = list2;
226: } else {
227: throw new Exception();
228: }
229: } catch (Throwable t) {
230: recordTokenizer.restoreState(rtState);
231: }
232: }
233:
234: // mouse pressed, list selection, focus change, mouse released, list selection, mouse clicked
235: if (children == null) {
236: try {
237: MouseEventRecordable mousePressed = (MouseEventRecordable) recordTokenizer
238: .next();
239: ListSelectionEventRecordable list1 = (ListSelectionEventRecordable) recordTokenizer
240: .next();
241: FocusChange focusChange = (FocusChange) FocusChange
242: .parse(env, recordTokenizer);
243: MouseEventRecordable mouseReleased = (MouseEventRecordable) recordTokenizer
244: .next();
245: ListSelectionEventRecordable list2 = (ListSelectionEventRecordable) recordTokenizer
246: .next();
247: MouseEventRecordable mouseClicked = (MouseEventRecordable) recordTokenizer
248: .next();
249:
250: boolean cond = true;
251: cond = cond && (focusChange != null);
252: cond = cond
253: && (mousePressed.getID() == MouseEvent.MOUSE_PRESSED)
254: && (mouseReleased.getID() == MouseEvent.MOUSE_RELEASED)
255: && (mouseClicked.getID() == MouseEvent.MOUSE_CLICKED);
256: cond = cond && (list1 != null) && (list2 != null);
257:
258: if (cond) {
259: RecordTokenizerState beforeClick = recordTokenizer
260: .saveState();
261: MouseClick secondClick = (MouseClick) MouseClick
262: .parse(env, recordTokenizer);
263:
264: if ((secondClick != null)
265: && (secondClick.getClickedChild()
266: .getClickCount() != 2)) {
267: secondClick = null;
268: recordTokenizer.restoreState(beforeClick);
269: }
270:
271: StructureElement[] mouseChildren = new StructureElement[3];
272: mouseChildren[0] = mousePressed;
273: mouseChildren[1] = mouseReleased;
274: mouseChildren[2] = mouseClicked;
275:
276: MouseClick firstClick = new MouseClick(env,
277: mouseChildren);
278:
279: children = new StructureElement[4];
280:
281: int index = 0;
282:
283: if (secondClick != null) {
284: MouseClick[] mClickChildren = new MouseClick[2];
285: mClickChildren[0] = firstClick;
286: mClickChildren[1] = secondClick;
287:
288: MultipleMouseClick mClick = new MultipleMouseClick(
289: env, mClickChildren);
290: children[index++] = mClick;
291: } else {
292: children[index++] = firstClick;
293: }
294:
295: children[index++] = focusChange;
296: children[index++] = list1;
297: children[index++] = list2;
298: } else {
299: throw new Exception();
300: }
301: } catch (Throwable t) {
302: recordTokenizer.restoreState(rtState);
303: }
304: }
305:
306: // focus change, list selection, list selection,
307: if (children == null) {
308: try {
309: FocusChange focusChange = (FocusChange) FocusChange
310: .parse(env, recordTokenizer);
311: ListSelectionEventRecordable list1 = (ListSelectionEventRecordable) recordTokenizer
312: .next();
313: ListSelectionEventRecordable list2 = (ListSelectionEventRecordable) recordTokenizer
314: .next();
315:
316: boolean cond = (focusChange != null) && (list1 != null)
317: && (list2 != null);
318:
319: if (cond) {
320: children = new StructureElement[3];
321:
322: int index = 0;
323: children[index++] = focusChange;
324: children[index++] = list1;
325: children[index++] = list2;
326: } else {
327: throw new Exception();
328: }
329: } catch (Throwable t) {
330: recordTokenizer.restoreState(rtState);
331: }
332: }
333:
334: // mouse pressed, list selection, mouse drag, mouse released, list selection
335: if (children == null) {
336: try {
337: MouseEventRecordable mousePressed = (MouseEventRecordable) recordTokenizer
338: .next();
339: ListSelectionEventRecordable list1 = (ListSelectionEventRecordable) recordTokenizer
340: .next();
341: MouseDrag mouseDrag = (MouseDrag) MouseDrag.parse(env,
342: recordTokenizer);
343: MouseEventRecordable mouseReleased = (MouseEventRecordable) recordTokenizer
344: .next();
345: ListSelectionEventRecordable list2 = (ListSelectionEventRecordable) recordTokenizer
346: .next();
347:
348: boolean cond = true;
349: cond = cond && (mouseDrag != null);
350: cond = cond
351: && (mousePressed.getID() == MouseEvent.MOUSE_PRESSED)
352: && (mouseReleased.getID() == MouseEvent.MOUSE_RELEASED);
353: cond = cond && (list1 != null) && (list2 != null);
354:
355: if (cond) {
356: children = new StructureElement[5];
357:
358: int index = 0;
359: children[index++] = mousePressed;
360: children[index++] = mouseDrag;
361: children[index++] = list1;
362: children[index++] = mouseReleased;
363: children[index++] = list2;
364: } else {
365: throw new Exception();
366: }
367: } catch (Throwable t) {
368: recordTokenizer.restoreState(rtState);
369: }
370: }
371:
372: // Create the result;
373: if (children != null) {
374: result = new ListSelectionChange(env, children);
375: } else {
376: recordTokenizer.restoreState(rtState);
377: }
378:
379: return result;
380: }
381:
382: /**
383: * Returns the name of the element.
384: *
385: * @return the name
386: */
387: public String getElementName() {
388: return language
389: .getString("Structures.ListSelectionChange.Name");
390: }
391:
392: /**
393: * Returns a description of the element.
394: *
395: * @return the description
396: */
397: public String getElementDescription() {
398: return language
399: .getString("Structures.ListSelectionChange.Description");
400: }
401:
402: /**
403: * Returns a String which describes the content of the element shortly.
404: *
405: * @return a string with a short description of the element
406: */
407: public String toShortString() {
408: return getElementName();
409: }
410:
411: /**
412: * Clones the element.
413: *
414: * @return DOCUMENT ME!
415: */
416: public Object clone() {
417: StructureElement[] clonedChildren = getClonedChildren();
418:
419: return new ListSelectionChange(env, clonedChildren);
420: }
421: }
|