1 19 20 package jxl.biff.formula; 21 22 import java.io.UnsupportedEncodingException ; 23 import java.util.ArrayList ; 24 25 import common.Assert; 26 import common.Logger; 27 28 import jxl.biff.RecordData; 29 import jxl.biff.StringHelper; 30 import jxl.biff.IntegerHelper; 31 import jxl.biff.CellReferenceHelper; 32 33 36 class Area extends Operand implements ParsedThing 37 { 38 41 private static Logger logger = Logger.getLogger(Area.class); 42 43 private int columnFirst; 44 private int rowFirst; 45 private int columnLast; 46 private int rowLast; 47 private boolean columnFirstRelative; 48 private boolean rowFirstRelative; 49 private boolean columnLastRelative; 50 private boolean rowLastRelative; 51 52 55 Area() 56 { 57 } 58 59 64 Area(String s) 65 { 66 int seppos = s.indexOf(":"); 67 Assert.verify(seppos != -1); 68 String startcell = s.substring(0, seppos); 69 String endcell = s.substring(seppos+1); 70 71 columnFirst = CellReferenceHelper.getColumn(startcell); 72 rowFirst = CellReferenceHelper.getRow(startcell); 73 columnLast = CellReferenceHelper.getColumn(endcell); 74 rowLast = CellReferenceHelper.getRow(endcell); 75 76 columnFirstRelative = CellReferenceHelper.isColumnRelative(startcell); 77 rowFirstRelative = CellReferenceHelper.isRowRelative(startcell); 78 columnLastRelative = CellReferenceHelper.isColumnRelative(endcell); 79 rowLastRelative = CellReferenceHelper.isRowRelative(endcell); 80 } 81 82 int getFirstColumn() 83 { 84 return columnFirst; 85 } 86 87 int getFirstRow() 88 { 89 return rowFirst; 90 } 91 92 int getLastColumn() 93 { 94 return columnLast; 95 } 96 97 int getLastRow() 98 { 99 return rowLast; 100 } 101 102 109 public int read(byte[] data, int pos) 110 { 111 rowFirst = IntegerHelper.getInt(data[pos], data[pos+1]); 112 rowLast = IntegerHelper.getInt(data[pos+2], data[pos+3]); 113 int columnMask = IntegerHelper.getInt(data[pos+4], data[pos+5]); 114 columnFirst = columnMask & 0x00ff; 115 columnFirstRelative = ((columnMask & 0x4000) != 0); 116 rowFirstRelative = ((columnMask & 0x8000) != 0); 117 columnMask = IntegerHelper.getInt(data[pos+6], data[pos+7]); 118 columnLast = columnMask & 0x00ff; 119 columnLastRelative = ((columnMask & 0x4000) != 0); 120 rowLastRelative = ((columnMask & 0x8000) != 0); 121 122 return 8; 123 } 124 125 130 public void getString(StringBuffer buf) 131 { 132 CellReferenceHelper.getCellReference(columnFirst, rowFirst, buf); 133 buf.append(':'); 134 CellReferenceHelper.getCellReference(columnLast, rowLast, buf); 135 } 136 137 142 byte[] getBytes() 143 { 144 byte[] data = new byte[9]; 145 data[0] = !useAlternateCode() ? Token.AREA.getCode() : 146 Token.AREA.getCode2(); 147 148 IntegerHelper.getTwoBytes(rowFirst, data, 1); 149 IntegerHelper.getTwoBytes(rowLast, data, 3); 150 151 int grcol = columnFirst; 152 153 if (rowFirstRelative) 155 { 156 grcol |= 0x8000; 157 } 158 159 if (columnFirstRelative) 160 { 161 grcol |= 0x4000; 162 } 163 164 IntegerHelper.getTwoBytes(grcol, data, 5); 165 166 grcol = columnLast; 167 168 if (rowLastRelative) 170 { 171 grcol |= 0x8000; 172 } 173 174 if (columnLastRelative) 175 { 176 grcol |= 0x4000; 177 } 178 179 IntegerHelper.getTwoBytes(grcol, data, 7); 180 181 return data; 182 } 183 184 191 public void adjustRelativeCellReferences(int colAdjust, int rowAdjust) 192 { 193 if (columnFirstRelative) 194 { 195 columnFirst += colAdjust; 196 } 197 198 if (columnLastRelative) 199 { 200 columnLast += colAdjust; 201 } 202 203 if (rowFirstRelative) 204 { 205 rowFirst += rowAdjust; 206 } 207 208 if (rowLastRelative) 209 { 210 rowLast += rowAdjust; 211 } 212 } 213 214 224 void columnInserted(int sheetIndex, int col, boolean currentSheet) 225 { 226 if (!currentSheet) 227 { 228 return; 229 } 230 231 if (col <= columnFirst) 232 { 233 columnFirst++; 234 } 235 236 if (col <= columnLast) 237 { 238 columnLast++; 239 } 240 } 241 242 252 void columnRemoved(int sheetIndex, int col, boolean currentSheet) 253 { 254 if (!currentSheet) 255 { 256 return; 257 } 258 259 if (col < columnFirst) 260 { 261 columnFirst--; 262 } 263 264 if (col <= columnLast) 265 { 266 columnLast--; 267 } 268 } 269 270 280 void rowInserted(int sheetIndex, int row, boolean currentSheet) 281 { 282 if (!currentSheet) 283 { 284 return; 285 } 286 287 if (row <= rowFirst) 288 { 289 rowFirst++; 290 } 291 292 if (row <= rowLast) 293 { 294 rowLast++; 295 } 296 } 297 298 308 void rowRemoved(int sheetIndex, int row, boolean currentSheet) 309 { 310 if (!currentSheet) 311 { 312 return; 313 } 314 315 if (row < rowFirst) 316 { 317 rowFirst--; 318 } 319 320 if (row <= rowLast) 321 { 322 rowLast--; 323 } 324 } 325 } 326 327 328 329 330 331 332 333 334 | Popular Tags |