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.record.MouseEventRecordable;
028: import jacareto.system.Environment;
029:
030: import java.awt.event.MouseEvent;
031:
032: /**
033: * This structure element stands for a mouse motion.
034: *
035: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
036: * @version 1.01
037: */
038: public class MouseMotion extends StructureElement {
039: /** The x coordinate of the motion start position. */
040: private int startX;
041:
042: /** the x coordinate of the motion stop position. */
043: private int stopX;
044:
045: /** The y coordinate of the motion start position. */
046: private int startY;
047:
048: /** the y coordinate of the motion stop position. */
049: private int stopY;
050:
051: /** The name of the source component. */
052: private String sourceName;
053:
054: /**
055: * Creates a new "mouse motion" structure element.
056: *
057: * @param env the environment
058: * @param children the child structure elements
059: */
060: public MouseMotion(Environment env, StructureElement[] children) {
061: super (env, children);
062:
063: MouseEventRecordable first = (MouseEventRecordable) children[0];
064: MouseEventRecordable last = (MouseEventRecordable) children[children.length - 1];
065: startX = first.getX();
066: startY = first.getY();
067: stopX = last.getX();
068: stopY = last.getY();
069: sourceName = first.getSourceName();
070: }
071:
072: /**
073: * Parses a record which is tokenized by the given record tokenizer.
074: *
075: * @param env DOCUMENT ME!
076: * @param recordTokenizer the record tokenizer
077: *
078: * @return a structure element, or <code>null</code> if this class cannot parse the record at
079: * the current position
080: */
081: public static StructureElement parse(Environment env,
082: RecordTokenizer recordTokenizer) {
083: int counter = 0;
084: StructureElement element;
085: StructureElement result = null;
086:
087: try {
088: do {
089: element = recordTokenizer.get(counter);
090: counter++;
091: } while (element instanceof MouseEventRecordable
092: && (((MouseEventRecordable) element).getID() == MouseEvent.MOUSE_MOVED));
093:
094: counter--;
095:
096: if (counter > 0) {
097: StructureElement[] children = new StructureElement[counter];
098:
099: for (int i = 0; i < counter; i++) {
100: children[i] = recordTokenizer.get(i);
101: }
102:
103: recordTokenizer.forward(counter);
104: result = new MouseMotion(env, children);
105: }
106: } catch (Exception e) {
107: ;
108: }
109:
110: return result;
111: }
112:
113: /**
114: * Returns the x-coordinate of the motion start position.
115: *
116: * @return DOCUMENT ME!
117: */
118: public int getStartX() {
119: return startX;
120: }
121:
122: /**
123: * Returns the y-coordinate of the motion start position.
124: *
125: * @return DOCUMENT ME!
126: */
127: public int getStartY() {
128: return startY;
129: }
130:
131: /**
132: * Returns the x-coordinate of the motion stop position.
133: *
134: * @return DOCUMENT ME!
135: */
136: public int getStopX() {
137: return stopX;
138: }
139:
140: /**
141: * Returns the y-coordinate of the motion stop position.
142: *
143: * @return DOCUMENT ME!
144: */
145: public int getStopY() {
146: return stopY;
147: }
148:
149: /**
150: * Returns the source name.
151: *
152: * @return DOCUMENT ME!
153: */
154: public String getSourceName() {
155: return sourceName;
156: }
157:
158: /**
159: * Returns the name of the element.
160: *
161: * @return the name
162: */
163: public String getElementName() {
164: return language.getString("Structures.MouseMotion.Name");
165: }
166:
167: /**
168: * Returns a description of the element.
169: *
170: * @return the description
171: */
172: public String getElementDescription() {
173: return language.getString("Structures.MouseMotion.Description");
174: }
175:
176: /**
177: * Returns a String which describes the content of the element shortly.
178: *
179: * @return a string with a short description of the element
180: */
181: public String toShortString() {
182: return getElementName() + " (" + startX + "," + startY
183: + ") -> (" + stopX + "," + stopY + ")";
184: }
185:
186: /**
187: * Clones the element.
188: *
189: * @return DOCUMENT ME!
190: */
191: public Object clone() {
192: StructureElement[] clonedChildren = getClonedChildren();
193:
194: return new MouseMotion(env, clonedChildren);
195: }
196: }
|