public class EditorPageable
extends java.lang.Object
implements java.awt.print.Pageable, java.awt.print.Printable
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.
| Constructor and Description |
|---|
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. |
| Modifier and Type | Method and Description |
|---|---|
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. |
static void |
incrementNumber(char[] number)
Utility routine which, given a char array containing the string representation of a number, will increment the number by one.
|
protected void |
invalidate()
Invalidates our repagination info.
|
protected boolean |
isPageIndexValid(int pageIndex)
Checks if a page index is valid.
|
static int |
numDigits(int number)
Utility routine to compute the number of digits in the specified number.
|
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.
|
static void |
setNumber(char[] numberChars, int number)
Utility routine which, given a char array and a number, will convert the number into a char[] representation, and set it into the provided array, left-padding with spaces to fit the width properly.
|
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.
|
public EditorPageable(java.lang.String fileName,
BasicDocument document,
PrintOptions printOptions,
java.awt.print.PageFormat pageFormat)
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.fileName - the name of the file for the file headerdocument - the document to printprintOptions - the printing options to usepageFormat - the format of a pagepublic void setPrintOptions(PrintOptions printOptions)
printOptions - the print options to usepublic void setPageFormat(java.awt.print.PageFormat pageFormat)
public void repaginate()
protected void invalidate()
protected void repaginateIfNeeded()
protected boolean isPageIndexValid(int pageIndex)
pageIndex - the page to check
protected void verifyPageIndexValid(int pageIndex)
throws java.lang.IndexOutOfBoundsException
pageIndex - the page to checkjava.lang.IndexOutOfBoundsException - if the page is invalidpublic int getNumberOfPages()
Pageable implementations return the true number of pages rather than the UNKNOWN_NUMBER_OF_PAGES constant.getNumberOfPages in interface java.awt.print.PageablePageable.
public java.awt.print.PageFormat getPageFormat(int pageIndex)
throws java.lang.IndexOutOfBoundsException
PageFormat of the page specified by pageIndex.getPageFormat in interface java.awt.print.PageablepageIndex - the zero based index of the page whose PageFormat is being requestedPageFormat describing the size and orientation.IndexOutOfBoundsException - the Pageable does not contain the requested page.java.lang.IndexOutOfBoundsException
public java.awt.print.Printable getPrintable(int pageIndex)
throws java.lang.IndexOutOfBoundsException
Printable instance responsible for rendering the page specified by pageIndex.getPrintable in interface java.awt.print.PageablepageIndex - the zero based index of the page whose Printable is being requestedPrintable that renders the page.IndexOutOfBoundsException - the Pageable does not contain the requested page.java.lang.IndexOutOfBoundsException
public int print(java.awt.Graphics graphics,
java.awt.print.PageFormat pageFormat,
int pageIndex)
throws java.awt.print.PrinterException
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.print in interface java.awt.print.Printablegraphics - the context into which the page is drawnpageFormat - the size and orientation of the page being drawnpageIndex - the zero based index of the page to be drawnpageIndex specifies a non-existent page.java.awt.print.PrinterException - thrown when the print job is terminated.
protected void printHeader(java.awt.Graphics graphics,
java.awt.print.PageFormat pageFormat,
int pageIndex)
graphics - the context into which the page is drawnpageFormat - the size and orientation of the page being drawnpageIndex - the zero based index of the page to be drawn
protected void printLineNumbers(java.awt.Graphics graphics,
java.awt.print.PageFormat pageFormat,
int pageIndex)
graphics - the context into which the page is drawnpageFormat - the size and orientation of the page being drawnpageIndex - the zero based index of the page to be drawn
protected void printWrappedSymbols(java.awt.Graphics graphics,
java.awt.print.PageFormat pageFormat,
int pageIndex)
graphics - the context into which the page is drawnpageFormat - the size and orientation of the page being drawnpageIndex - the zero based index of the page to be drawn
protected void printText(java.awt.Graphics graphics,
java.awt.print.PageFormat pageFormat,
int pageIndex)
graphics - the context into which the page is drawnpageFormat - the size and orientation of the page being drawnpageIndex - the zero based index of the page to be drawnpublic static int numDigits(int number)
number - the number to calculate the number of digits for
public static void setNumber(char[] numberChars,
int number)
numberChars - the char array to store the result innumber - the integer to get the representation ofpublic static void incrementNumber(char[] number)
number - the char array to store the result in