jdk/src/share/classes/java/awt/print/PageFormat.java
author erikj
Thu, 07 Jun 2012 18:05:09 -0700
changeset 12813 c10ab96dcf41
parent 5506 202f599c92aa
child 16734 da1901d79073
permissions -rw-r--r--
7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI Reviewed-by: ohair, ohrstrom, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1997, 2000, 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
package java.awt.print;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.geom.AffineTransform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.geom.Point2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.geom.Rectangle2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
12813
c10ab96dcf41 7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI
erikj
parents: 5506
diff changeset
    32
import javax.tools.annotation.GenerateNativeHeader;
c10ab96dcf41 7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI
erikj
parents: 5506
diff changeset
    33
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * The <code>PageFormat</code> class describes the size and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * orientation of a page to be printed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 */
12813
c10ab96dcf41 7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI
erikj
parents: 5506
diff changeset
    38
/* No native methods here, but the constants are needed in the supporting JNI code */
c10ab96dcf41 7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI
erikj
parents: 5506
diff changeset
    39
@GenerateNativeHeader
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
public class PageFormat implements Cloneable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 /* Class Constants */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     *  The origin is at the bottom left of the paper with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     *  x running bottom to top and y running left to right.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     *  Note that this is not the Macintosh landscape but
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     *  is the Window's and PostScript landscape.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    public static final int LANDSCAPE = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     *  The origin is at the top left of the paper with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     *  x running to the right and y running down the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     *  paper.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    public static final int PORTRAIT = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     *  The origin is at the top right of the paper with x
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     *  running top to bottom and y running right to left.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     *  Note that this is the Macintosh landscape.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    public static final int REVERSE_LANDSCAPE = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 /* Instance Variables */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * A description of the physical piece of paper.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private Paper mPaper;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * The orientation of the current page. This will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * one of the constants: PORTRIAT, LANDSCAPE, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * REVERSE_LANDSCAPE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private int mOrientation = PORTRAIT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 /* Constructors */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * Creates a default, portrait-oriented
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * <code>PageFormat</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public PageFormat()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        mPaper = new Paper();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 /* Instance Methods */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * Makes a copy of this <code>PageFormat</code> with the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * contents as this <code>PageFormat</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @return a copy of this <code>PageFormat</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    public Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        PageFormat newPage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            newPage = (PageFormat) super.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            newPage.mPaper = (Paper)mPaper.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        } catch (CloneNotSupportedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            newPage = null;     // should never happen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        return newPage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * Returns the width, in 1/72nds of an inch, of the page.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * This method takes into account the orientation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * page when determining the width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * @return the width of the page.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    public double getWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        double width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        int orientation = getOrientation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        if (orientation == PORTRAIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            width = mPaper.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            width = mPaper.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        return width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * Returns the height, in 1/72nds of an inch, of the page.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * This method takes into account the orientation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * page when determining the height.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @return the height of the page.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    public double getHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        double height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        int orientation = getOrientation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        if (orientation == PORTRAIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            height = mPaper.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            height = mPaper.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        return height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * Returns the x coordinate of the upper left point of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * imageable area of the <code>Paper</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * associated with this <code>PageFormat</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * This method takes into account the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * orientation of the page.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * @return the x coordinate of the upper left point of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * imageable area of the <code>Paper</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * associated with this <code>PageFormat</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    public double getImageableX() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        double x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        switch (getOrientation()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        case LANDSCAPE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            x = mPaper.getHeight()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                - (mPaper.getImageableY() + mPaper.getImageableHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        case PORTRAIT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            x = mPaper.getImageableX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        case REVERSE_LANDSCAPE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            x = mPaper.getImageableY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            /* This should never happen since it signifies that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
             * PageFormat is in an invalid orientation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            throw new InternalError("unrecognized orientation");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        return x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * Returns the y coordinate of the upper left point of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * imageable area of the <code>Paper</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * associated with this <code>PageFormat</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * This method takes into account the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * orientation of the page.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @return the y coordinate of the upper left point of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * imageable area of the <code>Paper</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * associated with this <code>PageFormat</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    public double getImageableY() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        double y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        switch (getOrientation()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        case LANDSCAPE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            y = mPaper.getImageableX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        case PORTRAIT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            y = mPaper.getImageableY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        case REVERSE_LANDSCAPE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            y = mPaper.getWidth()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                - (mPaper.getImageableX() + mPaper.getImageableWidth());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            /* This should never happen since it signifies that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
             * PageFormat is in an invalid orientation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            throw new InternalError("unrecognized orientation");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        return y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * Returns the width, in 1/72nds of an inch, of the imageable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * area of the page. This method takes into account the orientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * of the page.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @return the width of the page.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    public double getImageableWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        double width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        if (getOrientation() == PORTRAIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            width = mPaper.getImageableWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            width = mPaper.getImageableHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        return width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * Return the height, in 1/72nds of an inch, of the imageable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * area of the page. This method takes into account the orientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * of the page.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * @return the height of the page.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    public double getImageableHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        double height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        if (getOrientation() == PORTRAIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            height = mPaper.getImageableHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            height = mPaper.getImageableWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        return height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * Returns a copy of the {@link Paper} object associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * with this <code>PageFormat</code>.  Changes made to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * <code>Paper</code> object returned from this method do not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * affect the <code>Paper</code> object of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * <code>PageFormat</code>.  To update the <code>Paper</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * object of this <code>PageFormat</code>, create a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * <code>Paper</code> object and set it into this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * <code>PageFormat</code> by using the {@link #setPaper(Paper)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * @return a copy of the <code>Paper</code> object associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     *          with this <code>PageFormat</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @see #setPaper
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    public Paper getPaper() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        return (Paper)mPaper.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * Sets the <code>Paper</code> object for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * <code>PageFormat</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * @param paper the <code>Paper</code> object to which to set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * the <code>Paper</code> object for this <code>PageFormat</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * @exception <code>NullPointerException</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     *              a null paper instance was passed as a parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * @see #getPaper
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     public void setPaper(Paper paper) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
         mPaper = (Paper)paper.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * Sets the page orientation. <code>orientation</code> must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * one of the constants: PORTRAIT, LANDSCAPE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * or REVERSE_LANDSCAPE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * @param orientation the new orientation for the page
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * @throws IllegalArgumentException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     *          an unknown orientation was requested
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * @see #getOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    public void setOrientation(int orientation) throws IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        if (0 <= orientation && orientation <= REVERSE_LANDSCAPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            mOrientation = orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * Returns the orientation of this <code>PageFormat</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * @return this <code>PageFormat</code> object's orientation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * @see #setOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    public int getOrientation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        return mOrientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * Returns a transformation matrix that translates user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * space rendering to the requested orientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * of the page.  The values are placed into the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * array as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * {&nbsp;m00,&nbsp;m10,&nbsp;m01,&nbsp;m11,&nbsp;m02,&nbsp;m12} in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * the form required by the {@link AffineTransform}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * @return the matrix used to translate user space rendering
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * to the orientation of the page.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * @see java.awt.geom.AffineTransform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    public double[] getMatrix() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        double[] matrix = new double[6];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        switch (mOrientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        case LANDSCAPE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            matrix[0] =  0;     matrix[1] = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            matrix[2] =  1;     matrix[3] =  0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            matrix[4] =  0;     matrix[5] =  mPaper.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        case PORTRAIT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            matrix[0] =  1;     matrix[1] =  0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            matrix[2] =  0;     matrix[3] =  1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            matrix[4] =  0;     matrix[5] =  0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        case REVERSE_LANDSCAPE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            matrix[0] =  0;                     matrix[1] =  1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            matrix[2] = -1;                     matrix[3] =  0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            matrix[4] =  mPaper.getWidth();     matrix[5] =  0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        return matrix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
}