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 DataFormatRecord 34 extends Record 35 { 36 public final static short sid = 0x1006; 37 private short field_1_pointNumber; 38 private short field_2_seriesIndex; 39 private short field_3_seriesNumber; 40 private short field_4_formatFlags; 41 private BitField useExcel4Colors = new BitField(0x1); 42 43 44 public DataFormatRecord() 45 { 46 47 } 48 49 57 58 public DataFormatRecord(short id, short size, byte [] data) 59 { 60 super(id, size, data); 61 62 } 63 64 73 74 public DataFormatRecord(short id, short size, byte [] data, int offset) 75 { 76 super(id, size, data, offset); 77 78 } 79 80 85 protected void validateSid(short id) 86 { 87 if (id != sid) 88 { 89 throw new RecordFormatException("Not a DataFormat record"); 90 } 91 } 92 93 protected void fillFields(byte [] data, short size, int offset) 94 { 95 96 int pos = 0; 97 field_1_pointNumber = LittleEndian.getShort(data, pos + 0x0 + offset); 98 field_2_seriesIndex = LittleEndian.getShort(data, pos + 0x2 + offset); 99 field_3_seriesNumber = LittleEndian.getShort(data, pos + 0x4 + offset); 100 field_4_formatFlags = LittleEndian.getShort(data, pos + 0x6 + offset); 101 102 } 103 104 public String toString() 105 { 106 StringBuffer buffer = new StringBuffer (); 107 108 buffer.append("[DATAFORMAT]\n"); 109 buffer.append(" .pointNumber = ") 110 .append("0x").append(HexDump.toHex( getPointNumber ())) 111 .append(" (").append( getPointNumber() ).append(" )"); 112 buffer.append(System.getProperty("line.separator")); 113 buffer.append(" .seriesIndex = ") 114 .append("0x").append(HexDump.toHex( getSeriesIndex ())) 115 .append(" (").append( getSeriesIndex() ).append(" )"); 116 buffer.append(System.getProperty("line.separator")); 117 buffer.append(" .seriesNumber = ") 118 .append("0x").append(HexDump.toHex( getSeriesNumber ())) 119 .append(" (").append( getSeriesNumber() ).append(" )"); 120 buffer.append(System.getProperty("line.separator")); 121 buffer.append(" .formatFlags = ") 122 .append("0x").append(HexDump.toHex( getFormatFlags ())) 123 .append(" (").append( getFormatFlags() ).append(" )"); 124 buffer.append(System.getProperty("line.separator")); 125 buffer.append(" .useExcel4Colors = ").append(isUseExcel4Colors()).append('\n'); 126 127 buffer.append("[/DATAFORMAT]\n"); 128 return buffer.toString(); 129 } 130 131 public int serialize(int offset, byte[] data) 132 { 133 int pos = 0; 134 135 LittleEndian.putShort(data, 0 + offset, sid); 136 LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4)); 137 138 LittleEndian.putShort(data, 4 + offset + pos, field_1_pointNumber); 139 LittleEndian.putShort(data, 6 + offset + pos, field_2_seriesIndex); 140 LittleEndian.putShort(data, 8 + offset + pos, field_3_seriesNumber); 141 LittleEndian.putShort(data, 10 + offset + pos, field_4_formatFlags); 142 143 return getRecordSize(); 144 } 145 146 149 public int getRecordSize() 150 { 151 return 4 + 2 + 2 + 2 + 2; 152 } 153 154 public short getSid() 155 { 156 return this.sid; 157 } 158 159 public Object clone() { 160 DataFormatRecord rec = new DataFormatRecord(); 161 162 rec.field_1_pointNumber = field_1_pointNumber; 163 rec.field_2_seriesIndex = field_2_seriesIndex; 164 rec.field_3_seriesNumber = field_3_seriesNumber; 165 rec.field_4_formatFlags = field_4_formatFlags; 166 return rec; 167 } 168 169 170 171 172 175 public short getPointNumber() 176 { 177 return field_1_pointNumber; 178 } 179 180 183 public void setPointNumber(short field_1_pointNumber) 184 { 185 this.field_1_pointNumber = field_1_pointNumber; 186 } 187 188 191 public short getSeriesIndex() 192 { 193 return field_2_seriesIndex; 194 } 195 196 199 public void setSeriesIndex(short field_2_seriesIndex) 200 { 201 this.field_2_seriesIndex = field_2_seriesIndex; 202 } 203 204 207 public short getSeriesNumber() 208 { 209 return field_3_seriesNumber; 210 } 211 212 215 public void setSeriesNumber(short field_3_seriesNumber) 216 { 217 this.field_3_seriesNumber = field_3_seriesNumber; 218 } 219 220 223 public short getFormatFlags() 224 { 225 return field_4_formatFlags; 226 } 227 228 231 public void setFormatFlags(short field_4_formatFlags) 232 { 233 this.field_4_formatFlags = field_4_formatFlags; 234 } 235 236 240 public void setUseExcel4Colors(boolean value) 241 { 242 field_4_formatFlags = useExcel4Colors.setShortBoolean(field_4_formatFlags, value); 243 } 244 245 249 public boolean isUseExcel4Colors() 250 { 251 return useExcel4Colors.isSet(field_4_formatFlags); 252 } 253 254 255 } 257 258 259 260 | Popular Tags |