home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / unsupported / JDK1.2beta3 / SOURCE / SRC.ZIP / java / awt / print / Paper.java < prev    next >
Encoding:
Java Source  |  1998-03-20  |  3.9 KB  |  162 lines

  1. /*
  2.  * @(#)Paper.java    1.3 98/03/18
  3.  *
  4.  * Copyright 1997 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.awt.print;
  16.  
  17. import java.awt.geom.Rectangle2D;
  18.  
  19. /**
  20.  * Describes the physical characteristics of a
  21.  * piece of paper.
  22.  *
  23.  * 11/11/97 Notes
  24.  *    - Should support media color, weight, and type.
  25.  */    
  26. public class Paper {
  27.  
  28.  /* Private Class Variables */
  29.  
  30.     private static final int INCH = 72;
  31.     private static final double LETTER_WIDTH = 8.5 * INCH;
  32.     private static final double LETTER_HEIGHT = 11 * INCH;
  33.  
  34.  /* Instance Variables */
  35.  
  36.     /**
  37.      * The height of the physical page in 1/72ths
  38.      * of an inch. The number is stored as a floating
  39.      * point value rather than as an integer
  40.      * to facilitate the conversion from metric
  41.      * units to 1/72ths of an inch and then back.
  42.      * (This may or may not be a good enough reason
  43.      * for a float).
  44.      */
  45.     private double mHeight;
  46.     
  47.     /**
  48.      * The width of the physical page in 1/72ths
  49.      * of an inch.
  50.      */
  51.     private double mWidth;
  52.  
  53.     /**
  54.      * The area of the page on which drawing will
  55.      * be visable. The area outside of this
  56.      * rectangle but on the Page generally
  57.      * reflects the printer's hardware margins.
  58.      * The origin of the physical page is
  59.      * at (0, 0) with this rectangle provided
  60.      * in that coordinate system.
  61.      */
  62.     private Rectangle2D mImageableArea;
  63.      
  64.  /* Constructors */
  65.     
  66.     /**
  67.      * Creates a letter sized piece of paper
  68.      * with one inch margins.
  69.      */
  70.     public Paper()
  71.     {
  72.     mHeight = LETTER_HEIGHT;
  73.     mWidth = LETTER_WIDTH;
  74.     mImageableArea = new Rectangle2D.Double(INCH, INCH,
  75.                         mWidth - 2 * INCH,
  76.                         mHeight - 2 * INCH);
  77.     }
  78.  
  79.  /* Instance Methods */
  80.  
  81.     /**
  82.      *    Create a copy of this Paper.
  83.      */
  84.      public Object clone()
  85.      {
  86.     Paper newPaper = new Paper();
  87.     newPaper.mHeight = mHeight;
  88.     newPaper.mWidth = mWidth;
  89.  
  90.     /* It's okay to copy the reference to the imageable
  91.      * area into the clone since we always return a copy
  92.      * of the imageable area when asked for it.
  93.      */
  94.     newPaper.mImageableArea = mImageableArea;
  95.     
  96.     return newPaper;
  97.      }
  98.  
  99.     /**
  100.      *    Return the height of the page in 1/72ths
  101.      *    of an inch.
  102.     */
  103.     public double getHeight()
  104.     {
  105.     return mHeight;
  106.     }
  107.     
  108.     /**
  109.      * Set the width and height of the paper.
  110.      * The dimensions are supplied in1/72nds of
  111.      * and inch.
  112.      */
  113.      public void setSize(double width, double height)
  114.      {
  115.     mWidth = width;
  116.     mHeight = height;
  117.      }
  118.  
  119.     /**
  120.      * Return the width of the page in 1/72ths
  121.      * of an inch.
  122.      */
  123.     public double getWidth()
  124.     {
  125.     return mWidth;
  126.     }
  127.  
  128.     /**
  129.      * Set the imageable area of the paper.
  130.      */
  131.      public void setImageableArea(Rectangle2D imageableArea)
  132.      {
  133.     mImageableArea = imageableArea;
  134.      }
  135.  
  136.     /**
  137.      * Set the imageable area of the paper. This routine
  138.      * is not public but exists to make writing some of
  139.      * the native code easier - it doesn't need to make
  140.      * a Rectangle2D instance in order to set the imageable
  141.      * area.
  142.      */
  143.      protected void setImageableArea(double x, double y, double width,
  144.                                 double height)
  145.      {
  146.     setImageableArea(new Rectangle2D.Double(x, y, width,height));        
  147.      }
  148.  
  149.     /**
  150.      * Return the portion of the page on which
  151.      * drawing can occur. The rectangle is
  152.      * expressed in 1/72ths of an inch.
  153.      */
  154.     public Rectangle2D getImageableArea()
  155.     {
  156.     return new Rectangle2D.Double(mImageableArea.getX(),
  157.                     mImageableArea.getY(),
  158.                     mImageableArea.getWidth(),
  159.                     mImageableArea.getHeight());
  160.     }
  161. }
  162.