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.WindowEventRecordable;
029: import jacareto.system.Environment;
030:
031: import java.awt.event.WindowEvent;
032:
033: /**
034: * A window is closing. A structure element can parse a part of a record.
035: *
036: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
037: * @version 1.0
038: */
039: public class WindowClosing extends StructureElement {
040: /**
041: * Creates a new "window closing" structure element.
042: *
043: * @param env the environment
044: * @param children the child structure elements
045: */
046: public WindowClosing(Environment env, StructureElement[] children) {
047: super (env, children);
048: }
049:
050: /**
051: * Parses a record which is tokenized by the given record tokenizer.
052: *
053: * @param env DOCUMENT ME!
054: * @param recordTokenizer the record tokenizer
055: *
056: * @return a structure element, or <code>null</code> if this class cannot parse the record at
057: * the current position
058: */
059: public static StructureElement parse(Environment env,
060: RecordTokenizer recordTokenizer) {
061: StructureElement result = null;
062: StructureElement[] children = null;
063:
064: RecordTokenizerState rtState = recordTokenizer.saveState();
065:
066: try {
067: WindowEventRecordable closing = (WindowEventRecordable) recordTokenizer
068: .next();
069: WindowDeactivation deactivation = (WindowDeactivation) WindowDeactivation
070: .parse(env, recordTokenizer);
071:
072: if ((closing.getID() == WindowEvent.WINDOW_CLOSING)
073: && (deactivation != null)) {
074: children = new StructureElement[2];
075: children[0] = closing;
076: children[1] = deactivation;
077: result = new WindowClosing(env, children);
078: } else {
079: throw new Exception();
080: }
081: } catch (Throwable t) {
082: recordTokenizer.restoreState(rtState);
083: }
084:
085: return result;
086: }
087:
088: /**
089: * Returns the name of the element.
090: *
091: * @return the name
092: */
093: public String getElementName() {
094: return language.getString("Structures.WindowClosing.Name");
095: }
096:
097: /**
098: * Returns a description of the element.
099: *
100: * @return the description
101: */
102: public String getElementDescription() {
103: return language
104: .getString("Structures.WindowClosing.Description");
105: }
106:
107: /**
108: * Returns a String which describes the content of the element shortly.
109: *
110: * @return a string with a short description of the element
111: */
112: public String toShortString() {
113: return getElementName();
114: }
115:
116: /**
117: * Clones the element.
118: *
119: * @return DOCUMENT ME!
120: */
121: public Object clone() {
122: StructureElement[] clonedChildren = getClonedChildren();
123:
124: return new WindowClosing(env, clonedChildren);
125: }
126: }
|