gov.nih.nlm.util
Class TwoPagePrintable

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

public class TwoPagePrintable
extends Object
implements Printable

Handles printing of the contents of a JEditorPane using two pages 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  double current_page
           
protected  JEditorPane jeditor_pane
           
protected  double page_end_y
           
protected  double page_start_y
           
protected  int[] page_starts
           
protected  int pages_printed
           
protected  String title
           
 
Fields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
 
Constructor Summary
TwoPagePrintable(JEditorPane jp, String title)
          Instantiates the TwoPagePrintable using the specified JEditorPane and String title.
 
Method Summary
 int getPagesPrinted()
          Returns the number of pages printed.
 boolean getScaleWidthToFit()
          Indicates whether or not to scale content to fit 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 indiciating whether or not to scale content to fit the width of the page
 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

jeditor_pane

protected JEditorPane jeditor_pane

page_end_y

protected double page_end_y

current_page

protected double current_page

page_start_y

protected double page_start_y

page_starts

protected int[] page_starts

pages_printed

protected int pages_printed

title

protected String title
Constructor Detail

TwoPagePrintable

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

Parameters:
jp - the JEditorPane 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 two logical pages to the same sheet of paper with a title bar and a vertical line separating the two pages.

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 to scale content to fit width of the page.

Returns:
true if the content should be scaled, false otherwise

setScaleWidthToFit

public void setScaleWidthToFit(boolean scale_width)
Sets the flag indiciating whether or not to scale content to fit the width of the page

Parameters:
scale_width - a boolean flag indicating whether or not to scale the content

setScalingFactor

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

Parameters:
scaling_factor - double

getScalingFactor

public double getScalingFactor()
Returns the scaling factor.

Returns:
the scaling factor


Copyright ©2005