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