1 19 20 package jxl.biff.formula; 21 22 import common.Logger; 23 import jxl.Cell; 24 import jxl.biff.IntegerHelper; 25 import jxl.biff.CellReferenceHelper; 26 27 30 class CellReference extends Operand implements ParsedThing 31 { 32 35 private static Logger logger = Logger.getLogger(CellReference.class); 36 37 40 private boolean columnRelative; 41 42 45 private boolean rowRelative; 46 47 50 private int column; 51 52 55 private int row; 56 57 61 private Cell relativeTo; 62 63 68 public CellReference(Cell rt) 69 { 70 relativeTo = rt; 71 } 72 73 76 public CellReference() 77 { 78 } 79 80 85 public CellReference(String s) 86 { 87 column = CellReferenceHelper.getColumn(s); 88 row = CellReferenceHelper.getRow(s); 89 columnRelative = CellReferenceHelper.isColumnRelative(s); 90 rowRelative = CellReferenceHelper.isRowRelative(s); 91 } 92 93 100 public int read(byte[] data, int pos) 101 { 102 row = IntegerHelper.getInt(data[pos], data[pos+1]); 103 int columnMask = IntegerHelper.getInt(data[pos+2], data[pos+3]); 104 column = columnMask & 0x00ff; 105 columnRelative = ((columnMask & 0x4000) != 0); 106 rowRelative = ((columnMask & 0x8000) != 0); 107 108 return 4; 109 } 110 111 116 public int getColumn() 117 { 118 return column; 119 } 120 121 126 public int getRow() 127 { 128 return row; 129 } 130 131 136 public void getString(StringBuffer buf) 137 { 138 CellReferenceHelper.getCellReference(column, !columnRelative, 139 row, !rowRelative, 140 buf); 141 } 142 143 148 byte[] getBytes() 149 { 150 byte[] data = new byte[5]; 151 data[0] = !useAlternateCode() ? Token.REF.getCode() : 152 Token.REF.getCode2(); 153 154 IntegerHelper.getTwoBytes(row, data, 1); 155 156 int grcol = column; 157 158 if (rowRelative) 160 { 161 grcol |= 0x8000; 162 } 163 164 if (columnRelative) 165 { 166 grcol |= 0x4000; 167 } 168 169 IntegerHelper.getTwoBytes(grcol, data, 3); 170 171 return data; 172 } 173 174 181 public void adjustRelativeCellReferences(int colAdjust, int rowAdjust) 182 { 183 if (columnRelative) 184 { 185 column += colAdjust; 186 } 187 188 if (rowRelative) 189 { 190 row += rowAdjust; 191 } 192 } 193 194 204 public void columnInserted(int sheetIndex, int col, boolean currentSheet) 205 { 206 if (!currentSheet) 207 { 208 return; 209 } 210 211 if (column >= col) 212 { 213 column++; 214 } 215 } 216 217 227 void columnRemoved(int sheetIndex, int col, boolean currentSheet) 228 { 229 if (!currentSheet) 230 { 231 return; 232 } 233 234 if (column >= col) 235 { 236 column--; 237 } 238 } 239 240 250 void rowInserted(int sheetIndex, int r, boolean currentSheet) 251 { 252 if (!currentSheet) 253 { 254 return; 255 } 256 257 if (row >= r) 258 { 259 row++; 260 } 261 } 262 263 273 void rowRemoved(int sheetIndex, int r, boolean currentSheet) 274 { 275 if (!currentSheet) 276 { 277 return; 278 } 279 280 if (row >= r) 281 { 282 row--; 283 } 284 } 285 } 286 | Popular Tags |