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: import java.util.Vector;
031:
032: /**
033: * Actions on a hypertext.
034: *
035: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
036: * @version 1.01
037: */
038: public class HypertextActions extends StructureElement {
039: /** The url. */
040: private String URL;
041:
042: /**
043: * Creates a new "hypertext actions" structure element. If one of its children is a hyperlink
044: * chosen element, the URL will be taken from it.
045: *
046: * @param env the environment
047: * @param children the child structure elements
048: */
049: public HypertextActions(Environment env, StructureElement[] children) {
050: super (env, children);
051: URL = env.getLanguage().getString(
052: "Structures.HypertextActions.UnknownURL");
053:
054: for (int i = 0; i < children.length; i++) {
055: if (children[i] instanceof HyperlinkChosen) {
056: URL = ((HyperlinkChosen) children[i]).getURL();
057:
058: break;
059: }
060: }
061: }
062:
063: /**
064: * Creates a new "hypertext actions" structure element.
065: *
066: * @param env the environment
067: * @param children the child structure elements
068: * @param URL the url of the hypertext, or <code>null</code> if there's no URL
069: */
070: public HypertextActions(Environment env,
071: StructureElement[] children, String URL) {
072: super (env, children);
073:
074: if (URL != null) {
075: this .URL = URL;
076: } else {
077: this .URL = env.getLanguage().getString(
078: "Structures.HypertextActions.UnknownURL");
079: }
080: }
081:
082: /**
083: * Parses a record which is tokenized by the given record tokenizer.
084: *
085: * @param env DOCUMENT ME!
086: * @param recordTokenizer the record tokenizer
087: *
088: * @return a structure element, or <code>null</code> if this class cannot parse the record at
089: * the current position
090: */
091: public static StructureElement parse(Environment env,
092: RecordTokenizer recordTokenizer) {
093: StructureElement result = null;
094: Vector addedChildren = new Vector(5, 5);
095: String URL = null;
096:
097: RecordTokenizerState rtState = recordTokenizer.saveState();
098:
099: HyperlinkChosen chosen = (HyperlinkChosen) HyperlinkChosen
100: .parse(env, recordTokenizer);
101:
102: if (chosen != null) {
103: addedChildren.add(chosen);
104: URL = chosen.getURL();
105: }
106:
107: try {
108: boolean elementFound = true;
109:
110: while (recordTokenizer.hasMore() && elementFound) {
111: elementFound = false;
112:
113: RecordTokenizerState beforeChosen = recordTokenizer
114: .saveState();
115: chosen = (HyperlinkChosen) HyperlinkChosen.parse(env,
116: recordTokenizer);
117:
118: if (chosen != null) {
119: recordTokenizer.restoreState(beforeChosen);
120:
121: break;
122: }
123:
124: StructureElement next = null;
125:
126: next = MouseExited.parse(env, recordTokenizer);
127:
128: if (next == null) {
129: next = MouseEntered.parse(env, recordTokenizer);
130: }
131:
132: if (next == null) {
133: next = ScrollBarDrag.parse(env, recordTokenizer);
134: }
135:
136: if (next == null) {
137: next = MouseMotionOverHyperlinks.parse(env,
138: recordTokenizer);
139: }
140:
141: if (next == null) {
142: next = MouseMotionOverHyperlink.parse(env,
143: recordTokenizer);
144: }
145:
146: if (next == null) {
147: next = MouseMotionOverComponents.parse(env,
148: recordTokenizer);
149: }
150:
151: if (next == null) {
152: next = MouseMotion.parse(env, recordTokenizer);
153: }
154:
155: if (next == null) {
156: next = MouseDrag.parse(env, recordTokenizer);
157: }
158:
159: if (next == null) {
160: next = MouseClick.parse(env, recordTokenizer);
161: }
162:
163: if (next == null) {
164: next = KeySequence.parse(env, recordTokenizer);
165: }
166:
167: if (next == null) {
168: next = WindowActivationChange.parse(env,
169: recordTokenizer);
170: }
171:
172: if (next != null) {
173: addedChildren.add(next);
174: elementFound = true;
175: }
176: }
177:
178: if (addedChildren.size() > 0) {
179: //result = new HypertextActions (env, vectorToArray (addedChildren));
180: result = new HypertextActions(env,
181: vectorToArray(addedChildren), URL);
182: } else {
183: throw new Exception();
184: }
185: } catch (Throwable t) {
186: recordTokenizer.restoreState(rtState);
187: }
188:
189: return result;
190: }
191:
192: /**
193: * Returns the name of the element.
194: *
195: * @return the name
196: */
197: public String getElementName() {
198: return language.getString("Structures.HypertextActions.Name");
199: }
200:
201: /**
202: * Returns a description of the element.
203: *
204: * @return the description
205: */
206: public String getElementDescription() {
207: return language
208: .getString("Structures.HypertextActions.Description");
209: }
210:
211: /**
212: * Returns a String which describes the content of the element shortly.
213: *
214: * @return a string with a short description of the element
215: */
216: public String toShortString() {
217: String insertedText = null;
218:
219: if (getURL().length() < 40) {
220: insertedText = getURL();
221: } else {
222: int length = getURL().length();
223: insertedText = getURL().substring(0, 9) + "..."
224: + getURL().substring(length - 28, length - 1);
225: }
226:
227: return getElementName() + " (" + insertedText + ")";
228: }
229:
230: /**
231: * Returns the URL.
232: *
233: * @return DOCUMENT ME!
234: */
235: public String getURL() {
236: return URL;
237: }
238:
239: /**
240: * Clones the element.
241: *
242: * @return DOCUMENT ME!
243: */
244: public Object clone() {
245: StructureElement[] clonedChildren = getClonedChildren();
246:
247: return new HypertextActions(env, clonedChildren, URL);
248: }
249:
250: public boolean hasProcTime() {
251: return true;
252: }
253: }
|