Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.dinopolis.util
Class PrintUtilities  view PrintUtilities download PrintUtilities.java

java.lang.Object
  extended byorg.dinopolis.util.PrintUtilities
All Implemented Interfaces:
java.awt.print.Printable

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

A simple utility class that lets you very simply print an arbitrary component. Just pass the component to the PrintUtilities.printComponent. The component you want to print doesn't need a print method and doesn't have to implement any interface or do anything special at all.

If you are going to be printing many times, it is marginally more efficient to first do the following:

    PrintUtilities printHelper = new PrintUtilities(theComponent);
  
then later do printHelper.print(). But this is a very tiny difference, so in most cases just do the simpler PrintUtilities.printComponent(componentToBePrinted). 7/99 Marty Hall, http://www.apl.jhu.edu/~hall/java/ May be freely used or adapted.


Field Summary
protected  java.awt.Component componentToBePrinted
           
 
Fields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
 
Constructor Summary
(package private) PrintUtilities(java.awt.Component componentToBePrinted)
          Constructor taking the component to be printed
 
Method Summary
static void disableDoubleBuffering(java.awt.Component c)
          The speed and quality of printing suffers dramatically if any of the containers have double buffering turned on.
static void enableDoubleBuffering(java.awt.Component c)
          Re-enables double buffering globally.
 void print()
          Prints the component set in the constructor
 int print(java.awt.Graphics g, java.awt.print.PageFormat pageFormat, int pageIndex)
          Implementation of the Printable interface.
static void printComponent(java.awt.Component componentToBePrinted)
          Prints the given component.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

componentToBePrinted

protected java.awt.Component componentToBePrinted
Constructor Detail

PrintUtilities

PrintUtilities(java.awt.Component componentToBePrinted)
Constructor taking the component to be printed

Method Detail

printComponent

public static void printComponent(java.awt.Component componentToBePrinted)
Prints the given component.


print

public void print()
Prints the component set in the constructor


print

public int print(java.awt.Graphics g,
                 java.awt.print.PageFormat pageFormat,
                 int pageIndex)
Implementation of the Printable interface.

Specified by:
print in interface java.awt.print.Printable

disableDoubleBuffering

public static void disableDoubleBuffering(java.awt.Component c)
The speed and quality of printing suffers dramatically if any of the containers have double buffering turned on. So this turns if off globally.


enableDoubleBuffering

public static void enableDoubleBuffering(java.awt.Component c)
Re-enables double buffering globally.