0001: /*
0002: * Copyright 1999-2006 Sun Microsystems, Inc. All Rights Reserved.
0003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0004: *
0005: * This code is free software; you can redistribute it and/or modify it
0006: * under the terms of the GNU General Public License version 2 only, as
0007: * published by the Free Software Foundation. Sun designates this
0008: * particular file as subject to the "Classpath" exception as provided
0009: * by Sun in the LICENSE file that accompanied this code.
0010: *
0011: * This code is distributed in the hope that it will be useful, but WITHOUT
0012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0014: * version 2 for more details (a copy is included in the LICENSE file that
0015: * accompanied this code).
0016: *
0017: * You should have received a copy of the GNU General Public License version
0018: * 2 along with this work; if not, write to the Free Software Foundation,
0019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0020: *
0021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0022: * CA 95054 USA or visit www.sun.com if you need additional information or
0023: * have any questions.
0024: */
0025:
0026: package java.awt;
0027:
0028: import java.util.Locale;
0029:
0030: /**
0031: * A set of attributes which control the output of a printed page.
0032: * <p>
0033: * Instances of this class control the color state, paper size (media type),
0034: * orientation, logical origin, print quality, and resolution of every
0035: * page which uses the instance. Attribute names are compliant with the
0036: * Internet Printing Protocol (IPP) 1.1 where possible. Attribute values
0037: * are partially compliant where possible.
0038: * <p>
0039: * To use a method which takes an inner class type, pass a reference to
0040: * one of the constant fields of the inner class. Client code cannot create
0041: * new instances of the inner class types because none of those classes
0042: * has a public constructor. For example, to set the color state to
0043: * monochrome, use the following code:
0044: * <pre>
0045: * import java.awt.PageAttributes;
0046: *
0047: * public class MonochromeExample {
0048: * public void setMonochrome(PageAttributes pageAttributes) {
0049: * pageAttributes.setColor(PageAttributes.ColorType.MONOCHROME);
0050: * }
0051: * }
0052: * </pre>
0053: * <p>
0054: * Every IPP attribute which supports an <i>attributeName</i>-default value
0055: * has a corresponding <code>set<i>attributeName</i>ToDefault</code> method.
0056: * Default value fields are not provided.
0057: *
0058: * @version 1.15, 05/05/07
0059: * @author David Mendenhall
0060: * @since 1.3
0061: */
0062: public final class PageAttributes implements Cloneable {
0063: /**
0064: * A type-safe enumeration of possible color states.
0065: * @since 1.3
0066: */
0067: public static final class ColorType extends AttributeValue {
0068: private static final int I_COLOR = 0;
0069: private static final int I_MONOCHROME = 1;
0070:
0071: private static final String NAMES[] = { "color", "monochrome" };
0072:
0073: /**
0074: * The ColorType instance to use for specifying color printing.
0075: */
0076: public static final ColorType COLOR = new ColorType(I_COLOR);
0077: /**
0078: * The ColorType instance to use for specifying monochrome printing.
0079: */
0080: public static final ColorType MONOCHROME = new ColorType(
0081: I_MONOCHROME);
0082:
0083: private ColorType(int type) {
0084: super (type, NAMES);
0085: }
0086: }
0087:
0088: /**
0089: * A type-safe enumeration of possible paper sizes. These sizes are in
0090: * compliance with IPP 1.1.
0091: * @since 1.3
0092: */
0093: public static final class MediaType extends AttributeValue {
0094: private static final int I_ISO_4A0 = 0;
0095: private static final int I_ISO_2A0 = 1;
0096: private static final int I_ISO_A0 = 2;
0097: private static final int I_ISO_A1 = 3;
0098: private static final int I_ISO_A2 = 4;
0099: private static final int I_ISO_A3 = 5;
0100: private static final int I_ISO_A4 = 6;
0101: private static final int I_ISO_A5 = 7;
0102: private static final int I_ISO_A6 = 8;
0103: private static final int I_ISO_A7 = 9;
0104: private static final int I_ISO_A8 = 10;
0105: private static final int I_ISO_A9 = 11;
0106: private static final int I_ISO_A10 = 12;
0107: private static final int I_ISO_B0 = 13;
0108: private static final int I_ISO_B1 = 14;
0109: private static final int I_ISO_B2 = 15;
0110: private static final int I_ISO_B3 = 16;
0111: private static final int I_ISO_B4 = 17;
0112: private static final int I_ISO_B5 = 18;
0113: private static final int I_ISO_B6 = 19;
0114: private static final int I_ISO_B7 = 20;
0115: private static final int I_ISO_B8 = 21;
0116: private static final int I_ISO_B9 = 22;
0117: private static final int I_ISO_B10 = 23;
0118: private static final int I_JIS_B0 = 24;
0119: private static final int I_JIS_B1 = 25;
0120: private static final int I_JIS_B2 = 26;
0121: private static final int I_JIS_B3 = 27;
0122: private static final int I_JIS_B4 = 28;
0123: private static final int I_JIS_B5 = 29;
0124: private static final int I_JIS_B6 = 30;
0125: private static final int I_JIS_B7 = 31;
0126: private static final int I_JIS_B8 = 32;
0127: private static final int I_JIS_B9 = 33;
0128: private static final int I_JIS_B10 = 34;
0129: private static final int I_ISO_C0 = 35;
0130: private static final int I_ISO_C1 = 36;
0131: private static final int I_ISO_C2 = 37;
0132: private static final int I_ISO_C3 = 38;
0133: private static final int I_ISO_C4 = 39;
0134: private static final int I_ISO_C5 = 40;
0135: private static final int I_ISO_C6 = 41;
0136: private static final int I_ISO_C7 = 42;
0137: private static final int I_ISO_C8 = 43;
0138: private static final int I_ISO_C9 = 44;
0139: private static final int I_ISO_C10 = 45;
0140: private static final int I_ISO_DESIGNATED_LONG = 46;
0141: private static final int I_EXECUTIVE = 47;
0142: private static final int I_FOLIO = 48;
0143: private static final int I_INVOICE = 49;
0144: private static final int I_LEDGER = 50;
0145: private static final int I_NA_LETTER = 51;
0146: private static final int I_NA_LEGAL = 52;
0147: private static final int I_QUARTO = 53;
0148: private static final int I_A = 54;
0149: private static final int I_B = 55;
0150: private static final int I_C = 56;
0151: private static final int I_D = 57;
0152: private static final int I_E = 58;
0153: private static final int I_NA_10X15_ENVELOPE = 59;
0154: private static final int I_NA_10X14_ENVELOPE = 60;
0155: private static final int I_NA_10X13_ENVELOPE = 61;
0156: private static final int I_NA_9X12_ENVELOPE = 62;
0157: private static final int I_NA_9X11_ENVELOPE = 63;
0158: private static final int I_NA_7X9_ENVELOPE = 64;
0159: private static final int I_NA_6X9_ENVELOPE = 65;
0160: private static final int I_NA_NUMBER_9_ENVELOPE = 66;
0161: private static final int I_NA_NUMBER_10_ENVELOPE = 67;
0162: private static final int I_NA_NUMBER_11_ENVELOPE = 68;
0163: private static final int I_NA_NUMBER_12_ENVELOPE = 69;
0164: private static final int I_NA_NUMBER_14_ENVELOPE = 70;
0165: private static final int I_INVITE_ENVELOPE = 71;
0166: private static final int I_ITALY_ENVELOPE = 72;
0167: private static final int I_MONARCH_ENVELOPE = 73;
0168: private static final int I_PERSONAL_ENVELOPE = 74;
0169:
0170: private static final String NAMES[] = { "iso-4a0", "iso-2a0",
0171: "iso-a0", "iso-a1", "iso-a2", "iso-a3", "iso-a4",
0172: "iso-a5", "iso-a6", "iso-a7", "iso-a8", "iso-a9",
0173: "iso-a10", "iso-b0", "iso-b1", "iso-b2", "iso-b3",
0174: "iso-b4", "iso-b5", "iso-b6", "iso-b7", "iso-b8",
0175: "iso-b9", "iso-b10", "jis-b0", "jis-b1", "jis-b2",
0176: "jis-b3", "jis-b4", "jis-b5", "jis-b6", "jis-b7",
0177: "jis-b8", "jis-b9", "jis-b10", "iso-c0", "iso-c1",
0178: "iso-c2", "iso-c3", "iso-c4", "iso-c5", "iso-c6",
0179: "iso-c7", "iso-c8", "iso-c9", "iso-c10",
0180: "iso-designated-long", "executive", "folio", "invoice",
0181: "ledger", "na-letter", "na-legal", "quarto", "a", "b",
0182: "c", "d", "e", "na-10x15-envelope",
0183: "na-10x14-envelope", "na-10x13-envelope",
0184: "na-9x12-envelope", "na-9x11-envelope",
0185: "na-7x9-envelope", "na-6x9-envelope",
0186: "na-number-9-envelope", "na-number-10-envelope",
0187: "na-number-11-envelope", "na-number-12-envelope",
0188: "na-number-14-envelope", "invite-envelope",
0189: "italy-envelope", "monarch-envelope",
0190: "personal-envelope" };
0191:
0192: /**
0193: * The MediaType instance for ISO/DIN & JIS 4A0, 1682 x 2378 mm.
0194: */
0195: public static final MediaType ISO_4A0 = new MediaType(I_ISO_4A0);
0196: /**
0197: * The MediaType instance for ISO/DIN & JIS 2A0, 1189 x 1682 mm.
0198: */
0199: public static final MediaType ISO_2A0 = new MediaType(I_ISO_2A0);
0200: /**
0201: * The MediaType instance for ISO/DIN & JIS A0, 841 x 1189 mm.
0202: */
0203: public static final MediaType ISO_A0 = new MediaType(I_ISO_A0);
0204: /**
0205: * The MediaType instance for ISO/DIN & JIS A1, 594 x 841 mm.
0206: */
0207: public static final MediaType ISO_A1 = new MediaType(I_ISO_A1);
0208: /**
0209: * The MediaType instance for ISO/DIN & JIS A2, 420 x 594 mm.
0210: */
0211: public static final MediaType ISO_A2 = new MediaType(I_ISO_A2);
0212: /**
0213: * The MediaType instance for ISO/DIN & JIS A3, 297 x 420 mm.
0214: */
0215: public static final MediaType ISO_A3 = new MediaType(I_ISO_A3);
0216: /**
0217: * The MediaType instance for ISO/DIN & JIS A4, 210 x 297 mm.
0218: */
0219: public static final MediaType ISO_A4 = new MediaType(I_ISO_A4);
0220: /**
0221: * The MediaType instance for ISO/DIN & JIS A5, 148 x 210 mm.
0222: */
0223: public static final MediaType ISO_A5 = new MediaType(I_ISO_A5);
0224: /**
0225: * The MediaType instance for ISO/DIN & JIS A6, 105 x 148 mm.
0226: */
0227: public static final MediaType ISO_A6 = new MediaType(I_ISO_A6);
0228: /**
0229: * The MediaType instance for ISO/DIN & JIS A7, 74 x 105 mm.
0230: */
0231: public static final MediaType ISO_A7 = new MediaType(I_ISO_A7);
0232: /**
0233: * The MediaType instance for ISO/DIN & JIS A8, 52 x 74 mm.
0234: */
0235: public static final MediaType ISO_A8 = new MediaType(I_ISO_A8);
0236: /**
0237: * The MediaType instance for ISO/DIN & JIS A9, 37 x 52 mm.
0238: */
0239: public static final MediaType ISO_A9 = new MediaType(I_ISO_A9);
0240: /**
0241: * The MediaType instance for ISO/DIN & JIS A10, 26 x 37 mm.
0242: */
0243: public static final MediaType ISO_A10 = new MediaType(I_ISO_A10);
0244: /**
0245: * The MediaType instance for ISO/DIN B0, 1000 x 1414 mm.
0246: */
0247: public static final MediaType ISO_B0 = new MediaType(I_ISO_B0);
0248: /**
0249: * The MediaType instance for ISO/DIN B1, 707 x 1000 mm.
0250: */
0251: public static final MediaType ISO_B1 = new MediaType(I_ISO_B1);
0252: /**
0253: * The MediaType instance for ISO/DIN B2, 500 x 707 mm.
0254: */
0255: public static final MediaType ISO_B2 = new MediaType(I_ISO_B2);
0256: /**
0257: * The MediaType instance for ISO/DIN B3, 353 x 500 mm.
0258: */
0259: public static final MediaType ISO_B3 = new MediaType(I_ISO_B3);
0260: /**
0261: * The MediaType instance for ISO/DIN B4, 250 x 353 mm.
0262: */
0263: public static final MediaType ISO_B4 = new MediaType(I_ISO_B4);
0264: /**
0265: * The MediaType instance for ISO/DIN B5, 176 x 250 mm.
0266: */
0267: public static final MediaType ISO_B5 = new MediaType(I_ISO_B5);
0268: /**
0269: * The MediaType instance for ISO/DIN B6, 125 x 176 mm.
0270: */
0271: public static final MediaType ISO_B6 = new MediaType(I_ISO_B6);
0272: /**
0273: * The MediaType instance for ISO/DIN B7, 88 x 125 mm.
0274: */
0275: public static final MediaType ISO_B7 = new MediaType(I_ISO_B7);
0276: /**
0277: * The MediaType instance for ISO/DIN B8, 62 x 88 mm.
0278: */
0279: public static final MediaType ISO_B8 = new MediaType(I_ISO_B8);
0280: /**
0281: * The MediaType instance for ISO/DIN B9, 44 x 62 mm.
0282: */
0283: public static final MediaType ISO_B9 = new MediaType(I_ISO_B9);
0284: /**
0285: * The MediaType instance for ISO/DIN B10, 31 x 44 mm.
0286: */
0287: public static final MediaType ISO_B10 = new MediaType(I_ISO_B10);
0288: /**
0289: * The MediaType instance for JIS B0, 1030 x 1456 mm.
0290: */
0291: public static final MediaType JIS_B0 = new MediaType(I_JIS_B0);
0292: /**
0293: * The MediaType instance for JIS B1, 728 x 1030 mm.
0294: */
0295: public static final MediaType JIS_B1 = new MediaType(I_JIS_B1);
0296: /**
0297: * The MediaType instance for JIS B2, 515 x 728 mm.
0298: */
0299: public static final MediaType JIS_B2 = new MediaType(I_JIS_B2);
0300: /**
0301: * The MediaType instance for JIS B3, 364 x 515 mm.
0302: */
0303: public static final MediaType JIS_B3 = new MediaType(I_JIS_B3);
0304: /**
0305: * The MediaType instance for JIS B4, 257 x 364 mm.
0306: */
0307: public static final MediaType JIS_B4 = new MediaType(I_JIS_B4);
0308: /**
0309: * The MediaType instance for JIS B5, 182 x 257 mm.
0310: */
0311: public static final MediaType JIS_B5 = new MediaType(I_JIS_B5);
0312: /**
0313: * The MediaType instance for JIS B6, 128 x 182 mm.
0314: */
0315: public static final MediaType JIS_B6 = new MediaType(I_JIS_B6);
0316: /**
0317: * The MediaType instance for JIS B7, 91 x 128 mm.
0318: */
0319: public static final MediaType JIS_B7 = new MediaType(I_JIS_B7);
0320: /**
0321: * The MediaType instance for JIS B8, 64 x 91 mm.
0322: */
0323: public static final MediaType JIS_B8 = new MediaType(I_JIS_B8);
0324: /**
0325: * The MediaType instance for JIS B9, 45 x 64 mm.
0326: */
0327: public static final MediaType JIS_B9 = new MediaType(I_JIS_B9);
0328: /**
0329: * The MediaType instance for JIS B10, 32 x 45 mm.
0330: */
0331: public static final MediaType JIS_B10 = new MediaType(I_JIS_B10);
0332: /**
0333: * The MediaType instance for ISO/DIN C0, 917 x 1297 mm.
0334: */
0335: public static final MediaType ISO_C0 = new MediaType(I_ISO_C0);
0336: /**
0337: * The MediaType instance for ISO/DIN C1, 648 x 917 mm.
0338: */
0339: public static final MediaType ISO_C1 = new MediaType(I_ISO_C1);
0340: /**
0341: * The MediaType instance for ISO/DIN C2, 458 x 648 mm.
0342: */
0343: public static final MediaType ISO_C2 = new MediaType(I_ISO_C2);
0344: /**
0345: * The MediaType instance for ISO/DIN C3, 324 x 458 mm.
0346: */
0347: public static final MediaType ISO_C3 = new MediaType(I_ISO_C3);
0348: /**
0349: * The MediaType instance for ISO/DIN C4, 229 x 324 mm.
0350: */
0351: public static final MediaType ISO_C4 = new MediaType(I_ISO_C4);
0352: /**
0353: * The MediaType instance for ISO/DIN C5, 162 x 229 mm.
0354: */
0355: public static final MediaType ISO_C5 = new MediaType(I_ISO_C5);
0356: /**
0357: * The MediaType instance for ISO/DIN C6, 114 x 162 mm.
0358: */
0359: public static final MediaType ISO_C6 = new MediaType(I_ISO_C6);
0360: /**
0361: * The MediaType instance for ISO/DIN C7, 81 x 114 mm.
0362: */
0363: public static final MediaType ISO_C7 = new MediaType(I_ISO_C7);
0364: /**
0365: * The MediaType instance for ISO/DIN C8, 57 x 81 mm.
0366: */
0367: public static final MediaType ISO_C8 = new MediaType(I_ISO_C8);
0368: /**
0369: * The MediaType instance for ISO/DIN C9, 40 x 57 mm.
0370: */
0371: public static final MediaType ISO_C9 = new MediaType(I_ISO_C9);
0372: /**
0373: * The MediaType instance for ISO/DIN C10, 28 x 40 mm.
0374: */
0375: public static final MediaType ISO_C10 = new MediaType(I_ISO_C10);
0376: /**
0377: * The MediaType instance for ISO Designated Long, 110 x 220 mm.
0378: */
0379: public static final MediaType ISO_DESIGNATED_LONG = new MediaType(
0380: I_ISO_DESIGNATED_LONG);
0381: /**
0382: * The MediaType instance for Executive, 7 1/4 x 10 1/2 in.
0383: */
0384: public static final MediaType EXECUTIVE = new MediaType(
0385: I_EXECUTIVE);
0386: /**
0387: * The MediaType instance for Folio, 8 1/2 x 13 in.
0388: */
0389: public static final MediaType FOLIO = new MediaType(I_FOLIO);
0390: /**
0391: * The MediaType instance for Invoice, 5 1/2 x 8 1/2 in.
0392: */
0393: public static final MediaType INVOICE = new MediaType(I_INVOICE);
0394: /**
0395: * The MediaType instance for Ledger, 11 x 17 in.
0396: */
0397: public static final MediaType LEDGER = new MediaType(I_LEDGER);
0398: /**
0399: * The MediaType instance for North American Letter, 8 1/2 x 11 in.
0400: */
0401: public static final MediaType NA_LETTER = new MediaType(
0402: I_NA_LETTER);
0403: /**
0404: * The MediaType instance for North American Legal, 8 1/2 x 14 in.
0405: */
0406: public static final MediaType NA_LEGAL = new MediaType(
0407: I_NA_LEGAL);
0408: /**
0409: * The MediaType instance for Quarto, 215 x 275 mm.
0410: */
0411: public static final MediaType QUARTO = new MediaType(I_QUARTO);
0412: /**
0413: * The MediaType instance for Engineering A, 8 1/2 x 11 in.
0414: */
0415: public static final MediaType A = new MediaType(I_A);
0416: /**
0417: * The MediaType instance for Engineering B, 11 x 17 in.
0418: */
0419: public static final MediaType B = new MediaType(I_B);
0420: /**
0421: * The MediaType instance for Engineering C, 17 x 22 in.
0422: */
0423: public static final MediaType C = new MediaType(I_C);
0424: /**
0425: * The MediaType instance for Engineering D, 22 x 34 in.
0426: */
0427: public static final MediaType D = new MediaType(I_D);
0428: /**
0429: * The MediaType instance for Engineering E, 34 x 44 in.
0430: */
0431: public static final MediaType E = new MediaType(I_E);
0432: /**
0433: * The MediaType instance for North American 10 x 15 in.
0434: */
0435: public static final MediaType NA_10X15_ENVELOPE = new MediaType(
0436: I_NA_10X15_ENVELOPE);
0437: /**
0438: * The MediaType instance for North American 10 x 14 in.
0439: */
0440: public static final MediaType NA_10X14_ENVELOPE = new MediaType(
0441: I_NA_10X14_ENVELOPE);
0442: /**
0443: * The MediaType instance for North American 10 x 13 in.
0444: */
0445: public static final MediaType NA_10X13_ENVELOPE = new MediaType(
0446: I_NA_10X13_ENVELOPE);
0447: /**
0448: * The MediaType instance for North American 9 x 12 in.
0449: */
0450: public static final MediaType NA_9X12_ENVELOPE = new MediaType(
0451: I_NA_9X12_ENVELOPE);
0452: /**
0453: * The MediaType instance for North American 9 x 11 in.
0454: */
0455: public static final MediaType NA_9X11_ENVELOPE = new MediaType(
0456: I_NA_9X11_ENVELOPE);
0457: /**
0458: * The MediaType instance for North American 7 x 9 in.
0459: */
0460: public static final MediaType NA_7X9_ENVELOPE = new MediaType(
0461: I_NA_7X9_ENVELOPE);
0462: /**
0463: * The MediaType instance for North American 6 x 9 in.
0464: */
0465: public static final MediaType NA_6X9_ENVELOPE = new MediaType(
0466: I_NA_6X9_ENVELOPE);
0467: /**
0468: * The MediaType instance for North American #9 Business Envelope,
0469: * 3 7/8 x 8 7/8 in.
0470: */
0471: public static final MediaType NA_NUMBER_9_ENVELOPE = new MediaType(
0472: I_NA_NUMBER_9_ENVELOPE);
0473: /**
0474: * The MediaType instance for North American #10 Business Envelope,
0475: * 4 1/8 x 9 1/2 in.
0476: */
0477: public static final MediaType NA_NUMBER_10_ENVELOPE = new MediaType(
0478: I_NA_NUMBER_10_ENVELOPE);
0479: /**
0480: * The MediaType instance for North American #11 Business Envelope,
0481: * 4 1/2 x 10 3/8 in.
0482: */
0483: public static final MediaType NA_NUMBER_11_ENVELOPE = new MediaType(
0484: I_NA_NUMBER_11_ENVELOPE);
0485: /**
0486: * The MediaType instance for North American #12 Business Envelope,
0487: * 4 3/4 x 11 in.
0488: */
0489: public static final MediaType NA_NUMBER_12_ENVELOPE = new MediaType(
0490: I_NA_NUMBER_12_ENVELOPE);
0491: /**
0492: * The MediaType instance for North American #14 Business Envelope,
0493: * 5 x 11 1/2 in.
0494: */
0495: public static final MediaType NA_NUMBER_14_ENVELOPE = new MediaType(
0496: I_NA_NUMBER_14_ENVELOPE);
0497: /**
0498: * The MediaType instance for Invitation Envelope, 220 x 220 mm.
0499: */
0500: public static final MediaType INVITE_ENVELOPE = new MediaType(
0501: I_INVITE_ENVELOPE);
0502: /**
0503: * The MediaType instance for Italy Envelope, 110 x 230 mm.
0504: */
0505: public static final MediaType ITALY_ENVELOPE = new MediaType(
0506: I_ITALY_ENVELOPE);
0507: /**
0508: * The MediaType instance for Monarch Envelope, 3 7/8 x 7 1/2 in.
0509: */
0510: public static final MediaType MONARCH_ENVELOPE = new MediaType(
0511: I_MONARCH_ENVELOPE);
0512: /**
0513: * The MediaType instance for 6 3/4 envelope, 3 5/8 x 6 1/2 in.
0514: */
0515: public static final MediaType PERSONAL_ENVELOPE = new MediaType(
0516: I_PERSONAL_ENVELOPE);
0517: /**
0518: * An alias for ISO_A0.
0519: */
0520: public static final MediaType A0 = ISO_A0;
0521: /**
0522: * An alias for ISO_A1.
0523: */
0524: public static final MediaType A1 = ISO_A1;
0525: /**
0526: * An alias for ISO_A2.
0527: */
0528: public static final MediaType A2 = ISO_A2;
0529: /**
0530: * An alias for ISO_A3.
0531: */
0532: public static final MediaType A3 = ISO_A3;
0533: /**
0534: * An alias for ISO_A4.
0535: */
0536: public static final MediaType A4 = ISO_A4;
0537: /**
0538: * An alias for ISO_A5.
0539: */
0540: public static final MediaType A5 = ISO_A5;
0541: /**
0542: * An alias for ISO_A6.
0543: */
0544: public static final MediaType A6 = ISO_A6;
0545: /**
0546: * An alias for ISO_A7.
0547: */
0548: public static final MediaType A7 = ISO_A7;
0549: /**
0550: * An alias for ISO_A8.
0551: */
0552: public static final MediaType A8 = ISO_A8;
0553: /**
0554: * An alias for ISO_A9.
0555: */
0556: public static final MediaType A9 = ISO_A9;
0557: /**
0558: * An alias for ISO_A10.
0559: */
0560: public static final MediaType A10 = ISO_A10;
0561: /**
0562: * An alias for ISO_B0.
0563: */
0564: public static final MediaType B0 = ISO_B0;
0565: /**
0566: * An alias for ISO_B1.
0567: */
0568: public static final MediaType B1 = ISO_B1;
0569: /**
0570: * An alias for ISO_B2.
0571: */
0572: public static final MediaType B2 = ISO_B2;
0573: /**
0574: * An alias for ISO_B3.
0575: */
0576: public static final MediaType B3 = ISO_B3;
0577: /**
0578: * An alias for ISO_B4.
0579: */
0580: public static final MediaType B4 = ISO_B4;
0581: /**
0582: * An alias for ISO_B4.
0583: */
0584: public static final MediaType ISO_B4_ENVELOPE = ISO_B4;
0585: /**
0586: * An alias for ISO_B5.
0587: */
0588: public static final MediaType B5 = ISO_B5;
0589: /**
0590: * An alias for ISO_B5.
0591: */
0592: public static final MediaType ISO_B5_ENVELOPE = ISO_B5;
0593: /**
0594: * An alias for ISO_B6.
0595: */
0596: public static final MediaType B6 = ISO_B6;
0597: /**
0598: * An alias for ISO_B7.
0599: */
0600: public static final MediaType B7 = ISO_B7;
0601: /**
0602: * An alias for ISO_B8.
0603: */
0604: public static final MediaType B8 = ISO_B8;
0605: /**
0606: * An alias for ISO_B9.
0607: */
0608: public static final MediaType B9 = ISO_B9;
0609: /**
0610: * An alias for ISO_B10.
0611: */
0612: public static final MediaType B10 = ISO_B10;
0613: /**
0614: * An alias for ISO_C0.
0615: */
0616: public static final MediaType C0 = ISO_C0;
0617: /**
0618: * An alias for ISO_C0.
0619: */
0620: public static final MediaType ISO_C0_ENVELOPE = ISO_C0;
0621: /**
0622: * An alias for ISO_C1.
0623: */
0624: public static final MediaType C1 = ISO_C1;
0625: /**
0626: * An alias for ISO_C1.
0627: */
0628: public static final MediaType ISO_C1_ENVELOPE = ISO_C1;
0629: /**
0630: * An alias for ISO_C2.
0631: */
0632: public static final MediaType C2 = ISO_C2;
0633: /**
0634: * An alias for ISO_C2.
0635: */
0636: public static final MediaType ISO_C2_ENVELOPE = ISO_C2;
0637: /**
0638: * An alias for ISO_C3.
0639: */
0640: public static final MediaType C3 = ISO_C3;
0641: /**
0642: * An alias for ISO_C3.
0643: */
0644: public static final MediaType ISO_C3_ENVELOPE = ISO_C3;
0645: /**
0646: * An alias for ISO_C4.
0647: */
0648: public static final MediaType C4 = ISO_C4;
0649: /**
0650: * An alias for ISO_C4.
0651: */
0652: public static final MediaType ISO_C4_ENVELOPE = ISO_C4;
0653: /**
0654: * An alias for ISO_C5.
0655: */
0656: public static final MediaType C5 = ISO_C5;
0657: /**
0658: * An alias for ISO_C5.
0659: */
0660: public static final MediaType ISO_C5_ENVELOPE = ISO_C5;
0661: /**
0662: * An alias for ISO_C6.
0663: */
0664: public static final MediaType C6 = ISO_C6;
0665: /**
0666: * An alias for ISO_C6.
0667: */
0668: public static final MediaType ISO_C6_ENVELOPE = ISO_C6;
0669: /**
0670: * An alias for ISO_C7.
0671: */
0672: public static final MediaType C7 = ISO_C7;
0673: /**
0674: * An alias for ISO_C7.
0675: */
0676: public static final MediaType ISO_C7_ENVELOPE = ISO_C7;
0677: /**
0678: * An alias for ISO_C8.
0679: */
0680: public static final MediaType C8 = ISO_C8;
0681: /**
0682: * An alias for ISO_C8.
0683: */
0684: public static final MediaType ISO_C8_ENVELOPE = ISO_C8;
0685: /**
0686: * An alias for ISO_C9.
0687: */
0688: public static final MediaType C9 = ISO_C9;
0689: /**
0690: * An alias for ISO_C9.
0691: */
0692: public static final MediaType ISO_C9_ENVELOPE = ISO_C9;
0693: /**
0694: * An alias for ISO_C10.
0695: */
0696: public static final MediaType C10 = ISO_C10;
0697: /**
0698: * An alias for ISO_C10.
0699: */
0700: public static final MediaType ISO_C10_ENVELOPE = ISO_C10;
0701: /**
0702: * An alias for ISO_DESIGNATED_LONG.
0703: */
0704: public static final MediaType ISO_DESIGNATED_LONG_ENVELOPE = ISO_DESIGNATED_LONG;
0705: /**
0706: * An alias for INVOICE.
0707: */
0708: public static final MediaType STATEMENT = INVOICE;
0709: /**
0710: * An alias for LEDGER.
0711: */
0712: public static final MediaType TABLOID = LEDGER;
0713: /**
0714: * An alias for NA_LETTER.
0715: */
0716: public static final MediaType LETTER = NA_LETTER;
0717: /**
0718: * An alias for NA_LETTER.
0719: */
0720: public static final MediaType NOTE = NA_LETTER;
0721: /**
0722: * An alias for NA_LEGAL.
0723: */
0724: public static final MediaType LEGAL = NA_LEGAL;
0725: /**
0726: * An alias for NA_10X15_ENVELOPE.
0727: */
0728: public static final MediaType ENV_10X15 = NA_10X15_ENVELOPE;
0729: /**
0730: * An alias for NA_10X14_ENVELOPE.
0731: */
0732: public static final MediaType ENV_10X14 = NA_10X14_ENVELOPE;
0733: /**
0734: * An alias for NA_10X13_ENVELOPE.
0735: */
0736: public static final MediaType ENV_10X13 = NA_10X13_ENVELOPE;
0737: /**
0738: * An alias for NA_9X12_ENVELOPE.
0739: */
0740: public static final MediaType ENV_9X12 = NA_9X12_ENVELOPE;
0741: /**
0742: * An alias for NA_9X11_ENVELOPE.
0743: */
0744: public static final MediaType ENV_9X11 = NA_9X11_ENVELOPE;
0745: /**
0746: * An alias for NA_7X9_ENVELOPE.
0747: */
0748: public static final MediaType ENV_7X9 = NA_7X9_ENVELOPE;
0749: /**
0750: * An alias for NA_6X9_ENVELOPE.
0751: */
0752: public static final MediaType ENV_6X9 = NA_6X9_ENVELOPE;
0753: /**
0754: * An alias for NA_NUMBER_9_ENVELOPE.
0755: */
0756: public static final MediaType ENV_9 = NA_NUMBER_9_ENVELOPE;
0757: /**
0758: * An alias for NA_NUMBER_10_ENVELOPE.
0759: */
0760: public static final MediaType ENV_10 = NA_NUMBER_10_ENVELOPE;
0761: /**
0762: * An alias for NA_NUMBER_11_ENVELOPE.
0763: */
0764: public static final MediaType ENV_11 = NA_NUMBER_11_ENVELOPE;
0765: /**
0766: * An alias for NA_NUMBER_12_ENVELOPE.
0767: */
0768: public static final MediaType ENV_12 = NA_NUMBER_12_ENVELOPE;
0769: /**
0770: * An alias for NA_NUMBER_14_ENVELOPE.
0771: */
0772: public static final MediaType ENV_14 = NA_NUMBER_14_ENVELOPE;
0773: /**
0774: * An alias for INVITE_ENVELOPE.
0775: */
0776: public static final MediaType ENV_INVITE = INVITE_ENVELOPE;
0777: /**
0778: * An alias for ITALY_ENVELOPE.
0779: */
0780: public static final MediaType ENV_ITALY = ITALY_ENVELOPE;
0781: /**
0782: * An alias for MONARCH_ENVELOPE.
0783: */
0784: public static final MediaType ENV_MONARCH = MONARCH_ENVELOPE;
0785: /**
0786: * An alias for PERSONAL_ENVELOPE.
0787: */
0788: public static final MediaType ENV_PERSONAL = PERSONAL_ENVELOPE;
0789: /**
0790: * An alias for INVITE_ENVELOPE.
0791: */
0792: public static final MediaType INVITE = INVITE_ENVELOPE;
0793: /**
0794: * An alias for ITALY_ENVELOPE.
0795: */
0796: public static final MediaType ITALY = ITALY_ENVELOPE;
0797: /**
0798: * An alias for MONARCH_ENVELOPE.
0799: */
0800: public static final MediaType MONARCH = MONARCH_ENVELOPE;
0801: /**
0802: * An alias for PERSONAL_ENVELOPE.
0803: */
0804: public static final MediaType PERSONAL = PERSONAL_ENVELOPE;
0805:
0806: private MediaType(int type) {
0807: super (type, NAMES);
0808: }
0809: }
0810:
0811: /**
0812: * A type-safe enumeration of possible orientations. These orientations
0813: * are in partial compliance with IPP 1.1.
0814: * @since 1.3
0815: */
0816: public static final class OrientationRequestedType extends
0817: AttributeValue {
0818: private static final int I_PORTRAIT = 0;
0819: private static final int I_LANDSCAPE = 1;
0820:
0821: private static final String NAMES[] = { "portrait", "landscape" };
0822:
0823: /**
0824: * The OrientationRequestedType instance to use for specifying a
0825: * portrait orientation.
0826: */
0827: public static final OrientationRequestedType PORTRAIT = new OrientationRequestedType(
0828: I_PORTRAIT);
0829: /**
0830: * The OrientationRequestedType instance to use for specifying a
0831: * landscape orientation.
0832: */
0833: public static final OrientationRequestedType LANDSCAPE = new OrientationRequestedType(
0834: I_LANDSCAPE);
0835:
0836: private OrientationRequestedType(int type) {
0837: super (type, NAMES);
0838: }
0839: }
0840:
0841: /**
0842: * A type-safe enumeration of possible origins.
0843: * @since 1.3
0844: */
0845: public static final class OriginType extends AttributeValue {
0846: private static final int I_PHYSICAL = 0;
0847: private static final int I_PRINTABLE = 1;
0848:
0849: private static final String NAMES[] = { "physical", "printable" };
0850:
0851: /**
0852: * The OriginType instance to use for specifying a physical origin.
0853: */
0854: public static final OriginType PHYSICAL = new OriginType(
0855: I_PHYSICAL);
0856: /**
0857: * The OriginType instance to use for specifying a printable origin.
0858: */
0859: public static final OriginType PRINTABLE = new OriginType(
0860: I_PRINTABLE);
0861:
0862: private OriginType(int type) {
0863: super (type, NAMES);
0864: }
0865: }
0866:
0867: /**
0868: * A type-safe enumeration of possible print qualities. These print
0869: * qualities are in compliance with IPP 1.1.
0870: * @since 1.3
0871: */
0872: public static final class PrintQualityType extends AttributeValue {
0873: private static final int I_HIGH = 0;
0874: private static final int I_NORMAL = 1;
0875: private static final int I_DRAFT = 2;
0876:
0877: private static final String NAMES[] = { "high", "normal",
0878: "draft" };
0879:
0880: /**
0881: * The PrintQualityType instance to use for specifying a high print
0882: * quality.
0883: */
0884: public static final PrintQualityType HIGH = new PrintQualityType(
0885: I_HIGH);
0886: /**
0887: * The PrintQualityType instance to use for specifying a normal print
0888: * quality.
0889: */
0890: public static final PrintQualityType NORMAL = new PrintQualityType(
0891: I_NORMAL);
0892: /**
0893: * The PrintQualityType instance to use for specifying a draft print
0894: * quality.
0895: */
0896: public static final PrintQualityType DRAFT = new PrintQualityType(
0897: I_DRAFT);
0898:
0899: private PrintQualityType(int type) {
0900: super (type, NAMES);
0901: }
0902: }
0903:
0904: private ColorType color;
0905: private MediaType media;
0906: private OrientationRequestedType orientationRequested;
0907: private OriginType origin;
0908: private PrintQualityType printQuality;
0909: private int[] printerResolution;
0910:
0911: /**
0912: * Constructs a PageAttributes instance with default values for every
0913: * attribute.
0914: */
0915: public PageAttributes() {
0916: setColor(ColorType.MONOCHROME);
0917: setMediaToDefault();
0918: setOrientationRequestedToDefault();
0919: setOrigin(OriginType.PHYSICAL);
0920: setPrintQualityToDefault();
0921: setPrinterResolutionToDefault();
0922: }
0923:
0924: /**
0925: * Constructs a PageAttributes instance which is a copy of the supplied
0926: * PageAttributes.
0927: *
0928: * @param obj the PageAttributes to copy.
0929: */
0930: public PageAttributes(PageAttributes obj) {
0931: set(obj);
0932: }
0933:
0934: /**
0935: * Constructs a PageAttributes instance with the specified values for
0936: * every attribute.
0937: *
0938: * @param color ColorType.COLOR or ColorType.MONOCHROME.
0939: * @param media one of the constant fields of the MediaType class.
0940: * @param orientationRequested OrientationRequestedType.PORTRAIT or
0941: * OrientationRequestedType.LANDSCAPE.
0942: * @param origin OriginType.PHYSICAL or OriginType.PRINTABLE
0943: * @param printQuality PrintQualityType.DRAFT, PrintQualityType.NORMAL,
0944: * or PrintQualityType.HIGH
0945: * @param printerResolution an integer array of 3 elements. The first
0946: * element must be greater than 0. The second element must be
0947: * must be greater than 0. The third element must be either
0948: * <code>3</code> or <code>4</code>.
0949: * @throws IllegalArgumentException if one or more of the above
0950: * conditions is violated.
0951: */
0952: public PageAttributes(ColorType color, MediaType media,
0953: OrientationRequestedType orientationRequested,
0954: OriginType origin, PrintQualityType printQuality,
0955: int[] printerResolution) {
0956: setColor(color);
0957: setMedia(media);
0958: setOrientationRequested(orientationRequested);
0959: setOrigin(origin);
0960: setPrintQuality(printQuality);
0961: setPrinterResolution(printerResolution);
0962: }
0963:
0964: /**
0965: * Creates and returns a copy of this PageAttributes.
0966: *
0967: * @return the newly created copy. It is safe to cast this Object into
0968: * a PageAttributes.
0969: */
0970: public Object clone() {
0971: try {
0972: return super .clone();
0973: } catch (CloneNotSupportedException e) {
0974: // Since we implement Cloneable, this should never happen
0975: throw new InternalError();
0976: }
0977: }
0978:
0979: /**
0980: * Sets all of the attributes of this PageAttributes to the same values as
0981: * the attributes of obj.
0982: *
0983: * @param obj the PageAttributes to copy.
0984: */
0985: public void set(PageAttributes obj) {
0986: color = obj.color;
0987: media = obj.media;
0988: orientationRequested = obj.orientationRequested;
0989: origin = obj.origin;
0990: printQuality = obj.printQuality;
0991: // okay because we never modify the contents of printerResolution
0992: printerResolution = obj.printerResolution;
0993: }
0994:
0995: /**
0996: * Returns whether pages using these attributes will be rendered in
0997: * color or monochrome. This attribute is updated to the value chosen
0998: * by the user.
0999: *
1000: * @return ColorType.COLOR or ColorType.MONOCHROME.
1001: */
1002: public ColorType getColor() {
1003: return color;
1004: }
1005:
1006: /**
1007: * Specifies whether pages using these attributes will be rendered in
1008: * color or monochrome. Not specifying this attribute is equivalent to
1009: * specifying ColorType.MONOCHROME.
1010: *
1011: * @param color ColorType.COLOR or ColorType.MONOCHROME.
1012: * @throws IllegalArgumentException if color is null.
1013: */
1014: public void setColor(ColorType color) {
1015: if (color == null) {
1016: throw new IllegalArgumentException(
1017: "Invalid value for attribute " + "color");
1018: }
1019: this .color = color;
1020: }
1021:
1022: /**
1023: * Returns the paper size for pages using these attributes. This
1024: * attribute is updated to the value chosen by the user.
1025: *
1026: * @return one of the constant fields of the MediaType class.
1027: */
1028: public MediaType getMedia() {
1029: return media;
1030: }
1031:
1032: /**
1033: * Specifies the desired paper size for pages using these attributes. The
1034: * actual paper size will be determined by the limitations of the target
1035: * printer. If an exact match cannot be found, an implementation will
1036: * choose the closest possible match. Not specifying this attribute is
1037: * equivalent to specifying the default size for the default locale. The
1038: * default size for locales in the United States and Canada is
1039: * MediaType.NA_LETTER. The default size for all other locales is
1040: * MediaType.ISO_A4.
1041: *
1042: * @param media one of the constant fields of the MediaType class.
1043: * @throws IllegalArgumentException if media is null.
1044: */
1045: public void setMedia(MediaType media) {
1046: if (media == null) {
1047: throw new IllegalArgumentException(
1048: "Invalid value for attribute " + "media");
1049: }
1050: this .media = media;
1051: }
1052:
1053: /**
1054: * Sets the paper size for pages using these attributes to the default
1055: * size for the default locale. The default size for locales in the
1056: * United States and Canada is MediaType.NA_LETTER. The default size for
1057: * all other locales is MediaType.ISO_A4.
1058: */
1059: public void setMediaToDefault() {
1060: String defaultCountry = Locale.getDefault().getCountry();
1061: if (defaultCountry != null
1062: && (defaultCountry.equals(Locale.US.getCountry()) || defaultCountry
1063: .equals(Locale.CANADA.getCountry()))) {
1064: setMedia(MediaType.NA_LETTER);
1065: } else {
1066: setMedia(MediaType.ISO_A4);
1067: }
1068: }
1069:
1070: /**
1071: * Returns the print orientation for pages using these attributes. This
1072: * attribute is updated to the value chosen by the user.
1073: *
1074: * @return OrientationRequestedType.PORTRAIT or
1075: * OrientationRequestedType.LANDSCAPE.
1076: */
1077: public OrientationRequestedType getOrientationRequested() {
1078: return orientationRequested;
1079: }
1080:
1081: /**
1082: * Specifies the print orientation for pages using these attributes. Not
1083: * specifying the property is equivalent to specifying
1084: * OrientationRequestedType.PORTRAIT.
1085: *
1086: * @param orientationRequested OrientationRequestedType.PORTRAIT or
1087: * OrientationRequestedType.LANDSCAPE.
1088: * @throws IllegalArgumentException if orientationRequested is null.
1089: */
1090: public void setOrientationRequested(
1091: OrientationRequestedType orientationRequested) {
1092: if (orientationRequested == null) {
1093: throw new IllegalArgumentException(
1094: "Invalid value for attribute "
1095: + "orientationRequested");
1096: }
1097: this .orientationRequested = orientationRequested;
1098: }
1099:
1100: /**
1101: * Specifies the print orientation for pages using these attributes.
1102: * Specifying <code>3</code> denotes portrait. Specifying <code>4</code>
1103: * denotes landscape. Specifying any other value will generate an
1104: * IllegalArgumentException. Not specifying the property is equivalent
1105: * to calling setOrientationRequested(OrientationRequestedType.PORTRAIT).
1106: *
1107: * @param orientationRequested <code>3</code> or <code>4</code>
1108: * @throws IllegalArgumentException if orientationRequested is not
1109: * <code>3</code> or <code>4</code>
1110: */
1111: public void setOrientationRequested(int orientationRequested) {
1112: switch (orientationRequested) {
1113: case 3:
1114: setOrientationRequested(OrientationRequestedType.PORTRAIT);
1115: break;
1116: case 4:
1117: setOrientationRequested(OrientationRequestedType.LANDSCAPE);
1118: break;
1119: default:
1120: // This will throw an IllegalArgumentException
1121: setOrientationRequested(null);
1122: break;
1123: }
1124: }
1125:
1126: /**
1127: * Sets the print orientation for pages using these attributes to the
1128: * default. The default orientation is portrait.
1129: */
1130: public void setOrientationRequestedToDefault() {
1131: setOrientationRequested(OrientationRequestedType.PORTRAIT);
1132: }
1133:
1134: /**
1135: * Returns whether drawing at (0, 0) to pages using these attributes
1136: * draws at the upper-left corner of the physical page, or at the
1137: * upper-left corner of the printable area. (Note that these locations
1138: * could be equivalent.) This attribute cannot be modified by,
1139: * and is not subject to any limitations of, the implementation or the
1140: * target printer.
1141: *
1142: * @return OriginType.PHYSICAL or OriginType.PRINTABLE
1143: */
1144: public OriginType getOrigin() {
1145: return origin;
1146: }
1147:
1148: /**
1149: * Specifies whether drawing at (0, 0) to pages using these attributes
1150: * draws at the upper-left corner of the physical page, or at the
1151: * upper-left corner of the printable area. (Note that these locations
1152: * could be equivalent.) Not specifying the property is equivalent to
1153: * specifying OriginType.PHYSICAL.
1154: *
1155: * @param origin OriginType.PHYSICAL or OriginType.PRINTABLE
1156: * @throws IllegalArgumentException if origin is null.
1157: */
1158: public void setOrigin(OriginType origin) {
1159: if (origin == null) {
1160: throw new IllegalArgumentException(
1161: "Invalid value for attribute " + "origin");
1162: }
1163: this .origin = origin;
1164: }
1165:
1166: /**
1167: * Returns the print quality for pages using these attributes. This
1168: * attribute is updated to the value chosen by the user.
1169: *
1170: * @return PrintQualityType.DRAFT, PrintQualityType.NORMAL, or
1171: * PrintQualityType.HIGH
1172: */
1173: public PrintQualityType getPrintQuality() {
1174: return printQuality;
1175: }
1176:
1177: /**
1178: * Specifies the print quality for pages using these attributes. Not
1179: * specifying the property is equivalent to specifying
1180: * PrintQualityType.NORMAL.
1181: *
1182: * @param printQuality PrintQualityType.DRAFT, PrintQualityType.NORMAL,
1183: * or PrintQualityType.HIGH
1184: * @throws IllegalArgumentException if printQuality is null.
1185: */
1186: public void setPrintQuality(PrintQualityType printQuality) {
1187: if (printQuality == null) {
1188: throw new IllegalArgumentException(
1189: "Invalid value for attribute " + "printQuality");
1190: }
1191: this .printQuality = printQuality;
1192: }
1193:
1194: /**
1195: * Specifies the print quality for pages using these attributes.
1196: * Specifying <code>3</code> denotes draft. Specifying <code>4</code>
1197: * denotes normal. Specifying <code>5</code> denotes high. Specifying
1198: * any other value will generate an IllegalArgumentException. Not
1199: * specifying the property is equivalent to calling
1200: * setPrintQuality(PrintQualityType.NORMAL).
1201: *
1202: * @param printQuality <code>3</code>, <code>4</code>, or <code>5</code>
1203: * @throws IllegalArgumentException if printQuality is not <code>3
1204: * </code>, <code>4</code>, or <code>5</code>
1205: */
1206: public void setPrintQuality(int printQuality) {
1207: switch (printQuality) {
1208: case 3:
1209: setPrintQuality(PrintQualityType.DRAFT);
1210: break;
1211: case 4:
1212: setPrintQuality(PrintQualityType.NORMAL);
1213: break;
1214: case 5:
1215: setPrintQuality(PrintQualityType.HIGH);
1216: break;
1217: default:
1218: // This will throw an IllegalArgumentException
1219: setPrintQuality(null);
1220: break;
1221: }
1222: }
1223:
1224: /**
1225: * Sets the print quality for pages using these attributes to the default.
1226: * The default print quality is normal.
1227: */
1228: public void setPrintQualityToDefault() {
1229: setPrintQuality(PrintQualityType.NORMAL);
1230: }
1231:
1232: /**
1233: * Returns the print resolution for pages using these attributes.
1234: * Index 0 of the array specifies the cross feed direction resolution
1235: * (typically the horizontal resolution). Index 1 of the array specifies
1236: * the feed direction resolution (typically the vertical resolution).
1237: * Index 2 of the array specifies whether the resolutions are in dots per
1238: * inch or dots per centimeter. <code>3</code> denotes dots per inch.
1239: * <code>4</code> denotes dots per centimeter.
1240: *
1241: * @return an integer array of 3 elements. The first
1242: * element must be greater than 0. The second element must be
1243: * must be greater than 0. The third element must be either
1244: * <code>3</code> or <code>4</code>.
1245: */
1246: public int[] getPrinterResolution() {
1247: // Return a copy because otherwise client code could circumvent the
1248: // the checks made in setPrinterResolution by modifying the
1249: // returned array.
1250: int[] copy = new int[3];
1251: copy[0] = printerResolution[0];
1252: copy[1] = printerResolution[1];
1253: copy[2] = printerResolution[2];
1254: return copy;
1255: }
1256:
1257: /**
1258: * Specifies the desired print resolution for pages using these attributes.
1259: * The actual resolution will be determined by the limitations of the
1260: * implementation and the target printer. Index 0 of the array specifies
1261: * the cross feed direction resolution (typically the horizontal
1262: * resolution). Index 1 of the array specifies the feed direction
1263: * resolution (typically the vertical resolution). Index 2 of the array
1264: * specifies whether the resolutions are in dots per inch or dots per
1265: * centimeter. <code>3</code> denotes dots per inch. <code>4</code>
1266: * denotes dots per centimeter. Note that the 1.1 printing implementation
1267: * (Toolkit.getPrintJob) requires that the feed and cross feed resolutions
1268: * be the same. Not specifying the property is equivalent to calling
1269: * setPrinterResolution(72).
1270: *
1271: * @param printerResolution an integer array of 3 elements. The first
1272: * element must be greater than 0. The second element must be
1273: * must be greater than 0. The third element must be either
1274: * <code>3</code> or <code>4</code>.
1275: * @throws IllegalArgumentException if one or more of the above
1276: * conditions is violated.
1277: */
1278: public void setPrinterResolution(int[] printerResolution) {
1279: if (printerResolution == null
1280: || printerResolution.length != 3
1281: || printerResolution[0] <= 0
1282: || printerResolution[1] <= 0
1283: || (printerResolution[2] != 3 && printerResolution[2] != 4)) {
1284: throw new IllegalArgumentException(
1285: "Invalid value for attribute "
1286: + "printerResolution");
1287: }
1288: // Store a copy because otherwise client code could circumvent the
1289: // the checks made above by holding a reference to the array and
1290: // modifying it after calling setPrinterResolution.
1291: int[] copy = new int[3];
1292: copy[0] = printerResolution[0];
1293: copy[1] = printerResolution[1];
1294: copy[2] = printerResolution[2];
1295: this .printerResolution = copy;
1296: }
1297:
1298: /**
1299: * Specifies the desired cross feed and feed print resolutions in dots per
1300: * inch for pages using these attributes. The same value is used for both
1301: * resolutions. The actual resolutions will be determined by the
1302: * limitations of the implementation and the target printer. Not
1303: * specifying the property is equivalent to specifying <code>72</code>.
1304: *
1305: * @param printerResolution an integer greater than 0.
1306: * @throws IllegalArgumentException if printerResolution is less than or
1307: * equal to 0.
1308: */
1309: public void setPrinterResolution(int printerResolution) {
1310: setPrinterResolution(new int[] { printerResolution,
1311: printerResolution, 3 });
1312: }
1313:
1314: /**
1315: * Sets the printer resolution for pages using these attributes to the
1316: * default. The default is 72 dpi for both the feed and cross feed
1317: * resolutions.
1318: */
1319: public void setPrinterResolutionToDefault() {
1320: setPrinterResolution(72);
1321: }
1322:
1323: /**
1324: * Determines whether two PageAttributes are equal to each other.
1325: * <p>
1326: * Two PageAttributes are equal if and only if each of their attributes are
1327: * equal. Attributes of enumeration type are equal if and only if the
1328: * fields refer to the same unique enumeration object. This means that
1329: * an aliased media is equal to its underlying unique media. Printer
1330: * resolutions are equal if and only if the feed resolution, cross feed
1331: * resolution, and units are equal.
1332: *
1333: * @param obj the object whose equality will be checked.
1334: * @return whether obj is equal to this PageAttribute according to the
1335: * above criteria.
1336: */
1337: public boolean equals(Object obj) {
1338: if (!(obj instanceof PageAttributes)) {
1339: return false;
1340: }
1341:
1342: PageAttributes rhs = (PageAttributes) obj;
1343:
1344: return (color == rhs.color && media == rhs.media
1345: && orientationRequested == rhs.orientationRequested
1346: && origin == rhs.origin
1347: && printQuality == rhs.printQuality
1348: && printerResolution[0] == rhs.printerResolution[0]
1349: && printerResolution[1] == rhs.printerResolution[1] && printerResolution[2] == rhs.printerResolution[2]);
1350: }
1351:
1352: /**
1353: * Returns a hash code value for this PageAttributes.
1354: *
1355: * @return the hash code.
1356: */
1357: public int hashCode() {
1358: return (color.hashCode() << 31 ^ media.hashCode() << 24
1359: ^ orientationRequested.hashCode() << 23
1360: ^ origin.hashCode() << 22
1361: ^ printQuality.hashCode() << 20
1362: ^ printerResolution[2] >> 2 << 19
1363: ^ printerResolution[1] << 10 ^ printerResolution[0]);
1364: }
1365:
1366: /**
1367: * Returns a string representation of this PageAttributes.
1368: *
1369: * @return the string representation.
1370: */
1371: public String toString() {
1372: // int[] printerResolution = getPrinterResolution();
1373: return "color=" + getColor() + ",media=" + getMedia()
1374: + ",orientation-requested=" + getOrientationRequested()
1375: + ",origin=" + getOrigin() + ",print-quality="
1376: + getPrintQuality() + ",printer-resolution=["
1377: + printerResolution[0] + "," + printerResolution[1]
1378: + "," + printerResolution[2] + "]";
1379: }
1380: }
|