gov.nih.nlm.util
Class HTMLDocumentRenderer

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

public class HTMLDocumentRenderer
extends Object

Handles printing of HTML documents. Text attributes, including fonts, color, and small icons, will be rendered to a printed page. HTMLDocumentRenderer 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  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
HTMLDocumentRenderer()
          Instantiates an HTMLDocumentRenderer.
 
Method Summary
 Document getDocument()
          Returns the current Document.
 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(HTMLDocument html_document)
          Prints the specified HTMLDocument.
 int print(JEditorPane jed_pane)
          Prints the specified JEditorPane.
 int print(PlainDocument plain_document)
          Prints the specified PlainDocument
protected  int printDialog()
          Displays the print dialog and initiates printing in response to user input.
protected  void setContentType(String type)
          Sets the content type the JEditorPane.
 void setDocument(HTMLDocument html_doc)
          Sets an HTMLDocument as the document to print.
 void setDocument(JEditorPane jed_pane)
          Sets the document to print as the one contained in a JEditorPane.
 void setDocument(PlainDocument plain_document)
          Sets a PlainDocument as the Document to print.
protected  void setDocument(String type, Document document)
          Sets the content type and document of the JEditorPane.
 void setOnePagePerSheet()
          Sets the number of pages per sheet to one (1).
 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

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

HTMLDocumentRenderer

public HTMLDocumentRenderer()
Instantiates an HTMLDocumentRenderer.

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).


getDocument

public Document getDocument()
Returns the current Document.

Returns:
the current Document

pageDialog

public void pageDialog()
Displays a page setup dialog.


print

public int print(HTMLDocument html_document)
          throws PrinterException
Prints the specified HTMLDocument.

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

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(PlainDocument plain_document)
          throws PrinterException
Prints the specified PlainDocument

Parameters:
plain_document - the PlainDocument 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

setContentType

protected void setContentType(String type)
Sets the content type the JEditorPane.

Parameters:
type - the content type the JEditorPane

setDocument

public void setDocument(HTMLDocument html_doc)
Sets an HTMLDocument as the document to print.

Parameters:
html_doc - the specified HTMLDocument

setDocument

public void setDocument(JEditorPane jed_pane)
Sets the document to print as the one contained in a JEditorPane. This method is useful when Java does not provide direct access to a particular Document type, such as a Rich Text Format document. With this method such a document can be sent to the HTMLDocumentRenderer class enclosed in a JEditorPane.

Parameters:
jed_pane - An object JEditorPane

setDocument

public void setDocument(PlainDocument plain_document)
Sets a PlainDocument as the Document to print.

Parameters:
plain_document - the PlainDocument to print

setDocument

protected void setDocument(String type,
                           Document document)
Sets the content type and document of the JEditorPane.

Parameters:
type - document type
document - the Document


Copyright ©2005