Printable to print JTextComponent with
the header and footer.
Warning
this class is to be used in javax.swing.text.JTextComponent only.
The implementation creates a new JTextComponent (printShell)
to print the content using the Document, EditorKit and
rendering-affecting properties from the original JTextComponent.
printShell is laid out on the first print invocation.
This class can be used on any thread. Part of the implementation is executed on the EDT though.
| Modifier and Type | Class and Description |
|---|---|
| private static class | TextComponentPrintable.
Class to represent segment of integers. |
| Modifier and Type | Field and Description |
|---|---|
| private static final float | |
| private final Font | |
| private final MessageFormat | |
| private volatile FontRenderContext | |
| private static final float | |
| private final Font | |
| private final MessageFormat | |
| private boolean | |
| private static final int | |
| private boolean | |
| private final List | pagesMetrics
thread-safe list for storing pages metrics. |
| private final JTextComponent | printShell
Special text component used to print to the printer. |
| private final List | rowsMetrics
stores metrics for the unhandled rows. |
| private final JTextComponent |
| Access | Constructor and Description |
|---|---|
| private | TextComponentPrintable(JTextComponent
JTextComponent to printthe page header or headerFormat, MessageFormat null for nonethe page footer or footerFormat)null for noneConstructs |
| Modifier and Type | Method and Description |
|---|---|
| private void | acquireReadLock()
Tries to acquire document's readLock if it was released in releaseReadLock() method. |
| private void | |
| private static void | createFrames(final JEditorPane
the editor)JEditorPane to create frames forTriggers the frames creation for |
| private JTextComponent | Returns: the print shellJTextComponent to create a
printShell forcreates a printShell. |
| private JTextComponent | |
| private static List | Returns: list of all framesthe editor)JEditorPane to find the frames forReturns frames under the |
| private static void | getFrames(final Container
the container to find all frames under container, List<JEditorPane> List to append the results tooAdds all |
| public int | Returns: the number of pages.Implements sun. Returns the number of pages in this printable. |
| public static Printable | Returns: TextComponentPrintable to print textComponentJTextComponent to printthe page header, or headerFormat, final MessageFormat null for nonethe page footer, or footerFormat)null for noneReturns |
| private static boolean | Returns: true if the document has framesthe document)Document to checkChecks whether the document has frames. |
| private void | |
| private void | |
| public int | print(final Graphics graphics, final PageFormat pf, final int pageIndex)
Implements java. See Printable.print for the API description. |
| private int | printOnEDT(final Graphics graphics, final PageFormat pf, final int pageIndex)
The EDT part of the print method. |
| private void | |
| private void | updatePagesMetrics(final int
the page to update the metrics for pageIndex, final int the page height pageHeight)Calculates pageMetrics for the pages up to the |
| FOOTER_FONT_SIZE | back to summary |
|---|---|
| private static final float FOOTER_FONT_SIZE | |
| footerFont | back to summary |
|---|---|
| private final Font footerFont | |
| footerFormat | back to summary |
|---|---|
| private final MessageFormat footerFormat | |
| frc | back to summary |
|---|---|
| private volatile FontRenderContext frc | |
| HEADER_FONT_SIZE | back to summary |
|---|---|
| private static final float HEADER_FONT_SIZE | |
| headerFont | back to summary |
|---|---|
| private final Font headerFont | |
| headerFormat | back to summary |
|---|---|
| private final MessageFormat headerFormat | |
| isLayouted | back to summary |
|---|---|
| private boolean isLayouted | |
| LIST_SIZE | back to summary |
|---|---|
| private static final int LIST_SIZE | |
| needReadLock | back to summary |
|---|---|
| private boolean needReadLock | |
| pagesMetrics | back to summary |
|---|---|
| private final List<TextComponentPrintable. thread-safe list for storing pages metrics. The only metrics we need are yStart and yEnd. It has to be thread-safe since metrics are calculated on the printing thread and accessed on the EDT thread. sorted | |
| printShell | back to summary |
|---|---|
| private final JTextComponent printShell Special text component used to print to the printer. | |
| rowsMetrics | back to summary |
|---|---|
| private final List<TextComponentPrintable. stores metrics for the unhandled rows. The only metrics we need are yStart and yEnd when row is handled by updatePagesMetrics it is removed from the list. Thus the head of the list is the fist row to handle. sorted | |
| textComponentToPrint | back to summary |
|---|---|
| private final JTextComponent textComponentToPrint | |
| TextComponentPrintable | back to summary |
|---|---|
| private TextComponentPrintable(JTextComponent textComponent, MessageFormat headerFormat, MessageFormat footerFormat) Constructs
| |
| acquireReadLock | back to summary |
|---|---|
| private void acquireReadLock() Tries to acquire document's readLock if it was released in releaseReadLock() method. Note Not to be called on the EDT. | |
| calculateRowsMetrics | back to summary |
|---|---|
| private void calculateRowsMetrics() Calculates rowsMetrics for the document. The result is stored
in the
| |
| createFrames | back to summary |
|---|---|
| private static void createFrames(final JEditorPane editor) Triggers the frames creation for
| |
| createPrintShell | back to summary |
|---|---|
| private JTextComponent createPrintShell(final JTextComponent textComponent) creates a printShell.
It creates closest text component to
| |
| createPrintShellOnEDT | back to summary |
|---|---|
| private JTextComponent createPrintShellOnEDT(final JTextComponent textComponent) | |
| getFrames | back to summary |
|---|---|
| private static List Returns frames under the
| |
| getFrames | back to summary |
|---|---|
| private static void getFrames(final Container container, List<JEditorPane> list) Adds all
| |
| getNumberOfPages | back to summary |
|---|---|
| public int getNumberOfPages() Implements sun. Returns the number of pages in this printable.
This number is defined only after
| |
| getPrintable | back to summary |
|---|---|
| public static Printable getPrintable(final JTextComponent textComponent, final MessageFormat headerFormat, final MessageFormat footerFormat) Returns
| |
| isFrameSetDocument | back to summary |
|---|---|
| private static boolean isFrameSetDocument(final Document document) Checks whether the document has frames. Only HTMLDocument might have frames.
| |
| layout | back to summary |
|---|---|
| private void layout(final int width) Prepares
| |
| layoutOnEDT | back to summary |
|---|---|
| private void layoutOnEDT(final int width) The EDT part of layout method. This method is to be called on the EDT only. | |
| back to summary | |
|---|---|
| public int print(final Graphics graphics, final PageFormat pf, final int pageIndex) throws PrinterException Implements java. See Printable.print for the API description. There are two parts in the implementation. First part (print) is to be called on the printing thread. Second part (printOnEDT) is to be called on the EDT only. print triggers printOnEDT
| |
| printOnEDT | back to summary |
|---|---|
| private int printOnEDT(final Graphics graphics, final PageFormat pf, final int pageIndex) throws PrinterException The EDT part of the print method. This method is to be called on the EDT only. Layout should be done before calling this method. | |
| releaseReadLock | back to summary |
|---|---|
| private void releaseReadLock() Tries to release document's readlock Note: Not to be called on the EDT. | |
| updatePagesMetrics | back to summary |
|---|---|
| private void updatePagesMetrics(final int pageIndex, final int pageHeight) Calculates pageMetrics for the pages up to the
| |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final int | |
| pack-priv final int |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public int | compareTo(TextComponentPrintable.
Implements java. Compares this object with the specified object for order. |
| public boolean | equals(Object obj)
Overrides java. Indicates whether some other object is "equal to" this one. |
| public int | |
| public String |
| end | back to summary |
|---|---|
| pack-priv final int end | |
| start | back to summary |
|---|---|
| pack-priv final int start | |
| IntegerSegment | back to summary |
|---|---|
| pack-priv IntegerSegment(int start, int end) | |
| compareTo | back to summary |
|---|---|
| public int compareTo(TextComponentPrintable. Implements java. Doc from java. Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object. The implementor must ensure The implementor must also ensure that the relation is transitive:
Finally, the implementor must ensure that | |
| equals | back to summary |
|---|---|
| public boolean equals(Object obj) Overrides java. Doc from java. Indicates whether some other object is "equal to" this one.
The
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Doc from java. Returns a hash code value for this object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non-
| |