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.FocusEventRecordable;
028: import jacareto.record.Recordable;
029: import jacareto.record.WindowEventRecordable;
030: import jacareto.system.Environment;
031:
032: import java.awt.event.FocusEvent;
033: import java.awt.event.WindowEvent;
034:
035: /**
036: * A window has been activated . A structure element can parse a part of a record.
037: *
038: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
039: * @version 1.01
040: */
041: public class WindowActivation extends StructureElement {
042: /** The window name. */
043: private String windowName;
044:
045: /** The title of the window. */
046: private String windowTitle;
047:
048: /**
049: * Creates a new "window activation" structure element. The first element in the children array
050: * must be a window event recordable with the id WINDOW_ACTIVATED.
051: *
052: * @param env the environment
053: * @param children the child structure elements
054: */
055: public WindowActivation(Environment env, StructureElement[] children) {
056: super (env, children);
057: this .windowName = ((WindowEventRecordable) children[0])
058: .getWindowName();
059: this .windowTitle = ((WindowEventRecordable) children[0])
060: .getWindowTitle();
061: }
062:
063: /**
064: * Creates a new "window activation" structure element.
065: *
066: * @param env the environment
067: * @param children the child structure elements
068: * @param windowName the name of the window
069: * @param windowTitle the title of the window
070: */
071: public WindowActivation(Environment env,
072: StructureElement[] children, String windowName,
073: String windowTitle) {
074: super (env, children);
075: this .windowName = windowName;
076: this .windowTitle = windowTitle;
077: }
078:
079: /**
080: * Parses a record which is tokenized by the given record tokenizer.
081: *
082: * @param env DOCUMENT ME!
083: * @param recordTokenizer the record tokenizer
084: *
085: * @return a structure element, or <code>null</code> if this class cannot parse the record at
086: * the current position
087: */
088: public static StructureElement parse(Environment env,
089: RecordTokenizer recordTokenizer) {
090: StructureElement result = null;
091: StructureElement[] children = null;
092: boolean cond;
093:
094: try {
095: WindowEventRecordable first = (WindowEventRecordable) recordTokenizer
096: .get();
097: FocusEventRecordable second = (FocusEventRecordable) recordTokenizer
098: .get(1);
099:
100: Recordable third = recordTokenizer.get(2);
101:
102: cond = true;
103: cond = cond
104: && (first.getID() == WindowEvent.WINDOW_ACTIVATED);
105: cond = cond && (second.getID() == FocusEvent.FOCUS_GAINED);
106:
107: if (cond) {
108: if ((third != null)
109: && third instanceof WindowEventRecordable
110: && (((WindowEventRecordable) third).getID() == WindowEvent.WINDOW_ACTIVATED)
111: && ((WindowEventRecordable) third)
112: .getSourceName().equals(
113: first.getSourceName())) {
114: children = new StructureElement[3];
115: children[2] = third;
116: recordTokenizer.forward(3);
117: } else {
118: children = new StructureElement[2];
119: recordTokenizer.forward(2);
120: }
121:
122: children[0] = first;
123: children[1] = second;
124:
125: //result = new WindowActivation (env, children);
126: result = new WindowActivation(env, children, first
127: .getWindowName(), first.getWindowTitle());
128: }
129: } catch (Throwable t) {
130: ;
131: }
132:
133: if (result == null) {
134: try {
135: WindowEventRecordable windowEvent = (WindowEventRecordable) recordTokenizer
136: .get();
137:
138: if (windowEvent.getID() == WindowEvent.WINDOW_ACTIVATED) {
139: children = new StructureElement[1];
140: children[0] = windowEvent;
141: recordTokenizer.forward();
142:
143: //result = new WindowActivation (env, children);
144: result = new WindowActivation(env, children,
145: windowEvent.getWindowName(), windowEvent
146: .getWindowTitle());
147: }
148: } catch (Exception e) {
149: ;
150: }
151: }
152:
153: return result;
154: }
155:
156: /**
157: * Returns the name of the element.
158: *
159: * @return the name
160: */
161: public String getElementName() {
162: return language.getString("Structures.WindowActivation.Name");
163: }
164:
165: /**
166: * Returns a description of the element.
167: *
168: * @return the description
169: */
170: public String getElementDescription() {
171: return language
172: .getString("Structures.WindowActivation.Description");
173: }
174:
175: /**
176: * Returns a String which describes the content of the element shortly.
177: *
178: * @return a string with a short description of the element
179: */
180: public String toShortString() {
181: String result = getElementName();
182:
183: if (windowName != null) {
184: String windowIdentifier = (((windowTitle == null) || windowTitle
185: .equals("")) ? windowName : windowTitle);
186: String insertedText = ((windowIdentifier.length() < 40) ? windowIdentifier
187: : (windowIdentifier.substring(0, 37) + "..."));
188: result += (" (" + insertedText + ")");
189: }
190:
191: return result;
192: }
193:
194: /**
195: * The name of the activated window.
196: *
197: * @return DOCUMENT ME!
198: */
199: public String getWindowName() {
200: return windowName;
201: }
202:
203: /**
204: * The title of the activated window.
205: *
206: * @return DOCUMENT ME!
207: */
208: public String getWindowTitle() {
209: return windowTitle;
210: }
211:
212: /**
213: * Clones the element.
214: *
215: * @return DOCUMENT ME!
216: */
217: public Object clone() {
218: StructureElement[] clonedChildren = getClonedChildren();
219:
220: return new WindowActivation(env, clonedChildren, windowName,
221: windowTitle);
222: }
223: }
|