KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: FlashObject.java,v 1.3 2002/07/16 20:17:29 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 java.io.PrintStream JavaDoc;
54
55 import java.awt.geom.Rectangle2D JavaDoc;
56
57 import org.openlaszlo.iv.flash.util.*;
58 import org.openlaszlo.iv.flash.context.Context;
59
60 /**
61  * Abstract base class for flash objects which can be placed on Flash timeline (usually tags) and generated back
62  *
63  * @author Dmitry Skavish
64  * @see FlashDef
65  * @see FlashItem
66  */

67 public abstract class FlashObject extends FlashItem {
68
69     /**
70      * Defines whether this object is constant for generator processing or not<BR>
71      * Possible values are:<BR>
72      * <UL>
73      * <LI>0 - it is not known yet whether this object is constant or not
74      * <LI>1 - this object is constant
75      * <LI>2 - this object is not a constant
76      *
77      * @see #isConstant
78      */

79     private byte isConstant = (byte)0;
80
81     /**
82      * Returns tag id of this object
83      *
84      * @return tag id of this object
85      * @see org.openlaszlo.iv.flash.util.Tag
86      */

87     public abstract int getTag();
88
89     /**
90      * Collects all dependencies this objects has in given {@link DepsCollector}<br>
91      * For example object of {@link org.openlaszlo.iv.flash.api.button.Button Button} class depends on objects of
92      * {@link FlashDef} class, i.e. consists of flash definitions.
93      * It means that all objects this object depends on have to be generated
94      * <B>before</B> this object is generated.
95      *
96      * @param dc collector of dependent objects
97      */

98     public void collectDeps( DepsCollector dc ) {}
99
100     /**
101      * Collects all possible fonts this object uses (if any)
102      *
103      * @param fc fonts collector
104      */

105     public void collectFonts( FontsCollector fc ) {}
106
107     /**
108      * Generates this object to FlashOutput, but first generates all dependencies<br>
109      * Usually you don't need to override this method<BR>
110      * Method:<BR>
111      * <UL>
112      * <LI>collects all dependencies of this object
113      * <LI>writes these dependencies first to FlashOutput
114      * <LI>writes this object itself
115      * </UL>
116      *
117      * @param fob buffer to write to
118      * @param dc dependencies collector
119      * @see #write
120      * @see #collectDeps
121      */

122     public void generate( FlashOutput fob, DepsCollector dc ) {
123         //Object id = this instanceof FlashDef?(Object)new Integer(((FlashDef)this).getID()):(Object)this;
124
//System.out.println( "FlashObject.generate: ID="+id );
125
dc.startCollect();
126         collectDeps( dc );
127         IVVector collected = dc.getCollected();
128         //System.out.println( "generate collected:" );
129
for( int i=0; i<collected.size(); i++ ) {
130             FlashObject d = (FlashObject) collected.elementAt(i);
131             if( !dc.isGenerated(d) ) {
132                 dc.addGenerated(d);
133                 d.generate( fob, dc );
134             }
135         }
136         dc.endCollect();
137         //System.out.println( "FlashObject.write: ID="+id );
138
write( fob );
139     }
140
141     /**
142      * Processes this flash object in specified context and flash file
143      *
144      * @param file flash file
145      * @param context generator context
146      * @exception IVException
147      */

148     public void process( FlashFile file, Context context ) throws IVException {}
149
150     /**
151      * Returns true of this object was processed
152      *
153      * @return true of this object was processed
154      */

155     public boolean isProcessed() {
156         return true;
157     }
158
159     /**
160      * Sets this object as processed
161      */

162     public void setProcessed() {}
163
164     /**
165      * Applies given context to this object<BR>
166      * If this object is not constant ({@link #isConstant})
167      * then it may be altered by generator context if it has generator variables
168      * somewhere inside.<BR>
169      *
170      * @param context generator context to be applied to this object
171      */

172     public void apply( Context context ) {}
173
174     /**
175      * Returns true if this object is not subject to generator substitutions or commands<BR>
176      * Override this method if you know the dynamic nature of content of your object and want
177      * to avoid unneccesary copying or/and execution.<BR>
178      * Constant objects are not duplicated and are not processed by generator.<BR>
179      *
180      * @return true if object is constant
181      * @see #isConstant
182      */

183     protected boolean _isConstant() {
184         return false;
185     }
186
187     protected void setConstant( boolean is_const ) {
188         isConstant = is_const? (byte)1: (byte)2;
189     }
190
191     /**
192      * Returns true if this object is not subject to generator substitutions or commands<BR>
193      * You usually don't need to override this method, this method is merely a cache for
194      * {@link #_isConstant} method.
195      *
196      * @return true if object is constant
197      * @see #isConstant
198      */

199     public boolean isConstant() {
200         if( isConstant == (byte)0 ) {
201             isConstant = _isConstant()? (byte)1: (byte)2;
202         }
203         return isConstant == (byte)1;
204     }
205
206     /**
207      * Returns rectangular bounds of this object<BR>
208      * It's ok to return null if this object does not have any bounds,
209      * as for example {@link org.openlaszlo.iv.flash.api.action.DoAction}
210      *
211      * @return bounds of this object or null
212      */

213     public Rectangle2D JavaDoc getBounds() {
214         return null;
215     }
216
217     public void printContent( PrintStream JavaDoc out, String JavaDoc indent ) {
218         int tag = getTag();
219         String JavaDoc name;
220         if( tag >= Tag.tagNames.length || tag < 0 ) name = "Unknown";
221         else name = Tag.tagNames[tag];
222         out.println( indent+"Tag: 0x"+Util.b2h(getTag())+" '"+name+"'" );
223     }
224
225     protected FlashItem copyInto( FlashItem item, ScriptCopier copier ) {
226         super.copyInto( item, copier );
227         ((FlashObject)item).isConstant = isConstant;
228         return item;
229     }
230
231 }
232
233
Popular Tags