1. /*
  2. * @(#)PageRanges.java 1.7 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.print.attribute.standard;
  8. import javax.print.attribute.SetOfIntegerSyntax;
  9. import javax.print.attribute.DocAttribute;
  10. import javax.print.attribute.PrintRequestAttribute;
  11. import javax.print.attribute.PrintJobAttribute;
  12. /**
  13. * Class PageRanges is a printing attribute class, a set of integers, that
  14. * identifies the range(s) of print-stream pages that the Printer object uses
  15. * for each copy of each document which are to be printed. Nothing is printed
  16. * for any pages identified that do not exist in the document(s). The attribute
  17. * is associated with <I>print-stream</I> pages, not application-numbered pages
  18. * (for example, the page numbers found in the headers and or footers for
  19. * certain word processing applications).
  20. * <P>
  21. * In most cases, the exact pages to be printed will be generated by a device
  22. * driver and this attribute would not be required. However, when printing an
  23. * archived document which has already been formatted, the end user may elect to
  24. * print just a subset of the pages contained in the document. In this case, if
  25. * a page range of <CODE>"<I>n</I>-<I>m</I>"</CODE> is specified, the first page
  26. * to be printed will be page <I>n.</I> All subsequent pages of the document
  27. * will be printed through and including page <I>m.</I>
  28. * <P>
  29. * If a PageRanges attribute is not specified for a print job, all pages of
  30. * the document will be printed. In other words, the default value for the
  31. * PageRanges attribute is always <CODE>{{1, Integer.MAX_VALUE}}</CODE>.
  32. * <P>
  33. * The effect of a PageRanges attribute on a multidoc print job (a job with
  34. * multiple documents) depends on whether all the docs have the same page ranges
  35. * specified or whether different docs have different page ranges specified, and
  36. * on the (perhaps defaulted) value of the {@link MultipleDocumentHandling
  37. * MultipleDocumentHandling} attribute.
  38. * <UL>
  39. * <LI>
  40. * If all the docs have the same page ranges specified, then any value of {@link
  41. * MultipleDocumentHandling MultipleDocumentHandling} makes sense, and the
  42. * printer's processing depends on the {@link MultipleDocumentHandling
  43. * MultipleDocumentHandling} value:
  44. * <UL>
  45. * <LI>
  46. * SINGLE_DOCUMENT -- All the input docs will be combined together into one
  47. * output document. The specified page ranges of that output document will be
  48. * printed.
  49. * <P>
  50. * <LI>
  51. * SINGLE_DOCUMENT_NEW_SHEET -- All the input docs will be combined together
  52. * into one output document, and the first impression of each input doc will
  53. * always start on a new media sheet. The specified page ranges of that output
  54. * document will be printed.
  55. * <P>
  56. * <LI>
  57. * SEPARATE_DOCUMENTS_UNCOLLATED_COPIES -- For each separate input doc, the
  58. * specified page ranges will be printed.
  59. * <P>
  60. * <LI>
  61. * SEPARATE_DOCUMENTS_COLLATED_COPIES -- For each separate input doc, the
  62. * specified page ranges will be printed.
  63. * </UL>
  64. * <UL>
  65. * <LI>
  66. * SEPARATE_DOCUMENTS_UNCOLLATED_COPIES -- For each separate input doc, its own
  67. * specified page ranges will be printed..
  68. * <P>
  69. * <LI>
  70. * SEPARATE_DOCUMENTS_COLLATED_COPIES -- For each separate input doc, its own
  71. * specified page ranges will be printed..
  72. * </UL>
  73. * </UL>
  74. * <P>
  75. * <B>IPP Compatibility:</B> The PageRanges attribute's canonical array form
  76. * gives the lower and upper bound for each range of pages to be included in
  77. * and IPP "page-ranges" attribute. See class {@link
  78. * javax.print.attribute.SetOfIntegerSyntax SetOfIntegerSyntax} for an
  79. * explanation of canonical array form. The category name returned by
  80. * <CODE>getName()</CODE> gives the IPP attribute name.
  81. * <P>
  82. *
  83. * @author David Mendenhall
  84. * @author Alan Kaminsky
  85. */
  86. public final class PageRanges extends SetOfIntegerSyntax
  87. implements DocAttribute, PrintRequestAttribute, PrintJobAttribute {
  88. /**
  89. * Construct a new page ranges attribute with the given members. The
  90. * members are specified in "array form;" see class {@link
  91. * javax.print.attribute.SetOfIntegerSyntax SetOfIntegerSyntax} for an
  92. * explanation of array form.
  93. *
  94. * @param members Set members in array form.
  95. *
  96. * @exception NullPointerException
  97. * (unchecked exception) Thrown if <CODE>members</CODE> is null or
  98. * any element of <CODE>members</CODE> is null.
  99. * @exception IllegalArgumentException
  100. * (unchecked exception) Thrown if any element of
  101. * <CODE>members</CODE> is not a length-one or length-two array. Also
  102. * thrown if <CODE>members</CODE> is a zero-length array or if any
  103. * member of the set is less than 1.
  104. */
  105. public PageRanges(int[][] members) {
  106. super (members);
  107. if (members == null) {
  108. throw new NullPointerException("members is null");
  109. }
  110. myPageRanges();
  111. }
  112. /**
  113. * Construct a new page ranges attribute with the given members in
  114. * string form.
  115. * See class {@link javax.print.attribute.SetOfIntegerSyntax
  116. * SetOfIntegerSyntax}
  117. * for explanation of the syntax.
  118. *
  119. * @param members Set members in string form.
  120. *
  121. * @exception NullPointerException
  122. * (unchecked exception) Thrown if <CODE>members</CODE> is null or
  123. * any element of <CODE>members</CODE> is null.
  124. * @exception IllegalArgumentException
  125. * (Unchecked exception) Thrown if <CODE>members</CODE> does not
  126. * obey the proper syntax. Also
  127. * thrown if the constructed set-of-integer is a
  128. * zero-length array or if any
  129. * member of the set is less than 1.
  130. */
  131. public PageRanges(String members) {
  132. super(members);
  133. if (members == null) {
  134. throw new NullPointerException("members is null");
  135. }
  136. myPageRanges();
  137. }
  138. private void myPageRanges() {
  139. int[][] myMembers = getMembers();
  140. int n = myMembers.length;
  141. if (n == 0) {
  142. throw new IllegalArgumentException("members is zero-length");
  143. }
  144. int i;
  145. for (i = 0; i < n; ++ i) {
  146. if (myMembers[i][0] < 1) {
  147. throw new IllegalArgumentException("Page value < 1 specified");
  148. }
  149. }
  150. }
  151. /**
  152. * Construct a new page ranges attribute containing a single integer. That
  153. * is, only the one page is to be printed.
  154. *
  155. * @param member Set member.
  156. *
  157. * @exception IllegalArgumentException
  158. * (Unchecked exception) Thrown if <CODE>member</CODE> is less than
  159. * 1.
  160. */
  161. public PageRanges(int member) {
  162. super (member);
  163. if (member < 1) {
  164. throw new IllegalArgumentException("Page value < 1 specified");
  165. }
  166. }
  167. /**
  168. * Construct a new page ranges attribute containing a single range of
  169. * integers. That is, only those pages in the one range are to be printed.
  170. *
  171. * @param lowerBound Lower bound of the range.
  172. * @param upperBound Upper bound of the range.
  173. *
  174. * @exception IllegalArgumentException
  175. * (Unchecked exception) Thrown if a null range is specified or if a
  176. * non-null range is specified with <CODE>lowerBound</CODE> less than
  177. * 1.
  178. */
  179. public PageRanges(int lowerBound, int upperBound) {
  180. super (lowerBound, upperBound);
  181. if (lowerBound > upperBound) {
  182. throw new IllegalArgumentException("Null range specified");
  183. } else if (lowerBound < 1) {
  184. throw new IllegalArgumentException("Page value < 1 specified");
  185. }
  186. }
  187. /**
  188. * Returns whether this page ranges attribute is equivalent to the passed
  189. * in object. To be equivalent, all of the following conditions must be
  190. * true:
  191. * <OL TYPE=1>
  192. * <LI>
  193. * <CODE>object</CODE> is not null.
  194. * <LI>
  195. * <CODE>object</CODE> is an instance of class PageRanges.
  196. * <LI>
  197. * This page ranges attribute's members and <CODE>object</CODE>'s members
  198. * are the same.
  199. * </OL>
  200. *
  201. * @param object Object to compare to.
  202. *
  203. * @return True if <CODE>object</CODE> is equivalent to this page ranges
  204. * attribute, false otherwise.
  205. */
  206. public boolean equals(Object object) {
  207. return (super.equals(object) && object instanceof PageRanges);
  208. }
  209. /**
  210. * Get the printing attribute class which is to be used as the "category"
  211. * for this printing attribute value.
  212. * <P>
  213. * For class PageRanges, the category is class PageRanges itself.
  214. *
  215. * @return Printing attribute class (category), an instance of class
  216. * {@link java.lang.Class java.lang.Class}.
  217. */
  218. public final Class getCategory() {
  219. return PageRanges.class;
  220. }
  221. /**
  222. * Get the name of the category of which this attribute value is an
  223. * instance.
  224. * <P>
  225. * For class PageRanges, the category name is <CODE>"page-ranges"</CODE>.
  226. *
  227. * @return Attribute category name.
  228. */
  229. public final String getName() {
  230. return "page-ranges";
  231. }
  232. }