1 2 17 18 19 package org.apache.poi.hssf.record; 20 21 import org.apache.poi.util.LittleEndian; 22 23 32 33 public class DimensionsRecord 34 extends Record 35 { 36 public final static short sid = 0x200; 37 private int field_1_first_row; 38 private int field_2_last_row; private short field_3_first_col; 40 private short field_4_last_col; 41 private short field_5_zero; 43 public DimensionsRecord() 44 { 45 } 46 47 54 55 public DimensionsRecord(short id, short size, byte [] data) 56 { 57 super(id, size, data); 58 } 59 60 68 69 public DimensionsRecord(short id, short size, byte [] data, int offset) 70 { 71 super(id, size, data, offset); 72 } 73 74 protected void validateSid(short id) 75 { 76 if (id != sid) 77 { 78 throw new RecordFormatException("NOT A valid DIMENSIONS RECORD"); 79 } 80 } 81 82 protected void fillFields(byte [] data, short size, int offset) 83 { 84 field_1_first_row = LittleEndian.getInt(data, 0 + offset); 85 field_2_last_row = LittleEndian.getInt(data, 4 + offset); 86 field_3_first_col = LittleEndian.getShort(data, 8 + offset); 87 field_4_last_col = LittleEndian.getShort(data, 10 + offset); 88 field_5_zero = LittleEndian.getShort(data, 12 + offset); 89 } 90 91 95 96 public void setFirstRow(int row) 97 { 98 field_1_first_row = row; 99 } 100 101 105 106 public void setLastRow(int row) 107 { 108 field_2_last_row = row; 109 } 110 111 115 116 public void setFirstCol(short col) 117 { 118 field_3_first_col = col; 119 } 120 121 125 126 public void setLastCol(short col) 127 { 128 field_4_last_col = col; 129 } 130 131 135 136 public int getFirstRow() 137 { 138 return field_1_first_row; 139 } 140 141 145 146 public int getLastRow() 147 { 148 return field_2_last_row; 149 } 150 151 155 156 public short getFirstCol() 157 { 158 return field_3_first_col; 159 } 160 161 165 166 public short getLastCol() 167 { 168 return field_4_last_col; 169 } 170 171 public String toString() 172 { 173 StringBuffer buffer = new StringBuffer (); 174 175 buffer.append("[DIMENSIONS]\n"); 176 buffer.append(" .firstrow = ") 177 .append(Integer.toHexString(getFirstRow())).append("\n"); 178 buffer.append(" .lastrow = ") 179 .append(Integer.toHexString(getLastRow())).append("\n"); 180 buffer.append(" .firstcol = ") 181 .append(Integer.toHexString(getFirstCol())).append("\n"); 182 buffer.append(" .lastcol = ") 183 .append(Integer.toHexString(getLastCol())).append("\n"); 184 buffer.append(" .zero = ") 185 .append(Integer.toHexString(field_5_zero)).append("\n"); 186 buffer.append("[/DIMENSIONS]\n"); 187 return buffer.toString(); 188 } 189 190 public int serialize(int offset, byte [] data) 191 { 192 LittleEndian.putShort(data, 0 + offset, sid); 193 LittleEndian.putShort(data, 2 + offset, ( short ) 14); 194 LittleEndian.putInt(data, 4 + offset, getFirstRow()); 195 LittleEndian.putInt(data, 8 + offset, getLastRow()); 196 LittleEndian.putShort(data, 12 + offset, getFirstCol()); 197 LittleEndian.putShort(data, 14 + offset, getLastCol()); 198 LittleEndian.putShort(data, 16 + offset, ( short ) 0); 199 return getRecordSize(); 200 } 201 202 public int getRecordSize() 203 { 204 return 18; 205 } 206 207 public short getSid() 208 { 209 return this.sid; 210 } 211 212 public Object clone() { 213 DimensionsRecord rec = new DimensionsRecord(); 214 rec.field_1_first_row = field_1_first_row; 215 rec.field_2_last_row = field_2_last_row; 216 rec.field_3_first_col = field_3_first_col; 217 rec.field_4_last_col = field_4_last_col; 218 rec.field_5_zero = field_5_zero; 219 return rec; 220 } 221 } 222 | Popular Tags |