ij2x.print
Class PrintableDocument

java.lang.Object
  extended by ij2x.print.PrintableDocument
All Implemented Interfaces:
java.awt.print.Pageable, java.awt.print.Printable

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

This class implements the Pageable and Printable interfaces and allows the contents of any JTextComponent to be printed using the java.awt.print printing API.


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
PrintableDocument(javax.swing.text.JTextComponent textComponent)
          This constructor allows printing the contents of any JTextComponent using a default PageFormat and a default scale factor.
PrintableDocument(javax.swing.text.JTextComponent textComponent, java.awt.print.PageFormat format, double scalefactor)
          This constructor allows the contents of any JTextComponent to be printed, using any specified PageFormat object and any scaling factor.
 
Method Summary
 int getNumberOfPages()
          Return the number of pages.
 java.awt.print.PageFormat getPageFormat(int pagenum)
          Return the PageFormat object for the specified page.
 java.awt.print.Printable getPrintable(int pagenum)
          This Pageable method returns the Printable object for the specified page.
 int print(java.awt.Graphics g, java.awt.print.PageFormat format, int pageIndex)
          This is the basic Printable method that prints a specified page
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PrintableDocument

public PrintableDocument(javax.swing.text.JTextComponent textComponent)
This constructor allows printing the contents of any JTextComponent using a default PageFormat and a default scale factor. The default scale factor is .75 because the default fonts are overly large.


PrintableDocument

public PrintableDocument(javax.swing.text.JTextComponent textComponent,
                         java.awt.print.PageFormat format,
                         double scalefactor)
This constructor allows the contents of any JTextComponent to be printed, using any specified PageFormat object and any scaling factor.

Method Detail

getNumberOfPages

public int getNumberOfPages()
Return the number of pages. This is a Pageable method.

Specified by:
getNumberOfPages in interface java.awt.print.Pageable

getPageFormat

public java.awt.print.PageFormat getPageFormat(int pagenum)
Return the PageFormat object for the specified page. This is a Pageable method. This implementation uses the computed length of the page in the returned PageFormat object. The PrinterJob will use this as a clipping region, which will prevent extraneous parts of the document from being drawn in the top and bottom margins.

Specified by:
getPageFormat in interface java.awt.print.Pageable

getPrintable

public java.awt.print.Printable getPrintable(int pagenum)
This Pageable method returns the Printable object for the specified page. Since this class implements both Pageable and Printable, it just returns this.

Specified by:
getPrintable in interface java.awt.print.Pageable

print

public int print(java.awt.Graphics g,
                 java.awt.print.PageFormat format,
                 int pageIndex)
This is the basic Printable method that prints a specified page

Specified by:
print in interface java.awt.print.Printable