KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openlaszlo > iv > flash > api > Timeline


1 /*
2  * $Id: Timeline.java,v 1.3 2002/08/08 23:26:54 skavish Exp $
3  *
4  * ==========================================================================
5  *
6  * The JGenerator Software License, Version 1.0
7  *
8  * Copyright (c) 2000 Dmitry Skavish (skavish@usa.net). All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in
18  * the documentation and/or other materials provided with the
19  * distribution.
20  *
21  * 3. The end-user documentation included with the redistribution, if
22  * any, must include the following acknowlegement:
23  * "This product includes software developed by Dmitry Skavish
24  * (skavish@usa.net, http://www.flashgap.com/)."
25  * Alternately, this acknowlegement may appear in the software itself,
26  * if and wherever such third-party acknowlegements normally appear.
27  *
28  * 4. The name "The JGenerator" must not be used to endorse or promote
29  * products derived from this software without prior written permission.
30  * For written permission, please contact skavish@usa.net.
31  *
32  * 5. Products derived from this software may not be called "The JGenerator"
33  * nor may "The JGenerator" appear in their names without prior written
34  * permission of Dmitry Skavish.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL DMITRY SKAVISH OR THE OTHER
40  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  *
49  */

50
51 package org.openlaszlo.iv.flash.api;
52
53 import org.openlaszlo.iv.flash.util.*;
54 import org.openlaszlo.iv.flash.context.Context;
55 import java.io.*;
56 import java.util.*;
57 import java.awt.geom.*;
58
59 /**
60  * Flash timeline
61  * <P>
62  * A timeline contains zero or more {@link Frame frames}
63  *
64  * @author Dmitry Skavish
65  * @see Frame
66  * @see Script
67  */

68 public final class Timeline extends IVVector {
69
70     /**
71      * Creates empty timeline
72      */

73     public Timeline() {}
74
75     /**
76      * Creates empty timeline of specified capacity
77      */

78     public Timeline( int capacity ) {
79         super( capacity );
80     }
81
82     /**
83      * Creates timeline from specified vector
84      * <P>
85      * Copies all the frames from specified vector
86      *
87      * @param data vector of Frames
88      */

89     public Timeline( IVVector data ) {
90         super( data );
91     }
92
93     /**
94      * Creates new empty frame, adds it to the end of this timeline and returns it
95      *
96      * @return new frame
97      */

98     public Frame newFrame() {
99         Frame f = new Frame();
100         addFrame(f);
101         return f;
102     }
103
104     /**
105      * Adds specified frame to the end of this timeline
106      *
107      * @param o frame to be added
108      */

109     public void addFrame( Frame o ) {
110         addElement( o );
111     }
112
113     /**
114      * Returns index of specified frame in the timeline or -1
115      *
116      * @param frame specified frame
117      * @return index of specified frame in the timeline or -1
118      */

119     public int getFrameIndex( Frame frame ) {
120         return find(frame);
121     }
122
123     /**
124      * Removes frame from this timeline at specified index
125      *
126      * @param index specified index
127      * @return removed frame
128      */

129     public Frame removeFrameAt( int index ) {
130         return (Frame) removeElementAt( index );
131     }
132
133     /**
134      * Removes specified frame from this timeline
135      *
136      * @param o frame to be removed
137      */

138     public void removeFrame( Frame o ) {
139         removeElement( o );
140     }
141
142     /**
143      * Returns frame from this timeline at specified index
144      *
145      * @param index specified index
146      * @return frame at specified index
147      */

148     public Frame getFrameAt( int index ) {
149         return (Frame) elementAt( index );
150     }
151
152     /**
153      * Replaces frame at specified index with specified one
154      *
155      * @param o specified frame
156      * @param index specified index
157      */

158     public void setFrameAt( Frame o, int index ) {
159         setElementAt( o , index );
160     }
161
162     /**
163      * Inserts specified number of empty frames
164      * <P>
165      * Beginning from frame number 'from' inserts 'num' empty frame in the timeline.
166      *
167      * @param from start inserting frames beginning from this one
168      * @param num number of empty frames to insert
169      */

170     public void insertFrames( int from, int num ) {
171         insertObjects( from, num );
172         for( int i=from; i<from+num; i++ ) {
173             setFrameAt( new Frame(), i );
174         }
175     }
176
177     /**
178      * Inserts one empty frame at specified index
179      *
180      * @param index specified index
181      * @return new inserted frame
182      */

183     public Frame insertFrame( int index ) {
184         insertFrames( index, 1 );
185         return getFrameAt(index);
186     }
187
188     /**
189      * Returns number of frames in the timeline
190      *
191      * @return number of frames
192      */

193     public int getFrameCount() {
194         return size();
195     }
196
197     /**
198      * Writes this timeline to flash buffer
199      * <P>
200      * Has to be used only when writing NON main timelines
201      *
202      * @param fob flash buffer to write to
203      */

204     public void write( FlashOutput fob ) {
205         for( int i=0; i<top; i++ ) {
206             Frame fo = (Frame) objects[i];
207             fo.write(fob);
208         }
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
241     public void collectDeps( DepsCollector dc ) {
242         for( int i=0; i<top; i++ ) {
243             Frame fo = (Frame) objects[i];
244             fo.collectDeps(dc);
245         }
246     }
247
248     public void apply( Context context ) {
249         for( int i=0; i<top; i++ ) {
250             Frame fo = (Frame) objects[i];
251             fo.apply(context);
252         }
253     }
254
255     public void process( FlashFile file, Context context ) 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 ) throws IVException {
263         for( int i=0; i<top; i++ ) {
264             Frame fo = (Frame) objects[i];
265             fo.doCommand(file, context, parent, i);
266         }
267     }
268
269     public void addBounds( Rectangle2D rect ) {
270         for( int i=0; i<top; i++ ) {
271             Frame fo = (Frame) objects[i];
272             fo.addBounds( rect );
273         }
274     }
275
276     public boolean isConstant() {
277         for( int i=0; i<top; i++ ) {
278             Frame fo = (Frame) objects[i];
279             if( !fo.isConstant() ) return false;
280         }
281         return true;
282     }
283
284     public void printContent( PrintStream out, String JavaDoc indent ) {
285         for( int i=0; i<top; i++ ) {
286             Frame fo = (Frame) objects[i];
287             out.print( indent+"Frame #"+i );
288             if( fo.getName() != null ) {
289                 out.println( " name='"+fo.getName()+"' "+(fo.isAnchor()?"anchor":"") );
290             } else {
291                 out.println();
292             }
293             fo.printContent( out, indent );
294         }
295     }
296
297     public IVVector getCopy( ScriptCopier copier ) {
298         Timeline t = new Timeline( size() );
299         for( int i=0; i<top; i++ ) {
300             Frame fo = (Frame) objects[i];
301             t.setElementAt( fo.getCopy(copier), i );
302         }
303         return t;
304     }
305 }
306
307
Popular Tags