com.wildcrest.j2printerworks
Class J2TreePrinter

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

public class J2TreePrinter
extends J2Pageable

A Java 2 component for multi-page printing of any JTree or JTree subclass as either a Pageable or a Flowable, breaking pages on tree node (row) boundaries.

This component is appropriate for printing hierarchical lists such as file directories, outline views, geneologies, taxonomies, nested categorizations, and the like.

J2TreePrinter will shrink-to-fit so that the JTree fits within a single page width and then print as many pages vertically as necessary to print the entire (scaled) JTree.

The JTree will be printed "WYSIWYG" so that all fonts, colors, row spacing, collapsed and expanded nodes, root handles, and custom cell renderers will be preserved in the printed output.

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

(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
J2TreePrinter()
          Construct a J2TreePrinter object (no JTree specified)
J2TreePrinter(javax.swing.JTree tree)
          Construct a J2TreePrinter object for a single JTree to be printed
 
Method Summary
 void addPropertyChangeListener(java.beans.PropertyChangeListener l)
          Add a PropertyChangeListener for this component
 void dispose()
          Release all heap objects created by this J2TreePrinter 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 Component on page.
 double getMaximumPaginationGap()
          Returns largest acceptable pagination gap as a percentage of the full body size.
 java.awt.Color getOutsideLineColor()
          Returns outside line Color.
 javax.swing.JTree getTree()
          Returns the JTree to be printed.
 int getVerticalAlignment()
          Returns vertical alignment (TOP, CENTER, BOTTOM) of this JTree on page.
 boolean isOutsideLines()
          Returns whether to print outside border lines around JTree.
 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 setHorizontalAlignment(int horizontalAlignment)
          Sets the horizontal alignment (LEFT, CENTER, RIGHT) for printing the JTree on the page.
 void setMaximumPages(int pagesHigh)
          Rescale this J2TreePrinter 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 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 JTree.
 void setTree(javax.swing.JTree tree)
          Specifies JTree to be printed.
 void setVerticalAlignment(int verticalAlignment)
          Sets the vertical alignment (TOP, CENTER, BOTTOM) for printing the JTree on the page.
 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

J2TreePrinter

public J2TreePrinter()
Construct a J2TreePrinter object (no JTree specified)


J2TreePrinter

public J2TreePrinter(javax.swing.JTree tree)
Construct a J2TreePrinter object for a single JTree to be printed

Method Detail

dispose

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

Overrides:
dispose in class J2Pageable

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 J2TreePrinter 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, etc., you must call setMaximumPages again.

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

setTree

public void setTree(javax.swing.JTree tree)
Specifies JTree to be printed. JTree will paginate on JTree row boundaries. Will shrink-to-fit within a single page width, printing as many pages vertically as necessary.

Parameters:
tree - the JTree to be printed

getTree

public javax.swing.JTree getTree()
Returns the JTree to be printed.


setHorizontalAlignment

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

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

getHorizontalAlignment

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


setVerticalAlignment

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

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

getVerticalAlignment

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


setOutsideLines

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

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 JTree.


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 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 next page if the remaining space is less than the maximumPaginationGap value, otherwise split the content over the page boundary. Honored by TILE, BREAK_ON_ROWS, and SHRINK_TO_WIDTH modes, ignored by SHRINK_TO_FIT mode (which paginates if and only if this results in less shrinking).

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, never waste a pixel, a value of almost 1.0 means OK to skip almost all 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 size.


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