ReportCat 1.1

li.netcat.print
Class PrintManager

java.lang.Object
  extended byli.netcat.print.PrintManager
All Implemented Interfaces:
java.awt.print.Pageable, java.awt.print.Printable

public class PrintManager
extends java.lang.Object
implements java.awt.print.Pageable, java.awt.print.Printable

The PrintManager adds the PageFormat and the PrinterJob to a Print and controls the layouting, i.e. it uses the Print to create a PrintIterator and consumes all Painters of the iterator. The PrintManager also has the capability for scaling (Graphics2D required).

Author:
Arthur Marxer

Field Summary
 
Fields inherited from interface java.awt.print.Pageable
UNKNOWN_NUMBER_OF_PAGES
 
Fields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
 
Constructor Summary
PrintManager()
          Constructs a new PrintManager with no Print and a scale of 1.0.
PrintManager(boolean createPrinterJob, java.awt.print.PageFormat pageFormat)
          Constructs a new PrintManager with no Print and a scale of 1.0.
PrintManager(Print print)
          Constructs a new PrintManager with the given Print and a scale of 1.0.
 
Method Summary
 void addPrintManagerListener(PrintManagerListener listener)
          Adds a PrintManagerListener to the list of listerners.
 void ensureLayout(java.awt.Graphics g)
          Call this method to ensure that the layout is done.
 int getImageableHeight()
          Returns the current imageableHeight of the paper as an int.
 int getImageableWidth()
          Returns the current imageableWidth of the paper as an int.
 int getImageableX()
          Returns the current imageableX of the paper as an int.
 int getImageableY()
          Returns the current imageableY of the paper as an int.
 int getNumberOfPages()
           
 int getOrientation()
          Returns the current orientation of the PageFormat.
 int getPageCount()
          Returns the current number of pages or -1, if the layout is not jet done.
 java.awt.print.PageFormat getPageFormat()
          Returns a copy of the PageFormat associated with this PrintManager.
 java.awt.print.PageFormat getPageFormat(int page)
           
 Painter getPainter(int page)
          Returns the Painter that is able to paint the page with the given index.
 int getPaperHeight()
          Returns the current height of the paper as an int.
 int getPaperWidth()
          Returns the current width of the paper as an int.
 Print getPrint()
           
 java.awt.print.Printable getPrintable(int page)
           
 java.awt.print.PrinterJob getPrinterJob()
          Returns the PrinterJob associated with this PrintManager.
 double getScaleValue()
          Returns the scale value that is applyed by the PrintManager.
 void pageDialog(boolean separateThread)
          Shows the page dialog to change the PageFormat.
 void print(boolean showDialog)
          Prints the Print associated with the PrintManager.
 int print(java.awt.Graphics g, java.awt.print.PageFormat pageFormat, int pageIndex)
           
 void removePrintManagerListener(PrintManagerListener listener)
          Removes a PrintManagerListener from the list of listeners.
static void setErrorPainterTooManyPages(Painter painter)
          Sets the painter that is used when the layout exceeds the maximum number of pages.
static void setErrorPainterTooSmall(Painter painter)
          Sets the painter that is used when the imageable area is too small.
 void setImageableArea(int imageableX, int imageableY, int imageableWidth, int imageableHeight)
          Sets the imageable area of the PageFormat.
 void setMaxNumberOfPages(int number)
          Sets the maximum number of pages before the layout is aborted.
 void setOrientation(int orientation)
          Sets the orientation of the PageFormat.
 void setPageFormat(java.awt.print.PageFormat pageFormat)
          Sets the given PageFormat to the PrintManager.
 void setPrint(Print print)
          Sets the Print associated with this PrintManager.
 void setScaleValue(double scaleValue)
          Sets the scale value.
 void setValidateAgainstPrinterJob(boolean b)
          Specify true if the page layout should be validated against the PrinterJob.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PrintManager

public PrintManager()
Constructs a new PrintManager with no Print and a scale of 1.0.


PrintManager

public PrintManager(boolean createPrinterJob,
                    java.awt.print.PageFormat pageFormat)
Constructs a new PrintManager with no Print and a scale of 1.0.

Parameters:
createPrinterJob - Specify false, if you want to use the PrintManager as pure adapter class, i.e. it will NOT allocate its own PrinterJob instance. Note that the methods pageDialog(boolean) and print(boolean) will throw an IllegalStateException if the PrintManager has no PrinterJob instance.
pageFormat - The pageFormat that defines the size of one page. If set to null, the default page format of the printer job will be used. If the flag createPrinterJob is set fo false, this parameter must not be null.

PrintManager

public PrintManager(Print print)
Constructs a new PrintManager with the given Print and a scale of 1.0.

Method Detail

getPrinterJob

public java.awt.print.PrinterJob getPrinterJob()
Returns the PrinterJob associated with this PrintManager.

Returns:
The PrinterJob associated with this PrintManager.

getPaperWidth

public int getPaperWidth()
Returns the current width of the paper as an int.

Returns:
The current width of the paper as an int.

getPaperHeight

public int getPaperHeight()
Returns the current height of the paper as an int.

Returns:
The current height of the paper as an int.

getImageableX

public int getImageableX()
Returns the current imageableX of the paper as an int.

Returns:
The current imageableX of the paper as an int.

getImageableY

public int getImageableY()
Returns the current imageableY of the paper as an int.

Returns:
The current imageableY of the paper as an int.

getImageableWidth

public int getImageableWidth()
Returns the current imageableWidth of the paper as an int.

Returns:
The current imageableWidth of the paper as an int.

getImageableHeight

public int getImageableHeight()
Returns the current imageableHeight of the paper as an int.

Returns:
The current imageableHeight of the paper as an int.

getOrientation

public int getOrientation()
Returns the current orientation of the PageFormat.

Returns:
The current orientation of the PageFormat, one of the values LANDSCAPE, PORTRAIT or REVERSE_LANDSCAPE.

setOrientation

public void setOrientation(int orientation)
Sets the orientation of the PageFormat.

Parameters:
orientation - The orientation of the PageFormat, one of the values LANDSCAPE, PORTRAIT or REVERSE_LANDSCAPE.

getPageFormat

public java.awt.print.PageFormat getPageFormat()
Returns a copy of the PageFormat associated with this PrintManager. Modifications made to the returned instance take no effect.

Returns:
A copy of the PageFormat associated with that PrintManager.

setPageFormat

public void setPageFormat(java.awt.print.PageFormat pageFormat)
Sets the given PageFormat to the PrintManager. This method creates uses copy of the given parameter for further operations.

Parameters:
pageFormat - The PageFormat to be used for layouting.

setImageableArea

public void setImageableArea(int imageableX,
                             int imageableY,
                             int imageableWidth,
                             int imageableHeight)
Sets the imageable area of the PageFormat. This method is independent of the orientation.

Parameters:
imageableX - The x offset of the page format.
imageableY - The y offset of the page format.
imageableWidth - The imageable width of the page format.
imageableHeight - The mageable height of the page format.

getPrint

public Print getPrint()

setPrint

public void setPrint(Print print)
Sets the Print associated with this PrintManager.

Parameters:
print - The Print associated with this PrintManager, might be null.

setMaxNumberOfPages

public void setMaxNumberOfPages(int number)
Sets the maximum number of pages before the layout is aborted. The default value is 1000.

Parameters:
number - The macimum number of pages before the layout is aborted.

getPageCount

public int getPageCount()
Returns the current number of pages or -1, if the layout is not jet done. Use ensureLayout(...) to make sure that the layout is made. This method returns Integer.MAX_VALUE if an error occured during layouting.

Returns:
The current number of pages.

getPainter

public Painter getPainter(int page)
Returns the Painter that is able to paint the page with the given index.

Parameters:
page - The index of the page, starting at 0 as usual.

getScaleValue

public double getScaleValue()
Returns the scale value that is applyed by the PrintManager.

Returns:
The scale value that is applyed by the PrintManager.

setScaleValue

public void setScaleValue(double scaleValue)
Sets the scale value.

Parameters:
scaleValue - The scale value that is applyed by the PrintManager.

addPrintManagerListener

public void addPrintManagerListener(PrintManagerListener listener)
Adds a PrintManagerListener to the list of listerners.

Parameters:
listener - The listener to be added.

removePrintManagerListener

public void removePrintManagerListener(PrintManagerListener listener)
Removes a PrintManagerListener from the list of listeners.

Parameters:
listener - The listener to be removed.

pageDialog

public void pageDialog(boolean separateThread)
Shows the page dialog to change the PageFormat.

Parameters:
separateThread - Creates a new thread to run the dialog so that the swing thread continues working.

print

public void print(boolean showDialog)
           throws java.awt.print.PrinterException
Prints the Print associated with the PrintManager.

Parameters:
showDialog - Specify true to show the print dialog before printing.
Throws:
java.awt.print.PrinterException

setValidateAgainstPrinterJob

public void setValidateAgainstPrinterJob(boolean b)
Specify true if the page layout should be validated against the PrinterJob.

Parameters:
b - The flag.

ensureLayout

public void ensureLayout(java.awt.Graphics g)
Call this method to ensure that the layout is done.

Parameters:
g - The relevant Graphics object that is used for layouting.

setErrorPainterTooManyPages

public static void setErrorPainterTooManyPages(Painter painter)
Sets the painter that is used when the layout exceeds the maximum number of pages.

Parameters:
painter - A painter showing the error, not null.

setErrorPainterTooSmall

public static void setErrorPainterTooSmall(Painter painter)
Sets the painter that is used when the imageable area is too small.

Parameters:
painter - A painter showing the error, not null.

print

public int print(java.awt.Graphics g,
                 java.awt.print.PageFormat pageFormat,
                 int pageIndex)
Specified by:
print in interface java.awt.print.Printable

getPrintable

public java.awt.print.Printable getPrintable(int page)
Specified by:
getPrintable in interface java.awt.print.Pageable

getPageFormat

public java.awt.print.PageFormat getPageFormat(int page)
Specified by:
getPageFormat in interface java.awt.print.Pageable

getNumberOfPages

public int getNumberOfPages()
Specified by:
getNumberOfPages in interface java.awt.print.Pageable

ReportCat 1.1

Copyright © 2003 - 2005 NetCat Inc.. All rights reserved. Feedback

Print,Printing,Printer,Java,Java Print,SDK,Java Printing,Printing Java,Print Java,Library,Java Library,Print Library,Report,Reports,Java Report,Java Programming,Java Output,Layout,Page,API,Preview,Print Preview,Content,A4,Free,Output,Header,Footer,Download,Package,Jar,Evaluation, Print,Printing,Printer,Java,Java Print,SDK,Java Printing,Printing Java,Print Java,Library,Java Library,Print Library,Report,Reports,Java Report,Java Programming,Java Output,Layout,Page,API,Preview,Print Preview,Content,A4,Free,Output,Header,Footer,Download,Package,Jar,Evaluation, Print,Printing,Printer,Java,Java Print,SDK,Java Printing,Printing Java,Print Java,Library,Java Library,Print Library,Report,Reports,Java Report,Java Programming,Java Output,Layout,Page,API,Preview,Print Preview,Content,A4,Free,Output,Header,Footer,Download,Package,Jar,Evaluation