1 16 17 package org.apache.poi.hssf.usermodel; 18 19 import org.apache.poi.ddf.EscherClientAnchorRecord; 20 import org.apache.poi.ddf.EscherRecord; 21 22 23 29 public class HSSFClientAnchor 30 extends HSSFAnchor 31 { 32 short col1; 33 int row1; 34 short col2; 35 int row2; 36 37 40 public HSSFClientAnchor() 41 { 42 } 43 44 57 public HSSFClientAnchor( int dx1, int dy1, int dx2, int dy2, short col1, int row1, short col2, int row2 ) 58 { 59 super( dx1, dy1, dx2, dy2 ); 60 61 checkRange(dx1, 0, 1023, "dx1"); 62 checkRange(dx2, 0, 1023, "dx2"); 63 checkRange(dy1, 0, 255, "dy1"); 64 checkRange(dy2, 0, 255, "dy2"); 65 checkRange(col1, 0, 255, "col1"); 66 checkRange(col2, 0, 255, "col2"); 67 checkRange(row1, 0, 255 * 256, "row1"); 68 checkRange(row2, 0, 255 * 256, "row2"); 69 70 this.col1 = col1; 71 this.row1 = row1; 72 this.col2 = col2; 73 this.row2 = row2; 74 } 75 76 82 public float getAnchorHeightInPoints(HSSFSheet sheet ) 83 { 84 int y1 = Math.min( getDy1(), getDy2() ); 85 int y2 = Math.max( getDy1(), getDy2() ); 86 int row1 = Math.min( getRow1(), getRow2() ); 87 int row2 = Math.max( getRow1(), getRow2() ); 88 89 float points = 0; 90 if (row1 == row2) 91 { 92 points = ((y2 - y1) / 256.0f) * getRowHeightInPoints(sheet, row2); 93 } 94 else 95 { 96 points += ((256.0f - y1) / 256.0f) * getRowHeightInPoints(sheet, row1); 97 for (int i = row1 + 1; i < row2; i++) 98 { 99 points += getRowHeightInPoints(sheet, i); 100 } 101 points += (y2 / 256.0f) * getRowHeightInPoints(sheet, row2); 102 } 103 104 return points; 105 } 106 107 private float getRowHeightInPoints(HSSFSheet sheet, int rowNum) 108 { 109 HSSFRow row = sheet.getRow(rowNum); 110 if (row == null) 111 return sheet.getDefaultRowHeightInPoints(); 112 else 113 return row.getHeightInPoints(); 114 } 115 116 public short getCol1() 117 { 118 return col1; 119 } 120 121 public void setCol1( short col1 ) 122 { 123 checkRange(col1, 0, 255, "col1"); 124 this.col1 = col1; 125 } 126 127 public short getCol2() 128 { 129 return col2; 130 } 131 132 public void setCol2( short col2 ) 133 { 134 checkRange(col2, 0, 255, "col2"); 135 this.col2 = col2; 136 } 137 138 public int getRow1() 139 { 140 return row1; 141 } 142 143 public void setRow1( int row1 ) 144 { 145 checkRange(row1, 0, 256 * 256, "row1"); 146 this.row1 = row1; 147 } 148 149 public int getRow2() 150 { 151 return row2; 152 } 153 154 public void setRow2( int row2 ) 155 { 156 checkRange(row2, 0, 256 * 256, "row2"); 157 this.row2 = row2; 158 } 159 160 173 public void setAnchor( short col1, int row1, int x1, int y1, short col2, int row2, int x2, int y2 ) 174 { 175 checkRange(dx1, 0, 1023, "dx1"); 176 checkRange(dx2, 0, 1023, "dx2"); 177 checkRange(dy1, 0, 255, "dy1"); 178 checkRange(dy2, 0, 255, "dy2"); 179 checkRange(col1, 0, 255, "col1"); 180 checkRange(col2, 0, 255, "col2"); 181 checkRange(row1, 0, 255 * 256, "row1"); 182 checkRange(row2, 0, 255 * 256, "row2"); 183 184 this.col1 = col1; 185 this.row1 = row1; 186 this.dx1 = x1; 187 this.dy1 = y1; 188 this.col2 = col2; 189 this.row2 = row2; 190 this.dx2 = x2; 191 this.dy2 = y2; 192 } 193 194 197 public boolean isHorizontallyFlipped() 198 { 199 if (col1 == col2) 200 return dx1 > dx2; 201 else 202 return col1 > col2; 203 } 204 205 208 public boolean isVerticallyFlipped() 209 { 210 if (row1 == row2) 211 return dy1 > dy2; 212 else 213 return row1 > row2; 214 } 215 216 private void checkRange( int value, int minRange, int maxRange, String varName ) 217 { 218 if (value < minRange || value > maxRange) 219 throw new IllegalArgumentException (varName + " must be between " + minRange + " and " + maxRange); 220 } 221 222 223 } 224 | Popular Tags |