gov.nih.nlm.util
Class OnePagePrintable

java.lang.Object
  extended bygov.nih.nlm.util.OnePagePrintable
All Implemented Interfaces:
Printable

public class OnePagePrintable
extends Object
implements Printable

Handles printing of the contents of a JEditorPane, JTree, and JTable using one page per sheet of paper. This class implements the Printable interface, instances of this class can also be used as the argument in the setPrintable method of the PrinterJob class.

Author:
MEME Group
See Also:
HTMLDocumentRenderer

Field Summary
protected  int current_page
           
protected  JEditorPane jeditor_pane
           
protected  JTable jtable
           
protected  JTree jtree
           
protected  double page_end_y
           
protected  double page_start_y
           
protected  int pages_printed
           
protected  String title
           
 
Fields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
 
Constructor Summary
OnePagePrintable(JEditorPane jp, String title)
          Instantiates OnePagePrintable using the specified JEditorPane and String title.
OnePagePrintable(JTable jt, String title)
          Instantiates OnePagePrintable using the specified JTable and String title.
OnePagePrintable(JTree jt, String title)
          Instantiates OnePagePrintable using the specified JTree and String title.
 
Method Summary
 int getPagesPrinted()
          Returns the number of pages printed.
 boolean getScaleWidthToFit()
          Indicates whether or not the content should be scaled to fit the width of the page.
 double getScalingFactor()
          Returns the scaling factor.
 int print(Graphics graphics, PageFormat page_format, int page_index)
          The print method implements the Printable interface.
protected  boolean printView(Graphics2D graphics_2D, Shape allocation, View view)
          printView is a recursive method which iterates through the tree structure of the view sent to it.
 void setScaleWidthToFit(boolean scale_width)
          Sets the flag indicating whether or not to scale the content.
 void setScalingFactor(double scaling_factor)
          Set the scaling factor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

current_page

protected int current_page

jeditor_pane

protected JEditorPane jeditor_pane

jtable

protected JTable jtable

jtree

protected JTree jtree

page_end_y

protected double page_end_y

page_start_y

protected double page_start_y

pages_printed

protected int pages_printed

title

protected String title
Constructor Detail

OnePagePrintable

public OnePagePrintable(JEditorPane jp,
                        String title)
Instantiates OnePagePrintable using the specified JEditorPane and String title.

Parameters:
jp - the JEditorPane to print
title - the title

OnePagePrintable

public OnePagePrintable(JTable jt,
                        String title)
Instantiates OnePagePrintable using the specified JTable and String title.

Parameters:
jt - the JTable to print
title - the title

OnePagePrintable

public OnePagePrintable(JTree jt,
                        String title)
Instantiates OnePagePrintable using the specified JTree and String title.

Parameters:
jt - the JTree to print
title - the title
Method Detail

getPagesPrinted

public int getPagesPrinted()
Returns the number of pages printed.

Returns:
the number of pages printed

print

public int print(Graphics graphics,
                 PageFormat page_format,
                 int page_index)
The print method implements the Printable interface. The code prints one logical page per sheet of paper with a title bar.

Specified by:
print in interface Printable
Parameters:
graphics - the Graphics representing the printer
page_format - the PageFormat
page_index - the page index
Returns:
an int representation of printable status

printView

protected boolean printView(Graphics2D graphics_2D,
                            Shape allocation,
                            View view)
printView is a recursive method which iterates through the tree structure of the view sent to it. If the view sent to printView is a branch view, that is one with children, the method calls itself on each of these children. If the view is a leaf view, that is a view without children which represents an actual piece of text to be painted, printView attempts to render the view to the Graphics2D object. I. When any view starts after the beginning of the current printable page, this means that there are pages to print and the method sets page_exists to true. II. When a leaf view is taller than the printable area of a page, it cannot, of course, be broken down to fit a single page. Such a View will be printed whenever it intersects with the Graphics2D clip. III. If a leaf view intersects the printable area of the graphics clip and fits vertically within the printable area, it will be rendered.

Parameters:
graphics_2D - An object Graphics2D
allocation - An object Shape
view - An object View
Returns:
A boolean representation of page status

getScaleWidthToFit

public boolean getScaleWidthToFit()
Indicates whether or not the content should be scaled to fit the width of the page.

Returns:
true if it should, false otherwise

setScaleWidthToFit

public void setScaleWidthToFit(boolean scale_width)
Sets the flag indicating whether or not to scale the content.

Parameters:
scale_width - A boolean flag indiciating whether or not to scale the content to fit the width of the page

setScalingFactor

public void setScalingFactor(double scaling_factor)
Set the scaling factor.

Parameters:
scaling_factor - the scaling factor

getScalingFactor

public double getScalingFactor()
Returns the scaling factor.

Returns:
the scaling factor


Copyright ©2005