|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.banglapad.DocumentRenderer
public class DocumentRenderer
DocumentRenderer prints objects of type Document. Text attributes, including fonts, color, and small icons, will be rendered to a printed page. DocumentRenderer 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.
As objects which implement the Printable Interface, instances of the DocumentRenderer class can also be used as the argument in the setPrintable method of the PrinterJob class. Instead of using the print() methods detailed above, a programmer may gain access to the formatting capabilities of this class without using its print dialog by creating an instance of DocumentRenderer and setting the document to be printed with the setDocument() or setJEditorPane(). The Document may then be printed by setting the instance of DocumentRenderer in any PrinterJob.
Field Summary |
---|
Fields inherited from interface java.awt.print.Printable |
---|
NO_SUCH_PAGE, PAGE_EXISTS |
Constructor Summary | |
---|---|
DocumentRenderer()
The constructor initializes the pFormat and PJob variables. |
Method Summary | |
---|---|
javax.swing.text.Document |
getDocument()
Method to get the current Document |
boolean |
getScaleWidthToFit()
Method to get the current choice the width scaling option. |
void |
pageDialog()
pageDialog() displays a page setup dialog. |
int |
print(java.awt.Graphics graphics,
java.awt.print.PageFormat pageFormat,
int pageIndex)
The print method implements the Printable interface. |
void |
print(javax.swing.text.html.HTMLDocument htmlDocument)
print(HTMLDocument) is called to set an HTMLDocument for printing. |
void |
print(javax.swing.JEditorPane jedPane)
print(JEditorPane) prints a Document contained within a JEDitorPane. |
void |
print(javax.swing.text.PlainDocument plainDocument)
print(PlainDocument) is called to set a PlainDocument for printing. |
void |
setDocument(javax.swing.text.html.HTMLDocument htmlDocument)
Method to set an HTMLDocument as the Document to print. |
void |
setDocument(javax.swing.JEditorPane jedPane)
Method to set the Document to print as the one contained in a JEditorPane. |
void |
setDocument(javax.swing.text.PlainDocument plainDocument)
Method to set a PlainDocument as the Document to print. |
void |
setScaleWidthToFit(boolean scaleWidth)
Method to set the current choice of the width scaling option. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DocumentRenderer()
Method Detail |
---|
public javax.swing.text.Document getDocument()
public boolean getScaleWidthToFit()
public void pageDialog()
public int print(java.awt.Graphics graphics, java.awt.print.PageFormat pageFormat, int pageIndex)
The highlights of the process used print a page are as follows:
The Printable Interface always prints the area indexed by reference to the Graphics object. For instance, with a standard 8.5 x 11 inch page with 1 inch margins the rectangle X = 72, Y = 72, Width = 468, and Height = 648, the area 72, 72, 468, 648 will be painted regardless of which page is actually being printed.
To align the allocation Rectangle with the graphics2D object two things are done. The first step is to translate the X and Y coordinates of the graphics2D object to begin at the X and Y coordinates of the printable clip, see step VII. Next, when printing other than the first page, the allocation rectangle must start laying out in coordinates represented by negative numbers. After page one, the beginning of the allocation is started at minus the page end of the prior page. This moves the part which has already been rendered to before the printable clip of the graphics2D object.
Although public, print should not ordinarily be called by programs other than PrinterJob.
print
in interface java.awt.print.Printable
public void print(javax.swing.text.html.HTMLDocument htmlDocument)
public void print(javax.swing.JEditorPane jedPane)
public void print(javax.swing.text.PlainDocument plainDocument)
public void setDocument(javax.swing.text.html.HTMLDocument htmlDocument)
public void setDocument(javax.swing.JEditorPane jedPane)
public void setDocument(javax.swing.text.PlainDocument plainDocument)
public void setScaleWidthToFit(boolean scaleWidth)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |