1. /*
  2. * @(#)Paper.java 1.11 01/11/29
  3. *
  4. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.awt.print;
  8. import java.awt.geom.Rectangle2D;
  9. /**
  10. * The <code>Paper</code> class describes the physical characteristics of
  11. * a piece of paper.
  12. */
  13. public class Paper implements Cloneable {
  14. /* Private Class Variables */
  15. private static final int INCH = 72;
  16. private static final double LETTER_WIDTH = 8.5 * INCH;
  17. private static final double LETTER_HEIGHT = 11 * INCH;
  18. /* Instance Variables */
  19. /**
  20. * The height of the physical page in 1/72nds
  21. * of an inch. The number is stored as a floating
  22. * point value rather than as an integer
  23. * to facilitate the conversion from metric
  24. * units to 1/72nds of an inch and then back.
  25. * (This may or may not be a good enough reason
  26. * for a float).
  27. */
  28. private double mHeight;
  29. /**
  30. * The width of the physical page in 1/72nds
  31. * of an inch.
  32. */
  33. private double mWidth;
  34. /**
  35. * The area of the page on which drawing will
  36. * be visable. The area outside of this
  37. * rectangle but on the Page generally
  38. * reflects the printer's hardware margins.
  39. * The origin of the physical page is
  40. * at (0, 0) with this rectangle provided
  41. * in that coordinate system.
  42. */
  43. private Rectangle2D mImageableArea;
  44. /* Constructors */
  45. /**
  46. * Creates a letter sized piece of paper
  47. * with one inch margins.
  48. */
  49. public Paper() {
  50. mHeight = LETTER_HEIGHT;
  51. mWidth = LETTER_WIDTH;
  52. mImageableArea = new Rectangle2D.Double(INCH, INCH,
  53. mWidth - 2 * INCH,
  54. mHeight - 2 * INCH);
  55. }
  56. /* Instance Methods */
  57. /**
  58. * Creates a copy of this <code>Paper</code> with the same contents
  59. * as this <code>Paper</code>.
  60. * @return a copy of this <code>Paper</code>.
  61. */
  62. public Object clone() {
  63. Paper newPaper;
  64. try {
  65. /* It's okay to copy the reference to the imageable
  66. * area into the clone since we always return a copy
  67. * of the imageable area when asked for it.
  68. */
  69. newPaper = (Paper) super.clone();
  70. } catch (CloneNotSupportedException e) {
  71. e.printStackTrace();
  72. newPaper = null; // should never happen.
  73. }
  74. return newPaper;
  75. }
  76. /**
  77. * Returns the height of the page in 1/72nds of an inch.
  78. * @return the height of the page described by this
  79. * <code>Paper</code>.
  80. */
  81. public double getHeight() {
  82. return mHeight;
  83. }
  84. /**
  85. * Sets the width and height of this <code>Paper</code>.
  86. * The dimensions are supplied in 1/72nds of
  87. * and inch.
  88. * @param width the value to which to set this <code>Paper</code>
  89. * object's width
  90. * @param height the value to which to set this <code>Paper</code>
  91. * object's height
  92. */
  93. public void setSize(double width, double height) {
  94. mWidth = width;
  95. mHeight = height;
  96. }
  97. /**
  98. * Returns the width of the page in 1/72nds
  99. * of an inch.
  100. * @return the width of the page described by this
  101. * <code>Paper</code>.
  102. */
  103. public double getWidth() {
  104. return mWidth;
  105. }
  106. /**
  107. * Sets the imageable area of this <code>Paper</code>.
  108. * @param x, y the coordinates to which to set the
  109. * upper-left corner of the imageable area of this <code>Paper</code>
  110. * @param width the value to which to set the width of the
  111. * imageable area of this <code>Paper</code>
  112. * @param height the value to which to set the height of the
  113. * imageable area of this <code>Paper</code>
  114. */
  115. public void setImageableArea(double x, double y,
  116. double width, double height) {
  117. mImageableArea = new Rectangle2D.Double(x, y, width,height);
  118. }
  119. /**
  120. * Returns the x coordinate of the upper-left corner of this
  121. * <code>Paper</code> object's imageable area.
  122. * @return the x coordinate of the imageable area.
  123. */
  124. public double getImageableX() {
  125. return mImageableArea.getX();
  126. }
  127. /**
  128. * Returns the y coordinate of the upper-left corner of this
  129. * <code>Paper</code> object's imageable area.
  130. * @return the y coordinate of the imageable area.
  131. */
  132. public double getImageableY() {
  133. return mImageableArea.getY();
  134. }
  135. /**
  136. * Returns the width of this <code>Paper</code> object's imageable
  137. * area.
  138. * @return the width of the imageable area.
  139. */
  140. public double getImageableWidth() {
  141. return mImageableArea.getWidth();
  142. }
  143. /**
  144. * Returns the height of this <code>Paper</code> object's imageable
  145. * area.
  146. * @return the height of the imageable area.
  147. */
  148. public double getImageableHeight() {
  149. return mImageableArea.getHeight();
  150. }
  151. }