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.ChangeEventRecordable;
029: import jacareto.record.MouseEventRecordable;
030: import jacareto.system.Environment;
031: import jacareto.toolkit.StringToolkit;
032:
033: import java.awt.event.MouseEvent;
034:
035: /**
036: * This structure element stands for a "tab change".
037: *
038: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
039: * @version 1.0
040: */
041: public class TabChange extends StructureElement {
042: /** The tab info. */
043: private String tabInfo;
044:
045: /**
046: * Creates a new "tab change" structure element.
047: *
048: * @param env the environment
049: * @param children the child structure elements
050: */
051: public TabChange(Environment env, StructureElement[] children) {
052: super (env, children);
053:
054: StructureElement[] changeEventChildren = getChildren("jacareto.record.ChangeEventRecordable");
055:
056: if (changeEventChildren.length > 0) {
057: tabInfo = ((ChangeEventRecordable) changeEventChildren[0])
058: .getAdditionalInformation();
059: }
060: }
061:
062: /**
063: * Parses a record which is tokenized by the given record tokenizer.
064: *
065: * @param env DOCUMENT ME!
066: * @param recordTokenizer the record tokenizer
067: *
068: * @return a structure element, or <code>null</code> if this class cannot parse the record at
069: * the current position
070: */
071: public static StructureElement parse(Environment env,
072: RecordTokenizer recordTokenizer) {
073: StructureElement result = null;
074:
075: RecordTokenizerState rtState = recordTokenizer.saveState();
076:
077: // mouse pressed, change event, (focus change) mouse released, mouse clicked
078: try {
079: MouseEventRecordable mousePressed = (MouseEventRecordable) recordTokenizer
080: .next();
081: ChangeEventRecordable changeEvent = (ChangeEventRecordable) recordTokenizer
082: .next();
083: FocusChange focusChange = (FocusChange) FocusChange.parse(
084: env, recordTokenizer);
085: MouseEventRecordable mouseReleased = (MouseEventRecordable) recordTokenizer
086: .next();
087: MouseEventRecordable mouseClicked = (MouseEventRecordable) recordTokenizer
088: .next();
089:
090: boolean cond = (mousePressed.getID() == MouseEvent.MOUSE_PRESSED)
091: && (mouseReleased.getID() == MouseEvent.MOUSE_RELEASED)
092: && (mouseClicked.getID() == MouseEvent.MOUSE_CLICKED)
093: && changeEvent.getSourceClass().equals(
094: "javax.swing.JTabbedPane");
095:
096: if (cond) {
097: StructureElement[] mouseChildren = new StructureElement[3];
098: mouseChildren[0] = mousePressed;
099: mouseChildren[1] = mouseReleased;
100: mouseChildren[2] = mouseClicked;
101:
102: MouseClick mouseClick = new MouseClick(env,
103: mouseChildren);
104: StructureElement[] children = null;
105:
106: if (focusChange != null) {
107: children = new StructureElement[3];
108: children[1] = focusChange;
109: } else {
110: children = new StructureElement[2];
111: }
112:
113: children[0] = mouseClick;
114: children[children.length - 1] = changeEvent;
115: result = new TabChange(env, children);
116: } else {
117: throw new Exception();
118: }
119: } catch (Exception e) {
120: recordTokenizer.restoreState(rtState);
121: }
122:
123: // mouse pressed, change event, mouse drag, mouse released
124: if (result == null) {
125: try {
126: MouseEventRecordable mousePressed = (MouseEventRecordable) recordTokenizer
127: .next();
128: ChangeEventRecordable changeEvent = (ChangeEventRecordable) recordTokenizer
129: .next();
130: MouseDrag mouseDrag = (MouseDrag) MouseDrag.parse(env,
131: recordTokenizer);
132: MouseEventRecordable mouseReleased = (MouseEventRecordable) recordTokenizer
133: .next();
134:
135: boolean cond = (mousePressed.getID() == MouseEvent.MOUSE_PRESSED)
136: && (mouseReleased.getID() == MouseEvent.MOUSE_RELEASED)
137: && (mouseDrag != null)
138: && changeEvent.getSourceClass().equals(
139: "javax.swing.JTabbedPane");
140:
141: if (cond) {
142: StructureElement[] children = new StructureElement[4];
143: children[0] = mousePressed;
144: children[1] = changeEvent;
145: children[2] = mouseDrag;
146: children[3] = mouseReleased;
147: result = new TabChange(env, children);
148: } else {
149: throw new Exception();
150: }
151: } catch (Exception e) {
152: recordTokenizer.restoreState(rtState);
153: }
154: }
155:
156: return result;
157: }
158:
159: /**
160: * Returns the name of the element.
161: *
162: * @return the name
163: */
164: public String getElementName() {
165: return language.getString("Structures.TabChange.Name");
166: }
167:
168: /**
169: * Returns a description of the element.
170: *
171: * @return the description
172: */
173: public String getElementDescription() {
174: return language.getString("Structures.TabChange.Description");
175: }
176:
177: /**
178: * Returns a String which describes the content of the element shortly.
179: *
180: * @return a string with a short description of the element
181: */
182: public String toShortString() {
183: String result = getElementName();
184:
185: if (StringToolkit.isDefined(tabInfo)) {
186: result += (" (" + tabInfo + ")");
187: }
188:
189: return result;
190: }
191:
192: /**
193: * Clones the element.
194: *
195: * @return DOCUMENT ME!
196: */
197: public Object clone() {
198: StructureElement[] clonedChildren = getClonedChildren();
199:
200: return new TabChange(env, clonedChildren);
201: }
202: }
|