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.PrintJobAttribute;
31 import javax.print.attribute.PrintRequestAttribute;
32 import javax.print.attribute.ResolutionSyntax;
33 
34 /**
35  * Class {@code PrinterResolution} is a printing attribute class that specifies
36  * an exact resolution supported by a printer or to be used for a print job.
37  * This attribute assumes that printers have a small set of device resolutions
38  * at which they can operate rather than a continuum.
39  * <p>
40  * {@code PrinterResolution} is used in multiple ways:
41  * <ol type=1>
42  *   <li>When a client searches looking for a printer that supports the client's
43  *   desired resolution exactly (no more, no less), the client specifies an
44  *   instance of class {@code PrinterResolution} indicating the exact resolution
45  *   the client wants. Only printers supporting that exact resolution will match
46  *   the search.
47  *   <li>When a client needs to print a job using the client's desired
48  *   resolution exactly (no more, no less), the client specifies an instance of
49  *   class {@code PrinterResolution} as an attribute of the Print Job. This will
50  *   fail if the Print Job doesn't support that exact resolution, and
51  *   {@code Fidelity} is set to true.
52  * </ol>
53  * If a client wants to locate a printer supporting a resolution greater than
54  * some required minimum, then it may be necessary to exclude this attribute
55  * from a lookup request and to directly query the set of supported resolutions,
56  * and specify the one that most closely meets the client's requirements. In
57  * some cases this may be more simply achieved by specifying a
58  * {@code PrintQuality} attribute which often controls resolution.
59  * <p>
60  * <b>IPP Compatibility:</b> The information needed to construct an IPP
61  * {@code "printer-resolution"} attribute can be obtained by calling methods on
62  * the PrinterResolution object. The category name returned by {@code getName()}
63  * gives the IPP attribute name.
64  *
65  * @author David Mendenhall
66  * @author Alan Kaminsky
67  */
68 public final class PrinterResolution    extends ResolutionSyntax
69         implements DocAttribute, PrintRequestAttribute, PrintJobAttribute {
70 
71     /**
72      * Use serialVersionUID from JDK 1.4 for interoperability.
73      */
74     private static final long serialVersionUID = 13090306561090558L;
75 
76     /**
77      * Construct a new printer resolution attribute from the given items.
78      *
79      * @param  crossFeedResolution cross feed direction resolution
80      * @param  feedResolution feed direction resolution
81      * @param  units unit conversion factor, e.g. {@code ResolutionSyntax.DPI}
82      *         or {@code ResolutionSyntax.DPCM}
83      * @throws IllegalArgumentException if {@code crossFeedResolution < 1} or
84      *         {@code feedResolution < 1} or {@code units < 1}
85      */
PrinterResolution(int crossFeedResolution, int feedResolution, int units)86     public PrinterResolution(int crossFeedResolution, int feedResolution,
87                              int units) {
88         super (crossFeedResolution, feedResolution, units);
89     }
90 
91     /**
92      * Returns whether this printer resolution attribute is equivalent to the
93      * passed in object. To be equivalent, all of the following conditions must
94      * be true:
95      * <ol type=1>
96      *   <li>{@code object} is not {@code null}.
97      *   <li>{@code object} is an instance of class {@code PrinterResolution}.
98      *   <li>This attribute's cross feed direction resolution is equal to
99      *   {@code object}'s cross feed direction resolution.
100      *   <li>This attribute's feed direction resolution is equal to
101      *   {@code object}'s feed direction resolution.
102      * </ol>
103      *
104      * @param  object {@code Object} to compare to
105      * @return {@code true} if {@code object} is equivalent to this printer
106      *         resolution attribute, {@code false} otherwise
107      */
equals(Object object)108     public boolean equals(Object object) {
109         return (super.equals (object) &&
110                 object instanceof PrinterResolution);
111     }
112 
113     /**
114      * Get the printing attribute class which is to be used as the "category"
115      * for this printing attribute value.
116      * <p>
117      * For class {@code PrinterResolution}, the category is class
118      * {@code PrinterResolution} itself.
119      *
120      * @return printing attribute class (category), an instance of class
121      *         {@link Class java.lang.Class}
122      */
getCategory()123     public final Class<? extends Attribute> getCategory() {
124         return PrinterResolution.class;
125     }
126 
127     /**
128      * Get the name of the category of which this attribute value is an
129      * instance.
130      * <p>
131      * For class {@code PrinterResolution}, the category name is
132      * {@code "printer-resolution"}.
133      *
134      * @return attribute category name
135      */
getName()136     public final String getName() {
137         return "printer-resolution";
138     }
139 }
140