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.MouseEventRecordable;
029: import jacareto.system.Environment;
030:
031: import java.awt.event.MouseEvent;
032:
033: import java.util.Vector;
034:
035: /**
036: * The menu has been opened and closed without selecting a menu item.
037: *
038: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
039: * @version 1.0
040: */
041: public class MenuOpenedAndClosed extends StructureElement {
042: /**
043: * Creates a new "menu opened and closed" structure element.
044: *
045: * @param env the environment
046: * @param children the child structure elements
047: */
048: public MenuOpenedAndClosed(Environment env,
049: StructureElement[] children) {
050: super (env, children);
051: }
052:
053: /**
054: * Parses a record which is tokenized by the given record tokenizer.
055: *
056: * @param env DOCUMENT ME!
057: * @param recordTokenizer the record tokenizer
058: *
059: * @return a structure element, or <code>null</code> if this class cannot parse the record at
060: * the current position
061: */
062: public static StructureElement parse(Environment env,
063: RecordTokenizer recordTokenizer) {
064: StructureElement result = null;
065: Vector addedChildren = null;
066:
067: RecordTokenizerState rtState = recordTokenizer.saveState();
068:
069: // Menu Opened
070: // Mouse Motion over Components
071: // mouse pressed
072: // focus change
073: // Item State Change
074: // mouse released
075: // mouse clicked
076: try {
077: MenuOpened menuOpened = (MenuOpened) MenuOpened.parse(env,
078: recordTokenizer);
079:
080: if (menuOpened == null) {
081: throw new Exception();
082: }
083:
084: MouseMotionOverComponents motion = (MouseMotionOverComponents) MouseMotionOverComponents
085: .parse(env, recordTokenizer);
086:
087: if (motion == null) {
088: throw new Exception();
089: }
090:
091: MouseEventRecordable mousePressed = (MouseEventRecordable) recordTokenizer
092: .next();
093:
094: if (mousePressed == null) {
095: throw new Exception();
096: }
097:
098: FocusChange focusChange = (FocusChange) FocusChange.parse(
099: env, recordTokenizer);
100:
101: if (focusChange == null) {
102: throw new Exception();
103: }
104:
105: ItemStateChange item = (ItemStateChange) ItemStateChange
106: .parse(env, recordTokenizer);
107:
108: if (item == null) {
109: throw new Exception();
110: }
111:
112: MouseEventRecordable mouseReleased = (MouseEventRecordable) recordTokenizer
113: .next();
114:
115: if (mouseReleased == null) {
116: throw new Exception();
117: }
118:
119: MouseEventRecordable mouseClicked = (MouseEventRecordable) recordTokenizer
120: .next();
121:
122: if (mouseClicked == null) {
123: throw new Exception();
124: }
125:
126: boolean cond = item.getSourceClass().equals(
127: "javax.swing.JMenu");
128: cond = cond && !item.isSelected();
129: cond = cond
130: && (mousePressed.getID() == MouseEvent.MOUSE_PRESSED)
131: && (mouseReleased.getID() == MouseEvent.MOUSE_RELEASED)
132: && (mouseClicked.getID() == MouseEvent.MOUSE_CLICKED);
133:
134: if (cond) {
135: StructureElement[] mouseChildren = new StructureElement[3];
136: mouseChildren[0] = mousePressed;
137: mouseChildren[1] = mouseReleased;
138: mouseChildren[2] = mouseClicked;
139:
140: MouseClick mouseClick = new MouseClick(env,
141: mouseChildren);
142:
143: addedChildren = new Vector(10);
144: addedChildren.add(menuOpened);
145: addedChildren.add(motion);
146: addedChildren.add(mouseClick);
147: addedChildren.add(focusChange);
148: addedChildren.add(item);
149: result = new MenuOpenedAndClosed(env,
150: vectorToArray(addedChildren));
151: } else {
152: throw new Exception();
153: }
154: } catch (Exception e) {
155: recordTokenizer.restoreState(rtState);
156: }
157:
158: // menu opened, (mouse motion over comp | key sequence )*, item deselected
159: if (result == null) {
160: try {
161: MenuOpened menuOpened = (MenuOpened) MenuOpened.parse(
162: env, recordTokenizer);
163:
164: if (menuOpened == null) {
165: throw new Exception();
166: }
167:
168: addedChildren = new Vector(10, 10);
169: addedChildren.add(menuOpened);
170:
171: StructureElement motion = null;
172:
173: do {
174: motion = MouseMotionOverComponents.parse(env,
175: recordTokenizer);
176:
177: if (motion == null) {
178: motion = KeySequence
179: .parse(env, recordTokenizer);
180: }
181:
182: if (motion == null) {
183: motion = MouseEntered.parse(env,
184: recordTokenizer);
185: }
186:
187: if (motion == null) {
188: motion = MouseMotion
189: .parse(env, recordTokenizer);
190: }
191:
192: if (motion != null) {
193: addedChildren.add(motion);
194: }
195: } while (motion != null);
196:
197: ItemStateChange item = (ItemStateChange) ItemStateChange
198: .parse(env, recordTokenizer);
199:
200: if (item == null) {
201: throw new Exception();
202: }
203:
204: addedChildren.add(item);
205:
206: boolean cond = item.getSourceClass().equals(
207: "javax.swing.JMenu");
208: cond = cond && !item.isSelected();
209:
210: if (cond) {
211: result = new MenuOpenedAndClosed(env,
212: vectorToArray(addedChildren));
213: } else {
214: throw new Exception();
215: }
216: } catch (Exception e) {
217: recordTokenizer.restoreState(rtState);
218: }
219: }
220:
221: return result;
222: }
223:
224: /**
225: * Returns the name of the element.
226: *
227: * @return the name
228: */
229: public String getElementName() {
230: return language
231: .getString("Structures.MenuOpenedAndClosed.Name");
232: }
233:
234: /**
235: * Returns a description of the element.
236: *
237: * @return the description
238: */
239: public String getElementDescription() {
240: return language
241: .getString("Structures.MenuOpenedAndClosed.Description");
242: }
243:
244: /**
245: * Returns a String which describes the content of the element shortly.
246: *
247: * @return a string with a short description of the element
248: */
249: public String toShortString() {
250: return getElementName();
251: }
252:
253: /**
254: * Clones the element.
255: *
256: * @return DOCUMENT ME!
257: */
258: public Object clone() {
259: StructureElement[] clonedChildren = getClonedChildren();
260:
261: return new MenuOpenedAndClosed(env, clonedChildren);
262: }
263: }
|