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 BarRecord 34 extends Record 35 { 36 public final static short sid = 0x1017; 37 private short field_1_barSpace; 38 private short field_2_categorySpace; 39 private short field_3_formatFlags; 40 private BitField horizontal = new BitField(0x1); 41 private BitField stacked = new BitField(0x2); 42 private BitField displayAsPercentage = new BitField(0x4); 43 private BitField shadow = new BitField(0x8); 44 45 46 public BarRecord() 47 { 48 49 } 50 51 59 60 public BarRecord(short id, short size, byte [] data) 61 { 62 super(id, size, data); 63 64 } 65 66 75 76 public BarRecord(short id, short size, byte [] data, int offset) 77 { 78 super(id, size, data, offset); 79 80 } 81 82 87 protected void validateSid(short id) 88 { 89 if (id != sid) 90 { 91 throw new RecordFormatException("Not a Bar record"); 92 } 93 } 94 95 protected void fillFields(byte [] data, short size, int offset) 96 { 97 98 int pos = 0; 99 field_1_barSpace = LittleEndian.getShort(data, pos + 0x0 + offset); 100 field_2_categorySpace = LittleEndian.getShort(data, pos + 0x2 + offset); 101 field_3_formatFlags = LittleEndian.getShort(data, pos + 0x4 + offset); 102 103 } 104 105 public String toString() 106 { 107 StringBuffer buffer = new StringBuffer (); 108 109 buffer.append("[BAR]\n"); 110 buffer.append(" .barSpace = ") 111 .append("0x").append(HexDump.toHex( getBarSpace ())) 112 .append(" (").append( getBarSpace() ).append(" )"); 113 buffer.append(System.getProperty("line.separator")); 114 buffer.append(" .categorySpace = ") 115 .append("0x").append(HexDump.toHex( getCategorySpace ())) 116 .append(" (").append( getCategorySpace() ).append(" )"); 117 buffer.append(System.getProperty("line.separator")); 118 buffer.append(" .formatFlags = ") 119 .append("0x").append(HexDump.toHex( getFormatFlags ())) 120 .append(" (").append( getFormatFlags() ).append(" )"); 121 buffer.append(System.getProperty("line.separator")); 122 buffer.append(" .horizontal = ").append(isHorizontal()).append('\n'); 123 buffer.append(" .stacked = ").append(isStacked()).append('\n'); 124 buffer.append(" .displayAsPercentage = ").append(isDisplayAsPercentage()).append('\n'); 125 buffer.append(" .shadow = ").append(isShadow()).append('\n'); 126 127 buffer.append("[/BAR]\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_barSpace); 139 LittleEndian.putShort(data, 6 + offset + pos, field_2_categorySpace); 140 LittleEndian.putShort(data, 8 + offset + pos, field_3_formatFlags); 141 142 return getRecordSize(); 143 } 144 145 148 public int getRecordSize() 149 { 150 return 4 + 2 + 2 + 2; 151 } 152 153 public short getSid() 154 { 155 return this.sid; 156 } 157 158 public Object clone() { 159 BarRecord rec = new BarRecord(); 160 161 rec.field_1_barSpace = field_1_barSpace; 162 rec.field_2_categorySpace = field_2_categorySpace; 163 rec.field_3_formatFlags = field_3_formatFlags; 164 return rec; 165 } 166 167 168 169 170 173 public short getBarSpace() 174 { 175 return field_1_barSpace; 176 } 177 178 181 public void setBarSpace(short field_1_barSpace) 182 { 183 this.field_1_barSpace = field_1_barSpace; 184 } 185 186 189 public short getCategorySpace() 190 { 191 return field_2_categorySpace; 192 } 193 194 197 public void setCategorySpace(short field_2_categorySpace) 198 { 199 this.field_2_categorySpace = field_2_categorySpace; 200 } 201 202 205 public short getFormatFlags() 206 { 207 return field_3_formatFlags; 208 } 209 210 213 public void setFormatFlags(short field_3_formatFlags) 214 { 215 this.field_3_formatFlags = field_3_formatFlags; 216 } 217 218 222 public void setHorizontal(boolean value) 223 { 224 field_3_formatFlags = horizontal.setShortBoolean(field_3_formatFlags, value); 225 } 226 227 231 public boolean isHorizontal() 232 { 233 return horizontal.isSet(field_3_formatFlags); 234 } 235 236 240 public void setStacked(boolean value) 241 { 242 field_3_formatFlags = stacked.setShortBoolean(field_3_formatFlags, value); 243 } 244 245 249 public boolean isStacked() 250 { 251 return stacked.isSet(field_3_formatFlags); 252 } 253 254 258 public void setDisplayAsPercentage(boolean value) 259 { 260 field_3_formatFlags = displayAsPercentage.setShortBoolean(field_3_formatFlags, value); 261 } 262 263 267 public boolean isDisplayAsPercentage() 268 { 269 return displayAsPercentage.isSet(field_3_formatFlags); 270 } 271 272 276 public void setShadow(boolean value) 277 { 278 field_3_formatFlags = shadow.setShortBoolean(field_3_formatFlags, value); 279 } 280 281 285 public boolean isShadow() 286 { 287 return shadow.isSet(field_3_formatFlags); 288 } 289 290 291 } 293 294 295 296 | Popular Tags |