1 7 8 package java.awt; 9 10 import java.util.Locale ; 11 12 43 public final class PageAttributes implements Cloneable { 44 47 public static final class ColorType extends AttributeValue { 48 private static final int I_COLOR = 0; 49 private static final int I_MONOCHROME = 1; 50 51 private static final String NAMES[] = { 52 "color", "monochrome" 53 }; 54 55 58 public static final ColorType COLOR = new ColorType(I_COLOR); 59 62 public static final ColorType MONOCHROME = new ColorType(I_MONOCHROME); 63 64 private ColorType(int type) { 65 super(type, NAMES); 66 } 67 } 68 69 73 public static final class MediaType extends AttributeValue { 74 private static final int I_ISO_4A0 = 0; 75 private static final int I_ISO_2A0 = 1; 76 private static final int I_ISO_A0 = 2; 77 private static final int I_ISO_A1 = 3; 78 private static final int I_ISO_A2 = 4; 79 private static final int I_ISO_A3 = 5; 80 private static final int I_ISO_A4 = 6; 81 private static final int I_ISO_A5 = 7; 82 private static final int I_ISO_A6 = 8; 83 private static final int I_ISO_A7 = 9; 84 private static final int I_ISO_A8 = 10; 85 private static final int I_ISO_A9 = 11; 86 private static final int I_ISO_A10 = 12; 87 private static final int I_ISO_B0 = 13; 88 private static final int I_ISO_B1 = 14; 89 private static final int I_ISO_B2 = 15; 90 private static final int I_ISO_B3 = 16; 91 private static final int I_ISO_B4 = 17; 92 private static final int I_ISO_B5 = 18; 93 private static final int I_ISO_B6 = 19; 94 private static final int I_ISO_B7 = 20; 95 private static final int I_ISO_B8 = 21; 96 private static final int I_ISO_B9 = 22; 97 private static final int I_ISO_B10 = 23; 98 private static final int I_JIS_B0 = 24; 99 private static final int I_JIS_B1 = 25; 100 private static final int I_JIS_B2 = 26; 101 private static final int I_JIS_B3 = 27; 102 private static final int I_JIS_B4 = 28; 103 private static final int I_JIS_B5 = 29; 104 private static final int I_JIS_B6 = 30; 105 private static final int I_JIS_B7 = 31; 106 private static final int I_JIS_B8 = 32; 107 private static final int I_JIS_B9 = 33; 108 private static final int I_JIS_B10 = 34; 109 private static final int I_ISO_C0 = 35; 110 private static final int I_ISO_C1 = 36; 111 private static final int I_ISO_C2 = 37; 112 private static final int I_ISO_C3 = 38; 113 private static final int I_ISO_C4 = 39; 114 private static final int I_ISO_C5 = 40; 115 private static final int I_ISO_C6 = 41; 116 private static final int I_ISO_C7 = 42; 117 private static final int I_ISO_C8 = 43; 118 private static final int I_ISO_C9 = 44; 119 private static final int I_ISO_C10 = 45; 120 private static final int I_ISO_DESIGNATED_LONG = 46; 121 private static final int I_EXECUTIVE = 47; 122 private static final int I_FOLIO = 48; 123 private static final int I_INVOICE = 49; 124 private static final int I_LEDGER = 50; 125 private static final int I_NA_LETTER = 51; 126 private static final int I_NA_LEGAL = 52; 127 private static final int I_QUARTO = 53; 128 private static final int I_A = 54; 129 private static final int I_B = 55; 130 private static final int I_C = 56; 131 private static final int I_D = 57; 132 private static final int I_E = 58; 133 private static final int I_NA_10X15_ENVELOPE = 59; 134 private static final int I_NA_10X14_ENVELOPE = 60; 135 private static final int I_NA_10X13_ENVELOPE = 61; 136 private static final int I_NA_9X12_ENVELOPE = 62; 137 private static final int I_NA_9X11_ENVELOPE = 63; 138 private static final int I_NA_7X9_ENVELOPE = 64; 139 private static final int I_NA_6X9_ENVELOPE = 65; 140 private static final int I_NA_NUMBER_9_ENVELOPE = 66; 141 private static final int I_NA_NUMBER_10_ENVELOPE = 67; 142 private static final int I_NA_NUMBER_11_ENVELOPE = 68; 143 private static final int I_NA_NUMBER_12_ENVELOPE = 69; 144 private static final int I_NA_NUMBER_14_ENVELOPE = 70; 145 private static final int I_INVITE_ENVELOPE = 71; 146 private static final int I_ITALY_ENVELOPE = 72; 147 private static final int I_MONARCH_ENVELOPE = 73; 148 private static final int I_PERSONAL_ENVELOPE = 74; 149 150 private static final String NAMES[] = { 151 "iso-4a0", "iso-2a0", "iso-a0", "iso-a1", "iso-a2", "iso-a3", 152 "iso-a4", "iso-a5", "iso-a6", "iso-a7", "iso-a8", "iso-a9", 153 "iso-a10", "iso-b0", "iso-b1", "iso-b2", "iso-b3", "iso-b4", 154 "iso-b5", "iso-b6", "iso-b7", "iso-b8", "iso-b9", "iso-b10", 155 "jis-b0", "jis-b1", "jis-b2", "jis-b3", "jis-b4", "jis-b5", 156 "jis-b6", "jis-b7", "jis-b8", "jis-b9", "jis-b10", "iso-c0", 157 "iso-c1", "iso-c2", "iso-c3", "iso-c4", "iso-c5", "iso-c6", 158 "iso-c7", "iso-c8", "iso-c9", "iso-c10", "iso-designated-long", 159 "executive", "folio", "invoice", "ledger", "na-letter", "na-legal", 160 "quarto", "a", "b", "c", "d", "e", "na-10x15-envelope", 161 "na-10x14-envelope", "na-10x13-envelope", "na-9x12-envelope", 162 "na-9x11-envelope", "na-7x9-envelope", "na-6x9-envelope", 163 "na-number-9-envelope", "na-number-10-envelope", 164 "na-number-11-envelope", "na-number-12-envelope", 165 "na-number-14-envelope", "invite-envelope", "italy-envelope", 166 "monarch-envelope", "personal-envelope" 167 }; 168 169 172 public static final MediaType ISO_4A0 = new MediaType(I_ISO_4A0); 173 176 public static final MediaType ISO_2A0 = new MediaType(I_ISO_2A0); 177 180 public static final MediaType ISO_A0 = new MediaType(I_ISO_A0); 181 184 public static final MediaType ISO_A1 = new MediaType(I_ISO_A1); 185 188 public static final MediaType ISO_A2 = new MediaType(I_ISO_A2); 189 192 public static final MediaType ISO_A3 = new MediaType(I_ISO_A3); 193 196 public static final MediaType ISO_A4 = new MediaType(I_ISO_A4); 197 200 public static final MediaType ISO_A5 = new MediaType(I_ISO_A5); 201 204 public static final MediaType ISO_A6 = new MediaType(I_ISO_A6); 205 208 public static final MediaType ISO_A7 = new MediaType(I_ISO_A7); 209 212 public static final MediaType ISO_A8 = new MediaType(I_ISO_A8); 213 216 public static final MediaType ISO_A9 = new MediaType(I_ISO_A9); 217 220 public static final MediaType ISO_A10 = new MediaType(I_ISO_A10); 221 224 public static final MediaType ISO_B0 = new MediaType(I_ISO_B0); 225 228 public static final MediaType ISO_B1 = new MediaType(I_ISO_B1); 229 232 public static final MediaType ISO_B2 = new MediaType(I_ISO_B2); 233 236 public static final MediaType ISO_B3 = new MediaType(I_ISO_B3); 237 240 public static final MediaType ISO_B4 = new MediaType(I_ISO_B4); 241 244 public static final MediaType ISO_B5 = new MediaType(I_ISO_B5); 245 248 public static final MediaType ISO_B6 = new MediaType(I_ISO_B6); 249 252 public static final MediaType ISO_B7 = new MediaType(I_ISO_B7); 253 256 public static final MediaType ISO_B8 = new MediaType(I_ISO_B8); 257 260 public static final MediaType ISO_B9 = new MediaType(I_ISO_B9); 261 264 public static final MediaType ISO_B10 = new MediaType(I_ISO_B10); 265 268 public static final MediaType JIS_B0 = new MediaType(I_JIS_B0); 269 272 public static final MediaType JIS_B1 = new MediaType(I_JIS_B1); 273 276 public static final MediaType JIS_B2 = new MediaType(I_JIS_B2); 277 280 public static final MediaType JIS_B3 = new MediaType(I_JIS_B3); 281 284 public static final MediaType JIS_B4 = new MediaType(I_JIS_B4); 285 288 public static final MediaType JIS_B5 = new MediaType(I_JIS_B5); 289 292 public static final MediaType JIS_B6 = new MediaType(I_JIS_B6); 293 296 public static final MediaType JIS_B7 = new MediaType(I_JIS_B7); 297 300 public static final MediaType JIS_B8 = new MediaType(I_JIS_B8); 301 304 public static final MediaType JIS_B9 = new MediaType(I_JIS_B9); 305 308 public static final MediaType JIS_B10 = new MediaType(I_JIS_B10); 309 312 public static final MediaType ISO_C0 = new MediaType(I_ISO_C0); 313 316 public static final MediaType ISO_C1 = new MediaType(I_ISO_C1); 317 320 public static final MediaType ISO_C2 = new MediaType(I_ISO_C2); 321 324 public static final MediaType ISO_C3 = new MediaType(I_ISO_C3); 325 328 public static final MediaType ISO_C4 = new MediaType(I_ISO_C4); 329 332 public static final MediaType ISO_C5 = new MediaType(I_ISO_C5); 333 336 public static final MediaType ISO_C6 = new MediaType(I_ISO_C6); 337 340 public static final MediaType ISO_C7 = new MediaType(I_ISO_C7); 341 344 public static final MediaType ISO_C8 = new MediaType(I_ISO_C8); 345 348 public static final MediaType ISO_C9 = new MediaType(I_ISO_C9); 349 352 public static final MediaType ISO_C10 = new MediaType(I_ISO_C10); 353 356 public static final MediaType ISO_DESIGNATED_LONG = 357 new MediaType(I_ISO_DESIGNATED_LONG); 358 361 public static final MediaType EXECUTIVE = new MediaType(I_EXECUTIVE); 362 365 public static final MediaType FOLIO = new MediaType(I_FOLIO); 366 369 public static final MediaType INVOICE = new MediaType(I_INVOICE); 370 373 public static final MediaType LEDGER = new MediaType(I_LEDGER); 374 377 public static final MediaType NA_LETTER = new MediaType(I_NA_LETTER); 378 381 public static final MediaType NA_LEGAL = new MediaType(I_NA_LEGAL); 382 385 public static final MediaType QUARTO = new MediaType(I_QUARTO); 386 389 public static final MediaType A = new MediaType(I_A); 390 393 public static final MediaType B = new MediaType(I_B); 394 397 public static final MediaType C = new MediaType(I_C); 398 401 public static final MediaType D = new MediaType(I_D); 402 405 public static final MediaType E = new MediaType(I_E); 406 409 public static final MediaType NA_10X15_ENVELOPE = 410 new MediaType(I_NA_10X15_ENVELOPE); 411 414 public static final MediaType NA_10X14_ENVELOPE = 415 new MediaType(I_NA_10X14_ENVELOPE); 416 419 public static final MediaType NA_10X13_ENVELOPE = 420 new MediaType(I_NA_10X13_ENVELOPE); 421 424 public static final MediaType NA_9X12_ENVELOPE = 425 new MediaType(I_NA_9X12_ENVELOPE); 426 429 public static final MediaType NA_9X11_ENVELOPE = 430 new MediaType(I_NA_9X11_ENVELOPE); 431 434 public static final MediaType NA_7X9_ENVELOPE = 435 new MediaType(I_NA_7X9_ENVELOPE); 436 439 public static final MediaType NA_6X9_ENVELOPE = 440 new MediaType(I_NA_6X9_ENVELOPE); 441 445 public static final MediaType NA_NUMBER_9_ENVELOPE = 446 new MediaType(I_NA_NUMBER_9_ENVELOPE); 447 451 public static final MediaType NA_NUMBER_10_ENVELOPE = 452 new MediaType(I_NA_NUMBER_10_ENVELOPE); 453 457 public static final MediaType NA_NUMBER_11_ENVELOPE = 458 new MediaType(I_NA_NUMBER_11_ENVELOPE); 459 463 public static final MediaType NA_NUMBER_12_ENVELOPE = 464 new MediaType(I_NA_NUMBER_12_ENVELOPE); 465 469 public static final MediaType NA_NUMBER_14_ENVELOPE = 470 new MediaType(I_NA_NUMBER_14_ENVELOPE); 471 474 public static final MediaType INVITE_ENVELOPE = 475 new MediaType(I_INVITE_ENVELOPE); 476 479 public static final MediaType ITALY_ENVELOPE = 480 new MediaType(I_ITALY_ENVELOPE); 481 484 public static final MediaType MONARCH_ENVELOPE = 485 new MediaType(I_MONARCH_ENVELOPE); 486 489 public static final MediaType PERSONAL_ENVELOPE = 490 new MediaType(I_PERSONAL_ENVELOPE); 491 494 public static final MediaType A0 = ISO_A0; 495 498 public static final MediaType A1 = ISO_A1; 499 502 public static final MediaType A2 = ISO_A2; 503 506 public static final MediaType A3 = ISO_A3; 507 510 public static final MediaType A4 = ISO_A4; 511 514 public static final MediaType A5 = ISO_A5; 515 518 public static final MediaType A6 = ISO_A6; 519 522 public static final MediaType A7 = ISO_A7; 523 526 public static final MediaType A8 = ISO_A8; 527 530 public static final MediaType A9 = ISO_A9; 531 534 public static final MediaType A10 = ISO_A10; 535 538 public static final MediaType B0 = ISO_B0; 539 542 public static final MediaType B1 = ISO_B1; 543 546 public static final MediaType B2 = ISO_B2; 547 550 public static final MediaType B3 = ISO_B3; 551 554 public static final MediaType B4 = ISO_B4; 555 558 public static final MediaType ISO_B4_ENVELOPE = ISO_B4; 559 562 public static final MediaType B5 = ISO_B5; 563 566 public static final MediaType ISO_B5_ENVELOPE = ISO_B5; 567 570 public static final MediaType B6 = ISO_B6; 571 574 public static final MediaType B7 = ISO_B7; 575 578 public static final MediaType B8 = ISO_B8; 579 582 public static final MediaType B9 = ISO_B9; 583 586 public static final MediaType B10 = ISO_B10; 587 590 public static final MediaType C0 = ISO_C0; 591 594 public static final MediaType ISO_C0_ENVELOPE = ISO_C0; 595 598 public static final MediaType C1 = ISO_C1; 599 602 public static final MediaType ISO_C1_ENVELOPE = ISO_C1; 603 606 public static final MediaType C2 = ISO_C2; 607 610 public static final MediaType ISO_C2_ENVELOPE = ISO_C2; 611 614 public static final MediaType C3 = ISO_C3; 615 618 public static final MediaType ISO_C3_ENVELOPE = ISO_C3; 619 622 public static final MediaType C4 = ISO_C4; 623 626 public static final MediaType ISO_C4_ENVELOPE = ISO_C4; 627 630 public static final MediaType C5 = ISO_C5; 631 634 public static final MediaType ISO_C5_ENVELOPE = ISO_C5; 635 638 public static final MediaType C6 = ISO_C6; 639 642 public static final MediaType ISO_C6_ENVELOPE = ISO_C6; 643 646 public static final MediaType C7 = ISO_C7; 647 650 public static final MediaType ISO_C7_ENVELOPE = ISO_C7; 651 654 public static final MediaType C8 = ISO_C8; 655 658 public static final MediaType ISO_C8_ENVELOPE = ISO_C8; 659 662 public static final MediaType C9 = ISO_C9; 663 666 public static final MediaType ISO_C9_ENVELOPE = ISO_C9; 667 670 public static final MediaType C10 = ISO_C10; 671 674 public static final MediaType ISO_C10_ENVELOPE = ISO_C10; 675 678 public static final MediaType ISO_DESIGNATED_LONG_ENVELOPE = 679 ISO_DESIGNATED_LONG; 680 683 public static final MediaType STATEMENT = INVOICE; 684 687 public static final MediaType TABLOID = LEDGER; 688 691 public static final MediaType LETTER = NA_LETTER; 692 695 public static final MediaType NOTE = NA_LETTER; 696 699 public static final MediaType LEGAL = NA_LEGAL; 700 703 public static final MediaType ENV_10X15 = NA_10X15_ENVELOPE; 704 707 public static final MediaType ENV_10X14 = NA_10X14_ENVELOPE; 708 711 public static final MediaType ENV_10X13 = NA_10X13_ENVELOPE; 712 715 public static final MediaType ENV_9X12 = NA_9X12_ENVELOPE; 716 719 public static final MediaType ENV_9X11 = NA_9X11_ENVELOPE; 720 723 public static final MediaType ENV_7X9 = NA_7X9_ENVELOPE; 724 727 public static final MediaType ENV_6X9 = NA_6X9_ENVELOPE; 728 731 public static final MediaType ENV_9 = NA_NUMBER_9_ENVELOPE; 732 735 public static final MediaType ENV_10 = NA_NUMBER_10_ENVELOPE; 736 739 public static final MediaType ENV_11 = NA_NUMBER_11_ENVELOPE; 740 743 public static final MediaType ENV_12 = NA_NUMBER_12_ENVELOPE; 744 747 public static final MediaType ENV_14 = NA_NUMBER_14_ENVELOPE; 748 751 public static final MediaType ENV_INVITE = INVITE_ENVELOPE; 752 755 public static final MediaType ENV_ITALY = ITALY_ENVELOPE; 756 759 public static final MediaType ENV_MONARCH = MONARCH_ENVELOPE; 760 763 public static final MediaType ENV_PERSONAL = PERSONAL_ENVELOPE; 764 767 public static final MediaType INVITE = INVITE_ENVELOPE; 768 771 public static final MediaType ITALY = ITALY_ENVELOPE; 772 775 public static final MediaType MONARCH = MONARCH_ENVELOPE; 776 779 public static final MediaType PERSONAL = PERSONAL_ENVELOPE; 780 781 private MediaType(int type) { 782 super(type, NAMES); 783 } 784 } 785 786 790 public static final class OrientationRequestedType extends AttributeValue { 791 private static final int I_PORTRAIT = 0; 792 private static final int I_LANDSCAPE = 1; 793 794 private static final String NAMES[] = { 795 "portrait", "landscape" 796 }; 797 798 802 public static final OrientationRequestedType PORTRAIT = 803 new OrientationRequestedType(I_PORTRAIT); 804 808 public static final OrientationRequestedType LANDSCAPE = 809 new OrientationRequestedType(I_LANDSCAPE); 810 811 private OrientationRequestedType(int type) { 812 super(type, NAMES); 813 } 814 } 815 816 819 public static final class OriginType extends AttributeValue { 820 private static final int I_PHYSICAL = 0; 821 private static final int I_PRINTABLE = 1; 822 823 private static final String NAMES[] = { 824 "physical", "printable" 825 }; 826 827 830 public static final OriginType PHYSICAL = new OriginType(I_PHYSICAL); 831 834 public static final OriginType PRINTABLE = new OriginType(I_PRINTABLE); 835 836 private OriginType(int type) { 837 super(type, NAMES); 838 } 839 } 840 841 845 public static final class PrintQualityType extends AttributeValue { 846 private static final int I_HIGH = 0; 847 private static final int I_NORMAL = 1; 848 private static final int I_DRAFT = 2; 849 850 private static final String NAMES[] = { 851 "high", "normal", "draft" 852 }; 853 854 858 public static final PrintQualityType HIGH = 859 new PrintQualityType(I_HIGH); 860 864 public static final PrintQualityType NORMAL = 865 new PrintQualityType(I_NORMAL); 866 870 public static final PrintQualityType DRAFT = 871 new PrintQualityType(I_DRAFT); 872 873 private PrintQualityType(int type) { 874 super(type, NAMES); 875 } 876 } 877 878 private ColorType color; 879 private MediaType media; 880 private OrientationRequestedType orientationRequested; 881 private OriginType origin; 882 private PrintQualityType printQuality; 883 private int[] printerResolution; 884 885 889 public PageAttributes() { 890 setColor(ColorType.MONOCHROME); 891 setMediaToDefault(); 892 setOrientationRequestedToDefault(); 893 setOrigin(OriginType.PHYSICAL); 894 setPrintQualityToDefault(); 895 setPrinterResolutionToDefault(); 896 } 897 898 904 public PageAttributes(PageAttributes obj) { 905 set(obj); 906 } 907 908 926 public PageAttributes(ColorType color, MediaType media, 927 OrientationRequestedType orientationRequested, 928 OriginType origin, PrintQualityType printQuality, 929 int[] printerResolution) { 930 setColor(color); 931 setMedia(media); 932 setOrientationRequested(orientationRequested); 933 setOrigin(origin); 934 setPrintQuality(printQuality); 935 setPrinterResolution(printerResolution); 936 } 937 938 944 public Object clone() { 945 try { 946 return super.clone(); 947 } catch (CloneNotSupportedException e) { 948 throw new InternalError (); 950 } 951 } 952 953 959 public void set(PageAttributes obj) { 960 color = obj.color; 961 media = obj.media; 962 orientationRequested = obj.orientationRequested; 963 origin = obj.origin; 964 printQuality = obj.printQuality; 965 printerResolution = obj.printerResolution; 967 } 968 969 976 public ColorType getColor() { 977 return color; 978 } 979 980 988 public void setColor(ColorType color) { 989 if (color == null) { 990 throw new IllegalArgumentException ("Invalid value for attribute "+ 991 "color"); 992 } 993 this.color = color; 994 } 995 996 1002 public MediaType getMedia() { 1003 return media; 1004 } 1005 1006 1019 public void setMedia(MediaType media) { 1020 if (media == null) { 1021 throw new IllegalArgumentException ("Invalid value for attribute "+ 1022 "media"); 1023 } 1024 this.media = media; 1025 } 1026 1027 1033 public void setMediaToDefault(){ 1034 String defaultCountry = Locale.getDefault().getCountry(); 1035 if (defaultCountry != null && 1036 (defaultCountry.equals(Locale.US.getCountry()) || 1037 defaultCountry.equals(Locale.CANADA.getCountry()))) { 1038 setMedia(MediaType.NA_LETTER); 1039 } else { 1040 setMedia(MediaType.ISO_A4); 1041 } 1042 } 1043 1044 1051 public OrientationRequestedType getOrientationRequested() { 1052 return orientationRequested; 1053 } 1054 1055 1064 public void setOrientationRequested(OrientationRequestedType 1065 orientationRequested) { 1066 if (orientationRequested == null) { 1067 throw new IllegalArgumentException ("Invalid value for attribute "+ 1068 "orientationRequested"); 1069 } 1070 this.orientationRequested = orientationRequested; 1071 } 1072 1073 1084 public void setOrientationRequested(int orientationRequested) { 1085 switch (orientationRequested) { 1086 case 3: 1087 setOrientationRequested(OrientationRequestedType.PORTRAIT); 1088 break; 1089 case 4: 1090 setOrientationRequested(OrientationRequestedType.LANDSCAPE); 1091 break; 1092 default: 1093 setOrientationRequested(null); 1095 break; 1096 } 1097 } 1098 1099 1103 public void setOrientationRequestedToDefault() { 1104 setOrientationRequested(OrientationRequestedType.PORTRAIT); 1105 } 1106 1107 1117 public OriginType getOrigin() { 1118 return origin; 1119 } 1120 1121 1131 public void setOrigin(OriginType origin) { 1132 if (origin == null) { 1133 throw new IllegalArgumentException ("Invalid value for attribute "+ 1134 "origin"); 1135 } 1136 this.origin = origin; 1137 } 1138 1139 1146 public PrintQualityType getPrintQuality() { 1147 return printQuality; 1148 } 1149 1150 1159 public void setPrintQuality(PrintQualityType printQuality) { 1160 if (printQuality == null) { 1161 throw new IllegalArgumentException ("Invalid value for attribute "+ 1162 "printQuality"); 1163 } 1164 this.printQuality = printQuality; 1165 } 1166 1167 1179 public void setPrintQuality(int printQuality) { 1180 switch (printQuality) { 1181 case 3: 1182 setPrintQuality(PrintQualityType.DRAFT); 1183 break; 1184 case 4: 1185 setPrintQuality(PrintQualityType.NORMAL); 1186 break; 1187 case 5: 1188 setPrintQuality(PrintQualityType.HIGH); 1189 break; 1190 default: 1191 setPrintQuality(null); 1193 break; 1194 } 1195 } 1196 1197 1201 public void setPrintQualityToDefault() { 1202 setPrintQuality(PrintQualityType.NORMAL); 1203 } 1204 1205 1219 public int[] getPrinterResolution() { 1220 int[] copy = new int[3]; 1224 copy[0] = printerResolution[0]; 1225 copy[1] = printerResolution[1]; 1226 copy[2] = printerResolution[2]; 1227 return copy; 1228 } 1229 1230 1251 public void setPrinterResolution(int[] printerResolution) { 1252 if (printerResolution == null || 1253 printerResolution.length != 3 || 1254 printerResolution[0] <= 0 || 1255 printerResolution[1] <= 0 || 1256 (printerResolution[2] != 3 && printerResolution[2] != 4)) { 1257 throw new IllegalArgumentException ("Invalid value for attribute "+ 1258 "printerResolution"); 1259 } 1260 int[] copy = new int[3]; 1264 copy[0] = printerResolution[0]; 1265 copy[1] = printerResolution[1]; 1266 copy[2] = printerResolution[2]; 1267 this.printerResolution = copy; 1268 } 1269 1270 1281 public void setPrinterResolution(int printerResolution) { 1282 setPrinterResolution(new int[] { printerResolution, printerResolution, 1283 3 } ); 1284 } 1285 1286 1291 public void setPrinterResolutionToDefault() { 1292 setPrinterResolution(72); 1293 } 1294 1295 1309 public boolean equals(Object obj) { 1310 if (!(obj instanceof PageAttributes )) { 1311 return false; 1312 } 1313 1314 PageAttributes rhs = (PageAttributes )obj; 1315 1316 return (color == rhs.color && 1317 media == rhs.media && 1318 orientationRequested == rhs.orientationRequested && 1319 origin == rhs.origin && 1320 printQuality == rhs.printQuality && 1321 printerResolution[0] == rhs.printerResolution[0] && 1322 printerResolution[1] == rhs.printerResolution[1] && 1323 printerResolution[2] == rhs.printerResolution[2]); 1324 } 1325 1326 1331 public int hashCode() { 1332 return (color.hashCode() << 31 ^ 1333 media.hashCode() << 24 ^ 1334 orientationRequested.hashCode() << 23 ^ 1335 origin.hashCode() << 22 ^ 1336 printQuality.hashCode() << 20 ^ 1337 printerResolution[2] >> 2 << 19 ^ 1338 printerResolution[1] << 10 ^ 1339 printerResolution[0]); 1340 } 1341 1342 1347 public String toString() { 1348 return "color=" + getColor() + ",media=" + getMedia() + 1350 ",orientation-requested=" + getOrientationRequested() + 1351 ",origin=" + getOrigin() + ",print-quality=" + getPrintQuality() + 1352 ",printer-resolution=[" + printerResolution[0] + "," + 1353 printerResolution[1] + "," + printerResolution[2] + "]"; 1354 } 1355} 1356 | Popular Tags |