1 19 20 package jxl.biff; 21 22 import jxl.Range; 23 import jxl.Cell; 24 import jxl.Sheet; 25 26 32 public class SheetRangeImpl implements Range 33 { 34 37 private Sheet sheet; 38 39 42 private int column1; 43 44 47 private int row1; 48 49 52 private int column2; 53 54 57 private int row2; 58 59 67 public SheetRangeImpl(Sheet s, int c1, int r1, 68 int c2, int r2) 69 { 70 sheet = s; 71 row1 = r1; 72 row2 = r2; 73 column1 = c1; 74 column2 = c2; 75 } 76 77 83 public SheetRangeImpl(SheetRangeImpl c, Sheet s) 84 { 85 sheet = s; 86 row1 = c.row1; 87 row2 = c.row2; 88 column1 = c.column1; 89 column2 = c.column2; 90 } 91 92 97 public Cell getTopLeft() 98 { 99 return sheet.getCell(column1, row1); 100 } 101 102 107 public Cell getBottomRight() 108 { 109 return sheet.getCell(column2, row2); 110 } 111 112 118 public int getFirstSheetIndex() 119 { 120 return -1; 121 } 122 123 129 public int getLastSheetIndex() 130 { 131 return -1; 132 } 133 134 143 public boolean intersects(SheetRangeImpl range) 144 { 145 if (range == this) 146 { 147 return true; 148 } 149 150 if (row2 < range.row1 || 151 row1 > range.row2 || 152 column2 < range.column1 || 153 column1 > range.column2) 154 { 155 return false; 156 } 157 158 return true; 159 } 160 161 166 public String toString() 167 { 168 StringBuffer sb = new StringBuffer (); 169 CellReferenceHelper.getCellReference(column1, row1, sb); 170 sb.append('-'); 171 CellReferenceHelper.getCellReference(column2, row2, sb); 172 return sb.toString(); 173 } 174 175 180 public void insertRow(int r) 181 { 182 if (r > row2) 183 { 184 return; 185 } 186 187 if (r <= row1) 188 { 189 row1++; 190 } 191 192 if (r <= row2) 193 { 194 row2++; 195 } 196 } 197 198 203 public void insertColumn(int c) 204 { 205 if (c > column2) 206 { 207 return; 208 } 209 210 if (c <= column1) 211 { 212 column1++; 213 } 214 215 if (c <= column2) 216 { 217 column2++; 218 } 219 } 220 221 226 public void removeRow(int r) 227 { 228 if (r > row2) 229 { 230 return; 231 } 232 233 if (r < row1) 234 { 235 row1--; 236 } 237 238 if (r < row2) 239 { 240 row2--; 241 } 242 } 243 244 249 public void removeColumn(int c) 250 { 251 if (c > column2) 252 { 253 return; 254 } 255 256 if (c < column1) 257 { 258 column1--; 259 } 260 261 if (c < column2) 262 { 263 column2--; 264 } 265 } 266 267 272 public int hashCode() 273 { 274 return 0xffff ^ row1 ^ row2 ^ column1 ^ column2; 275 } 276 277 283 public boolean equals(Object o) 284 { 285 if (o == this) 286 { 287 return true; 288 } 289 290 if (!(o instanceof SheetRangeImpl)) 291 { 292 return false; 293 } 294 295 SheetRangeImpl compare = (SheetRangeImpl) o; 296 297 return (column1 == compare.column1 && 298 column2 == compare.column2 && 299 row1 == compare.row1 && 300 row2 == compare.row2); 301 } 302 303 } 304 305 306 307 308 309 310 311 312 313 314 | Popular Tags |