1 /
55
56
57 package org.apache.poi.hssf.record;
58
59
60
61 import org.apache.poi.util.BitField;
62 import org.apache.poi.util.LittleEndian;
63 import org.apache.poi.util.StringUtil;
64 import org.apache.poi.util.HexDump;
65
66
73 public class LegendRecord
74 extends Record
75 {
76 public final static short sid = 0x1015;
77 private int field_1_xPosition;
78 private int field_2_yPosition;
79 private int field_3_xSize;
80 private int field_4_ySize;
81 private byte field_5_type;
82 public final static byte TYPE_BOTTOM = 0;
83 public final static byte TYPE_CORNER = 1;
84 public final static byte TYPE_TOP = 2;
85 public final static byte TYPE_RIGHT = 3;
86 public final static byte TYPE_LEFT = 4;
87 public final static byte TYPE_NOT_DOCKED = 7;
88 private byte field_6_spacing;
89 public final static byte SPACING_CLOSE = 0;
90 public final static byte SPACING_MEDIUM = 1;
91 public final static byte SPACING_OPEN = 2;
92 private short field_7_options;
93 private BitField autoPosition = new BitField(0x1);
94 private BitField autoSeries = new BitField(0x2);
95 private BitField autoPosX = new BitField(0x4);
96 private BitField autoPosY = new BitField(0x8);
97 private BitField vert = new BitField(0x10);
98 private BitField containsDataTable = new BitField(0x20);
99
100
101 public LegendRecord()
102 {
103
104 }
105
106
114
115 public LegendRecord(short id, short size, byte [] data)
116 {
117 super(id, size, data);
118 }
119
120
129
130 public LegendRecord(short id, short size, byte [] data, int offset)
131 {
132 super(id, size, data, offset);
133 }
134
135
140 protected void validateSid(short id)
141 {
142 if (id != sid)
143 {
144 throw new RecordFormatException("Not a Legend record");
145 }
146 }
147
148 protected void fillFields(byte [] data, short size, int offset)
149 {
150 field_1_xPosition = LittleEndian.getInt(data, 0x0 + offset);
151 field_2_yPosition = LittleEndian.getInt(data, 0x4 + offset);
152 field_3_xSize = LittleEndian.getInt(data, 0x8 + offset);
153 field_4_ySize = LittleEndian.getInt(data, 0xc + offset);
154 field_5_type = data[ 0x10 + offset ];
155 field_6_spacing = data[ 0x11 + offset ];
156 field_7_options = LittleEndian.getShort(data, 0x12 + offset);
157
158 }
159
160 public String toString()
161 {
162 StringBuffer buffer = new StringBuffer();
163
164 buffer.append("[Legend]\n");
165
166 buffer.append(" .xPosition = ")
167 .append("0x")
168 .append(HexDump.toHex((int)getXPosition()))
169 .append(" (").append(getXPosition()).append(" )\n");
170
171 buffer.append(" .yPosition = ")
172 .append("0x")
173 .append(HexDump.toHex((int)getYPosition()))
174 .append(" (").append(getYPosition()).append(" )\n");
175
176 buffer.append(" .xSize = ")
177 .append("0x")
178 .append(HexDump.toHex((int)getXSize()))
179 .append(" (").append(getXSize()).append(" )\n");
180
181 buffer.append(" .ySize = ")
182 .append("0x")
183 .append(HexDump.toHex((int)getYSize()))
184 .append(" (").append(getYSize()).append(" )\n");
185
186 buffer.append(" .type = ")
187 .append("0x")
188 .append(HexDump.toHex((byte)getType()))
189 .append(" (").append(getType()).append(" )\n");
190
191 buffer.append(" .spacing = ")
192 .append("0x")
193 .append(HexDump.toHex((byte)getSpacing()))
194 .append(" (").append(getSpacing()).append(" )\n");
195
196 buffer.append(" .options = ")
197 .append("0x")
198 .append(HexDump.toHex((short)getOptions()))
199 .append(" (").append(getOptions()).append(" )\n");
200 buffer.append(" .autoPosition = ").append(isAutoPosition ()).append('\n');
201 buffer.append(" .autoSeries = ").append(isAutoSeries ()).append('\n');
202 buffer.append(" .autoPosX = ").append(isAutoPosX ()).append('\n');
203 buffer.append(" .autoPosY = ").append(isAutoPosY ()).append('\n');
204 buffer.append(" .vert = ").append(isVert ()).append('\n');
205 buffer.append(" .containsDataTable = ").append(isContainsDataTable ()).append('\n');
206
207 buffer.append("[/Legend]\n");
208 return buffer.toString();
209 }
210
211 public int serialize(int offset, byte[] data)
212 {
213 LittleEndian.putShort(data, 0 + offset, sid);
214 LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4));
215
216 LittleEndian.putInt(data, 4 + offset, field_1_xPosition);
217 LittleEndian.putInt(data, 8 + offset, field_2_yPosition);
218 LittleEndian.putInt(data, 12 + offset, field_3_xSize);
219 LittleEndian.putInt(data, 16 + offset, field_4_ySize);
220 data[ 20 + offset ] = field_5_type;
221 data[ 21 + offset ] = field_6_spacing;
222 LittleEndian.putShort(data, 22 + offset, field_7_options);
223
224 return getRecordSize();
225 }
226
227
230 public int getRecordSize()
231 {
232 return 4 + 4 + 4 + 4 + 4 + 1 + 1 + 2;
233 }
234
235 public short getSid()
236 {
237 return this.sid;
238 }
239
240
241
244 public int getXPosition()
245 {
246 return field_1_xPosition;
247 }
248
249
252 public void setXPosition(int field_1_xPosition)
253 {
254 this.field_1_xPosition = field_1_xPosition;
255 }
256
257
260 public int getYPosition()
261 {
262 return field_2_yPosition;
263 }
264
265
268 public void setYPosition(int field_2_yPosition)
269 {
270 this.field_2_yPosition = field_2_yPosition;
271 }
272
273
276 public int getXSize()
277 {
278 return field_3_xSize;
279 }
280
281
284 public void setXSize(int field_3_xSize)
285 {
286 this.field_3_xSize = field_3_xSize;
287 }
288
289
292 public int getYSize()
293 {
294 return field_4_ySize;
295 }
296
297
300 public void setYSize(int field_4_ySize)
301 {
302 this.field_4_ySize = field_4_ySize;
303 }
304
305
316 public byte getType()
317 {
318 return field_5_type;
319 }
320
321
333 public void setType(byte field_5_type)
334 {
335 this.field_5_type = field_5_type;
336 }
337
338
346 public byte getSpacing()
347 {
348 return field_6_spacing;
349 }
350
351
360 public void setSpacing(byte field_6_spacing)
361 {
362 this.field_6_spacing = field_6_spacing;
363 }
364
365
368 public short getOptions()
369 {
370 return field_7_options;
371 }
372
373
376 public void setOptions(short field_7_options)
377 {
378 this.field_7_options = field_7_options;
379 }
380
381
385 public void setAutoPosition(boolean value)
386 {
387 field_7_options = autoPosition.setShortBoolean(field_7_options, value);
388 }
389
390
394 public boolean isAutoPosition()
395 {
396 return autoPosition.isSet(field_7_options);
397 }
398
399
403 public void setAutoSeries(boolean value)
404 {
405 field_7_options = autoSeries.setShortBoolean(field_7_options, value);
406 }
407
408
412 public boolean isAutoSeries()
413 {
414 return autoSeries.isSet(field_7_options);
415 }
416
417
421 public void setAutoPosX(boolean value)
422 {
423 field_7_options = autoPosX.setShortBoolean(field_7_options, value);
424 }
425
426
430 public boolean isAutoPosX()
431 {
432 return autoPosX.isSet(field_7_options);
433 }
434
435
439 public void setAutoPosY(boolean value)
440 {
441 field_7_options = autoPosY.setShortBoolean(field_7_options, value);
442 }
443
444
448 public boolean isAutoPosY()
449 {
450 return autoPosY.isSet(field_7_options);
451 }
452
453
457 public void setVert(boolean value)
458 {
459 field_7_options = vert.setShortBoolean(field_7_options, value);
460 }
461
462
466 public boolean isVert()
467 {
468 return vert.isSet(field_7_options);
469 }
470
471
475 public void setContainsDataTable(boolean value)
476 {
477 field_7_options = containsDataTable.setShortBoolean(field_7_options, value);
478 }
479
480
484 public boolean isContainsDataTable()
485 {
486 return containsDataTable.isSet(field_7_options);
487 }
488
489
490 }
491
492
493
494
495