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 AreaFormatRecord 34 extends Record 35 { 36 public final static short sid = 0x100a; 37 private int field_1_foregroundColor; 38 private int field_2_backgroundColor; 39 private short field_3_pattern; 40 private short field_4_formatFlags; 41 private BitField automatic = new BitField(0x1); 42 private BitField invert = new BitField(0x2); 43 private short field_5_forecolorIndex; 44 private short field_6_backcolorIndex; 45 46 47 public AreaFormatRecord() 48 { 49 50 } 51 52 60 61 public AreaFormatRecord(short id, short size, byte [] data) 62 { 63 super(id, size, data); 64 65 } 66 67 76 77 public AreaFormatRecord(short id, short size, byte [] data, int offset) 78 { 79 super(id, size, data, offset); 80 81 } 82 83 88 protected void validateSid(short id) 89 { 90 if (id != sid) 91 { 92 throw new RecordFormatException("Not a AreaFormat record"); 93 } 94 } 95 96 protected void fillFields(byte [] data, short size, int offset) 97 { 98 99 int pos = 0; 100 field_1_foregroundColor = LittleEndian.getInt(data, pos + 0x0 + offset); 101 field_2_backgroundColor = LittleEndian.getInt(data, pos + 0x4 + offset); 102 field_3_pattern = LittleEndian.getShort(data, pos + 0x8 + offset); 103 field_4_formatFlags = LittleEndian.getShort(data, pos + 0xa + offset); 104 field_5_forecolorIndex = LittleEndian.getShort(data, pos + 0xc + offset); 105 field_6_backcolorIndex = LittleEndian.getShort(data, pos + 0xe + offset); 106 107 } 108 109 public String toString() 110 { 111 StringBuffer buffer = new StringBuffer (); 112 113 buffer.append("[AREAFORMAT]\n"); 114 buffer.append(" .foregroundColor = ") 115 .append("0x").append(HexDump.toHex( getForegroundColor ())) 116 .append(" (").append( getForegroundColor() ).append(" )"); 117 buffer.append(System.getProperty("line.separator")); 118 buffer.append(" .backgroundColor = ") 119 .append("0x").append(HexDump.toHex( getBackgroundColor ())) 120 .append(" (").append( getBackgroundColor() ).append(" )"); 121 buffer.append(System.getProperty("line.separator")); 122 buffer.append(" .pattern = ") 123 .append("0x").append(HexDump.toHex( getPattern ())) 124 .append(" (").append( getPattern() ).append(" )"); 125 buffer.append(System.getProperty("line.separator")); 126 buffer.append(" .formatFlags = ") 127 .append("0x").append(HexDump.toHex( getFormatFlags ())) 128 .append(" (").append( getFormatFlags() ).append(" )"); 129 buffer.append(System.getProperty("line.separator")); 130 buffer.append(" .automatic = ").append(isAutomatic()).append('\n'); 131 buffer.append(" .invert = ").append(isInvert()).append('\n'); 132 buffer.append(" .forecolorIndex = ") 133 .append("0x").append(HexDump.toHex( getForecolorIndex ())) 134 .append(" (").append( getForecolorIndex() ).append(" )"); 135 buffer.append(System.getProperty("line.separator")); 136 buffer.append(" .backcolorIndex = ") 137 .append("0x").append(HexDump.toHex( getBackcolorIndex ())) 138 .append(" (").append( getBackcolorIndex() ).append(" )"); 139 buffer.append(System.getProperty("line.separator")); 140 141 buffer.append("[/AREAFORMAT]\n"); 142 return buffer.toString(); 143 } 144 145 public int serialize(int offset, byte[] data) 146 { 147 int pos = 0; 148 149 LittleEndian.putShort(data, 0 + offset, sid); 150 LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4)); 151 152 LittleEndian.putInt(data, 4 + offset + pos, field_1_foregroundColor); 153 LittleEndian.putInt(data, 8 + offset + pos, field_2_backgroundColor); 154 LittleEndian.putShort(data, 12 + offset + pos, field_3_pattern); 155 LittleEndian.putShort(data, 14 + offset + pos, field_4_formatFlags); 156 LittleEndian.putShort(data, 16 + offset + pos, field_5_forecolorIndex); 157 LittleEndian.putShort(data, 18 + offset + pos, field_6_backcolorIndex); 158 159 return getRecordSize(); 160 } 161 162 165 public int getRecordSize() 166 { 167 return 4 + 4 + 4 + 2 + 2 + 2 + 2; 168 } 169 170 public short getSid() 171 { 172 return this.sid; 173 } 174 175 public Object clone() { 176 AreaFormatRecord rec = new AreaFormatRecord(); 177 178 rec.field_1_foregroundColor = field_1_foregroundColor; 179 rec.field_2_backgroundColor = field_2_backgroundColor; 180 rec.field_3_pattern = field_3_pattern; 181 rec.field_4_formatFlags = field_4_formatFlags; 182 rec.field_5_forecolorIndex = field_5_forecolorIndex; 183 rec.field_6_backcolorIndex = field_6_backcolorIndex; 184 return rec; 185 } 186 187 188 189 190 193 public int getForegroundColor() 194 { 195 return field_1_foregroundColor; 196 } 197 198 201 public void setForegroundColor(int field_1_foregroundColor) 202 { 203 this.field_1_foregroundColor = field_1_foregroundColor; 204 } 205 206 209 public int getBackgroundColor() 210 { 211 return field_2_backgroundColor; 212 } 213 214 217 public void setBackgroundColor(int field_2_backgroundColor) 218 { 219 this.field_2_backgroundColor = field_2_backgroundColor; 220 } 221 222 225 public short getPattern() 226 { 227 return field_3_pattern; 228 } 229 230 233 public void setPattern(short field_3_pattern) 234 { 235 this.field_3_pattern = field_3_pattern; 236 } 237 238 241 public short getFormatFlags() 242 { 243 return field_4_formatFlags; 244 } 245 246 249 public void setFormatFlags(short field_4_formatFlags) 250 { 251 this.field_4_formatFlags = field_4_formatFlags; 252 } 253 254 257 public short getForecolorIndex() 258 { 259 return field_5_forecolorIndex; 260 } 261 262 265 public void setForecolorIndex(short field_5_forecolorIndex) 266 { 267 this.field_5_forecolorIndex = field_5_forecolorIndex; 268 } 269 270 273 public short getBackcolorIndex() 274 { 275 return field_6_backcolorIndex; 276 } 277 278 281 public void setBackcolorIndex(short field_6_backcolorIndex) 282 { 283 this.field_6_backcolorIndex = field_6_backcolorIndex; 284 } 285 286 290 public void setAutomatic(boolean value) 291 { 292 field_4_formatFlags = automatic.setShortBoolean(field_4_formatFlags, value); 293 } 294 295 299 public boolean isAutomatic() 300 { 301 return automatic.isSet(field_4_formatFlags); 302 } 303 304 308 public void setInvert(boolean value) 309 { 310 field_4_formatFlags = invert.setShortBoolean(field_4_formatFlags, value); 311 } 312 313 317 public boolean isInvert() 318 { 319 return invert.isSet(field_4_formatFlags); 320 } 321 322 323 } 325 326 327 328 | Popular Tags |