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
118
127
128 public LegendRecord(short id, short size, byte [] data, int offset)
129 {
130 super(id, size, data, offset);
131
132 }
133
134
139 protected void validateSid(short id)
140 {
141 if (id != sid)
142 {
143 throw new RecordFormatException("Not a Legend record");
144 }
145 }
146
147 protected void fillFields(byte [] data, short size, int offset)
148 {
149
150 int pos = 0;
151 field_1_xAxisUpperLeft = LittleEndian.getInt(data, pos + 0x0 + offset);
152 field_2_yAxisUpperLeft = LittleEndian.getInt(data, pos + 0x4 + offset);
153 field_3_xSize = LittleEndian.getInt(data, pos + 0x8 + offset);
154 field_4_ySize = LittleEndian.getInt(data, pos + 0xc + offset);
155 field_5_type = data[ pos + 0x10 + offset ];
156 field_6_spacing = data[ pos + 0x11 + offset ];
157 field_7_options = LittleEndian.getShort(data, pos + 0x12 + offset);
158
159 }
160
161 public String toString()
162 {
163 StringBuffer buffer = new StringBuffer();
164
165 buffer.append("[LEGEND]\n");
166 buffer.append(" .xAxisUpperLeft = ")
167 .append("0x").append(HexDump.toHex( getXAxisUpperLeft ()))
168 .append(" (").append( getXAxisUpperLeft() ).append(" )");
169 buffer.append(System.getProperty("line.separator"));
170 buffer.append(" .yAxisUpperLeft = ")
171 .append("0x").append(HexDump.toHex( getYAxisUpperLeft ()))
172 .append(" (").append( getYAxisUpperLeft() ).append(" )");
173 buffer.append(System.getProperty("line.separator"));
174 buffer.append(" .xSize = ")
175 .append("0x").append(HexDump.toHex( getXSize ()))
176 .append(" (").append( getXSize() ).append(" )");
177 buffer.append(System.getProperty("line.separator"));
178 buffer.append(" .ySize = ")
179 .append("0x").append(HexDump.toHex( getYSize ()))
180 .append(" (").append( getYSize() ).append(" )");
181 buffer.append(System.getProperty("line.separator"));
182 buffer.append(" .type = ")
183 .append("0x").append(HexDump.toHex( getType ()))
184 .append(" (").append( getType() ).append(" )");
185 buffer.append(System.getProperty("line.separator"));
186 buffer.append(" .spacing = ")
187 .append("0x").append(HexDump.toHex( getSpacing ()))
188 .append(" (").append( getSpacing() ).append(" )");
189 buffer.append(System.getProperty("line.separator"));
190 buffer.append(" .options = ")
191 .append("0x").append(HexDump.toHex( getOptions ()))
192 .append(" (").append( getOptions() ).append(" )");
193 buffer.append(System.getProperty("line.separator"));
194 buffer.append(" .autoPosition = ").append(isAutoPosition()).append('\n');
195 buffer.append(" .autoSeries = ").append(isAutoSeries()).append('\n');
196 buffer.append(" .autoXPositioning = ").append(isAutoXPositioning()).append('\n');
197 buffer.append(" .autoYPositioning = ").append(isAutoYPositioning()).append('\n');
198 buffer.append(" .vertical = ").append(isVertical()).append('\n');
199 buffer.append(" .dataTable = ").append(isDataTable()).append('\n');
200
201 buffer.append("[/LEGEND]\n");
202 return buffer.toString();
203 }
204
205 public int serialize(int offset, byte[] data)
206 {
207 int pos = 0;
208
209 LittleEndian.putShort(data, 0 + offset, sid);
210 LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4));
211
212 LittleEndian.putInt(data, 4 + offset + pos, field_1_xAxisUpperLeft);
213 LittleEndian.putInt(data, 8 + offset + pos, field_2_yAxisUpperLeft);
214 LittleEndian.putInt(data, 12 + offset + pos, field_3_xSize);
215 LittleEndian.putInt(data, 16 + offset + pos, field_4_ySize);
216 data[ 20 + offset + pos ] = field_5_type;
217 data[ 21 + offset + pos ] = field_6_spacing;
218 LittleEndian.putShort(data, 22 + offset + pos, field_7_options);
219
220 return getRecordSize();
221 }
222
223
226 public int getRecordSize()
227 {
228 return 4 + 4 + 4 + 4 + 4 + 1 + 1 + 2;
229 }
230
231 public short getSid()
232 {
233 return this.sid;
234 }
235
236 public Object clone() {
237 LegendRecord rec = new LegendRecord();
238
239 rec.field_1_xAxisUpperLeft = field_1_xAxisUpperLeft;
240 rec.field_2_yAxisUpperLeft = field_2_yAxisUpperLeft;
241 rec.field_3_xSize = field_3_xSize;
242 rec.field_4_ySize = field_4_ySize;
243 rec.field_5_type = field_5_type;
244 rec.field_6_spacing = field_6_spacing;
245 rec.field_7_options = field_7_options;
246 return rec;
247 }
248
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