1 2 17 18 19 20 package org.apache.poi.hssf.record; 21 22 23 24 import org.apache.poi.util.*; 25 26 33 public class LegendRecord 34 extends Record 35 { 36 public final static short sid = 0x1015; 37 private int field_1_xAxisUpperLeft; 38 private int field_2_yAxisUpperLeft; 39 private int field_3_xSize; 40 private int field_4_ySize; 41 private byte field_5_type; 42 public final static byte TYPE_BOTTOM = 0; 43 public final static byte TYPE_CORNER = 1; 44 public final static byte TYPE_TOP = 2; 45 public final static byte TYPE_RIGHT = 3; 46 public final static byte TYPE_LEFT = 4; 47 public final static byte TYPE_UNDOCKED = 7; 48 private byte field_6_spacing; 49 public final static byte SPACING_CLOSE = 0; 50 public final static byte SPACING_MEDIUM = 1; 51 public final static byte SPACING_OPEN = 2; 52 private short field_7_options; 53 private BitField autoPosition = new BitField(0x1); 54 private BitField autoSeries = new BitField(0x2); 55 private BitField autoXPositioning = new BitField(0x4); 56 private BitField autoYPositioning = new BitField(0x8); 57 private BitField vertical = new BitField(0x10); 58 private BitField dataTable = new BitField(0x20); 59 60 61 public LegendRecord() 62 { 63 64 } 65 66 74 75 public LegendRecord(short id, short size, byte [] data) 76 { 77 super(id, size, data); 78 79 } 80 81 90 91 public LegendRecord(short id, short size, byte [] data, int offset) 92 { 93 super(id, size, data, offset); 94 95 } 96 97 102 protected void validateSid(short id) 103 { 104 if (id != sid) 105 { 106 throw new RecordFormatException("Not a Legend record"); 107 } 108 } 109 110 protected void fillFields(byte [] data, short size, int offset) 111 { 112 113 int pos = 0; 114 field_1_xAxisUpperLeft = LittleEndian.getInt(data, pos + 0x0 + offset); 115 field_2_yAxisUpperLeft = LittleEndian.getInt(data, pos + 0x4 + offset); 116 field_3_xSize = LittleEndian.getInt(data, pos + 0x8 + offset); 117 field_4_ySize = LittleEndian.getInt(data, pos + 0xc + offset); 118 field_5_type = data[ pos + 0x10 + offset ]; 119 field_6_spacing = data[ pos + 0x11 + offset ]; 120 field_7_options = LittleEndian.getShort(data, pos + 0x12 + offset); 121 122 } 123 124 public String toString() 125 { 126 StringBuffer buffer = new StringBuffer (); 127 128 buffer.append("[LEGEND]\n"); 129 buffer.append(" .xAxisUpperLeft = ") 130 .append("0x").append(HexDump.toHex( getXAxisUpperLeft ())) 131 .append(" (").append( getXAxisUpperLeft() ).append(" )"); 132 buffer.append(System.getProperty("line.separator")); 133 buffer.append(" .yAxisUpperLeft = ") 134 .append("0x").append(HexDump.toHex( getYAxisUpperLeft ())) 135 .append(" (").append( getYAxisUpperLeft() ).append(" )"); 136 buffer.append(System.getProperty("line.separator")); 137 buffer.append(" .xSize = ") 138 .append("0x").append(HexDump.toHex( getXSize ())) 139 .append(" (").append( getXSize() ).append(" )"); 140 buffer.append(System.getProperty("line.separator")); 141 buffer.append(" .ySize = ") 142 .append("0x").append(HexDump.toHex( getYSize ())) 143 .append(" (").append( getYSize() ).append(" )"); 144 buffer.append(System.getProperty("line.separator")); 145 buffer.append(" .type = ") 146 .append("0x").append(HexDump.toHex( getType ())) 147 .append(" (").append( getType() ).append(" )"); 148 buffer.append(System.getProperty("line.separator")); 149 buffer.append(" .spacing = ") 150 .append("0x").append(HexDump.toHex( getSpacing ())) 151 .append(" (").append( getSpacing() ).append(" )"); 152 buffer.append(System.getProperty("line.separator")); 153 buffer.append(" .options = ") 154 .append("0x").append(HexDump.toHex( getOptions ())) 155 .append(" (").append( getOptions() ).append(" )"); 156 buffer.append(System.getProperty("line.separator")); 157 buffer.append(" .autoPosition = ").append(isAutoPosition()).append('\n'); 158 buffer.append(" .autoSeries = ").append(isAutoSeries()).append('\n'); 159 buffer.append(" .autoXPositioning = ").append(isAutoXPositioning()).append('\n'); 160 buffer.append(" .autoYPositioning = ").append(isAutoYPositioning()).append('\n'); 161 buffer.append(" .vertical = ").append(isVertical()).append('\n'); 162 buffer.append(" .dataTable = ").append(isDataTable()).append('\n'); 163 164 buffer.append("[/LEGEND]\n"); 165 return buffer.toString(); 166 } 167 168 public int serialize(int offset, byte[] data) 169 { 170 int pos = 0; 171 172 LittleEndian.putShort(data, 0 + offset, sid); 173 LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4)); 174 175 LittleEndian.putInt(data, 4 + offset + pos, field_1_xAxisUpperLeft); 176 LittleEndian.putInt(data, 8 + offset + pos, field_2_yAxisUpperLeft); 177 LittleEndian.putInt(data, 12 + offset + pos, field_3_xSize); 178 LittleEndian.putInt(data, 16 + offset + pos, field_4_ySize); 179 data[ 20 + offset + pos ] = field_5_type; 180 data[ 21 + offset + pos ] = field_6_spacing; 181 LittleEndian.putShort(data, 22 + offset + pos, field_7_options); 182 183 return getRecordSize(); 184 } 185 186 189 public int getRecordSize() 190 { 191 return 4 + 4 + 4 + 4 + 4 + 1 + 1 + 2; 192 } 193 194 public short getSid() 195 { 196 return this.sid; 197 } 198 199 public Object clone() { 200 LegendRecord rec = new LegendRecord(); 201 202 rec.field_1_xAxisUpperLeft = field_1_xAxisUpperLeft; 203 rec.field_2_yAxisUpperLeft = field_2_yAxisUpperLeft; 204 rec.field_3_xSize = field_3_xSize; 205 rec.field_4_ySize = field_4_ySize; 206 rec.field_5_type = field_5_type; 207 rec.field_6_spacing = field_6_spacing; 208 rec.field_7_options = field_7_options; 209 return rec; 210 } 211 212 213 214 215 218 public int getXAxisUpperLeft() 219 { 220 return field_1_xAxisUpperLeft; 221 } 222 223 226 public void setXAxisUpperLeft(int field_1_xAxisUpperLeft) 227 { 228 this.field_1_xAxisUpperLeft = field_1_xAxisUpperLeft; 229 } 230 231 234 public int getYAxisUpperLeft() 235 { 236 return field_2_yAxisUpperLeft; 237 } 238 239 242 public void setYAxisUpperLeft(int field_2_yAxisUpperLeft) 243 { 244 this.field_2_yAxisUpperLeft = field_2_yAxisUpperLeft; 245 } 246 247 250 public int getXSize() 251 { 252 return field_3_xSize; 253 } 254 255 258 public void setXSize(int field_3_xSize) 259 { 260 this.field_3_xSize = field_3_xSize; 261 } 262 263 266 public int getYSize() 267 { 268 return field_4_ySize; 269 } 270 271 274 public void setYSize(int field_4_ySize) 275 { 276 this.field_4_ySize = field_4_ySize; 277 } 278 279 290 public byte getType() 291 { 292 return field_5_type; 293 } 294 295 307 public void setType(byte field_5_type) 308 { 309 this.field_5_type = field_5_type; 310 } 311 312 320 public byte getSpacing() 321 { 322 return field_6_spacing; 323 } 324 325 334 public void setSpacing(byte field_6_spacing) 335 { 336 this.field_6_spacing = field_6_spacing; 337 } 338 339 342 public short getOptions() 343 { 344 return field_7_options; 345 } 346 347 350 public void setOptions(short field_7_options) 351 { 352 this.field_7_options = field_7_options; 353 } 354 355 359 public void setAutoPosition(boolean value) 360 { 361 field_7_options = autoPosition.setShortBoolean(field_7_options, value); 362 } 363 364 368 public boolean isAutoPosition() 369 { 370 return autoPosition.isSet(field_7_options); 371 } 372 373 377 public void setAutoSeries(boolean value) 378 { 379 field_7_options = autoSeries.setShortBoolean(field_7_options, value); 380 } 381 382 386 public boolean isAutoSeries() 387 { 388 return autoSeries.isSet(field_7_options); 389 } 390 391 395 public void setAutoXPositioning(boolean value) 396 { 397 field_7_options = autoXPositioning.setShortBoolean(field_7_options, value); 398 } 399 400 404 public boolean isAutoXPositioning() 405 { 406 return autoXPositioning.isSet(field_7_options); 407 } 408 409 413 public void setAutoYPositioning(boolean value) 414 { 415 field_7_options = autoYPositioning.setShortBoolean(field_7_options, value); 416 } 417 418 422 public boolean isAutoYPositioning() 423 { 424 return autoYPositioning.isSet(field_7_options); 425 } 426 427 431 public void setVertical(boolean value) 432 { 433 field_7_options = vertical.setShortBoolean(field_7_options, value); 434 } 435 436 440 public boolean isVertical() 441 { 442 return vertical.isSet(field_7_options); 443 } 444 445 449 public void setDataTable(boolean value) 450 { 451 field_7_options = dataTable.setShortBoolean(field_7_options, value); 452 } 453 454 458 public boolean isDataTable() 459 { 460 return dataTable.isSet(field_7_options); 461 } 462 463 464 } 466 467 468 469 | Popular Tags |