util
Class ComponentPrinter

java.lang.Object
  extended by java.lang.Thread
      extended by util.ComponentPrinter
All Implemented Interfaces:
java.awt.print.Pageable, java.awt.print.Printable, java.lang.Runnable

public class ComponentPrinter
extends java.lang.Thread
implements java.awt.print.Pageable, java.awt.print.Printable

Implements a simple printing class for an awtin a Thread.

Author:
Daniel Wachsstock

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Fields inherited from interface java.awt.print.Pageable
UNKNOWN_NUMBER_OF_PAGES
 
Fields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
 
Constructor Summary
ComponentPrinter(java.awt.Component c)
          Creates a new instance of ComponentPrinter with default PageFormat
ComponentPrinter(java.awt.Component c, java.awt.print.PageFormat format)
          Creates a new instance of StringPrinter
 
Method Summary
 int getNumberOfPages()
           
 java.awt.print.PageFormat getPageFormat(int pageIndex)
           
 java.awt.print.Printable getPrintable(int pageIndex)
           
 int print(java.awt.Graphics g, java.awt.print.PageFormat format, int pageIndex)
          renders a page
 void run()
          prints the Component
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ComponentPrinter

public ComponentPrinter(java.awt.Component c)
Creates a new instance of ComponentPrinter with default PageFormat


ComponentPrinter

public ComponentPrinter(java.awt.Component c,
                        java.awt.print.PageFormat format)
Creates a new instance of StringPrinter

Parameters:
c - the Component to print
format - the PageFormat to use; uses PrinterJob.getPrinterJob().defaultPage() if null
Method Detail

run

public void run()
prints the Component

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

getPageFormat

public java.awt.print.PageFormat getPageFormat(int pageIndex)
                                        throws java.lang.IndexOutOfBoundsException
Specified by:
getPageFormat in interface java.awt.print.Pageable
Throws:
java.lang.IndexOutOfBoundsException

print

public int print(java.awt.Graphics g,
                 java.awt.print.PageFormat format,
                 int pageIndex)
          throws java.awt.print.PrinterException
renders a page

Specified by:
print in interface java.awt.print.Printable
Parameters:
g - the Graphics to render on
format - the PageFormat to use for rendering
pageIndex - the page to print
Returns:
NO_SUCH_PAGE or PAGE_EXISTS, as approprite for pageIndex
Throws:
java.awt.print.PrinterException - if the component's print() method does

getNumberOfPages

public int getNumberOfPages()
Specified by:
getNumberOfPages in interface java.awt.print.Pageable

getPrintable

public java.awt.print.Printable getPrintable(int pageIndex)
                                      throws java.lang.IndexOutOfBoundsException
Specified by:
getPrintable in interface java.awt.print.Pageable
Throws:
java.lang.IndexOutOfBoundsException