FileDocCategorySizeDatePackage
PageFormat.javaAPI DocJava SE 5 API9313Fri Aug 26 14:56:56 BST 2005java.awt.print

PageFormat

public class PageFormat extends Object implements Cloneable
The PageFormat class describes the size and orientation of a page to be printed.

Fields Summary
public static final int
LANDSCAPE
The origin is at the bottom left of the paper with x running bottom to top and y running left to right. Note that this is not the Macintosh landscape but is the Window's and PostScript landscape.
public static final int
PORTRAIT
The origin is at the top left of the paper with x running to the right and y running down the paper.
public static final int
REVERSE_LANDSCAPE
The origin is at the top right of the paper with x running top to bottom and y running right to left. Note that this is the Macintosh landscape.
private Paper
mPaper
A description of the physical piece of paper.
private int
mOrientation
The orientation of the current page. This will be one of the constants: PORTRIAT, LANDSCAPE, or REVERSE_LANDSCAPE,
Constructors Summary
public PageFormat()
Creates a default, portrait-oriented PageFormat.


 /* Constructors */

              
     
    
	mPaper = new Paper();
    
Methods Summary
public java.lang.Objectclone()
Makes a copy of this PageFormat with the same contents as this PageFormat.

return
a copy of this PageFormat.

	PageFormat newPage;

	try {
	    newPage = (PageFormat) super.clone();
	    newPage.mPaper = (Paper)mPaper.clone();

	} catch (CloneNotSupportedException e) {
	    e.printStackTrace();
	    newPage = null;	// should never happen.
	}

	return newPage;
    
public doublegetHeight()
Returns the height, in 1/72nds of an inch, of the page. This method takes into account the orientation of the page when determining the height.

return
the height of the page.

        double height;
	int orientation = getOrientation();

        if (orientation == PORTRAIT) {
            height = mPaper.getHeight();
        } else {
            height = mPaper.getWidth();
        }

        return height;
    
public doublegetImageableHeight()
Return the height, in 1/72nds of an inch, of the imageable area of the page. This method takes into account the orientation of the page.

return
the height of the page.

        double height;

        if (getOrientation() == PORTRAIT) {
            height = mPaper.getImageableHeight();
        } else {
            height = mPaper.getImageableWidth();
        }

        return height;
    
public doublegetImageableWidth()
Returns the width, in 1/72nds of an inch, of the imageable area of the page. This method takes into account the orientation of the page.

return
the width of the page.

        double width;

        if (getOrientation() == PORTRAIT) {
            width = mPaper.getImageableWidth();
        } else {
            width = mPaper.getImageableHeight();
        }

        return width;
    
public doublegetImageableX()
Returns the x coordinate of the upper left point of the imageable area of the Paper object associated with this PageFormat. This method takes into account the orientation of the page.

return
the x coordinate of the upper left point of the imageable area of the Paper object associated with this PageFormat.

        double x;

	switch (getOrientation()) {

	case LANDSCAPE:
	    x = mPaper.getHeight()
		- (mPaper.getImageableY() + mPaper.getImageableHeight());
	    break;

	case PORTRAIT:
	    x = mPaper.getImageableX();
	    break;

	case REVERSE_LANDSCAPE:
	    x = mPaper.getImageableY();
	    break;

	default:
	    /* This should never happen since it signifies that the
	     * PageFormat is in an invalid orientation.
	     */
	    throw new InternalError("unrecognized orientation");

	}

        return x;
    
public doublegetImageableY()
Returns the y coordinate of the upper left point of the imageable area of the Paper object associated with this PageFormat. This method takes into account the orientation of the page.

return
the y coordinate of the upper left point of the imageable area of the Paper object associated with this PageFormat.

        double y;

	switch (getOrientation()) {

	case LANDSCAPE:
	    y = mPaper.getImageableX();
	    break;

	case PORTRAIT:
	    y = mPaper.getImageableY();
	    break;

	case REVERSE_LANDSCAPE:
	    y = mPaper.getWidth()
		- (mPaper.getImageableX() + mPaper.getImageableWidth());
	    break;

	default:
	    /* This should never happen since it signifies that the
	     * PageFormat is in an invalid orientation.
	     */
	    throw new InternalError("unrecognized orientation");

	}

        return y;
    
public double[]getMatrix()
Returns a transformation matrix that translates user space rendering to the requested orientation of the page. The values are placed into the array as { m00, m10, m01, m11, m02, m12} in the form required by the {@link AffineTransform} constructor.

return
the matrix used to translate user space rendering to the orientation of the page.
see
java.awt.geom.AffineTransform

        double[] matrix = new double[6];

	switch (mOrientation) {

	case LANDSCAPE:
            matrix[0] =  0;     matrix[1] = -1;
            matrix[2] =  1;     matrix[3] =  0;
            matrix[4] =  0;     matrix[5] =  mPaper.getHeight();
	    break;

	case PORTRAIT:
            matrix[0] =  1;     matrix[1] =  0;
            matrix[2] =  0;     matrix[3] =  1;
            matrix[4] =  0;     matrix[5] =  0;
	    break;

	case REVERSE_LANDSCAPE:
            matrix[0] =  0;			matrix[1] =  1;
            matrix[2] = -1;			matrix[3] =  0;
            matrix[4] =  mPaper.getWidth();     matrix[5] =  0;
	    break;

	default:
	    throw new IllegalArgumentException();
	}

	return matrix;
    
public intgetOrientation()
Returns the orientation of this PageFormat.

return
this PageFormat object's orientation.
see
#setOrientation

	return mOrientation;
    
public java.awt.print.PapergetPaper()
Returns a copy of the {@link Paper} object associated with this PageFormat. Changes made to the Paper object returned from this method do not affect the Paper object of this PageFormat. To update the Paper object of this PageFormat, create a new Paper object and set it into this PageFormat by using the {@link #setPaper(Paper)} method.

return
a copy of the Paper object associated with this PageFormat.
see
#setPaper

	return (Paper)mPaper.clone();
    
public doublegetWidth()
Returns the width, in 1/72nds of an inch, of the page. This method takes into account the orientation of the page when determining the width.

return
the width of the page.

	double width;
	int orientation = getOrientation();

        if (orientation == PORTRAIT) {
            width = mPaper.getWidth();
        } else {
            width = mPaper.getHeight();
        }

        return width;
    
public voidsetOrientation(int orientation)
Sets the page orientation. orientation must be one of the constants: PORTRAIT, LANDSCAPE, or REVERSE_LANDSCAPE.

param
orientation the new orientation for the page
throws
IllegalArgumentException if an unknown orientation was requested
see
#getOrientation

	if (0 <= orientation && orientation <= REVERSE_LANDSCAPE) {
	    mOrientation = orientation;
	} else {
	    throw new IllegalArgumentException();
	}
    
public voidsetPaper(java.awt.print.Paper paper)
Sets the Paper object for this PageFormat.

param
paper the Paper object to which to set the Paper object for this PageFormat.
exception
NullPointerException a null paper instance was passed as a parameter.
see
#getPaper

         mPaper = (Paper)paper.clone();