1 /
55
56
57 package org.apache.poi.hssf.record;
58
59
60
61 import org.apache.poi.util.*;
62
63
70 public class AreaFormatRecord
71 extends Record
72 {
73 public final static short sid = 0x100a;
74 private int field_1_foregroundColor;
75 private int field_2_backgroundColor;
76 private short field_3_pattern;
77 private short field_4_formatFlags;
78 private BitField automatic = new BitField(0x1);
79 private BitField invert = new BitField(0x2);
80 private short field_5_forecolorIndex;
81 private short field_6_backcolorIndex;
82
83
84 public AreaFormatRecord()
85 {
86
87 }
88
89
97
98 public AreaFormatRecord(short id, short size, byte [] data)
99 {
100 super(id, size, data);
101 }
102
103
112
113 public AreaFormatRecord(short id, short size, byte [] data, int offset)
114 {
115 super(id, size, data, offset);
116 }
117
118
123 protected void validateSid(short id)
124 {
125 if (id != sid)
126 {
127 throw new RecordFormatException("Not a AreaFormat record");
128 }
129 }
130
131 protected void fillFields(byte [] data, short size, int offset)
132 {
133 field_1_foregroundColor = LittleEndian.getInt(data, 0x0 + offset);
134 field_2_backgroundColor = LittleEndian.getInt(data, 0x4 + offset);
135 field_3_pattern = LittleEndian.getShort(data, 0x8 + offset);
136 field_4_formatFlags = LittleEndian.getShort(data, 0xa + offset);
137 field_5_forecolorIndex = LittleEndian.getShort(data, 0xc + offset);
138 field_6_backcolorIndex = LittleEndian.getShort(data, 0xe + offset);
139
140 }
141
142 public String toString()
143 {
144 StringBuffer buffer = new StringBuffer();
145
146 buffer.append("[AreaFormat]\n");
147
148 buffer.append(" .foregroundColor = ")
149 .append("0x")
150 .append(HexDump.toHex((int)getForegroundColor()))
151 .append(" (").append(getForegroundColor()).append(" )\n");
152
153 buffer.append(" .backgroundColor = ")
154 .append("0x")
155 .append(HexDump.toHex((int)getBackgroundColor()))
156 .append(" (").append(getBackgroundColor()).append(" )\n");
157
158 buffer.append(" .pattern = ")
159 .append("0x")
160 .append(HexDump.toHex((short)getPattern()))
161 .append(" (").append(getPattern()).append(" )\n");
162
163 buffer.append(" .formatFlags = ")
164 .append("0x")
165 .append(HexDump.toHex((short)getFormatFlags()))
166 .append(" (").append(getFormatFlags()).append(" )\n");
167 buffer.append(" .automatic = ").append(isAutomatic ()).append('\n');
168 buffer.append(" .invert = ").append(isInvert ()).append('\n');
169
170 buffer.append(" .forecolorIndex = ")
171 .append("0x")
172 .append(HexDump.toHex((short)getForecolorIndex()))
173 .append(" (").append(getForecolorIndex()).append(" )\n");
174
175 buffer.append(" .backcolorIndex = ")
176 .append("0x")
177 .append(HexDump.toHex((short)getBackcolorIndex()))
178 .append(" (").append(getBackcolorIndex()).append(" )\n");
179
180 buffer.append("[/AreaFormat]\n");
181 return buffer.toString();
182 }
183
184 public int serialize(int offset, byte[] data)
185 {
186 LittleEndian.putShort(data, 0 + offset, sid);
187 LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4));
188
189 LittleEndian.putInt(data, 4 + offset, field_1_foregroundColor);
190 LittleEndian.putInt(data, 8 + offset, field_2_backgroundColor);
191 LittleEndian.putShort(data, 12 + offset, field_3_pattern);
192 LittleEndian.putShort(data, 14 + offset, field_4_formatFlags);
193 LittleEndian.putShort(data, 16 + offset, field_5_forecolorIndex);
194 LittleEndian.putShort(data, 18 + offset, field_6_backcolorIndex);
195
196 return getRecordSize();
197 }
198
199
202 public int getRecordSize()
203 {
204 return 4 + 4 + 4 + 2 + 2 + 2 + 2;
205 }
206
207 public short getSid()
208 {
209 return this.sid;
210 }
211
212 public Object clone() {
213 AreaFormatRecord rec = new AreaFormatRecord();
214
215 rec.field_1_foregroundColor = field_1_foregroundColor;
216 rec.field_2_backgroundColor = field_2_backgroundColor;
217 rec.field_3_pattern = field_3_pattern;
218 rec.field_4_formatFlags = field_4_formatFlags;
219 rec.field_5_forecolorIndex = field_5_forecolorIndex;
220 rec.field_6_backcolorIndex = field_6_backcolorIndex;
221
222 return rec;
223 }
224
225
226
229 public int getForegroundColor()
230 {
231 return field_1_foregroundColor;
232 }
233
234
237 public void setForegroundColor(int field_1_foregroundColor)
238 {
239 this.field_1_foregroundColor = field_1_foregroundColor;
240 }
241
242
245 public int getBackgroundColor()
246 {
247 return field_2_backgroundColor;
248 }
249
250
253 public void setBackgroundColor(int field_2_backgroundColor)
254 {
255 this.field_2_backgroundColor = field_2_backgroundColor;
256 }
257
258
261 public short getPattern()
262 {
263 return field_3_pattern;
264 }
265
266
269 public void setPattern(short field_3_pattern)
270 {
271 this.field_3_pattern = field_3_pattern;
272 }
273
274
277 public short getFormatFlags()
278 {
279 return field_4_formatFlags;
280 }
281
282
285 public void setFormatFlags(short field_4_formatFlags)
286 {
287 this.field_4_formatFlags = field_4_formatFlags;
288 }
289
290
293 public short getForecolorIndex()
294 {
295 return field_5_forecolorIndex;
296 }
297
298
301 public void setForecolorIndex(short field_5_forecolorIndex)
302 {
303 this.field_5_forecolorIndex = field_5_forecolorIndex;
304 }
305
306
309 public short getBackcolorIndex()
310 {
311 return field_6_backcolorIndex;
312 }
313
314
317 public void setBackcolorIndex(short field_6_backcolorIndex)
318 {
319 this.field_6_backcolorIndex = field_6_backcolorIndex;
320 }
321
322
326 public void setAutomatic(boolean value)
327 {
328 field_4_formatFlags = automatic.setShortBoolean(field_4_formatFlags, value);
329 }
330
331
335 public boolean isAutomatic()
336 {
337 return automatic.isSet(field_4_formatFlags);
338 }
339
340
344 public void setInvert(boolean value)
345 {
346 field_4_formatFlags = invert.setShortBoolean(field_4_formatFlags, value);
347 }
348
349
353 public boolean isInvert()
354 {
355 return invert.isSet(field_4_formatFlags);
356 }
357
358
359 }
360
361
362
363
364