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.record.WindowEventRecordable;
030: import jacareto.system.Environment;
031:
032: import java.awt.event.MouseEvent;
033: import java.awt.event.WindowEvent;
034:
035: /**
036: * This structure element stands for a "popup menu opened" structure element.
037: *
038: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
039: * @version 1.0
040: */
041: public class PopupMenuOpened extends StructureElement {
042: /**
043: * Creates a new "popup menu opened" structure element.
044: *
045: * @param env the environment
046: * @param children the child structure elements
047: */
048: public PopupMenuOpened(Environment env, 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:
065: RecordTokenizerState rtState = recordTokenizer.saveState();
066:
067: try {
068: MousePressedReleased mpar = (MousePressedReleased) MousePressedReleased
069: .parse(env, recordTokenizer);
070:
071: if (mpar == null) {
072: throw new Exception();
073: }
074:
075: MouseChangedComponent change = null;
076: MouseEntered mouseEntered = (MouseEntered) MouseEntered
077: .parse(env, recordTokenizer);
078:
079: if (mouseEntered == null) {
080: change = (MouseChangedComponent) MouseChangedComponent
081: .parse(env, recordTokenizer);
082:
083: if (change == null) {
084: throw new Exception();
085: }
086: }
087:
088: MouseEventRecordable mouseClicked = (MouseEventRecordable) recordTokenizer
089: .get(0);
090:
091: if ((mouseClicked != null)
092: && (mouseClicked.getID() == MouseEvent.MOUSE_CLICKED)) {
093: recordTokenizer.forward();
094: } else {
095: throw new Exception();
096: }
097:
098: MouseMotionOverComponents motion = (MouseMotionOverComponents) MouseMotionOverComponents
099: .parse(env, recordTokenizer);
100:
101: if (motion == null) {
102: throw new Exception();
103: }
104:
105: WindowEventRecordable opened = (WindowEventRecordable) recordTokenizer
106: .get(0);
107:
108: if ((opened != null)
109: && (opened.getID() == WindowEvent.WINDOW_OPENED)
110: && opened
111: .getSourceClass()
112: .equals(
113: "com.sun.java.swing.plaf.windows.WindowsPopupWindow")) {
114: recordTokenizer.forward();
115: } else {
116: throw new Exception();
117: }
118:
119: StructureElement[] children = new StructureElement[4];
120:
121: // mouse clicked children
122: StructureElement[] mparChildren = mpar.getChildren();
123: StructureElement[] clickedChildren = new StructureElement[3];
124: clickedChildren[0] = mparChildren[0];
125: clickedChildren[1] = mparChildren[1];
126: clickedChildren[2] = mouseClicked;
127:
128: children[0] = new MouseClick(env, clickedChildren);
129:
130: if (mouseEntered != null) {
131: children[1] = mouseEntered;
132: } else {
133: children[1] = change;
134: }
135:
136: children[2] = motion;
137: children[3] = opened;
138: result = new PopupMenuOpened(env, children);
139: } catch (Throwable t) {
140: recordTokenizer.restoreState(rtState);
141: }
142:
143: // mouse drag
144: // mouse changed component || mouse motion over components
145: // window opened
146: if (result == null) {
147: try {
148: MouseDrag drag = (MouseDrag) MouseDrag.parse(env,
149: recordTokenizer);
150:
151: if (drag == null) {
152: throw new Exception();
153: }
154:
155: MouseChangedComponent change = null;
156: MouseMotionOverComponents motion = (MouseMotionOverComponents) MouseMotionOverComponents
157: .parse(env, recordTokenizer);
158:
159: if (motion == null) {
160: change = (MouseChangedComponent) MouseChangedComponent
161: .parse(env, recordTokenizer);
162:
163: if (change == null) {
164: throw new Exception();
165: }
166: }
167:
168: WindowEventRecordable opened = (WindowEventRecordable) recordTokenizer
169: .get(0);
170:
171: if ((opened != null)
172: && (opened.getID() == WindowEvent.WINDOW_OPENED)
173: && opened
174: .getSourceClass()
175: .equals(
176: "com.sun.java.swing.plaf.windows.WindowsPopupWindow")) {
177: recordTokenizer.forward();
178: } else {
179: throw new Exception();
180: }
181:
182: StructureElement[] children = new StructureElement[3];
183:
184: children[0] = drag;
185:
186: if (change != null) {
187: children[1] = change;
188: } else {
189: children[1] = motion;
190: }
191:
192: children[2] = opened;
193: result = new PopupMenuOpened(env, children);
194: } catch (Throwable t) {
195: recordTokenizer.restoreState(rtState);
196: }
197: }
198:
199: return result;
200: }
201:
202: /**
203: * Returns the name of the element.
204: *
205: * @return the name
206: */
207: public String getElementName() {
208: return language.getString("Structures.PopupMenuOpened.Name");
209: }
210:
211: /**
212: * Returns a description of the element.
213: *
214: * @return the description
215: */
216: public String getElementDescription() {
217: return language
218: .getString("Structures.PopupMenuOpened.Description");
219: }
220:
221: /**
222: * Returns a String which describes the content of the element shortly.
223: *
224: * @return a string with a short description of the element
225: */
226: public String toShortString() {
227: return getElementName();
228: }
229:
230: /**
231: * Clones the element.
232: *
233: * @return DOCUMENT ME!
234: */
235: public Object clone() {
236: StructureElement[] clonedChildren = getClonedChildren();
237:
238: return new PopupMenuOpened(env, clonedChildren);
239: }
240: }
|