1 /
55
56
57 package org.apache.poi.hssf.record;
58
59
60
61 import org.apache.poi.util.*;
62
63
70 public class TextRecord
71 extends Record
72 {
73 public final static short sid = 0x1025;
74 private byte field_1_horizontalAlignment;
75 public final static byte HORIZONTAL_ALIGNMENT_LEFT = 1;
76 public final static byte HORIZONTAL_ALIGNMENT_CENTER = 2;
77 public final static byte HORIZONTAL_ALIGNMENT_BOTTOM = 3;
78 public final static byte HORIZONTAL_ALIGNMENT_JUSTIFY = 4;
79 private byte field_2_verticalAlignment;
80 public final static byte VERTICAL_ALIGNMENT_TOP = 1;
81 public final static byte VERTICAL_ALIGNMENT_CENTER = 2;
82 public final static byte VERTICAL_ALIGNMENT_BOTTOM = 3;
83 public final static byte VERTICAL_ALIGNMENT_JUSTIFY = 4;
84 private short field_3_displayMode;
85 public final static short DISPLAY_MODE_TRANSPARENT = 1;
86 public final static short DISPLAY_MODE_OPAQUE = 2;
87 private int field_4_rgbColor;
88 private int field_5_x;
89 private int field_6_y;
90 private int field_7_width;
91 private int field_8_height;
92 private short field_9_options1;
93 private BitField autoColor = new BitField(0x1);
94 private BitField showKey = new BitField(0x2);
95 private BitField showValue = new BitField(0x4);
96 private BitField vertical = new BitField(0x8);
97 private BitField autoGeneratedText = new BitField(0x10);
98 private BitField generated = new BitField(0x20);
99 private BitField autoLabelDeleted = new BitField(0x40);
100 private BitField autoBackground = new BitField(0x80);
101 private BitField rotation = new BitField(0x0700);
102 public final static short ROTATION_NONE = 0;
103 public final static short ROTATION_TOP_TO_BOTTOM = 1;
104 public final static short ROTATION_ROTATED_90_DEGREES = 2;
105 public final static short ROTATION_ROTATED_90_DEGREES_CLOCKWISE = 3;
106 private BitField showCategoryLabelAsPercentage = new BitField(0x800);
107 private BitField showValueAsPercentage = new BitField(0x1000);
108 private BitField showBubbleSizes = new BitField(0x2000);
109 private BitField showLabel = new BitField(0x4000);
110 private short field_10_indexOfColorValue;
111 private short field_11_options2;
112 private BitField dataLabelPlacement = new BitField(0x000F);
113 public final static short DATA_LABEL_PLACEMENT_CHART_DEPENDENT = 0;
114 public final static short DATA_LABEL_PLACEMENT_OUTSIDE = 1;
115 public final static short DATA_LABEL_PLACEMENT_INSIDE = 2;
116 public final static short DATA_LABEL_PLACEMENT_CENTER = 3;
117 public final static short DATA_LABEL_PLACEMENT_AXIS = 4;
118 public final static short DATA_LABEL_PLACEMENT_ABOVE = 5;
119 public final static short DATA_LABEL_PLACEMENT_BELOW = 6;
120 public final static short DATA_LABEL_PLACEMENT_LEFT = 7;
121 public final static short DATA_LABEL_PLACEMENT_RIGHT = 8;
122 public final static short DATA_LABEL_PLACEMENT_AUTO = 9;
123 public final static short DATA_LABEL_PLACEMENT_USER_MOVED = 10;
124 private short field_12_textRotation;
125
126
127 public TextRecord()
128 {
129
130 }
131
132
140
141 public TextRecord(short id, short size, byte [] data)
142 {
143 super(id, size, data);
144 }
145
146
155
156 public TextRecord(short id, short size, byte [] data, int offset)
157 {
158 super(id, size, data, offset);
159 }
160
161
166 protected void validateSid(short id)
167 {
168 if (id != sid)
169 {
170 throw new RecordFormatException("Not a Text record");
171 }
172 }
173
174 protected void fillFields(byte [] data, short size, int offset)
175 {
176 field_1_horizontalAlignment = data[ 0x0 + offset ];
177 field_2_verticalAlignment = data[ 0x1 + offset ];
178 field_3_displayMode = LittleEndian.getShort(data, 0x2 + offset);
179 field_4_rgbColor = LittleEndian.getInt(data, 0x4 + offset);
180 field_5_x = LittleEndian.getInt(data, 0x8 + offset);
181 field_6_y = LittleEndian.getInt(data, 0xc + offset);
182 field_7_width = LittleEndian.getInt(data, 0x10 + offset);
183 field_8_height = LittleEndian.getInt(data, 0x14 + offset);
184 field_9_options1 = LittleEndian.getShort(data, 0x18 + offset);
185 field_10_indexOfColorValue = LittleEndian.getShort(data, 0x1a + offset);
186 field_11_options2 = LittleEndian.getShort(data, 0x1c + offset);
187 field_12_textRotation = LittleEndian.getShort(data, 0x1e + offset);
188
189 }
190
191 public String toString()
192 {
193 StringBuffer buffer = new StringBuffer();
194
195 buffer.append("[Text]\n");
196
197 buffer.append(" .horizontalAlignment = ")
198 .append("0x")
199 .append(HexDump.toHex((byte)getHorizontalAlignment()))
200 .append(" (").append(getHorizontalAlignment()).append(" )\n");
201
202 buffer.append(" .verticalAlignment = ")
203 .append("0x")
204 .append(HexDump.toHex((byte)getVerticalAlignment()))
205 .append(" (").append(getVerticalAlignment()).append(" )\n");
206
207 buffer.append(" .displayMode = ")
208 .append("0x")
209 .append(HexDump.toHex((short)getDisplayMode()))
210 .append(" (").append(getDisplayMode()).append(" )\n");
211
212 buffer.append(" .rgbColor = ")
213 .append("0x")
214 .append(HexDump.toHex((int)getRgbColor()))
215 .append(" (").append(getRgbColor()).append(" )\n");
216
217 buffer.append(" .x = ")
218 .append("0x")
219 .append(HexDump.toHex((int)getX()))
220 .append(" (").append(getX()).append(" )\n");
221
222 buffer.append(" .y = ")
223 .append("0x")
224 .append(HexDump.toHex((int)getY()))
225 .append(" (").append(getY()).append(" )\n");
226
227 buffer.append(" .width = ")
228 .append("0x")
229 .append(HexDump.toHex((int)getWidth()))
230 .append(" (").append(getWidth()).append(" )\n");
231
232 buffer.append(" .height = ")
233 .append("0x")
234 .append(HexDump.toHex((int)getHeight()))
235 .append(" (").append(getHeight()).append(" )\n");
236
237 buffer.append(" .options1 = ")
238 .append("0x")
239 .append(HexDump.toHex((short)getOptions1()))
240 .append(" (").append(getOptions1()).append(" )\n");
241 buffer.append(" .autoColor = ").append(isAutoColor ()).append('\n');
242 buffer.append(" .showKey = ").append(isShowKey ()).append('\n');
243 buffer.append(" .showValue = ").append(isShowValue ()).append('\n');
244 buffer.append(" .vertical = ").append(isVertical ()).append('\n');
245 buffer.append(" .autoGeneratedText = ").append(isAutoGeneratedText ()).append('\n');
246 buffer.append(" .generated = ").append(isGenerated ()).append('\n');
247 buffer.append(" .autoLabelDeleted = ").append(isAutoLabelDeleted ()).append('\n');
248 buffer.append(" .autoBackground = ").append(isAutoBackground ()).append('\n');
249 buffer.append(" .rotation = ").append(getRotation ()).append('\n');
250 buffer.append(" .showCategoryLabelAsPercentage = ").append(isShowCategoryLabelAsPercentage()).append('\n');
251 buffer.append(" .showValueAsPercentage = ").append(isShowValueAsPercentage()).append('\n');
252 buffer.append(" .showBubbleSizes = ").append(isShowBubbleSizes ()).append('\n');
253 buffer.append(" .showLabel = ").append(isShowLabel ()).append('\n');
254
255 buffer.append(" .indexOfColorValue = ")
256 .append("0x")
257 .append(HexDump.toHex((short)getIndexOfColorValue()))
258 .append(" (").append(getIndexOfColorValue()).append(" )\n");
259
260 buffer.append(" .options2 = ")
261 .append("0x")
262 .append(HexDump.toHex((short)getOptions2()))
263 .append(" (").append(getOptions2()).append(" )\n");
264 buffer.append(" .dataLabelPlacement = ").append(getDataLabelPlacement ()).append('\n');
265
266 buffer.append(" .textRotation = ")
267 .append("0x")
268 .append(HexDump.toHex((short)getTextRotation()))
269 .append(" (").append(getTextRotation()).append(" )\n");
270
271 buffer.append("[/Text]\n");
272 return buffer.toString();
273 }
274
275 public int serialize(int offset, byte[] data)
276 {
277 LittleEndian.putShort(data, 0 + offset, sid);
278 LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4));
279
280 data[ 4 + offset ] = field_1_horizontalAlignment;
281 data[ 5 + offset ] = field_2_verticalAlignment;
282 LittleEndian.putShort(data, 6 + offset, field_3_displayMode);
283 LittleEndian.putInt(data, 8 + offset, field_4_rgbColor);
284 LittleEndian.putInt(data, 12 + offset, field_5_x);
285 LittleEndian.putInt(data, 16 + offset, field_6_y);
286 LittleEndian.putInt(data, 20 + offset, field_7_width);
287 LittleEndian.putInt(data, 24 + offset, field_8_height);
288 LittleEndian.putShort(data, 28 + offset, field_9_options1);
289 LittleEndian.putShort(data, 30 + offset, field_10_indexOfColorValue);
290 LittleEndian.putShort(data, 32 + offset, field_11_options2);
291 LittleEndian.putShort(data, 34 + offset, field_12_textRotation);
292
293 return getRecordSize();
294 }
295
296
299 public int getRecordSize()
300 {
301 return 4 + 1 + 1 + 2 + 4 + 4 + 4 + 4 + 4 + 2 + 2 + 2 + 2;
302 }
303
304 public short getSid()
305 {
306 return this.sid;
307 }
308
309
310
319 public byte getHorizontalAlignment()
320 {
321 return field_1_horizontalAlignment;
322 }
323
324
334 public void setHorizontalAlignment(byte field_1_horizontalAlignment)
335 {
336 this.field_1_horizontalAlignment = field_1_horizontalAlignment;
337 }
338
339
348 public byte getVerticalAlignment()
349 {
350 return field_2_verticalAlignment;
351 }
352
353
363 public void setVerticalAlignment(byte field_2_verticalAlignment)
364 {
365 this.field_2_verticalAlignment = field_2_verticalAlignment;
366 }
367
368
375 public short getDisplayMode()
376 {
377 return field_3_displayMode;
378 }
379
380
388 public void setDisplayMode(short field_3_displayMode)
389 {
390 this.field_3_displayMode = field_3_displayMode;
391 }
392
393
396 public int getRgbColor()
397 {
398 return field_4_rgbColor;
399 }
400
401
404 public void setRgbColor(int field_4_rgbColor)
405 {
406 this.field_4_rgbColor = field_4_rgbColor;
407 }
408
409
412 public int getX()
413 {
414 return field_5_x;
415 }
416
417
420 public void setX(int field_5_x)
421 {
422 this.field_5_x = field_5_x;
423 }
424
425
428 public int getY()
429 {
430 return field_6_y;
431 }
432
433
436 public void setY(int field_6_y)
437 {
438 this.field_6_y = field_6_y;
439 }
440
441
444 public int getWidth()
445 {
446 return field_7_width;
447 }
448
449
452 public void setWidth(int field_7_width)
453 {
454 this.field_7_width = field_7_width;
455 }
456
457
460 public int getHeight()
461 {
462 return field_8_height;
463 }
464
465
468 public void setHeight(int field_8_height)
469 {
470 this.field_8_height = field_8_height;
471 }
472
473
476 public short getOptions1()
477 {
478 return field_9_options1;
479 }
480
481
484 public void setOptions1(short field_9_options1)
485 {
486 this.field_9_options1 = field_9_options1;
487 }
488
489
492 public short getIndexOfColorValue()
493 {
494 return field_10_indexOfColorValue;
495 }
496
497
500 public void setIndexOfColorValue(short field_10_indexOfColorValue)
501 {
502 this.field_10_indexOfColorValue = field_10_indexOfColorValue;
503 }
504
505
508 public short getOptions2()
509 {
510 return field_11_options2;
511 }
512
513
516 public void setOptions2(short field_11_options2)
517 {
518 this.field_11_options2 = field_11_options2;
519 }
520
521
524 public short getTextRotation()
525 {
526 return field_12_textRotation;
527 }
528
529
532 public void setTextRotation(short field_12_textRotation)
533 {
534 this.field_12_textRotation = field_12_textRotation;
535 }
536
537
541 public void setAutoColor(boolean value)
542 {
543 field_9_options1 = autoColor.setShortBoolean(field_9_options1, value);
544 }
545
546
550 public boolean isAutoColor()
551 {
552 return autoColor.isSet(field_9_options1);
553 }
554
555
559 public void setShowKey(boolean value)
560 {
561 field_9_options1 = showKey.setShortBoolean(field_9_options1, value);
562 }
563
564
568 public boolean isShowKey()
569 {
570 return showKey.isSet(field_9_options1);
571 }
572
573
577 public void setShowValue(boolean value)
578 {
579 field_9_options1 = showValue.setShortBoolean(field_9_options1, value);
580 }
581
582
586 public boolean isShowValue()
587 {
588 return showValue.isSet(field_9_options1);
589 }
590
591
595 public void setVertical(boolean value)
596 {
597 field_9_options1 = vertical.setShortBoolean(field_9_options1, value);
598 }
599
600
604 public boolean isVertical()
605 {
606 return vertical.isSet(field_9_options1);
607 }
608
609
613 public void setAutoGeneratedText(boolean value)
614 {
615 field_9_options1 = autoGeneratedText.setShortBoolean(field_9_options1, value);
616 }
617
618
622 public boolean isAutoGeneratedText()
623 {
624 return autoGeneratedText.isSet(field_9_options1);
625 }
626
627
631 public void setGenerated(boolean value)
632 {
633 field_9_options1 = generated.setShortBoolean(field_9_options1, value);
634 }
635
636
640 public boolean isGenerated()
641 {
642 return generated.isSet(field_9_options1);
643 }
644
645
649 public void setAutoLabelDeleted(boolean value)
650 {
651 field_9_options1 = autoLabelDeleted.setShortBoolean(field_9_options1, value);
652 }
653
654
658 public boolean isAutoLabelDeleted()
659 {
660 return autoLabelDeleted.isSet(field_9_options1);
661 }
662
663
667 public void setAutoBackground(boolean value)
668 {
669 field_9_options1 = autoBackground.setShortBoolean(field_9_options1, value);
670 }
671
672
676 public boolean isAutoBackground()
677 {
678 return autoBackground.isSet(field_9_options1);
679 }
680
681
685 public void setRotation(short value)
686 {
687 field_9_options1 = rotation.setShortValue(field_9_options1, value);
688 }
689
690
694 public short getRotation()
695 {
696 return rotation.getShortValue(field_9_options1);
697 }
698
699
703 public void setShowCategoryLabelAsPercentage(boolean value)
704 {
705 field_9_options1 = showCategoryLabelAsPercentage.setShortBoolean(field_9_options1, value);
706 }
707
708
712 public boolean isShowCategoryLabelAsPercentage()
713 {
714 return showCategoryLabelAsPercentage.isSet(field_9_options1);
715 }
716
717
721 public void setShowValueAsPercentage(boolean value)
722 {
723 field_9_options1 = showValueAsPercentage.setShortBoolean(field_9_options1, value);
724 }
725
726
730 public boolean isShowValueAsPercentage()
731 {
732 return showValueAsPercentage.isSet(field_9_options1);
733 }
734
735
739 public void setShowBubbleSizes(boolean value)
740 {
741 field_9_options1 = showBubbleSizes.setShortBoolean(field_9_options1, value);
742 }
743
744
748 public boolean isShowBubbleSizes()
749 {
750 return showBubbleSizes.isSet(field_9_options1);
751 }
752
753
757 public void setShowLabel(boolean value)
758 {
759 field_9_options1 = showLabel.setShortBoolean(field_9_options1, value);
760 }
761
762
766 public boolean isShowLabel()
767 {
768 return showLabel.isSet(field_9_options1);
769 }
770
771
775 public void setDataLabelPlacement(short value)
776 {
777 field_11_options2 = dataLabelPlacement.setShortValue(field_11_options2, value);
778 }
779
780
784 public short getDataLabelPlacement()
785 {
786 return dataLabelPlacement.getShortValue(field_11_options2);
787 }
788
789
790 }
791
792
793
794
795