1 32 33 package it.businesslogic.ireport.util; 34 35 import java.awt.Point ; 36 37 import java.util.HashMap ; 38 import java.util.Iterator ; 39 import java.util.Map ; 40 41 42 public class PageSize 43 { 44 private PageSize() 45 { 46 47 } 49 50 54 public static HashMap pageFormats; 55 56 57 public static final Point LETTER = new Point (612, 792); 58 59 60 public static final Point NOTE = new Point (540, 720); 61 62 63 public static final Point LEGAL = new Point (612, 1008); 64 65 66 public static final Point A0 = new Point (2380, 3368); 67 68 69 public static final Point A1 = new Point (1684, 2380); 70 71 72 public static final Point A2 = new Point (1190, 1684); 73 74 75 public static final Point A3 = new Point (842, 1190); 76 77 78 public static final Point A4 = new Point (595, 842); 79 80 81 public static final Point A5 = new Point (421, 595); 82 83 84 public static final Point A6 = new Point (297, 421); 85 86 87 public static final Point A7 = new Point (210, 297); 88 89 90 public static final Point A8 = new Point (148, 210); 91 92 93 public static final Point A9 = new Point (105, 148); 94 95 96 public static final Point A10 = new Point (74, 105); 97 98 99 public static final Point B0 = new Point (2836, 4008); 100 101 102 public static final Point B1 = new Point (2004, 2836); 103 104 105 public static final Point B2 = new Point (1418, 2004); 106 107 108 public static final Point B3 = new Point (1002, 1418); 109 110 111 public static final Point B4 = new Point (709, 1002); 112 113 114 public static final Point B5 = new Point (501, 709); 115 116 117 public static final Point ARCH_E = new Point (2592, 3456); 118 119 120 public static final Point ARCH_D = new Point (1728, 2592); 121 122 123 public static final Point ARCH_C = new Point (1296, 1728); 124 125 126 public static final Point ARCH_B = new Point (864, 1296); 127 128 129 public static final Point ARCH_A = new Point (648, 864); 130 131 132 public static final Point FLSA = new Point (612, 936); 133 134 135 public static final Point FLSE = new Point (612, 936); 136 137 138 public static final Point HALFLETTER = new Point (396, 612); 139 140 141 public static final Point _11X17 = new Point (792, 1224); 142 143 144 public static final Point LEDGER = new Point (1224, 792); 145 146 149 static 150 { 151 152 HashMap pageFormats = new HashMap (); 153 154 pageFormats.put("LETTER", LETTER); 155 pageFormats.put("NOTE", NOTE); 156 pageFormats.put("LEGAL", LEGAL); 157 pageFormats.put("A0", A0); 158 pageFormats.put("A1", A1); 159 pageFormats.put("A2", A2); 160 pageFormats.put("A3", A3); 161 pageFormats.put("A4", A4); 162 pageFormats.put("A5", A5); 163 pageFormats.put("A6", A6); 164 pageFormats.put("A7", A7); 165 pageFormats.put("A8", A8); 166 pageFormats.put("A9", A9); 167 pageFormats.put("A10", A10); 168 169 pageFormats.put("B0", B0); 170 pageFormats.put("B1", B1); 171 pageFormats.put("B2", B2); 172 pageFormats.put("B3", B3); 173 pageFormats.put("B4", B4); 174 pageFormats.put("B5", B5); 175 176 pageFormats.put("ARCHE_E", ARCH_E); 177 pageFormats.put("ARCHE_D", ARCH_D); 178 pageFormats.put("ARCHE_C", ARCH_C); 179 pageFormats.put("ARCHE_B", ARCH_B); 180 pageFormats.put("ARCHE_A", ARCH_A); 181 182 pageFormats.put("FLSA", FLSA); 183 pageFormats.put("FLSE", FLSE); 184 185 pageFormats.put("HALFLETTER", HALFLETTER); 186 pageFormats.put("11x17", _11X17); 187 pageFormats.put("LEDGER", LEDGER); 188 189 PageSize.pageFormats = pageFormats; 190 191 } 192 193 199 public static Point getFormatSize(String format) 200 { 201 202 Point point = (Point ) pageFormats.get(format); 203 204 if (point == null) 205 { 206 point = A4; } 208 209 return point; 210 } 211 212 220 public static String deductPageFormat(int pageWidth, int pageHeight) 221 { 222 223 int width = pageWidth < pageHeight 226 ? pageWidth 227 : pageHeight; int height = pageWidth > pageHeight 229 ? pageWidth 230 : pageHeight; String format = "Custom"; 232 233 for (Iterator i = pageFormats.entrySet().iterator(); i.hasNext();) 237 { 238 239 Map.Entry entry = (Map.Entry ) i.next(); 240 241 if (((Point ) entry.getValue()).x == width) 242 { 243 244 if (((Point ) entry.getValue()).y == height) 245 { 246 247 format = (String ) entry.getKey(); 249 } 250 } 251 } 252 253 return format; 254 } 255 256 public static String findOneDown(int pageWidth, int pageHeight) 257 { 258 261 int height = pageWidth < pageHeight 262 ? pageWidth 263 : pageHeight; 268 int width = (pageWidth > pageHeight 269 ? pageWidth 270 : pageHeight) / 2 ; 271 String format = "Custom"; 272 273 for (Iterator i = pageFormats.entrySet().iterator(); i.hasNext();) 277 { 278 279 Map.Entry entry = (Map.Entry ) i.next(); 280 281 if (((Point ) entry.getValue()).x == width) 282 { 283 284 if (((Point ) entry.getValue()).y == height) 285 { 286 287 format = (String ) entry.getKey(); 289 } 290 } 291 } 292 return format; 293 294 295 296 297 } 298 299 300 } 301 | Popular Tags |