blob: da8efe6233c7e550ab6229c5cdce5ce5204b62b0 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 1999-2006 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26package java.awt;
27
28import java.util.Locale;
29
30/**
31 * A set of attributes which control the output of a printed page.
32 * <p>
33 * Instances of this class control the color state, paper size (media type),
34 * orientation, logical origin, print quality, and resolution of every
35 * page which uses the instance. Attribute names are compliant with the
36 * Internet Printing Protocol (IPP) 1.1 where possible. Attribute values
37 * are partially compliant where possible.
38 * <p>
39 * To use a method which takes an inner class type, pass a reference to
40 * one of the constant fields of the inner class. Client code cannot create
41 * new instances of the inner class types because none of those classes
42 * has a public constructor. For example, to set the color state to
43 * monochrome, use the following code:
44 * <pre>
45 * import java.awt.PageAttributes;
46 *
47 * public class MonochromeExample {
48 * public void setMonochrome(PageAttributes pageAttributes) {
49 * pageAttributes.setColor(PageAttributes.ColorType.MONOCHROME);
50 * }
51 * }
52 * </pre>
53 * <p>
54 * Every IPP attribute which supports an <i>attributeName</i>-default value
55 * has a corresponding <code>set<i>attributeName</i>ToDefault</code> method.
56 * Default value fields are not provided.
57 *
58 * @author David Mendenhall
59 * @since 1.3
60 */
61public final class PageAttributes implements Cloneable {
62 /**
63 * A type-safe enumeration of possible color states.
64 * @since 1.3
65 */
66 public static final class ColorType extends AttributeValue {
67 private static final int I_COLOR = 0;
68 private static final int I_MONOCHROME = 1;
69
70 private static final String NAMES[] = {
71 "color", "monochrome"
72 };
73
74 /**
75 * The ColorType instance to use for specifying color printing.
76 */
77 public static final ColorType COLOR = new ColorType(I_COLOR);
78 /**
79 * The ColorType instance to use for specifying monochrome printing.
80 */
81 public static final ColorType MONOCHROME = new ColorType(I_MONOCHROME);
82
83 private ColorType(int type) {
84 super(type, NAMES);
85 }
86 }
87
88 /**
89 * A type-safe enumeration of possible paper sizes. These sizes are in
90 * compliance with IPP 1.1.
91 * @since 1.3
92 */
93 public static final class MediaType extends AttributeValue {
94 private static final int I_ISO_4A0 = 0;
95 private static final int I_ISO_2A0 = 1;
96 private static final int I_ISO_A0 = 2;
97 private static final int I_ISO_A1 = 3;
98 private static final int I_ISO_A2 = 4;
99 private static final int I_ISO_A3 = 5;
100 private static final int I_ISO_A4 = 6;
101 private static final int I_ISO_A5 = 7;
102 private static final int I_ISO_A6 = 8;
103 private static final int I_ISO_A7 = 9;
104 private static final int I_ISO_A8 = 10;
105 private static final int I_ISO_A9 = 11;
106 private static final int I_ISO_A10 = 12;
107 private static final int I_ISO_B0 = 13;
108 private static final int I_ISO_B1 = 14;
109 private static final int I_ISO_B2 = 15;
110 private static final int I_ISO_B3 = 16;
111 private static final int I_ISO_B4 = 17;
112 private static final int I_ISO_B5 = 18;
113 private static final int I_ISO_B6 = 19;
114 private static final int I_ISO_B7 = 20;
115 private static final int I_ISO_B8 = 21;
116 private static final int I_ISO_B9 = 22;
117 private static final int I_ISO_B10 = 23;
118 private static final int I_JIS_B0 = 24;
119 private static final int I_JIS_B1 = 25;
120 private static final int I_JIS_B2 = 26;
121 private static final int I_JIS_B3 = 27;
122 private static final int I_JIS_B4 = 28;
123 private static final int I_JIS_B5 = 29;
124 private static final int I_JIS_B6 = 30;
125 private static final int I_JIS_B7 = 31;
126 private static final int I_JIS_B8 = 32;
127 private static final int I_JIS_B9 = 33;
128 private static final int I_JIS_B10 = 34;
129 private static final int I_ISO_C0 = 35;
130 private static final int I_ISO_C1 = 36;
131 private static final int I_ISO_C2 = 37;
132 private static final int I_ISO_C3 = 38;
133 private static final int I_ISO_C4 = 39;
134 private static final int I_ISO_C5 = 40;
135 private static final int I_ISO_C6 = 41;
136 private static final int I_ISO_C7 = 42;
137 private static final int I_ISO_C8 = 43;
138 private static final int I_ISO_C9 = 44;
139 private static final int I_ISO_C10 = 45;
140 private static final int I_ISO_DESIGNATED_LONG = 46;
141 private static final int I_EXECUTIVE = 47;
142 private static final int I_FOLIO = 48;
143 private static final int I_INVOICE = 49;
144 private static final int I_LEDGER = 50;
145 private static final int I_NA_LETTER = 51;
146 private static final int I_NA_LEGAL = 52;
147 private static final int I_QUARTO = 53;
148 private static final int I_A = 54;
149 private static final int I_B = 55;
150 private static final int I_C = 56;
151 private static final int I_D = 57;
152 private static final int I_E = 58;
153 private static final int I_NA_10X15_ENVELOPE = 59;
154 private static final int I_NA_10X14_ENVELOPE = 60;
155 private static final int I_NA_10X13_ENVELOPE = 61;
156 private static final int I_NA_9X12_ENVELOPE = 62;
157 private static final int I_NA_9X11_ENVELOPE = 63;
158 private static final int I_NA_7X9_ENVELOPE = 64;
159 private static final int I_NA_6X9_ENVELOPE = 65;
160 private static final int I_NA_NUMBER_9_ENVELOPE = 66;
161 private static final int I_NA_NUMBER_10_ENVELOPE = 67;
162 private static final int I_NA_NUMBER_11_ENVELOPE = 68;
163 private static final int I_NA_NUMBER_12_ENVELOPE = 69;
164 private static final int I_NA_NUMBER_14_ENVELOPE = 70;
165 private static final int I_INVITE_ENVELOPE = 71;
166 private static final int I_ITALY_ENVELOPE = 72;
167 private static final int I_MONARCH_ENVELOPE = 73;
168 private static final int I_PERSONAL_ENVELOPE = 74;
169
170 private static final String NAMES[] = {
171 "iso-4a0", "iso-2a0", "iso-a0", "iso-a1", "iso-a2", "iso-a3",
172 "iso-a4", "iso-a5", "iso-a6", "iso-a7", "iso-a8", "iso-a9",
173 "iso-a10", "iso-b0", "iso-b1", "iso-b2", "iso-b3", "iso-b4",
174 "iso-b5", "iso-b6", "iso-b7", "iso-b8", "iso-b9", "iso-b10",
175 "jis-b0", "jis-b1", "jis-b2", "jis-b3", "jis-b4", "jis-b5",
176 "jis-b6", "jis-b7", "jis-b8", "jis-b9", "jis-b10", "iso-c0",
177 "iso-c1", "iso-c2", "iso-c3", "iso-c4", "iso-c5", "iso-c6",
178 "iso-c7", "iso-c8", "iso-c9", "iso-c10", "iso-designated-long",
179 "executive", "folio", "invoice", "ledger", "na-letter", "na-legal",
180 "quarto", "a", "b", "c", "d", "e", "na-10x15-envelope",
181 "na-10x14-envelope", "na-10x13-envelope", "na-9x12-envelope",
182 "na-9x11-envelope", "na-7x9-envelope", "na-6x9-envelope",
183 "na-number-9-envelope", "na-number-10-envelope",
184 "na-number-11-envelope", "na-number-12-envelope",
185 "na-number-14-envelope", "invite-envelope", "italy-envelope",
186 "monarch-envelope", "personal-envelope"
187 };
188
189 /**
190 * The MediaType instance for ISO/DIN & JIS 4A0, 1682 x 2378 mm.
191 */
192 public static final MediaType ISO_4A0 = new MediaType(I_ISO_4A0);
193 /**
194 * The MediaType instance for ISO/DIN & JIS 2A0, 1189 x 1682 mm.
195 */
196 public static final MediaType ISO_2A0 = new MediaType(I_ISO_2A0);
197 /**
198 * The MediaType instance for ISO/DIN & JIS A0, 841 x 1189 mm.
199 */
200 public static final MediaType ISO_A0 = new MediaType(I_ISO_A0);
201 /**
202 * The MediaType instance for ISO/DIN & JIS A1, 594 x 841 mm.
203 */
204 public static final MediaType ISO_A1 = new MediaType(I_ISO_A1);
205 /**
206 * The MediaType instance for ISO/DIN & JIS A2, 420 x 594 mm.
207 */
208 public static final MediaType ISO_A2 = new MediaType(I_ISO_A2);
209 /**
210 * The MediaType instance for ISO/DIN & JIS A3, 297 x 420 mm.
211 */
212 public static final MediaType ISO_A3 = new MediaType(I_ISO_A3);
213 /**
214 * The MediaType instance for ISO/DIN & JIS A4, 210 x 297 mm.
215 */
216 public static final MediaType ISO_A4 = new MediaType(I_ISO_A4);
217 /**
218 * The MediaType instance for ISO/DIN & JIS A5, 148 x 210 mm.
219 */
220 public static final MediaType ISO_A5 = new MediaType(I_ISO_A5);
221 /**
222 * The MediaType instance for ISO/DIN & JIS A6, 105 x 148 mm.
223 */
224 public static final MediaType ISO_A6 = new MediaType(I_ISO_A6);
225 /**
226 * The MediaType instance for ISO/DIN & JIS A7, 74 x 105 mm.
227 */
228 public static final MediaType ISO_A7 = new MediaType(I_ISO_A7);
229 /**
230 * The MediaType instance for ISO/DIN & JIS A8, 52 x 74 mm.
231 */
232 public static final MediaType ISO_A8 = new MediaType(I_ISO_A8);
233 /**
234 * The MediaType instance for ISO/DIN & JIS A9, 37 x 52 mm.
235 */
236 public static final MediaType ISO_A9 = new MediaType(I_ISO_A9);
237 /**
238 * The MediaType instance for ISO/DIN & JIS A10, 26 x 37 mm.
239 */
240 public static final MediaType ISO_A10 = new MediaType(I_ISO_A10);
241 /**
242 * The MediaType instance for ISO/DIN B0, 1000 x 1414 mm.
243 */
244 public static final MediaType ISO_B0 = new MediaType(I_ISO_B0);
245 /**
246 * The MediaType instance for ISO/DIN B1, 707 x 1000 mm.
247 */
248 public static final MediaType ISO_B1 = new MediaType(I_ISO_B1);
249 /**
250 * The MediaType instance for ISO/DIN B2, 500 x 707 mm.
251 */
252 public static final MediaType ISO_B2 = new MediaType(I_ISO_B2);
253 /**
254 * The MediaType instance for ISO/DIN B3, 353 x 500 mm.
255 */
256 public static final MediaType ISO_B3 = new MediaType(I_ISO_B3);
257 /**
258 * The MediaType instance for ISO/DIN B4, 250 x 353 mm.
259 */
260 public static final MediaType ISO_B4 = new MediaType(I_ISO_B4);
261 /**
262 * The MediaType instance for ISO/DIN B5, 176 x 250 mm.
263 */
264 public static final MediaType ISO_B5 = new MediaType(I_ISO_B5);
265 /**
266 * The MediaType instance for ISO/DIN B6, 125 x 176 mm.
267 */
268 public static final MediaType ISO_B6 = new MediaType(I_ISO_B6);
269 /**
270 * The MediaType instance for ISO/DIN B7, 88 x 125 mm.
271 */
272 public static final MediaType ISO_B7 = new MediaType(I_ISO_B7);
273 /**
274 * The MediaType instance for ISO/DIN B8, 62 x 88 mm.
275 */
276 public static final MediaType ISO_B8 = new MediaType(I_ISO_B8);
277 /**
278 * The MediaType instance for ISO/DIN B9, 44 x 62 mm.
279 */
280 public static final MediaType ISO_B9 = new MediaType(I_ISO_B9);
281 /**
282 * The MediaType instance for ISO/DIN B10, 31 x 44 mm.
283 */
284 public static final MediaType ISO_B10 = new MediaType(I_ISO_B10);
285 /**
286 * The MediaType instance for JIS B0, 1030 x 1456 mm.
287 */
288 public static final MediaType JIS_B0 = new MediaType(I_JIS_B0);
289 /**
290 * The MediaType instance for JIS B1, 728 x 1030 mm.
291 */
292 public static final MediaType JIS_B1 = new MediaType(I_JIS_B1);
293 /**
294 * The MediaType instance for JIS B2, 515 x 728 mm.
295 */
296 public static final MediaType JIS_B2 = new MediaType(I_JIS_B2);
297 /**
298 * The MediaType instance for JIS B3, 364 x 515 mm.
299 */
300 public static final MediaType JIS_B3 = new MediaType(I_JIS_B3);
301 /**
302 * The MediaType instance for JIS B4, 257 x 364 mm.
303 */
304 public static final MediaType JIS_B4 = new MediaType(I_JIS_B4);
305 /**
306 * The MediaType instance for JIS B5, 182 x 257 mm.
307 */
308 public static final MediaType JIS_B5 = new MediaType(I_JIS_B5);
309 /**
310 * The MediaType instance for JIS B6, 128 x 182 mm.
311 */
312 public static final MediaType JIS_B6 = new MediaType(I_JIS_B6);
313 /**
314 * The MediaType instance for JIS B7, 91 x 128 mm.
315 */
316 public static final MediaType JIS_B7 = new MediaType(I_JIS_B7);
317 /**
318 * The MediaType instance for JIS B8, 64 x 91 mm.
319 */
320 public static final MediaType JIS_B8 = new MediaType(I_JIS_B8);
321 /**
322 * The MediaType instance for JIS B9, 45 x 64 mm.
323 */
324 public static final MediaType JIS_B9 = new MediaType(I_JIS_B9);
325 /**
326 * The MediaType instance for JIS B10, 32 x 45 mm.
327 */
328 public static final MediaType JIS_B10 = new MediaType(I_JIS_B10);
329 /**
330 * The MediaType instance for ISO/DIN C0, 917 x 1297 mm.
331 */
332 public static final MediaType ISO_C0 = new MediaType(I_ISO_C0);
333 /**
334 * The MediaType instance for ISO/DIN C1, 648 x 917 mm.
335 */
336 public static final MediaType ISO_C1 = new MediaType(I_ISO_C1);
337 /**
338 * The MediaType instance for ISO/DIN C2, 458 x 648 mm.
339 */
340 public static final MediaType ISO_C2 = new MediaType(I_ISO_C2);
341 /**
342 * The MediaType instance for ISO/DIN C3, 324 x 458 mm.
343 */
344 public static final MediaType ISO_C3 = new MediaType(I_ISO_C3);
345 /**
346 * The MediaType instance for ISO/DIN C4, 229 x 324 mm.
347 */
348 public static final MediaType ISO_C4 = new MediaType(I_ISO_C4);
349 /**
350 * The MediaType instance for ISO/DIN C5, 162 x 229 mm.
351 */
352 public static final MediaType ISO_C5 = new MediaType(I_ISO_C5);
353 /**
354 * The MediaType instance for ISO/DIN C6, 114 x 162 mm.
355 */
356 public static final MediaType ISO_C6 = new MediaType(I_ISO_C6);
357 /**
358 * The MediaType instance for ISO/DIN C7, 81 x 114 mm.
359 */
360 public static final MediaType ISO_C7 = new MediaType(I_ISO_C7);
361 /**
362 * The MediaType instance for ISO/DIN C8, 57 x 81 mm.
363 */
364 public static final MediaType ISO_C8 = new MediaType(I_ISO_C8);
365 /**
366 * The MediaType instance for ISO/DIN C9, 40 x 57 mm.
367 */
368 public static final MediaType ISO_C9 = new MediaType(I_ISO_C9);
369 /**
370 * The MediaType instance for ISO/DIN C10, 28 x 40 mm.
371 */
372 public static final MediaType ISO_C10 = new MediaType(I_ISO_C10);
373 /**
374 * The MediaType instance for ISO Designated Long, 110 x 220 mm.
375 */
376 public static final MediaType ISO_DESIGNATED_LONG =
377 new MediaType(I_ISO_DESIGNATED_LONG);
378 /**
379 * The MediaType instance for Executive, 7 1/4 x 10 1/2 in.
380 */
381 public static final MediaType EXECUTIVE = new MediaType(I_EXECUTIVE);
382 /**
383 * The MediaType instance for Folio, 8 1/2 x 13 in.
384 */
385 public static final MediaType FOLIO = new MediaType(I_FOLIO);
386 /**
387 * The MediaType instance for Invoice, 5 1/2 x 8 1/2 in.
388 */
389 public static final MediaType INVOICE = new MediaType(I_INVOICE);
390 /**
391 * The MediaType instance for Ledger, 11 x 17 in.
392 */
393 public static final MediaType LEDGER = new MediaType(I_LEDGER);
394 /**
395 * The MediaType instance for North American Letter, 8 1/2 x 11 in.
396 */
397 public static final MediaType NA_LETTER = new MediaType(I_NA_LETTER);
398 /**
399 * The MediaType instance for North American Legal, 8 1/2 x 14 in.
400 */
401 public static final MediaType NA_LEGAL = new MediaType(I_NA_LEGAL);
402 /**
403 * The MediaType instance for Quarto, 215 x 275 mm.
404 */
405 public static final MediaType QUARTO = new MediaType(I_QUARTO);
406 /**
407 * The MediaType instance for Engineering A, 8 1/2 x 11 in.
408 */
409 public static final MediaType A = new MediaType(I_A);
410 /**
411 * The MediaType instance for Engineering B, 11 x 17 in.
412 */
413 public static final MediaType B = new MediaType(I_B);
414 /**
415 * The MediaType instance for Engineering C, 17 x 22 in.
416 */
417 public static final MediaType C = new MediaType(I_C);
418 /**
419 * The MediaType instance for Engineering D, 22 x 34 in.
420 */
421 public static final MediaType D = new MediaType(I_D);
422 /**
423 * The MediaType instance for Engineering E, 34 x 44 in.
424 */
425 public static final MediaType E = new MediaType(I_E);
426 /**
427 * The MediaType instance for North American 10 x 15 in.
428 */
429 public static final MediaType NA_10X15_ENVELOPE =
430 new MediaType(I_NA_10X15_ENVELOPE);
431 /**
432 * The MediaType instance for North American 10 x 14 in.
433 */
434 public static final MediaType NA_10X14_ENVELOPE =
435 new MediaType(I_NA_10X14_ENVELOPE);
436 /**
437 * The MediaType instance for North American 10 x 13 in.
438 */
439 public static final MediaType NA_10X13_ENVELOPE =
440 new MediaType(I_NA_10X13_ENVELOPE);
441 /**
442 * The MediaType instance for North American 9 x 12 in.
443 */
444 public static final MediaType NA_9X12_ENVELOPE =
445 new MediaType(I_NA_9X12_ENVELOPE);
446 /**
447 * The MediaType instance for North American 9 x 11 in.
448 */
449 public static final MediaType NA_9X11_ENVELOPE =
450 new MediaType(I_NA_9X11_ENVELOPE);
451 /**
452 * The MediaType instance for North American 7 x 9 in.
453 */
454 public static final MediaType NA_7X9_ENVELOPE =
455 new MediaType(I_NA_7X9_ENVELOPE);
456 /**
457 * The MediaType instance for North American 6 x 9 in.
458 */
459 public static final MediaType NA_6X9_ENVELOPE =
460 new MediaType(I_NA_6X9_ENVELOPE);
461 /**
462 * The MediaType instance for North American #9 Business Envelope,
463 * 3 7/8 x 8 7/8 in.
464 */
465 public static final MediaType NA_NUMBER_9_ENVELOPE =
466 new MediaType(I_NA_NUMBER_9_ENVELOPE);
467 /**
468 * The MediaType instance for North American #10 Business Envelope,
469 * 4 1/8 x 9 1/2 in.
470 */
471 public static final MediaType NA_NUMBER_10_ENVELOPE =
472 new MediaType(I_NA_NUMBER_10_ENVELOPE);
473 /**
474 * The MediaType instance for North American #11 Business Envelope,
475 * 4 1/2 x 10 3/8 in.
476 */
477 public static final MediaType NA_NUMBER_11_ENVELOPE =
478 new MediaType(I_NA_NUMBER_11_ENVELOPE);
479 /**
480 * The MediaType instance for North American #12 Business Envelope,
481 * 4 3/4 x 11 in.
482 */
483 public static final MediaType NA_NUMBER_12_ENVELOPE =
484 new MediaType(I_NA_NUMBER_12_ENVELOPE);
485 /**
486 * The MediaType instance for North American #14 Business Envelope,
487 * 5 x 11 1/2 in.
488 */
489 public static final MediaType NA_NUMBER_14_ENVELOPE =
490 new MediaType(I_NA_NUMBER_14_ENVELOPE);
491 /**
492 * The MediaType instance for Invitation Envelope, 220 x 220 mm.
493 */
494 public static final MediaType INVITE_ENVELOPE =
495 new MediaType(I_INVITE_ENVELOPE);
496 /**
497 * The MediaType instance for Italy Envelope, 110 x 230 mm.
498 */
499 public static final MediaType ITALY_ENVELOPE =
500 new MediaType(I_ITALY_ENVELOPE);
501 /**
502 * The MediaType instance for Monarch Envelope, 3 7/8 x 7 1/2 in.
503 */
504 public static final MediaType MONARCH_ENVELOPE =
505 new MediaType(I_MONARCH_ENVELOPE);
506 /**
507 * The MediaType instance for 6 3/4 envelope, 3 5/8 x 6 1/2 in.
508 */
509 public static final MediaType PERSONAL_ENVELOPE =
510 new MediaType(I_PERSONAL_ENVELOPE);
511 /**
512 * An alias for ISO_A0.
513 */
514 public static final MediaType A0 = ISO_A0;
515 /**
516 * An alias for ISO_A1.
517 */
518 public static final MediaType A1 = ISO_A1;
519 /**
520 * An alias for ISO_A2.
521 */
522 public static final MediaType A2 = ISO_A2;
523 /**
524 * An alias for ISO_A3.
525 */
526 public static final MediaType A3 = ISO_A3;
527 /**
528 * An alias for ISO_A4.
529 */
530 public static final MediaType A4 = ISO_A4;
531 /**
532 * An alias for ISO_A5.
533 */
534 public static final MediaType A5 = ISO_A5;
535 /**
536 * An alias for ISO_A6.
537 */
538 public static final MediaType A6 = ISO_A6;
539 /**
540 * An alias for ISO_A7.
541 */
542 public static final MediaType A7 = ISO_A7;
543 /**
544 * An alias for ISO_A8.
545 */
546 public static final MediaType A8 = ISO_A8;
547 /**
548 * An alias for ISO_A9.
549 */
550 public static final MediaType A9 = ISO_A9;
551 /**
552 * An alias for ISO_A10.
553 */
554 public static final MediaType A10 = ISO_A10;
555 /**
556 * An alias for ISO_B0.
557 */
558 public static final MediaType B0 = ISO_B0;
559 /**
560 * An alias for ISO_B1.
561 */
562 public static final MediaType B1 = ISO_B1;
563 /**
564 * An alias for ISO_B2.
565 */
566 public static final MediaType B2 = ISO_B2;
567 /**
568 * An alias for ISO_B3.
569 */
570 public static final MediaType B3 = ISO_B3;
571 /**
572 * An alias for ISO_B4.
573 */
574 public static final MediaType B4 = ISO_B4;
575 /**
576 * An alias for ISO_B4.
577 */
578 public static final MediaType ISO_B4_ENVELOPE = ISO_B4;
579 /**
580 * An alias for ISO_B5.
581 */
582 public static final MediaType B5 = ISO_B5;
583 /**
584 * An alias for ISO_B5.
585 */
586 public static final MediaType ISO_B5_ENVELOPE = ISO_B5;
587 /**
588 * An alias for ISO_B6.
589 */
590 public static final MediaType B6 = ISO_B6;
591 /**
592 * An alias for ISO_B7.
593 */
594 public static final MediaType B7 = ISO_B7;
595 /**
596 * An alias for ISO_B8.
597 */
598 public static final MediaType B8 = ISO_B8;
599 /**
600 * An alias for ISO_B9.
601 */
602 public static final MediaType B9 = ISO_B9;
603 /**
604 * An alias for ISO_B10.
605 */
606 public static final MediaType B10 = ISO_B10;
607 /**
608 * An alias for ISO_C0.
609 */
610 public static final MediaType C0 = ISO_C0;
611 /**
612 * An alias for ISO_C0.
613 */
614 public static final MediaType ISO_C0_ENVELOPE = ISO_C0;
615 /**
616 * An alias for ISO_C1.
617 */
618 public static final MediaType C1 = ISO_C1;
619 /**
620 * An alias for ISO_C1.
621 */
622 public static final MediaType ISO_C1_ENVELOPE = ISO_C1;
623 /**
624 * An alias for ISO_C2.
625 */
626 public static final MediaType C2 = ISO_C2;
627 /**
628 * An alias for ISO_C2.
629 */
630 public static final MediaType ISO_C2_ENVELOPE = ISO_C2;
631 /**
632 * An alias for ISO_C3.
633 */
634 public static final MediaType C3 = ISO_C3;
635 /**
636 * An alias for ISO_C3.
637 */
638 public static final MediaType ISO_C3_ENVELOPE = ISO_C3;
639 /**
640 * An alias for ISO_C4.
641 */
642 public static final MediaType C4 = ISO_C4;
643 /**
644 * An alias for ISO_C4.
645 */
646 public static final MediaType ISO_C4_ENVELOPE = ISO_C4;
647 /**
648 * An alias for ISO_C5.
649 */
650 public static final MediaType C5 = ISO_C5;
651 /**
652 * An alias for ISO_C5.
653 */
654 public static final MediaType ISO_C5_ENVELOPE = ISO_C5;
655 /**
656 * An alias for ISO_C6.
657 */
658 public static final MediaType C6 = ISO_C6;
659 /**
660 * An alias for ISO_C6.
661 */
662 public static final MediaType ISO_C6_ENVELOPE = ISO_C6;
663 /**
664 * An alias for ISO_C7.
665 */
666 public static final MediaType C7 = ISO_C7;
667 /**
668 * An alias for ISO_C7.
669 */
670 public static final MediaType ISO_C7_ENVELOPE = ISO_C7;
671 /**
672 * An alias for ISO_C8.
673 */
674 public static final MediaType C8 = ISO_C8;
675 /**
676 * An alias for ISO_C8.
677 */
678 public static final MediaType ISO_C8_ENVELOPE = ISO_C8;
679 /**
680 * An alias for ISO_C9.
681 */
682 public static final MediaType C9 = ISO_C9;
683 /**
684 * An alias for ISO_C9.
685 */
686 public static final MediaType ISO_C9_ENVELOPE = ISO_C9;
687 /**
688 * An alias for ISO_C10.
689 */
690 public static final MediaType C10 = ISO_C10;
691 /**
692 * An alias for ISO_C10.
693 */
694 public static final MediaType ISO_C10_ENVELOPE = ISO_C10;
695 /**
696 * An alias for ISO_DESIGNATED_LONG.
697 */
698 public static final MediaType ISO_DESIGNATED_LONG_ENVELOPE =
699 ISO_DESIGNATED_LONG;
700 /**
701 * An alias for INVOICE.
702 */
703 public static final MediaType STATEMENT = INVOICE;
704 /**
705 * An alias for LEDGER.
706 */
707 public static final MediaType TABLOID = LEDGER;
708 /**
709 * An alias for NA_LETTER.
710 */
711 public static final MediaType LETTER = NA_LETTER;
712 /**
713 * An alias for NA_LETTER.
714 */
715 public static final MediaType NOTE = NA_LETTER;
716 /**
717 * An alias for NA_LEGAL.
718 */
719 public static final MediaType LEGAL = NA_LEGAL;
720 /**
721 * An alias for NA_10X15_ENVELOPE.
722 */
723 public static final MediaType ENV_10X15 = NA_10X15_ENVELOPE;
724 /**
725 * An alias for NA_10X14_ENVELOPE.
726 */
727 public static final MediaType ENV_10X14 = NA_10X14_ENVELOPE;
728 /**
729 * An alias for NA_10X13_ENVELOPE.
730 */
731 public static final MediaType ENV_10X13 = NA_10X13_ENVELOPE;
732 /**
733 * An alias for NA_9X12_ENVELOPE.
734 */
735 public static final MediaType ENV_9X12 = NA_9X12_ENVELOPE;
736 /**
737 * An alias for NA_9X11_ENVELOPE.
738 */
739 public static final MediaType ENV_9X11 = NA_9X11_ENVELOPE;
740 /**
741 * An alias for NA_7X9_ENVELOPE.
742 */
743 public static final MediaType ENV_7X9 = NA_7X9_ENVELOPE;
744 /**
745 * An alias for NA_6X9_ENVELOPE.
746 */
747 public static final MediaType ENV_6X9 = NA_6X9_ENVELOPE;
748 /**
749 * An alias for NA_NUMBER_9_ENVELOPE.
750 */
751 public static final MediaType ENV_9 = NA_NUMBER_9_ENVELOPE;
752 /**
753 * An alias for NA_NUMBER_10_ENVELOPE.
754 */
755 public static final MediaType ENV_10 = NA_NUMBER_10_ENVELOPE;
756 /**
757 * An alias for NA_NUMBER_11_ENVELOPE.
758 */
759 public static final MediaType ENV_11 = NA_NUMBER_11_ENVELOPE;
760 /**
761 * An alias for NA_NUMBER_12_ENVELOPE.
762 */
763 public static final MediaType ENV_12 = NA_NUMBER_12_ENVELOPE;
764 /**
765 * An alias for NA_NUMBER_14_ENVELOPE.
766 */
767 public static final MediaType ENV_14 = NA_NUMBER_14_ENVELOPE;
768 /**
769 * An alias for INVITE_ENVELOPE.
770 */
771 public static final MediaType ENV_INVITE = INVITE_ENVELOPE;
772 /**
773 * An alias for ITALY_ENVELOPE.
774 */
775 public static final MediaType ENV_ITALY = ITALY_ENVELOPE;
776 /**
777 * An alias for MONARCH_ENVELOPE.
778 */
779 public static final MediaType ENV_MONARCH = MONARCH_ENVELOPE;
780 /**
781 * An alias for PERSONAL_ENVELOPE.
782 */
783 public static final MediaType ENV_PERSONAL = PERSONAL_ENVELOPE;
784 /**
785 * An alias for INVITE_ENVELOPE.
786 */
787 public static final MediaType INVITE = INVITE_ENVELOPE;
788 /**
789 * An alias for ITALY_ENVELOPE.
790 */
791 public static final MediaType ITALY = ITALY_ENVELOPE;
792 /**
793 * An alias for MONARCH_ENVELOPE.
794 */
795 public static final MediaType MONARCH = MONARCH_ENVELOPE;
796 /**
797 * An alias for PERSONAL_ENVELOPE.
798 */
799 public static final MediaType PERSONAL = PERSONAL_ENVELOPE;
800
801 private MediaType(int type) {
802 super(type, NAMES);
803 }
804 }
805
806 /**
807 * A type-safe enumeration of possible orientations. These orientations
808 * are in partial compliance with IPP 1.1.
809 * @since 1.3
810 */
811 public static final class OrientationRequestedType extends AttributeValue {
812 private static final int I_PORTRAIT = 0;
813 private static final int I_LANDSCAPE = 1;
814
815 private static final String NAMES[] = {
816 "portrait", "landscape"
817 };
818
819 /**
820 * The OrientationRequestedType instance to use for specifying a
821 * portrait orientation.
822 */
823 public static final OrientationRequestedType PORTRAIT =
824 new OrientationRequestedType(I_PORTRAIT);
825 /**
826 * The OrientationRequestedType instance to use for specifying a
827 * landscape orientation.
828 */
829 public static final OrientationRequestedType LANDSCAPE =
830 new OrientationRequestedType(I_LANDSCAPE);
831
832 private OrientationRequestedType(int type) {
833 super(type, NAMES);
834 }
835 }
836
837 /**
838 * A type-safe enumeration of possible origins.
839 * @since 1.3
840 */
841 public static final class OriginType extends AttributeValue {
842 private static final int I_PHYSICAL = 0;
843 private static final int I_PRINTABLE = 1;
844
845 private static final String NAMES[] = {
846 "physical", "printable"
847 };
848
849 /**
850 * The OriginType instance to use for specifying a physical origin.
851 */
852 public static final OriginType PHYSICAL = new OriginType(I_PHYSICAL);
853 /**
854 * The OriginType instance to use for specifying a printable origin.
855 */
856 public static final OriginType PRINTABLE = new OriginType(I_PRINTABLE);
857
858 private OriginType(int type) {
859 super(type, NAMES);
860 }
861 }
862
863 /**
864 * A type-safe enumeration of possible print qualities. These print
865 * qualities are in compliance with IPP 1.1.
866 * @since 1.3
867 */
868 public static final class PrintQualityType extends AttributeValue {
869 private static final int I_HIGH = 0;
870 private static final int I_NORMAL = 1;
871 private static final int I_DRAFT = 2;
872
873 private static final String NAMES[] = {
874 "high", "normal", "draft"
875 };
876
877 /**
878 * The PrintQualityType instance to use for specifying a high print
879 * quality.
880 */
881 public static final PrintQualityType HIGH =
882 new PrintQualityType(I_HIGH);
883 /**
884 * The PrintQualityType instance to use for specifying a normal print
885 * quality.
886 */
887 public static final PrintQualityType NORMAL =
888 new PrintQualityType(I_NORMAL);
889 /**
890 * The PrintQualityType instance to use for specifying a draft print
891 * quality.
892 */
893 public static final PrintQualityType DRAFT =
894 new PrintQualityType(I_DRAFT);
895
896 private PrintQualityType(int type) {
897 super(type, NAMES);
898 }
899 }
900
901 private ColorType color;
902 private MediaType media;
903 private OrientationRequestedType orientationRequested;
904 private OriginType origin;
905 private PrintQualityType printQuality;
906 private int[] printerResolution;
907
908 /**
909 * Constructs a PageAttributes instance with default values for every
910 * attribute.
911 */
912 public PageAttributes() {
913 setColor(ColorType.MONOCHROME);
914 setMediaToDefault();
915 setOrientationRequestedToDefault();
916 setOrigin(OriginType.PHYSICAL);
917 setPrintQualityToDefault();
918 setPrinterResolutionToDefault();
919 }
920
921 /**
922 * Constructs a PageAttributes instance which is a copy of the supplied
923 * PageAttributes.
924 *
925 * @param obj the PageAttributes to copy.
926 */
927 public PageAttributes(PageAttributes obj) {
928 set(obj);
929 }
930
931 /**
932 * Constructs a PageAttributes instance with the specified values for
933 * every attribute.
934 *
935 * @param color ColorType.COLOR or ColorType.MONOCHROME.
936 * @param media one of the constant fields of the MediaType class.
937 * @param orientationRequested OrientationRequestedType.PORTRAIT or
938 * OrientationRequestedType.LANDSCAPE.
939 * @param origin OriginType.PHYSICAL or OriginType.PRINTABLE
940 * @param printQuality PrintQualityType.DRAFT, PrintQualityType.NORMAL,
941 * or PrintQualityType.HIGH
942 * @param printerResolution an integer array of 3 elements. The first
943 * element must be greater than 0. The second element must be
944 * must be greater than 0. The third element must be either
945 * <code>3</code> or <code>4</code>.
946 * @throws IllegalArgumentException if one or more of the above
947 * conditions is violated.
948 */
949 public PageAttributes(ColorType color, MediaType media,
950 OrientationRequestedType orientationRequested,
951 OriginType origin, PrintQualityType printQuality,
952 int[] printerResolution) {
953 setColor(color);
954 setMedia(media);
955 setOrientationRequested(orientationRequested);
956 setOrigin(origin);
957 setPrintQuality(printQuality);
958 setPrinterResolution(printerResolution);
959 }
960
961 /**
962 * Creates and returns a copy of this PageAttributes.
963 *
964 * @return the newly created copy. It is safe to cast this Object into
965 * a PageAttributes.
966 */
967 public Object clone() {
968 try {
969 return super.clone();
970 } catch (CloneNotSupportedException e) {
971 // Since we implement Cloneable, this should never happen
972 throw new InternalError();
973 }
974 }
975
976 /**
977 * Sets all of the attributes of this PageAttributes to the same values as
978 * the attributes of obj.
979 *
980 * @param obj the PageAttributes to copy.
981 */
982 public void set(PageAttributes obj) {
983 color = obj.color;
984 media = obj.media;
985 orientationRequested = obj.orientationRequested;
986 origin = obj.origin;
987 printQuality = obj.printQuality;
988 // okay because we never modify the contents of printerResolution
989 printerResolution = obj.printerResolution;
990 }
991
992 /**
993 * Returns whether pages using these attributes will be rendered in
994 * color or monochrome. This attribute is updated to the value chosen
995 * by the user.
996 *
997 * @return ColorType.COLOR or ColorType.MONOCHROME.
998 */
999 public ColorType getColor() {
1000 return color;
1001 }
1002
1003 /**
1004 * Specifies whether pages using these attributes will be rendered in
1005 * color or monochrome. Not specifying this attribute is equivalent to
1006 * specifying ColorType.MONOCHROME.
1007 *
1008 * @param color ColorType.COLOR or ColorType.MONOCHROME.
1009 * @throws IllegalArgumentException if color is null.
1010 */
1011 public void setColor(ColorType color) {
1012 if (color == null) {
1013 throw new IllegalArgumentException("Invalid value for attribute "+
1014 "color");
1015 }
1016 this.color = color;
1017 }
1018
1019 /**
1020 * Returns the paper size for pages using these attributes. This
1021 * attribute is updated to the value chosen by the user.
1022 *
1023 * @return one of the constant fields of the MediaType class.
1024 */
1025 public MediaType getMedia() {
1026 return media;
1027 }
1028
1029 /**
1030 * Specifies the desired paper size for pages using these attributes. The
1031 * actual paper size will be determined by the limitations of the target
1032 * printer. If an exact match cannot be found, an implementation will
1033 * choose the closest possible match. Not specifying this attribute is
1034 * equivalent to specifying the default size for the default locale. The
1035 * default size for locales in the United States and Canada is
1036 * MediaType.NA_LETTER. The default size for all other locales is
1037 * MediaType.ISO_A4.
1038 *
1039 * @param media one of the constant fields of the MediaType class.
1040 * @throws IllegalArgumentException if media is null.
1041 */
1042 public void setMedia(MediaType media) {
1043 if (media == null) {
1044 throw new IllegalArgumentException("Invalid value for attribute "+
1045 "media");
1046 }
1047 this.media = media;
1048 }
1049
1050 /**
1051 * Sets the paper size for pages using these attributes to the default
1052 * size for the default locale. The default size for locales in the
1053 * United States and Canada is MediaType.NA_LETTER. The default size for
1054 * all other locales is MediaType.ISO_A4.
1055 */
1056 public void setMediaToDefault(){
1057 String defaultCountry = Locale.getDefault().getCountry();
1058 if (defaultCountry != null &&
1059 (defaultCountry.equals(Locale.US.getCountry()) ||
1060 defaultCountry.equals(Locale.CANADA.getCountry()))) {
1061 setMedia(MediaType.NA_LETTER);
1062 } else {
1063 setMedia(MediaType.ISO_A4);
1064 }
1065 }
1066
1067 /**
1068 * Returns the print orientation for pages using these attributes. This
1069 * attribute is updated to the value chosen by the user.
1070 *
1071 * @return OrientationRequestedType.PORTRAIT or
1072 * OrientationRequestedType.LANDSCAPE.
1073 */
1074 public OrientationRequestedType getOrientationRequested() {
1075 return orientationRequested;
1076 }
1077
1078 /**
1079 * Specifies the print orientation for pages using these attributes. Not
1080 * specifying the property is equivalent to specifying
1081 * OrientationRequestedType.PORTRAIT.
1082 *
1083 * @param orientationRequested OrientationRequestedType.PORTRAIT or
1084 * OrientationRequestedType.LANDSCAPE.
1085 * @throws IllegalArgumentException if orientationRequested is null.
1086 */
1087 public void setOrientationRequested(OrientationRequestedType
1088 orientationRequested) {
1089 if (orientationRequested == null) {
1090 throw new IllegalArgumentException("Invalid value for attribute "+
1091 "orientationRequested");
1092 }
1093 this.orientationRequested = orientationRequested;
1094 }
1095
1096 /**
1097 * Specifies the print orientation for pages using these attributes.
1098 * Specifying <code>3</code> denotes portrait. Specifying <code>4</code>
1099 * denotes landscape. Specifying any other value will generate an
1100 * IllegalArgumentException. Not specifying the property is equivalent
1101 * to calling setOrientationRequested(OrientationRequestedType.PORTRAIT).
1102 *
1103 * @param orientationRequested <code>3</code> or <code>4</code>
1104 * @throws IllegalArgumentException if orientationRequested is not
1105 * <code>3</code> or <code>4</code>
1106 */
1107 public void setOrientationRequested(int orientationRequested) {
1108 switch (orientationRequested) {
1109 case 3:
1110 setOrientationRequested(OrientationRequestedType.PORTRAIT);
1111 break;
1112 case 4:
1113 setOrientationRequested(OrientationRequestedType.LANDSCAPE);
1114 break;
1115 default:
1116 // This will throw an IllegalArgumentException
1117 setOrientationRequested(null);
1118 break;
1119 }
1120 }
1121
1122 /**
1123 * Sets the print orientation for pages using these attributes to the
1124 * default. The default orientation is portrait.
1125 */
1126 public void setOrientationRequestedToDefault() {
1127 setOrientationRequested(OrientationRequestedType.PORTRAIT);
1128 }
1129
1130 /**
1131 * Returns whether drawing at (0, 0) to pages using these attributes
1132 * draws at the upper-left corner of the physical page, or at the
1133 * upper-left corner of the printable area. (Note that these locations
1134 * could be equivalent.) This attribute cannot be modified by,
1135 * and is not subject to any limitations of, the implementation or the
1136 * target printer.
1137 *
1138 * @return OriginType.PHYSICAL or OriginType.PRINTABLE
1139 */
1140 public OriginType getOrigin() {
1141 return origin;
1142 }
1143
1144 /**
1145 * Specifies whether drawing at (0, 0) to pages using these attributes
1146 * draws at the upper-left corner of the physical page, or at the
1147 * upper-left corner of the printable area. (Note that these locations
1148 * could be equivalent.) Not specifying the property is equivalent to
1149 * specifying OriginType.PHYSICAL.
1150 *
1151 * @param origin OriginType.PHYSICAL or OriginType.PRINTABLE
1152 * @throws IllegalArgumentException if origin is null.
1153 */
1154 public void setOrigin(OriginType origin) {
1155 if (origin == null) {
1156 throw new IllegalArgumentException("Invalid value for attribute "+
1157 "origin");
1158 }
1159 this.origin = origin;
1160 }
1161
1162 /**
1163 * Returns the print quality for pages using these attributes. This
1164 * attribute is updated to the value chosen by the user.
1165 *
1166 * @return PrintQualityType.DRAFT, PrintQualityType.NORMAL, or
1167 * PrintQualityType.HIGH
1168 */
1169 public PrintQualityType getPrintQuality() {
1170 return printQuality;
1171 }
1172
1173 /**
1174 * Specifies the print quality for pages using these attributes. Not
1175 * specifying the property is equivalent to specifying
1176 * PrintQualityType.NORMAL.
1177 *
1178 * @param printQuality PrintQualityType.DRAFT, PrintQualityType.NORMAL,
1179 * or PrintQualityType.HIGH
1180 * @throws IllegalArgumentException if printQuality is null.
1181 */
1182 public void setPrintQuality(PrintQualityType printQuality) {
1183 if (printQuality == null) {
1184 throw new IllegalArgumentException("Invalid value for attribute "+
1185 "printQuality");
1186 }
1187 this.printQuality = printQuality;
1188 }
1189
1190 /**
1191 * Specifies the print quality for pages using these attributes.
1192 * Specifying <code>3</code> denotes draft. Specifying <code>4</code>
1193 * denotes normal. Specifying <code>5</code> denotes high. Specifying
1194 * any other value will generate an IllegalArgumentException. Not
1195 * specifying the property is equivalent to calling
1196 * setPrintQuality(PrintQualityType.NORMAL).
1197 *
1198 * @param printQuality <code>3</code>, <code>4</code>, or <code>5</code>
1199 * @throws IllegalArgumentException if printQuality is not <code>3
1200 * </code>, <code>4</code>, or <code>5</code>
1201 */
1202 public void setPrintQuality(int printQuality) {
1203 switch (printQuality) {
1204 case 3:
1205 setPrintQuality(PrintQualityType.DRAFT);
1206 break;
1207 case 4:
1208 setPrintQuality(PrintQualityType.NORMAL);
1209 break;
1210 case 5:
1211 setPrintQuality(PrintQualityType.HIGH);
1212 break;
1213 default:
1214 // This will throw an IllegalArgumentException
1215 setPrintQuality(null);
1216 break;
1217 }
1218 }
1219
1220 /**
1221 * Sets the print quality for pages using these attributes to the default.
1222 * The default print quality is normal.
1223 */
1224 public void setPrintQualityToDefault() {
1225 setPrintQuality(PrintQualityType.NORMAL);
1226 }
1227
1228 /**
1229 * Returns the print resolution for pages using these attributes.
1230 * Index 0 of the array specifies the cross feed direction resolution
1231 * (typically the horizontal resolution). Index 1 of the array specifies
1232 * the feed direction resolution (typically the vertical resolution).
1233 * Index 2 of the array specifies whether the resolutions are in dots per
1234 * inch or dots per centimeter. <code>3</code> denotes dots per inch.
1235 * <code>4</code> denotes dots per centimeter.
1236 *
1237 * @return an integer array of 3 elements. The first
1238 * element must be greater than 0. The second element must be
1239 * must be greater than 0. The third element must be either
1240 * <code>3</code> or <code>4</code>.
1241 */
1242 public int[] getPrinterResolution() {
1243 // Return a copy because otherwise client code could circumvent the
1244 // the checks made in setPrinterResolution by modifying the
1245 // returned array.
1246 int[] copy = new int[3];
1247 copy[0] = printerResolution[0];
1248 copy[1] = printerResolution[1];
1249 copy[2] = printerResolution[2];
1250 return copy;
1251 }
1252
1253 /**
1254 * Specifies the desired print resolution for pages using these attributes.
1255 * The actual resolution will be determined by the limitations of the
1256 * implementation and the target printer. Index 0 of the array specifies
1257 * the cross feed direction resolution (typically the horizontal
1258 * resolution). Index 1 of the array specifies the feed direction
1259 * resolution (typically the vertical resolution). Index 2 of the array
1260 * specifies whether the resolutions are in dots per inch or dots per
1261 * centimeter. <code>3</code> denotes dots per inch. <code>4</code>
1262 * denotes dots per centimeter. Note that the 1.1 printing implementation
1263 * (Toolkit.getPrintJob) requires that the feed and cross feed resolutions
1264 * be the same. Not specifying the property is equivalent to calling
1265 * setPrinterResolution(72).
1266 *
1267 * @param printerResolution an integer array of 3 elements. The first
1268 * element must be greater than 0. The second element must be
1269 * must be greater than 0. The third element must be either
1270 * <code>3</code> or <code>4</code>.
1271 * @throws IllegalArgumentException if one or more of the above
1272 * conditions is violated.
1273 */
1274 public void setPrinterResolution(int[] printerResolution) {
1275 if (printerResolution == null ||
1276 printerResolution.length != 3 ||
1277 printerResolution[0] <= 0 ||
1278 printerResolution[1] <= 0 ||
1279 (printerResolution[2] != 3 && printerResolution[2] != 4)) {
1280 throw new IllegalArgumentException("Invalid value for attribute "+
1281 "printerResolution");
1282 }
1283 // Store a copy because otherwise client code could circumvent the
1284 // the checks made above by holding a reference to the array and
1285 // modifying it after calling setPrinterResolution.
1286 int[] copy = new int[3];
1287 copy[0] = printerResolution[0];
1288 copy[1] = printerResolution[1];
1289 copy[2] = printerResolution[2];
1290 this.printerResolution = copy;
1291 }
1292
1293 /**
1294 * Specifies the desired cross feed and feed print resolutions in dots per
1295 * inch for pages using these attributes. The same value is used for both
1296 * resolutions. The actual resolutions will be determined by the
1297 * limitations of the implementation and the target printer. Not
1298 * specifying the property is equivalent to specifying <code>72</code>.
1299 *
1300 * @param printerResolution an integer greater than 0.
1301 * @throws IllegalArgumentException if printerResolution is less than or
1302 * equal to 0.
1303 */
1304 public void setPrinterResolution(int printerResolution) {
1305 setPrinterResolution(new int[] { printerResolution, printerResolution,
1306 3 } );
1307 }
1308
1309 /**
1310 * Sets the printer resolution for pages using these attributes to the
1311 * default. The default is 72 dpi for both the feed and cross feed
1312 * resolutions.
1313 */
1314 public void setPrinterResolutionToDefault() {
1315 setPrinterResolution(72);
1316 }
1317
1318 /**
1319 * Determines whether two PageAttributes are equal to each other.
1320 * <p>
1321 * Two PageAttributes are equal if and only if each of their attributes are
1322 * equal. Attributes of enumeration type are equal if and only if the
1323 * fields refer to the same unique enumeration object. This means that
1324 * an aliased media is equal to its underlying unique media. Printer
1325 * resolutions are equal if and only if the feed resolution, cross feed
1326 * resolution, and units are equal.
1327 *
1328 * @param obj the object whose equality will be checked.
1329 * @return whether obj is equal to this PageAttribute according to the
1330 * above criteria.
1331 */
1332 public boolean equals(Object obj) {
1333 if (!(obj instanceof PageAttributes)) {
1334 return false;
1335 }
1336
1337 PageAttributes rhs = (PageAttributes)obj;
1338
1339 return (color == rhs.color &&
1340 media == rhs.media &&
1341 orientationRequested == rhs.orientationRequested &&
1342 origin == rhs.origin &&
1343 printQuality == rhs.printQuality &&
1344 printerResolution[0] == rhs.printerResolution[0] &&
1345 printerResolution[1] == rhs.printerResolution[1] &&
1346 printerResolution[2] == rhs.printerResolution[2]);
1347 }
1348
1349 /**
1350 * Returns a hash code value for this PageAttributes.
1351 *
1352 * @return the hash code.
1353 */
1354 public int hashCode() {
1355 return (color.hashCode() << 31 ^
1356 media.hashCode() << 24 ^
1357 orientationRequested.hashCode() << 23 ^
1358 origin.hashCode() << 22 ^
1359 printQuality.hashCode() << 20 ^
1360 printerResolution[2] >> 2 << 19 ^
1361 printerResolution[1] << 10 ^
1362 printerResolution[0]);
1363 }
1364
1365 /**
1366 * Returns a string representation of this PageAttributes.
1367 *
1368 * @return the string representation.
1369 */
1370 public String toString() {
1371 // int[] printerResolution = getPrinterResolution();
1372 return "color=" + getColor() + ",media=" + getMedia() +
1373 ",orientation-requested=" + getOrientationRequested() +
1374 ",origin=" + getOrigin() + ",print-quality=" + getPrintQuality() +
1375 ",printer-resolution=[" + printerResolution[0] + "," +
1376 printerResolution[1] + "," + printerResolution[2] + "]";
1377 }
1378}