1 /
55
56
57 package org.apache.poi.hssf.record;
58
59
60
61 import org.apache.poi.util.*;
62
63
70 public class LegendRecord
71 extends Record
72 {
73 public final static short sid = 0x1015;
74 private int field_1_xAxisUpperLeft;
75 private int field_2_yAxisUpperLeft;
76 private int field_3_xSize;
77 private int field_4_ySize;
78 private byte field_5_type;
79 public final static byte TYPE_BOTTOM = 0;
80 public final static byte TYPE_CORNER = 1;
81 public final static byte TYPE_TOP = 2;
82 public final static byte TYPE_RIGHT = 3;
83 public final static byte TYPE_LEFT = 4;
84 public final static byte TYPE_UNDOCKED = 7;
85 private byte field_6_spacing;
86 public final static byte SPACING_CLOSE = 0;
87 public final static byte SPACING_MEDIUM = 1;
88 public final static byte SPACING_OPEN = 2;
89 private short field_7_options;
90 private BitField autoPosition = new BitField(0x1);
91 private BitField autoSeries = new BitField(0x2);
92 private BitField autoXPositioning = new BitField(0x4);
93 private BitField autoYPositioning = new BitField(0x8);
94 private BitField vertical = new BitField(0x10);
95 private BitField dataTable = new BitField(0x20);
96
97
98 public LegendRecord()
99 {
100
101 }
102
103
111
112 public LegendRecord(short id, short size, byte [] data)
113 {
114 super(id, size, data);
115 }
116
117
126
127 public LegendRecord(short id, short size, byte [] data, int offset)
128 {
129 super(id, size, data, offset);
130 }
131
132
137 protected void validateSid(short id)
138 {
139 if (id != sid)
140 {
141 throw new RecordFormatException("Not a Legend record");
142 }
143 }
144
145 protected void fillFields(byte [] data, short size, int offset)
146 {
147 field_1_xAxisUpperLeft = LittleEndian.getInt(data, 0x0 + offset);
148 field_2_yAxisUpperLeft = LittleEndian.getInt(data, 0x4 + offset);
149 field_3_xSize = LittleEndian.getInt(data, 0x8 + offset);
150 field_4_ySize = LittleEndian.getInt(data, 0xc + offset);
151 field_5_type = data[ 0x10 + offset ];
152 field_6_spacing = data[ 0x11 + offset ];
153 field_7_options = LittleEndian.getShort(data, 0x12 + offset);
154
155 }
156
157 public String toString()
158 {
159 StringBuffer buffer = new StringBuffer();
160
161 buffer.append("[Legend]\n");
162
163 buffer.append(" .xAxisUpperLeft = ")
164 .append("0x")
165 .append(HexDump.toHex((int)getXAxisUpperLeft()))
166 .append(" (").append(getXAxisUpperLeft()).append(" )\n");
167
168 buffer.append(" .yAxisUpperLeft = ")
169 .append("0x")
170 .append(HexDump.toHex((int)getYAxisUpperLeft()))
171 .append(" (").append(getYAxisUpperLeft()).append(" )\n");
172
173 buffer.append(" .xSize = ")
174 .append("0x")
175 .append(HexDump.toHex((int)getXSize()))
176 .append(" (").append(getXSize()).append(" )\n");
177
178 buffer.append(" .ySize = ")
179 .append("0x")
180 .append(HexDump.toHex((int)getYSize()))
181 .append(" (").append(getYSize()).append(" )\n");
182
183 buffer.append(" .type = ")
184 .append("0x")
185 .append(HexDump.toHex((byte)getType()))
186 .append(" (").append(getType()).append(" )\n");
187
188 buffer.append(" .spacing = ")
189 .append("0x")
190 .append(HexDump.toHex((byte)getSpacing()))
191 .append(" (").append(getSpacing()).append(" )\n");
192
193 buffer.append(" .options = ")
194 .append("0x")
195 .append(HexDump.toHex((short)getOptions()))
196 .append(" (").append(getOptions()).append(" )\n");
197 buffer.append(" .autoPosition = ").append(isAutoPosition ()).append('\n');
198 buffer.append(" .autoSeries = ").append(isAutoSeries ()).append('\n');
199 buffer.append(" .autoXPositioning = ").append(isAutoXPositioning ()).append('\n');
200 buffer.append(" .autoYPositioning = ").append(isAutoYPositioning ()).append('\n');
201 buffer.append(" .vertical = ").append(isVertical ()).append('\n');
202 buffer.append(" .dataTable = ").append(isDataTable ()).append('\n');
203
204 buffer.append("[/Legend]\n");
205 return buffer.toString();
206 }
207
208 public int serialize(int offset, byte[] data)
209 {
210 LittleEndian.putShort(data, 0 + offset, sid);
211 LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4));
212
213 LittleEndian.putInt(data, 4 + offset, field_1_xAxisUpperLeft);
214 LittleEndian.putInt(data, 8 + offset, field_2_yAxisUpperLeft);
215 LittleEndian.putInt(data, 12 + offset, field_3_xSize);
216 LittleEndian.putInt(data, 16 + offset, field_4_ySize);
217 data[ 20 + offset ] = field_5_type;
218 data[ 21 + offset ] = field_6_spacing;
219 LittleEndian.putShort(data, 22 + offset, field_7_options);
220
221 return getRecordSize();
222 }
223
224
227 public int getRecordSize()
228 {
229 return 4 + 4 + 4 + 4 + 4 + 1 + 1 + 2;
230 }
231
232 public short getSid()
233 {
234 return this.sid;
235 }
236
237 public Object clone() {
238 LegendRecord rec = new LegendRecord();
239
240 rec.field_1_xAxisUpperLeft = field_1_xAxisUpperLeft;
241 rec.field_2_yAxisUpperLeft = field_2_yAxisUpperLeft;
242 rec.field_3_xSize = field_3_xSize;
243 rec.field_4_ySize = field_4_ySize;
244 rec.field_5_type = field_5_type;
245 rec.field_6_spacing = field_6_spacing;
246 rec.field_7_options = field_7_options;
247
248 return rec;
249 }
250
251
252
255 public int getXAxisUpperLeft()
256 {
257 return field_1_xAxisUpperLeft;
258 }
259
260
263 public void setXAxisUpperLeft(int field_1_xAxisUpperLeft)
264 {
265 this.field_1_xAxisUpperLeft = field_1_xAxisUpperLeft;
266 }
267
268
271 public int getYAxisUpperLeft()
272 {
273 return field_2_yAxisUpperLeft;
274 }
275
276
279 public void setYAxisUpperLeft(int field_2_yAxisUpperLeft)
280 {
281 this.field_2_yAxisUpperLeft = field_2_yAxisUpperLeft;
282 }
283
284
287 public int getXSize()
288 {
289 return field_3_xSize;
290 }
291
292
295 public void setXSize(int field_3_xSize)
296 {
297 this.field_3_xSize = field_3_xSize;
298 }
299
300
303 public int getYSize()
304 {
305 return field_4_ySize;
306 }
307
308
311 public void setYSize(int field_4_ySize)
312 {
313 this.field_4_ySize = field_4_ySize;
314 }
315
316
327 public byte getType()
328 {
329 return field_5_type;
330 }
331
332
344 public void setType(byte field_5_type)
345 {
346 this.field_5_type = field_5_type;
347 }
348
349
357 public byte getSpacing()
358 {
359 return field_6_spacing;
360 }
361
362
371 public void setSpacing(byte field_6_spacing)
372 {
373 this.field_6_spacing = field_6_spacing;
374 }
375
376
379 public short getOptions()
380 {
381 return field_7_options;
382 }
383
384
387 public void setOptions(short field_7_options)
388 {
389 this.field_7_options = field_7_options;
390 }
391
392
396 public void setAutoPosition(boolean value)
397 {
398 field_7_options = autoPosition.setShortBoolean(field_7_options, value);
399 }
400
401
405 public boolean isAutoPosition()
406 {
407 return autoPosition.isSet(field_7_options);
408 }
409
410
414 public void setAutoSeries(boolean value)
415 {
416 field_7_options = autoSeries.setShortBoolean(field_7_options, value);
417 }
418
419
423 public boolean isAutoSeries()
424 {
425 return autoSeries.isSet(field_7_options);
426 }
427
428
432 public void setAutoXPositioning(boolean value)
433 {
434 field_7_options = autoXPositioning.setShortBoolean(field_7_options, value);
435 }
436
437
441 public boolean isAutoXPositioning()
442 {
443 return autoXPositioning.isSet(field_7_options);
444 }
445
446
450 public void setAutoYPositioning(boolean value)
451 {
452 field_7_options = autoYPositioning.setShortBoolean(field_7_options, value);
453 }
454
455
459 public boolean isAutoYPositioning()
460 {
461 return autoYPositioning.isSet(field_7_options);
462 }
463
464
468 public void setVertical(boolean value)
469 {
470 field_7_options = vertical.setShortBoolean(field_7_options, value);
471 }
472
473
477 public boolean isVertical()
478 {
479 return vertical.isSet(field_7_options);
480 }
481
482
486 public void setDataTable(boolean value)
487 {
488 field_7_options = dataTable.setShortBoolean(field_7_options, value);
489 }
490
491
495 public boolean isDataTable()
496 {
497 return dataTable.isSet(field_7_options);
498 }
499
500
501 }
502
503
504
505
506