Extension SDK 10.1.2

oracle.javatools.editor.print
Class EditorPageable

java.lang.Object
  extended byoracle.javatools.editor.print.EditorPageable
All Implemented Interfaces:
java.awt.print.Pageable, java.awt.print.Printable

public class EditorPageable
extends java.lang.Object
implements java.awt.print.Pageable, java.awt.print.Printable

The EditorPageable is an implementation of the Pageable interface to support printed output of a BasicDocument optionally using the syntax highlighting features of the editor framework.

Use the PrintOptions class to control the appearance of the printed output, whether we print out the syntax highlighting foreground colors and font styles, line numbers, page numbers, wrapping behavior, and so on. Note that this implementation will not print out highlights, nor will it print out any background colors. In case a syntax highlight foreground color is Color.white, black will be used in its place.


Field Summary
 
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
EditorPageable(java.lang.String fileName, BasicDocument document, PrintOptions printOptions, java.awt.print.PageFormat pageFormat)
          Construct a new EditorPageable that will be used for printing a document.
 
Method Summary
 int getNumberOfPages()
          Returns the number of pages in the set.
 java.awt.print.PageFormat getPageFormat(int pageIndex)
          Returns the PageFormat of the page specified by pageIndex.
 java.awt.print.Printable getPrintable(int pageIndex)
          Returns the Printable instance responsible for rendering the page specified by pageIndex.
protected  void invalidate()
          Invalidates our repagination info.
protected  boolean isPageIndexValid(int pageIndex)
          Checks if a page index is valid.
 int print(java.awt.Graphics graphics, java.awt.print.PageFormat pageFormat, int pageIndex)
          Prints the page at the specified index into the specified Graphics context in the specified format.
protected  void printHeader(java.awt.Graphics graphics, java.awt.print.PageFormat pageFormat, int pageIndex)
          Print out the header for the printed output, based on the settings of the print options.
protected  void printLineNumbers(java.awt.Graphics graphics, java.awt.print.PageFormat pageFormat, int pageIndex)
          Print out the line numbers on the left side of the page, depending on the settings in the print options.
protected  void printText(java.awt.Graphics graphics, java.awt.print.PageFormat pageFormat, int pageIndex)
          Print out the text content in the main part of the page.
protected  void printWrappedSymbols(java.awt.Graphics graphics, java.awt.print.PageFormat pageFormat, int pageIndex)
          Print out the wrapped symbols on the right, if we are performing line wrapping.
 void repaginate()
          Force a repagination to occur.
protected  void repaginateIfNeeded()
          Performs a repagination if we don't have any page info currently.
 void setPageFormat(java.awt.print.PageFormat pageFormat)
          Changes the page format of the document for printing.
 void setPrintOptions(PrintOptions printOptions)
          Sets the print options for printing.
protected  void verifyPageIndexValid(int pageIndex)
          Verifies that a page index is valid.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EditorPageable

public EditorPageable(java.lang.String fileName,
                      BasicDocument document,
                      PrintOptions printOptions,
                      java.awt.print.PageFormat pageFormat)
Construct a new EditorPageable that will be used for printing a document. The specified file name is used for printing the file header (if enabled), and the print options used for controlling the appearance of the output. The LanguageSupport of the document will be used to determine the syntax highlight rendering used.

Parameters:
fileName - the name of the file for the file header
document - the document to print
printOptions - the printing options to use
Method Detail

setPrintOptions

public void setPrintOptions(PrintOptions printOptions)
Sets the print options for printing. This will force a repagination to occur before printing.

Parameters:
printOptions - the print options to use

setPageFormat

public void setPageFormat(java.awt.print.PageFormat pageFormat)
Changes the page format of the document for printing. This will force a repagination to occur before printing.


repaginate

public void repaginate()
Force a repagination to occur. This will recalculate the number of pages in the printed output and the content of each page.


invalidate

protected void invalidate()
Invalidates our repagination info. This will force a repagination to occur before printing.


repaginateIfNeeded

protected void repaginateIfNeeded()
Performs a repagination if we don't have any page info currently.


isPageIndexValid

protected boolean isPageIndexValid(int pageIndex)
Checks if a page index is valid.

Parameters:
pageIndex - the page to check
Returns:
true if the page exists, false otherwise

verifyPageIndexValid

protected void verifyPageIndexValid(int pageIndex)
                             throws java.lang.IndexOutOfBoundsException
Verifies that a page index is valid. This will throw an exception if it is not.

Parameters:
pageIndex - the page to check
Throws:
java.lang.IndexOutOfBoundsException - if the page is invalid

getNumberOfPages

public int getNumberOfPages()
Returns the number of pages in the set. To enable advanced printing features, it is recommended that Pageable implementations return the true number of pages rather than the UNKNOWN_NUMBER_OF_PAGES constant.

Specified by:
getNumberOfPages in interface java.awt.print.Pageable
Returns:
the number of pages in this Pageable.

getPageFormat

public java.awt.print.PageFormat getPageFormat(int pageIndex)
                                        throws java.lang.IndexOutOfBoundsException
Returns the PageFormat of the page specified by pageIndex.

Specified by:
getPageFormat in interface java.awt.print.Pageable
Parameters:
pageIndex - the zero based index of the page whose PageFormat is being requested
Returns:
the PageFormat describing the size and orientation.
Throws:
IndexOutOfBoundsException - the Pageable does not contain the requested page.
java.lang.IndexOutOfBoundsException

getPrintable

public java.awt.print.Printable getPrintable(int pageIndex)
                                      throws java.lang.IndexOutOfBoundsException
Returns the Printable instance responsible for rendering the page specified by pageIndex.

Specified by:
getPrintable in interface java.awt.print.Pageable
Parameters:
pageIndex - the zero based index of the page whose Printable is being requested
Returns:
the Printable that renders the page.
Throws:
IndexOutOfBoundsException - the Pageable does not contain the requested page.
java.lang.IndexOutOfBoundsException

print

public int print(java.awt.Graphics graphics,
                 java.awt.print.PageFormat pageFormat,
                 int pageIndex)
          throws java.awt.print.PrinterException
Prints the page at the specified index into the specified Graphics context in the specified format. A PrinterJob calls the Printable interface to request that a page be rendered into the context specified by graphics. The format of the page to be drawn is specified by pageFormat. The zero based index of the requested page is specified by pageIndex. If the requested page does not exist then this method returns NO_SUCH_PAGE; otherwise PAGE_EXISTS is returned. The Graphics class or subclass implements the PrinterGraphics interface to provide additional information. If the Printable object aborts the print job then it throws a PrinterException.

Specified by:
print in interface java.awt.print.Printable
Parameters:
graphics - the context into which the page is drawn
pageFormat - the size and orientation of the page being drawn
pageIndex - the zero based index of the page to be drawn
Returns:
PAGE_EXISTS if the page is rendered successfully or NO_SUCH_PAGE if pageIndex specifies a non-existent page.
Throws:
java.awt.print.PrinterException - thrown when the print job is terminated.

printHeader

protected void printHeader(java.awt.Graphics graphics,
                           java.awt.print.PageFormat pageFormat,
                           int pageIndex)
Print out the header for the printed output, based on the settings of the print options.

Parameters:
graphics - the context into which the page is drawn
pageFormat - the size and orientation of the page being drawn
pageIndex - the zero based index of the page to be drawn

printLineNumbers

protected void printLineNumbers(java.awt.Graphics graphics,
                                java.awt.print.PageFormat pageFormat,
                                int pageIndex)
Print out the line numbers on the left side of the page, depending on the settings in the print options.

Parameters:
graphics - the context into which the page is drawn
pageFormat - the size and orientation of the page being drawn
pageIndex - the zero based index of the page to be drawn

printWrappedSymbols

protected void printWrappedSymbols(java.awt.Graphics graphics,
                                   java.awt.print.PageFormat pageFormat,
                                   int pageIndex)
Print out the wrapped symbols on the right, if we are performing line wrapping.

Parameters:
graphics - the context into which the page is drawn
pageFormat - the size and orientation of the page being drawn
pageIndex - the zero based index of the page to be drawn

printText

protected void printText(java.awt.Graphics graphics,
                         java.awt.print.PageFormat pageFormat,
                         int pageIndex)
Print out the text content in the main part of the page.

Parameters:
graphics - the context into which the page is drawn
pageFormat - the size and orientation of the page being drawn
pageIndex - the zero based index of the page to be drawn

Extension SDK

 

Copyright © 1997, 2004, Oracle. All rights reserved.