ewe.fx.print
Interface Printable

All Known Implementing Classes:
PrintableObject

public interface Printable

This is an interface which must be supported by objects which print to the printer. During the printing process the validatePage(int pageIndex) is called for each page to be printed (starting from 0) and if it returns true, then the print() method will be called for that page index. This process continues until validatePage() returns false.


Field Summary
static int UNKNOWN_NUMBER_OF_PAGES
           
 
Method Summary
 int countPages(PageFormat page)
          This is called when printing is about to start and it requests a count of the number of pages that would be necessary to print.
 boolean print(Handle handle, PrintSurface printSurface, PageFormat page, int pageIndex)
          Prints the page at the specified index into the specified Graphics context in the specified format.
 boolean validatePage(PageFormat page, int pageIndex)
          This returns true if the page with the specified index should be printed.
 

Field Detail

UNKNOWN_NUMBER_OF_PAGES

public static final int UNKNOWN_NUMBER_OF_PAGES
See Also:
Constant Field Values
Method Detail

print

public boolean print(Handle handle,
                     PrintSurface printSurface,
                     PageFormat page,
                     int pageIndex)
Prints the page at the specified index into the specified Graphics context in the specified format. A PrinterJob calls the Printable interface to request that a page be rendered into the context specified by graphics. The format of the page to be drawn is specified by pageFormat. The zero based index of the requested page is specified by pageIndex.

Within this method you should call printSurface.getPageRect() to get a Rectangular window onto the virtual printer page. You can then draw into the image provided by that PageRect and then afterwards, transfer the PageRect to the printer using printSurface.putPageRect().

The PageMosaic class is an excellent class for allowing you to draw onto an arbitrary section on the output page.

Parameters:
handle - a Handle that an outside thread can use to monitor the printing. During the printing you should check the shouldStop value of the Handle, and if it is true, then you should abort printing and return false.
printSurface - A printSurface that you should call getPageRect() on in order to get buffers to draw on.
page - the format for the page you are printing on.
pageIndex - the index of the page you are printing on, starting from index 0.
Returns:
true if printing was successful, false if the shouldStop value of handle was set.

validatePage

public boolean validatePage(PageFormat page,
                            int pageIndex)
This returns true if the page with the specified index should be printed.


countPages

public int countPages(PageFormat page)
This is called when printing is about to start and it requests a count of the number of pages that would be necessary to print. If this is unknown then the method should return UNKNOWN_NUMBER_OF_PAGES, but even if it returns a valid number pages, the validatePage() method will still be called before each page is printed via print().