1 /*
   2  * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javax.print.attribute.standard;
  27 
  28 import javax.print.attribute.Attribute;
  29 import javax.print.attribute.DocAttribute;
  30 import javax.print.attribute.IntegerSyntax;
  31 import javax.print.attribute.PrintJobAttribute;
  32 import javax.print.attribute.PrintRequestAttribute;
  33 
  34 /**
  35  * Class {@code NumberUp} is an integer valued printing attribute class that
  36  * specifies the number of print-stream pages to impose upon a single side of an
  37  * instance of a selected medium. That is, if the NumberUp value is <i>n,</i>
  38  * the printer must place <i>n</i> print-stream pages on a single side of an
  39  * instance of the selected medium. To accomplish this, the printer may add some
  40  * sort of translation, scaling, or rotation. This attribute primarily controls
  41  * the translation, scaling and rotation of print-stream pages.
  42  * <p>
  43  * The effect of a {@code NumberUp} attribute on a multidoc print job (a job
  44  * with multiple documents) depends on whether all the docs have the same number
  45  * up values specified or whether different docs have different number up values
  46  * specified, and on the (perhaps defaulted) value of the
  47  * {@link MultipleDocumentHandling MultipleDocumentHandling} attribute.
  48  * <ul>
  49  *   <li>If all the docs have the same number up value <i>n</i> specified, then
  50  *   any value of {@link MultipleDocumentHandling MultipleDocumentHandling}
  51  *   makes sense, and the printer's processing depends on the
  52  *   {@link MultipleDocumentHandling MultipleDocumentHandling} value:
  53  *   <ul>
  54  *     <li>{@code SINGLE_DOCUMENT} -- All the input docs will be combined
  55  *     together into one output document. Each media impression will consist of
  56  *     <i>n</i>m print-stream pages from the output document.
  57  *     <li>{@code SINGLE_DOCUMENT_NEW_SHEET} -- All the input docs will be
  58  *     combined together into one output document. Each media impression will
  59  *     consist of <i>n</i> print-stream pages from the output document. However,
  60  *     the first impression of each input doc will always start on a new media
  61  *     sheet; this means the last impression of an input doc may have fewer than
  62  *     <i>n</i> print-stream pages on it.
  63  *     <li>{@code SEPARATE_DOCUMENTS_UNCOLLATED_COPIES} -- The input docs will
  64  *     remain separate. Each media impression will consist of <i>n</i>
  65  *     print-stream pages from the input doc. Since the input docs are separate,
  66  *     the first impression of each input doc will always start on a new media
  67  *     sheet; this means the last impression of an input doc may have fewer than
  68  *     <i>n</i> print-stream pages on it.
  69  *     <li>{@code SEPARATE_DOCUMENTS_COLLATED_COPIES} -- The input docs will
  70  *     remain separate. Each media impression will consist of <i>n</i>
  71  *     print-stream pages from the input doc. Since the input docs are separate,
  72  *     the first impression of each input doc will always start on a new media
  73  *     sheet; this means the last impression of an input doc may have fewer than
  74  *     <i>n</i> print-stream pages on it.
  75  *   </ul>
  76  *   <ul>
  77  *     <li>{@code SINGLE_DOCUMENT} -- All the input docs will be combined
  78  *     together into one output document. Each media impression will consist of
  79  *     <i>n<sub>i</sub></i> print-stream pages from the output document, where
  80  *     <i>i</i> is the number of the input doc corresponding to that point in
  81  *     the output document. When the next input doc has a different number up
  82  *     value from the previous input doc, the first print-stream page of the
  83  *     next input doc goes at the start of the next media impression, possibly
  84  *     leaving fewer than the full number of print-stream pages on the previous
  85  *     media impression.
  86  *     <li>{@code SINGLE_DOCUMENT_NEW_SHEET} -- All the input docs will be
  87  *     combined together into one output document. Each media impression will
  88  *     consist of <i>n</i> print-stream pages from the output document. However,
  89  *     the first impression of each input doc will always start on a new media
  90  *     sheet; this means the last impression of an input doc may have fewer than
  91  *     <i>n</i> print-stream pages on it.
  92  *     <li>{@code SEPARATE_DOCUMENTS_UNCOLLATED_COPIES} -- The input docs will
  93  *     remain separate. For input doc <i>i,</i> each media impression will
  94  *     consist of <i>n<sub>i</sub></i> print-stream pages from the input doc.
  95  *     Since the input docs are separate, the first impression of each input doc
  96  *     will always start on a new media sheet; this means the last impression of
  97  *     an input doc may have fewer than <i>n<sub>i</sub></i> print-stream pages
  98  *     on it.
  99  *     <li>{@code SEPARATE_DOCUMENTS_COLLATED_COPIES} -- The input docs will
 100  *     remain separate. For input doc <i>i,</i> each media impression will
 101  *     consist of <i>n<sub>i</sub></i> print-stream pages from the input doc.
 102  *     Since the input docs are separate, the first impression of each input doc
 103  *     will always start on a new media sheet; this means the last impression of
 104  *     an input doc may have fewer than <i>n<sub>i</sub></i> print-stream pages
 105  *     on it.
 106  *   </ul>
 107  * </ul>
 108  * <b>IPP Compatibility:</b> The integer value gives the IPP integer value. The
 109  * category name returned by {@code getName()} gives the IPP attribute name.
 110  *
 111  * @author Alan Kaminsky
 112  */
 113 public final class NumberUp extends IntegerSyntax
 114     implements DocAttribute, PrintRequestAttribute, PrintJobAttribute {
 115 
 116     /**
 117      * Use serialVersionUID from JDK 1.4 for interoperability.
 118      */
 119     private static final long serialVersionUID = -3040436486786527811L;
 120 
 121     /**
 122      * Construct a new number up attribute with the given integer value.
 123      *
 124      * @param  value Integer value
 125      * @throws IllegalArgumentException if {@code value < 1}
 126      */
 127     public NumberUp(int value) {
 128         super (value, 1, Integer.MAX_VALUE);
 129     }
 130 
 131     /**
 132      * Returns whether this number up attribute is equivalent to the passed in
 133      * object. To be equivalent, all of the following conditions must be true:
 134      * <ol type=1>
 135      *   <li>{@code object} is not {@code null}.
 136      *   <li>{@code object} is an instance of class {@code NumberUp}.
 137      *   <li>This number up attribute's value and {@code object}'s value are
 138      *   equal.
 139      * </ol>
 140      *
 141      * @param  object {@code Object} to compare to
 142      * @return {@code true} if {@code object} is equivalent to this number up
 143      *         attribute, {@code false} otherwise
 144      */
 145     public boolean equals(Object object) {
 146         return (super.equals(object) && object instanceof NumberUp);
 147     }
 148 
 149     /**
 150      * Get the printing attribute class which is to be used as the "category"
 151      * for this printing attribute value.
 152      * <p>
 153      * For class {@code NumberUp}, the category is class {@code NumberUp}
 154      * itself.
 155      *
 156      * @return printing attribute class (category), an instance of class
 157      *         {@link Class java.lang.Class}
 158      */
 159     public final Class<? extends Attribute> getCategory() {
 160         return NumberUp.class;
 161     }
 162 
 163     /**
 164      * Get the name of the category of which this attribute value is an
 165      * instance.
 166      * <p>
 167      * For class {@code NumberUp}, the category name is {@code "number-up"}.
 168      *
 169      * @return attribute category name
 170      */
 171     public final String getName() {
 172         return "number-up";
 173     }
 174 }