org.PingOO.DLAI.lib.util
Class TextPrintable

java.lang.Object
  |
  +--org.PingOO.DLAI.lib.util.TextPrintable

public class TextPrintable
extends java.lang.Object
implements java.awt.print.Printable

The class is a printable object used to print plain text.
It will format and prepare pages of text as the printer request them.

Printing text is exactly the same thing than drawing on screen.
Since I could not find any implemetnation of Printable for text, I had to do it myself.

Since:
PingOO 2.0
Version:
2.0
Author:
Fabrice Bouyé (bouye@cur-archamps.fr)
See Also:
Printable

Field Summary
private  boolean allowHeader
          Indicates if the header is to be printed.
(package private)  int currentPage
          The current page number.
private  java.awt.Font font
          The current font used to render the text.
private static java.awt.Font FONT
          The font used to render text.
private  java.awt.print.PageFormat pageFormat
          The current page format.
private  java.util.Vector pageVector
          The vector containing pre-computed pages.
static int TAB_SIZE
          The default number of space used to transform a tabulation.
private  java.lang.String text
          The full text to print.
 
Constructor Summary
TextPrintable(java.lang.String text)
          Creates a new printable object used to render plain text.
TextPrintable(java.lang.String text, boolean allowHeader)
          Creates a new printable object used to render plain text.
TextPrintable(java.lang.String text, java.awt.Font font)
          Creates a new printable object used to render plain text.
TextPrintable(java.lang.String text, java.awt.Font font, boolean allowHeader)
          Creates a new printable object used to render plain text.
 
Method Summary
protected  void preparePages(java.awt.Graphics graphics, java.awt.print.PageFormat pageFormat)
           
 int print(java.awt.Graphics graphics, java.awt.print.PageFormat pageFormat, int pageIndex)
          Prints the page at the specified index into the specified Graphics context in the specified format.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

TAB_SIZE

public static final int TAB_SIZE
The default number of space used to transform a tabulation.

FONT

private static final java.awt.Font FONT
The font used to render text.

allowHeader

private boolean allowHeader
Indicates if the header is to be printed.

font

private java.awt.Font font
The current font used to render the text.

text

private java.lang.String text
The full text to print.

pageVector

private java.util.Vector pageVector
The vector containing pre-computed pages.

pageFormat

private java.awt.print.PageFormat pageFormat
The current page format.

currentPage

int currentPage
The current page number.
Constructor Detail

TextPrintable

public TextPrintable(java.lang.String text)
Creates a new printable object used to render plain text.
Parameters:
text - The text to print.

TextPrintable

public TextPrintable(java.lang.String text,
                     java.awt.Font font)
Creates a new printable object used to render plain text.
Parameters:
font - The font used to render this text on the printer.

TextPrintable

public TextPrintable(java.lang.String text,
                     boolean allowHeader)
Creates a new printable object used to render plain text.
Parameters:
allowHeader - If true a header will be displayed on top of the page containing the page number and the current date.

TextPrintable

public TextPrintable(java.lang.String text,
                     java.awt.Font font,
                     boolean allowHeader)
Creates a new printable object used to render plain text.
Parameters:
font - The font used to render this text on the printer.
allowHeader - If true a header will be displayed on top of the page containing the page number and the current date.
Method Detail

preparePages

protected void preparePages(java.awt.Graphics graphics,
                            java.awt.print.PageFormat pageFormat)

print

public int print(java.awt.Graphics graphics,
                 java.awt.print.PageFormat pageFormat,
                 int pageIndex)
          throws java.awt.print.PrinterException
Prints the page at the specified index into the specified Graphics context in the specified format.
Specified by:
print in interface java.awt.print.Printable
Parameters:
graphics - The context into which the page is drawn.
pageFormat - The size and orientation of the page being drawn.
pageIndex - The zero based index of the page to be drawn
Returns:
Printable.PAGE_EXISTS if the page is rendered successfully or Printable.NO_SUCH_PAGE if pageIndex specifies a non-existent page.
Throws:
java.awt.print.PrinterException - Thrown when the print job is terminated.