1 7 8 package java.awt; 9 10 42 public final class JobAttributes implements Cloneable { 43 46 public static final class DefaultSelectionType extends AttributeValue { 47 private static final int I_ALL = 0; 48 private static final int I_RANGE = 1; 49 private static final int I_SELECTION = 2; 50 51 private static final String NAMES[] = { 52 "all", "range", "selection" 53 }; 54 55 59 public static final DefaultSelectionType ALL = 60 new DefaultSelectionType(I_ALL); 61 65 public static final DefaultSelectionType RANGE = 66 new DefaultSelectionType(I_RANGE); 67 71 public static final DefaultSelectionType SELECTION = 72 new DefaultSelectionType(I_SELECTION); 73 74 private DefaultSelectionType(int type) { 75 super(type, NAMES); 76 } 77 } 78 79 82 public static final class DestinationType extends AttributeValue { 83 private static final int I_FILE = 0; 84 private static final int I_PRINTER = 1; 85 86 private static final String NAMES[] = { 87 "file", "printer" 88 }; 89 90 94 public static final DestinationType FILE = 95 new DestinationType(I_FILE); 96 100 public static final DestinationType PRINTER = 101 new DestinationType(I_PRINTER); 102 103 private DestinationType(int type) { 104 super(type, NAMES); 105 } 106 } 107 108 111 public static final class DialogType extends AttributeValue { 112 private static final int I_COMMON = 0; 113 private static final int I_NATIVE = 1; 114 private static final int I_NONE = 2; 115 116 private static final String NAMES[] = { 117 "common", "native", "none" 118 }; 119 120 124 public static final DialogType COMMON = new DialogType(I_COMMON); 125 129 public static final DialogType NATIVE = new DialogType(I_NATIVE); 130 134 public static final DialogType NONE = new DialogType(I_NONE); 135 136 private DialogType(int type) { 137 super(type, NAMES); 138 } 139 } 140 141 146 public static final class MultipleDocumentHandlingType extends 147 AttributeValue { 148 private static final int I_SEPARATE_DOCUMENTS_COLLATED_COPIES = 0; 149 private static final int I_SEPARATE_DOCUMENTS_UNCOLLATED_COPIES = 1; 150 151 private static final String NAMES[] = { 152 "separate-documents-collated-copies", 153 "separate-documents-uncollated-copies" 154 }; 155 156 160 public static final MultipleDocumentHandlingType 161 SEPARATE_DOCUMENTS_COLLATED_COPIES = 162 new MultipleDocumentHandlingType( 163 I_SEPARATE_DOCUMENTS_COLLATED_COPIES); 164 168 public static final MultipleDocumentHandlingType 169 SEPARATE_DOCUMENTS_UNCOLLATED_COPIES = 170 new MultipleDocumentHandlingType( 171 I_SEPARATE_DOCUMENTS_UNCOLLATED_COPIES); 172 173 private MultipleDocumentHandlingType(int type) { 174 super(type, NAMES); 175 } 176 } 177 178 182 public static final class SidesType extends AttributeValue { 183 private static final int I_ONE_SIDED = 0; 184 private static final int I_TWO_SIDED_LONG_EDGE = 1; 185 private static final int I_TWO_SIDED_SHORT_EDGE = 2; 186 187 private static final String NAMES[] = { 188 "one-sided", "two-sided-long-edge", "two-sided-short-edge" 189 }; 190 191 196 public static final SidesType ONE_SIDED = new SidesType(I_ONE_SIDED); 197 204 public static final SidesType TWO_SIDED_LONG_EDGE = 205 new SidesType(I_TWO_SIDED_LONG_EDGE); 206 213 public static final SidesType TWO_SIDED_SHORT_EDGE = 214 new SidesType(I_TWO_SIDED_SHORT_EDGE); 215 216 private SidesType(int type) { 217 super(type, NAMES); 218 } 219 } 220 221 private int copies; 222 private DefaultSelectionType defaultSelection; 223 private DestinationType destination; 224 private DialogType dialog; 225 private String fileName; 226 private int fromPage; 227 private int maxPage; 228 private int minPage; 229 private MultipleDocumentHandlingType multipleDocumentHandling; 230 private int[][] pageRanges; 231 private int prFirst; 232 private int prLast; 233 private String printer; 234 private SidesType sides; 235 private int toPage; 236 237 249 public JobAttributes() { 250 setCopiesToDefault(); 251 setDefaultSelection(DefaultSelectionType.ALL); 252 setDestination(DestinationType.PRINTER); 253 setDialog(DialogType.NATIVE); 254 setMaxPage(Integer.MAX_VALUE); 255 setMinPage(1); 256 setMultipleDocumentHandlingToDefault(); 257 setSidesToDefault(); 258 } 259 260 266 public JobAttributes(JobAttributes obj) { 267 set(obj); 268 } 269 270 312 public JobAttributes(int copies, DefaultSelectionType defaultSelection, 313 DestinationType destination, DialogType dialog, 314 String fileName, int maxPage, int minPage, 315 MultipleDocumentHandlingType multipleDocumentHandling, 316 int[][] pageRanges, String printer, SidesType sides) { 317 setCopies(copies); 318 setDefaultSelection(defaultSelection); 319 setDestination(destination); 320 setDialog(dialog); 321 setFileName(fileName); 322 setMaxPage(maxPage); 323 setMinPage(minPage); 324 setMultipleDocumentHandling(multipleDocumentHandling); 325 setPageRanges(pageRanges); 326 setPrinter(printer); 327 setSides(sides); 328 } 329 330 336 public Object clone() { 337 try { 338 return super.clone(); 339 } catch (CloneNotSupportedException e) { 340 throw new InternalError (); 342 } 343 } 344 345 351 public void set(JobAttributes obj) { 352 copies = obj.copies; 353 defaultSelection = obj.defaultSelection; 354 destination = obj.destination; 355 dialog = obj.dialog; 356 fileName = obj.fileName; 357 fromPage = obj.fromPage; 358 maxPage = obj.maxPage; 359 minPage = obj.minPage; 360 multipleDocumentHandling = obj.multipleDocumentHandling; 361 pageRanges = obj.pageRanges; 363 prFirst = obj.prFirst; 364 prLast = obj.prLast; 365 printer = obj.printer; 366 sides = obj.sides; 367 toPage = obj.toPage; 368 } 369 370 377 public int getCopies() { 378 return copies; 379 } 380 381 390 public void setCopies(int copies) { 391 if (copies <= 0) { 392 throw new IllegalArgumentException ("Invalid value for attribute "+ 393 "copies"); 394 } 395 this.copies = copies; 396 } 397 398 402 public void setCopiesToDefault() { 403 setCopies(1); 404 } 405 406 415 public DefaultSelectionType getDefaultSelection() { 416 return defaultSelection; 417 } 418 419 429 public void setDefaultSelection(DefaultSelectionType defaultSelection) { 430 if (defaultSelection == null) { 431 throw new IllegalArgumentException ("Invalid value for attribute "+ 432 "defaultSelection"); 433 } 434 this.defaultSelection = defaultSelection; 435 } 436 437 444 public DestinationType getDestination() { 445 return destination; 446 } 447 448 456 public void setDestination(DestinationType destination) { 457 if (destination == null) { 458 throw new IllegalArgumentException ("Invalid value for attribute "+ 459 "destination"); 460 } 461 this.destination = destination; 462 } 463 464 478 public DialogType getDialog() { 479 return dialog; 480 } 481 482 497 public void setDialog(DialogType dialog) { 498 if (dialog == null) { 499 throw new IllegalArgumentException ("Invalid value for attribute "+ 500 "dialog"); 501 } 502 this.dialog = dialog; 503 } 504 505 511 public String getFileName() { 512 return fileName; 513 } 514 515 521 public void setFileName(String fileName) { 522 this.fileName = fileName; 523 } 524 525 538 public int getFromPage() { 539 if (fromPage != 0) { 540 return fromPage; 541 } else if (toPage != 0) { 542 return getMinPage(); 543 } else if (pageRanges != null) { 544 return prFirst; 545 } else { 546 return getMinPage(); 547 } 548 } 549 550 565 public void setFromPage(int fromPage) { 566 if (fromPage <= 0 || 567 (toPage != 0 && fromPage > toPage) || 568 fromPage < minPage || 569 fromPage > maxPage) { 570 throw new IllegalArgumentException ("Invalid value for attribute "+ 571 "fromPage"); 572 } 573 this.fromPage = fromPage; 574 } 575 576 585 public int getMaxPage() { 586 return maxPage; 587 } 588 589 599 public void setMaxPage(int maxPage) { 600 if (maxPage <= 0 || maxPage < minPage) { 601 throw new IllegalArgumentException ("Invalid value for attribute "+ 602 "maxPage"); 603 } 604 this.maxPage = maxPage; 605 } 606 607 616 public int getMinPage() { 617 return minPage; 618 } 619 620 630 public void setMinPage(int minPage) { 631 if (minPage <= 0 || minPage > maxPage) { 632 throw new IllegalArgumentException ("Invalid value for attribute "+ 633 "minPage"); 634 } 635 this.minPage = minPage; 636 } 637 638 647 public MultipleDocumentHandlingType getMultipleDocumentHandling() { 648 return multipleDocumentHandling; 649 } 650 651 662 public void setMultipleDocumentHandling(MultipleDocumentHandlingType 663 multipleDocumentHandling) { 664 if (multipleDocumentHandling == null) { 665 throw new IllegalArgumentException ("Invalid value for attribute "+ 666 "multipleDocumentHandling"); 667 } 668 this.multipleDocumentHandling = multipleDocumentHandling; 669 } 670 671 676 public void setMultipleDocumentHandlingToDefault() { 677 setMultipleDocumentHandling( 678 MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_UNCOLLATED_COPIES); 679 } 680 681 699 public int[][] getPageRanges() { 700 if (pageRanges != null) { 701 int[][] copy = new int[pageRanges.length][2]; 705 for (int i = 0; i < pageRanges.length; i++) { 706 copy[i][0] = pageRanges[i][0]; 707 copy[i][1] = pageRanges[i][1]; 708 } 709 return copy; 710 } else if (fromPage != 0 || toPage != 0) { 711 int fromPage = getFromPage(); 712 int toPage = getToPage(); 713 return new int[][] { new int[] { fromPage, toPage } }; 714 } else { 715 int minPage = getMinPage(); 716 return new int[][] { new int[] { minPage, minPage } }; 717 } 718 } 719 720 745 public void setPageRanges(int[][] pageRanges) { 746 String xcp = "Invalid value for attribute pageRanges"; 747 int first = 0; 748 int last = 0; 749 750 if (pageRanges == null) { 751 throw new IllegalArgumentException (xcp); 752 } 753 754 for (int i = 0; i < pageRanges.length; i++) { 755 if (pageRanges[i] == null || 756 pageRanges[i].length != 2 || 757 pageRanges[i][0] <= last || 758 pageRanges[i][1] < pageRanges[i][0]) { 759 throw new IllegalArgumentException (xcp); 760 } 761 last = pageRanges[i][1]; 762 if (first == 0) { 763 first = pageRanges[i][0]; 764 } 765 } 766 767 if (first < minPage || last > maxPage) { 768 throw new IllegalArgumentException (xcp); 769 } 770 771 int[][] copy = new int[pageRanges.length][2]; 775 for (int i = 0; i < pageRanges.length; i++) { 776 copy[i][0] = pageRanges[i][0]; 777 copy[i][1] = pageRanges[i][1]; 778 } 779 this.pageRanges = copy; 780 this.prFirst = first; 781 this.prLast = last; 782 } 783 784 790 public String getPrinter() { 791 return printer; 792 } 793 794 800 public void setPrinter(String printer) { 801 this.printer = printer; 802 } 803 804 823 public SidesType getSides() { 824 return sides; 825 } 826 827 847 public void setSides(SidesType sides) { 848 if (sides == null) { 849 throw new IllegalArgumentException ("Invalid value for attribute "+ 850 "sides"); 851 } 852 this.sides = sides; 853 } 854 855 860 public void setSidesToDefault() { 861 setSides(SidesType.ONE_SIDED); 862 } 863 864 877 public int getToPage() { 878 if (toPage != 0) { 879 return toPage; 880 } else if (fromPage != 0) { 881 return fromPage; 882 } else if (pageRanges != null) { 883 return prLast; 884 } else { 885 return getMinPage(); 886 } 887 } 888 889 904 public void setToPage(int toPage) { 905 if (toPage <= 0 || 906 (fromPage != 0 && toPage < fromPage) || 907 toPage < minPage || 908 toPage > maxPage) { 909 throw new IllegalArgumentException ("Invalid value for attribute "+ 910 "toPage"); 911 } 912 this.toPage = toPage; 913 } 914 915 928 public boolean equals(Object obj) { 929 if (!(obj instanceof JobAttributes )) { 930 return false; 931 } 932 JobAttributes rhs = (JobAttributes )obj; 933 934 if (fileName == null) { 935 if (rhs.fileName != null) { 936 return false; 937 } 938 } else { 939 if (!fileName.equals(rhs.fileName)) { 940 return false; 941 } 942 } 943 944 if (pageRanges == null) { 945 if (rhs.pageRanges != null) { 946 return false; 947 } 948 } else { 949 if (rhs.pageRanges == null || 950 pageRanges.length != rhs.pageRanges.length) { 951 return false; 952 } 953 for (int i = 0; i < pageRanges.length; i++) { 954 if (pageRanges[i][0] != rhs.pageRanges[i][0] || 955 pageRanges[i][1] != rhs.pageRanges[i][1]) { 956 return false; 957 } 958 } 959 } 960 961 if (printer == null) { 962 if (rhs.printer != null) { 963 return false; 964 } 965 } else { 966 if (!printer.equals(rhs.printer)) { 967 return false; 968 } 969 } 970 971 return (copies == rhs.copies && 972 defaultSelection == rhs.defaultSelection && 973 destination == rhs.destination && 974 dialog == rhs.dialog && 975 fromPage == rhs.fromPage && 976 maxPage == rhs.maxPage && 977 minPage == rhs.minPage && 978 multipleDocumentHandling == rhs.multipleDocumentHandling && 979 prFirst == rhs.prFirst && 980 prLast == rhs.prLast && 981 sides == rhs.sides && 982 toPage == rhs.toPage); 983 } 984 985 990 public int hashCode() { 991 int rest = ((copies + fromPage + maxPage + minPage + prFirst + prLast + 992 toPage) * 31) << 21; 993 if (pageRanges != null) { 994 int sum = 0; 995 for (int i = 0; i < pageRanges.length; i++) { 996 sum += pageRanges[i][0] + pageRanges[i][1]; 997 } 998 rest ^= (sum * 31) << 11; 999 } 1000 if (fileName != null) { 1001 rest ^= fileName.hashCode(); 1002 } 1003 if (printer != null) { 1004 rest ^= printer.hashCode(); 1005 } 1006 return (defaultSelection.hashCode() << 6 ^ 1007 destination.hashCode() << 5 ^ 1008 dialog.hashCode() << 3 ^ 1009 multipleDocumentHandling.hashCode() << 2 ^ 1010 sides.hashCode() ^ 1011 rest); 1012 } 1013 1014 1019 public String toString() { 1020 int[][] pageRanges = getPageRanges(); 1021 String prStr = "["; 1022 boolean first = true; 1023 for (int i = 0; i < pageRanges.length; i++) { 1024 if (first) { 1025 first = false; 1026 } else { 1027 prStr += ","; 1028 } 1029 prStr += pageRanges[i][0] + ":" + pageRanges[i][1]; 1030 } 1031 prStr += "]"; 1032 1033 return "copies=" + getCopies() + ",defaultSelection=" + 1034 getDefaultSelection() + ",destination=" + getDestination() + 1035 ",dialog=" + getDialog() + ",fileName=" + getFileName() + 1036 ",fromPage=" + getFromPage() + ",maxPage=" + getMaxPage() + 1037 ",minPage=" + getMinPage() + ",multiple-document-handling=" + 1038 getMultipleDocumentHandling() + ",page-ranges=" + prStr + 1039 ",printer=" + getPrinter() + ",sides=" + getSides() + ",toPage=" + 1040 getToPage(); 1041 } 1042} 1043 | Popular Tags |