001/* PageFormat.java -- Information about the page format
002   Copyright (C) 1999, 2006 Free Software Foundation, Inc.
003
004This file is part of GNU Classpath.
005
006GNU Classpath is free software; you can redistribute it and/or modify
007it under the terms of the GNU General Public License as published by
008the Free Software Foundation; either version 2, or (at your option)
009any later version.
010
011GNU Classpath is distributed in the hope that it will be useful, but
012WITHOUT ANY WARRANTY; without even the implied warranty of
013MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014General Public License for more details.
015
016You should have received a copy of the GNU General Public License
017along with GNU Classpath; see the file COPYING.  If not, write to the
018Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
01902110-1301 USA.
020
021Linking this library statically or dynamically with other modules is
022making a combined work based on this library.  Thus, the terms and
023conditions of the GNU General Public License cover the whole
024combination.
025
026As a special exception, the copyright holders of this library give you
027permission to link this library with independent modules to produce an
028executable, regardless of the license terms of these independent
029modules, and to copy and distribute the resulting executable under
030terms of your choice, provided that you also meet, for each linked
031independent module, the terms and conditions of the license of that
032module.  An independent module is a module which is not derived from
033or based on this library.  If you modify this library, you may extend
034this exception to your version of the library, but you are not
035obligated to do so.  If you do not wish to do so, delete this
036exception statement from your version. */
037
038
039package java.awt.print;
040
041/**
042 * This class contains information about the desired page format to use for
043 * printing a particular set of pages.
044 *
045 * @author Aaron M. Renn (arenn@urbanophile.com)
046 */
047public class PageFormat
048  implements Cloneable
049{
050  /**
051   * A constant for a landscaped page orientation. Used by
052   * <code>getOrientation</code> and <code>setOrientation</code>.
053   */
054  public static final int LANDSCAPE = 0;
055
056  /**
057   * A constant for a portrait page orientation. Used by
058   * <code>getOrientation</code> and <code>setOrientation</code>.
059   */
060  public static final int PORTRAIT = 1;
061
062  /**
063   * A constant for a reversed landscaped page orientation. This is the
064   * orientation used by Macintosh's for landscape. The origin is in the
065   * upper right hand corner instead of the upper left. The X and Y axes
066   * are reversed. Used by <code>getOrientation</code> and
067   * <code>setOrientation</code>.
068   */
069  public static final int REVERSE_LANDSCAPE = 2;
070
071  // The page orientation
072  private int orientation;
073
074  // The paper type
075  private Paper paper;
076
077  /**
078   * This method creates a default page layout, which will be in portrait
079   * format.
080   */
081  public PageFormat()
082  {
083    this.paper = new Paper();
084    this.orientation = PORTRAIT;
085  }
086
087  /**
088   * This method returns the width of the page, in 1/72nd's of an inch. The
089   * "width" measured depends on orientation.
090   *
091   * @return The width of the page.
092   */
093  public double getWidth()
094  {
095    return paper.getWidth();
096  }
097
098  /**
099   * This method returns the height of the page, in 1/72nd's of an inch. The
100   * "height" measured depends on the orientation.
101   *
102   * @return The height of the page.
103   */
104  public double getHeight()
105  {
106    return paper.getHeight();
107  }
108
109  /**
110   * This method returns the X coordinate value of the upper leftmost drawable
111   * area of the paper.
112   *
113   * @return The upper leftmost imageable X coordinate.
114   */
115  public double getImageableX()
116  {
117    return paper.getImageableX();
118  }
119
120  /**
121   * This method returns the Y coordinate value of the upper leftmost drawable
122   * area of the paper.
123   *
124   * @return The upper leftmost imageable Y coordinate.
125   */
126  public double getImageableY()
127  {
128    return paper.getImageableY();
129  }
130
131  /**
132   * This method returns the imageable width of the paper, in 1/72nd's of an
133   * inch.
134   *
135   * @return The imageable width of the paper.
136   */
137  public double getImageableWidth()
138  {
139    return paper.getImageableWidth();
140  }
141
142  /**
143   * This method returns the imageable height of the paper, in 1/72nd's of an
144   * inch.
145   *
146   * @return The imageable height of the paper.
147   */
148  public double getImageableHeight()
149  {
150    return paper.getImageableHeight();
151  }
152
153  /**
154   * Returns a copy of the <code>paper</code> object being used for this page
155   * format.
156   *
157   * @return A copy of the <code>Paper</code> object for this format.
158   */
159  public Paper getPaper()
160  {
161    return (Paper) paper.clone();
162  }
163
164  /**
165   * Sets the <code>Paper</code> object to be used by this page format.
166   *
167   * @param paper The new <code>Paper</code> object for this page format.
168   */
169  public void setPaper(Paper paper)
170  {
171    this.paper = paper;
172  }
173
174  /**
175   * This method returns the current page orientation. The value returned will
176   * be one of the page orientation constants from this class.
177   *
178   * @return The current page orientation.
179   */
180  public int getOrientation()
181  {
182    return orientation;
183  }
184
185  /**
186   * This method sets the page orientation for this format to the specified
187   * value. It must be one of the page orientation constants from this class
188   * or an exception will be thrown.
189   *
190   * @param orientation The new page orientation.
191   * @exception IllegalArgumentException If the specified page orientation
192   *            value is not one of the constants from this class.
193   */
194  public void setOrientation(int orientation) throws IllegalArgumentException
195  {
196    if ((orientation != PORTRAIT) && (orientation != LANDSCAPE)
197        && (orientation != REVERSE_LANDSCAPE))
198      throw new IllegalArgumentException("Bad page orientation value: "
199                                         + orientation);
200
201    this.orientation = orientation;
202  }
203
204  /**
205   * This method returns a matrix used for transforming user space coordinates
206   * to page coordinates. The value returned will be six doubles as described
207   * in <code>java.awt.geom.AffineTransform</code>.
208   *
209   * @return The transformation matrix for this page format.
210   */
211  public double[] getMatrix()
212  {
213    throw new RuntimeException("Not implemented since I don't know what to do");
214  }
215
216  /**
217   * This method returns a copy of this object.
218   *
219   * @return A copy of this object.
220   */
221  public Object clone()
222  {
223    try
224      {
225        return (super.clone());
226      }
227    catch (CloneNotSupportedException e)
228      {
229        return (null);
230      }
231  }
232
233}