jwo.utils.gui
Class PrintUtilities

java.lang.Object
  extended byjwo.utils.gui.PrintUtilities
All Implemented Interfaces:
PrintJobListener, Runnable

public class PrintUtilities
extends Object
implements Runnable, PrintJobListener

Handles the printing of any printable object.

Version:
2.1, 10th August, 2004
Author:
Jo Wood,

Constructor Summary
PrintUtilities()
          Sets up the print services for possible printing.
PrintUtilities(DocFlavor flavour)
          Sets up the print services for possible printing.
 
Method Summary
static Paper createA3()
          Returns an object representing A3 paper with 2cm margins.
static Paper createA4()
          Returns an object representing A4 paper with 2cm margins.
 float getScale(Dimension objectSize, PageFormat pageFormat)
          Reports the scaling that would be applied if an object of the given size was to be printed using the supplied page format.
 void print(Printable printableObject, boolean showDialogue)
          Prints the given printable object.
 void printDataTransferCompleted(PrintJobEvent e)
          Reports that the transfer of data to print job has been completed, but currently ignored.
 void printJobCanceled(PrintJobEvent e)
          Reports that the print job has been cancelled for some reason.
 void printJobCompleted(PrintJobEvent e)
          Reports that the print job has been completed, but currently ignored.
 void printJobFailed(PrintJobEvent e)
          Reports that there has been some problem with the print job.
 void printJobNoMoreEvents(PrintJobEvent e)
          Reports that there will be no more events generated by this print job, but currently ignored.
 void printJobRequiresAttention(PrintJobEvent e)
          Reports that print job requires attention of some kind.
 void printPreview(Frame parent, Printable printableObject)
          Provides a print preview of the given printable object.
 void run()
          Queries the available print services.
 Graphics2D scale(Graphics g, Dimension objectSize, PageFormat pageFormat, int pageIndex)
          Scales the given graphics to the required printer page dimensions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PrintUtilities

public PrintUtilities()
Sets up the print services for possible printing. To print a printable object, call one of the print() methods.


PrintUtilities

public PrintUtilities(DocFlavor flavour)
Sets up the print services for possible printing. To print a printable object, call one of the print() methods.

Parameters:
flavour - Type of document to print.
Method Detail

run

public void run()
Queries the available print services. This process is called by the constructor. Printing will be queued until the enquiries have been made.

Specified by:
run in interface Runnable

print

public void print(Printable printableObject,
                  boolean showDialogue)
Prints the given printable object.

Parameters:
printableObject - Printable object.
showDialogue - Will ask for printer type if true.

printPreview

public void printPreview(Frame parent,
                         Printable printableObject)
Provides a print preview of the given printable object.

Parameters:
parent - Parent GUI requesting print preview.
printableObject - Printable object.

scale

public Graphics2D scale(Graphics g,
                        Dimension objectSize,
                        PageFormat pageFormat,
                        int pageIndex)
Scales the given graphics to the required printer page dimensions. Will scale over several pages if necessary. Scales width of object to width of printer paper.

Parameters:
g - Graphics context to print.
objectSize - Size of object to print.
pageFormat - Page format for printing.
pageIndex - Page index (for multiple pages).
Returns:
Scaled graphics context ready for printing.

getScale

public float getScale(Dimension objectSize,
                      PageFormat pageFormat)
Reports the scaling that would be applied if an object of the given size was to be printed using the supplied page format. This can be useful for displaying scale invariant objects and text.

Parameters:
objectSize - Size of object to print.
pageFormat - Page format for printing.
Returns:
Scaling that would be applied.

printDataTransferCompleted

public void printDataTransferCompleted(PrintJobEvent e)
Reports that the transfer of data to print job has been completed, but currently ignored.

Specified by:
printDataTransferCompleted in interface PrintJobListener
Parameters:
e - Event monitoring print job.

printJobCompleted

public void printJobCompleted(PrintJobEvent e)
Reports that the print job has been completed, but currently ignored.

Specified by:
printJobCompleted in interface PrintJobListener
Parameters:
e - Event monitoring print job.

printJobFailed

public void printJobFailed(PrintJobEvent e)
Reports that there has been some problem with the print job.

Specified by:
printJobFailed in interface PrintJobListener
Parameters:
e - Event monitoring print job.

printJobCanceled

public void printJobCanceled(PrintJobEvent e)
Reports that the print job has been cancelled for some reason.

Specified by:
printJobCanceled in interface PrintJobListener
Parameters:
e - Event monitoring print job.

printJobNoMoreEvents

public void printJobNoMoreEvents(PrintJobEvent e)
Reports that there will be no more events generated by this print job, but currently ignored.

Specified by:
printJobNoMoreEvents in interface PrintJobListener
Parameters:
e - Event monitoring print job.

printJobRequiresAttention

public void printJobRequiresAttention(PrintJobEvent e)
Reports that print job requires attention of some kind.

Specified by:
printJobRequiresAttention in interface PrintJobListener
Parameters:
e - Event monitoring print job.

createA4

public static Paper createA4()
Returns an object representing A4 paper with 2cm margins.

Returns:
A4 paper dimensions.

createA3

public static Paper createA3()
Returns an object representing A3 paper with 2cm margins.

Returns:
A3 paper dimensions.


Copyright Jo Wood, 1996-2004, last modified, 3rd September, 2004