KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > ddf > EscherSpRecord


1
2 /* ====================================================================
3    Copyright 2002-2004 Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16 ==================================================================== */

17         
18 package org.apache.poi.ddf;
19
20 import org.apache.poi.util.HexDump;
21 import org.apache.poi.util.LittleEndian;
22
23 /**
24  * Together the the EscherOptRecord this record defines some of the basic
25  * properties of a shape.
26  *
27  * @author Glen Stampoultzis (glens at apache.org)
28  */

29 public class EscherSpRecord
30     extends EscherRecord
31 {
32     public static final short RECORD_ID = (short) 0xF00A;
33     public static final String JavaDoc RECORD_DESCRIPTION = "MsofbtSp";
34
35     public static final int FLAG_GROUP = 0x0001;
36     public static final int FLAG_CHILD = 0x0002;
37     public static final int FLAG_PATRIARCH = 0x0004;
38     public static final int FLAG_DELETED = 0x0008;
39     public static final int FLAG_OLESHAPE = 0x0010;
40     public static final int FLAG_HAVEMASTER = 0x0020;
41     public static final int FLAG_FLIPHORIZ = 0x0040;
42     public static final int FLAG_FLIPVERT = 0x0080;
43     public static final int FLAG_CONNECTOR = 0x0100;
44     public static final int FLAG_HAVEANCHOR = 0x0200;
45     public static final int FLAG_BACKGROUND = 0x0400;
46     public static final int FLAG_HASSHAPETYPE = 0x0800;
47
48     private int field_1_shapeId;
49     private int field_2_flags;
50
51     /**
52      * This method deserializes the record from a byte array.
53      *
54      * @param data The byte array containing the escher record information
55      * @param offset The starting offset into <code>data</code>.
56      * @param recordFactory May be null since this is not a container record.
57      * @return The number of bytes read from the byte array.
58      */

59     public int fillFields( byte[] data, int offset, EscherRecordFactory recordFactory )
60     {
61         int bytesRemaining = readHeader( data, offset );
62         int pos = offset + 8;
63         int size = 0;
64         field_1_shapeId = LittleEndian.getInt( data, pos + size ); size += 4;
65         field_2_flags = LittleEndian.getInt( data, pos + size ); size += 4;
66 // bytesRemaining -= size;
67
// remainingData = new byte[bytesRemaining];
68
// System.arraycopy( data, pos + size, remainingData, 0, bytesRemaining );
69
return getRecordSize();
70     }
71
72     /**
73      * This method serializes this escher record into a byte array.
74      *
75      * @param offset The offset into <code>data</code> to start writing the record data to.
76      * @param data The byte array to serialize to.
77      * @param listener A listener to retrieve start and end callbacks. Use a <code>NullEscherSerailizationListener</code> to ignore these events.
78      * @return The number of bytes written.
79      *
80      * @see NullEscherSerializationListener
81      */

82     public int serialize( int offset, byte[] data, EscherSerializationListener listener )
83     {
84         listener.beforeRecordSerialize( offset, getRecordId(), this );
85         LittleEndian.putShort( data, offset, getOptions() );
86         LittleEndian.putShort( data, offset + 2, getRecordId() );
87         int remainingBytes = 8;
88         LittleEndian.putInt( data, offset + 4, remainingBytes );
89         LittleEndian.putInt( data, offset + 8, field_1_shapeId );
90         LittleEndian.putInt( data, offset + 12, field_2_flags );
91 // System.arraycopy( remainingData, 0, data, offset + 26, remainingData.length );
92
// int pos = offset + 8 + 18 + remainingData.length;
93
listener.afterRecordSerialize( offset + getRecordSize(), getRecordId(), getRecordSize(), this );
94         return 8 + 8;
95     }
96
97     /**
98      * Returns the number of bytes that are required to serialize this record.
99      *
100      * @return Number of bytes
101      */

102     public int getRecordSize()
103     {
104         return 8 + 8;
105     }
106
107     /**
108      * @return the 16 bit identifier for this record.
109      */

110     public short getRecordId()
111     {
112         return RECORD_ID;
113     }
114
115     /**
116      * The short name for this record
117      */

118     public String JavaDoc getRecordName()
119     {
120         return "Sp";
121     }
122
123     /**
124      * @return the string representing this shape.
125      */

126     public String JavaDoc toString()
127     {
128         String JavaDoc nl = System.getProperty("line.separator");
129
130         return getClass().getName() + ":" + nl +
131                 " RecordId: 0x" + HexDump.toHex(RECORD_ID) + nl +
132                 " Options: 0x" + HexDump.toHex(getOptions()) + nl +
133                 " ShapeId: " + field_1_shapeId + nl +
134                 " Flags: " + decodeFlags(field_2_flags) + " (0x" + HexDump.toHex(field_2_flags) + ")" + nl;
135
136     }
137
138     /**
139      * Converts the shape flags into a more descriptive name.
140      */

141     private String JavaDoc decodeFlags( int flags )
142     {
143         StringBuffer JavaDoc result = new StringBuffer JavaDoc();
144         result.append( ( flags & FLAG_GROUP ) != 0 ? "|GROUP" : "" );
145         result.append( ( flags & FLAG_CHILD ) != 0 ? "|CHILD" : "" );
146         result.append( ( flags & FLAG_PATRIARCH ) != 0 ? "|PATRIARCH" : "" );
147         result.append( ( flags & FLAG_DELETED ) != 0 ? "|DELETED" : "" );
148         result.append( ( flags & FLAG_OLESHAPE ) != 0 ? "|OLESHAPE" : "" );
149         result.append( ( flags & FLAG_HAVEMASTER ) != 0 ? "|HAVEMASTER" : "" );
150         result.append( ( flags & FLAG_FLIPHORIZ ) != 0 ? "|FLIPHORIZ" : "" );
151         result.append( ( flags & FLAG_FLIPVERT ) != 0 ? "|FLIPVERT" : "" );
152         result.append( ( flags & FLAG_CONNECTOR ) != 0 ? "|CONNECTOR" : "" );
153         result.append( ( flags & FLAG_HAVEANCHOR ) != 0 ? "|HAVEANCHOR" : "" );
154         result.append( ( flags & FLAG_BACKGROUND ) != 0 ? "|BACKGROUND" : "" );
155         result.append( ( flags & FLAG_HASSHAPETYPE ) != 0 ? "|HASSHAPETYPE" : "" );
156
157         result.deleteCharAt(0);
158         return result.toString();
159     }
160
161     /**
162      * @return A number that identifies this shape
163      */

164     public int getShapeId()
165     {
166         return field_1_shapeId;
167     }
168
169     /**
170      * Sets a number that identifies this shape.
171      */

172     public void setShapeId( int field_1_shapeId )
173     {
174         this.field_1_shapeId = field_1_shapeId;
175     }
176
177     /**
178      * The flags that apply to this shape.
179      *
180      * @see #FLAG_GROUP
181      * @see #FLAG_CHILD
182      * @see #FLAG_PATRIARCH
183      * @see #FLAG_DELETED
184      * @see #FLAG_OLESHAPE
185      * @see #FLAG_HAVEMASTER
186      * @see #FLAG_FLIPHORIZ
187      * @see #FLAG_FLIPVERT
188      * @see #FLAG_CONNECTOR
189      * @see #FLAG_HAVEANCHOR
190      * @see #FLAG_BACKGROUND
191      * @see #FLAG_HASSHAPETYPE
192      */

193     public int getFlags()
194     {
195         return field_2_flags;
196     }
197
198     /**
199      * The flags that apply to this shape.
200      *
201      * @see #FLAG_GROUP
202      * @see #FLAG_CHILD
203      * @see #FLAG_PATRIARCH
204      * @see #FLAG_DELETED
205      * @see #FLAG_OLESHAPE
206      * @see #FLAG_HAVEMASTER
207      * @see #FLAG_FLIPHORIZ
208      * @see #FLAG_FLIPVERT
209      * @see #FLAG_CONNECTOR
210      * @see #FLAG_HAVEANCHOR
211      * @see #FLAG_BACKGROUND
212      * @see #FLAG_HASSHAPETYPE
213      */

214     public void setFlags( int field_2_flags )
215     {
216         this.field_2_flags = field_2_flags;
217     }
218 }
219
Popular Tags