API Overview API Index Package Overview Direct link to this page
JDK 1.6
  java.awt. JobAttributes View Javadoc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048

/*
 * @(#)JobAttributes.java	1.11 06/04/07
 *
 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

package java.awt;

/**
 * A set of attributes which control a print job.
 * <p>
 * Instances of this class control the number of copies, default selection,
 * destination, print dialog, file and printer names, page ranges, multiple
 * document handling (including collation), and multi-page imposition (such
 * as duplex) of every print job which uses the instance. Attribute names are
 * compliant with the Internet Printing Protocol (IPP) 1.1 where possible.
 * Attribute values are partially compliant where possible.
 * <p>
 * To use a method which takes an inner class type, pass a reference to
 * one of the constant fields of the inner class. Client code cannot create
 * new instances of the inner class types because none of those classes
 * has a public constructor. For example, to set the print dialog type to
 * the cross-platform, pure Java print dialog, use the following code:
 * <pre>
 * import java.awt.JobAttributes;
 *
 * public class PureJavaPrintDialogExample {
 *     public void setPureJavaPrintDialog(JobAttributes jobAttributes) {
 *         jobAttributes.setDialog(JobAttributes.DialogType.COMMON);
 *     }
 * }
 * </pre>
 * <p>
 * Every IPP attribute which supports an <i>attributeName</i>-default value
 * has a corresponding <code>set<i>attributeName</i>ToDefault</code> method.
 * Default value fields are not provided.
 *
 * @version	1.11, 04/07/06
 * @author	David Mendenhall
 * @since 1.3
 */
public final class JobAttributes implements Cloneable {
    /**
     * A type-safe enumeration of possible default selection states.
     * @since 1.3
     */
    public static final class DefaultSelectionType extends AttributeValue {
        private static final int I_ALL = 0;
        private static final int I_RANGE = 1;
        private static final int I_SELECTION = 2;

        private static final String NAMES[] = {
	    "all", "range", "selection"
	};

        /**
	 * The <code>DefaultSelectionType</code> instance to use for
         * specifying that all pages of the job should be printed.
	 */
        public static final DefaultSelectionType ALL =
           new DefaultSelectionType(I_ALL);
        /**
	 * The <code>DefaultSelectionType</code> instance to use for
         * specifying that a range of pages of the job should be printed.
	 */
        public static final DefaultSelectionType RANGE =
           new DefaultSelectionType(I_RANGE);
        /**
	 * The <code>DefaultSelectionType</code> instance to use for
         * specifying that the current selection should be printed.
	 */
        public static final DefaultSelectionType SELECTION =
           new DefaultSelectionType(I_SELECTION);

        private DefaultSelectionType(int type) {
	    super(type, NAMES);
	}
    }

    /**
     * A type-safe enumeration of possible job destinations.
     * @since 1.3
     */
    public static final class DestinationType extends AttributeValue {
        private static final int I_FILE = 0;
        private static final int I_PRINTER = 1;

        private static final String NAMES[] = {
	    "file", "printer"
	};

        /**
	 * The <code>DestinationType</code> instance to use for
         * specifying print to file.
	 */
        public static final DestinationType FILE =
            new DestinationType(I_FILE);
        /**
	 * The <code>DestinationType</code> instance to use for
         * specifying print to printer.
	 */
        public static final DestinationType PRINTER =
            new DestinationType(I_PRINTER);

        private DestinationType(int type) {
	    super(type, NAMES);
	}
    }

    /**
     * A type-safe enumeration of possible dialogs to display to the user.
     * @since 1.3
     */
    public static final class DialogType extends AttributeValue {
        private static final int I_COMMON = 0;
        private static final int I_NATIVE = 1;
        private static final int I_NONE = 2;

        private static final String NAMES[] = {
	    "common", "native", "none"
	};

        /**
	 * The <code>DialogType</code> instance to use for
         * specifying the cross-platform, pure Java print dialog.
	 */
        public static final DialogType COMMON = new DialogType(I_COMMON);
        /**
	 * The <code>DialogType</code> instance to use for
         * specifying the platform's native print dialog.
	 */
        public static final DialogType NATIVE = new DialogType(I_NATIVE);
        /**
	 * The <code>DialogType</code> instance to use for
         * specifying no print dialog.
	 */
        public static final DialogType NONE = new DialogType(I_NONE);

        private DialogType(int type) {
	    super(type, NAMES);
	}
    }

    /**
     * A type-safe enumeration of possible multiple copy handling states.
     * It is used to control how the sheets of multiple copies of a single
     * document are collated.
     * @since 1.3
     */
    public static final class MultipleDocumentHandlingType extends
                                                               AttributeValue {
        private static final int I_SEPARATE_DOCUMENTS_COLLATED_COPIES = 0;
        private static final int I_SEPARATE_DOCUMENTS_UNCOLLATED_COPIES = 1;

        private static final String NAMES[] = {
	    "separate-documents-collated-copies",
	    "separate-documents-uncollated-copies"
	};

        /**
	 * The <code>MultipleDocumentHandlingType</code> instance to use for specifying
	 * that the job should be divided into separate, collated copies.
	 */
        public static final MultipleDocumentHandlingType
            SEPARATE_DOCUMENTS_COLLATED_COPIES =
                new MultipleDocumentHandlingType(
                    I_SEPARATE_DOCUMENTS_COLLATED_COPIES);
        /**
	 * The <code>MultipleDocumentHandlingType</code> instance to use for specifying
	 * that the job should be divided into separate, uncollated copies.
	 */
        public static final MultipleDocumentHandlingType
            SEPARATE_DOCUMENTS_UNCOLLATED_COPIES =
                new MultipleDocumentHandlingType(
                    I_SEPARATE_DOCUMENTS_UNCOLLATED_COPIES);

        private MultipleDocumentHandlingType(int type) {
	    super(type, NAMES);
	}
    }

    /**
     * A type-safe enumeration of possible multi-page impositions. These
     * impositions are in compliance with IPP 1.1.
     * @since 1.3
     */
    public static final class SidesType extends AttributeValue {
        private static final int I_ONE_SIDED = 0;
        private static final int I_TWO_SIDED_LONG_EDGE = 1;
        private static final int I_TWO_SIDED_SHORT_EDGE = 2;

        private static final String NAMES[] = {
	    "one-sided", "two-sided-long-edge", "two-sided-short-edge"
	};

        /**
	 * The <code>SidesType</code> instance to use for specifying that 
	 * consecutive job pages should be printed upon the same side of
         * consecutive media sheets.
	 */
        public static final SidesType ONE_SIDED = new SidesType(I_ONE_SIDED);
        /**
	 * The <code>SidesType</code> instance to use for specifying that
         * consecutive job pages should be printed upon front and back sides
         * of consecutive media sheets, such that the orientation of each pair
         * of pages on the medium would be correct for the reader as if for
         * binding on the long edge.
	 */
        public static final SidesType TWO_SIDED_LONG_EDGE =
            new SidesType(I_TWO_SIDED_LONG_EDGE);
        /**
	 * The <code>SidesType</code> instance to use for specifying that
         * consecutive job pages should be printed upon front and back sides
         * of consecutive media sheets, such that the orientation of each pair
         * of pages on the medium would be correct for the reader as if for
         * binding on the short edge.
	 */
        public static final SidesType TWO_SIDED_SHORT_EDGE =
            new SidesType(I_TWO_SIDED_SHORT_EDGE);

        private SidesType(int type) {
	    super(type, NAMES);
	}
    }

    private int copies;
    private DefaultSelectionType defaultSelection;
    private DestinationType destination;
    private DialogType dialog;
    private String fileName;
    private int fromPage;
    private int maxPage;
    private int minPage;
    private MultipleDocumentHandlingType multipleDocumentHandling;
    private int[][] pageRanges;
    private int prFirst;
    private int prLast;
    private String printer;
    private SidesType sides;
    private int toPage;

    /**
     * Constructs a <code>JobAttributes</code> instance with default
     * values for every attribute.  The dialog defaults to
     * <code>DialogType.NATIVE</code>.  Min page defaults to
     * <code>1</code>.  Max page defaults to <code>Integer.MAX_VALUE</code>.
     * Destination defaults to <code>DestinationType.PRINTER</code>.
     * Selection defaults to <code>DefaultSelectionType.ALL</code>.
     * Number of copies defaults to <code>1</code>. Multiple document handling defaults
     * to <code>MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_UNCOLLATED_COPIES</code>.
     * Sides defaults to <code>SidesType.ONE_SIDED</code>. File name defaults
     * to <code>null</code>.
     */
    public JobAttributes() {
        setCopiesToDefault();
	setDefaultSelection(DefaultSelectionType.ALL);
	setDestination(DestinationType.PRINTER);
	setDialog(DialogType.NATIVE);
	setMaxPage(Integer.MAX_VALUE);
	setMinPage(1);
	setMultipleDocumentHandlingToDefault();
	setSidesToDefault();
    }

    /**
     * Constructs a <code>JobAttributes</code> instance which is a copy
     * of the supplied <code>JobAttributes</code>.
     *
     * @param	obj the <code>JobAttributes</code> to copy
     */
    public JobAttributes(JobAttributes obj) {
        set(obj);
    }

    /**
     * Constructs a <code>JobAttributes</code> instance with the
     * specified values for every attribute.
     *
     * @param	copies an integer greater than 0
     * @param	defaultSelection <code>DefaultSelectionType.ALL</code>,
     *		<code>DefaultSelectionType.RANGE</code>, or
     *          <code>DefaultSelectionType.SELECTION</code>
     * @param	destination <code>DesintationType.FILE</code> or
     *          <code>DesintationType.PRINTER</code>
     * @param	dialog <code>DialogType.COMMON</code>,
     *          <code>DialogType.NATIVE</code>, or
     *		<code>DialogType.NONE</code>
     * @param	fileName the possibly <code>null</code> file name
     * @param	maxPage an integer greater than zero and greater than or equal
     *		to <i>minPage</i>
     * @param	minPage an integer greater than zero and less than or equal
     *		to <i>maxPage</i>
     * @param	multipleDocumentHandling
     *     <code>MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_COLLATED_COPIES</code> or
     *     <code>MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_UNCOLLATED_COPIES</code>
     * @param	pageRanges an array of integer arrays of two elements; an array
     *		is interpreted as a range spanning all pages including and
     *		between the specified pages; ranges must be in ascending
     *		order and must not overlap; specified page numbers cannot be
     *		less than <i>minPage</i> nor greater than <i>maxPage</i>;
     *		for example:
     *          <pre>
     *		(new int[][] { new int[] { 1, 3 }, new int[] { 5, 5 },
     *		               new int[] { 15, 19 } }),
     *          </pre>
     *		specifies pages 1, 2, 3, 5, 15, 16, 17, 18, and 19. Note that
     *		(<code>new int[][] { new int[] { 1, 1 }, new int[] { 1, 2 } }</code>),
     *		is an invalid set of page ranges because the two ranges
     *		overlap
     * @param	printer the possibly <code>null</code> printer name
     * @param	sides <code>SidesType.ONE_SIDED</code>,
     *          <code>SidesType.TWO_SIDED_LONG_EDGE</code>, or
     *		<code>SidesType.TWO_SIDED_SHORT_EDGE</code>
     * @throws	IllegalArgumentException if one or more of the above
     *		conditions is violated
     */
    public JobAttributes(int copies, DefaultSelectionType defaultSelection,
			 DestinationType destination, DialogType dialog,
			 String fileName, int maxPage, int minPage,
			 MultipleDocumentHandlingType multipleDocumentHandling,
			 int[][] pageRanges, String printer, SidesType sides) {
        setCopies(copies);
	setDefaultSelection(defaultSelection);
	setDestination(destination);
	setDialog(dialog);
	setFileName(fileName);
	setMaxPage(maxPage);
	setMinPage(minPage);
	setMultipleDocumentHandling(multipleDocumentHandling);
	setPageRanges(pageRanges);
	setPrinter(printer);
	setSides(sides);
    }

    /**
     * Creates and returns a copy of this <code>JobAttributes</code>.
     *
     * @return	the newly created copy; it is safe to cast this Object into
     *		a <code>JobAttributes</code>
     */
    public Object clone() {
        try {
	    return super.clone();
	} catch (CloneNotSupportedException e) {
	    // Since we implement Cloneable, this should never happen
	    throw new InternalError();
	}
    }

    /**
     * Sets all of the attributes of this <code>JobAttributes</code> to
     * the same values as the attributes of obj.
     *
     * @param	obj the <code>JobAttributes</code> to copy
     */
    public void set(JobAttributes obj) {
        copies = obj.copies;
	defaultSelection = obj.defaultSelection;
	destination = obj.destination;
	dialog = obj.dialog;
	fileName = obj.fileName;
	fromPage = obj.fromPage;
	maxPage = obj.maxPage;
	minPage = obj.minPage;
	multipleDocumentHandling = obj.multipleDocumentHandling;
	// okay because we never modify the contents of pageRanges
	pageRanges = obj.pageRanges;
	prFirst = obj.prFirst;
	prLast = obj.prLast;
	printer = obj.printer;
	sides = obj.sides;
	toPage = obj.toPage;
    }

    /**
     * Returns the number of copies the application should render for jobs
     * using these attributes. This attribute is updated to the value chosen
     * by the user.
     *
     * @return	an integer greater than 0.
     */
    public int getCopies() {
        return copies;
    }

    /**
     * Specifies the number of copies the application should render for jobs
     * using these attributes. Not specifying this attribute is equivalent to
     * specifying <code>1</code>.
     *
     * @param	copies an integer greater than 0
     * @throws	IllegalArgumentException if <code>copies</code> is less than
     *      or equal to 0
     */
    public void setCopies(int copies) {
        if (copies <= 0) {
	    throw new IllegalArgumentException("Invalid value for attribute "+
					       "copies");
	}
	this.copies = copies;
    }

    /**
     * Sets the number of copies the application should render for jobs using
     * these attributes to the default. The default number of copies is 1.
     */
    public void setCopiesToDefault() {
        setCopies(1);
    }

    /**
     * Specifies whether, for jobs using these attributes, the application
     * should print all pages, the range specified by the return value of
     * <code>getPageRanges</code>, or the current selection. This attribute
     * is updated to the value chosen by the user.
     *
     * @return	DefaultSelectionType.ALL, DefaultSelectionType.RANGE, or
     *		DefaultSelectionType.SELECTION
     */
    public DefaultSelectionType getDefaultSelection() {
        return defaultSelection;
    }

    /**
     * Specifies whether, for jobs using these attributes, the application
     * should print all pages, the range specified by the return value of
     * <code>getPageRanges</code>, or the current selection. Not specifying
     * this attribute is equivalent to specifying DefaultSelectionType.ALL.
     *
     * @param	defaultSelection DefaultSelectionType.ALL,
     *		DefaultSelectionType.RANGE, or DefaultSelectionType.SELECTION.
     * @throws	IllegalArgumentException if defaultSelection is <code>null</code>
     */
    public void setDefaultSelection(DefaultSelectionType defaultSelection) {
        if (defaultSelection == null) {
	    throw new IllegalArgumentException("Invalid value for attribute "+
					       "defaultSelection");
	}
        this.defaultSelection = defaultSelection;
    }

    /**
     * Specifies whether output will be to a printer or a file for jobs using
     * these attributes. This attribute is updated to the value chosen by the
     * user.
     *
     * @return	DesintationType.FILE or DesintationType.PRINTER
     */
    public DestinationType getDestination() {
        return destination;
    }

    /**
     * Specifies whether output will be to a printer or a file for jobs using
     * these attributes. Not specifying this attribute is equivalent to
     * specifying DesintationType.PRINTER.
     *
     * @param	destination DesintationType.FILE or DesintationType.PRINTER.
     * @throws	IllegalArgumentException if destination is null.
     */
    public void setDestination(DestinationType destination) {
        if (destination == null) {
	    throw new IllegalArgumentException("Invalid value for attribute "+
					       "destination");
	}
        this.destination = destination;
    }

    /**
     * Returns whether, for jobs using these attributes, the user should see
     * a print dialog in which to modify the print settings, and which type of
     * print dialog should be displayed. DialogType.COMMON denotes a cross-
     * platform, pure Java print dialog. DialogType.NATIVE denotes the
     * platform's native print dialog. If a platform does not support a native
     * print dialog, the pure Java print dialog is displayed instead.
     * DialogType.NONE specifies no print dialog (i.e., background printing).
     * This attribute cannot be modified by, and is not subject to any
     * limitations of, the implementation or the target printer.
     *
     * @return	<code>DialogType.COMMON</code>, <code>DialogType.NATIVE</code>, or
     *		<code>DialogType.NONE</code>
     */
    public DialogType getDialog() {
        return dialog;
    }

    /**
     * Specifies whether, for jobs using these attributes, the user should see
     * a print dialog in which to modify the print settings, and which type of
     * print dialog should be displayed. DialogType.COMMON denotes a cross-
     * platform, pure Java print dialog. DialogType.NATIVE denotes the
     * platform's native print dialog. If a platform does not support a native
     * print dialog, the pure Java print dialog is displayed instead.
     * DialogType.NONE specifies no print dialog (i.e., background printing).
     * Not specifying this attribute is equivalent to specifying
     * DialogType.NATIVE.
     *
     * @param	dialog DialogType.COMMON, DialogType.NATIVE, or
     *		DialogType.NONE.
     * @throws	IllegalArgumentException if dialog is null.
     */
    public void setDialog(DialogType dialog) {
        if (dialog == null) {
	    throw new IllegalArgumentException("Invalid value for attribute "+
					       "dialog");
	}
        this.dialog = dialog;
    }

    /**
     * Specifies the file name for the output file for jobs using these
     * attributes. This attribute is updated to the value chosen by the user.
     *
     * @return	the possibly <code>null</code> file name
     */
    public String getFileName() {
        return fileName;
    }

    /**
     * Specifies the file name for the output file for jobs using these
     * attributes. Default is platform-dependent and implementation-defined.
     *
     * @param	fileName the possibly null file name.
     */
    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    /**
     * Returns, for jobs using these attributes, the first page to be
     * printed, if a range of pages is to be printed. This attribute is
     * updated to the value chosen by the user. An application should ignore
     * this attribute on output, unless the return value of the <code>
     * getDefaultSelection</code> method is DefaultSelectionType.RANGE. An
     * application should honor the return value of <code>getPageRanges</code>
     * over the return value of this method, if possible.
     *
     * @return	an integer greater than zero and less than or equal to
     *          <i>toPage</i> and greater than or equal to <i>minPage</i> and
     *		less than or equal to <i>maxPage</i>.
     */
    public int getFromPage() {
        if (fromPage != 0) {
	    return fromPage;
	} else if (toPage != 0) {
	    return getMinPage();
	} else if (pageRanges != null) {
	    return prFirst;
	} else {
	    return getMinPage();
	}
    }

    /**
     * Specifies, for jobs using these attributes, the first page to be
     * printed, if a range of pages is to be printed. If this attribute is not
     * specified, then the values from the pageRanges attribute are used. If
     * pageRanges and either or both of fromPage and toPage are specified,
     * pageRanges takes precedence. Specifying none of pageRanges, fromPage,
     * or toPage is equivalent to calling
     * setPageRanges(new int[][] { new int[] { <i>minPage</i> } });
     *
     * @param	fromPage an integer greater than zero and less than or equal to
     *          <i>toPage</i> and greater than or equal to <i>minPage</i> and
     *		less than or equal to <i>maxPage</i>.
     * @throws	IllegalArgumentException if one or more of the above
     *		conditions is violated.
     */
    public void setFromPage(int fromPage) {
        if (fromPage <= 0 ||
	    (toPage != 0 && fromPage > toPage) ||
	    fromPage < minPage ||
	    fromPage > maxPage) {
	    throw new IllegalArgumentException("Invalid value for attribute "+
					       "fromPage");
	}
	this.fromPage = fromPage;
    }

    /**
     * Specifies the maximum value the user can specify as the last page to
     * be printed for jobs using these attributes. This attribute cannot be
     * modified by, and is not subject to any limitations of, the
     * implementation or the target printer.
     *
     * @return	an integer greater than zero and greater than or equal
     *		to <i>minPage</i>.
     */
    public int getMaxPage() {
        return maxPage;
    }

    /**
     * Specifies the maximum value the user can specify as the last page to
     * be printed for jobs using these attributes. Not specifying this
     * attribute is equivalent to specifying <code>Integer.MAX_VALUE</code>.
     *
     * @param	maxPage an integer greater than zero and greater than or equal
     *		to <i>minPage</i>
     * @throws	IllegalArgumentException if one or more of the above
     *		conditions is violated
     */
    public void setMaxPage(int maxPage) {
        if (maxPage <= 0 || maxPage < minPage) {
	    throw new IllegalArgumentException("Invalid value for attribute "+
					       "maxPage");
	}
	this.maxPage = maxPage;
    }

    /**
     * Specifies the minimum value the user can specify as the first page to
     * be printed for jobs using these attributes. This attribute cannot be
     * modified by, and is not subject to any limitations of, the
     * implementation or the target printer.
     *
     * @return	an integer greater than zero and less than or equal
     *		to <i>maxPage</i>.
     */
    public int getMinPage() {
        return minPage;
    }

    /**
     * Specifies the minimum value the user can specify as the first page to
     * be printed for jobs using these attributes. Not specifying this
     * attribute is equivalent to specifying <code>1</code>.
     *
     * @param	minPage an integer greater than zero and less than or equal
     *		to <i>maxPage</i>.
     * @throws	IllegalArgumentException if one or more of the above
     *		conditions is violated.
     */
    public void setMinPage(int minPage) {
        if (minPage <= 0 || minPage > maxPage) {
	    throw new IllegalArgumentException("Invalid value for attribute "+
					       "minPage");
	}
	this.minPage = minPage;
    }

    /**
     * Specifies the handling of multiple copies, including collation, for
     * jobs using these attributes. This attribute is updated to the value
     * chosen by the user.
     *
     * @return
     *     MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_COLLATED_COPIES or
     *     MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_UNCOLLATED_COPIES.
     */
    public MultipleDocumentHandlingType getMultipleDocumentHandling() {
        return multipleDocumentHandling;
    }

    /**
     * Specifies the handling of multiple copies, including collation, for
     * jobs using these attributes. Not specifying this attribute is equivalent
     * to specifying
     * MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_UNCOLLATED_COPIES.
     *
     * @param	multipleDocumentHandling
     *     MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_COLLATED_COPIES or
     *     MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_UNCOLLATED_COPIES.
     * @throws	IllegalArgumentException if multipleDocumentHandling is null.
     */
    public void setMultipleDocumentHandling(MultipleDocumentHandlingType
					    multipleDocumentHandling) {
        if (multipleDocumentHandling == null) {
	    throw new IllegalArgumentException("Invalid value for attribute "+
					       "multipleDocumentHandling");
	}
        this.multipleDocumentHandling = multipleDocumentHandling;
    }

    /**
     * Sets the handling of multiple copies, including collation, for jobs
     * using these attributes to the default. The default handling is
     * MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_UNCOLLATED_COPIES.
     */
    public void setMultipleDocumentHandlingToDefault() {
        setMultipleDocumentHandling(
            MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_UNCOLLATED_COPIES);
    }

    /**
     * Specifies, for jobs using these attributes, the ranges of pages to be
     * printed, if a range of pages is to be printed. All range numbers are
     * inclusive. This attribute is updated to the value chosen by the user.
     * An application should ignore this attribute on output, unless the
     * return value of the <code>getDefaultSelection</code> method is
     * DefaultSelectionType.RANGE.
     *
     * @return	an array of integer arrays of 2 elements. An array
     *		is interpreted as a range spanning all pages including and
     *		between the specified pages. Ranges must be in ascending
     *		order and must not overlap. Specified page numbers cannot be
     *		less than <i>minPage</i> nor greater than <i>maxPage</i>.
     *		For example:
     *		(new int[][] { new int[] { 1, 3 }, new int[] { 5, 5 },
     *		               new int[] { 15, 19 } }),
     *		specifies pages 1, 2, 3, 5, 15, 16, 17, 18, and 19.
     */
    public int[][] getPageRanges() {
        if (pageRanges != null) {
	    // Return a copy because otherwise client code could circumvent the
	    // the checks made in setPageRanges by modifying the returned
	    // array.
	    int[][] copy = new int[pageRanges.length][2];
	    for (int i = 0; i < pageRanges.length; i++) {
		copy[i][0] = pageRanges[i][0];
		copy[i][1] = pageRanges[i][1];
	    }
	    return copy;
	} else if (fromPage != 0 || toPage != 0) {
	    int fromPage = getFromPage();
	    int toPage = getToPage();
	    return new int[][] { new int[] { fromPage, toPage } };
	} else {
	    int minPage = getMinPage();
	    return new int[][] { new int[] { minPage, minPage } };
	}
    }

    /**
     * Specifies, for jobs using these attributes, the ranges of pages to be
     * printed, if a range of pages is to be printed. All range numbers are
     * inclusive. If this attribute is not specified, then the values from the
     * fromPage and toPages attributes are used. If pageRanges and either or
     * both of fromPage and toPage are specified, pageRanges takes precedence.
     * Specifying none of pageRanges, fromPage, or toPage is equivalent to
     * calling setPageRanges(new int[][] { new int[] { <i>minPage</i>, 
     *                                                 <i>minPage</i> } });
     *
     * @param	pageRanges an array of integer arrays of 2 elements. An array
     *		is interpreted as a range spanning all pages including and
     *		between the specified pages. Ranges must be in ascending
     *		order and must not overlap. Specified page numbers cannot be
     *		less than <i>minPage</i> nor greater than <i>maxPage</i>.
     *		For example:
     *		(new int[][] { new int[] { 1, 3 }, new int[] { 5, 5 },
     *		               new int[] { 15, 19 } }),
     *		specifies pages 1, 2, 3, 5, 15, 16, 17, 18, and 19. Note that
     *		(new int[][] { new int[] { 1, 1 }, new int[] { 1, 2 } }),
     *		is an invalid set of page ranges because the two ranges
     *		overlap.
     * @throws	IllegalArgumentException if one or more of the above
     *		conditions is violated.
     */
    public void setPageRanges(int[][] pageRanges) {
        String xcp = "Invalid value for attribute pageRanges";
	int first = 0;
        int last = 0;

	if (pageRanges == null) {
	    throw new IllegalArgumentException(xcp);
	}

        for (int i = 0; i < pageRanges.length; i++) {
	    if (pageRanges[i] == null ||
		pageRanges[i].length != 2 ||
		pageRanges[i][0] <= last ||
		pageRanges[i][1] < pageRanges[i][0]) {
	            throw new IllegalArgumentException(xcp);
	    }
	    last = pageRanges[i][1];
	    if (first == 0) {
	        first = pageRanges[i][0];
	    }
	}

	if (first < minPage || last > maxPage) {
	    throw new IllegalArgumentException(xcp);
	}

        // Store a copy because otherwise client code could circumvent the
        // the checks made above by holding a reference to the array and
	// modifying it after calling setPageRanges.
        int[][] copy = new int[pageRanges.length][2];
	for (int i = 0; i < pageRanges.length; i++) {
	    copy[i][0] = pageRanges[i][0];
	    copy[i][1] = pageRanges[i][1];
	}
	this.pageRanges = copy;
	this.prFirst = first;
	this.prLast = last;
    }

    /**
     * Returns the destination printer for jobs using these attributes. This
     * attribute is updated to the value chosen by the user.
     *
     * @return	the possibly null printer name.
     */
    public String getPrinter() {
        return printer;
    }

    /**
     * Specifies the destination printer for jobs using these attributes.
     * Default is platform-dependent and implementation-defined.
     *
     * @param	printer the possibly null printer name.
     */
    public void setPrinter(String printer) {
        this.printer = printer;
    }

    /**
     * Returns how consecutive pages should be imposed upon the sides of the
     * print medium for jobs using these attributes. SidesType.ONE_SIDED
     * imposes each consecutive page upon the same side of consecutive media
     * sheets. This imposition is sometimes called <i>simplex</i>.
     * SidesType.TWO_SIDED_LONG_EDGE imposes each consecutive pair of pages
     * upon front and back sides of consecutive media sheets, such that the
     * orientation of each pair of pages on the medium would be correct for
     * the reader as if for binding on the long edge. This imposition is
     * sometimes called <i>duplex</i>. SidesType.TWO_SIDED_SHORT_EDGE imposes
     * each consecutive pair of pages upon front and back sides of consecutive
     * media sheets, such that the orientation of each pair of pages on the
     * medium would be correct for the reader as if for binding on the short
     * edge. This imposition is sometimes called <i>tumble</i>. This attribute
     * is updated to the value chosen by the user.
     *
     * @return	SidesType.ONE_SIDED, SidesType.TWO_SIDED_LONG_EDGE, or
     *		SidesType.TWO_SIDED_SHORT_EDGE.
     */
    public SidesType getSides() {
        return sides;
    }

    /**
     * Specifies how consecutive pages should be imposed upon the sides of the
     * print medium for jobs using these attributes. SidesType.ONE_SIDED
     * imposes each consecutive page upon the same side of consecutive media
     * sheets. This imposition is sometimes called <i>simplex</i>.
     * SidesType.TWO_SIDED_LONG_EDGE imposes each consecutive pair of pages
     * upon front and back sides of consecutive media sheets, such that the
     * orientation of each pair of pages on the medium would be correct for
     * the reader as if for binding on the long edge. This imposition is
     * sometimes called <i>duplex</i>. SidesType.TWO_SIDED_SHORT_EDGE imposes
     * each consecutive pair of pages upon front and back sides of consecutive
     * media sheets, such that the orientation of each pair of pages on the
     * medium would be correct for the reader as if for binding on the short
     * edge. This imposition is sometimes called <i>tumble</i>. Not specifying
     * this attribute is equivalent to specifying SidesType.ONE_SIDED.
     *
     * @param	sides SidesType.ONE_SIDED, SidesType.TWO_SIDED_LONG_EDGE, or
     *		SidesType.TWO_SIDED_SHORT_EDGE.
     * @throws	IllegalArgumentException if sides is null.
     */
    public void setSides(SidesType sides) {
        if (sides == null) {
	    throw new IllegalArgumentException("Invalid value for attribute "+
					       "sides");
	}
        this.sides = sides;
    }

    /**
     * Sets how consecutive pages should be imposed upon the sides of the
     * print medium for jobs using these attributes to the default. The
     * default imposition is SidesType.ONE_SIDED.
     */
    public void setSidesToDefault() {
        setSides(SidesType.ONE_SIDED);
    }

    /**
     * Returns, for jobs using these attributes, the last page (inclusive)
     * to be printed, if a range of pages is to be printed. This attribute is
     * updated to the value chosen by the user. An application should ignore
     * this attribute on output, unless the return value of the <code>
     * getDefaultSelection</code> method is DefaultSelectionType.RANGE. An
     * application should honor the return value of <code>getPageRanges</code>
     * over the return value of this method, if possible.
     *
     * @return	an integer greater than zero and greater than or equal
     *		to <i>toPage</i> and greater than or equal to <i>minPage</i>
     *		and less than or equal to <i>maxPage</i>.
     */
    public int getToPage() {
        if (toPage != 0) {
	    return toPage;
	} else if (fromPage != 0) {
	    return fromPage;
	} else if (pageRanges != null) {
	    return prLast;
	} else {
	    return getMinPage();
	}
    }

    /**
     * Specifies, for jobs using these attributes, the last page (inclusive)
     * to be printed, if a range of pages is to be printed.
     * If this attribute is not specified, then the values from the pageRanges
     * attribute are used. If pageRanges and either or both of fromPage and
     * toPage are specified, pageRanges takes precedence. Specifying none of
     * pageRanges, fromPage, or toPage is equivalent to calling
     * setPageRanges(new int[][] { new int[] { <i>minPage</i> } });
     *
     * @param	toPage an integer greater than zero and greater than or equal
     *		to <i>fromPage</i> and greater than or equal to <i>minPage</i>
     *		and less than or equal to <i>maxPage</i>.
     * @throws	IllegalArgumentException if one or more of the above
     *		conditions is violated.
     */
    public void setToPage(int toPage) {
        if (toPage <= 0 ||
	    (fromPage != 0 && toPage < fromPage) ||
	    toPage < minPage ||
	    toPage > maxPage) {
	    throw new IllegalArgumentException("Invalid value for attribute "+
					       "toPage");
	}
	this.toPage = toPage;
    }

    /**
     * Determines whether two JobAttributes are equal to each other.
     * <p>
     * Two JobAttributes are equal if and only if each of their attributes are
     * equal. Attributes of enumeration type are equal if and only if the
     * fields refer to the same unique enumeration object. A set of page
     * ranges is equal if and only if the sets are of equal length, each range
     * enumerates the same pages, and the ranges are in the same order.
     *
     * @param	obj the object whose equality will be checked.
     * @return	whether obj is equal to this JobAttribute according to the
     *		above criteria.
     */
    public boolean equals(Object obj) {
        if (!(obj instanceof JobAttributes)) {
	    return false;
	}
	JobAttributes rhs = (JobAttributes)obj;

	if (fileName == null) {
	    if (rhs.fileName != null) {
	        return false;
	    }
	} else {
	    if (!fileName.equals(rhs.fileName)) {
	        return false;
	    }
	}

	if (pageRanges == null) {
	    if (rhs.pageRanges != null) {
	        return false;
	    }
	} else {
	    if (rhs.pageRanges == null ||
		    pageRanges.length != rhs.pageRanges.length) {
	        return false;
	    }
	    for (int i = 0; i < pageRanges.length; i++) {
	        if (pageRanges[i][0] != rhs.pageRanges[i][0] ||
		    pageRanges[i][1] != rhs.pageRanges[i][1]) {
		    return false;
		}
	    }
	}

	if (printer == null) {
	    if (rhs.printer != null) {
	        return false;
	    }
	} else {
	    if (!printer.equals(rhs.printer)) {
	        return false;
	    }
	}

	return (copies == rhs.copies &&
		defaultSelection == rhs.defaultSelection &&
		destination == rhs.destination &&
		dialog == rhs.dialog &&
		fromPage == rhs.fromPage &&
		maxPage == rhs.maxPage &&
		minPage == rhs.minPage &&
		multipleDocumentHandling == rhs.multipleDocumentHandling &&
		prFirst == rhs.prFirst &&
		prLast == rhs.prLast &&
		sides == rhs.sides &&
		toPage == rhs.toPage);
    }

    /**
     * Returns a hash code value for this JobAttributes.
     *
     * @return	the hash code.
     */
    public int hashCode() {
	int rest = ((copies + fromPage + maxPage + minPage + prFirst + prLast +
		     toPage) * 31) << 21;
	if (pageRanges != null) {
	    int sum = 0;
	    for (int i = 0; i < pageRanges.length; i++) {
	        sum += pageRanges[i][0] + pageRanges[i][1];
	    }
	    rest ^= (sum * 31) << 11;
	}
	if (fileName != null) {
	    rest ^= fileName.hashCode();
	}
	if (printer != null) {
	    rest ^= printer.hashCode();
	}
	return (defaultSelection.hashCode() << 6 ^
		destination.hashCode() << 5 ^
		dialog.hashCode() << 3 ^
		multipleDocumentHandling.hashCode() << 2 ^
		sides.hashCode() ^
		rest);
    }

    /**
     * Returns a string representation of this JobAttributes.
     *
     * @return	the string representation.
     */
    public String toString() {
        int[][] pageRanges = getPageRanges();
	String prStr = "[";
	boolean first = true;
	for (int i = 0; i < pageRanges.length; i++) {
	    if (first) {
	        first = false;
	    } else {
	        prStr += ",";
	    }
	    prStr += pageRanges[i][0] + ":" + pageRanges[i][1];
	}
	prStr += "]";

        return "copies=" + getCopies() + ",defaultSelection=" + 
	    getDefaultSelection() + ",destination=" + getDestination() +
	    ",dialog=" + getDialog() + ",fileName=" + getFileName() +
	    ",fromPage=" + getFromPage() + ",maxPage=" + getMaxPage() +
	    ",minPage=" + getMinPage() + ",multiple-document-handling=" +
	    getMultipleDocumentHandling() + ",page-ranges=" + prStr +
	    ",printer=" + getPrinter() + ",sides=" + getSides() + ",toPage=" +
	    getToPage();
    }
}

Generated By: JavaOnTracks Doclet 0.1.4     ©Thibaut Colar