1 16 17 18 package org.apache.poi.hssf.util; 19 20 import org.apache.poi.hssf.record.MergeCellsRecord.MergedRegion; 21 22 29 30 public class Region 31 implements Comparable 32 { 33 private int rowFrom; 34 private short colFrom; 35 private int rowTo; 36 private short colTo; 37 38 41 42 public Region() 43 { 44 } 45 46 public Region(int rowFrom, short colFrom, int rowTo, short colTo) 47 { 48 this.rowFrom = rowFrom; 49 this.rowTo = rowTo; 50 this.colFrom = colFrom; 51 this.colTo = colTo; 52 } 53 54 58 59 public Region(MergedRegion region) 60 { 61 this(region.row_from, region.col_from, region.row_to, region.col_to); 62 } 63 64 69 70 public short getColumnFrom() 71 { 72 return colFrom; 73 } 74 75 80 81 public int getRowFrom() 82 { 83 return rowFrom; 84 } 85 86 91 92 public short getColumnTo() 93 { 94 return colTo; 95 } 96 97 102 103 public int getRowTo() 104 { 105 return rowTo; 106 } 107 108 113 114 public void setColumnFrom(short colFrom) 115 { 116 this.colFrom = colFrom; 117 } 118 119 124 125 public void setRowFrom(int rowFrom) 126 { 127 this.rowFrom = rowFrom; 128 } 129 130 135 136 public void setColumnTo(short colTo) 137 { 138 this.colTo = colTo; 139 } 140 141 146 147 public void setRowTo(int rowTo) 148 { 149 this.rowTo = rowTo; 150 } 151 152 158 159 public boolean contains(int row, short col) 160 { 161 if ((this.rowFrom <= row) && (this.rowTo >= row) 162 && (this.colFrom <= col) && (this.colTo >= col)) 163 { 164 165 return true; 168 } 169 return false; 170 } 171 172 public boolean equals(Region r) 173 { 174 return (compareTo(r) == 0); 175 } 176 177 186 187 public int compareTo(Region r) 188 { 189 if ((this.getRowFrom() == r.getRowFrom()) 190 && (this.getColumnFrom() == r.getColumnFrom()) 191 && (this.getRowTo() == r.getRowTo()) 192 && (this.getColumnTo() == r.getColumnTo())) 193 { 194 return 0; 195 } 196 if ((this.getRowFrom() < r.getRowFrom()) 197 || (this.getColumnFrom() < r.getColumnFrom()) 198 || (this.getRowTo() < r.getRowTo()) 199 || (this.getColumnTo() < r.getColumnTo())) 200 { 201 return 1; 202 } 203 return -1; 204 } 205 206 public int compareTo(Object o) 207 { 208 return compareTo(( Region ) o); 209 } 210 211 214 215 public int getArea() 216 { 217 return ((1 + (getRowTo() - getRowFrom())) 218 * (1 + (getColumnTo() - getColumnFrom()))); 219 } 220 } 221 | Popular Tags |