KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.io.ByteArrayOutputStream JavaDoc;
24
25 /**
26  * The escher client anchor specifies which rows and cells the shape is bound to as well as
27  * the offsets within those cells. Each cell is 1024 units wide by 256 units long regardless
28  * of the actual size of the cell. The EscherClientAnchorRecord only applies to the top-most
29  * shapes. Shapes contained in groups are bound using the EscherChildAnchorRecords.
30  *
31  * @author Glen Stampoultzis
32  * @see EscherChildAnchorRecord
33  */

34 public class EscherClientAnchorRecord
35         extends EscherRecord
36 {
37     public static final short RECORD_ID = (short) 0xF010;
38     public static final String JavaDoc RECORD_DESCRIPTION = "MsofbtClientAnchor";
39
40     private short field_1_flag;
41     private short field_2_col1;
42     private short field_3_dx1;
43     private short field_4_row1;
44     private short field_5_dy1;
45     private short field_6_col2;
46     private short field_7_dx2;
47     private short field_8_row2;
48     private short field_9_dy2;
49     private byte[] remainingData;
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_flag = LittleEndian.getShort( data, pos + size ); size += 2;
65         field_2_col1 = LittleEndian.getShort( data, pos + size ); size += 2;
66         field_3_dx1 = LittleEndian.getShort( data, pos + size ); size += 2;
67         field_4_row1 = LittleEndian.getShort( data, pos + size ); size += 2;
68         field_5_dy1 = LittleEndian.getShort( data, pos + size ); size += 2;
69         field_6_col2 = LittleEndian.getShort( data, pos + size ); size += 2;
70         field_7_dx2 = LittleEndian.getShort( data, pos + size ); size += 2;
71         field_8_row2 = LittleEndian.getShort( data, pos + size ); size += 2;
72         field_9_dy2 = LittleEndian.getShort( data, pos + size ); size += 2;
73         bytesRemaining -= size;
74         remainingData = new byte[bytesRemaining];
75         System.arraycopy( data, pos + size, remainingData, 0, bytesRemaining );
76         return 8 + size + bytesRemaining;
77     }
78
79     /**
80      * This method serializes this escher record into a byte array.
81      *
82      * @param offset The offset into <code>data</code> to start writing the record data to.
83      * @param data The byte array to serialize to.
84      * @param listener A listener to retrieve start and end callbacks. Use a <code>NullEscherSerailizationListener</code> to ignore these events.
85      * @return The number of bytes written.
86      * @see NullEscherSerializationListener
87      */

88     public int serialize( int offset, byte[] data, EscherSerializationListener listener )
89     {
90         listener.beforeRecordSerialize( offset, getRecordId(), this );
91
92         if (remainingData == null) remainingData = new byte[0];
93         LittleEndian.putShort( data, offset, getOptions() );
94         LittleEndian.putShort( data, offset + 2, getRecordId() );
95         int remainingBytes = remainingData.length + 18;
96         LittleEndian.putInt( data, offset + 4, remainingBytes );
97         LittleEndian.putShort( data, offset + 8, field_1_flag );
98         LittleEndian.putShort( data, offset + 10, field_2_col1 );
99         LittleEndian.putShort( data, offset + 12, field_3_dx1 );
100         LittleEndian.putShort( data, offset + 14, field_4_row1 );
101         LittleEndian.putShort( data, offset + 16, field_5_dy1 );
102         LittleEndian.putShort( data, offset + 18, field_6_col2 );
103         LittleEndian.putShort( data, offset + 20, field_7_dx2 );
104         LittleEndian.putShort( data, offset + 22, field_8_row2 );
105         LittleEndian.putShort( data, offset + 24, field_9_dy2 );
106         System.arraycopy( remainingData, 0, data, offset + 26, remainingData.length );
107         int pos = offset + 8 + 18 + remainingData.length;
108
109         listener.afterRecordSerialize( pos, getRecordId(), pos - offset, this );
110         return pos - offset;
111     }
112
113     /**
114      * Returns the number of bytes that are required to serialize this record.
115      *
116      * @return Number of bytes
117      */

118     public int getRecordSize()
119     {
120         return 8 + 18 + (remainingData == null ? 0 : remainingData.length);
121     }
122
123     /**
124      * The record id for this record.
125      */

126     public short getRecordId()
127     {
128         return RECORD_ID;
129     }
130
131     /**
132      * The short name for this record
133      */

134     public String JavaDoc getRecordName()
135     {
136         return "ClientAnchor";
137     }
138
139     /**
140      * Returns the string representation for this record.
141      *
142      * @return A string
143      */

144     public String JavaDoc toString()
145     {
146         String JavaDoc nl = System.getProperty("line.separator");
147
148         String JavaDoc extraData;
149         ByteArrayOutputStream JavaDoc b = new ByteArrayOutputStream JavaDoc();
150         try
151         {
152             HexDump.dump(this.remainingData, 0, b, 0);
153             extraData = b.toString();
154         }
155         catch ( Exception JavaDoc e )
156         {
157             extraData = "error";
158         }
159         return getClass().getName() + ":" + nl +
160                 " RecordId: 0x" + HexDump.toHex(RECORD_ID) + nl +
161                 " Options: 0x" + HexDump.toHex(getOptions()) + nl +
162                 " Flag: " + field_1_flag + nl +
163                 " Col1: " + field_2_col1 + nl +
164                 " DX1: " + field_3_dx1 + nl +
165                 " Row1: " + field_4_row1 + nl +
166                 " DY1: " + field_5_dy1 + nl +
167                 " Col2: " + field_6_col2 + nl +
168                 " DX2: " + field_7_dx2 + nl +
169                 " Row2: " + field_8_row2 + nl +
170                 " DY2: " + field_9_dy2 + nl +
171                 " Extra Data:" + nl + extraData;
172
173     }
174
175     /**
176      * 0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells.
177      */

178     public short getFlag()
179     {
180         return field_1_flag;
181     }
182
183     /**
184      * 0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells.
185      */

186     public void setFlag( short field_1_flag )
187     {
188         this.field_1_flag = field_1_flag;
189     }
190
191     /**
192      * The column number for the top-left position. 0 based.
193      */

194     public short getCol1()
195     {
196         return field_2_col1;
197     }
198
199     /**
200      * The column number for the top-left position. 0 based.
201      */

202     public void setCol1( short field_2_col1 )
203     {
204         this.field_2_col1 = field_2_col1;
205     }
206
207     /**
208      * The x offset within the top-left cell. Range is from 0 to 1023.
209      */

210     public short getDx1()
211     {
212         return field_3_dx1;
213     }
214
215     /**
216      * The x offset within the top-left cell. Range is from 0 to 1023.
217      */

218     public void setDx1( short field_3_dx1 )
219     {
220         this.field_3_dx1 = field_3_dx1;
221     }
222
223     /**
224      * The row number for the top-left corner of the shape.
225      */

226     public short getRow1()
227     {
228         return field_4_row1;
229     }
230
231     /**
232      * The row number for the top-left corner of the shape.
233      */

234     public void setRow1( short field_4_row1 )
235     {
236         this.field_4_row1 = field_4_row1;
237     }
238
239     /**
240      * The y offset within the top-left corner of the current shape.
241      */

242     public short getDy1()
243     {
244         return field_5_dy1;
245     }
246
247     /**
248      * The y offset within the top-left corner of the current shape.
249      */

250     public void setDy1( short field_5_dy1 )
251     {
252         this.field_5_dy1 = field_5_dy1;
253     }
254
255     /**
256      * The column of the bottom right corner of this shape.
257      */

258     public short getCol2()
259     {
260         return field_6_col2;
261     }
262
263     /**
264      * The column of the bottom right corner of this shape.
265      */

266     public void setCol2( short field_6_col2 )
267     {
268         this.field_6_col2 = field_6_col2;
269     }
270
271     /**
272      * The x offset withing the cell for the bottom-right corner of this shape.
273      */

274     public short getDx2()
275     {
276         return field_7_dx2;
277     }
278
279     /**
280      * The x offset withing the cell for the bottom-right corner of this shape.
281      */

282     public void setDx2( short field_7_dx2 )
283     {
284         this.field_7_dx2 = field_7_dx2;
285     }
286
287     /**
288      * The row number for the bottom-right corner of the current shape.
289      */

290     public short getRow2()
291     {
292         return field_8_row2;
293     }
294
295     /**
296      * The row number for the bottom-right corner of the current shape.
297      */

298     public void setRow2( short field_8_row2 )
299     {
300         this.field_8_row2 = field_8_row2;
301     }
302
303     /**
304      * The y offset withing the cell for the bottom-right corner of this shape.
305      */

306     public short getDy2()
307     {
308         return field_9_dy2;
309     }
310
311     /**
312      * The y offset withing the cell for the bottom-right corner of this shape.
313      */

314     public void setDy2( short field_9_dy2 )
315     {
316         this.field_9_dy2 = field_9_dy2;
317     }
318
319     /**
320      * Any remaining data in the record
321      */

322     public byte[] getRemainingData()
323     {
324         return remainingData;
325     }
326
327     /**
328      * Any remaining data in the record
329      */

330     public void setRemainingData( byte[] remainingData )
331     {
332         this.remainingData = remainingData;
333     }
334 }
335
Popular Tags