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 entered" structure element.
034: *
035: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
036: * @version 1.01
037: */
038: public class MouseEntered extends StructureElement {
039: /** The name of the component which has been entered. */
040: private String componentName;
041:
042: /**
043: * Creates a new "mouse entered" structure element. The last child must be the mouse entered
044: * event recordable
045: *
046: * @param env the environment
047: * @param children the child structure elements
048: */
049: public MouseEntered(Environment env, StructureElement[] children) {
050: super (env, children);
051: this .componentName = ((MouseEventRecordable) children[children.length - 1])
052: .getSourceName();
053: }
054:
055: /**
056: * Creates a new "mouse entered" structure element.
057: *
058: * @param env the environment
059: * @param children the child structure elements
060: * @param componentName DOCUMENT ME!
061: */
062: public MouseEntered(Environment env, StructureElement[] children,
063: String componentName) {
064: super (env, children);
065: this .componentName = componentName;
066: }
067:
068: /**
069: * Parses a record which is tokenized by the given record tokenizer.
070: *
071: * @param env Environment
072: * @param recordTokenizer the record tokenizer
073: *
074: * @return a structure element, or <code>null</code> if this class cannot parse the record at
075: * the current position
076: */
077: public static StructureElement parse(Environment env,
078: RecordTokenizer recordTokenizer) {
079: int counter = 0;
080: StructureElement element;
081:
082: do {
083: element = recordTokenizer.get(counter);
084: counter++;
085: } while (element instanceof MouseEventRecordable
086: && (((MouseEventRecordable) element).getID() == MouseEvent.MOUSE_ENTERED));
087:
088: // one too far
089: counter--;
090:
091: if (counter > 0) {
092: StructureElement[] children = new StructureElement[counter];
093:
094: for (int i = 0; i < counter; i++) {
095: children[i] = recordTokenizer.get(i);
096: }
097:
098: recordTokenizer.forward(counter);
099:
100: String componentName = ((MouseEventRecordable) children[children.length - 1])
101: .getSourceName();
102:
103: //return new MouseEntered (env, children);
104: return new MouseEntered(env, children, componentName);
105: } else {
106: return null;
107: }
108: }
109:
110: /**
111: * Returns the name of the element.
112: *
113: * @return the name
114: */
115: public String getElementName() {
116: return language.getString("Structures.MouseEntered.Name");
117: }
118:
119: /**
120: * Returns a description of the element.
121: *
122: * @return the description
123: */
124: public String getElementDescription() {
125: return language
126: .getString("Structures.MouseEntered.Description");
127: }
128:
129: /**
130: * Returns a String which describes the content of the element shortly.
131: *
132: * @return a string with a short description of the element
133: */
134: public String toShortString() {
135: return getElementName();
136: }
137:
138: /**
139: * Returns the name of the component which has been entered.
140: *
141: * @return DOCUMENT ME!
142: */
143: public String getComponentName() {
144: return componentName;
145: }
146:
147: /**
148: * Clones the element.
149: *
150: * @return DOCUMENT ME!
151: */
152: public Object clone() {
153: StructureElement[] clonedChildren = getClonedChildren();
154:
155: return new MouseEntered(env, clonedChildren, componentName);
156: }
157: }
|