001: /*
002: * $Id: Timeline.java,v 1.3 2002/08/08 23:26:54 skavish Exp $
003: *
004: * ==========================================================================
005: *
006: * The JGenerator Software License, Version 1.0
007: *
008: * Copyright (c) 2000 Dmitry Skavish (skavish@usa.net). All rights reserved.
009: *
010: * Redistribution and use in source and binary forms, with or without
011: * modification, are permitted provided that the following conditions are met:
012: *
013: * 1. Redistributions of source code must retain the above copyright
014: * notice, this list of conditions and the following disclaimer.
015: *
016: * 2. Redistributions in binary form must reproduce the above copyright
017: * notice, this list of conditions and the following disclaimer in
018: * the documentation and/or other materials provided with the
019: * distribution.
020: *
021: * 3. The end-user documentation included with the redistribution, if
022: * any, must include the following acknowlegement:
023: * "This product includes software developed by Dmitry Skavish
024: * (skavish@usa.net, http://www.flashgap.com/)."
025: * Alternately, this acknowlegement may appear in the software itself,
026: * if and wherever such third-party acknowlegements normally appear.
027: *
028: * 4. The name "The JGenerator" must not be used to endorse or promote
029: * products derived from this software without prior written permission.
030: * For written permission, please contact skavish@usa.net.
031: *
032: * 5. Products derived from this software may not be called "The JGenerator"
033: * nor may "The JGenerator" appear in their names without prior written
034: * permission of Dmitry Skavish.
035: *
036: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
037: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
038: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
039: * DISCLAIMED. IN NO EVENT SHALL DMITRY SKAVISH OR THE OTHER
040: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047: * SUCH DAMAGE.
048: *
049: */
050:
051: package org.openlaszlo.iv.flash.api;
052:
053: import org.openlaszlo.iv.flash.util.*;
054: import org.openlaszlo.iv.flash.context.Context;
055: import java.io.*;
056: import java.util.*;
057: import java.awt.geom.*;
058:
059: /**
060: * Flash timeline
061: * <P>
062: * A timeline contains zero or more {@link Frame frames}
063: *
064: * @author Dmitry Skavish
065: * @see Frame
066: * @see Script
067: */
068: public final class Timeline extends IVVector {
069:
070: /**
071: * Creates empty timeline
072: */
073: public Timeline() {
074: }
075:
076: /**
077: * Creates empty timeline of specified capacity
078: */
079: public Timeline(int capacity) {
080: super (capacity);
081: }
082:
083: /**
084: * Creates timeline from specified vector
085: * <P>
086: * Copies all the frames from specified vector
087: *
088: * @param data vector of Frames
089: */
090: public Timeline(IVVector data) {
091: super (data);
092: }
093:
094: /**
095: * Creates new empty frame, adds it to the end of this timeline and returns it
096: *
097: * @return new frame
098: */
099: public Frame newFrame() {
100: Frame f = new Frame();
101: addFrame(f);
102: return f;
103: }
104:
105: /**
106: * Adds specified frame to the end of this timeline
107: *
108: * @param o frame to be added
109: */
110: public void addFrame(Frame o) {
111: addElement(o);
112: }
113:
114: /**
115: * Returns index of specified frame in the timeline or -1
116: *
117: * @param frame specified frame
118: * @return index of specified frame in the timeline or -1
119: */
120: public int getFrameIndex(Frame frame) {
121: return find(frame);
122: }
123:
124: /**
125: * Removes frame from this timeline at specified index
126: *
127: * @param index specified index
128: * @return removed frame
129: */
130: public Frame removeFrameAt(int index) {
131: return (Frame) removeElementAt(index);
132: }
133:
134: /**
135: * Removes specified frame from this timeline
136: *
137: * @param o frame to be removed
138: */
139: public void removeFrame(Frame o) {
140: removeElement(o);
141: }
142:
143: /**
144: * Returns frame from this timeline at specified index
145: *
146: * @param index specified index
147: * @return frame at specified index
148: */
149: public Frame getFrameAt(int index) {
150: return (Frame) elementAt(index);
151: }
152:
153: /**
154: * Replaces frame at specified index with specified one
155: *
156: * @param o specified frame
157: * @param index specified index
158: */
159: public void setFrameAt(Frame o, int index) {
160: setElementAt(o, index);
161: }
162:
163: /**
164: * Inserts specified number of empty frames
165: * <P>
166: * Beginning from frame number 'from' inserts 'num' empty frame in the timeline.
167: *
168: * @param from start inserting frames beginning from this one
169: * @param num number of empty frames to insert
170: */
171: public void insertFrames(int from, int num) {
172: insertObjects(from, num);
173: for (int i = from; i < from + num; i++) {
174: setFrameAt(new Frame(), i);
175: }
176: }
177:
178: /**
179: * Inserts one empty frame at specified index
180: *
181: * @param index specified index
182: * @return new inserted frame
183: */
184: public Frame insertFrame(int index) {
185: insertFrames(index, 1);
186: return getFrameAt(index);
187: }
188:
189: /**
190: * Returns number of frames in the timeline
191: *
192: * @return number of frames
193: */
194: public int getFrameCount() {
195: return size();
196: }
197:
198: /**
199: * Writes this timeline to flash buffer
200: * <P>
201: * Has to be used only when writing NON main timelines
202: *
203: * @param fob flash buffer to write to
204: */
205: public void write(FlashOutput fob) {
206: for (int i = 0; i < top; i++) {
207: Frame fo = (Frame) objects[i];
208: fo.write(fob);
209: }
210: }
211:
212: /**
213: * Writes this timeline to flash buffer
214: * <P>
215: * Has to be used only when writing main timeline
216: *
217: * @param fob flash buffer to write to
218: * @param dc dependencies collector used when writing
219: */
220: public void generate(FlashOutput fob, DepsCollector dc) {
221: generate(fob, dc, 0);
222: }
223:
224: /**
225: * Writes this timeline to flash buffer
226: * <P>
227: * Has to be used only when writing main timeline
228: *
229: * @param fob flash buffer to write to
230: * @param dc dependencies collector used when writing
231: * @param off frame offset to start from
232: */
233: public void generate(FlashOutput fob, DepsCollector dc, int off) {
234: for (int i = off; i < top; i++) {
235: Frame fo = (Frame) objects[i];
236: fo.generate(fob, dc);
237: }
238: }
239:
240: public void collectDeps(DepsCollector dc) {
241: for (int i = 0; i < top; i++) {
242: Frame fo = (Frame) objects[i];
243: fo.collectDeps(dc);
244: }
245: }
246:
247: public void apply(Context context) {
248: for (int i = 0; i < top; i++) {
249: Frame fo = (Frame) objects[i];
250: fo.apply(context);
251: }
252: }
253:
254: public void process(FlashFile file, Context context)
255: throws IVException {
256: for (int i = 0; i < top; i++) {
257: Frame fo = (Frame) objects[i];
258: fo.process(file, context);
259: }
260: }
261:
262: public void doCommand(FlashFile file, Context context, Script parent)
263: throws IVException {
264: for (int i = 0; i < top; i++) {
265: Frame fo = (Frame) objects[i];
266: fo.doCommand(file, context, parent, i);
267: }
268: }
269:
270: public void addBounds(Rectangle2D rect) {
271: for (int i = 0; i < top; i++) {
272: Frame fo = (Frame) objects[i];
273: fo.addBounds(rect);
274: }
275: }
276:
277: public boolean isConstant() {
278: for (int i = 0; i < top; i++) {
279: Frame fo = (Frame) objects[i];
280: if (!fo.isConstant())
281: return false;
282: }
283: return true;
284: }
285:
286: public void printContent(PrintStream out, String indent) {
287: for (int i = 0; i < top; i++) {
288: Frame fo = (Frame) objects[i];
289: out.print(indent + "Frame #" + i);
290: if (fo.getName() != null) {
291: out.println(" name='" + fo.getName() + "' "
292: + (fo.isAnchor() ? "anchor" : ""));
293: } else {
294: out.println();
295: }
296: fo.printContent(out, indent);
297: }
298: }
299:
300: public IVVector getCopy(ScriptCopier copier) {
301: Timeline t = new Timeline(size());
302: for (int i = 0; i < top; i++) {
303: Frame fo = (Frame) objects[i];
304: t.setElementAt(fo.getCopy(copier), i);
305: }
306: return t;
307: }
308: }
|