KickJava   Java API By Example, From Geeks To Geeks.

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


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  * A list of the most recently used colours for the drawings contained in
26  * this document.
27  *
28  * @author Glen Stampoultzis (glens at apache.org)
29  */

30 public class EscherSplitMenuColorsRecord
31     extends EscherRecord
32 {
33     public static final short RECORD_ID = (short) 0xF11E;
34     public static final String JavaDoc RECORD_DESCRIPTION = "MsofbtSplitMenuColors";
35
36     private int field_1_color1;
37     private int field_2_color2;
38     private int field_3_color3;
39     private int field_4_color4;
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_color1 = LittleEndian.getInt( data, pos + size );size+=4;
55         field_2_color2 = LittleEndian.getInt( data, pos + size );size+=4;
56         field_3_color3 = LittleEndian.getInt( data, pos + size );size+=4;
57         field_4_color4 = LittleEndian.getInt( data, pos + size );size+=4;
58         bytesRemaining -= size;
59         if (bytesRemaining != 0)
60             throw new RecordFormatException("Expecting no remaining data but got " + bytesRemaining + " byte(s).");
61         return 8 + size + bytesRemaining;
62     }
63
64     /**
65      * This method serializes this escher record into a byte array.
66      *
67      * @param offset The offset into <code>data</code> to start writing the record data to.
68      * @param data The byte array to serialize to.
69      * @param listener A listener to retrieve start and end callbacks. Use a <code>NullEscherSerailizationListener</code> to ignore these events.
70      * @return The number of bytes written.
71      *
72      * @see NullEscherSerializationListener
73      */

74     public int serialize( int offset, byte[] data, EscherSerializationListener listener )
75     {
76 // int field_2_numIdClusters = field_5_fileIdClusters.length + 1;
77
listener.beforeRecordSerialize( offset, getRecordId(), this );
78
79         int pos = offset;
80         LittleEndian.putShort( data, pos, getOptions() ); pos += 2;
81         LittleEndian.putShort( data, pos, getRecordId() ); pos += 2;
82         int remainingBytes = getRecordSize() - 8;
83
84         LittleEndian.putInt( data, pos, remainingBytes ); pos += 4;
85         LittleEndian.putInt( data, pos, field_1_color1 ); pos += 4;
86         LittleEndian.putInt( data, pos, field_2_color2 ); pos += 4;
87         LittleEndian.putInt( data, pos, field_3_color3 ); pos += 4;
88         LittleEndian.putInt( data, pos, field_4_color4 ); pos += 4;
89         listener.afterRecordSerialize( pos, getRecordId(), pos - offset, this );
90         return getRecordSize();
91     }
92
93     /**
94      * Returns the number of bytes that are required to serialize this record.
95      *
96      * @return Number of bytes
97      */

98     public int getRecordSize()
99     {
100         return 8 + 4 * 4;
101     }
102
103     /**
104      * @return the 16 bit identifer for this record.
105      */

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

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

122     public String JavaDoc toString()
123     {
124         String JavaDoc nl = System.getProperty("line.separator");
125
126 // String extraData;
127
// ByteArrayOutputStream b = new ByteArrayOutputStream();
128
// try
129
// {
130
// HexDump.dump(this.remainingData, 0, b, 0);
131
// extraData = b.toString();
132
// }
133
// catch ( Exception e )
134
// {
135
// extraData = "error";
136
// }
137
return getClass().getName() + ":" + nl +
138                 " RecordId: 0x" + HexDump.toHex(RECORD_ID) + nl +
139                 " Options: 0x" + HexDump.toHex(getOptions()) + nl +
140                 " Color1: 0x" + HexDump.toHex(field_1_color1) + nl +
141                 " Color2: 0x" + HexDump.toHex(field_2_color2) + nl +
142                 " Color3: 0x" + HexDump.toHex(field_3_color3) + nl +
143                 " Color4: 0x" + HexDump.toHex(field_4_color4) + nl +
144                 "";
145
146     }
147
148     public int getColor1()
149     {
150         return field_1_color1;
151     }
152
153     public void setColor1( int field_1_color1 )
154     {
155         this.field_1_color1 = field_1_color1;
156     }
157
158     public int getColor2()
159     {
160         return field_2_color2;
161     }
162
163     public void setColor2( int field_2_color2 )
164     {
165         this.field_2_color2 = field_2_color2;
166     }
167
168     public int getColor3()
169     {
170         return field_3_color3;
171     }
172
173     public void setColor3( int field_3_color3 )
174     {
175         this.field_3_color3 = field_3_color3;
176     }
177
178     public int getColor4()
179     {
180         return field_4_color4;
181     }
182
183     public void setColor4( int field_4_color4 )
184     {
185         this.field_4_color4 = field_4_color4;
186     }
187
188 }
189
Popular Tags