KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: StyleChangeRecord.java,v 1.2 2002/02/15 23:44:28 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 java.io.PrintStream JavaDoc;
56
57 /**
58  * Stylechange record.
59  * <P>
60  * The style change record is a non-edge record. It can be used to:
61  * <UL>
62  * <LI>Select a fill or line style for drawing
63  * <LI>Move the current drawing position (without drawing)
64  * <LI>Replace the current fill and line style arrays with a new set of styles
65  * </UL>
66  * Because fill and line styles often change at the start of a new path,
67  * it is useful to perform more than one action in a single record.
68  * For example, say a DefineShape tag defines a red circle and a blue square.
69  * After the circle is closed, it is necessary to move the drawing position,
70  * and replace the red fill with the blue fill. The style change record can achieve
71  * this with a single shape-record.
72  *
73  * @author Dmitry Skavish
74  */

75 public final class StyleChangeRecord extends FlashItem {
76
77     public static final int NEW_STYLES = 0x10;
78     public static final int LINESTYLE = 0x08;
79     public static final int FILLSTYLE1 = 0x04;
80     public static final int FILLSTYLE0 = 0x02;
81     public static final int MOVETO = 0x01;
82
83     private int flags;
84     private int deltaX;
85     private int deltaY;
86     private int fillStyle0;
87     private int fillStyle1;
88     private int lineStyle;
89
90     public StyleChangeRecord() {}
91
92     public int getFlags() {
93         return flags;
94     }
95
96     public void setFlags( int flags ) {
97         this.flags = flags;
98     }
99
100     public void addFlags( int flags ) {
101         this.flags |= flags;
102     }
103
104     public int getDeltaX() {
105         return deltaX;
106     }
107
108     public void setDeltaX( int deltaX ) {
109         this.deltaX = deltaX;
110     }
111
112     public int getDeltaY() {
113         return deltaY;
114     }
115
116     public void setDeltaY( int deltaY ) {
117         this.deltaY = deltaY;
118     }
119
120     public int getFillStyle0() {
121         return fillStyle0;
122     }
123
124     public void setFillStyle0( int fillStyle0 ) {
125         this.fillStyle0 = fillStyle0;
126     }
127
128     public int getFillStyle1() {
129         return fillStyle1;
130     }
131
132     public void setFillStyle1( int fillStyle1 ) {
133         this.fillStyle1 = fillStyle1;
134     }
135
136     public int getLineStyle() {
137         return lineStyle;
138     }
139
140     public void setLineStyle( int lineStyle ) {
141         this.lineStyle = lineStyle;
142     }
143
144     public void write( FlashOutput fob ) {
145         write(fob, 0, 0);
146     }
147
148     public void write( FlashOutput fob, int nFillBits, int nLineBits ) {
149         fob.writeBits(flags, 6);
150         if( (flags&MOVETO) != 0 ) {
151             int nBits = Util.getMinBitsS( Util.getMax(deltaX, deltaY) );
152             fob.writeBits(nBits, 5);
153             fob.writeBits(deltaX, nBits);
154             fob.writeBits(deltaY, nBits);
155         }
156         if( (flags&FILLSTYLE0) != 0 ) {
157             fob.writeBits(fillStyle0, nFillBits);
158         }
159         if( (flags&FILLSTYLE1) != 0 ) {
160             fob.writeBits(fillStyle1, nFillBits);
161         }
162         if( (flags&LINESTYLE) != 0 ) {
163             fob.writeBits(lineStyle, nLineBits);
164         }
165     }
166
167     public void printContent( PrintStream JavaDoc out, String JavaDoc indent ) {
168         if( (flags&MOVETO) != 0 ) {
169             out.println( indent+" moveto ("+deltaX+","+deltaY+")" );
170         }
171         if( (flags&FILLSTYLE0) != 0 ) {
172             out.println( indent+" fillStyle0 "+fillStyle0 );
173         }
174         if( (flags&FILLSTYLE1) != 0 ) {
175             out.println( indent+" fillStyle1 "+fillStyle1 );
176         }
177         if( (flags&LINESTYLE) != 0 ) {
178             out.println( indent+" lineStyle "+lineStyle );
179         }
180         if( (flags&NEW_STYLES) != 0 ) {
181             out.println( indent+" newstyles" );
182         }
183     }
184
185     protected FlashItem copyInto( FlashItem item, ScriptCopier copier ) {
186         ((StyleChangeRecord)item).deltaX = deltaX;
187         ((StyleChangeRecord)item).deltaY = deltaY;
188         ((StyleChangeRecord)item).fillStyle0 = fillStyle0;
189         ((StyleChangeRecord)item).fillStyle1 = fillStyle1;
190         ((StyleChangeRecord)item).lineStyle = lineStyle;
191         ((StyleChangeRecord)item).flags = flags;
192         return item;
193     }
194
195     public FlashItem getCopy( ScriptCopier copier ) {
196         return copyInto( new StyleChangeRecord(), copier );
197     }
198 }
199
Popular Tags