KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hssf > record > AreaFormatRecord


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
19
20 package org.apache.poi.hssf.record;
21
22
23
24 import org.apache.poi.util.*;
25
26 /**
27  * The area format record is used to define the colours and patterns for an area.
28  * NOTE: This source is automatically generated please do not modify this file. Either subclass or
29  * remove the record in src/records/definitions.
30
31  * @author Glen Stampoultzis (glens at apache.org)
32  */

33 public class AreaFormatRecord
34     extends Record
35 {
36     public final static short sid = 0x100a;
37     private int field_1_foregroundColor;
38     private int field_2_backgroundColor;
39     private short field_3_pattern;
40     private short field_4_formatFlags;
41     private BitField automatic = new BitField(0x1);
42     private BitField invert = new BitField(0x2);
43     private short field_5_forecolorIndex;
44     private short field_6_backcolorIndex;
45
46
47     public AreaFormatRecord()
48     {
49
50     }
51
52     /**
53      * Constructs a AreaFormat record and sets its fields appropriately.
54      *
55      * @param id id must be 0x100a or an exception
56      * will be throw upon validation
57      * @param size size the size of the data area of the record
58      * @param data data of the record (should not contain sid/len)
59      */

60
61     public AreaFormatRecord(short id, short size, byte [] data)
62     {
63         super(id, size, data);
64     
65     }
66
67     /**
68      * Constructs a AreaFormat record and sets its fields appropriately.
69      *
70      * @param id id must be 0x100a or an exception
71      * will be throw upon validation
72      * @param size size the size of the data area of the record
73      * @param data data of the record (should not contain sid/len)
74      * @param offset of the record's data
75      */

76
77     public AreaFormatRecord(short id, short size, byte [] data, int offset)
78     {
79         super(id, size, data, offset);
80     
81     }
82
83     /**
84      * Checks the sid matches the expected side for this record
85      *
86      * @param id the expected sid.
87      */

88     protected void validateSid(short id)
89     {
90         if (id != sid)
91         {
92             throw new RecordFormatException("Not a AreaFormat record");
93         }
94     }
95
96     protected void fillFields(byte [] data, short size, int offset)
97     {
98
99         int pos = 0;
100         field_1_foregroundColor = LittleEndian.getInt(data, pos + 0x0 + offset);
101         field_2_backgroundColor = LittleEndian.getInt(data, pos + 0x4 + offset);
102         field_3_pattern = LittleEndian.getShort(data, pos + 0x8 + offset);
103         field_4_formatFlags = LittleEndian.getShort(data, pos + 0xa + offset);
104         field_5_forecolorIndex = LittleEndian.getShort(data, pos + 0xc + offset);
105         field_6_backcolorIndex = LittleEndian.getShort(data, pos + 0xe + offset);
106
107     }
108
109     public String JavaDoc toString()
110     {
111         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
112
113         buffer.append("[AREAFORMAT]\n");
114         buffer.append(" .foregroundColor = ")
115             .append("0x").append(HexDump.toHex( getForegroundColor ()))
116             .append(" (").append( getForegroundColor() ).append(" )");
117         buffer.append(System.getProperty("line.separator"));
118         buffer.append(" .backgroundColor = ")
119             .append("0x").append(HexDump.toHex( getBackgroundColor ()))
120             .append(" (").append( getBackgroundColor() ).append(" )");
121         buffer.append(System.getProperty("line.separator"));
122         buffer.append(" .pattern = ")
123             .append("0x").append(HexDump.toHex( getPattern ()))
124             .append(" (").append( getPattern() ).append(" )");
125         buffer.append(System.getProperty("line.separator"));
126         buffer.append(" .formatFlags = ")
127             .append("0x").append(HexDump.toHex( getFormatFlags ()))
128             .append(" (").append( getFormatFlags() ).append(" )");
129         buffer.append(System.getProperty("line.separator"));
130         buffer.append(" .automatic = ").append(isAutomatic()).append('\n');
131         buffer.append(" .invert = ").append(isInvert()).append('\n');
132         buffer.append(" .forecolorIndex = ")
133             .append("0x").append(HexDump.toHex( getForecolorIndex ()))
134             .append(" (").append( getForecolorIndex() ).append(" )");
135         buffer.append(System.getProperty("line.separator"));
136         buffer.append(" .backcolorIndex = ")
137             .append("0x").append(HexDump.toHex( getBackcolorIndex ()))
138             .append(" (").append( getBackcolorIndex() ).append(" )");
139         buffer.append(System.getProperty("line.separator"));
140
141         buffer.append("[/AREAFORMAT]\n");
142         return buffer.toString();
143     }
144
145     public int serialize(int offset, byte[] data)
146     {
147         int pos = 0;
148
149         LittleEndian.putShort(data, 0 + offset, sid);
150         LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4));
151
152         LittleEndian.putInt(data, 4 + offset + pos, field_1_foregroundColor);
153         LittleEndian.putInt(data, 8 + offset + pos, field_2_backgroundColor);
154         LittleEndian.putShort(data, 12 + offset + pos, field_3_pattern);
155         LittleEndian.putShort(data, 14 + offset + pos, field_4_formatFlags);
156         LittleEndian.putShort(data, 16 + offset + pos, field_5_forecolorIndex);
157         LittleEndian.putShort(data, 18 + offset + pos, field_6_backcolorIndex);
158
159         return getRecordSize();
160     }
161
162     /**
163      * Size of record (exluding 4 byte header)
164      */

165     public int getRecordSize()
166     {
167         return 4 + 4 + 4 + 2 + 2 + 2 + 2;
168     }
169
170     public short getSid()
171     {
172         return this.sid;
173     }
174
175     public Object JavaDoc clone() {
176         AreaFormatRecord rec = new AreaFormatRecord();
177     
178         rec.field_1_foregroundColor = field_1_foregroundColor;
179         rec.field_2_backgroundColor = field_2_backgroundColor;
180         rec.field_3_pattern = field_3_pattern;
181         rec.field_4_formatFlags = field_4_formatFlags;
182         rec.field_5_forecolorIndex = field_5_forecolorIndex;
183         rec.field_6_backcolorIndex = field_6_backcolorIndex;
184         return rec;
185     }
186
187
188
189
190     /**
191      * Get the foreground color field for the AreaFormat record.
192      */

193     public int getForegroundColor()
194     {
195         return field_1_foregroundColor;
196     }
197
198     /**
199      * Set the foreground color field for the AreaFormat record.
200      */

201     public void setForegroundColor(int field_1_foregroundColor)
202     {
203         this.field_1_foregroundColor = field_1_foregroundColor;
204     }
205
206     /**
207      * Get the background color field for the AreaFormat record.
208      */

209     public int getBackgroundColor()
210     {
211         return field_2_backgroundColor;
212     }
213
214     /**
215      * Set the background color field for the AreaFormat record.
216      */

217     public void setBackgroundColor(int field_2_backgroundColor)
218     {
219         this.field_2_backgroundColor = field_2_backgroundColor;
220     }
221
222     /**
223      * Get the pattern field for the AreaFormat record.
224      */

225     public short getPattern()
226     {
227         return field_3_pattern;
228     }
229
230     /**
231      * Set the pattern field for the AreaFormat record.
232      */

233     public void setPattern(short field_3_pattern)
234     {
235         this.field_3_pattern = field_3_pattern;
236     }
237
238     /**
239      * Get the format flags field for the AreaFormat record.
240      */

241     public short getFormatFlags()
242     {
243         return field_4_formatFlags;
244     }
245
246     /**
247      * Set the format flags field for the AreaFormat record.
248      */

249     public void setFormatFlags(short field_4_formatFlags)
250     {
251         this.field_4_formatFlags = field_4_formatFlags;
252     }
253
254     /**
255      * Get the forecolor index field for the AreaFormat record.
256      */

257     public short getForecolorIndex()
258     {
259         return field_5_forecolorIndex;
260     }
261
262     /**
263      * Set the forecolor index field for the AreaFormat record.
264      */

265     public void setForecolorIndex(short field_5_forecolorIndex)
266     {
267         this.field_5_forecolorIndex = field_5_forecolorIndex;
268     }
269
270     /**
271      * Get the backcolor index field for the AreaFormat record.
272      */

273     public short getBackcolorIndex()
274     {
275         return field_6_backcolorIndex;
276     }
277
278     /**
279      * Set the backcolor index field for the AreaFormat record.
280      */

281     public void setBackcolorIndex(short field_6_backcolorIndex)
282     {
283         this.field_6_backcolorIndex = field_6_backcolorIndex;
284     }
285
286     /**
287      * Sets the automatic field value.
288      * automatic formatting
289      */

290     public void setAutomatic(boolean value)
291     {
292         field_4_formatFlags = automatic.setShortBoolean(field_4_formatFlags, value);
293     }
294
295     /**
296      * automatic formatting
297      * @return the automatic field value.
298      */

299     public boolean isAutomatic()
300     {
301         return automatic.isSet(field_4_formatFlags);
302     }
303
304     /**
305      * Sets the invert field value.
306      * swap foreground and background colours when data is negative
307      */

308     public void setInvert(boolean value)
309     {
310         field_4_formatFlags = invert.setShortBoolean(field_4_formatFlags, value);
311     }
312
313     /**
314      * swap foreground and background colours when data is negative
315      * @return the invert field value.
316      */

317     public boolean isInvert()
318     {
319         return invert.isSet(field_4_formatFlags);
320     }
321
322
323 } // END OF CLASS
324

325
326
327
328
Popular Tags