Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/print/attribute/standard/PageRanges.java
38918 views
/*1* Copyright (c) 2000, 2004, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.print.attribute.standard;2627import javax.print.attribute.Attribute;28import javax.print.attribute.SetOfIntegerSyntax;29import javax.print.attribute.DocAttribute;30import javax.print.attribute.PrintRequestAttribute;31import javax.print.attribute.PrintJobAttribute;3233/**34* Class PageRanges is a printing attribute class, a set of integers, that35* identifies the range(s) of print-stream pages that the Printer object uses36* for each copy of each document which are to be printed. Nothing is printed37* for any pages identified that do not exist in the document(s). The attribute38* is associated with <I>print-stream</I> pages, not application-numbered pages39* (for example, the page numbers found in the headers and or footers for40* certain word processing applications).41* <P>42* In most cases, the exact pages to be printed will be generated by a device43* driver and this attribute would not be required. However, when printing an44* archived document which has already been formatted, the end user may elect to45* print just a subset of the pages contained in the document. In this case, if46* a page range of <CODE>"<I>n</I>-<I>m</I>"</CODE> is specified, the first page47* to be printed will be page <I>n.</I> All subsequent pages of the document48* will be printed through and including page <I>m.</I>49* <P>50* If a PageRanges attribute is not specified for a print job, all pages of51* the document will be printed. In other words, the default value for the52* PageRanges attribute is always <CODE>{{1, Integer.MAX_VALUE}}</CODE>.53* <P>54* The effect of a PageRanges attribute on a multidoc print job (a job with55* multiple documents) depends on whether all the docs have the same page ranges56* specified or whether different docs have different page ranges specified, and57* on the (perhaps defaulted) value of the {@link MultipleDocumentHandling58* MultipleDocumentHandling} attribute.59* <UL>60* <LI>61* If all the docs have the same page ranges specified, then any value of {@link62* MultipleDocumentHandling MultipleDocumentHandling} makes sense, and the63* printer's processing depends on the {@link MultipleDocumentHandling64* MultipleDocumentHandling} value:65* <UL>66* <LI>67* SINGLE_DOCUMENT -- All the input docs will be combined together into one68* output document. The specified page ranges of that output document will be69* printed.70* <P>71* <LI>72* SINGLE_DOCUMENT_NEW_SHEET -- All the input docs will be combined together73* into one output document, and the first impression of each input doc will74* always start on a new media sheet. The specified page ranges of that output75* document will be printed.76* <P>77* <LI>78* SEPARATE_DOCUMENTS_UNCOLLATED_COPIES -- For each separate input doc, the79* specified page ranges will be printed.80* <P>81* <LI>82* SEPARATE_DOCUMENTS_COLLATED_COPIES -- For each separate input doc, the83* specified page ranges will be printed.84* </UL>85* <UL>86* <LI>87* SEPARATE_DOCUMENTS_UNCOLLATED_COPIES -- For each separate input doc, its own88* specified page ranges will be printed..89* <P>90* <LI>91* SEPARATE_DOCUMENTS_COLLATED_COPIES -- For each separate input doc, its own92* specified page ranges will be printed..93* </UL>94* </UL>95* <P>96* <B>IPP Compatibility:</B> The PageRanges attribute's canonical array form97* gives the lower and upper bound for each range of pages to be included in98* and IPP "page-ranges" attribute. See class {@link99* javax.print.attribute.SetOfIntegerSyntax SetOfIntegerSyntax} for an100* explanation of canonical array form. The category name returned by101* <CODE>getName()</CODE> gives the IPP attribute name.102* <P>103*104* @author David Mendenhall105* @author Alan Kaminsky106*/107public final class PageRanges extends SetOfIntegerSyntax108implements DocAttribute, PrintRequestAttribute, PrintJobAttribute {109110private static final long serialVersionUID = 8639895197656148392L;111112113/**114* Construct a new page ranges attribute with the given members. The115* members are specified in "array form;" see class {@link116* javax.print.attribute.SetOfIntegerSyntax SetOfIntegerSyntax} for an117* explanation of array form.118*119* @param members Set members in array form.120*121* @exception NullPointerException122* (unchecked exception) Thrown if <CODE>members</CODE> is null or123* any element of <CODE>members</CODE> is null.124* @exception IllegalArgumentException125* (unchecked exception) Thrown if any element of126* <CODE>members</CODE> is not a length-one or length-two array. Also127* thrown if <CODE>members</CODE> is a zero-length array or if any128* member of the set is less than 1.129*/130public PageRanges(int[][] members) {131super (members);132if (members == null) {133throw new NullPointerException("members is null");134}135myPageRanges();136}137/**138* Construct a new page ranges attribute with the given members in139* string form.140* See class {@link javax.print.attribute.SetOfIntegerSyntax141* SetOfIntegerSyntax}142* for explanation of the syntax.143*144* @param members Set members in string form.145*146* @exception NullPointerException147* (unchecked exception) Thrown if <CODE>members</CODE> is null or148* any element of <CODE>members</CODE> is null.149* @exception IllegalArgumentException150* (Unchecked exception) Thrown if <CODE>members</CODE> does not151* obey the proper syntax. Also152* thrown if the constructed set-of-integer is a153* zero-length array or if any154* member of the set is less than 1.155*/156public PageRanges(String members) {157super(members);158if (members == null) {159throw new NullPointerException("members is null");160}161myPageRanges();162}163164private void myPageRanges() {165int[][] myMembers = getMembers();166int n = myMembers.length;167if (n == 0) {168throw new IllegalArgumentException("members is zero-length");169}170int i;171for (i = 0; i < n; ++ i) {172if (myMembers[i][0] < 1) {173throw new IllegalArgumentException("Page value < 1 specified");174}175}176}177178/**179* Construct a new page ranges attribute containing a single integer. That180* is, only the one page is to be printed.181*182* @param member Set member.183*184* @exception IllegalArgumentException185* (Unchecked exception) Thrown if <CODE>member</CODE> is less than186* 1.187*/188public PageRanges(int member) {189super (member);190if (member < 1) {191throw new IllegalArgumentException("Page value < 1 specified");192}193}194195/**196* Construct a new page ranges attribute containing a single range of197* integers. That is, only those pages in the one range are to be printed.198*199* @param lowerBound Lower bound of the range.200* @param upperBound Upper bound of the range.201*202* @exception IllegalArgumentException203* (Unchecked exception) Thrown if a null range is specified or if a204* non-null range is specified with <CODE>lowerBound</CODE> less than205* 1.206*/207public PageRanges(int lowerBound, int upperBound) {208super (lowerBound, upperBound);209if (lowerBound > upperBound) {210throw new IllegalArgumentException("Null range specified");211} else if (lowerBound < 1) {212throw new IllegalArgumentException("Page value < 1 specified");213}214}215216/**217* Returns whether this page ranges attribute is equivalent to the passed218* in object. To be equivalent, all of the following conditions must be219* true:220* <OL TYPE=1>221* <LI>222* <CODE>object</CODE> is not null.223* <LI>224* <CODE>object</CODE> is an instance of class PageRanges.225* <LI>226* This page ranges attribute's members and <CODE>object</CODE>'s members227* are the same.228* </OL>229*230* @param object Object to compare to.231*232* @return True if <CODE>object</CODE> is equivalent to this page ranges233* attribute, false otherwise.234*/235public boolean equals(Object object) {236return (super.equals(object) && object instanceof PageRanges);237}238239/**240* Get the printing attribute class which is to be used as the "category"241* for this printing attribute value.242* <P>243* For class PageRanges, the category is class PageRanges itself.244*245* @return Printing attribute class (category), an instance of class246* {@link java.lang.Class java.lang.Class}.247*/248public final Class<? extends Attribute> getCategory() {249return PageRanges.class;250}251252/**253* Get the name of the category of which this attribute value is an254* instance.255* <P>256* For class PageRanges, the category name is <CODE>"page-ranges"</CODE>.257*258* @return Attribute category name.259*/260public final String getName() {261return "page-ranges";262}263264}265266267