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 TextRecord 34 extends Record 35 { 36 public final static short sid = 0x1025; 37 private byte field_1_horizontalAlignment; 38 public final static byte HORIZONTAL_ALIGNMENT_LEFT = 1; 39 public final static byte HORIZONTAL_ALIGNMENT_CENTER = 2; 40 public final static byte HORIZONTAL_ALIGNMENT_BOTTOM = 3; 41 public final static byte HORIZONTAL_ALIGNMENT_JUSTIFY = 4; 42 private byte field_2_verticalAlignment; 43 public final static byte VERTICAL_ALIGNMENT_TOP = 1; 44 public final static byte VERTICAL_ALIGNMENT_CENTER = 2; 45 public final static byte VERTICAL_ALIGNMENT_BOTTOM = 3; 46 public final static byte VERTICAL_ALIGNMENT_JUSTIFY = 4; 47 private short field_3_displayMode; 48 public final static short DISPLAY_MODE_TRANSPARENT = 1; 49 public final static short DISPLAY_MODE_OPAQUE = 2; 50 private int field_4_rgbColor; 51 private int field_5_x; 52 private int field_6_y; 53 private int field_7_width; 54 private int field_8_height; 55 private short field_9_options1; 56 private BitField autoColor = new BitField(0x1); 57 private BitField showKey = new BitField(0x2); 58 private BitField showValue = new BitField(0x4); 59 private BitField vertical = new BitField(0x8); 60 private BitField autoGeneratedText = new BitField(0x10); 61 private BitField generated = new BitField(0x20); 62 private BitField autoLabelDeleted = new BitField(0x40); 63 private BitField autoBackground = new BitField(0x80); 64 private BitField rotation = new BitField(0x0700); 65 public final static short ROTATION_NONE = 0; 66 public final static short ROTATION_TOP_TO_BOTTOM = 1; 67 public final static short ROTATION_ROTATED_90_DEGREES = 2; 68 public final static short ROTATION_ROTATED_90_DEGREES_CLOCKWISE = 3; 69 private BitField showCategoryLabelAsPercentage = new BitField(0x800); 70 private BitField showValueAsPercentage = new BitField(0x1000); 71 private BitField showBubbleSizes = new BitField(0x2000); 72 private BitField showLabel = new BitField(0x4000); 73 private short field_10_indexOfColorValue; 74 private short field_11_options2; 75 private BitField dataLabelPlacement = new BitField(0x000F); 76 public final static short DATA_LABEL_PLACEMENT_CHART_DEPENDENT = 0; 77 public final static short DATA_LABEL_PLACEMENT_OUTSIDE = 1; 78 public final static short DATA_LABEL_PLACEMENT_INSIDE = 2; 79 public final static short DATA_LABEL_PLACEMENT_CENTER = 3; 80 public final static short DATA_LABEL_PLACEMENT_AXIS = 4; 81 public final static short DATA_LABEL_PLACEMENT_ABOVE = 5; 82 public final static short DATA_LABEL_PLACEMENT_BELOW = 6; 83 public final static short DATA_LABEL_PLACEMENT_LEFT = 7; 84 public final static short DATA_LABEL_PLACEMENT_RIGHT = 8; 85 public final static short DATA_LABEL_PLACEMENT_AUTO = 9; 86 public final static short DATA_LABEL_PLACEMENT_USER_MOVED = 10; 87 private short field_12_textRotation; 88 89 90 public TextRecord() 91 { 92 93 } 94 95 103 104 public TextRecord(short id, short size, byte [] data) 105 { 106 super(id, size, data); 107 108 } 109 110 119 120 public TextRecord(short id, short size, byte [] data, int offset) 121 { 122 super(id, size, data, offset); 123 124 } 125 126 131 protected void validateSid(short id) 132 { 133 if (id != sid) 134 { 135 throw new RecordFormatException("Not a Text record"); 136 } 137 } 138 139 protected void fillFields(byte [] data, short size, int offset) 140 { 141 142 int pos = 0; 143 field_1_horizontalAlignment = data[ pos + 0x0 + offset ]; 144 field_2_verticalAlignment = data[ pos + 0x1 + offset ]; 145 field_3_displayMode = LittleEndian.getShort(data, pos + 0x2 + offset); 146 field_4_rgbColor = LittleEndian.getInt(data, pos + 0x4 + offset); 147 field_5_x = LittleEndian.getInt(data, pos + 0x8 + offset); 148 field_6_y = LittleEndian.getInt(data, pos + 0xc + offset); 149 field_7_width = LittleEndian.getInt(data, pos + 0x10 + offset); 150 field_8_height = LittleEndian.getInt(data, pos + 0x14 + offset); 151 field_9_options1 = LittleEndian.getShort(data, pos + 0x18 + offset); 152 field_10_indexOfColorValue = LittleEndian.getShort(data, pos + 0x1a + offset); 153 field_11_options2 = LittleEndian.getShort(data, pos + 0x1c + offset); 154 field_12_textRotation = LittleEndian.getShort(data, pos + 0x1e + offset); 155 156 } 157 158 public String toString() 159 { 160 StringBuffer buffer = new StringBuffer (); 161 162 buffer.append("[TEXT]\n"); 163 buffer.append(" .horizontalAlignment = ") 164 .append("0x").append(HexDump.toHex( getHorizontalAlignment ())) 165 .append(" (").append( getHorizontalAlignment() ).append(" )"); 166 buffer.append(System.getProperty("line.separator")); 167 buffer.append(" .verticalAlignment = ") 168 .append("0x").append(HexDump.toHex( getVerticalAlignment ())) 169 .append(" (").append( getVerticalAlignment() ).append(" )"); 170 buffer.append(System.getProperty("line.separator")); 171 buffer.append(" .displayMode = ") 172 .append("0x").append(HexDump.toHex( getDisplayMode ())) 173 .append(" (").append( getDisplayMode() ).append(" )"); 174 buffer.append(System.getProperty("line.separator")); 175 buffer.append(" .rgbColor = ") 176 .append("0x").append(HexDump.toHex( getRgbColor ())) 177 .append(" (").append( getRgbColor() ).append(" )"); 178 buffer.append(System.getProperty("line.separator")); 179 buffer.append(" .x = ") 180 .append("0x").append(HexDump.toHex( getX ())) 181 .append(" (").append( getX() ).append(" )"); 182 buffer.append(System.getProperty("line.separator")); 183 buffer.append(" .y = ") 184 .append("0x").append(HexDump.toHex( getY ())) 185 .append(" (").append( getY() ).append(" )"); 186 buffer.append(System.getProperty("line.separator")); 187 buffer.append(" .width = ") 188 .append("0x").append(HexDump.toHex( getWidth ())) 189 .append(" (").append( getWidth() ).append(" )"); 190 buffer.append(System.getProperty("line.separator")); 191 buffer.append(" .height = ") 192 .append("0x").append(HexDump.toHex( getHeight ())) 193 .append(" (").append( getHeight() ).append(" )"); 194 buffer.append(System.getProperty("line.separator")); 195 buffer.append(" .options1 = ") 196 .append("0x").append(HexDump.toHex( getOptions1 ())) 197 .append(" (").append( getOptions1() ).append(" )"); 198 buffer.append(System.getProperty("line.separator")); 199 buffer.append(" .autoColor = ").append(isAutoColor()).append('\n'); 200 buffer.append(" .showKey = ").append(isShowKey()).append('\n'); 201 buffer.append(" .showValue = ").append(isShowValue()).append('\n'); 202 buffer.append(" .vertical = ").append(isVertical()).append('\n'); 203 buffer.append(" .autoGeneratedText = ").append(isAutoGeneratedText()).append('\n'); 204 buffer.append(" .generated = ").append(isGenerated()).append('\n'); 205 buffer.append(" .autoLabelDeleted = ").append(isAutoLabelDeleted()).append('\n'); 206 buffer.append(" .autoBackground = ").append(isAutoBackground()).append('\n'); 207 buffer.append(" .rotation = ").append(getRotation()).append('\n'); 208 buffer.append(" .showCategoryLabelAsPercentage = ").append(isShowCategoryLabelAsPercentage()).append('\n'); 209 buffer.append(" .showValueAsPercentage = ").append(isShowValueAsPercentage()).append('\n'); 210 buffer.append(" .showBubbleSizes = ").append(isShowBubbleSizes()).append('\n'); 211 buffer.append(" .showLabel = ").append(isShowLabel()).append('\n'); 212 buffer.append(" .indexOfColorValue = ") 213 .append("0x").append(HexDump.toHex( getIndexOfColorValue ())) 214 .append(" (").append( getIndexOfColorValue() ).append(" )"); 215 buffer.append(System.getProperty("line.separator")); 216 buffer.append(" .options2 = ") 217 .append("0x").append(HexDump.toHex( getOptions2 ())) 218 .append(" (").append( getOptions2() ).append(" )"); 219 buffer.append(System.getProperty("line.separator")); 220 buffer.append(" .dataLabelPlacement = ").append(getDataLabelPlacement()).append('\n'); 221 buffer.append(" .textRotation = ") 222 .append("0x").append(HexDump.toHex( getTextRotation ())) 223 .append(" (").append( getTextRotation() ).append(" )"); 224 buffer.append(System.getProperty("line.separator")); 225 226 buffer.append("[/TEXT]\n"); 227 return buffer.toString(); 228 } 229 230 public int serialize(int offset, byte[] data) 231 { 232 int pos = 0; 233 234 LittleEndian.putShort(data, 0 + offset, sid); 235 LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4)); 236 237 data[ 4 + offset + pos ] = field_1_horizontalAlignment; 238 data[ 5 + offset + pos ] = field_2_verticalAlignment; 239 LittleEndian.putShort(data, 6 + offset + pos, field_3_displayMode); 240 LittleEndian.putInt(data, 8 + offset + pos, field_4_rgbColor); 241 LittleEndian.putInt(data, 12 + offset + pos, field_5_x); 242 LittleEndian.putInt(data, 16 + offset + pos, field_6_y); 243 LittleEndian.putInt(data, 20 + offset + pos, field_7_width); 244 LittleEndian.putInt(data, 24 + offset + pos, field_8_height); 245 LittleEndian.putShort(data, 28 + offset + pos, field_9_options1); 246 LittleEndian.putShort(data, 30 + offset + pos, field_10_indexOfColorValue); 247 LittleEndian.putShort(data, 32 + offset + pos, field_11_options2); 248 LittleEndian.putShort(data, 34 + offset + pos, field_12_textRotation); 249 250 return getRecordSize(); 251 } 252 253 256 public int getRecordSize() 257 { 258 return 4 + 1 + 1 + 2 + 4 + 4 + 4 + 4 + 4 + 2 + 2 + 2 + 2; 259 } 260 261 public short getSid() 262 { 263 return this.sid; 264 } 265 266 public Object clone() { 267 TextRecord rec = new TextRecord(); 268 269 rec.field_1_horizontalAlignment = field_1_horizontalAlignment; 270 rec.field_2_verticalAlignment = field_2_verticalAlignment; 271 rec.field_3_displayMode = field_3_displayMode; 272 rec.field_4_rgbColor = field_4_rgbColor; 273 rec.field_5_x = field_5_x; 274 rec.field_6_y = field_6_y; 275 rec.field_7_width = field_7_width; 276 rec.field_8_height = field_8_height; 277 rec.field_9_options1 = field_9_options1; 278 rec.field_10_indexOfColorValue = field_10_indexOfColorValue; 279 rec.field_11_options2 = field_11_options2; 280 rec.field_12_textRotation = field_12_textRotation; 281 return rec; 282 } 283 284 285 286 287 296 public byte getHorizontalAlignment() 297 { 298 return field_1_horizontalAlignment; 299 } 300 301 311 public void setHorizontalAlignment(byte field_1_horizontalAlignment) 312 { 313 this.field_1_horizontalAlignment = field_1_horizontalAlignment; 314 } 315 316 325 public byte getVerticalAlignment() 326 { 327 return field_2_verticalAlignment; 328 } 329 330 340 public void setVerticalAlignment(byte field_2_verticalAlignment) 341 { 342 this.field_2_verticalAlignment = field_2_verticalAlignment; 343 } 344 345 352 public short getDisplayMode() 353 { 354 return field_3_displayMode; 355 } 356 357 365 public void setDisplayMode(short field_3_displayMode) 366 { 367 this.field_3_displayMode = field_3_displayMode; 368 } 369 370 373 public int getRgbColor() 374 { 375 return field_4_rgbColor; 376 } 377 378 381 public void setRgbColor(int field_4_rgbColor) 382 { 383 this.field_4_rgbColor = field_4_rgbColor; 384 } 385 386 389 public int getX() 390 { 391 return field_5_x; 392 } 393 394 397 public void setX(int field_5_x) 398 { 399 this.field_5_x = field_5_x; 400 } 401 402 405 public int getY() 406 { 407 return field_6_y; 408 } 409 410 413 public void setY(int field_6_y) 414 { 415 this.field_6_y = field_6_y; 416 } 417 418 421 public int getWidth() 422 { 423 return field_7_width; 424 } 425 426 429 public void setWidth(int field_7_width) 430 { 431 this.field_7_width = field_7_width; 432 } 433 434 437 public int getHeight() 438 { 439 return field_8_height; 440 } 441 442 445 public void setHeight(int field_8_height) 446 { 447 this.field_8_height = field_8_height; 448 } 449 450 453 public short getOptions1() 454 { 455 return field_9_options1; 456 } 457 458 461 public void setOptions1(short field_9_options1) 462 { 463 this.field_9_options1 = field_9_options1; 464 } 465 466 469 public short getIndexOfColorValue() 470 { 471 return field_10_indexOfColorValue; 472 } 473 474 477 public void setIndexOfColorValue(short field_10_indexOfColorValue) 478 { 479 this.field_10_indexOfColorValue = field_10_indexOfColorValue; 480 } 481 482 485 public short getOptions2() 486 { 487 return field_11_options2; 488 } 489 490 493 public void setOptions2(short field_11_options2) 494 { 495 this.field_11_options2 = field_11_options2; 496 } 497 498 501 public short getTextRotation() 502 { 503 return field_12_textRotation; 504 } 505 506 509 public void setTextRotation(short field_12_textRotation) 510 { 511 this.field_12_textRotation = field_12_textRotation; 512 } 513 514 518 public void setAutoColor(boolean value) 519 { 520 field_9_options1 = autoColor.setShortBoolean(field_9_options1, value); 521 } 522 523 527 public boolean isAutoColor() 528 { 529 return autoColor.isSet(field_9_options1); 530 } 531 532 536 public void setShowKey(boolean value) 537 { 538 field_9_options1 = showKey.setShortBoolean(field_9_options1, value); 539 } 540 541 545 public boolean isShowKey() 546 { 547 return showKey.isSet(field_9_options1); 548 } 549 550 554 public void setShowValue(boolean value) 555 { 556 field_9_options1 = showValue.setShortBoolean(field_9_options1, value); 557 } 558 559 563 public boolean isShowValue() 564 { 565 return showValue.isSet(field_9_options1); 566 } 567 568 572 public void setVertical(boolean value) 573 { 574 field_9_options1 = vertical.setShortBoolean(field_9_options1, value); 575 } 576 577 581 public boolean isVertical() 582 { 583 return vertical.isSet(field_9_options1); 584 } 585 586 590 public void setAutoGeneratedText(boolean value) 591 { 592 field_9_options1 = autoGeneratedText.setShortBoolean(field_9_options1, value); 593 } 594 595 599 public boolean isAutoGeneratedText() 600 { 601 return autoGeneratedText.isSet(field_9_options1); 602 } 603 604 608 public void setGenerated(boolean value) 609 { 610 field_9_options1 = generated.setShortBoolean(field_9_options1, value); 611 } 612 613 617 public boolean isGenerated() 618 { 619 return generated.isSet(field_9_options1); 620 } 621 622 626 public void setAutoLabelDeleted(boolean value) 627 { 628 field_9_options1 = autoLabelDeleted.setShortBoolean(field_9_options1, value); 629 } 630 631 635 public boolean isAutoLabelDeleted() 636 { 637 return autoLabelDeleted.isSet(field_9_options1); 638 } 639 640 644 public void setAutoBackground(boolean value) 645 { 646 field_9_options1 = autoBackground.setShortBoolean(field_9_options1, value); 647 } 648 649 653 public boolean isAutoBackground() 654 { 655 return autoBackground.isSet(field_9_options1); 656 } 657 658 662 public void setRotation(short value) 663 { 664 field_9_options1 = rotation.setShortValue(field_9_options1, value); 665 } 666 667 671 public short getRotation() 672 { 673 return rotation.getShortValue(field_9_options1); 674 } 675 676 680 public void setShowCategoryLabelAsPercentage(boolean value) 681 { 682 field_9_options1 = showCategoryLabelAsPercentage.setShortBoolean(field_9_options1, value); 683 } 684 685 689 public boolean isShowCategoryLabelAsPercentage() 690 { 691 return showCategoryLabelAsPercentage.isSet(field_9_options1); 692 } 693 694 698 public void setShowValueAsPercentage(boolean value) 699 { 700 field_9_options1 = showValueAsPercentage.setShortBoolean(field_9_options1, value); 701 } 702 703 707 public boolean isShowValueAsPercentage() 708 { 709 return showValueAsPercentage.isSet(field_9_options1); 710 } 711 712 716 public void setShowBubbleSizes(boolean value) 717 { 718 field_9_options1 = showBubbleSizes.setShortBoolean(field_9_options1, value); 719 } 720 721 725 public boolean isShowBubbleSizes() 726 { 727 return showBubbleSizes.isSet(field_9_options1); 728 } 729 730 734 public void setShowLabel(boolean value) 735 { 736 field_9_options1 = showLabel.setShortBoolean(field_9_options1, value); 737 } 738 739 743 public boolean isShowLabel() 744 { 745 return showLabel.isSet(field_9_options1); 746 } 747 748 752 public void setDataLabelPlacement(short value) 753 { 754 field_11_options2 = dataLabelPlacement.setShortValue(field_11_options2, value); 755 } 756 757 761 public short getDataLabelPlacement() 762 { 763 return dataLabelPlacement.getShortValue(field_11_options2); 764 } 765 766 767 } 769 770 771 772 | Popular Tags |