KickJava   Java API By Example, From Geeks To Geeks.

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


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  * This record simply holds the number of shapes in the drawing group and the
25  * last shape id used for this drawing group.
26  *
27  * @author Glen Stampoultzis
28  */

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

46     public int fillFields( byte[] data, int offset, EscherRecordFactory recordFactory )
47     {
48         int bytesRemaining = readHeader( data, offset );
49         int pos = offset + 8;
50         int size = 0;
51         field_1_numShapes = LittleEndian.getInt( data, pos + size ); size += 4;
52         field_2_lastMSOSPID = LittleEndian.getInt( data, pos + size ); size += 4;
53 // bytesRemaining -= size;
54
// remainingData = new byte[bytesRemaining];
55
// System.arraycopy( data, pos + size, remainingData, 0, bytesRemaining );
56
return getRecordSize();
57     }
58
59     /**
60      * This method serializes this escher record into a byte array.
61      *
62      * @param offset The offset into <code>data</code> to start writing the record data to.
63      * @param data The byte array to serialize to.
64      * @param listener A listener to retrieve start and end callbacks. Use a <code>NullEscherSerailizationListener</code> to ignore these events.
65      * @return The number of bytes written.
66      * @see NullEscherSerializationListener
67      */

68     public int serialize( int offset, byte[] data, EscherSerializationListener listener )
69     {
70         listener.beforeRecordSerialize( offset, getRecordId(), this );
71
72         LittleEndian.putShort( data, offset, getOptions() );
73         LittleEndian.putShort( data, offset + 2, getRecordId() );
74         LittleEndian.putInt( data, offset + 4, 8 );
75         LittleEndian.putInt( data, offset + 8, field_1_numShapes );
76         LittleEndian.putInt( data, offset + 12, field_2_lastMSOSPID );
77 // System.arraycopy( remainingData, 0, data, offset + 26, remainingData.length );
78
// int pos = offset + 8 + 18 + remainingData.length;
79

80         listener.afterRecordSerialize( offset + 16, getRecordId(), getRecordSize(), this );
81         return getRecordSize();
82     }
83
84     /**
85      * Returns the number of bytes that are required to serialize this record.
86      *
87      * @return Number of bytes
88      */

89     public int getRecordSize()
90     {
91         return 8 + 8;
92     }
93
94     public short getRecordId()
95     {
96         return RECORD_ID;
97     }
98
99     /**
100      * The short name for this record
101      */

102     public String JavaDoc getRecordName()
103     {
104         return "Dg";
105     }
106
107     /**
108      * Returns the string representation of this record.
109      */

110     public String JavaDoc toString()
111     {
112         String JavaDoc nl = System.getProperty("line.separator");
113
114 // String extraData;
115
// ByteArrayOutputStream b = new ByteArrayOutputStream();
116
// try
117
// {
118
// HexDump.dump(this.remainingData, 0, b, 0);
119
// extraData = b.toString();
120
// }
121
// catch ( Exception e )
122
// {
123
// extraData = "error";
124
// }
125
return getClass().getName() + ":" + nl +
126                 " RecordId: 0x" + HexDump.toHex(RECORD_ID) + nl +
127                 " Options: 0x" + HexDump.toHex(getOptions()) + nl +
128                 " NumShapes: " + field_1_numShapes + nl +
129                 " LastMSOSPID: " + field_2_lastMSOSPID + nl;
130
131     }
132
133     /**
134      * The number of shapes in this drawing group.
135      */

136     public int getNumShapes()
137     {
138         return field_1_numShapes;
139     }
140
141     /**
142      * The number of shapes in this drawing group.
143      */

144     public void setNumShapes( int field_1_numShapes )
145     {
146         this.field_1_numShapes = field_1_numShapes;
147     }
148
149     /**
150      * The last shape id used in this drawing group.
151      */

152     public int getLastMSOSPID()
153     {
154         return field_2_lastMSOSPID;
155     }
156
157     /**
158      * The last shape id used in this drawing group.
159      */

160     public void setLastMSOSPID( int field_2_lastMSOSPID )
161     {
162         this.field_2_lastMSOSPID = field_2_lastMSOSPID;
163     }
164
165     /**
166      * Gets the drawing group id for this record. This is encoded in the
167      * instance part of the option record.
168      *
169      * @return a drawing group id.
170      */

171     public short getDrawingGroupId()
172     {
173         return (short) ( getOptions() >> 4 );
174     }
175
176     public void incrementShapeCount()
177     {
178         this.field_1_numShapes++;
179     }
180 }
181
Popular Tags