Holger's
Java API

com.antelmann.util
Class TextPrinter

java.lang.Object
  extended by com.antelmann.util.TextPrinter
All Implemented Interfaces:
Printable

public class TextPrinter
extends Object
implements Printable

enables printing of plain text with line wrapping over multiple pages

Author:
Holger Antelmann
See Also:
PrintUtilities

Field Summary
protected  ArrayList<StringBuilder> pageText
           
static Font standardFont
          the standard font used when no specific font was specified for a TextPrinter
 
Fields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
 
Constructor Summary
TextPrinter(String text)
           
TextPrinter(String text, Font font, Color color)
           
 
Method Summary
 Color getColor()
           
 Font getFont()
           
 String getText()
          returns the text this object has been instanciated with.
 int print(Graphics g, PageFormat format, int pageIndex)
           
protected  String printPage(Graphics g, PageFormat format, StringBuilder text)
          prints the given text onto the given format using the given graphics.
protected  String printParagraph(Graphics2D g, PageFormat format, String paragraph, Point2D.Float pen)
           
 void setColor(Color color)
           
 void setFont(Font font)
           
 void startPrint()
          prints this TextPrinter directly to the default printer
 void startPrint(PrinterJob job, boolean showDialog)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

standardFont

public static Font standardFont
the standard font used when no specific font was specified for a TextPrinter


pageText

protected ArrayList<StringBuilder> pageText
Constructor Detail

TextPrinter

public TextPrinter(String text)

TextPrinter

public TextPrinter(String text,
                   Font font,
                   Color color)
Method Detail

getText

public String getText()
returns the text this object has been instanciated with. If the object was originally called with null as text, this method returns an empty string.


setFont

public void setFont(Font font)

setColor

public void setColor(Color color)

getFont

public Font getFont()

getColor

public Color getColor()

startPrint

public void startPrint()
                throws PrinterException
prints this TextPrinter directly to the default printer

Throws:
PrinterException

startPrint

public void startPrint(PrinterJob job,
                       boolean showDialog)
                throws PrinterException
Throws:
PrinterException

print

public int print(Graphics g,
                 PageFormat format,
                 int pageIndex)
          throws PrinterException
Specified by:
print in interface Printable
Throws:
PrinterException

printPage

protected String printPage(Graphics g,
                           PageFormat format,
                           StringBuilder text)
prints the given text onto the given format using the given graphics. The text parameter will be stripped to only contain the text that actually fit on the page, while the remainder is returned.

Returns:
the remaining text that didn't fit on the page (may return an empty string but never null)

printParagraph

protected String printParagraph(Graphics2D g,
                                PageFormat format,
                                String paragraph,
                                Point2D.Float pen)


(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads