KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > awt > PageAttributes


1 /*
2  * @(#)PageAttributes.java 1.7 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package java.awt;
9
10 import java.util.Locale JavaDoc;
11
12 /**
13  * A set of attributes which control the output of a printed page.
14  * <p>
15  * Instances of this class control the color state, paper size (media type),
16  * orientation, logical origin, print quality, and resolution of every
17  * page which uses the instance. Attribute names are compliant with the
18  * Internet Printing Protocol (IPP) 1.1 where possible. Attribute values
19  * are partially compliant where possible.
20  * <p>
21  * To use a method which takes an inner class type, pass a reference to
22  * one of the constant fields of the inner class. Client code cannot create
23  * new instances of the inner class types because none of those classes
24  * has a public constructor. For example, to set the color state to
25  * monochrome, use the following code:
26  * <pre>
27  * import java.awt.PageAttributes;
28  *
29  * public class MonochromeExample {
30  * public void setMonochrome(PageAttributes pageAttributes) {
31  * pageAttributes.setColor(PageAttributes.ColorType.MONOCHROME);
32  * }
33  * }
34  * </pre>
35  * <p>
36  * Every IPP attribute which supports an <i>attributeName</i>-default value
37  * has a corresponding <code>set<i>attributeName</i>ToDefault</code> method.
38  * Default value fields are not provided.
39  *
40  * @version 1.7, 12/19/03
41  * @author David Mendenhall
42  */

43 public final class PageAttributes implements Cloneable JavaDoc {
44     /**
45      * A type-safe enumeration of possible color states.
46      */

47     public static final class ColorType extends AttributeValue JavaDoc {
48         private static final int I_COLOR = 0;
49         private static final int I_MONOCHROME = 1;
50
51         private static final String JavaDoc NAMES[] = {
52         "color", "monochrome"
53     };
54
55         /**
56      * The ColorType instance to use for specifying color printing.
57      */

58         public static final ColorType COLOR = new ColorType(I_COLOR);
59         /**
60      * The ColorType instance to use for specifying monochrome printing.
61      */

62         public static final ColorType MONOCHROME = new ColorType(I_MONOCHROME);
63
64         private ColorType(int type) {
65         super(type, NAMES);
66     }
67     }
68
69     /**
70      * A type-safe enumeration of possible paper sizes. These sizes are in
71      * compliance with IPP 1.1.
72      */

73     public static final class MediaType extends AttributeValue JavaDoc {
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 JavaDoc 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         /**
170          * The MediaType instance for ISO/DIN & JIS 4A0, 1682 x 2378 mm.
171          */

172         public static final MediaType ISO_4A0 = new MediaType(I_ISO_4A0);
173         /**
174          * The MediaType instance for ISO/DIN & JIS 2A0, 1189 x 1682 mm.
175          */

176         public static final MediaType ISO_2A0 = new MediaType(I_ISO_2A0);
177         /**
178          * The MediaType instance for ISO/DIN & JIS A0, 841 x 1189 mm.
179          */

180         public static final MediaType ISO_A0 = new MediaType(I_ISO_A0);
181         /**
182          * The MediaType instance for ISO/DIN & JIS A1, 594 x 841 mm.
183          */

184         public static final MediaType ISO_A1 = new MediaType(I_ISO_A1);
185         /**
186          * The MediaType instance for ISO/DIN & JIS A2, 420 x 594 mm.
187          */

188         public static final MediaType ISO_A2 = new MediaType(I_ISO_A2);
189         /**
190          * The MediaType instance for ISO/DIN & JIS A3, 297 x 420 mm.
191          */

192         public static final MediaType ISO_A3 = new MediaType(I_ISO_A3);
193         /**
194          * The MediaType instance for ISO/DIN & JIS A4, 210 x 297 mm.
195          */

196         public static final MediaType ISO_A4 = new MediaType(I_ISO_A4);
197         /**
198          * The MediaType instance for ISO/DIN & JIS A5, 148 x 210 mm.
199          */

200         public static final MediaType ISO_A5 = new MediaType(I_ISO_A5);
201         /**
202          * The MediaType instance for ISO/DIN & JIS A6, 105 x 148 mm.
203          */

204         public static final MediaType ISO_A6 = new MediaType(I_ISO_A6);
205         /**
206          * The MediaType instance for ISO/DIN & JIS A7, 74 x 105 mm.
207          */

208         public static final MediaType ISO_A7 = new MediaType(I_ISO_A7);
209         /**
210          * The MediaType instance for ISO/DIN & JIS A8, 52 x 74 mm.
211          */

212         public static final MediaType ISO_A8 = new MediaType(I_ISO_A8);
213         /**
214          * The MediaType instance for ISO/DIN & JIS A9, 37 x 52 mm.
215          */

216         public static final MediaType ISO_A9 = new MediaType(I_ISO_A9);
217         /**
218          * The MediaType instance for ISO/DIN & JIS A10, 26 x 37 mm.
219          */

220         public static final MediaType ISO_A10 = new MediaType(I_ISO_A10);
221         /**
222          * The MediaType instance for ISO/DIN B0, 1000 x 1414 mm.
223          */

224         public static final MediaType ISO_B0 = new MediaType(I_ISO_B0);
225         /**
226          * The MediaType instance for ISO/DIN B1, 707 x 1000 mm.
227          */

228         public static final MediaType ISO_B1 = new MediaType(I_ISO_B1);
229         /**
230          * The MediaType instance for ISO/DIN B2, 500 x 707 mm.
231          */

232         public static final MediaType ISO_B2 = new MediaType(I_ISO_B2);
233         /**
234          * The MediaType instance for ISO/DIN B3, 353 x 500 mm.
235          */

236         public static final MediaType ISO_B3 = new MediaType(I_ISO_B3);
237         /**
238          * The MediaType instance for ISO/DIN B4, 250 x 353 mm.
239          */

240         public static final MediaType ISO_B4 = new MediaType(I_ISO_B4);
241         /**
242          * The MediaType instance for ISO/DIN B5, 176 x 250 mm.
243          */

244         public static final MediaType ISO_B5 = new MediaType(I_ISO_B5);
245         /**
246          * The MediaType instance for ISO/DIN B6, 125 x 176 mm.
247          */

248         public static final MediaType ISO_B6 = new MediaType(I_ISO_B6);
249         /**
250          * The MediaType instance for ISO/DIN B7, 88 x 125 mm.
251          */

252         public static final MediaType ISO_B7 = new MediaType(I_ISO_B7);
253         /**
254          * The MediaType instance for ISO/DIN B8, 62 x 88 mm.
255          */

256         public static final MediaType ISO_B8 = new MediaType(I_ISO_B8);
257         /**
258          * The MediaType instance for ISO/DIN B9, 44 x 62 mm.
259          */

260         public static final MediaType ISO_B9 = new MediaType(I_ISO_B9);
261         /**
262          * The MediaType instance for ISO/DIN B10, 31 x 44 mm.
263          */

264         public static final MediaType ISO_B10 = new MediaType(I_ISO_B10);
265         /**
266          * The MediaType instance for JIS B0, 1030 x 1456 mm.
267          */

268         public static final MediaType JIS_B0 = new MediaType(I_JIS_B0);
269         /**
270          * The MediaType instance for JIS B1, 728 x 1030 mm.
271          */

272         public static final MediaType JIS_B1 = new MediaType(I_JIS_B1);
273         /**
274          * The MediaType instance for JIS B2, 515 x 728 mm.
275          */

276         public static final MediaType JIS_B2 = new MediaType(I_JIS_B2);
277         /**
278          * The MediaType instance for JIS B3, 364 x 515 mm.
279          */

280         public static final MediaType JIS_B3 = new MediaType(I_JIS_B3);
281         /**
282          * The MediaType instance for JIS B4, 257 x 364 mm.
283          */

284         public static final MediaType JIS_B4 = new MediaType(I_JIS_B4);
285         /**
286          * The MediaType instance for JIS B5, 182 x 257 mm.
287          */

288         public static final MediaType JIS_B5 = new MediaType(I_JIS_B5);
289         /**
290          * The MediaType instance for JIS B6, 128 x 182 mm.
291          */

292         public static final MediaType JIS_B6 = new MediaType(I_JIS_B6);
293         /**
294          * The MediaType instance for JIS B7, 91 x 128 mm.
295          */

296         public static final MediaType JIS_B7 = new MediaType(I_JIS_B7);
297         /**
298          * The MediaType instance for JIS B8, 64 x 91 mm.
299          */

300         public static final MediaType JIS_B8 = new MediaType(I_JIS_B8);
301         /**
302          * The MediaType instance for JIS B9, 45 x 64 mm.
303          */

304         public static final MediaType JIS_B9 = new MediaType(I_JIS_B9);
305         /**
306          * The MediaType instance for JIS B10, 32 x 45 mm.
307          */

308         public static final MediaType JIS_B10 = new MediaType(I_JIS_B10);
309         /**
310          * The MediaType instance for ISO/DIN C0, 917 x 1297 mm.
311          */

312         public static final MediaType ISO_C0 = new MediaType(I_ISO_C0);
313         /**
314          * The MediaType instance for ISO/DIN C1, 648 x 917 mm.
315          */

316         public static final MediaType ISO_C1 = new MediaType(I_ISO_C1);
317         /**
318          * The MediaType instance for ISO/DIN C2, 458 x 648 mm.
319          */

320         public static final MediaType ISO_C2 = new MediaType(I_ISO_C2);
321         /**
322          * The MediaType instance for ISO/DIN C3, 324 x 458 mm.
323          */

324         public static final MediaType ISO_C3 = new MediaType(I_ISO_C3);
325         /**
326          * The MediaType instance for ISO/DIN C4, 229 x 324 mm.
327          */

328         public static final MediaType ISO_C4 = new MediaType(I_ISO_C4);
329         /**
330          * The MediaType instance for ISO/DIN C5, 162 x 229 mm.
331          */

332         public static final MediaType ISO_C5 = new MediaType(I_ISO_C5);
333         /**
334          * The MediaType instance for ISO/DIN C6, 114 x 162 mm.
335          */

336         public static final MediaType ISO_C6 = new MediaType(I_ISO_C6);
337         /**
338          * The MediaType instance for ISO/DIN C7, 81 x 114 mm.
339          */

340         public static final MediaType ISO_C7 = new MediaType(I_ISO_C7);
341         /**
342          * The MediaType instance for ISO/DIN C8, 57 x 81 mm.
343          */

344         public static final MediaType ISO_C8 = new MediaType(I_ISO_C8);
345         /**
346          * The MediaType instance for ISO/DIN C9, 40 x 57 mm.
347          */

348         public static final MediaType ISO_C9 = new MediaType(I_ISO_C9);
349         /**
350          * The MediaType instance for ISO/DIN C10, 28 x 40 mm.
351          */

352         public static final MediaType ISO_C10 = new MediaType(I_ISO_C10);
353         /**
354          * The MediaType instance for ISO Designated Long, 110 x 220 mm.
355          */

356         public static final MediaType ISO_DESIGNATED_LONG =
357             new MediaType(I_ISO_DESIGNATED_LONG);
358         /**
359          * The MediaType instance for Executive, 7 1/4 x 10 1/2 in.
360          */

361         public static final MediaType EXECUTIVE = new MediaType(I_EXECUTIVE);
362         /**
363          * The MediaType instance for Folio, 8 1/2 x 13 in.
364          */

365         public static final MediaType FOLIO = new MediaType(I_FOLIO);
366         /**
367          * The MediaType instance for Invoice, 5 1/2 x 8 1/2 in.
368          */

369         public static final MediaType INVOICE = new MediaType(I_INVOICE);
370         /**
371          * The MediaType instance for Ledger, 11 x 17 in.
372          */

373         public static final MediaType LEDGER = new MediaType(I_LEDGER);
374         /**
375          * The MediaType instance for North American Letter, 8 1/2 x 11 in.
376          */

377         public static final MediaType NA_LETTER = new MediaType(I_NA_LETTER);
378         /**
379          * The MediaType instance for North American Legal, 8 1/2 x 14 in.
380          */

381         public static final MediaType NA_LEGAL = new MediaType(I_NA_LEGAL);
382         /**
383          * The MediaType instance for Quarto, 215 x 275 mm.
384          */

385         public static final MediaType QUARTO = new MediaType(I_QUARTO);
386         /**
387          * The MediaType instance for Engineering A, 8 1/2 x 11 in.
388          */

389         public static final MediaType A = new MediaType(I_A);
390         /**
391          * The MediaType instance for Engineering B, 11 x 17 in.
392          */

393         public static final MediaType B = new MediaType(I_B);
394         /**
395          * The MediaType instance for Engineering C, 17 x 22 in.
396          */

397         public static final MediaType C = new MediaType(I_C);
398         /**
399          * The MediaType instance for Engineering D, 22 x 34 in.
400          */

401         public static final MediaType D = new MediaType(I_D);
402         /**
403          * The MediaType instance for Engineering E, 34 x 44 in.
404          */

405         public static final MediaType E = new MediaType(I_E);
406         /**
407          * The MediaType instance for North American 10 x 15 in.
408          */

409         public static final MediaType NA_10X15_ENVELOPE =
410             new MediaType(I_NA_10X15_ENVELOPE);
411         /**
412          * The MediaType instance for North American 10 x 14 in.
413          */

414         public static final MediaType NA_10X14_ENVELOPE =
415             new MediaType(I_NA_10X14_ENVELOPE);
416         /**
417          * The MediaType instance for North American 10 x 13 in.
418          */

419         public static final MediaType NA_10X13_ENVELOPE =
420             new MediaType(I_NA_10X13_ENVELOPE);
421         /**
422          * The MediaType instance for North American 9 x 12 in.
423          */

424         public static final MediaType NA_9X12_ENVELOPE =
425             new MediaType(I_NA_9X12_ENVELOPE);
426         /**
427          * The MediaType instance for North American 9 x 11 in.
428          */

429         public static final MediaType NA_9X11_ENVELOPE =
430             new MediaType(I_NA_9X11_ENVELOPE);
431         /**
432          * The MediaType instance for North American 7 x 9 in.
433          */

434         public static final MediaType NA_7X9_ENVELOPE =
435             new MediaType(I_NA_7X9_ENVELOPE);
436         /**
437          * The MediaType instance for North American 6 x 9 in.
438          */

439         public static final MediaType NA_6X9_ENVELOPE =
440             new MediaType(I_NA_6X9_ENVELOPE);
441         /**
442          * The MediaType instance for North American #9 Business Envelope,
443          * 3 7/8 x 8 7/8 in.
444          */

445         public static final MediaType NA_NUMBER_9_ENVELOPE =
446             new MediaType(I_NA_NUMBER_9_ENVELOPE);
447         /**
448          * The MediaType instance for North American #10 Business Envelope,
449          * 4 1/8 x 9 1/2 in.
450          */

451         public static final MediaType NA_NUMBER_10_ENVELOPE =
452             new MediaType(I_NA_NUMBER_10_ENVELOPE);
453         /**
454          * The MediaType instance for North American #11 Business Envelope,
455          * 4 1/2 x 10 3/8 in.
456          */

457         public static final MediaType NA_NUMBER_11_ENVELOPE =
458             new MediaType(I_NA_NUMBER_11_ENVELOPE);
459         /**
460          * The MediaType instance for North American #12 Business Envelope,
461          * 4 3/4 x 11 in.
462          */

463         public static final MediaType NA_NUMBER_12_ENVELOPE =
464             new MediaType(I_NA_NUMBER_12_ENVELOPE);
465         /**
466          * The MediaType instance for North American #14 Business Envelope,
467          * 5 x 11 1/2 in.
468          */

469         public static final MediaType NA_NUMBER_14_ENVELOPE =
470             new MediaType(I_NA_NUMBER_14_ENVELOPE);
471         /**
472          * The MediaType instance for Invitation Envelope, 220 x 220 mm.
473          */

474         public static final MediaType INVITE_ENVELOPE =
475             new MediaType(I_INVITE_ENVELOPE);
476         /**
477          * The MediaType instance for Italy Envelope, 110 x 230 mm.
478          */

479         public static final MediaType ITALY_ENVELOPE =
480             new MediaType(I_ITALY_ENVELOPE);
481         /**
482          * The MediaType instance for Monarch Envelope, 3 7/8 x 7 1/2 in.
483          */

484         public static final MediaType MONARCH_ENVELOPE =
485             new MediaType(I_MONARCH_ENVELOPE);
486         /**
487          * The MediaType instance for 6 3/4 envelope, 3 5/8 x 6 1/2 in.
488          */

489         public static final MediaType PERSONAL_ENVELOPE =
490             new MediaType(I_PERSONAL_ENVELOPE);
491         /**
492          * An alias for ISO_A0.
493          */

494         public static final MediaType A0 = ISO_A0;
495         /**
496          * An alias for ISO_A1.
497          */

498         public static final MediaType A1 = ISO_A1;
499         /**
500          * An alias for ISO_A2.
501          */

502         public static final MediaType A2 = ISO_A2;
503         /**
504          * An alias for ISO_A3.
505          */

506         public static final MediaType A3 = ISO_A3;
507         /**
508          * An alias for ISO_A4.
509          */

510         public static final MediaType A4 = ISO_A4;
511         /**
512          * An alias for ISO_A5.
513          */

514         public static final MediaType A5 = ISO_A5;
515         /**
516          * An alias for ISO_A6.
517          */

518         public static final MediaType A6 = ISO_A6;
519         /**
520          * An alias for ISO_A7.
521          */

522         public static final MediaType A7 = ISO_A7;
523         /**
524          * An alias for ISO_A8.
525          */

526         public static final MediaType A8 = ISO_A8;
527         /**
528          * An alias for ISO_A9.
529          */

530         public static final MediaType A9 = ISO_A9;
531         /**
532          * An alias for ISO_A10.
533          */

534         public static final MediaType A10 = ISO_A10;
535         /**
536          * An alias for ISO_B0.
537          */

538         public static final MediaType B0 = ISO_B0;
539         /**
540          * An alias for ISO_B1.
541          */

542         public static final MediaType B1 = ISO_B1;
543         /**
544          * An alias for ISO_B2.
545          */

546         public static final MediaType B2 = ISO_B2;
547         /**
548          * An alias for ISO_B3.
549          */

550         public static final MediaType B3 = ISO_B3;
551         /**
552          * An alias for ISO_B4.
553          */

554         public static final MediaType B4 = ISO_B4;
555         /**
556          * An alias for ISO_B4.
557          */

558         public static final MediaType ISO_B4_ENVELOPE = ISO_B4;
559         /**
560          * An alias for ISO_B5.
561          */

562         public static final MediaType B5 = ISO_B5;
563         /**
564          * An alias for ISO_B5.
565          */

566         public static final MediaType ISO_B5_ENVELOPE = ISO_B5;
567         /**
568          * An alias for ISO_B6.
569          */

570         public static final MediaType B6 = ISO_B6;
571         /**
572          * An alias for ISO_B7.
573          */

574         public static final MediaType B7 = ISO_B7;
575         /**
576          * An alias for ISO_B8.
577          */

578         public static final MediaType B8 = ISO_B8;
579         /**
580          * An alias for ISO_B9.
581          */

582         public static final MediaType B9 = ISO_B9;
583         /**
584          * An alias for ISO_B10.
585          */

586         public static final MediaType B10 = ISO_B10;
587         /**
588          * An alias for ISO_C0.
589          */

590         public static final MediaType C0 = ISO_C0;
591         /**
592          * An alias for ISO_C0.
593          */

594         public static final MediaType ISO_C0_ENVELOPE = ISO_C0;
595         /**
596          * An alias for ISO_C1.
597          */

598         public static final MediaType C1 = ISO_C1;
599         /**
600          * An alias for ISO_C1.
601          */

602         public static final MediaType ISO_C1_ENVELOPE = ISO_C1;
603         /**
604          * An alias for ISO_C2.
605          */

606         public static final MediaType C2 = ISO_C2;
607         /**
608          * An alias for ISO_C2.
609          */

610         public static final MediaType ISO_C2_ENVELOPE = ISO_C2;
611         /**
612          * An alias for ISO_C3.
613          */

614         public static final MediaType C3 = ISO_C3;
615         /**
616          * An alias for ISO_C3.
617          */

618         public static final MediaType ISO_C3_ENVELOPE = ISO_C3;
619         /**
620          * An alias for ISO_C4.
621          */

622         public static final MediaType C4 = ISO_C4;
623         /**
624          * An alias for ISO_C4.
625          */

626         public static final MediaType ISO_C4_ENVELOPE = ISO_C4;
627         /**
628          * An alias for ISO_C5.
629          */

630         public static final MediaType C5 = ISO_C5;
631         /**
632          * An alias for ISO_C5.
633          */

634         public static final MediaType ISO_C5_ENVELOPE = ISO_C5;
635         /**
636          * An alias for ISO_C6.
637          */

638         public static final MediaType C6 = ISO_C6;
639         /**
640          * An alias for ISO_C6.
641          */

642         public static final MediaType ISO_C6_ENVELOPE = ISO_C6;
643         /**
644          * An alias for ISO_C7.
645          */

646         public static final MediaType C7 = ISO_C7;
647         /**
648          * An alias for ISO_C7.
649          */

650         public static final MediaType ISO_C7_ENVELOPE = ISO_C7;
651         /**
652          * An alias for ISO_C8.
653          */

654         public static final MediaType C8 = ISO_C8;
655         /**
656          * An alias for ISO_C8.
657          */

658         public static final MediaType ISO_C8_ENVELOPE = ISO_C8;
659         /**
660          * An alias for ISO_C9.
661          */

662         public static final MediaType C9 = ISO_C9;
663         /**
664          * An alias for ISO_C9.
665          */

666         public static final MediaType ISO_C9_ENVELOPE = ISO_C9;
667         /**
668          * An alias for ISO_C10.
669          */

670         public static final MediaType C10 = ISO_C10;
671         /**
672          * An alias for ISO_C10.
673          */

674         public static final MediaType ISO_C10_ENVELOPE = ISO_C10;
675         /**
676          * An alias for ISO_DESIGNATED_LONG.
677          */

678         public static final MediaType ISO_DESIGNATED_LONG_ENVELOPE =
679                 ISO_DESIGNATED_LONG;
680         /**
681          * An alias for INVOICE.
682          */

683         public static final MediaType STATEMENT = INVOICE;
684         /**
685          * An alias for LEDGER.
686          */

687         public static final MediaType TABLOID = LEDGER;
688         /**
689          * An alias for NA_LETTER.
690          */

691         public static final MediaType LETTER = NA_LETTER;
692         /**
693          * An alias for NA_LETTER.
694          */

695         public static final MediaType NOTE = NA_LETTER;
696         /**
697          * An alias for NA_LEGAL.
698          */

699         public static final MediaType LEGAL = NA_LEGAL;
700         /**
701          * An alias for NA_10X15_ENVELOPE.
702          */

703         public static final MediaType ENV_10X15 = NA_10X15_ENVELOPE;
704         /**
705          * An alias for NA_10X14_ENVELOPE.
706          */

707         public static final MediaType ENV_10X14 = NA_10X14_ENVELOPE;
708         /**
709          * An alias for NA_10X13_ENVELOPE.
710          */

711         public static final MediaType ENV_10X13 = NA_10X13_ENVELOPE;
712         /**
713          * An alias for NA_9X12_ENVELOPE.
714          */

715         public static final MediaType ENV_9X12 = NA_9X12_ENVELOPE;
716         /**
717          * An alias for NA_9X11_ENVELOPE.
718          */

719         public static final MediaType ENV_9X11 = NA_9X11_ENVELOPE;
720         /**
721          * An alias for NA_7X9_ENVELOPE.
722          */

723         public static final MediaType ENV_7X9 = NA_7X9_ENVELOPE;
724         /**
725          * An alias for NA_6X9_ENVELOPE.
726          */

727         public static final MediaType ENV_6X9 = NA_6X9_ENVELOPE;
728         /**
729          * An alias for NA_NUMBER_9_ENVELOPE.
730          */

731         public static final MediaType ENV_9 = NA_NUMBER_9_ENVELOPE;
732         /**
733          * An alias for NA_NUMBER_10_ENVELOPE.
734          */

735         public static final MediaType ENV_10 = NA_NUMBER_10_ENVELOPE;
736         /**
737          * An alias for NA_NUMBER_11_ENVELOPE.
738          */

739         public static final MediaType ENV_11 = NA_NUMBER_11_ENVELOPE;
740         /**
741          * An alias for NA_NUMBER_12_ENVELOPE.
742          */

743         public static final MediaType ENV_12 = NA_NUMBER_12_ENVELOPE;
744         /**
745          * An alias for NA_NUMBER_14_ENVELOPE.
746          */

747         public static final MediaType ENV_14 = NA_NUMBER_14_ENVELOPE;
748         /**
749          * An alias for INVITE_ENVELOPE.
750          */

751         public static final MediaType ENV_INVITE = INVITE_ENVELOPE;
752         /**
753          * An alias for ITALY_ENVELOPE.
754          */

755         public static final MediaType ENV_ITALY = ITALY_ENVELOPE;
756         /**
757          * An alias for MONARCH_ENVELOPE.
758          */

759         public static final MediaType ENV_MONARCH = MONARCH_ENVELOPE;
760         /**
761          * An alias for PERSONAL_ENVELOPE.
762          */

763         public static final MediaType ENV_PERSONAL = PERSONAL_ENVELOPE;
764         /**
765          * An alias for INVITE_ENVELOPE.
766          */

767         public static final MediaType INVITE = INVITE_ENVELOPE;
768         /**
769          * An alias for ITALY_ENVELOPE.
770          */

771         public static final MediaType ITALY = ITALY_ENVELOPE;
772         /**
773          * An alias for MONARCH_ENVELOPE.
774          */

775         public static final MediaType MONARCH = MONARCH_ENVELOPE;
776         /**
777          * An alias for PERSONAL_ENVELOPE.
778          */

779         public static final MediaType PERSONAL = PERSONAL_ENVELOPE;
780
781         private MediaType(int type) {
782         super(type, NAMES);
783     }
784     }
785
786     /**
787      * A type-safe enumeration of possible orientations. These orientations
788      * are in partial compliance with IPP 1.1.
789      */

790     public static final class OrientationRequestedType extends AttributeValue JavaDoc {
791         private static final int I_PORTRAIT = 0;
792         private static final int I_LANDSCAPE = 1;
793
794         private static final String JavaDoc NAMES[] = {
795         "portrait", "landscape"
796     };
797
798         /**
799      * The OrientationRequestedType instance to use for specifying a
800      * portrait orientation.
801      */

802         public static final OrientationRequestedType PORTRAIT =
803             new OrientationRequestedType(I_PORTRAIT);
804         /**
805      * The OrientationRequestedType instance to use for specifying a
806      * landscape orientation.
807      */

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     /**
817      * A type-safe enumeration of possible origins.
818      */

819     public static final class OriginType extends AttributeValue JavaDoc {
820         private static final int I_PHYSICAL = 0;
821         private static final int I_PRINTABLE = 1;
822
823         private static final String JavaDoc NAMES[] = {
824         "physical", "printable"
825     };
826
827         /**
828      * The OriginType instance to use for specifying a physical origin.
829      */

830         public static final OriginType PHYSICAL = new OriginType(I_PHYSICAL);
831         /**
832      * The OriginType instance to use for specifying a printable origin.
833      */

834         public static final OriginType PRINTABLE = new OriginType(I_PRINTABLE);
835
836         private OriginType(int type) {
837         super(type, NAMES);
838     }
839     }
840
841     /**
842      * A type-safe enumeration of possible print qualities. These print
843      * qualities are in compliance with IPP 1.1.
844      */

845     public static final class PrintQualityType extends AttributeValue JavaDoc {
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 JavaDoc NAMES[] = {
851         "high", "normal", "draft"
852     };
853
854         /**
855      * The PrintQualityType instance to use for specifying a high print
856      * quality.
857      */

858         public static final PrintQualityType HIGH =
859         new PrintQualityType(I_HIGH);
860         /**
861      * The PrintQualityType instance to use for specifying a normal print
862      * quality.
863      */

864         public static final PrintQualityType NORMAL =
865             new PrintQualityType(I_NORMAL);
866         /**
867      * The PrintQualityType instance to use for specifying a draft print
868      * quality.
869      */

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     /**
886      * Constructs a PageAttributes instance with default values for every
887      * attribute.
888      */

889     public PageAttributes() {
890         setColor(ColorType.MONOCHROME);
891     setMediaToDefault();
892     setOrientationRequestedToDefault();
893     setOrigin(OriginType.PHYSICAL);
894     setPrintQualityToDefault();
895     setPrinterResolutionToDefault();
896     }
897
898     /**
899      * Constructs a PageAttributes instance which is a copy of the supplied
900      * PageAttributes.
901      *
902      * @param obj the PageAttributes to copy.
903      */

904     public PageAttributes(PageAttributes JavaDoc obj) {
905         set(obj);
906     }
907
908     /**
909      * Constructs a PageAttributes instance with the specified values for
910      * every attribute.
911      *
912      * @param color ColorType.COLOR or ColorType.MONOCHROME.
913      * @param media one of the constant fields of the MediaType class.
914      * @param orientationRequested OrientationRequestedType.PORTRAIT or
915      * OrientationRequestedType.LANDSCAPE.
916      * @param origin OriginType.PHYSICAL or OriginType.PRINTABLE
917      * @param printQuality PrintQualityType.DRAFT, PrintQualityType.NORMAL,
918      * or PrintQualityType.HIGH
919      * @param printerResolution an integer array of 3 elements. The first
920      * element must be greater than 0. The second element must be
921      * must be greater than 0. The third element must be either
922      * <code>3</code> or <code>4</code>.
923      * @throws IllegalArgumentException if one or more of the above
924      * conditions is violated.
925      */

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     /**
939      * Creates and returns a copy of this PageAttributes.
940      *
941      * @return the newly created copy. It is safe to cast this Object into
942      * a PageAttributes.
943      */

944     public Object JavaDoc clone() {
945         try {
946         return super.clone();
947     } catch (CloneNotSupportedException JavaDoc e) {
948         // Since we implement Cloneable, this should never happen
949
throw new InternalError JavaDoc();
950     }
951     }
952
953     /**
954      * Sets all of the attributes of this PageAttributes to the same values as
955      * the attributes of obj.
956      *
957      * @param obj the PageAttributes to copy.
958      */

959     public void set(PageAttributes JavaDoc obj) {
960         color = obj.color;
961     media = obj.media;
962     orientationRequested = obj.orientationRequested;
963     origin = obj.origin;
964     printQuality = obj.printQuality;
965     // okay because we never modify the contents of printerResolution
966
printerResolution = obj.printerResolution;
967     }
968
969     /**
970      * Returns whether pages using these attributes will be rendered in
971      * color or monochrome. This attribute is updated to the value chosen
972      * by the user.
973      *
974      * @return ColorType.COLOR or ColorType.MONOCHROME.
975      */

976     public ColorType getColor() {
977         return color;
978     }
979
980     /**
981      * Specifies whether pages using these attributes will be rendered in
982      * color or monochrome. Not specifying this attribute is equivalent to
983      * specifying ColorType.MONOCHROME.
984      *
985      * @param color ColorType.COLOR or ColorType.MONOCHROME.
986      * @throws IllegalArgumentException if color is null.
987      */

988     public void setColor(ColorType color) {
989         if (color == null) {
990         throw new IllegalArgumentException JavaDoc("Invalid value for attribute "+
991                            "color");
992     }
993         this.color = color;
994     }
995
996     /**
997      * Returns the paper size for pages using these attributes. This
998      * attribute is updated to the value chosen by the user.
999      *
1000     * @return one of the constant fields of the MediaType class.
1001     */

1002    public MediaType getMedia() {
1003        return media;
1004    }
1005
1006    /**
1007     * Specifies the desired paper size for pages using these attributes. The
1008     * actual paper size will be determined by the limitations of the target
1009     * printer. If an exact match cannot be found, an implementation will
1010     * choose the closest possible match. Not specifying this attribute is
1011     * equivalent to specifying the default size for the default locale. The
1012     * default size for locales in the United States and Canada is
1013     * MediaType.NA_LETTER. The default size for all other locales is
1014     * MediaType.ISO_A4.
1015     *
1016     * @param media one of the constant fields of the MediaType class.
1017     * @throws IllegalArgumentException if media is null.
1018     */

1019    public void setMedia(MediaType media) {
1020        if (media == null) {
1021        throw new IllegalArgumentException JavaDoc("Invalid value for attribute "+
1022                           "media");
1023    }
1024        this.media = media;
1025    }
1026
1027    /**
1028     * Sets the paper size for pages using these attributes to the default
1029     * size for the default locale. The default size for locales in the
1030     * United States and Canada is MediaType.NA_LETTER. The default size for
1031     * all other locales is MediaType.ISO_A4.
1032     */

1033    public void setMediaToDefault(){
1034    String JavaDoc 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    /**
1045     * Returns the print orientation for pages using these attributes. This
1046     * attribute is updated to the value chosen by the user.
1047     *
1048     * @return OrientationRequestedType.PORTRAIT or
1049     * OrientationRequestedType.LANDSCAPE.
1050     */

1051    public OrientationRequestedType getOrientationRequested() {
1052        return orientationRequested;
1053    }
1054
1055    /**
1056     * Specifies the print orientation for pages using these attributes. Not
1057     * specifying the property is equivalent to specifying
1058     * OrientationRequestedType.PORTRAIT.
1059     *
1060     * @param orientationRequested OrientationRequestedType.PORTRAIT or
1061     * OrientationRequestedType.LANDSCAPE.
1062     * @throws IllegalArgumentException if orientationRequested is null.
1063     */

1064    public void setOrientationRequested(OrientationRequestedType
1065                    orientationRequested) {
1066        if (orientationRequested == null) {
1067        throw new IllegalArgumentException JavaDoc("Invalid value for attribute "+
1068                           "orientationRequested");
1069    }
1070        this.orientationRequested = orientationRequested;
1071    }
1072
1073    /**
1074     * Specifies the print orientation for pages using these attributes.
1075     * Specifying <code>3</code> denotes portrait. Specifying <code>4</code>
1076     * denotes landscape. Specifying any other value will generate an
1077     * IllegalArgumentException. Not specifying the property is equivalent
1078     * to calling setOrientationRequested(OrientationRequestedType.PORTRAIT).
1079     *
1080     * @param orientationRequested <code>3</code> or <code>4</code>
1081     * @throws IllegalArgumentException if orientationRequested is not
1082     * <code>3</code> or <code>4</code>
1083     */

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        // This will throw an IllegalArgumentException
1094
setOrientationRequested(null);
1095        break;
1096    }
1097    }
1098
1099    /**
1100     * Sets the print orientation for pages using these attributes to the
1101     * default. The default orientation is portrait.
1102     */

1103    public void setOrientationRequestedToDefault() {
1104        setOrientationRequested(OrientationRequestedType.PORTRAIT);
1105    }
1106
1107    /**
1108     * Returns whether drawing at (0, 0) to pages using these attributes
1109     * draws at the upper-left corner of the physical page, or at the
1110     * upper-left corner of the printable area. (Note that these locations
1111     * could be equivalent.) This attribute cannot be modified by,
1112     * and is not subject to any limitations of, the implementation or the
1113     * target printer.
1114     *
1115     * @return OriginType.PHYSICAL or OriginType.PRINTABLE
1116     */

1117    public OriginType getOrigin() {
1118        return origin;
1119    }
1120
1121    /**
1122     * Specifies whether drawing at (0, 0) to pages using these attributes
1123     * draws at the upper-left corner of the physical page, or at the
1124     * upper-left corner of the printable area. (Note that these locations
1125     * could be equivalent.) Not specifying the property is equivalent to
1126     * specifying OriginType.PHYSICAL.
1127     *
1128     * @param origin OriginType.PHYSICAL or OriginType.PRINTABLE
1129     * @throws IllegalArgumentException if origin is null.
1130     */

1131    public void setOrigin(OriginType origin) {
1132        if (origin == null) {
1133        throw new IllegalArgumentException JavaDoc("Invalid value for attribute "+
1134                           "origin");
1135    }
1136        this.origin = origin;
1137    }
1138
1139    /**
1140     * Returns the print quality for pages using these attributes. This
1141     * attribute is updated to the value chosen by the user.
1142     *
1143     * @return PrintQualityType.DRAFT, PrintQualityType.NORMAL, or
1144     * PrintQualityType.HIGH
1145     */

1146    public PrintQualityType getPrintQuality() {
1147        return printQuality;
1148    }
1149
1150    /**
1151     * Specifies the print quality for pages using these attributes. Not
1152     * specifying the property is equivalent to specifying
1153     * PrintQualityType.NORMAL.
1154     *
1155     * @param printQuality PrintQualityType.DRAFT, PrintQualityType.NORMAL,
1156     * or PrintQualityType.HIGH
1157     * @throws IllegalArgumentException if printQuality is null.
1158     */

1159    public void setPrintQuality(PrintQualityType printQuality) {
1160        if (printQuality == null) {
1161        throw new IllegalArgumentException JavaDoc("Invalid value for attribute "+
1162                           "printQuality");
1163    }
1164        this.printQuality = printQuality;
1165    }
1166
1167    /**
1168     * Specifies the print quality for pages using these attributes.
1169     * Specifying <code>3</code> denotes draft. Specifying <code>4</code>
1170     * denotes normal. Specifying <code>5</code> denotes high. Specifying
1171     * any other value will generate an IllegalArgumentException. Not
1172     * specifying the property is equivalent to calling
1173     * setPrintQuality(PrintQualityType.NORMAL).
1174     *
1175     * @param printQuality <code>3</code>, <code>4</code>, or <code>5</code>
1176     * @throws IllegalArgumentException if printQuality is not <code>3
1177     * </code>, <code>4</code>, or <code>5</code>
1178     */

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        // This will throw an IllegalArgumentException
1192
setPrintQuality(null);
1193        break;
1194    }
1195    }
1196
1197    /**
1198     * Sets the print quality for pages using these attributes to the default.
1199     * The default print quality is normal.
1200     */

1201    public void setPrintQualityToDefault() {
1202        setPrintQuality(PrintQualityType.NORMAL);
1203    }
1204
1205    /**
1206     * Returns the print resolution for pages using these attributes.
1207     * Index 0 of the array specifies the cross feed direction resolution
1208     * (typically the horizontal resolution). Index 1 of the array specifies
1209     * the feed direction resolution (typically the vertical resolution).
1210     * Index 2 of the array specifies whether the resolutions are in dots per
1211     * inch or dots per centimeter. <code>3</code> denotes dots per inch.
1212     * <code>4</code> denotes dots per centimeter.
1213     *
1214     * @return an integer array of 3 elements. The first
1215     * element must be greater than 0. The second element must be
1216     * must be greater than 0. The third element must be either
1217     * <code>3</code> or <code>4</code>.
1218     */

1219    public int[] getPrinterResolution() {
1220        // Return a copy because otherwise client code could circumvent the
1221
// the checks made in setPrinterResolution by modifying the
1222
// returned array.
1223
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    /**
1231     * Specifies the desired print resolution for pages using these attributes.
1232     * The actual resolution will be determined by the limitations of the
1233     * implementation and the target printer. Index 0 of the array specifies
1234     * the cross feed direction resolution (typically the horizontal
1235     * resolution). Index 1 of the array specifies the feed direction
1236     * resolution (typically the vertical resolution). Index 2 of the array
1237     * specifies whether the resolutions are in dots per inch or dots per
1238     * centimeter. <code>3</code> denotes dots per inch. <code>4</code>
1239     * denotes dots per centimeter. Note that the 1.1 printing implementation
1240     * (Toolkit.getPrintJob) requires that the feed and cross feed resolutions
1241     * be the same. Not specifying the property is equivalent to calling
1242     * setPrinterResolution(72).
1243     *
1244     * @param printerResolution an integer array of 3 elements. The first
1245     * element must be greater than 0. The second element must be
1246     * must be greater than 0. The third element must be either
1247     * <code>3</code> or <code>4</code>.
1248     * @throws IllegalArgumentException if one or more of the above
1249     * conditions is violated.
1250     */

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 JavaDoc("Invalid value for attribute "+
1258                           "printerResolution");
1259    }
1260        // Store a copy because otherwise client code could circumvent the
1261
// the checks made above by holding a reference to the array and
1262
// modifying it after calling setPrinterResolution.
1263
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    /**
1271     * Specifies the desired cross feed and feed print resolutions in dots per
1272     * inch for pages using these attributes. The same value is used for both
1273     * resolutions. The actual resolutions will be determined by the
1274     * limitations of the implementation and the target printer. Not
1275     * specifying the property is equivalent to specifying <code>72</code>.
1276     *
1277     * @param printerResolution an integer greater than 0.
1278     * @throws IllegalArgumentException if printerResolution is less than or
1279     * equal to 0.
1280     */

1281    public void setPrinterResolution(int printerResolution) {
1282        setPrinterResolution(new int[] { printerResolution, printerResolution,
1283                     3 } );
1284    }
1285
1286    /**
1287     * Sets the printer resolution for pages using these attributes to the
1288     * default. The default is 72 dpi for both the feed and cross feed
1289     * resolutions.
1290     */

1291    public void setPrinterResolutionToDefault() {
1292        setPrinterResolution(72);
1293    }
1294
1295    /**
1296     * Determines whether two PageAttributes are equal to each other.
1297     * <p>
1298     * Two PageAttributes are equal if and only if each of their attributes are
1299     * equal. Attributes of enumeration type are equal if and only if the
1300     * fields refer to the same unique enumeration object. This means that
1301     * an aliased media is equal to its underlying unique media. Printer
1302     * resolutions are equal if and only if the feed resolution, cross feed
1303     * resolution, and units are equal.
1304     *
1305     * @param obj the object whose equality will be checked.
1306     * @return whether obj is equal to this PageAttribute according to the
1307     * above criteria.
1308     */

1309    public boolean equals(Object JavaDoc obj) {
1310        if (!(obj instanceof PageAttributes JavaDoc)) {
1311        return false;
1312    }
1313
1314    PageAttributes JavaDoc rhs = (PageAttributes JavaDoc)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    /**
1327     * Returns a hash code value for this PageAttributes.
1328     *
1329     * @return the hash code.
1330     */

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    /**
1343     * Returns a string representation of this PageAttributes.
1344     *
1345     * @return the string representation.
1346     */

1347    public String JavaDoc toString() {
1348        // int[] printerResolution = getPrinterResolution();
1349
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