1 2 17 18 19 package org.apache.poi.hssf.record; 20 21 import java.util.*; 22 23 import org.apache.poi.util.LittleEndian; 24 25 36 37 public class SelectionRecord 38 extends Record 39 { 40 public final static short sid = 0x1d; 41 private byte field_1_pane; 42 private int field_2_row_active_cell; 44 private short field_3_col_active_cell; 45 private short field_4_ref_active_cell; 46 private short field_5_num_refs; 47 private ArrayList field_6_refs; 49 public SelectionRecord() 50 { 51 } 52 53 60 61 public SelectionRecord(short id, short size, byte [] data) 62 { 63 super(id, size, data); 64 } 65 66 74 75 public SelectionRecord(short id, short size, byte [] data, int offset) 76 { 77 super(id, size, data, offset); 78 } 79 80 protected void validateSid(short id) 81 { 82 if (id != sid) 83 { 84 throw new RecordFormatException("NOT A valid Selection RECORD"); 85 } 86 } 87 88 protected void fillFields(byte [] data, short size, int offset) 89 { 90 field_1_pane = data[ 0 + offset ]; 91 field_2_row_active_cell = LittleEndian.getUShort(data, 1 + offset); 93 field_3_col_active_cell = LittleEndian.getShort(data, 3 + offset); 94 field_4_ref_active_cell = LittleEndian.getShort(data, 5 + offset); 95 field_5_num_refs = LittleEndian.getShort(data, 7 + offset); 96 } 97 98 102 103 public void setPane(byte pane) 104 { 105 field_1_pane = pane; 106 } 107 108 112 113 public void setActiveCellRow(int row) 115 { 116 field_2_row_active_cell = row; 117 } 118 119 123 124 public void setActiveCellCol(short col) 125 { 126 field_3_col_active_cell = col; 127 } 128 129 133 134 public void setActiveCellRef(short ref) 135 { 136 field_4_ref_active_cell = ref; 137 } 138 139 143 144 public void setNumRefs(short refs) 145 { 146 field_5_num_refs = refs; 147 } 148 149 153 154 public byte getPane() 155 { 156 return field_1_pane; 157 } 158 159 163 164 public int getActiveCellRow() 166 { 167 return field_2_row_active_cell; 168 } 169 170 174 175 public short getActiveCellCol() 176 { 177 return field_3_col_active_cell; 178 } 179 180 184 185 public short getActiveCellRef() 186 { 187 return field_4_ref_active_cell; 188 } 189 190 194 195 public short getNumRefs() 196 { 197 return field_5_num_refs; 198 } 199 200 public String toString() 201 { 202 StringBuffer buffer = new StringBuffer (); 203 204 buffer.append("[SELECTION]\n"); 205 buffer.append(" .pane = ") 206 .append(Integer.toHexString(getPane())).append("\n"); 207 buffer.append(" .activecellrow = ") 208 .append(Integer.toHexString(getActiveCellRow())).append("\n"); 209 buffer.append(" .activecellcol = ") 210 .append(Integer.toHexString(getActiveCellCol())).append("\n"); 211 buffer.append(" .activecellref = ") 212 .append(Integer.toHexString(getActiveCellRef())).append("\n"); 213 buffer.append(" .numrefs = ") 214 .append(Integer.toHexString(getNumRefs())).append("\n"); 215 buffer.append("[/SELECTION]\n"); 216 return buffer.toString(); 217 } 218 219 public int serialize(int offset, byte [] data) 221 { 222 LittleEndian.putShort(data, 0 + offset, sid); 223 LittleEndian.putShort(data, 2 + offset, ( short ) 15); 224 data[ 4 + offset ] = getPane(); 225 LittleEndian.putShort(data, 5 + offset, ( short ) getActiveCellRow()); 227 LittleEndian.putShort(data, 7 + offset, getActiveCellCol()); 228 LittleEndian.putShort(data, 9 + offset, getActiveCellRef()); 229 LittleEndian.putShort(data, 11 + offset, ( short ) 1); 230 LittleEndian.putShort(data, 13 + offset, ( short ) getActiveCellRow()); 231 LittleEndian.putShort(data, 15 + offset, ( short ) getActiveCellRow()); 232 data[ 17 + offset ] = (byte)getActiveCellCol(); 233 data[ 18 + offset ] = (byte)getActiveCellCol(); 234 return getRecordSize(); 235 } 236 237 public int getRecordSize() 238 { 239 return 19; 240 } 241 242 public short getSid() 243 { 244 return this.sid; 245 } 246 247 public Object clone() { 248 SelectionRecord rec = new SelectionRecord(); 249 rec.field_1_pane = field_1_pane; 250 rec.field_2_row_active_cell = field_2_row_active_cell; 251 rec.field_3_col_active_cell = field_3_col_active_cell; 252 rec.field_4_ref_active_cell = field_4_ref_active_cell; 253 rec.field_5_num_refs = field_5_num_refs; 254 rec.field_6_refs = field_6_refs; 255 return rec; 256 } 257 } 258 | Popular Tags |