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