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.system.Environment;
029:
030: import java.util.Vector;
031:
032: /**
033: * The mouse pointer has been moved over more than one component. A structure element can parse a
034: * part of a record.
035: *
036: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
037: * @version 1.0
038: */
039: public class MouseMotionOverComponents extends StructureElement {
040: /**
041: * Creates a new "mouse motion over components" structure element.
042: *
043: * @param env the environment
044: * @param children the child structure elements
045: */
046: public MouseMotionOverComponents(Environment env,
047: StructureElement[] children) {
048: super (env, children);
049: }
050:
051: /**
052: * Parses a record which is tokenized by the given record tokenizer.
053: *
054: * @param env DOCUMENT ME!
055: * @param recordTokenizer the record tokenizer
056: *
057: * @return a structure element, or <code>null</code> if this class cannot parse the record at
058: * the current position
059: */
060: public static StructureElement parse(Environment env,
061: RecordTokenizer recordTokenizer) {
062: StructureElement result = null;
063: Vector addedChildren = new Vector(5, 5);
064:
065: RecordTokenizerState rtState = recordTokenizer.saveState();
066:
067: try {
068: StructureElement motion;
069: StructureElement changed;
070: StructureElement entered;
071: StructureElement exited;
072:
073: int motionCounter = 0;
074: int changedCounter = 0;
075: int enteredExitedCounter = 0;
076:
077: do {
078: motion = null;
079: changed = null;
080: entered = null;
081: exited = null;
082:
083: motion = MouseMotion.parse(env, recordTokenizer);
084:
085: if (motion != null) {
086: addedChildren.add(motion);
087: motionCounter++;
088: }
089:
090: changed = MouseChangedComponent.parse(env,
091: recordTokenizer);
092:
093: if (changed != null) {
094: addedChildren.add(changed);
095: changedCounter++;
096: }
097:
098: entered = MouseEntered.parse(env, recordTokenizer);
099:
100: if (entered != null) {
101: addedChildren.add(entered);
102: enteredExitedCounter++;
103: }
104:
105: exited = MouseExited.parse(env, recordTokenizer);
106:
107: if (exited != null) {
108: addedChildren.add(exited);
109: enteredExitedCounter++;
110: }
111: } while ((motion != null) || (changed != null)
112: || (entered != null));
113:
114: if ((motionCounter > 0)
115: && ((changedCounter > 0) || (enteredExitedCounter > 1))) {
116: StructureElement[] children = vectorToArray(addedChildren);
117: result = new MouseMotionOverComponents(env, children);
118: } else {
119: recordTokenizer.restoreState(rtState);
120: }
121: } catch (Throwable t) {
122: recordTokenizer.restoreState(rtState);
123: }
124:
125: return result;
126: }
127:
128: /**
129: * Returns the name of the element.
130: *
131: * @return the name
132: */
133: public String getElementName() {
134: return language
135: .getString("Structures.MouseMotionOverComponents.Name");
136: }
137:
138: /**
139: * Returns a description of the element.
140: *
141: * @return the description
142: */
143: public String getElementDescription() {
144: return language
145: .getString("Structures.MouseMotionOverComponents.Description");
146: }
147:
148: /**
149: * Returns a String which describes the content of the element shortly.
150: *
151: * @return a string with a short description of the element
152: */
153: public String toShortString() {
154: return getElementName();
155: }
156:
157: /**
158: * Clones the element.
159: *
160: * @return DOCUMENT ME!
161: */
162: public Object clone() {
163: StructureElement[] clonedChildren = getClonedChildren();
164:
165: return new MouseMotionOverComponents(env, clonedChildren);
166: }
167: }
|