gov.nih.nlm.util
Class JComponentPrintHandler

java.lang.Object
  extended bygov.nih.nlm.util.JComponentPrintHandler

public class JComponentPrintHandler
extends Object

Handles printing of HTML documents. Text attributes, including fonts, color, and small icons, will be rendered to a printed page. JComponentPrintHandler computes line breaks, paginates, and performs other formatting. An HTMLDocument is printed by sending it as an argument to the print(HTMLDocument) method. A PlainDocument is printed the same way. Other types of Documents must be sent in a JEditorPane as an argument to the print(JEditorPane) method. Printing documents in this way will automatically display a print dialog unless the printer name has been specified.

Author:
MEME Group

Field Summary
protected  JEditorPane jeditor_pane
           
protected  JTable jtable
           
protected  JTree jtree
           
protected  PageFormat p_format
           
protected  PrinterJob p_job
           
protected  PrintService p_service
           
protected  int pages_per_sheet
           
protected  int pages_printed
           
protected  String printer_name
           
protected  boolean scale_width_to_fit
           
protected  double scaling_factor
           
protected  String title
           
 
Constructor Summary
JComponentPrintHandler()
          Instantiates an JComponentPrintHandler.
 
Method Summary
 int getPagesPerSheet()
          Returns the number of pages per sheet.
 String getPrinterName()
          Returns the printer name.
 String[] getPrinterNames()
          Returns the list of available printer names.
 boolean getScaleWidthToFit()
          Indicates whether or not the document should be scaled to fit the width of the page.
 double getScalingFactor()
          Returns the scaling factor.
 String getTitle()
          Returns the title.
 void pageDialog()
          Displays a page setup dialog.
 int print(JEditorPane jed_pane)
          Prints the specified JEditorPane.
 int print(JTable jtable)
          Prints the specified JTable.
 int print(JTree jtree)
          Prints the specified JTable.
protected  int printDialog()
          Displays the print dialog and initiates printing in response to user input.
 void setOnePagePerSheet()
          Sets the number of pages per sheet to one (1).
 void setPrintComponent(JEditorPane jed_pane)
          Sets the component to print to the JEditorPane.
 void setPrintComponent(JTable jt)
          Sets the component to print to the JTable.
 void setPrintComponent(JTree jt)
          Sets the component to print to the JTable.
 void setPrinterName(String printer_name)
          Sets the printer name.
 void setScaleWidthToFit(boolean scale_width_to_fit)
          Set the scale width to fit flag.
 void setScalingFactor(double scaling_factor)
          Sets the scaling factor.
 void setTitle(String title)
          Sets the title.
 void setTwoPagesPerSheet()
          Sets the number of pages per sheet to two (2).
 
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

jtree

protected JTree jtree

jtable

protected JTable jtable

p_format

protected PageFormat p_format

p_job

protected PrinterJob p_job

p_service

protected PrintService p_service

printer_name

protected String printer_name

pages_per_sheet

protected int pages_per_sheet

pages_printed

protected int pages_printed

title

protected String title

scale_width_to_fit

protected boolean scale_width_to_fit

scaling_factor

protected double scaling_factor
Constructor Detail

JComponentPrintHandler

public JComponentPrintHandler()
Instantiates an JComponentPrintHandler.

Method Detail

setScaleWidthToFit

public void setScaleWidthToFit(boolean scale_width_to_fit)
Set the scale width to fit flag.

Parameters:
scale_width_to_fit - a flag indiciating whether or not to scale the content to fit into the allowable width

getScaleWidthToFit

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

Returns:
true if it should, false otherwise

setScalingFactor

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

Parameters:
scaling_factor - the scaling factor (higher is smaller)

getScalingFactor

public double getScalingFactor()
Returns the scaling factor.

Returns:
the scaling factor

setPrinterName

public void setPrinterName(String printer_name)
Sets the printer name.

Parameters:
printer_name - the printer name

getPrinterName

public String getPrinterName()
Returns the printer name.

Returns:
the printer name

getPrinterNames

public String[] getPrinterNames()
Returns the list of available printer names.

Returns:
the list of available printer names

setTitle

public void setTitle(String title)
Sets the title.

Parameters:
title - the title

getTitle

public String getTitle()
Returns the title.

Returns:
the title

getPagesPerSheet

public int getPagesPerSheet()
Returns the number of pages per sheet.

Returns:
the nubmer of pages per sheet

setOnePagePerSheet

public void setOnePagePerSheet()
Sets the number of pages per sheet to one (1).


setTwoPagesPerSheet

public void setTwoPagesPerSheet()
Sets the number of pages per sheet to two (2).


pageDialog

public void pageDialog()
Displays a page setup dialog.


print

public int print(JEditorPane jed_pane)
          throws PrinterException
Prints the specified JEditorPane.

Parameters:
jed_pane - the JEditorPane to print
Returns:
the number of pages printed
Throws:
PrinterException - if failed to print document

print

public int print(JTable jtable)
          throws PrinterException
Prints the specified JTable.

Parameters:
jtable - the JTable to print
Returns:
the number of pages printed
Throws:
PrinterException - if failed to print document

print

public int print(JTree jtree)
          throws PrinterException
Prints the specified JTable.

Parameters:
jtree - the JTable to print
Returns:
the number of pages printed
Throws:
PrinterException - if failed to print document

printDialog

protected int printDialog()
                   throws PrinterException
Displays the print dialog and initiates printing in response to user input.

Returns:
the number of pages printed
Throws:
PrinterException - if failed to print document

setPrintComponent

public void setPrintComponent(JEditorPane jed_pane)
Sets the component to print to the JEditorPane.

Parameters:
jed_pane - the JEditorPane

setPrintComponent

public void setPrintComponent(JTable jt)
Sets the component to print to the JTable.

Parameters:
jt - the JTable

setPrintComponent

public void setPrintComponent(JTree jt)
Sets the component to print to the JTable.

Parameters:
jt - the JTable


Copyright ©2005