info.jonclark.print
Class LinePrinter

java.lang.Object
  extended by info.jonclark.print.LinePrinter
All Implemented Interfaces:
Printable

public class LinePrinter
extends Object
implements Printable

Taken from "TextPrinter" at http://experts.about.com/q/Java-1046/Print-Simple-Text-File.htm


Field Summary
static String DEFAULT_FONT_NAME
          Default type name, Serif
static int DEFAULT_FONT_SIZE
          Default font size, 12 point
 
Fields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
 
Constructor Summary
LinePrinter()
          Create a TextPrinter object with the default type font and size.
LinePrinter(String name, int size)
          Create a TextPrinter object ready to print text with a given font and type size.
 
Method Summary
 boolean doPrint(String[] header, String[] body, boolean interactive)
          Print some text.
 int getCharsPerLine()
          Initialize the print job, and return the base number of characters per line with the established font size and font.
static void main(String[] args)
          Main method for testing.
 int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
          Perform printing according to the Java printing model.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_FONT_SIZE

public static final int DEFAULT_FONT_SIZE
Default font size, 12 point

See Also:
Constant Field Values

DEFAULT_FONT_NAME

public static final String DEFAULT_FONT_NAME
Default type name, Serif

See Also:
Constant Field Values
Constructor Detail

LinePrinter

public LinePrinter()
Create a TextPrinter object with the default type font and size.


LinePrinter

public LinePrinter(String name,
                   int size)
Create a TextPrinter object ready to print text with a given font and type size.

Method Detail

getCharsPerLine

public int getCharsPerLine()
Initialize the print job, and return the base number of characters per line with the established font size and font. This is really just a guess, because we can't get the font metrics yet.


doPrint

public boolean doPrint(String[] header,
                       String[] body,
                       boolean interactive)
                throws PrinterException
Print some text. Headers are printed first, in bold, followed by the body text, in plain style. If the boolean argument interactive is set to true, then the printer dialog gets shown. Either array may be null, in which case they are treated as empty. This method returns true if printing was initiated, or false if the user cancelled printer. This method may throw PrinterException if printing could not be started.

Throws:
PrinterException

print

public int print(Graphics graphics,
                 PageFormat pageFormat,
                 int pageIndex)
          throws PrinterException
Perform printing according to the Java printing model. NEVER CALL THIS DIRECTLY! It will be called by the PrinterJob as necessary. This method always returns Printable.NO_SUCH_PAGE for any page number greater than 0.

Specified by:
print in interface Printable
Throws:
PrinterException

main

public static void main(String[] args)
Main method for testing. This main method sets up a header of "PRINTER TEST" and reads System.in to get body text.