PageFormat.java 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. /* PageFormat.java -- Information about the page format
  2. Copyright (C) 1999 Free Software Foundation, Inc.
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package java.awt.print;
  32. /**
  33. * This class contains information about the desired page format to
  34. * use for printing a particular set of pages.
  35. *
  36. * @author Aaron M. Renn (arenn@urbanophile.com)
  37. */
  38. public class PageFormat implements Cloneable
  39. {
  40. /*
  41. * Static Variables
  42. */
  43. /**
  44. * A constant for a landscaped page orientation. Used by
  45. * <code>getOrientation</code> and <code>setOrientation</code>.
  46. */
  47. public static final int LANDSCAPE = 0;
  48. /**
  49. * A constant for a portrait page orientation. Used by
  50. * <code>getOrientation</code> and <code>setOrientation</code>.
  51. */
  52. public static final int PORTRAIT = 1;
  53. /**
  54. * A constant for a reversed landscaped page orientation. This is
  55. * the orientation used by Macintosh's for landscape. The origin is
  56. * in the upper right hand corner instead of the upper left. The
  57. * X and Y axes are reversed. Used by <code>getOrientation</code> and
  58. * <code>setOrientation</code>.
  59. */
  60. public static final int REVERSE_LANDSCAPE = 2;
  61. /*************************************************************************/
  62. /*
  63. * Instance Variables
  64. */
  65. // The page orientation
  66. private int orientation;
  67. // The paper type
  68. private Paper paper;
  69. /*************************************************************************/
  70. /*
  71. * Constructors
  72. */
  73. /**
  74. * This method creates a default page layout, which will be in portrait
  75. * format.
  76. */
  77. public
  78. PageFormat()
  79. {
  80. this.paper = new Paper();
  81. this.orientation = PORTRAIT;
  82. }
  83. /*************************************************************************/
  84. /*
  85. * Instance Methods
  86. */
  87. /**
  88. * This method returns the width of the page, in 1/72nd's of an inch. The
  89. * "width" measured depends on orientation.
  90. *
  91. * @return The width of the page.
  92. */
  93. public double
  94. getWidth()
  95. {
  96. return(paper.getWidth());
  97. }
  98. /*************************************************************************/
  99. /**
  100. * This method returns the height of the page, in 1/72nd's of an inch.
  101. * The "height" measured depends on the orientation.
  102. *
  103. * @return The height of the page.
  104. */
  105. public double
  106. getHeight()
  107. {
  108. return(paper.getHeight());
  109. }
  110. /*************************************************************************/
  111. /**
  112. * This method returns the X coordinate value of the upper leftmost
  113. * drawable area of the paper.
  114. *
  115. * @return The upper leftmost imageable X coordinate.
  116. */
  117. public double
  118. getImageableX()
  119. {
  120. return(paper.getImageableX());
  121. }
  122. /*************************************************************************/
  123. /**
  124. * This method returns the Y coordinate value of the upper leftmost
  125. * drawable area of the paper.
  126. *
  127. * @return The upper leftmost imageable Y coordinate.
  128. */
  129. public double
  130. getImageableY()
  131. {
  132. return(paper.getImageableY());
  133. }
  134. /*************************************************************************/
  135. /**
  136. * This method returns the imageable width of the paper, in 1/72nd's of
  137. * an inch.
  138. *
  139. * @return The imageable width of the paper.
  140. */
  141. public double
  142. getImageableWidth()
  143. {
  144. return(paper.getImageableWidth());
  145. }
  146. /*************************************************************************/
  147. /**
  148. * This method returns the imageable height of the paper, in 1/72nd's of
  149. * an inch.
  150. *
  151. * @return The imageable height of the paper.
  152. */
  153. public double
  154. getImageableHeigth()
  155. {
  156. return(paper.getImageableHeight());
  157. }
  158. /*************************************************************************/
  159. /**
  160. * Returns a copy of the <code>paper</code> object being used for this
  161. * page format.
  162. *
  163. * @return A copy of the <code>Paper</code> object for this format.
  164. */
  165. public Paper
  166. getPaper()
  167. {
  168. return((Paper)paper.clone());
  169. }
  170. /*************************************************************************/
  171. /**
  172. * Sets the <code>Paper</code> object to be used by this page format.
  173. *
  174. * @param paper The new <code>Paper</code> object for this page format.
  175. */
  176. public void
  177. setPaper(Paper paper)
  178. {
  179. this.paper = paper;
  180. }
  181. /*************************************************************************/
  182. /**
  183. * This method returns the current page orientation. The value returned
  184. * will be one of the page orientation constants from this class.
  185. *
  186. * @return The current page orientation.
  187. */
  188. public int
  189. getOrientation()
  190. {
  191. return(orientation);
  192. }
  193. /*************************************************************************/
  194. /**
  195. * This method sets the page orientation for this format to the
  196. * specified value. It must be one of the page orientation constants
  197. * from this class or an exception will be thrown.
  198. *
  199. * @param orientation The new page orientation.
  200. *
  201. * @exception IllegalArgumentException If the specified page orientation
  202. * value is not one of the constants from this class.
  203. */
  204. public void
  205. setOrientation(int orientation) throws IllegalArgumentException
  206. {
  207. if ((orientation != PORTRAIT) &&
  208. (orientation != LANDSCAPE) &&
  209. (orientation != REVERSE_LANDSCAPE))
  210. throw new IllegalArgumentException("Bad page orientation value: " +
  211. orientation);
  212. this.orientation = orientation;
  213. }
  214. /*************************************************************************/
  215. /**
  216. * This method returns a matrix used for transforming user space
  217. * coordinates to page coordinates. The value returned will be six
  218. * doubles as described in <code>java.awt.geom.AffineTransform</code>.
  219. *
  220. * @return The transformation matrix for this page format.
  221. */
  222. public double[]
  223. getMatrix()
  224. {
  225. throw new RuntimeException("Not implemented since I don't know what to do");
  226. }
  227. /*************************************************************************/
  228. /**
  229. * This method returns a copy of this object.
  230. *
  231. * @return A copy of this object.
  232. */
  233. public Object
  234. clone()
  235. {
  236. try
  237. {
  238. return(super.clone());
  239. }
  240. catch(CloneNotSupportedException e)
  241. {
  242. return(null);
  243. }
  244. }
  245. } // class PageFormat