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 Area3d extends Operand implements ParsedThing 37 { 38 41 private static Logger logger = Logger.getLogger(Area3d.class); 42 43 private int sheet; 44 private int columnFirst; 45 private int rowFirst; 46 private int columnLast; 47 private int rowLast; 48 private boolean columnFirstRelative; 49 private boolean rowFirstRelative; 50 private boolean columnLastRelative; 51 private boolean rowLastRelative; 52 53 56 private ExternalSheet workbook; 57 58 Area3d(ExternalSheet es) 59 { 60 workbook = es; 61 } 62 63 68 Area3d(String s, ExternalSheet es) throws FormulaException 69 { 70 workbook = es; 71 int seppos = s.lastIndexOf(":"); 72 Assert.verify(seppos != -1); 73 String startcell = s.substring(0, seppos); 74 String endcell = s.substring(seppos+1); 75 76 int sep = s.indexOf('!'); 78 String cellString = s.substring(sep+1, seppos); 79 columnFirst = CellReferenceHelper.getColumn(cellString); 80 rowFirst = CellReferenceHelper.getRow(cellString); 81 82 String sheetName = s.substring(0, sep); 84 int sheetNamePos = sheetName.lastIndexOf(']'); 85 86 if (sheetName.charAt(0) == '\'' && 88 sheetName.charAt(sheetName.length()-1) == '\'') 89 { 90 sheetName = sheetName.substring(1, sheetName.length() - 1); 91 } 92 93 sheet = es.getExternalSheetIndex(sheetName); 94 95 if (sheet < 0) 96 { 97 throw new FormulaException(FormulaException.sheetRefNotFound, sheetName); 98 } 99 100 columnLast = CellReferenceHelper.getColumn(endcell); 102 rowLast = CellReferenceHelper.getRow(endcell); 103 104 columnFirstRelative = true; 105 rowFirstRelative = true; 106 columnLastRelative = true; 107 rowLastRelative = true; 108 } 109 110 int getFirstColumn() {return columnFirst;} 111 int getFirstRow() {return rowFirst;} 112 int getLastColumn() {return columnLast;} 113 int getLastRow() {return rowLast;} 114 115 122 public int read(byte[] data, int pos) 123 { 124 sheet = IntegerHelper.getInt(data[pos], data[pos+1]); 125 rowFirst = IntegerHelper.getInt(data[pos+2], data[pos+3]); 126 rowLast = IntegerHelper.getInt(data[pos+4], data[pos+5]); 127 int columnMask = IntegerHelper.getInt(data[pos+6], data[pos+7]); 128 columnFirst = columnMask & 0x00ff; 129 columnFirstRelative = ((columnMask & 0x4000) != 0); 130 rowFirstRelative = ((columnMask & 0x8000) != 0); 131 columnMask = IntegerHelper.getInt(data[pos+8], data[pos+9]); 132 columnLast = columnMask & 0x00ff; 133 columnLastRelative = ((columnMask & 0x4000) != 0); 134 rowLastRelative = ((columnMask & 0x8000) != 0); 135 136 return 10; 137 } 138 139 public void getString(StringBuffer buf) 140 { 141 CellReferenceHelper.getCellReference 142 (sheet, columnFirst, rowFirst, workbook, buf); 143 buf.append(':'); 144 CellReferenceHelper.getCellReference(columnLast, rowLast, buf); 145 } 146 147 152 byte[] getBytes() 153 { 154 byte[] data = new byte[11]; 155 data[0] = Token.AREA3D.getCode(); 156 157 IntegerHelper.getTwoBytes(sheet, data, 1); 158 159 IntegerHelper.getTwoBytes(rowFirst, data, 3); 160 IntegerHelper.getTwoBytes(rowLast, data, 5); 161 162 int grcol = columnFirst; 163 164 if (rowFirstRelative) 166 { 167 grcol |= 0x8000; 168 } 169 170 if (columnFirstRelative) 171 { 172 grcol |= 0x4000; 173 } 174 175 IntegerHelper.getTwoBytes(grcol, data, 7); 176 177 grcol = columnLast; 178 179 if (rowLastRelative) 181 { 182 grcol |= 0x8000; 183 } 184 185 if (columnLastRelative) 186 { 187 grcol |= 0x4000; 188 } 189 190 IntegerHelper.getTwoBytes(grcol, data, 9); 191 192 return data; 193 } 194 195 202 public void adjustRelativeCellReferences(int colAdjust, int rowAdjust) 203 { 204 if (columnFirstRelative) 205 { 206 columnFirst += colAdjust; 207 } 208 209 if (columnLastRelative) 210 { 211 columnLast += colAdjust; 212 } 213 214 if (rowFirstRelative) 215 { 216 rowFirst += rowAdjust; 217 } 218 219 if (rowLastRelative) 220 { 221 rowLast += rowAdjust; 222 } 223 } 224 225 235 public void columnInserted(int sheetIndex, int col, boolean currentSheet) 236 { 237 if (sheetIndex != sheet) 238 { 239 return; 240 } 241 242 if (columnFirst >= col) 243 { 244 columnFirst++; 245 } 246 247 if (columnLast >= col) 248 { 249 columnLast++; 250 } 251 } 252 253 263 void columnRemoved(int sheetIndex, int col, boolean currentSheet) 264 { 265 if (sheetIndex != sheet) 266 { 267 return; 268 } 269 270 if (col < columnFirst) 271 { 272 columnFirst--; 273 } 274 275 if (col <= columnLast) 276 { 277 columnLast--; 278 } 279 } 280 281 291 void rowInserted(int sheetIndex, int row, boolean currentSheet) 292 { 293 if (sheetIndex != sheet) 294 { 295 return; 296 } 297 298 if (row <= rowFirst) 299 { 300 rowFirst++; 301 } 302 303 if (row <= rowLast) 304 { 305 rowLast++; 306 } 307 } 308 309 319 void rowRemoved(int sheetIndex, int row, boolean currentSheet) 320 { 321 if (sheetIndex != sheet) 322 { 323 return; 324 } 325 if (row < rowFirst) 326 { 327 rowFirst--; 328 } 329 330 if (row <= rowLast) 331 { 332 rowLast--; 333 } 334 } 335 336 337 } 338 339 340 341 342 343 344 345 346 | Popular Tags |