KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openlaszlo > iv > flash > api > text > TextStyleChangeRecord


1 /*
2  * $Id: TextStyleChangeRecord.java,v 1.3 2002/07/15 22:39:32 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.text;
52
53 import org.openlaszlo.iv.flash.parser.*;
54 import org.openlaszlo.iv.flash.util.*;
55 import org.openlaszlo.iv.flash.api.*;
56 import java.io.*;
57 import java.util.*;
58
59 /**
60  * TextStyleChangeRecord.
61  * <p>
62  * Changes the text style or/and position of the following text (TextRecord)
63  *
64  * @author Dmitry Skavish
65  * @see TextRecord
66  */

67 public final class TextStyleChangeRecord extends FlashItem {
68
69     private Font font = null; // font of the following text
70
private Color color = null; // color of the following text
71
private int xOffset = Integer.MAX_VALUE; // x of the following text
72
private int yOffset = Integer.MAX_VALUE; // y of the following text
73
private int height; // font height
74

75     /**
76      * Creates empty change record
77      */

78     public TextStyleChangeRecord() {}
79
80     /**
81      * Creates change record of font and color
82      *
83      * @param font new font
84      * @param height height of the new font
85      * @param color new color
86      */

87     public TextStyleChangeRecord( Font font, int height, Color color ) {
88         this.font = font;
89         this.height = height;
90         this.color = color;
91     }
92
93     /**
94      * Creates change record of X and Y
95      *
96      * @param x new X (in twixels)
97      * @param y new Y (in twixels)
98      */

99     public TextStyleChangeRecord( int x, int y ) {
100         this.xOffset = x;
101         this.yOffset = y;
102     }
103
104     public void setFont( Font font ) { this.font = font; }
105     public void setColor( Color color ) { this.color = color; }
106     public void setX( int x ) { this.xOffset = x; }
107     public void setY( int y ) { this.yOffset = y; }
108     public void setHeight( int h ) { this.height = h; }
109
110     public Font getFont() { return font; }
111     public Color getColor() { return color; }
112     public int getX() { return xOffset; }
113     public int getY() { return yOffset; }
114     public int getHeight() { return height; }
115
116     /**
117      * Merges this record into specified one
118      * <P>
119      * Attributes of the specified one have bigger priority
120      *
121      * @param ts specified record
122      */

123     public void mergeTo( TextStyleChangeRecord ts ) {
124         if( ts.getFont() == null ) {
125             ts.setFont( font );
126             ts.setHeight( height );
127         }
128         if( ts.getColor() == null ) ts.setColor( color );
129         if( ts.getX() == Integer.MAX_VALUE ) ts.setX( xOffset );
130         if( ts.getY() == Integer.MAX_VALUE ) ts.setY( yOffset );
131     }
132
133     public void write( FlashOutput fob ) {
134         // write control record
135
fob.initBits();
136         fob.writeBits( 0x08, 4 );
137         fob.writeBool( font != null );
138         fob.writeBool( color != null );
139         fob.writeBool( yOffset != Integer.MAX_VALUE );
140         fob.writeBool( xOffset != Integer.MAX_VALUE );
141         fob.flushBits();
142         if( font != null ) fob.writeFontID( font );
143         if( color != null ) color.write(fob);
144         if( xOffset != Integer.MAX_VALUE ) fob.writeWord(xOffset);
145         if( yOffset != Integer.MAX_VALUE ) fob.writeWord(yOffset);
146         if( font != null ) fob.writeWord(height);
147     }
148
149     public boolean isX() {
150         return xOffset != Integer.MAX_VALUE;
151     }
152
153     public boolean isY() {
154         return yOffset != Integer.MAX_VALUE;
155     }
156
157     public void printContent( PrintStream out, String JavaDoc indent ) {
158         out.println( indent+"TextStyleChangeRecord: " );
159         if( font != null ) out.println( indent+" font="+font.getFontName()+", height="+height );
160         if( color != null ) color.printContent(out, indent+" ");
161         if( xOffset != Integer.MAX_VALUE ) out.println( indent+" xOffset="+xOffset );
162         if( yOffset != Integer.MAX_VALUE ) out.println( indent+" yOffset="+yOffset );
163     }
164
165     protected FlashItem copyInto( FlashItem item, ScriptCopier copier ) {
166         ((TextStyleChangeRecord)item).font = font;
167         ((TextStyleChangeRecord)item).color = color == null? null: (Color) color.getCopy(copier);
168         ((TextStyleChangeRecord)item).xOffset = xOffset;
169         ((TextStyleChangeRecord)item).yOffset = yOffset;
170         ((TextStyleChangeRecord)item).height = height;
171         return item;
172     }
173
174     public FlashItem getCopy( ScriptCopier copier ) {
175         return copyInto( new TextStyleChangeRecord(), copier );
176     }
177 }
178
179
Popular Tags