1 /* PageAttributes.java -- 2 Copyright (C) 2002, 2005 Free Software Foundation, Inc. 3 4 This file is part of GNU Classpath. 5 6 GNU Classpath is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2, or (at your option) 9 any later version. 10 11 GNU Classpath is distributed in the hope that it will be useful, but 12 WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with GNU Classpath; see the file COPYING. If not, write to the 18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 19 02110-1301 USA. 20 21 Linking this library statically or dynamically with other modules is 22 making a combined work based on this library. Thus, the terms and 23 conditions of the GNU General Public License cover the whole 24 combination. 25 26 As a special exception, the copyright holders of this library give you 27 permission to link this library with independent modules to produce an 28 executable, regardless of the license terms of these independent 29 modules, and to copy and distribute the resulting executable under 30 terms of your choice, provided that you also meet, for each linked 31 independent module, the terms and conditions of the license of that 32 module. An independent module is a module which is not derived from 33 or based on this library. If you modify this library, you may extend 34 this exception to your version of the library, but you are not 35 obligated to do so. If you do not wish to do so, delete this 36 exception statement from your version. */ 37 38 39 package java.awt; 40 41 import java.util.Locale; 42 43 /** 44 * Missing Documentation 45 * 46 * @author Eric Blake (ebb9@email.byu.edu) 47 * @since 1.3 48 * @status updated to 1.4, but missing documentation 49 */ 50 public final class PageAttributes implements Cloneable 51 { 52 public static final class ColorType extends AttributeValue 53 { 54 private static final String[] NAMES = { "color", "monochrome" }; 55 public static final ColorType COLOR = new ColorType(0); 56 public static final ColorType MONOCHROME = new ColorType(1); ColorType(int value)57 private ColorType(int value) 58 { 59 super(value, NAMES); 60 } 61 } // class ColorType 62 public static final class MediaType extends AttributeValue 63 { 64 private static final String[] NAMES 65 = { "iso-4a0", "iso-2a0", "iso-a0", "iso-a1", "iso-a2", "iso-a3", 66 "iso-a4", "iso-a5", "iso-a6", "iso-a7", "iso-a8", "iso-a9", 67 "iso-a10", "iso-b0", "iso-b1", "iso-b2", "iso-b3", "iso-b4", 68 "iso-b5", "iso-b6", "iso-b7", "iso-b8", "iso-b9", "iso-b10", 69 "jis-b0", "jis-b1", "jis-b2", "jis-b3", "jis-b4", "jis-b5", 70 "jis-b6", "jis-b7", "jis-b8", "jis-b9", "jis-b10", "iso-c0", 71 "iso-c1", "iso-c2", "iso-c3", "iso-c4", "iso-c5", "iso-c6", 72 "iso-c7", "iso-c8", "iso-c9", "iso-c10", "iso-designated-long", 73 "executive", "folio", "invoice", "ledger", "na-letter", "na-legal", 74 "quarto", "a", "b", "c", "d", "e", "na-10x15-envelope", 75 "na-10x14-envelope", "na-10x13-envelope", "na-9x12-envelope", 76 "na-9x11-envelope", "na-7x9-envelope", "na-6x9-envelope", 77 "na-number-9-envelope", "na-number-10-envelope", 78 "na-number-11-envelope", "na-number-12-envelope", 79 "na-number-14-envelope", "invite-envelope", "italy-envelope", 80 "monarch-envelope", "personal-envelope" }; 81 public static final MediaType ISO_4A0 = new MediaType(0); 82 public static final MediaType ISO_2A0 = new MediaType(1); 83 public static final MediaType ISO_A0 = new MediaType(2); 84 public static final MediaType ISO_A1 = new MediaType(3); 85 public static final MediaType ISO_A2 = new MediaType(4); 86 public static final MediaType ISO_A3 = new MediaType(5); 87 public static final MediaType ISO_A4 = new MediaType(6); 88 public static final MediaType ISO_A5 = new MediaType(7); 89 public static final MediaType ISO_A6 = new MediaType(8); 90 public static final MediaType ISO_A7 = new MediaType(9); 91 public static final MediaType ISO_A8 = new MediaType(10); 92 public static final MediaType ISO_A9 = new MediaType(11); 93 public static final MediaType ISO_A10 = new MediaType(12); 94 public static final MediaType ISO_B0 = new MediaType(13); 95 public static final MediaType ISO_B1 = new MediaType(14); 96 public static final MediaType ISO_B2 = new MediaType(15); 97 public static final MediaType ISO_B3 = new MediaType(16); 98 public static final MediaType ISO_B4 = new MediaType(17); 99 public static final MediaType ISO_B5 = new MediaType(18); 100 public static final MediaType ISO_B6 = new MediaType(19); 101 public static final MediaType ISO_B7 = new MediaType(20); 102 public static final MediaType ISO_B8 = new MediaType(21); 103 public static final MediaType ISO_B9 = new MediaType(22); 104 public static final MediaType ISO_B10 = new MediaType(23); 105 public static final MediaType JIS_B0 = new MediaType(24); 106 public static final MediaType JIS_B1 = new MediaType(25); 107 public static final MediaType JIS_B2 = new MediaType(26); 108 public static final MediaType JIS_B3 = new MediaType(27); 109 public static final MediaType JIS_B4 = new MediaType(28); 110 public static final MediaType JIS_B5 = new MediaType(29); 111 public static final MediaType JIS_B6 = new MediaType(30); 112 public static final MediaType JIS_B7 = new MediaType(31); 113 public static final MediaType JIS_B8 = new MediaType(32); 114 public static final MediaType JIS_B9 = new MediaType(33); 115 public static final MediaType JIS_B10 = new MediaType(34); 116 public static final MediaType ISO_C0 = new MediaType(35); 117 public static final MediaType ISO_C1 = new MediaType(36); 118 public static final MediaType ISO_C2 = new MediaType(37); 119 public static final MediaType ISO_C3 = new MediaType(38); 120 public static final MediaType ISO_C4 = new MediaType(39); 121 public static final MediaType ISO_C5 = new MediaType(40); 122 public static final MediaType ISO_C6 = new MediaType(41); 123 public static final MediaType ISO_C7 = new MediaType(42); 124 public static final MediaType ISO_C8 = new MediaType(43); 125 public static final MediaType ISO_C9 = new MediaType(44); 126 public static final MediaType ISO_C10 = new MediaType(45); 127 public static final MediaType ISO_DESIGNATED_LONG = new MediaType(46); 128 public static final MediaType EXECUTIVE = new MediaType(47); 129 public static final MediaType FOLIO = new MediaType(48); 130 public static final MediaType INVOICE = new MediaType(49); 131 public static final MediaType LEDGER = new MediaType(50); 132 public static final MediaType NA_LETTER = new MediaType(51); 133 public static final MediaType NA_LEGAL = new MediaType(52); 134 public static final MediaType QUARTO = new MediaType(53); 135 public static final MediaType A = new MediaType(54); 136 public static final MediaType B = new MediaType(55); 137 public static final MediaType C = new MediaType(56); 138 public static final MediaType D = new MediaType(57); 139 public static final MediaType E = new MediaType(58); 140 public static final MediaType NA_10X15_ENVELOPE = new MediaType(59); 141 public static final MediaType NA_10X14_ENVELOPE = new MediaType(60); 142 public static final MediaType NA_10X13_ENVELOPE = new MediaType(61); 143 public static final MediaType NA_9X12_ENVELOPE = new MediaType(62); 144 public static final MediaType NA_9X11_ENVELOPE = new MediaType(63); 145 public static final MediaType NA_7X9_ENVELOPE = new MediaType(64); 146 public static final MediaType NA_6X9_ENVELOPE = new MediaType(65); 147 public static final MediaType NA_NUMBER_9_ENVELOPE = new MediaType(66); 148 public static final MediaType NA_NUMBER_10_ENVELOPE = new MediaType(67); 149 public static final MediaType NA_NUMBER_11_ENVELOPE = new MediaType(68); 150 public static final MediaType NA_NUMBER_12_ENVELOPE = new MediaType(69); 151 public static final MediaType NA_NUMBER_14_ENVELOPE = new MediaType(70); 152 public static final MediaType INVITE_ENVELOPE = new MediaType(71); 153 public static final MediaType ITALY_ENVELOPE = new MediaType(72); 154 public static final MediaType MONARCH_ENVELOPE = new MediaType(73); 155 public static final MediaType PERSONAL_ENVELOPE = new MediaType(74); 156 public static final MediaType A0 = ISO_A0; 157 public static final MediaType A1 = ISO_A1; 158 public static final MediaType A2 = ISO_A2; 159 public static final MediaType A3 = ISO_A3; 160 public static final MediaType A4 = ISO_A4; 161 public static final MediaType A5 = ISO_A5; 162 public static final MediaType A6 = ISO_A6; 163 public static final MediaType A7 = ISO_A7; 164 public static final MediaType A8 = ISO_A8; 165 public static final MediaType A9 = ISO_A9; 166 public static final MediaType A10 = ISO_A10; 167 public static final MediaType B0 = ISO_B0; 168 public static final MediaType B1 = ISO_B1; 169 public static final MediaType B2 = ISO_B2; 170 public static final MediaType B3 = ISO_B3; 171 public static final MediaType B4 = ISO_B4; 172 public static final MediaType ISO_B4_ENVELOPE = ISO_B4; 173 public static final MediaType B5 = ISO_B5; 174 public static final MediaType ISO_B5_ENVELOPE = ISO_B4; 175 public static final MediaType B6 = ISO_B6; 176 public static final MediaType B7 = ISO_B7; 177 public static final MediaType B8 = ISO_B8; 178 public static final MediaType B9 = ISO_B9; 179 public static final MediaType B10 = ISO_B10; 180 public static final MediaType C0 = ISO_B0; 181 public static final MediaType ISO_C0_ENVELOPE = ISO_C0; 182 public static final MediaType C1 = ISO_C1; 183 public static final MediaType ISO_C1_ENVELOPE = ISO_C1; 184 public static final MediaType C2 = ISO_C2; 185 public static final MediaType ISO_C2_ENVELOPE = ISO_C2; 186 public static final MediaType C3 = ISO_C3; 187 public static final MediaType ISO_C3_ENVELOPE = ISO_C3; 188 public static final MediaType C4 = ISO_C4; 189 public static final MediaType ISO_C4_ENVELOPE = ISO_C4; 190 public static final MediaType C5 = ISO_C5; 191 public static final MediaType ISO_C5_ENVELOPE = ISO_C5; 192 public static final MediaType C6 = ISO_C6; 193 public static final MediaType ISO_C6_ENVELOPE = ISO_C6; 194 public static final MediaType C7 = ISO_C7; 195 public static final MediaType ISO_C7_ENVELOPE = ISO_C7; 196 public static final MediaType C8 = ISO_C8; 197 public static final MediaType ISO_C8_ENVELOPE = ISO_C8; 198 public static final MediaType C9 = ISO_C9; 199 public static final MediaType ISO_C9_ENVELOPE = ISO_C9; 200 public static final MediaType C10 = ISO_C10; 201 public static final MediaType ISO_C10_ENVELOPE = ISO_C10; 202 public static final MediaType ISO_DESIGNATED_LONG_ENVELOPE 203 = ISO_DESIGNATED_LONG; 204 public static final MediaType STATEMENT = INVOICE; 205 public static final MediaType TABLOID = LEDGER; 206 public static final MediaType LETTER = NA_LETTER; 207 public static final MediaType NOTE = NA_LETTER; 208 public static final MediaType LEGAL = NA_LEGAL; 209 public static final MediaType ENV_10X15 = NA_10X15_ENVELOPE; 210 public static final MediaType ENV_10X14 = NA_10X14_ENVELOPE; 211 public static final MediaType ENV_10X13 = NA_10X13_ENVELOPE; 212 public static final MediaType ENV_9X12 = NA_9X12_ENVELOPE; 213 public static final MediaType ENV_9X11 = NA_9X11_ENVELOPE; 214 public static final MediaType ENV_7X9 = NA_7X9_ENVELOPE; 215 public static final MediaType ENV_6X9 = NA_6X9_ENVELOPE; 216 public static final MediaType ENV_9 = NA_NUMBER_9_ENVELOPE; 217 public static final MediaType ENV_10 = NA_NUMBER_10_ENVELOPE; 218 public static final MediaType ENV_11 = NA_NUMBER_11_ENVELOPE; 219 public static final MediaType ENV_12 = NA_NUMBER_12_ENVELOPE; 220 public static final MediaType ENV_14 = NA_NUMBER_14_ENVELOPE; 221 public static final MediaType ENV_INVITE = INVITE_ENVELOPE; 222 public static final MediaType ENV_ITALY = ITALY_ENVELOPE; 223 public static final MediaType ENV_MONARCH = MONARCH_ENVELOPE; 224 public static final MediaType ENV_PERSONAL = PERSONAL_ENVELOPE; 225 public static final MediaType INVITE = INVITE_ENVELOPE; 226 public static final MediaType ITALY = ITALY_ENVELOPE; 227 public static final MediaType MONARCH = MONARCH_ENVELOPE; 228 public static final MediaType PERSONAL = PERSONAL_ENVELOPE; MediaType(int value)229 private MediaType(int value) 230 { 231 super(value, NAMES); 232 } 233 } // class MediaType 234 public static final class OrientationRequestedType extends AttributeValue 235 { 236 private static final String[] NAMES = { "portrait", "landscape" }; 237 public static final OrientationRequestedType PORTRAIT 238 = new OrientationRequestedType(0); 239 public static final OrientationRequestedType LANDSCAPE 240 = new OrientationRequestedType(1); OrientationRequestedType(int value)241 private OrientationRequestedType(int value) 242 { 243 super(value, NAMES); 244 } 245 } // class OrientationRequestedType 246 public static final class OriginType extends AttributeValue 247 { 248 private static final String[] NAMES = { "physical", "printable" }; 249 public static final OriginType PHYSICAL = new OriginType(0); 250 public static final OriginType PRINTABLE = new OriginType(1); OriginType(int value)251 private OriginType(int value) 252 { 253 super(value, NAMES); 254 } 255 } // class OriginType 256 public static final class PrintQualityType extends AttributeValue 257 { 258 private static final String[] NAMES = { "high", "normal", "draft" }; 259 public static final PrintQualityType HIGH = new PrintQualityType(0); 260 public static final PrintQualityType NORMAL = new PrintQualityType(1); 261 public static final PrintQualityType DRAFT = new PrintQualityType(2); PrintQualityType(int value)262 private PrintQualityType(int value) 263 { 264 super(value, NAMES); 265 } 266 } // class PrintQualityType 267 268 269 private ColorType color; 270 private MediaType media; 271 private OrientationRequestedType orientation; 272 private OriginType origin; 273 private PrintQualityType quality; 274 private int resolutionX; 275 private int resolutionY; 276 private int resolutionScale; PageAttributes()277 public PageAttributes() 278 { 279 color = ColorType.MONOCHROME; 280 setMediaToDefault(); 281 orientation = OrientationRequestedType.PORTRAIT; 282 origin = OriginType.PHYSICAL; 283 quality = PrintQualityType.NORMAL; 284 setPrinterResolutionToDefault(); 285 } 286 PageAttributes(PageAttributes attr)287 public PageAttributes(PageAttributes attr) 288 { 289 set(attr); 290 } 291 PageAttributes(ColorType color, MediaType media, OrientationRequestedType orientation, OriginType origin, PrintQualityType quality, int[] resolution)292 public PageAttributes(ColorType color, MediaType media, 293 OrientationRequestedType orientation, 294 OriginType origin, PrintQualityType quality, 295 int[] resolution) 296 { 297 if (color == null || media == null || orientation == null 298 || origin == null || quality == null) 299 throw new IllegalArgumentException(); 300 setPrinterResolution(resolution); 301 this.color = color; 302 this.media = media; 303 this.orientation = orientation; 304 this.origin = origin; 305 this.quality = quality; 306 } 307 clone()308 public Object clone() 309 { 310 return new PageAttributes(this); 311 } 312 set(PageAttributes attr)313 public void set(PageAttributes attr) 314 { 315 color = attr.color; 316 media = attr.media; 317 orientation = attr.orientation; 318 origin = attr.origin; 319 quality = attr.quality; 320 resolutionX = attr.resolutionX; 321 resolutionY = attr.resolutionY; 322 resolutionScale = attr.resolutionScale; 323 } 324 getColor()325 public ColorType getColor() 326 { 327 return color; 328 } 329 setColor(ColorType color)330 public void setColor(ColorType color) 331 { 332 if (color == null) 333 throw new IllegalArgumentException(); 334 this.color = color; 335 } 336 getMedia()337 public MediaType getMedia() 338 { 339 return media; 340 } 341 setMedia(MediaType media)342 public void setMedia(MediaType media) 343 { 344 if (media == null) 345 throw new IllegalArgumentException(); 346 this.media = media; 347 } 348 setMediaToDefault()349 public void setMediaToDefault() 350 { 351 String country = Locale.getDefault().getCountry(); 352 media = ("US".equals(country) || "CA".equals(country)) ? MediaType.LETTER 353 : MediaType.A4; 354 } 355 getOrientationRequested()356 public OrientationRequestedType getOrientationRequested() 357 { 358 return orientation; 359 } 360 setOrientationRequested(OrientationRequestedType orientation)361 public void setOrientationRequested(OrientationRequestedType orientation) 362 { 363 if (orientation == null) 364 throw new IllegalArgumentException(); 365 this.orientation = orientation; 366 } 367 setOrientationRequested(int orientation)368 public void setOrientationRequested(int orientation) 369 { 370 if (orientation == 3) 371 this.orientation = OrientationRequestedType.PORTRAIT; 372 else if (orientation == 4) 373 this.orientation = OrientationRequestedType.LANDSCAPE; 374 else 375 throw new IllegalArgumentException(); 376 } 377 setOrientationRequestedToDefault()378 public void setOrientationRequestedToDefault() 379 { 380 orientation = OrientationRequestedType.PORTRAIT; 381 } 382 getOrigin()383 public OriginType getOrigin() 384 { 385 return origin; 386 } 387 setOrigin(OriginType origin)388 public void setOrigin(OriginType origin) 389 { 390 if (origin == null) 391 throw new IllegalArgumentException(); 392 this.origin = origin; 393 } 394 getPrintQuality()395 public PrintQualityType getPrintQuality() 396 { 397 return quality; 398 } 399 setPrintQuality(PrintQualityType quality)400 public void setPrintQuality(PrintQualityType quality) 401 { 402 if (quality == null) 403 throw new IllegalArgumentException(); 404 this.quality = quality; 405 } 406 setPrintQuality(int quality)407 public void setPrintQuality(int quality) 408 { 409 if (quality == 3) 410 this.quality = PrintQualityType.DRAFT; 411 else if (quality == 4) 412 this.quality = PrintQualityType.NORMAL; 413 else if (quality == 5) 414 this.quality = PrintQualityType.HIGH; 415 else 416 throw new IllegalArgumentException(); 417 } 418 setPrintQualityToDefault()419 public void setPrintQualityToDefault() 420 { 421 quality = PrintQualityType.NORMAL; 422 } 423 getPrinterResolution()424 public int[] getPrinterResolution() 425 { 426 return new int[] { resolutionX, resolutionY, resolutionScale }; 427 } 428 setPrinterResolution(int[] resolution)429 public void setPrinterResolution(int[] resolution) 430 { 431 if (resolution == null || resolution.length != 3 || resolution[0] <= 0 432 || resolution[1] <= 0 || resolution[2] < 3 || resolution[2] > 4) 433 throw new IllegalArgumentException(); 434 resolutionX = resolution[0]; 435 resolutionY = resolution[1]; 436 resolutionScale = resolution[2]; 437 } 438 setPrinterResolution(int resolution)439 public void setPrinterResolution(int resolution) 440 { 441 if (resolution <= 0) 442 throw new IllegalArgumentException(); 443 resolutionX = resolution; 444 resolutionY = resolution; 445 resolutionScale = 3; 446 } 447 setPrinterResolutionToDefault()448 public void setPrinterResolutionToDefault() 449 { 450 resolutionX = 72; 451 resolutionY = 72; 452 resolutionScale = 3; 453 } 454 equals(Object o)455 public boolean equals(Object o) 456 { 457 if (this == o) 458 return true; 459 if (! (o instanceof PageAttributes)) 460 return false; 461 PageAttributes pa = (PageAttributes) o; 462 return color == pa.color && media == pa.media 463 && orientation == pa.orientation && origin == pa.origin 464 && quality == pa.quality && resolutionX == pa.resolutionX 465 && resolutionY == pa.resolutionY 466 && resolutionScale == pa.resolutionScale; 467 } hashCode()468 public int hashCode() 469 { 470 return (color.value << 31) ^ (media.value << 24) 471 ^ (orientation.value << 23) ^ (origin.value << 22) 472 ^ (quality.value << 20) ^ (resolutionScale << 19) 473 ^ (resolutionY << 10) ^ resolutionX; 474 } toString()475 public String toString() 476 { 477 return "color=" + color + ",media=" + media + ",orientation-requested=" 478 + orientation + ",origin=" + origin + ",print-quality=" + quality 479 + ",printer-resolution=[" + resolutionX + ',' + resolutionY + ',' 480 + resolutionScale + ']'; 481 } 482 } // class PageAttributes 483