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 LineFormatRecord 34 extends Record 35 { 36 public final static short sid = 0x1007; 37 private int field_1_lineColor; 38 private short field_2_linePattern; 39 public final static short LINE_PATTERN_SOLID = 0; 40 public final static short LINE_PATTERN_DASH = 1; 41 public final static short LINE_PATTERN_DOT = 2; 42 public final static short LINE_PATTERN_DASH_DOT = 3; 43 public final static short LINE_PATTERN_DASH_DOT_DOT = 4; 44 public final static short LINE_PATTERN_NONE = 5; 45 public final static short LINE_PATTERN_DARK_GRAY_PATTERN = 6; 46 public final static short LINE_PATTERN_MEDIUM_GRAY_PATTERN = 7; 47 public final static short LINE_PATTERN_LIGHT_GRAY_PATTERN = 8; 48 private short field_3_weight; 49 public final static short WEIGHT_HAIRLINE = -1; 50 public final static short WEIGHT_NARROW = 0; 51 public final static short WEIGHT_MEDIUM = 1; 52 public final static short WEIGHT_WIDE = 2; 53 private short field_4_format; 54 private BitField auto = new BitField(0x1); 55 private BitField drawTicks = new BitField(0x4); 56 private BitField unknown = new BitField(0x4); 57 private short field_5_colourPaletteIndex; 58 59 60 public LineFormatRecord() 61 { 62 63 } 64 65 73 74 public LineFormatRecord(short id, short size, byte [] data) 75 { 76 super(id, size, data); 77 78 } 79 80 89 90 public LineFormatRecord(short id, short size, byte [] data, int offset) 91 { 92 super(id, size, data, offset); 93 94 } 95 96 101 protected void validateSid(short id) 102 { 103 if (id != sid) 104 { 105 throw new RecordFormatException("Not a LineFormat record"); 106 } 107 } 108 109 protected void fillFields(byte [] data, short size, int offset) 110 { 111 112 int pos = 0; 113 field_1_lineColor = LittleEndian.getInt(data, pos + 0x0 + offset); 114 field_2_linePattern = LittleEndian.getShort(data, pos + 0x4 + offset); 115 field_3_weight = LittleEndian.getShort(data, pos + 0x6 + offset); 116 field_4_format = LittleEndian.getShort(data, pos + 0x8 + offset); 117 field_5_colourPaletteIndex = LittleEndian.getShort(data, pos + 0xa + offset); 118 119 } 120 121 public String toString() 122 { 123 StringBuffer buffer = new StringBuffer (); 124 125 buffer.append("[LINEFORMAT]\n"); 126 buffer.append(" .lineColor = ") 127 .append("0x").append(HexDump.toHex( getLineColor ())) 128 .append(" (").append( getLineColor() ).append(" )"); 129 buffer.append(System.getProperty("line.separator")); 130 buffer.append(" .linePattern = ") 131 .append("0x").append(HexDump.toHex( getLinePattern ())) 132 .append(" (").append( getLinePattern() ).append(" )"); 133 buffer.append(System.getProperty("line.separator")); 134 buffer.append(" .weight = ") 135 .append("0x").append(HexDump.toHex( getWeight ())) 136 .append(" (").append( getWeight() ).append(" )"); 137 buffer.append(System.getProperty("line.separator")); 138 buffer.append(" .format = ") 139 .append("0x").append(HexDump.toHex( getFormat ())) 140 .append(" (").append( getFormat() ).append(" )"); 141 buffer.append(System.getProperty("line.separator")); 142 buffer.append(" .auto = ").append(isAuto()).append('\n'); 143 buffer.append(" .drawTicks = ").append(isDrawTicks()).append('\n'); 144 buffer.append(" .unknown = ").append(isUnknown()).append('\n'); 145 buffer.append(" .colourPaletteIndex = ") 146 .append("0x").append(HexDump.toHex( getColourPaletteIndex ())) 147 .append(" (").append( getColourPaletteIndex() ).append(" )"); 148 buffer.append(System.getProperty("line.separator")); 149 150 buffer.append("[/LINEFORMAT]\n"); 151 return buffer.toString(); 152 } 153 154 public int serialize(int offset, byte[] data) 155 { 156 int pos = 0; 157 158 LittleEndian.putShort(data, 0 + offset, sid); 159 LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4)); 160 161 LittleEndian.putInt(data, 4 + offset + pos, field_1_lineColor); 162 LittleEndian.putShort(data, 8 + offset + pos, field_2_linePattern); 163 LittleEndian.putShort(data, 10 + offset + pos, field_3_weight); 164 LittleEndian.putShort(data, 12 + offset + pos, field_4_format); 165 LittleEndian.putShort(data, 14 + offset + pos, field_5_colourPaletteIndex); 166 167 return getRecordSize(); 168 } 169 170 173 public int getRecordSize() 174 { 175 return 4 + 4 + 2 + 2 + 2 + 2; 176 } 177 178 public short getSid() 179 { 180 return this.sid; 181 } 182 183 public Object clone() { 184 LineFormatRecord rec = new LineFormatRecord(); 185 186 rec.field_1_lineColor = field_1_lineColor; 187 rec.field_2_linePattern = field_2_linePattern; 188 rec.field_3_weight = field_3_weight; 189 rec.field_4_format = field_4_format; 190 rec.field_5_colourPaletteIndex = field_5_colourPaletteIndex; 191 return rec; 192 } 193 194 195 196 197 200 public int getLineColor() 201 { 202 return field_1_lineColor; 203 } 204 205 208 public void setLineColor(int field_1_lineColor) 209 { 210 this.field_1_lineColor = field_1_lineColor; 211 } 212 213 227 public short getLinePattern() 228 { 229 return field_2_linePattern; 230 } 231 232 247 public void setLinePattern(short field_2_linePattern) 248 { 249 this.field_2_linePattern = field_2_linePattern; 250 } 251 252 261 public short getWeight() 262 { 263 return field_3_weight; 264 } 265 266 276 public void setWeight(short field_3_weight) 277 { 278 this.field_3_weight = field_3_weight; 279 } 280 281 284 public short getFormat() 285 { 286 return field_4_format; 287 } 288 289 292 public void setFormat(short field_4_format) 293 { 294 this.field_4_format = field_4_format; 295 } 296 297 300 public short getColourPaletteIndex() 301 { 302 return field_5_colourPaletteIndex; 303 } 304 305 308 public void setColourPaletteIndex(short field_5_colourPaletteIndex) 309 { 310 this.field_5_colourPaletteIndex = field_5_colourPaletteIndex; 311 } 312 313 317 public void setAuto(boolean value) 318 { 319 field_4_format = auto.setShortBoolean(field_4_format, value); 320 } 321 322 326 public boolean isAuto() 327 { 328 return auto.isSet(field_4_format); 329 } 330 331 335 public void setDrawTicks(boolean value) 336 { 337 field_4_format = drawTicks.setShortBoolean(field_4_format, value); 338 } 339 340 344 public boolean isDrawTicks() 345 { 346 return drawTicks.isSet(field_4_format); 347 } 348 349 353 public void setUnknown(boolean value) 354 { 355 field_4_format = unknown.setShortBoolean(field_4_format, value); 356 } 357 358 362 public boolean isUnknown() 363 { 364 return unknown.isSet(field_4_format); 365 } 366 367 368 } 370 371 372 373 | Popular Tags |