com.wildcrest.j2printerworks
Class J2ComponentPrinter

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

public class J2ComponentPrinter
extends J2Pageable

A Java 2 component for printing the contents of any Java Component.
Prints the contents of any Java Component as a Pageable or a Flowable. J2ComponentPrinter can print and paginate any individual Swing JComponent, AWT Component, and most third-party Components, or any subclass thereof. J2ComponentPrinter can also print any Java Container such as a JPanel containing any number of Components using a user-specified layout. J2ComponentPrinter can also print any Java Image.

J2ComponentPrinter can be used either for Components that are expected to fit on a page or paginated using several possible pagination rules: shrink-to-fit scaling, tiling over multiple pages (breaking on pixel boundaries), breaking on contained Component boundaries, or breaking on color boundaries, such as white space, with separate pagination rules specified horizontally and vertically.

J2ComponentPrinter is designed to be used either for one or more Components that are small enough to fit on a single page, or which are appropriate for shrink-to-fit within a printed page (either width and/or height), or for objects such as Images or drawings that are appropriate to break (tile) on pixel boundaries, or as a container of Components that should be paginated without slicing through the Components, or for large Components (including those of third-parties) which can reasonably be paginated by breaking on boundaries of a given color such as "white space".

Using its break-on-color mode, J2ComponentPrinter provides an alternative pagination method useful for printing JTextPane, JTable, JTree, and JList components, though J2TextPrinter, J2TablePrinter, J2TreePrinter, and J2ListPrinter, respectively, are expressly designed for printing these components, are generally faster, and support particular features specific to printing each type of Swing component.

In addition to the standard J2Pageable features (headers, footers, margins, orientation, scaling), this component also supports horizontal and vertical centering, optional outside line drawing, and optional white background.

(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
static int BREAK_ON_COLOR
          Used in setHorizontalPageRule and setVerticalPageRule to indicate break-on-color mode
static int BREAK_ON_COMPONENTS
          Used in setHorizontalPageRule and setVerticalPageRule to indicate break-on-component-boundaries mode
static int SHRINK_TO_FIT
          Used in setHorizontalPageRule and setVerticalPageRule to indicate shrink-to-fit mode
static int TILE
          Used in setHorizontalPageRule and setVerticalPageRule to indicate tile mode
 
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
J2ComponentPrinter()
          Construct a J2ComponentPrinter object (no Component specified).
J2ComponentPrinter(java.awt.Component component)
          Construct a J2ComponentPrinter object specifying a Component (or any Component subclass, including Container, JComponent, JPanel, or subclasses thereof) to be printed.
J2ComponentPrinter(java.awt.Image image)
          Construct a J2ComponentPrinter object for printing an Image.
 
Method Summary
 void addPropertyChangeListener(java.beans.PropertyChangeListener l)
          Add a PropertyChangeListener for this component
 void dispose()
          Release all heap objects created by this J2ComponentPrinter object, must 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 getBreakOnColorIncrement()
          Returns the evaluation increment in pixels for BREAK_ON_COLOR mode.
 java.awt.Component getComponent()
          Returns the Component specified for printing.
 int getHorizontalAlignment()
          Returns horizontal alignment (LEFT, CENTER, RIGHT) for printing the Component, JPanel, or Image on the page.
 java.awt.Color getHorizontalBreakColor()
          Returns the Color being used as the break color for BREAK_ON_COLOR pagination mode when breaking horizontally.
 int getHorizontalPageRule()
          Returns current value of pageRule property (SHRINK_TO_FIT, TILE, BREAK_ON_COMPONENTS, or BREAK_ON_COLOR).
 double getMaximumPaginationGap()
          Returns largest acceptable pagination gap as a percentage of the full body size.
 java.awt.Color getOutsideLineColor()
          Returns outside line Color.
static java.awt.Dimension getPreferredSizeForWidth(int width, javax.swing.JComponent component)
          Convenience method to determine the preferredSize of a Swing JComponent that is exactly tall enough for all its own content (or its contained Components if it is a Container) given a specified width (which may or may not be wide enough for all content and/or contained Components).
 int getVerticalAlignment()
          Returns vertical alignment (TOP, CENTER, BOTTOM) for printing the Component, JPanel, or Image on the page.
 java.awt.Color getVerticalBreakColor()
          Returns the Color being used as the break color for BREAK_ON_COLOR pagination mode when breaking vertically.
 int getVerticalPageRule()
          Returns current value of pageRule property (SHRINK_TO_FIT, TILE, BREAK_ON_COMPONENTS, or BREAK_ON_COLOR).
 boolean isAutomaticRecalculation()
          Returns whether BREAK_ON_COLOR internal data tables recompute automatically every time you print or print preview this Component.
 boolean isOutsideLines()
          Returns whether to print outside border lines around Component, JPanel, or Image.
 boolean isOverlap()
          Returns whether to repeat the last pixel row (column) again on the next page when paginating.
 boolean isWhiteBackground()
          Returns whether Component, JPanel, or Image will be printed with a white background.
 javax.swing.JPanel makePagePanel(int which)
          Convenience factory method to create a JPanel whose size is the same size as the body of a printable page based on this J2ComponentPrinter's "local" settings (or J2Printer "global" settings if not specified).
 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 setAutomaticRecalculation(boolean automaticRecalculation)
          Sets whether the BREAK_ON_COLOR internal data tables recompute automatically every time you print or print preview this Component.
 void setBreakOnColorIncrement(int breakOnColorIncrement)
          Sets the evaluation increment in pixels for BREAK_ON_COLOR mode.
 void setComponent(java.awt.Component component)
          Specifies Component to be printed.
 void setHorizontalAlignment(int horizontalAlignment)
          Sets the horizontal alignment (LEFT, CENTER, RIGHT) for printing the Component, Container, or Image on the page.
 void setHorizontalBreakColor(java.awt.Color horizontalBreakColor)
          Sets the break color to be used for BREAK_ON_COLOR pagination mode when breaking horizontally.
 void setHorizontalPageRule(int horizontalPageRule)
          Sets the page rule for paginating each Component, Container, or Image horizontally, either SHRINK_TO_FIT, TILE, BREAK_ON_COMPONENTS, or BREAK_ON_COLOR.
 void setImage(java.awt.Image image)
          Convenience method for specifying Image to be printed.
 void setMaximumPaginationGap(double maximumPaginationGap)
          Sets the largest acceptable pagination gap as a percentage of the full page body size.
 void setOutsideLineColor(java.awt.Color outsideLineColor)
          Sets Color of outside border lines.
 void setOutsideLines(boolean showOutsideLines)
          Sets whether to print outside border lines around Component, Container, or Image.
 void setOverlap(boolean overlapEnabled)
          Sets whether to repeat the last pixel row (column) again on the next page when paginating.
 void setPanel(javax.swing.JPanel panel)
          Convenience method for specifying a JPanel to be printed.
static void setSizeForWidth(int width, javax.swing.JComponent component)
          Convenience method set the size (and preferredSize) of a Swing JComponent that is exactly tall enough for all its own content (or its contained Components if it is a Container) given a specified width (which may or may not be wide enough for all content and/or contained Components).
static void setSizeToFit(java.awt.Container container, boolean enlargeOnly)
          Convenience method to set size and preferred size of a Container to show all its contained Components.
 void setVerticalAlignment(int verticalAlignment)
          Sets the vertical alignment (TOP, CENTER, BOTTOM) for printing the Component, Container, or Image on the page.
 void setVerticalBreakColor(java.awt.Color verticalBreakColor)
          Sets the break color to be used for BREAK_ON_COLOR pagination mode when breaking vertically.
 void setVerticalPageRule(int verticalPageRule)
          Sets the page rule for paginating each Component, Container, or Image vertically, either SHRINK_TO_FIT, TILE, BREAK_ON_COMPONENTS, or BREAK_ON_COLOR.
 void setWhiteBackground(boolean whiteBackground)
          Sets whether to print Component, Container, or Image with a white background.
 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
 

Field Detail

SHRINK_TO_FIT

public static final int SHRINK_TO_FIT
Used in setHorizontalPageRule and setVerticalPageRule to indicate shrink-to-fit mode

See Also:
Constant Field Values

TILE

public static final int TILE
Used in setHorizontalPageRule and setVerticalPageRule to indicate tile mode

See Also:
Constant Field Values

BREAK_ON_COMPONENTS

public static final int BREAK_ON_COMPONENTS
Used in setHorizontalPageRule and setVerticalPageRule to indicate break-on-component-boundaries mode

See Also:
Constant Field Values

BREAK_ON_COLOR

public static final int BREAK_ON_COLOR
Used in setHorizontalPageRule and setVerticalPageRule to indicate break-on-color mode

See Also:
Constant Field Values
Constructor Detail

J2ComponentPrinter

public J2ComponentPrinter()
Construct a J2ComponentPrinter object (no Component specified).


J2ComponentPrinter

public J2ComponentPrinter(java.awt.Component component)
Construct a J2ComponentPrinter object specifying a Component (or any Component subclass, including Container, JComponent, JPanel, or subclasses thereof) to be printed.


J2ComponentPrinter

public J2ComponentPrinter(java.awt.Image image)
Construct a J2ComponentPrinter object for printing an Image.

Method Detail

dispose

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

Overrides:
dispose in class J2Pageable

getPreferredSizeForWidth

public static java.awt.Dimension getPreferredSizeForWidth(int width,
                                                          javax.swing.JComponent component)
Convenience method to determine the preferredSize of a Swing JComponent that is exactly tall enough for all its own content (or its contained Components if it is a Container) given a specified width (which may or may not be wide enough for all content and/or contained Components). Does not change the size or preferred size of the JComponent, leaving this up to you (or you can use setSizeForWidth()).

Parameters:
component - JComponent whose preferredSize for a given width is to be determined
width - specified width in pixels (may or may not be wide enough for all content and/or contained Components)

setSizeForWidth

public static void setSizeForWidth(int width,
                                   javax.swing.JComponent component)
Convenience method set the size (and preferredSize) of a Swing JComponent that is exactly tall enough for all its own content (or its contained Components if it is a Container) given a specified width (which may or may not be wide enough for all content and/or contained Components).

Parameters:
component - JComponent whose size (and preferredSize) for a given width is to be set
width - specified width in pixels (may or may not be wide enough for all content and/or contained Components)

setSizeToFit

public static void setSizeToFit(java.awt.Container container,
                                boolean enlargeOnly)
Convenience method to set size and preferred size of a Container to show all its contained Components. Does not relayout the contents of the Container.

Parameters:
container - Container whose size is to be changed
enlargeOnly - if true, will only enlarge; if false, will enlarge or reduce to achieve exact fit

makePagePanel

public javax.swing.JPanel makePagePanel(int which)
Convenience factory method to create a JPanel whose size is the same size as the body of a printable page based on this J2ComponentPrinter's "local" settings (or J2Printer "global" settings if not specified).

Parameters:
which - J2Pageable.FIRST (1) if page 1, or J2Pageable.REST (0) if pages 2...n.

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.


setComponent

public void setComponent(java.awt.Component component)
Specifies Component to be printed. Component may be an individual AWT Component (e.g. TextArea) or Swing JComponent (e.g., JLabel, JList, JTextArea) or a Java Container (Panel, JPanel, or content pane of a JFrame or JDialog), which may include a user-specified layout of other Components. Component should either fit within a printed page, or be appropriate for shrink-to-fit within a printed page (or page width), or be appropriate for tiling across multiple pages with simple pixel boundary pagination (e.g, an Image in a JPanel), or be a container of Components that should be paginated without slicing through the Components, or be appropriate for braek-on-color pagination.

In break-on-colors mode, J2ComponentPrinter can be used as an alternative method for paginating multi-page JTable, JTextPane, JTree, or JList components. However, generally you should use J2TablePrinter for JTable pagination on table row/column boundaries, J2TextPrinter for JTextPane pagination on text line boundaries, J2TreePrinter for JTree pagination on tree node boundaries, and J2ListPrinter for JList pagination on list item boundaries, since these support unique features specific to each type of component and are generally faster.

Parameters:
component - the Component to be printed

getComponent

public java.awt.Component getComponent()
Returns the Component specified for printing.


setPanel

public void setPanel(javax.swing.JPanel panel)
Convenience method for specifying a JPanel to be printed. JPanel may contain one or more Components using a user-specified LayoutManager.

Parameters:
panel - the JPanel to be printed

setImage

public void setImage(java.awt.Image image)
Convenience method for specifying Image to be printed. Image will be placed in an ImagePanel of the appropriate size.

Parameters:
image - the Image to be printed

setHorizontalAlignment

public void setHorizontalAlignment(int horizontalAlignment)
Sets the horizontal alignment (LEFT, CENTER, RIGHT) for printing the Component, Container, or Image on the page.

Parameters:
horizontalAlignment - possible values are J2PanelPrinter.LEFT, .CENTER, or .RIGHT (default: CENTER)

getHorizontalAlignment

public int getHorizontalAlignment()
Returns horizontal alignment (LEFT, CENTER, RIGHT) for printing the Component, JPanel, or Image on the page.


setVerticalAlignment

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

Parameters:
verticalAlignment - possible values are J2PanelPrinter.TOP, .CENTER, or .BOTTOM (default: TOP)

getVerticalAlignment

public int getVerticalAlignment()
Returns vertical alignment (TOP, CENTER, BOTTOM) for printing the Component, JPanel, or Image on the page.


setHorizontalPageRule

public void setHorizontalPageRule(int horizontalPageRule)
Sets the page rule for paginating each Component, Container, or Image horizontally, either SHRINK_TO_FIT, TILE, BREAK_ON_COMPONENTS, or BREAK_ON_COLOR.

Parameters:
horizontalPageRule - desired horizontal page rule, recognized values are: J2ComponentPrinter.SHRINK_TO_FIT (default), .TILE, .BREAK_ON_COMPONENTS, or .BREAK_ON_COLOR.

SHRINK_TO_FIT means shrink Component, Container, or Image to fit within the width of the current page.

TILE means print Component, Container, or Image across multiple horizontal pages without scaling by breaking the Component, Component, or Image as necessary on pixel boundaries.

BREAK_ON_COMPONENTS means if Component is a Container, then examine its contained Components and find the rightmost vertical boundaries where page break(s) can be inserted without slicing through any Components. Only examines the first level of contained Components, so the contents of any nested Containers (JPanel, JTextPane, etc.) will be kept together on the same page (unless larger than a page).

BREAK_ON_COLOR means analyze the Component, Container, or Image and determine the rightmost boundary that fits the width of the page and whose pixel color values most closely match the specified horizontal break color. For example, break on Color.white can be used for paginating certain third-party Components. Or, break on table.getGridColor() can be used for printing tables such as JTable.

For all pagination modes, MaximumPaginationGap determines when to start on a new page.

getHorizontalPageRule

public int getHorizontalPageRule()
Returns current value of pageRule property (SHRINK_TO_FIT, TILE, BREAK_ON_COMPONENTS, or BREAK_ON_COLOR).


setVerticalPageRule

public void setVerticalPageRule(int verticalPageRule)
Sets the page rule for paginating each Component, Container, or Image vertically, either SHRINK_TO_FIT, TILE, BREAK_ON_COMPONENTS, or BREAK_ON_COLOR.

Parameters:
verticalPageRule - desired vertical page rule, recognized values are: J2ComponentPrinter.SHRINK_TO_FIT, .TILE, .BREAK_ON_COMPONENTS, or .BREAK_ON_COLOR (default).

SHRINK_TO_FIT means shrink Component, Container, or Image to fit within the remaining height left on the current page.

TILE means print Component, Container, or Image across multiple vertical pages without scaling by breaking the Component, Container, or Image as necessary on pixel boundaries.

BREAK_ON_COMPONENTS means if Component is a Container, then examine its contained Components and find the bottommost horizontal boundaries where page break(s) can be inserted without slicing through any Components. Only examines the first level of contained Components, so the contents of any nested Containers will be kept together on the same page (unless larger than a page).

BREAK_ON_COLOR means analyze the Component, Container, or Image and determine the bottomost boundary that fits the width of the page and whose pixel color values most closely match the specified vertical break color. For example, break on Color.white can be used for paginating JTextPane, JTree, JList, and many third-party Components. Or, break on table.getGridColor() can be used for printing tables such as JTable.

For all pagination modes, MaximumPaginationGap determines when to start on a new page.

getVerticalPageRule

public int getVerticalPageRule()
Returns current value of pageRule property (SHRINK_TO_FIT, TILE, BREAK_ON_COMPONENTS, or BREAK_ON_COLOR).


setWhiteBackground

public void setWhiteBackground(boolean whiteBackground)
Sets whether to print Component, Container, or Image with a white background.

Parameters:
whiteBackground - true means set background of Component, JPanel, or Image to white for printing, false means use existing Component, Container, or Image background (default: true)

isWhiteBackground

public boolean isWhiteBackground()
Returns whether Component, JPanel, or Image will be printed with a white background.


setOverlap

public void setOverlap(boolean overlapEnabled)
Sets whether to repeat the last pixel row (column) again on the next page when paginating.

Parameters:
overlapEnabled - true means print last pixel row (column) again on the next page when paginating (default: false)

isOverlap

public boolean isOverlap()
Returns whether to repeat the last pixel row (column) again on the next page when paginating.


setOutsideLines

public void setOutsideLines(boolean showOutsideLines)
Sets whether to print outside border lines around Component, Container, or Image.

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 Component, JPanel, or Image.


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.


setHorizontalBreakColor

public void setHorizontalBreakColor(java.awt.Color horizontalBreakColor)
Sets the break color to be used for BREAK_ON_COLOR pagination mode when breaking horizontally.


getHorizontalBreakColor

public java.awt.Color getHorizontalBreakColor()
Returns the Color being used as the break color for BREAK_ON_COLOR pagination mode when breaking horizontally.


setVerticalBreakColor

public void setVerticalBreakColor(java.awt.Color verticalBreakColor)
Sets the break color to be used for BREAK_ON_COLOR pagination mode when breaking vertically.


getVerticalBreakColor

public java.awt.Color getVerticalBreakColor()
Returns the Color being used as the break color for BREAK_ON_COLOR pagination mode when breaking vertically.


setMaximumPaginationGap

public void setMaximumPaginationGap(double maximumPaginationGap)
Sets the largest acceptable pagination gap as a percentage of the full page body size. When the entire panel or a Component it contains won't fit in the remaining space on a page, then skip to the ext page if the remaining space is less than the maximumPaginationGap value, otherwise split the content over the page boundary. Honored by all pagination rules.

Parameters:
maximumPaginationGap - The largest acceptable pagination gap as a percentage of the full body size. 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 content over page boundaries, never waste a pixel, whereas a value of (almost) 1.0 means OK to skip (almost) all of a page to keep content together on the page (default: 0.2).

getMaximumPaginationGap

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


setAutomaticRecalculation

public void setAutomaticRecalculation(boolean automaticRecalculation)
Sets whether the BREAK_ON_COLOR internal data tables recompute automatically every time you print or print preview this Component. These calcuations can be slow for large multi-page Components. By default (true), J2ComponentPrinter recalculates these tables automatically every time you display or print the Component to take into account any properties of the Component or its underlying data that might have changed since setComponent was called. By setting this value to false, this calculation will be performed only once when setComponent is called. IMPORTANT: if set to false, it becomes your obligation to call setComponent every time your Component or its underlying data changes.

Parameters:
automaticRecalculation - true means recalculate automatically every time you display or print this Component, false means recalculate only once when setComponent is called (default: true)

isAutomaticRecalculation

public boolean isAutomaticRecalculation()
Returns whether BREAK_ON_COLOR internal data tables recompute automatically every time you print or print preview this Component.


setBreakOnColorIncrement

public void setBreakOnColorIncrement(int breakOnColorIncrement)
Sets the evaluation increment in pixels for BREAK_ON_COLOR mode. By default, the BREAK_ON_COLOR image analysis evaluates color values at every pixel, which ensures accurate break-on-color pagination but can be slow for large multi-page Components. Increasing this value to, for example, 10 (meaning evaluate only 1 out of every 10 pixels) will result in much faster processing and will still generally produce accurate results, though raising it too high increases the risk of inaccurate pagination depending upon the contents of the Component.

Parameters:
breakOnColorIncrement - causes BREAK_ON_COLOR to sample one in every breakOnColorIncrement pixels (default: 1)

getBreakOnColorIncrement

public int getBreakOnColorIncrement()
Returns the evaluation increment in pixels for BREAK_ON_COLOR mode.


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