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