com.wildcrest.j2printerworks
Class J2TextPrinter

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended bycom.wildcrest.j2printerworks.J2Pageable
                  extended bycom.wildcrest.j2printerworks.J2TextPrinter
All Implemented Interfaces:
Flowable, java.awt.image.ImageObserver, java.awt.MenuContainer, java.awt.print.Pageable, java.io.Serializable

public class J2TextPrinter
extends J2Pageable

A Java 2 component for multi-page printing of the contents of any multi-line JTextComponent (JTextPane, JEditorPane, JTextArea) or subclass thereof, as either a Pageable or a Flowable, breaking pages on text line boundaries.

Prints the contents of any multi-line JTextComponent such as a JTextPane, JEditorPane, JTextArea, or any subclass thereof. The contents of the JTextComponent will either be reflowed (rewrapped) to fit the available page or can be printed in "WYSIWYG" mode to maintain the layout of the specified JTextComponent. In addition, if the JTextComponent is a JTextPane, it can have embedded graphics or embedded components (provided they are <1 page in size). You can specify page breaks directly in the JTextComponent. The JTextComponent can be left, right, or center justified horizontally, or top, bottom, or center justified vertically on the page.

The JTextComponent model (Document or StyledDocument for a JTextPane) can be generated programmatically or, in the case of JTextPane and JEditorPane, specified using HTML or RTF (subject to the limitations of Java's support for these formats).

In addition, all the standard J2Pageable features are also available when printing J2TextPrinter as a Pageable, including control of headers, footers, margins, orientation, and scale.

(C) Copyright 2009, Wildcrest Associates (http://www.wildcrest.com). All rights reserved.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class com.wildcrest.j2printerworks.J2Pageable
BOTTOM, BOX, CENTER, FIRST, GLOBAL, LANDSCAPE, LEFT, LINE, NONE, PORTRAIT, PPI72, REST, REVERSE_LANDSCAPE, RIGHT, TOP
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.print.Pageable
UNKNOWN_NUMBER_OF_PAGES
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
J2TextPrinter()
          Construct a J2TextPrinter object (no JTextComponent specified)
J2TextPrinter(javax.swing.JEditorPane pane)
          Construct a J2TextPrinter object for a given JEditorPane
J2TextPrinter(javax.swing.JTextArea pane)
          Construct a J2TextPrinter object for a given JTextArea
J2TextPrinter(javax.swing.JTextPane pane)
          Construct a J2TextPrinter object for a given JTextPane
J2TextPrinter(java.lang.String string)
          Construct a J2TextPrinter object for a given String (uses default font: SansSerif, PLAIN, 12 with color: black and alignment: left)
J2TextPrinter(java.lang.String string, java.awt.Font font)
          Construct a J2TextPrinter object for a given String and given Font (with color: black and alignment: left).
J2TextPrinter(java.lang.String string, java.awt.Font font, java.awt.Color color, int alignment)
          Construct a J2TextPrinter object for a given String, Font, Color, and alignment.
 
Method Summary
 void addPropertyChangeListener(java.beans.PropertyChangeListener l)
          Add a PropertyChangeListener for this component
static void appendStyledText(javax.swing.JTextPane pane, java.lang.String string, javax.swing.text.SimpleAttributeSet attribute)
          Convenience method for appending text with the specified rich text attributes to the end of the StyledDocument that represents the current contents of the JTextPane.
static void clearPane(javax.swing.JTextPane pane)
          Convenience method to clear all text and attributes in the specified JTextPane
 javax.swing.JEditorPane clone(javax.swing.JEditorPane oldPane)
          Convenience factory method for making a new JEditorPane whose Document is a serialized copy (deep clone) of the specified JEditorPane's Document.
 javax.swing.JTextArea clone(javax.swing.JTextArea oldArea)
          Convenience factory method for making a new JTextArea whose Document is a serialized copy (deep clone) of the specified JTextArea's Document.
 javax.swing.JTextPane clone(javax.swing.JTextPane oldPane)
          Convenience factory method for making a new JTextPane whose StyledDocument is a serialized copy (deep clone) of the specified JTextPane's StyledDocument.
 void dispose()
          Release all heap objects created by this J2TextPrinter object, must not call until printing completes.
 boolean doneX()
          Returns whether there is no more of this Flowable object to print horizontally.
 boolean doneY()
          Returns whether there is no more of this Flowable object to print vertically.
 int getHorizontalAlignment()
          Returns horizontal alignment (LEFT, CENTER, RIGHT) of this JTextComponent on page.
 double getMaximumPaginationGap()
          Returns largest acceptable pagination gap as a percentage of the full body height.
 java.awt.Color getOutsideLineColor()
          Returns outside line Color.
 javax.swing.JTextPane getPane()
          Returns the JTextPane containing the StyledDocument that will be printed.
 javax.swing.text.JTextComponent getTextComponent()
          Returns the JTextComponent whose contents (Document) will be printed.
 int getVerticalAlignment()
          Returns vertical alignment (TOP, CENTER, BOTTOM) of this JTextComponent on page.
 void hideImagingFrame()
          Hide internal imaging JFrame (left behind if have embedded components), must only be called after printing completes.
 boolean isCloningUsed()
          Returns whether cloning is used for J2TextPrinter printing (see explanation under setCloningUsed).
 boolean isDirectPrint()
          Returns current value of Direct Print mode.
 boolean isOutsideLines()
          Returns whether to print outside border lines around this JTextComponent.
 boolean isPrintHTMLComments()
          Returns current value of printHTMLComments mode.
 boolean isWYSIWYG()
          Returns current value of wysiwyg mode.
static javax.swing.JTextPane makeHTMLPane(java.lang.String html)
          Convenience factory method for creating a JTextPane using an HTML String.
static javax.swing.text.SimpleAttributeSet makeSimpleAttributeSet(java.lang.String fontName, java.lang.String style, int size, int align, java.awt.Color color)
          Convenience factory method for making a SimpleAttributeSet for a desired Font, specified using font name, style, size, alignment, and color.
 void printFlowable(java.awt.Graphics g, int availableWidth, int availableHeight, int nextFullPageWidth, int nextFullPageHeight)
          Print the next sequential section of this Flowable object that fits into the next incremental area.
 void removePropertyChangeListener(java.beans.PropertyChangeListener l)
          Remove a PropertyChangeListener for this component
 void resetFlowable()
          Reset the Flowable object so that it starts printing from the beginning.
 void setCloningUsed(boolean cloningUsed)
          Specify whether cloning (copying by Java serialization) is to be used when printing with J2TextPrinter.
 void setDirectPrint(boolean directPrint)
          Sets whether "direct print" mode is enabled (see documentation).
 void setHorizontalAlignment(int horizontalAlignment)
          Sets the horizontal alignment (LEFT, CENTER, RIGHT) for printing the JTextComponent on the page, typically used with setWYSIWYG(true).
 void setHTMLEditorKit(javax.swing.text.html.HTMLEditorKit kit)
          Notify J2TextPrinter of your use of a custom HTMLEditorKit for this JTextPane or JEditorPane.
 void setMaximumPages(int pagesHigh)
          Rescale this J2TextPrinter to print within a maximum number of vertical pages (will minify to fit).
 void setMaximumPaginationGap(double maximumPaginationGap)
          Sets the largest acceptable pagination gap as a percentage of the full body height.
 void setOutsideLineColor(java.awt.Color outsideLineColor)
          Sets Color of outside border lines.
 void setOutsideLines(boolean showOutsideLines)
          Sets whether to print outside border lines around this JTextComponent.
 void setPane(javax.swing.JTextPane pane)
          Convenience method for specifying the JTextPane containing a StyledDocument that will be printed.
 void setPrintHTMLComments(boolean printHTMLComments)
          Sets whether HTML comments (delimited by <!-- and -->) are printed when printing HTML documents.
 void setTextComponent(javax.swing.text.JTextComponent component)
          Specifies the JTextComponent (JTextPane, JEditorPane, or JTextArea whose contents (Document) will be printed.
 void setVerticalAlignment(int verticalAlignment)
          Sets the vertical alignment (TOP, CENTER, BOTTOM) for printing the JTextComponent on the page.
 void setWYSIWYG(boolean wysiwyg)
          Sets whether WYSIWYG (What-You-See-Is-What-You-Get) mode is enabled (and thereby prevent relayout of text).
 int usedX()
          Returns the amount this Flowable object was able to advance horizontally in the last printFlowable call.
 int usedY()
          Returns the amount this Flowable object was able to advance vertically in the last printFlowable call.
 
Methods inherited from class com.wildcrest.j2printerworks.J2Pageable
clearFooters, clearFooters, clearHeaders, clearHeaders, getBodyHeight, getBodyWidth, getBottomMargin, getCenterFooter, getCenterFooter, getCenterHeader, getCenterHeader, getFooterFont, getFooterFont, getFooterStyle, getFooterStyle, getGapAboveFooter, getGapBelowHeader, getHeaderFont, getHeaderFont, getHeaderStyle, getHeaderStyle, getLeftFooter, getLeftFooter, getLeftHeader, getLeftHeader, getLeftMargin, getMaximumSize, getMinimumSize, getNumberOfPages, getNumberOfPagesHigh, getNumberOfPagesWide, getOrientation, getPageFormat, getPageFormat, getPreferredSize, getPrintable, getRightFooter, getRightFooter, getRightHeader, getRightHeader, getRightMargin, getScale, getTopMargin, paint, setBottomMargin, setCenterFooter, setCenterFooter, setCenterHeader, setCenterHeader, setFooterFont, setFooterFont, setFooterStyle, setFooterStyle, setGapAboveFooter, setGapBelowHeader, setHeaderFont, setHeaderFont, setHeaderStyle, setHeaderStyle, setLeftFooter, setLeftFooter, setLeftHeader, setLeftHeader, setLeftMargin, setLocale, setMaximumPages, setOrientation, setPageFormat, setParam, setRightFooter, setRightFooter, setRightHeader, setRightHeader, setRightMargin, setScale, setTopMargin
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getNextFocusableComponent, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

J2TextPrinter

public J2TextPrinter()
Construct a J2TextPrinter object (no JTextComponent specified)


J2TextPrinter

public J2TextPrinter(javax.swing.JTextPane pane)
Construct a J2TextPrinter object for a given JTextPane


J2TextPrinter

public J2TextPrinter(javax.swing.JEditorPane pane)
Construct a J2TextPrinter object for a given JEditorPane


J2TextPrinter

public J2TextPrinter(javax.swing.JTextArea pane)
Construct a J2TextPrinter object for a given JTextArea


J2TextPrinter

public J2TextPrinter(java.lang.String string)
Construct a J2TextPrinter object for a given String (uses default font: SansSerif, PLAIN, 12 with color: black and alignment: left)


J2TextPrinter

public J2TextPrinter(java.lang.String string,
                     java.awt.Font font,
                     java.awt.Color color,
                     int alignment)
Construct a J2TextPrinter object for a given String, Font, Color, and alignment.

Parameters:
string - String specifying desired text string to be printed
font - Font specifying desired Font to be used for printinge
color - Color specifying the desired Color of the text to be printed
alignment - int specifying desired left, center, right alignment, e.g., StyleConstants.ALIGN_LEFT, etc.

J2TextPrinter

public J2TextPrinter(java.lang.String string,
                     java.awt.Font font)
Construct a J2TextPrinter object for a given String and given Font (with color: black and alignment: left).

Parameters:
string - String specifying desired text string to be printed
font - Font specifying desired Font to be used for printinge
Method Detail

dispose

public void dispose()
Release all heap objects created by this J2TextPrinter object, must not call until printing completes.

Overrides:
dispose in class J2Pageable

hideImagingFrame

public void hideImagingFrame()
Hide internal imaging JFrame (left behind if have embedded components), must only be called after printing completes.


printFlowable

public void printFlowable(java.awt.Graphics g,
                          int availableWidth,
                          int availableHeight,
                          int nextFullPageWidth,
                          int nextFullPageHeight)
Description copied from interface: Flowable
Print the next sequential section of this Flowable object that fits into the next incremental area.

Parameters:
g - context into which the page is to be drawn (null means advance but don't actually print)
availableWidth - horizontal amount into which the next sequential amount of this Flowable is to be printed.
availableHeight - vertical amount into which the next sequential amount of this Flowable is to be printed.
nextFullPageWidth - horizontal size of next full page (lets Flowables decide whether to opt for next page).
nextFullPageHeight - vertical size of next full page (lets Flowables decide whether to opt for next page).

The above parameters specify a rectangular area of size width by height (height = down the page) in pixels (72 dpi printing "points"). A Flowable object is assumed to print in "raster" order (over then down). Assumes upon entry that translation and scale are already set up so that 0,0 is the upper left corner to print and width and height are already increased by the overall printer scale. Flowable object must return Graphics context translation and scale to values at entry if changed during printing. Upon return from printFlowable, the doneX, doneY, usedX, and usedY methods describe the resulting state of the Flowable, based on its ability to make progress. Return values of usedX and usedY are to be specified in same scale as availableWidth and availableHeight were given.


usedX

public int usedX()
Description copied from interface: Flowable
Returns the amount this Flowable object was able to advance horizontally in the last printFlowable call.


usedY

public int usedY()
Description copied from interface: Flowable
Returns the amount this Flowable object was able to advance vertically in the last printFlowable call.


doneX

public boolean doneX()
Description copied from interface: Flowable
Returns whether there is no more of this Flowable object to print horizontally.


doneY

public boolean doneY()
Description copied from interface: Flowable
Returns whether there is no more of this Flowable object to print vertically.


resetFlowable

public void resetFlowable()
Description copied from interface: Flowable
Reset the Flowable object so that it starts printing from the beginning.


setMaximumPages

public void setMaximumPages(int pagesHigh)
Rescale this J2TextPrinter to print within a maximum number of vertical pages (will minify to fit). Note: This method causes the rescaling to take place at the time it is called and does NOT remember or maintain the page limits you specify. Thus, if you change any printing parameters including your document content, headers, footers, margins, paper size, orientation, printer, etc., you must call setMaximumPages again.

Parameters:
pagesHigh - specifies maximum vertical number of pages for printing this J2TextPrinter (< or = 0 if unconstrained).

clone

public javax.swing.JTextPane clone(javax.swing.JTextPane oldPane)
Convenience factory method for making a new JTextPane whose StyledDocument is a serialized copy (deep clone) of the specified JTextPane's StyledDocument. Can subclass J2TextPrinter and override this method to provide own cloning method.

Parameters:
oldPane - JTextPane whose contents is to be cloned
Throws:
CloneException - if unable to serialize JTextPane's StyledDocument

clone

public javax.swing.JEditorPane clone(javax.swing.JEditorPane oldPane)
Convenience factory method for making a new JEditorPane whose Document is a serialized copy (deep clone) of the specified JEditorPane's Document. Can subclass J2TextPrinter and override this method to provide own cloning method.

Parameters:
oldPane - JEditorPane whose contents is to be cloned
Throws:
CloneException - if unable to serialize JEditorPane's Document

setHTMLEditorKit

public void setHTMLEditorKit(javax.swing.text.html.HTMLEditorKit kit)
Notify J2TextPrinter of your use of a custom HTMLEditorKit for this JTextPane or JEditorPane. When printing, J2PrinterWorks places your JTextPane/JEdtiorPane Document in an internal JTextPane/JEditorPane so it can reflow the text to the printed page width. This internal JTextPane/JEditorPane uses a special HTMLEditorKit that performs synchronous loading of images so that they are guaranteed to be loaded before printing begins. If you have defined your own custom HTMLEditorKit, you can use this method to direct J2TextPrinter to use your HTMLEditorKit when printing. In this case you will then be responsible for ensuring the synchronous loading of images by calling setLoadSynchronously(true) in the ImageView of the ViewFactory of your HTMLEditorKit.

Parameters:
kit - HTMLEditorKit to use when printing this JTextPane or JEditorPane

clone

public javax.swing.JTextArea clone(javax.swing.JTextArea oldArea)
Convenience factory method for making a new JTextArea whose Document is a serialized copy (deep clone) of the specified JTextArea's Document. Can subclass J2TextPrinter and override this method to provide own cloning method.

Parameters:
oldArea - JTextArea whose contents is to be cloned
Throws:
CloneException - if unable to serialize JTextArea's Document

makeHTMLPane

public static javax.swing.JTextPane makeHTMLPane(java.lang.String html)
Convenience factory method for creating a JTextPane using an HTML String. The JTextPane will use a special HTMLEditorKit which, unlike the default, uses synchronous loading of images, so that images are assured to be loaded when this method returns.

Parameters:
html - String specifying desired HTML contents for JTextPane

appendStyledText

public static void appendStyledText(javax.swing.JTextPane pane,
                                    java.lang.String string,
                                    javax.swing.text.SimpleAttributeSet attribute)
Convenience method for appending text with the specified rich text attributes to the end of the StyledDocument that represents the current contents of the JTextPane.

Parameters:
pane - JTextPane for appending styled text with the specified attributes
string - String of characters to be appended to the specified JTextPane
attribute - SimpleAttributeSet specifying desired text style (use makeSimpleAttributeSet)

clearPane

public static void clearPane(javax.swing.JTextPane pane)
Convenience method to clear all text and attributes in the specified JTextPane

Parameters:
pane - JTextPane for which all text and attributes will be cleared

makeSimpleAttributeSet

public static javax.swing.text.SimpleAttributeSet makeSimpleAttributeSet(java.lang.String fontName,
                                                                         java.lang.String style,
                                                                         int size,
                                                                         int align,
                                                                         java.awt.Color color)
Convenience factory method for making a SimpleAttributeSet for a desired Font, specified using font name, style, size, alignment, and color. You can add additional attributes using code like the following:

     SimpleAttributeSet aset = makeSimpleAttributeSet("Serif",
                                                      "BoldItalic",
                                                      12,
                                                      StyleConstants.ALIGN_LEFT,
                                                      Color.black);
     StyleConstants.setLineSpacing(aset,.25);
     StyleConstants.setBackground(aset,Color.yellow);
 

and similarly using StyleConstants for other attributes such as TabSet, FirstLineIndent, etc.

Parameters:
fontName - String name of desired Font, e.g., "Serif", "SansSerif"
style - String specifying the desired style using any combination of the words "Bold", "Italic", and/or "Underline"
size - the desired point size of Font
align - int = StyleConstants.ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT, or ALIGN_JUSTIFIED
color - desired Color of Font

setTextComponent

public void setTextComponent(javax.swing.text.JTextComponent component)
Specifies the JTextComponent (JTextPane, JEditorPane, or JTextArea whose contents (Document) will be printed. Need to call again if content of JTextComponent is changed after being printed.

Parameters:
component - the JTextComponent (JTextPane, JEditorPane, or JTexArea) whose contents (Document) will be printed

getTextComponent

public javax.swing.text.JTextComponent getTextComponent()
Returns the JTextComponent whose contents (Document) will be printed.


setPane

public void setPane(javax.swing.JTextPane pane)
Convenience method for specifying the JTextPane containing a StyledDocument that will be printed. Need to call again if content of JTextPane is changed after being printed.

Parameters:
pane - the JTextPane whose contents (StyledDocument) will be printed

getPane

public javax.swing.JTextPane getPane()
Returns the JTextPane containing the StyledDocument that will be printed.


setHorizontalAlignment

public void setHorizontalAlignment(int horizontalAlignment)
Sets the horizontal alignment (LEFT, CENTER, RIGHT) for printing the JTextComponent on the page, typically used with setWYSIWYG(true).

Parameters:
horizontalAlignment - J2TextPrinter.LEFT, .CENTER, or .RIGHT (default: CENTER)

getHorizontalAlignment

public int getHorizontalAlignment()
Returns horizontal alignment (LEFT, CENTER, RIGHT) of this JTextComponent on page.


setVerticalAlignment

public void setVerticalAlignment(int verticalAlignment)
Sets the vertical alignment (TOP, CENTER, BOTTOM) for printing the JTextComponent on the page.

Parameters:
verticalAlignment - J2TextPrinter.TOP, .CENTER, or .BOTTOM (default: TOP)

getVerticalAlignment

public int getVerticalAlignment()
Returns vertical alignment (TOP, CENTER, BOTTOM) of this JTextComponent on page.


setOutsideLines

public void setOutsideLines(boolean showOutsideLines)
Sets whether to print outside border lines around this JTextComponent.

Parameters:
showOutsideLines - true means print outside border lines, false if not (default: true)

isOutsideLines

public boolean isOutsideLines()
Returns whether to print outside border lines around this JTextComponent.


setOutsideLineColor

public void setOutsideLineColor(java.awt.Color outsideLineColor)
Sets Color of outside border lines.

Parameters:
outsideLineColor - color with which to draw outside lines (default: Color.black)

getOutsideLineColor

public java.awt.Color getOutsideLineColor()
Returns outside line Color.


setMaximumPaginationGap

public void setMaximumPaginationGap(double maximumPaginationGap)
Sets the largest acceptable pagination gap as a percentage of the full body height. When an embedded image, component, or very large font won't fit in the remaining space on a page, then skip to the top of the next page if the remaining space is less than this value, otherwise split the content over the page boundary.

Parameters:
maximumPaginationGap - The largest acceptable pagination gap as percentage of full body height. Must be less than 1.0 (will be set to 0.99 if a value 1.0 or greater is requested). A value of 0.0 means always split, never waste a pixel, close to 1.0 means OK to skip most of a page to keep content intact (default: 0.2).

getMaximumPaginationGap

public double getMaximumPaginationGap()
Returns largest acceptable pagination gap as a percentage of the full body height.


setWYSIWYG

public void setWYSIWYG(boolean wysiwyg)
Sets whether WYSIWYG (What-You-See-Is-What-You-Get) mode is enabled (and thereby prevent relayout of text).

True means JTextComponent width will be preserved when printing so that the JTextComponent will not undergo relayout. If the JTextComponent is wider than the printable page area between margins, the JTextComponent will be scaled (minified) to fit. False means the JTextComponent contents will be reflowed to fit the printable page area between margins.

Parameters:
wysiwyg - boolean representing whether to preserve the JTextComponent width when printing. Default: false

isWYSIWYG

public boolean isWYSIWYG()
Returns current value of wysiwyg mode.


setPrintHTMLComments

public void setPrintHTMLComments(boolean printHTMLComments)
Sets whether HTML comments (delimited by <!-- and -->) are printed when printing HTML documents. Displaying HTML comments is based on whether you call setEditable(true) on your JTextPane or JEditorPane. Printing HTML comments requires both setEditable(true) and setPrintHTMLComments(true).

The setPrintHTMLComments method has no effect if you call setDirectPrint(true). In that case, to get comments to print you need to call both setEditable(true) and setVisible(true) on your JTextPane or JEditorPane.

Parameters:
printHTMLComments - boolean representing whether to enable printing of HTML comments. Default: false

isPrintHTMLComments

public boolean isPrintHTMLComments()
Returns current value of printHTMLComments mode.


setDirectPrint

public void setDirectPrint(boolean directPrint)
Sets whether "direct print" mode is enabled (see documentation).

A value of "true" means that the JTextComponent will be printed directly from the original user JTextComponent. Cloning will not be used, regardless of the value set by the setCloningUsed method. WYSIWYG will be assumed, regardless of the value set by the setWYSIWYG method, and the JTextComponent will not be reflowed. JTextComponent must already be "realized", e.g., added to a frame followed by a call to either frame.setVisible(true) or frame.pack(). The JTextComponent will only be paginated, with the current layout and line breaks unchanged. Printing will be scaled down as necessary to fit the available page width (this requires JDK 1.4.2_02 or later). Direct print is not thread safe so JTextComponent must be left untouched until printing completes!

The main benefit of using direct print is that text entries in the fields of an HTML form will be printed, as well as any embedded components (even if they are not cloneable) without the need to remove them from the current display.

The direct print technique only works under JDK 1.3.1, 1.4.1, and 1.4.2 or later. It does not work at all prior to JDK 1.3.1. There is also a Java bug (Bug Parade 4708924) that causes this technique to throw an "IllegalStateException: constrain(xywh) is not supported for complex transform" under JDK 1.4. Due to the same bug, prior to JDK 1.4.2_02 you can only perform a print preview with 100% scale and cannot have a JTextComponent wider than getBodyWidth() which would cause the JTextComponent to be scaled down.

Parameters:
directPrint - boolean representing whether to print the JTextComponent directly from the original. Default: false

isDirectPrint

public boolean isDirectPrint()
Returns current value of Direct Print mode.


setCloningUsed

public void setCloningUsed(boolean cloningUsed)
Specify whether cloning (copying by Java serialization) is to be used when printing with J2TextPrinter.

J2TextPrinter needs to be able to reflow the contents of your JTextComponent without affecting its appearance on the screen. To accomplish this, J2TextPrinter prints your JTextComponent's contents from its own internal JTextComponent rather than from your JTextComponent (unless you use setDirectPrint(true), see documentation).

If cloningUsed is true, the internal JTextComponent Document (or StyledDocument in the case of a JTextPane) is set to a clone (serialized copy) of the Document of your JTextComponent. This allows printing to proceed without ever accessing your JTextComponent again. Cloning is the safest approach, particular if printing from a separate thread, since it assures thread-safety. The maindrawback is that it is possible to create JTextComponent instances that can't be copied using Java serialization, particularly when using earlier JDK releases which still had some number of serialization bugs. But in such cases, you often can still print if you set setCloningUsed(false).

If cloningUsed is false, the internal JTextComponent Document is set to point directly to your JTextComponent's Document. This results in a "shared model" approach, i.e., one copy of the model (Document) is used by both views (the internal imaging JTextComponent and your JTextComponent). For this reason, since there is no thread-safety, you need to leave your JTextComponent alone until printing completes when using setCloningUsed(false).

It has been determined that cloning is generally necessary if you are printing a JTextPane for which you have inserted a Component using insertComponent(). This is particularly true if it appears on the screen or if you are printing from a separate thread (setSeparatePrintThread(true), which is the default). This is because Java doesn't support having the same Component in multiple simultaneous views (Containers).

Cloning should be safe in all other cases as well, so the default for cloningUsed is true. This method allows cloning to be disabled if it causes any problems for a particular JTextCompoent and since it is slower.

In particular, serialization is broken in the JDK 1.4 beta2 release (see Bug Parade #4492468), so the cloningUsed default is set to false for that release. It has also been determined that certain HTML tags such as the border subtag of table are lost during serialization, so cloningUsed needs to be set to false for HTML documents that contain tables with borders, otherwise the borders will be missing. Also, prior to JDK 1.4.2, Java serialization failed for JTextComponents that contained non-ASCII (e.g. Unicode) characters.

Parameters:
cloningUsed - specifies whether cloning is used for J2TextPrinter printing. (Default: true except under JDK 1.4 beta2)

isCloningUsed

public boolean isCloningUsed()
Returns whether cloning is used for J2TextPrinter printing (see explanation under setCloningUsed).


addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener l)
Add a PropertyChangeListener for this component

Overrides:
addPropertyChangeListener in class J2Pageable

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener l)
Remove a PropertyChangeListener for this component

Overrides:
removePropertyChangeListener in class J2Pageable