001: /*
002: * $Id: StyleChangeRecord.java,v 1.2 2002/02/15 23:44:28 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.shape;
052:
053: import org.openlaszlo.iv.flash.util.*;
054: import org.openlaszlo.iv.flash.api.*;
055: import java.io.PrintStream;
056:
057: /**
058: * Stylechange record.
059: * <P>
060: * The style change record is a non-edge record. It can be used to:
061: * <UL>
062: * <LI>Select a fill or line style for drawing
063: * <LI>Move the current drawing position (without drawing)
064: * <LI>Replace the current fill and line style arrays with a new set of styles
065: * </UL>
066: * Because fill and line styles often change at the start of a new path,
067: * it is useful to perform more than one action in a single record.
068: * For example, say a DefineShape tag defines a red circle and a blue square.
069: * After the circle is closed, it is necessary to move the drawing position,
070: * and replace the red fill with the blue fill. The style change record can achieve
071: * this with a single shape-record.
072: *
073: * @author Dmitry Skavish
074: */
075: public final class StyleChangeRecord extends FlashItem {
076:
077: public static final int NEW_STYLES = 0x10;
078: public static final int LINESTYLE = 0x08;
079: public static final int FILLSTYLE1 = 0x04;
080: public static final int FILLSTYLE0 = 0x02;
081: public static final int MOVETO = 0x01;
082:
083: private int flags;
084: private int deltaX;
085: private int deltaY;
086: private int fillStyle0;
087: private int fillStyle1;
088: private int lineStyle;
089:
090: public StyleChangeRecord() {
091: }
092:
093: public int getFlags() {
094: return flags;
095: }
096:
097: public void setFlags(int flags) {
098: this .flags = flags;
099: }
100:
101: public void addFlags(int flags) {
102: this .flags |= flags;
103: }
104:
105: public int getDeltaX() {
106: return deltaX;
107: }
108:
109: public void setDeltaX(int deltaX) {
110: this .deltaX = deltaX;
111: }
112:
113: public int getDeltaY() {
114: return deltaY;
115: }
116:
117: public void setDeltaY(int deltaY) {
118: this .deltaY = deltaY;
119: }
120:
121: public int getFillStyle0() {
122: return fillStyle0;
123: }
124:
125: public void setFillStyle0(int fillStyle0) {
126: this .fillStyle0 = fillStyle0;
127: }
128:
129: public int getFillStyle1() {
130: return fillStyle1;
131: }
132:
133: public void setFillStyle1(int fillStyle1) {
134: this .fillStyle1 = fillStyle1;
135: }
136:
137: public int getLineStyle() {
138: return lineStyle;
139: }
140:
141: public void setLineStyle(int lineStyle) {
142: this .lineStyle = lineStyle;
143: }
144:
145: public void write(FlashOutput fob) {
146: write(fob, 0, 0);
147: }
148:
149: public void write(FlashOutput fob, int nFillBits, int nLineBits) {
150: fob.writeBits(flags, 6);
151: if ((flags & MOVETO) != 0) {
152: int nBits = Util.getMinBitsS(Util.getMax(deltaX, deltaY));
153: fob.writeBits(nBits, 5);
154: fob.writeBits(deltaX, nBits);
155: fob.writeBits(deltaY, nBits);
156: }
157: if ((flags & FILLSTYLE0) != 0) {
158: fob.writeBits(fillStyle0, nFillBits);
159: }
160: if ((flags & FILLSTYLE1) != 0) {
161: fob.writeBits(fillStyle1, nFillBits);
162: }
163: if ((flags & LINESTYLE) != 0) {
164: fob.writeBits(lineStyle, nLineBits);
165: }
166: }
167:
168: public void printContent(PrintStream out, String indent) {
169: if ((flags & MOVETO) != 0) {
170: out.println(indent + " moveto (" + deltaX + "," + deltaY
171: + ")");
172: }
173: if ((flags & FILLSTYLE0) != 0) {
174: out.println(indent + " fillStyle0 " + fillStyle0);
175: }
176: if ((flags & FILLSTYLE1) != 0) {
177: out.println(indent + " fillStyle1 " + fillStyle1);
178: }
179: if ((flags & LINESTYLE) != 0) {
180: out.println(indent + " lineStyle " + lineStyle);
181: }
182: if ((flags & NEW_STYLES) != 0) {
183: out.println(indent + " newstyles");
184: }
185: }
186:
187: protected FlashItem copyInto(FlashItem item, ScriptCopier copier) {
188: ((StyleChangeRecord) item).deltaX = deltaX;
189: ((StyleChangeRecord) item).deltaY = deltaY;
190: ((StyleChangeRecord) item).fillStyle0 = fillStyle0;
191: ((StyleChangeRecord) item).fillStyle1 = fillStyle1;
192: ((StyleChangeRecord) item).lineStyle = lineStyle;
193: ((StyleChangeRecord) item).flags = flags;
194: return item;
195: }
196:
197: public FlashItem getCopy(ScriptCopier copier) {
198: return copyInto(new StyleChangeRecord(), copier);
199: }
200: }
|