KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openlaszlo > iv > flash > api > shape > MorphShapeStyles


1 /*
2  * $Id: MorphShapeStyles.java,v 1.1 2002/02/15 23:46:26 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.shape;
52
53 import org.openlaszlo.iv.flash.util.*;
54 import org.openlaszlo.iv.flash.api.*;
55 import org.openlaszlo.iv.flash.parser.*;
56 import java.io.PrintStream JavaDoc;
57
58 /**
59  * This object represents collection of shape styles.
60  *
61  * @author Dmitry Skavish
62  */

63 public final class MorphShapeStyles extends FlashItem {
64
65     /**
66      * Vector of {@link MorphFillStyle}s records
67      */

68     public IVVector fillStyles;
69
70     /**
71      * Vector of {@link MorphLineStyle}s records.
72      */

73     public IVVector lineStyles;
74
75     /**
76      * Creates empty shapestyle
77      */

78     public MorphShapeStyles() {
79         this(new IVVector(), new IVVector());
80     }
81
82     public MorphShapeStyles( IVVector fillStyles, IVVector lineStyles ) {
83         this.fillStyles = fillStyles;
84         this.lineStyles = lineStyles;
85     }
86
87     /**
88      * Adds new fillstyle to this array.
89      *
90      * @param fs new fillstyle to be added
91      * @return index of added fillstyle
92      */

93     public int addFillStyle( MorphFillStyle fs ) {
94         fillStyles.addElement(fs);
95         return fillStyles.size();
96     }
97
98     /**
99      * Adds new linestyle to this array.
100      *
101      * @param ls new linestyle to be added
102      * @return index of added linestyle
103      */

104     public int addLineStyle( MorphLineStyle ls ) {
105         lineStyles.addElement(ls);
106         return lineStyles.size();
107     }
108
109     /**
110      * Returns index of specified fillstyle
111      *
112      * @param fs fillstyle which index is to be returned
113      * @return index of specified fillstyle or -1
114      */

115     public int getFillStyleIndex( MorphFillStyle fs ) {
116         for( int i=0; i<fillStyles.size(); i++ ) {
117             MorphFillStyle ffs = (MorphFillStyle) fillStyles.elementAt(i);
118             if( ffs == fs ) return i+1;
119         }
120         return -1;
121     }
122
123     /**
124      * Returns index of specified linestyle
125      *
126      * @param ls linestyle which index is to be returned
127      * @return index of specified linestyle or -1
128      */

129     public int getLineStyleIndex( MorphLineStyle ls ) {
130         for( int i=0; i<lineStyles.size(); i++ ) {
131             MorphLineStyle lls = (MorphLineStyle) lineStyles.elementAt(i);
132             if( lls == ls ) return i+1;
133         }
134         return -1;
135     }
136
137     /**
138      * Returns line style by its index
139      *
140      * @param index index of line style to be returned
141      * @return line style at specified index
142      */

143     public MorphLineStyle getLineStyle( int index ) {
144         return (MorphLineStyle) lineStyles.elementAt(index);
145     }
146
147     /**
148      * Returns fill style by its index
149      *
150      * @param index index of fill style to be returned
151      * @return fill style at specified index
152      */

153     public MorphFillStyle getFillStyle( int index ) {
154         return (MorphFillStyle) fillStyles.elementAt(index);
155     }
156
157     /**
158      * Returns maximum number of bits required to hold fillstyles' indexes
159      *
160      * @return maximum number of bits required to hold fillstyles' indexes
161      */

162     public int calcNFillBits() {
163         return Util.getMinBitsU( fillStyles.size() );
164     }
165
166     /**
167      * Returns maximum number of bits required to hold linestyles' indexes
168      *
169      * @return maximum number of bits required to hold linestyles' indexes
170      */

171     public int calcNLineBits() {
172         return Util.getMinBitsU( lineStyles.size() );
173     }
174
175     public void collectDeps( DepsCollector dc ) {
176         int fillStyleSize = fillStyles.size();
177         for( int i=0; i<fillStyleSize; i++ ) {
178             MorphFillStyle fillStyle = (MorphFillStyle) fillStyles.elementAt(i);
179             if( fillStyle.getBitmap() != null ) dc.addDep(fillStyle.getBitmap());
180         }
181     }
182
183     public void write( FlashOutput fob ) {
184         int fillStyleSize = fillStyles.size();
185         if( fillStyleSize > 254 ) {
186             fob.writeByte(255);
187             fob.writeWord(fillStyleSize);
188         } else {
189             fob.writeByte(fillStyleSize);
190         }
191         fillStyles.write(fob);
192         int lineStyleSize = lineStyles.size();
193         if( lineStyleSize > 254 ) {
194             fob.writeByte(255);
195             fob.writeWord(lineStyleSize);
196         } else {
197             fob.writeByte(lineStyleSize);
198         }
199         lineStyles.write(fob);
200     }
201
202     public static MorphShapeStyles parse( Parser p ) {
203         // Get the number of fills.
204
int nFills = p.getUByte();
205         if( nFills == 255 ) {
206             nFills = p.getUWord();
207         }
208         IVVector fillStyles = new IVVector(nFills);
209
210         // Get each of the fill style.
211
for( int i=0; i<nFills; i++ ) {
212             fillStyles.addElement( MorphFillStyle.parse(p) );
213         }
214
215         int nLines = p.getUByte();
216         if( nLines == 255 ) {
217             nLines = p.getUWord();
218         }
219         IVVector lineStyles = new IVVector(nLines);
220
221         // Get each of the line styles.
222
for( int i=0; i<nLines; i++ ) {
223             lineStyles.addElement( MorphLineStyle.parse(p) );
224         }
225
226         return new MorphShapeStyles(fillStyles, lineStyles);
227     }
228
229     public void printContent( PrintStream JavaDoc out, String JavaDoc indent ) {
230         out.println( indent+"MorphShapeStyles:" );
231         fillStyles.printContent(out, indent+" ");
232         lineStyles.printContent(out, indent+" ");
233     }
234
235     protected FlashItem copyInto( FlashItem item, ScriptCopier copier ) {
236         ((MorphShapeStyles)item).fillStyles = fillStyles.getCopy(copier);
237         ((MorphShapeStyles)item).lineStyles = lineStyles.getCopy(copier);
238         return item;
239     }
240
241     public FlashItem getCopy( ScriptCopier copier ) {
242         return copyInto( new MorphShapeStyles(null, null), copier );
243     }
244 }
245
246
Popular Tags