1 2 17 18 19 package org.apache.poi.hssf.record; 20 21 import org.apache.poi.util.BitField; 22 import org.apache.poi.util.LittleEndian; 23 24 32 33 public class RowRecord 34 extends Record 35 implements Comparable 36 { 37 public final static short sid = 0x208; 38 39 42 public final static int MAX_ROW_NUMBER = 65535; 43 44 private int field_1_row_number; 46 private short field_2_first_col; 47 private short field_3_last_col; private short field_4_height; 49 private short field_5_optimize; 51 private short field_6_reserved; 53 private short field_7_option_flags; 54 private BitField outlineLevel = new BitField(0x07); 55 56 private BitField colapsed = new BitField(0x10); 58 private BitField zeroHeight = new BitField(0x20); 59 private BitField badFontHeight = new BitField(0x40); 60 private BitField formatted = new BitField(0x80); 61 private short field_8_xf_index; 63 public RowRecord() 64 { 65 } 66 67 74 75 public RowRecord(short id, short size, byte [] data) 76 { 77 super(id, size, data); 78 } 79 80 88 89 public RowRecord(short id, short size, byte [] data, int offset) 90 { 91 super(id, size, data, offset); 92 } 93 94 protected void validateSid(short id) 95 { 96 if (id != sid) 97 { 98 throw new RecordFormatException("NOT A valid ROW RECORD"); 99 } 100 } 101 102 protected void fillFields(byte [] data, short size, int offset) 103 { 104 field_1_row_number = LittleEndian.getUShort(data, 0 + offset); 106 field_2_first_col = LittleEndian.getShort(data, 2 + offset); 107 field_3_last_col = LittleEndian.getShort(data, 4 + offset); 108 field_4_height = LittleEndian.getShort(data, 6 + offset); 109 field_5_optimize = LittleEndian.getShort(data, 8 + offset); 110 field_6_reserved = LittleEndian.getShort(data, 10 + offset); 111 field_7_option_flags = LittleEndian.getShort(data, 12 + offset); 112 field_8_xf_index = LittleEndian.getShort(data, 14 + offset); 113 } 114 115 119 120 public void setRowNumber(int row) 122 { 123 field_1_row_number = row; 124 } 125 126 130 131 public void setFirstCol(short col) 132 { 133 field_2_first_col = col; 134 } 135 136 140 141 public void setLastCol(short col) 142 { 143 field_3_last_col = col; 144 } 145 146 150 151 public void setHeight(short height) 152 { 153 field_4_height = height; 154 } 155 156 160 161 public void setOptimize(short optimize) 162 { 163 field_5_optimize = optimize; 164 } 165 166 171 172 public void setOptionFlags(short options) 173 { 174 field_7_option_flags = options; 175 } 176 177 179 184 185 public void setOutlineLevel(short ol) 186 { 187 field_7_option_flags = 188 outlineLevel.setShortValue(field_7_option_flags, ol); 189 } 190 191 196 197 public void setColapsed(boolean c) 198 { 199 field_7_option_flags = colapsed.setShortBoolean(field_7_option_flags, 200 c); 201 } 202 203 208 209 public void setZeroHeight(boolean z) 210 { 211 field_7_option_flags = 212 zeroHeight.setShortBoolean(field_7_option_flags, z); 213 } 214 215 220 221 public void setBadFontHeight(boolean f) 222 { 223 field_7_option_flags = 224 badFontHeight.setShortBoolean(field_7_option_flags, f); 225 } 226 227 232 233 public void setFormatted(boolean f) 234 { 235 field_7_option_flags = formatted.setShortBoolean(field_7_option_flags, 236 f); 237 } 238 239 241 246 247 public void setXFIndex(short index) 248 { 249 field_8_xf_index = index; 250 } 251 252 256 257 public int getRowNumber() 259 { 260 return field_1_row_number; 261 } 262 263 267 268 public short getFirstCol() 269 { 270 return field_2_first_col; 271 } 272 273 277 278 public short getLastCol() 279 { 280 return field_3_last_col; 281 } 282 283 287 288 public short getHeight() 289 { 290 return field_4_height; 291 } 292 293 297 298 public short getOptimize() 299 { 300 return field_5_optimize; 301 } 302 303 308 309 public short getOptionFlags() 310 { 311 return field_7_option_flags; 312 } 313 314 316 321 322 public short getOutlineLevel() 323 { 324 return outlineLevel.getShortValue(field_7_option_flags); 325 } 326 327 332 333 public boolean getColapsed() 334 { 335 return (colapsed.isSet(field_7_option_flags)); 336 } 337 338 343 344 public boolean getZeroHeight() 345 { 346 return zeroHeight.isSet(field_7_option_flags); 347 } 348 349 354 355 public boolean getBadFontHeight() 356 { 357 return badFontHeight.isSet(field_7_option_flags); 358 } 359 360 365 366 public boolean getFormatted() 367 { 368 return formatted.isSet(field_7_option_flags); 369 } 370 371 373 378 379 public short getXFIndex() 380 { 381 return field_8_xf_index; 382 } 383 384 public boolean isInValueSection() 385 { 386 return true; 387 } 388 389 public String toString() 390 { 391 StringBuffer buffer = new StringBuffer (); 392 393 buffer.append("[ROW]\n"); 394 buffer.append(" .rownumber = ") 395 .append(Integer.toHexString(getRowNumber())).append("\n"); 396 buffer.append(" .firstcol = ") 397 .append(Integer.toHexString(getFirstCol())).append("\n"); 398 buffer.append(" .lastcol = ") 399 .append(Integer.toHexString(getLastCol())).append("\n"); 400 buffer.append(" .height = ") 401 .append(Integer.toHexString(getHeight())).append("\n"); 402 buffer.append(" .optimize = ") 403 .append(Integer.toHexString(getOptimize())).append("\n"); 404 buffer.append(" .reserved = ") 405 .append(Integer.toHexString(field_6_reserved)).append("\n"); 406 buffer.append(" .optionflags = ") 407 .append(Integer.toHexString(getOptionFlags())).append("\n"); 408 buffer.append(" .outlinelvl = ") 409 .append(Integer.toHexString(getOutlineLevel())).append("\n"); 410 buffer.append(" .colapsed = ").append(getColapsed()) 411 .append("\n"); 412 buffer.append(" .zeroheight = ").append(getZeroHeight()) 413 .append("\n"); 414 buffer.append(" .badfontheig= ").append(getBadFontHeight()) 415 .append("\n"); 416 buffer.append(" .formatted = ").append(getFormatted()) 417 .append("\n"); 418 buffer.append(" .xfindex = ") 419 .append(Integer.toHexString(getXFIndex())).append("\n"); 420 buffer.append("[/ROW]\n"); 421 return buffer.toString(); 422 } 423 424 public int serialize(int offset, byte [] data) 425 { 426 LittleEndian.putShort(data, 0 + offset, sid); 427 LittleEndian.putShort(data, 2 + offset, ( short ) 16); 428 LittleEndian.putShort(data, 4 + offset, ( short ) getRowNumber()); 430 LittleEndian.putShort(data, 6 + offset, getFirstCol() == -1 ? (short)0 : getFirstCol()); 431 LittleEndian.putShort(data, 8 + offset, getLastCol() == -1 ? (short)0 : getLastCol()); 432 LittleEndian.putShort(data, 10 + offset, getHeight()); 433 LittleEndian.putShort(data, 12 + offset, getOptimize()); 434 LittleEndian.putShort(data, 14 + offset, field_6_reserved); 435 LittleEndian.putShort(data, 16 + offset, getOptionFlags()); 436 437 LittleEndian.putShort(data, 18 + offset, getXFIndex()); 439 return getRecordSize(); 440 } 441 442 public int getRecordSize() 443 { 444 return 20; 445 } 446 447 public short getSid() 448 { 449 return this.sid; 450 } 451 452 public int compareTo(Object obj) 453 { 454 RowRecord loc = ( RowRecord ) obj; 455 456 if (this.getRowNumber() == loc.getRowNumber()) 457 { 458 return 0; 459 } 460 if (this.getRowNumber() < loc.getRowNumber()) 461 { 462 return -1; 463 } 464 if (this.getRowNumber() > loc.getRowNumber()) 465 { 466 return 1; 467 } 468 return -1; 469 } 470 471 public boolean equals(Object obj) 472 { 473 if (!(obj instanceof RowRecord)) 474 { 475 return false; 476 } 477 RowRecord loc = ( RowRecord ) obj; 478 479 if (this.getRowNumber() == loc.getRowNumber()) 480 { 481 return true; 482 } 483 return false; 484 } 485 486 public Object clone() { 487 RowRecord rec = new RowRecord(); 488 rec.field_1_row_number = field_1_row_number; 489 rec.field_2_first_col = field_2_first_col; 490 rec.field_3_last_col = field_3_last_col; 491 rec.field_4_height = field_4_height; 492 rec.field_5_optimize = field_5_optimize; 493 rec.field_6_reserved = field_6_reserved; 494 rec.field_7_option_flags = field_7_option_flags; 495 rec.field_8_xf_index = field_8_xf_index; 496 return rec; 497 } 498 } 499 | Popular Tags |