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