ewe.fx.print
Class PrintPage

java.lang.Object
  extended byewe.fx.print.PrintPage

public class PrintPage
extends Object

A PrintPage is used to help you draw a section of, or complete page, on a PrintSurface - usually as provided by a PrinterJob. It does this by requesting successive PageRect buffers from the PrintSurface such that it eventually completely covers the area that you wish to draw on. The getNext() method is used to retrieve successive PageRect sub-areas until the entire area is covered.

Additionally, each PageRect created has its Graphics translated such that drawing relative to an origin of (0,0) each time will always be drawn relative to the top left corner of the page section that the PrintPage covers.


Constructor Summary
PrintPage(int pixelWidth, int pixelHeight, PrintSurface p, double x, double y, double width, double height, int hints)
          Create a PrintPage to cover a specific area on the PrintSurface where the xDPI and the yDPI are calculated such that they result in a pixel width and pixel height equal to those specified as parameters.
PrintPage(PrintSurface p, double x, double y, double width, double height, double xdpi, double ydpi, int hints)
          Create a PrintPage to cover a specific area on the PrintSurface with a specified x-DPI and y-DPI.
 
Method Summary
 PageRect getNext()
          Call this method repeatedly until it returns null - indicating the page is complete.
 PointRect getPageRectArea(PageRect pr, PointRect destination)
          Return the area within the PrintPage as covered by the PageRect specified.
 PrintSurface getPrintSurface()
          Return the PrintSurface being used by the PrintPage.
 boolean isWithin(PageRect pageRect, double x, double y)
          Returns true if the specified co-ordinate in Points is within the current PageRect.
 boolean isWithin(PageRect pageRect, double x, double y, double width, double height)
          Returns true if the specified rectangle in Points intersects the current PageRect.
 boolean isWithin(PageRect pageRect, PointRect area)
          Returns true if the specified rectangle in Points intersects the current PageRect.
 void requestBlockSize(double blockWidth, double blockHeight)
          Call this before calling getNextRect() for the first time on the PrintPage - to suggest the PageRect block size to use.
 Rect scaleToPixels(PointRect pr, Rect destination)
          Scale a PointRect containing Point dimensions into pixel dimensions for any PageRect created by this PrintPage.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, toString
 

Constructor Detail

PrintPage

public PrintPage(PrintSurface p,
                 double x,
                 double y,
                 double width,
                 double height,
                 double xdpi,
                 double ydpi,
                 int hints)
Create a PrintPage to cover a specific area on the PrintSurface with a specified x-DPI and y-DPI.

Parameters:
p - The PrintSurface.
x - The x position of the area from the left edge of the paper in Points (1/72 of an inch).
y - The y position of the area from the top edge of the paper in Points (1/72 of an inch).
width - The width of the area in Points (1/72 of an inch).
height - The height of the area in Points (1/72 of an inch).
hints - any of the PrintSurface.HINT_XXX values OR'ed together.

PrintPage

public PrintPage(int pixelWidth,
                 int pixelHeight,
                 PrintSurface p,
                 double x,
                 double y,
                 double width,
                 double height,
                 int hints)
Create a PrintPage to cover a specific area on the PrintSurface where the xDPI and the yDPI are calculated such that they result in a pixel width and pixel height equal to those specified as parameters.

Parameters:
pixelWidth - The desired width of the page area in pixels.
pixelHeight - The desired height of the page area in pixels.
p - The PrintSurface.
x - The x position of the area from the left edge of the paper in Points (1/72 of an inch).
y - The y position of the area from the top edge of the paper in Points (1/72 of an inch).
width - The width of the area in Points (1/72 of an inch).
height - The height of the area in Points (1/72 of an inch).
hints - any of the PrintSurface.HINT_XXX values OR'ed together.
Method Detail

getPrintSurface

public PrintSurface getPrintSurface()
Return the PrintSurface being used by the PrintPage.


isWithin

public boolean isWithin(PageRect pageRect,
                        double x,
                        double y)
Returns true if the specified co-ordinate in Points is within the current PageRect. Note that the x and y origin are relative to the top left of the area covered by the PrintPage, and not the full page.

Parameters:
pageRect - the current PageRect.
x - the x co-ordinate in Points (1/72 of an inch).
y - the y co-ordinate in Points (1/72 of an inch).
Returns:
true if the specified co-ordinate in Points is within this PageRect.

isWithin

public boolean isWithin(PageRect pageRect,
                        double x,
                        double y,
                        double width,
                        double height)
Returns true if the specified rectangle in Points intersects the current PageRect. Note that the x and y origin are relative to the top left of the area covered by the PrintPage, and not the full page.

Parameters:
pageRect - the current PageRect.
x - the x co-ordinate in Points (1/72 of an inch).
y - the y co-ordinate in Points (1/72 of an inch).
width - the width in Points (1/72 of an inch).
height - the height in Points (1/72 of an inch).
Returns:
true if the specified rectangle in Points intersects with this PageRect.

isWithin

public boolean isWithin(PageRect pageRect,
                        PointRect area)
Returns true if the specified rectangle in Points intersects the current PageRect. Note that the x and y origin are relative to the top left of the area covered by the PrintPage, and not the full page.

Parameters:
pageRect - the current PageRect.
Returns:
true if the specified rectangle in Points intersects with this PageRect.

scaleToPixels

public Rect scaleToPixels(PointRect pr,
                          Rect destination)
Scale a PointRect containing Point dimensions into pixel dimensions for any PageRect created by this PrintPage.


getPageRectArea

public PointRect getPageRectArea(PageRect pr,
                                 PointRect destination)
Return the area within the PrintPage as covered by the PageRect specified.


requestBlockSize

public void requestBlockSize(double blockWidth,
                             double blockHeight)
Call this before calling getNextRect() for the first time on the PrintPage - to suggest the PageRect block size to use. This may not be used if it is too big.

Parameters:
blockWidth - the suggested block width in Points (1/72 or an inch).
blockHeight - the suggested block height in Points (1/72 or an inch).

getNext

public PageRect getNext()
Call this method repeatedly until it returns null - indicating the page is complete. Each time you call it, a section of the whole page will be returned as a PageRect. The returned PageRect will have its Graphics translated such that the co-ordinates 0,0 will always refer to the top-left pixel of the entire page area of the PrintPage.

Because of this, you can print an entire page by simply painting the exact same set of data to each PageRect that you receive - or you can call the isWithin() method to determine if an area or point is within the current PageRect - in which case there is no need to draw it.