jdk/src/share/classes/javax/print/attribute/Size2DSyntax.java
author lana
Thu, 26 Dec 2013 12:04:16 -0800
changeset 23010 6dadb192ad81
parent 19166 e6cd1eb44237
child 24969 afa6934dd8e8
permissions -rw-r--r--
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013 Summary: updated files with 2011, 2012 and 2013 years according to the file's last updated date Reviewed-by: tbell, lancea, chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 19166
diff changeset
     2
 * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
package javax.print.attribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * Class Size2DSyntax is an abstract base class providing the common
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * implementation of all attributes denoting a size in two dimensions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * A two-dimensional size attribute's value consists of two items, the X
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * dimension and the Y dimension. A two-dimensional size attribute may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * constructed by supplying the two values and indicating the units in which the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * values are measured. Methods are provided to return a two-dimensional size
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * attribute's values, indicating the units in which the values are to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * returned. The two most common size units are inches (in) and millimeters
19166
e6cd1eb44237 8022175: Fix doclint warnings in javax.print
prr
parents: 5506
diff changeset
    41
 * (mm), and exported constants {@link #INCH INCH} and {@link #MM
e6cd1eb44237 8022175: Fix doclint warnings in javax.print
prr
parents: 5506
diff changeset
    42
 * MM} are provided for indicating those units.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * Once constructed, a two-dimensional size attribute's value is immutable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <B>Design</B>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * A two-dimensional size attribute's X and Y dimension values are stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * internally as integers in units of micrometers (&#181;m), where 1 micrometer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * = 10<SUP>-6</SUP> meter = 1/1000 millimeter = 1/25400 inch. This permits
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * dimensions to be represented exactly to a precision of 1/1000 mm (= 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * &#181;m) or 1/100 inch (= 254 &#181;m). If fractional inches are expressed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * negative powers of two, this permits dimensions to be represented exactly to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * a precision of 1/8 inch (= 3175 &#181;m) but not 1/16 inch (because 1/16 inch
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * does not equal an integral number of &#181;m).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * Storing the dimensions internally in common units of &#181;m lets two size
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * attributes be compared without regard to the units in which they were
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * created; for example, 8.5 in will compare equal to 215.9 mm, as they both are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * stored as 215900 &#181;m. For example, a lookup service can
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * match resolution attributes based on equality of their serialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * representations regardless of the units in which they were created. Using
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * integers for internal storage allows precise equality comparisons to be done,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * which would not be guaranteed if an internal floating point representation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * were used. Note that if you're looking for U.S. letter sized media in metric
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * units, you have to search for a media size of 215.9 x 279.4 mm; rounding off
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * to an integral 216 x 279 mm will not match.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * <P>
19166
e6cd1eb44237 8022175: Fix doclint warnings in javax.print
prr
parents: 5506
diff changeset
    69
 * The exported constant {@link #INCH INCH} is actually the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * conversion factor by which to multiply a value in inches to get the value in
19166
e6cd1eb44237 8022175: Fix doclint warnings in javax.print
prr
parents: 5506
diff changeset
    71
 * &#181;m. Likewise, the exported constant {@link #MM MM} is the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * conversion factor by which to multiply a value in mm to get the value in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * &#181;m. A client can specify a resolution value in units other than inches
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * or mm by supplying its own conversion factor. However, since the internal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * units of &#181;m was chosen with supporting only the external units of inch
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * and mm in mind, there is no guarantee that the conversion factor for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * client's units will be an exact integer. If the conversion factor isn't an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * exact integer, resolution values in the client's units won't be stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * precisely.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * @author  Alan Kaminsky
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
public abstract class Size2DSyntax implements Serializable, Cloneable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    private static final long serialVersionUID = 5584439964938660530L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * X dimension in units of micrometers (&#181;m).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    private int x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * Y dimension in units of micrometers (&#181;m).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private int y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * Value to indicate units of inches (in). It is actually the conversion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * factor by which to multiply inches to yield &#181;m (25400).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    public static final int INCH = 25400;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * Value to indicate units of millimeters (mm). It is actually the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * conversion factor by which to multiply mm to yield &#181;m (1000).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    public static final int MM = 1000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * Construct a new two-dimensional size attribute from the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * floating-point values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * @param  x  X dimension.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @param  y  Y dimension.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * @param  units
19166
e6cd1eb44237 8022175: Fix doclint warnings in javax.print
prr
parents: 5506
diff changeset
   120
     *     Unit conversion factor, e.g. {@link #INCH INCH} or
e6cd1eb44237 8022175: Fix doclint warnings in javax.print
prr
parents: 5506
diff changeset
   121
     *     {@link #MM MM}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @exception  IllegalArgumentException
19166
e6cd1eb44237 8022175: Fix doclint warnings in javax.print
prr
parents: 5506
diff changeset
   124
     *     (Unchecked exception) Thrown if {@code x < 0} or {@code y < 0} or
e6cd1eb44237 8022175: Fix doclint warnings in javax.print
prr
parents: 5506
diff changeset
   125
     *     {@code units < 1}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    protected Size2DSyntax(float x, float y, int units) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        if (x < 0.0f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            throw new IllegalArgumentException("x < 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        if (y < 0.0f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            throw new IllegalArgumentException("y < 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        if (units < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            throw new IllegalArgumentException("units < 1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        this.x = (int) (x * units + 0.5f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        this.y = (int) (y * units + 0.5f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * Construct a new two-dimensional size attribute from the given integer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @param  x  X dimension.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * @param  y  Y dimension.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * @param  units
19166
e6cd1eb44237 8022175: Fix doclint warnings in javax.print
prr
parents: 5506
diff changeset
   148
     *     Unit conversion factor, e.g. {@link #INCH INCH} or
e6cd1eb44237 8022175: Fix doclint warnings in javax.print
prr
parents: 5506
diff changeset
   149
     *     {@link #MM MM}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * @exception  IllegalArgumentException
19166
e6cd1eb44237 8022175: Fix doclint warnings in javax.print
prr
parents: 5506
diff changeset
   152
     *   (Unchecked exception) Thrown if {@code x < 0} or {@code y < 0}
e6cd1eb44237 8022175: Fix doclint warnings in javax.print
prr
parents: 5506
diff changeset
   153
     *    or {@code units < 1}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    protected Size2DSyntax(int x, int y, int units) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        if (x < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            throw new IllegalArgumentException("x < 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        if (y < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            throw new IllegalArgumentException("y < 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        if (units < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            throw new IllegalArgumentException("units < 1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        this.x = x * units;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        this.y = y * units;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * Convert a value from micrometers to some other units. The result is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * returned as a floating-point number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * @param  x
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *     Value (micrometers) to convert.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * @param  units
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *     Unit conversion factor, e.g. {@link #INCH <CODE>INCH</CODE>} or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *     {@link #MM <CODE>MM</CODE>}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @return  The value of <CODE>x</CODE> converted to the desired units.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @exception  IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *     (unchecked exception) Thrown if <CODE>units</CODE> < 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    private static float convertFromMicrometers(int x, int units) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        if (units < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            throw new IllegalArgumentException("units is < 1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        return ((float)x) / ((float)units);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * Get this two-dimensional size attribute's dimensions in the given units
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * as floating-point values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @param  units
19166
e6cd1eb44237 8022175: Fix doclint warnings in javax.print
prr
parents: 5506
diff changeset
   196
     *     Unit conversion factor, e.g. {@link #INCH INCH} or {@link #MM MM}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @return  A two-element array with the X dimension at index 0 and the Y
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *          dimension at index 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @exception  IllegalArgumentException
19166
e6cd1eb44237 8022175: Fix doclint warnings in javax.print
prr
parents: 5506
diff changeset
   202
     *     (unchecked exception) Thrown if {@code units < 1}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    public float[] getSize(int units) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        return new float[] {getX(units), getY(units)};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * Returns this two-dimensional size attribute's X dimension in the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * units as a floating-point value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * @param  units
19166
e6cd1eb44237 8022175: Fix doclint warnings in javax.print
prr
parents: 5506
diff changeset
   213
     *     Unit conversion factor, e.g. {@link #INCH INCH} or {@link #MM MM}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @return  X dimension.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * @exception  IllegalArgumentException
19166
e6cd1eb44237 8022175: Fix doclint warnings in javax.print
prr
parents: 5506
diff changeset
   218
     *     (unchecked exception) Thrown if {@code units < 1}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    public float getX(int units) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        return convertFromMicrometers(x, units);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * Returns this two-dimensional size attribute's Y dimension in the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * units as a floating-point value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * @param  units
19166
e6cd1eb44237 8022175: Fix doclint warnings in javax.print
prr
parents: 5506
diff changeset
   229
     *     Unit conversion factor, e.g. {@link #INCH INCH} or {@link #MM MM}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * @return  Y dimension.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @exception  IllegalArgumentException
19166
e6cd1eb44237 8022175: Fix doclint warnings in javax.print
prr
parents: 5506
diff changeset
   234
     *     (unchecked exception) Thrown if {@code units < 1}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    public float getY(int units) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        return convertFromMicrometers(y, units);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * Returns a string version of this two-dimensional size attribute in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * given units. The string takes the form <CODE>"<I>X</I>x<I>Y</I>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * <I>U</I>"</CODE>, where <I>X</I> is the X dimension, <I>Y</I> is the Y
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * dimension, and <I>U</I> is the units name. The values are displayed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * floating point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @param  units
19166
e6cd1eb44237 8022175: Fix doclint warnings in javax.print
prr
parents: 5506
diff changeset
   248
     *     Unit conversion factor, e.g. {@link #INCH INCH} or {@link #MM MM}.
e6cd1eb44237 8022175: Fix doclint warnings in javax.print
prr
parents: 5506
diff changeset
   249
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * @param  unitsName
19166
e6cd1eb44237 8022175: Fix doclint warnings in javax.print
prr
parents: 5506
diff changeset
   251
     *     Units name string, e.g. {@code in} or {@code mm}. If
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     *     null, no units name is appended to the result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * @return  String version of this two-dimensional size attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @exception  IllegalArgumentException
19166
e6cd1eb44237 8022175: Fix doclint warnings in javax.print
prr
parents: 5506
diff changeset
   257
     *     (unchecked exception) Thrown if {@code units < 1}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    public String toString(int units, String unitsName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        StringBuffer result = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        result.append(getX (units));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        result.append('x');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        result.append(getY (units));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        if (unitsName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            result.append(' ');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            result.append(unitsName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        return result.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * Returns whether this two-dimensional size attribute is equivalent to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * passed in object. To be equivalent, all of the following conditions must
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * be true:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * <OL TYPE=1>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * <LI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * <CODE>object</CODE> is not null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * <LI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * <CODE>object</CODE> is an instance of class Size2DSyntax.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * <LI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * This attribute's X dimension is equal to <CODE>object</CODE>'s X
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * dimension.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * <LI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * This attribute's Y dimension is equal to <CODE>object</CODE>'s Y
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * dimension.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * </OL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * @param  object  Object to compare to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * @return  True if <CODE>object</CODE> is equivalent to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     *          two-dimensional size attribute, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    public boolean equals(Object object) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        return(object != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
               object instanceof Size2DSyntax &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
               this.x == ((Size2DSyntax) object).x &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
               this.y == ((Size2DSyntax) object).y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * Returns a hash code value for this two-dimensional size attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        return (((x & 0x0000FFFF)      ) |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                ((y & 0x0000FFFF) << 16));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * Returns a string version of this two-dimensional size attribute. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * string takes the form <CODE>"<I>X</I>x<I>Y</I> um"</CODE>, where
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * <I>X</I> is the X dimension and <I>Y</I> is the Y dimension.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * The values are reported in the internal units of micrometers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        StringBuffer result = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        result.append(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        result.append('x');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        result.append(y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        result.append(" um");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        return result.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * Returns this two-dimensional size attribute's X dimension in units of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * micrometers (&#181;m). (For use in a subclass.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * @return  X dimension (&#181;m).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    protected int getXMicrometers(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        return x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * Returns this two-dimensional size attribute's Y dimension in units of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * micrometers (&#181;m). (For use in a subclass.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * @return  Y dimension (&#181;m).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    protected int getYMicrometers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        return y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
}