addbk.print
Class LinePrinter

java.lang.Object
  extended by addbk.print.LinePrinter

public class LinePrinter
extends java.lang.Object

Author:
Data Virtue - Public Domain - Copyright is hereby relinquished to the public domain.

Sorry for any spelling mistakes, if you improve this class PLEASE send me the new code!

seanka@datavirtue.com

This class simulates an old style (dot matrix, daisy wheel) printer. Just feed it the Font and some text: addLine(String), newLine(), formFeed(), and it shoots out perfectly on the paper No line wrapping, make sure to split up strings that contain new lines if you want the new lines to "print".

If 'boolean prompt' is set to false no print dialog is shown and printing takes place immediatly. This class still needs optimized for memory, you must always step lightly when printing large amount of data/pages.

This class could stand to be modified to allow greater control and configuration of the rendering page.

see main() for an example, just compile and run this class to see it in action. A print dialog will appear.


Constructor Summary
LinePrinter(java.awt.Font fnt, boolean prompt)
           
 
Method Summary
 void addLine(java.lang.String line)
          Adds a line of text to the page.
 void addLines(java.lang.String[] text)
          Adds the text Strings to the page.
 void formFeed()
          Manually starts a new page.
 void formFeed(java.awt.Font f)
          Starts a new "page" with a different font
 void go()
          Call formFeed() before calling go()
static void main(java.lang.String[] args)
           
 void newLine()
          Adds a "new line" (blank line).
 void setOrientation(java.lang.String orient)
          Set the orientation before calling formFeed() or go().
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LinePrinter

public LinePrinter(java.awt.Font fnt,
                   boolean prompt)
Method Detail

addLines

public void addLines(java.lang.String[] text)
Adds the text Strings to the page. If a line doesn't fit the page a new page is created and "printing" continues on the next page.


addLine

public void addLine(java.lang.String line)
Adds a line of text to the page. If a line goes over the page a new page is created and "printing" continues on the next page. You can create more methods to accept Vectors/Genrics and what not. Real new lines inside the string are ignored when rendering. This can be chaged by modifying this method to scan the string for the amount of newlines and then calling the newLine() method for each one.


newLine

public void newLine()
Adds a "new line" (blank line).


formFeed

public void formFeed()
Manually starts a new page.


formFeed

public void formFeed(java.awt.Font f)
Starts a new "page" with a different font


setOrientation

public void setOrientation(java.lang.String orient)
Set the orientation before calling formFeed() or go(). Valid strings are "portrait" and "landscape"


go

public void go()
Call formFeed() before calling go()


main

public static void main(java.lang.String[] args)