weka.gui
Class DocumentPrinting

java.lang.Object
  extended by weka.gui.DocumentPrinting
All Implemented Interfaces:
java.awt.print.Printable

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

DocumentPrinting is a class that lets you print documents on the fly for free ;) Printing in JDK 1.2 - 1.5 is hard. With this, you just simply call it in your application and add your text component like JTextPane:

 new DocumentPrinting().print(YourJTextComponent);
 
Reminder: Just make sure there is a text on your component ;P
 Author : Jan Michael Soan
 WebSite: http://www.jmsoan.com
 Date   : 04/17/2004 
 Time   : 2:20 PM 
 
Found on Toolbox (Terms of Use).

Author:
Jan Michael Soan (original code), FracPete (fracpete at waikato dot ac dot nz)

Field Summary
 
Fields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
 
Constructor Summary
DocumentPrinting()
          Initializes the printing.
 
Method Summary
 javax.swing.text.Document getDocument()
          Returns the document to print.
 boolean getScaleWidthToFit()
          Returns whether the width is to be scaled.
 int print(java.awt.Graphics graphics, java.awt.print.PageFormat pageFormat, int pageIndex)
          Prints the page.
 void print(javax.swing.JTextPane pane)
          Prints the document in the JTextPane.
 void printDialog()
          Shows the print dialog.
 void setContentType(java.lang.String type)
          Sets the content type.
 void setDocument(javax.swing.JTextPane pane)
          Sets the document from the given JTextPane.
 void setDocument(java.lang.String type, javax.swing.text.Document document)
          Sets the document and the according content type.
 void setScaleWidthToFit(boolean scaleWidth)
          Sets whether to scale the width to fit.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DocumentPrinting

public DocumentPrinting()
Initializes the printing.

Method Detail

print

public int print(java.awt.Graphics graphics,
                 java.awt.print.PageFormat pageFormat,
                 int pageIndex)
Prints the page.

Specified by:
print in interface java.awt.print.Printable
Parameters:
graphics - the graphics context
pageFormat - the format of the page
pageIndex - the page index
Returns:
either NO_SUCH_PAGE or PAGE_EXISTS
See Also:
Printable.NO_SUCH_PAGE, Printable.PAGE_EXISTS

print

public void print(javax.swing.JTextPane pane)
Prints the document in the JTextPane.

Parameters:
pane - the document to print

printDialog

public void printDialog()
Shows the print dialog.


setContentType

public void setContentType(java.lang.String type)
Sets the content type.

Parameters:
type - the content type

getDocument

public javax.swing.text.Document getDocument()
Returns the document to print.

Returns:
the document or null

setDocument

public void setDocument(javax.swing.JTextPane pane)
Sets the document from the given JTextPane.

Parameters:
pane - the JTextPane to get the document from

setDocument

public void setDocument(java.lang.String type,
                        javax.swing.text.Document document)
Sets the document and the according content type.

Parameters:
type - the content type
document - the document to print

setScaleWidthToFit

public void setScaleWidthToFit(boolean scaleWidth)
Sets whether to scale the width to fit.

Parameters:
scaleWidth - if true then the width will be scaled

getScaleWidthToFit

public boolean getScaleWidthToFit()
Returns whether the width is to be scaled.

Returns:
true if scaled