KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.apache.poi.hssf.record.RecordFormatException;
23
24 /**
25  * The spgr record defines information about a shape group. Groups in escher
26  * are simply another form of shape that you can't physically see.
27  *
28  * @author Glen Stampoultzis (glens at apache.org)
29  */

30 public class EscherSpgrRecord
31     extends EscherRecord
32 {
33     public static final short RECORD_ID = (short) 0xF009;
34     public static final String JavaDoc RECORD_DESCRIPTION = "MsofbtSpgr";
35
36     private int field_1_rectX1;
37     private int field_2_rectY1;
38     private int field_3_rectX2;
39     private int field_4_rectY2;
40
41     /**
42      * This method deserializes the record from a byte array.
43      *
44      * @param data The byte array containing the escher record information
45      * @param offset The starting offset into <code>data</code>.
46      * @param recordFactory May be null since this is not a container record.
47      * @return The number of bytes read from the byte array.
48      */

49     public int fillFields( byte[] data, int offset, EscherRecordFactory recordFactory )
50     {
51         int bytesRemaining = readHeader( data, offset );
52         int pos = offset + 8;
53         int size = 0;
54         field_1_rectX1 = LittleEndian.getInt( data, pos + size );size+=4;
55         field_2_rectY1 = LittleEndian.getInt( data, pos + size );size+=4;
56         field_3_rectX2 = LittleEndian.getInt( data, pos + size );size+=4;
57         field_4_rectY2 = LittleEndian.getInt( data, pos + size );size+=4;
58         bytesRemaining -= size;
59         if (bytesRemaining != 0) throw new RecordFormatException("Expected no remaining bytes but got " + bytesRemaining);
60 // remainingData = new byte[bytesRemaining];
61
// System.arraycopy( data, pos + size, remainingData, 0, bytesRemaining );
62
return 8 + size + bytesRemaining;
63     }
64
65     /**
66      * This method serializes this escher record into a byte array.
67      *
68      * @param offset The offset into <code>data</code> to start writing the record data to.
69      * @param data The byte array to serialize to.
70      * @param listener A listener to retrieve start and end callbacks. Use a <code>NullEscherSerailizationListener</code> to ignore these events.
71      * @return The number of bytes written.
72      *
73      * @see NullEscherSerializationListener
74      */

75     public int serialize( int offset, byte[] data, EscherSerializationListener listener )
76     {
77         listener.beforeRecordSerialize( offset, getRecordId(), this );
78         LittleEndian.putShort( data, offset, getOptions() );
79         LittleEndian.putShort( data, offset + 2, getRecordId() );
80         int remainingBytes = 16;
81         LittleEndian.putInt( data, offset + 4, remainingBytes );
82         LittleEndian.putInt( data, offset + 8, field_1_rectX1 );
83         LittleEndian.putInt( data, offset + 12, field_2_rectY1 );
84         LittleEndian.putInt( data, offset + 16, field_3_rectX2 );
85         LittleEndian.putInt( data, offset + 20, field_4_rectY2 );
86 // System.arraycopy( remainingData, 0, data, offset + 26, remainingData.length );
87
// int pos = offset + 8 + 18 + remainingData.length;
88
listener.afterRecordSerialize( offset + getRecordSize(), getRecordId(), offset + getRecordSize(), this );
89         return 8 + 16;
90     }
91
92     /**
93      * Returns the number of bytes that are required to serialize this record.
94      *
95      * @return Number of bytes
96      */

97     public int getRecordSize()
98     {
99         return 8 + 16;
100     }
101
102     /**
103      * The 16 bit identifier of this shape group record.
104      */

105     public short getRecordId()
106     {
107         return RECORD_ID;
108     }
109
110     /**
111      * The short name for this record
112      */

113     public String JavaDoc getRecordName()
114     {
115         return "Spgr";
116     }
117
118     /**
119      * @return the string representation of this record.
120      */

121     public String JavaDoc toString()
122     {
123         String JavaDoc nl = System.getProperty("line.separator");
124
125 // String extraData;
126
// ByteArrayOutputStream b = new ByteArrayOutputStream();
127
// try
128
// {
129
// HexDump.dump(this.remainingData, 0, b, 0);
130
// extraData = b.toString();
131
// }
132
// catch ( Exception e )
133
// {
134
// extraData = "error";
135
// }
136
return getClass().getName() + ":" + nl +
137                 " RecordId: 0x" + HexDump.toHex(RECORD_ID) + nl +
138                 " Options: 0x" + HexDump.toHex(getOptions()) + nl +
139                 " RectX: " + field_1_rectX1 + nl +
140                 " RectY: " + field_2_rectY1 + nl +
141                 " RectWidth: " + field_3_rectX2 + nl +
142                 " RectHeight: " + field_4_rectY2 + nl;
143
144     }
145
146     /**
147      * The starting top-left coordinate of child records.
148      */

149     public int getRectX1()
150     {
151         return field_1_rectX1;
152     }
153
154     /**
155      * The starting top-left coordinate of child records.
156      */

157     public void setRectX1( int x1 )
158     {
159         this.field_1_rectX1 = x1;
160     }
161
162     /**
163      * The starting top-left coordinate of child records.
164      */

165     public int getRectY1()
166     {
167         return field_2_rectY1;
168     }
169
170     /**
171      * The starting top-left coordinate of child records.
172      */

173     public void setRectY1( int y1 )
174     {
175         this.field_2_rectY1 = y1;
176     }
177
178     /**
179      * The starting bottom-right coordinate of child records.
180      */

181     public int getRectX2()
182     {
183         return field_3_rectX2;
184     }
185
186     /**
187      * The starting bottom-right coordinate of child records.
188      */

189     public void setRectX2( int x2 )
190     {
191         this.field_3_rectX2 = x2;
192     }
193
194     /**
195      * The starting bottom-right coordinate of child records.
196      */

197     public int getRectY2()
198     {
199         return field_4_rectY2;
200     }
201
202     /**
203      * The starting bottom-right coordinate of child records.
204      */

205     public void setRectY2( int field_4_rectY2 )
206     {
207         this.field_4_rectY2 = field_4_rectY2;
208     }
209 }
210
Popular Tags