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