home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-03-20 | 3.9 KB | 162 lines |
- /*
- * @(#)Paper.java 1.3 98/03/18
- *
- * Copyright 1997 by Sun Microsystems, Inc.,
- * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
- * All rights reserved.
- *
- * This software is the confidential and proprietary information
- * of Sun Microsystems, Inc. ("Confidential Information"). You
- * shall not disclose such Confidential Information and shall use
- * it only in accordance with the terms of the license agreement
- * you entered into with Sun.
- */
-
- package java.awt.print;
-
- import java.awt.geom.Rectangle2D;
-
- /**
- * Describes the physical characteristics of a
- * piece of paper.
- *
- * 11/11/97 Notes
- * - Should support media color, weight, and type.
- */
- public class Paper {
-
- /* Private Class Variables */
-
- private static final int INCH = 72;
- private static final double LETTER_WIDTH = 8.5 * INCH;
- private static final double LETTER_HEIGHT = 11 * INCH;
-
- /* Instance Variables */
-
- /**
- * The height of the physical page in 1/72ths
- * of an inch. The number is stored as a floating
- * point value rather than as an integer
- * to facilitate the conversion from metric
- * units to 1/72ths of an inch and then back.
- * (This may or may not be a good enough reason
- * for a float).
- */
- private double mHeight;
-
- /**
- * The width of the physical page in 1/72ths
- * of an inch.
- */
- private double mWidth;
-
- /**
- * The area of the page on which drawing will
- * be visable. The area outside of this
- * rectangle but on the Page generally
- * reflects the printer's hardware margins.
- * The origin of the physical page is
- * at (0, 0) with this rectangle provided
- * in that coordinate system.
- */
- private Rectangle2D mImageableArea;
-
- /* Constructors */
-
- /**
- * Creates a letter sized piece of paper
- * with one inch margins.
- */
- public Paper()
- {
- mHeight = LETTER_HEIGHT;
- mWidth = LETTER_WIDTH;
- mImageableArea = new Rectangle2D.Double(INCH, INCH,
- mWidth - 2 * INCH,
- mHeight - 2 * INCH);
- }
-
- /* Instance Methods */
-
- /**
- * Create a copy of this Paper.
- */
- public Object clone()
- {
- Paper newPaper = new Paper();
- newPaper.mHeight = mHeight;
- newPaper.mWidth = mWidth;
-
- /* It's okay to copy the reference to the imageable
- * area into the clone since we always return a copy
- * of the imageable area when asked for it.
- */
- newPaper.mImageableArea = mImageableArea;
-
- return newPaper;
- }
-
- /**
- * Return the height of the page in 1/72ths
- * of an inch.
- */
- public double getHeight()
- {
- return mHeight;
- }
-
- /**
- * Set the width and height of the paper.
- * The dimensions are supplied in1/72nds of
- * and inch.
- */
- public void setSize(double width, double height)
- {
- mWidth = width;
- mHeight = height;
- }
-
- /**
- * Return the width of the page in 1/72ths
- * of an inch.
- */
- public double getWidth()
- {
- return mWidth;
- }
-
- /**
- * Set the imageable area of the paper.
- */
- public void setImageableArea(Rectangle2D imageableArea)
- {
- mImageableArea = imageableArea;
- }
-
- /**
- * Set the imageable area of the paper. This routine
- * is not public but exists to make writing some of
- * the native code easier - it doesn't need to make
- * a Rectangle2D instance in order to set the imageable
- * area.
- */
- protected void setImageableArea(double x, double y, double width,
- double height)
- {
- setImageableArea(new Rectangle2D.Double(x, y, width,height));
- }
-
- /**
- * Return the portion of the page on which
- * drawing can occur. The rectangle is
- * expressed in 1/72ths of an inch.
- */
- public Rectangle2D getImageableArea()
- {
- return new Rectangle2D.Double(mImageableArea.getX(),
- mImageableArea.getY(),
- mImageableArea.getWidth(),
- mImageableArea.getHeight());
- }
- }
-