|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.awt.Component java.awt.Container javax.swing.JComponent com.wildcrest.j2printerworks.J2Pageable com.wildcrest.j2printerworks.J2PanelPrinter
A Java 2 component for printing the contents of any JPanel, Component, or Image as either a
Pageable or a Flowable, either shrink-to-fit within a page, shrink-to-width of a page, tiled over
multiple pages breaking on pixel boundaries, or broken on contained Component boundaries.
Prints the contents of any Java JPanel as a Pageable or a Flowable.
JPanel can contain any number of Components or JComponents arranged using a LayoutManager.
Can also print an individual Component, JComponent, Container, or Image.
If the JPanel is too big, J2PanelPrinter supports shrink-to-fit scaling, shrink-to-width scaling,
tiling multiple pages (breaking on pixel boundaries), or breaking on contained Component boundaries.
J2PanelPrinter is designed to be used
either for one or more Components that can reasonably fit on a single page, or which are appropriate
for shrink-to-fit within a printed page (or page width), 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.
Though J2PanelPrinter can print JTextPane, JTable, JTree, or JList components, typically it only
makes sense if these components are small, as J2PanelPrinter will not paginate them on
meaningful content (e.g., line, row, column, node, item) boundaries. Use J2TextPrinter,
J2TablePrinter, J2TreePrinter, or J2ListPrinter respectively to perform this kind of pagination.
Alternatively, you can use J2ComponentPrinter which can also perform paginatation
of these components by breaking on boundaries of a given color such as "white space".
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.
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_COMPONENTS
Used in setPageRule to indicate break-on-component-boundaries mode |
static int |
SHRINK_TO_FIT
Used in setPageRule to indicate shrink-to-fit mode |
static int |
SHRINK_TO_WIDTH
Used in setPageRule to indicate shrink-to-width mode |
static int |
TILE
Used in setPageRule 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 | |
J2PanelPrinter()
Construct a J2PanelPrinter object (no JPanel specified). |
|
J2PanelPrinter(java.awt.Component component)
Construct a J2PanelPrinter object specifying a Component (or any Component subclass, including Container, JComponent, JPanel, or subclasses thereof) to be printed. |
|
J2PanelPrinter(java.awt.Image image)
Construct a J2PanelPrinter object for printing an Image. |
Method Summary | |
void |
addPropertyChangeListener(java.beans.PropertyChangeListener l)
Add a PropertyChangeListener for this component |
void |
dispose()
Release all resources held by this J2PanelPrinter object, must not be called 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. |
java.awt.Component |
getComponent()
Returns the Component specified for printing. |
int |
getHorizontalAlignment()
Returns horizontal alignment (LEFT, CENTER, RIGHT) for printing the JPanel, Component, or Image on the page. |
double |
getMaximumPaginationGap()
Returns largest acceptable pagination gap as a percentage of the full body size. |
java.awt.Color |
getOutsideLineColor()
Returns outside line Color. |
int |
getPageRule()
Returns current value of pageRule property (SHRINK_TO_FIT, SHRINK_TO_WIDTH, TILE, or BREAK_ON_COMPONENTS). |
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 JPanel, Component, or Image on the page. |
boolean |
isOutsideLines()
Returns whether to print outside border lines around JPanel, Component, or Image. |
boolean |
isWhiteBackground()
Returns whether JPanel, Component, 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 J2PanelPrinter's "local" settings (or J2Printer "global" values 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 |
setComponent(java.awt.Component component)
Specifies Component to be printed. |
void |
setHorizontalAlignment(int horizontalAlignment)
Sets the horizontal alignment (LEFT, CENTER, RIGHT) for printing the JPanel, Component, or Image on the page. |
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 JPanel, Component, or Image. |
void |
setPageRule(int pageRule)
Sets the page rule for mapping each JPanel, Component, or Image into the printed page (SHRINK_TO_FIT, SHRINK_TO_WIDTH, TILE, or BREAK_ON_COMPONENTS). |
void |
setPanel(javax.swing.JPanel panel)
Convenience method for specifying 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 (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 JPanel, Component, or Image on the page. |
void |
setWhiteBackground(boolean whiteBackground)
Sets whether to print JPanel, Component, 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 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 |
public static final int SHRINK_TO_FIT
public static final int TILE
public static final int BREAK_ON_COMPONENTS
public static final int SHRINK_TO_WIDTH
Constructor Detail |
public J2PanelPrinter()
public J2PanelPrinter(java.awt.Component component)
public J2PanelPrinter(java.awt.Image image)
Method Detail |
public void dispose()
dispose
in class J2Pageable
public static java.awt.Dimension getPreferredSizeForWidth(int width, javax.swing.JComponent component)
component
- JComponent whose preferredSize for a given width is to be determinedwidth
- specified width in pixels (may or may not be wide enough for all content and/or
contained Components)public static void setSizeForWidth(int width, javax.swing.JComponent component)
component
- JComponent whose size (and preferredSize) for a given width is to be setwidth
- specified width in pixels (may or may not be wide enough for all content and/or contained Components)public static void setSizeToFit(java.awt.Container container, boolean enlargeOnly)
container
- Container whose size is to be changedenlargeOnly
- if true, will only enlarge; if false, will enlarge or reduce to achieve exact fitpublic javax.swing.JPanel makePagePanel(int which)
which
- J2Pageable.FIRST (1) if page 1, or J2Pageable.REST (0) if pages 2...n.public void printFlowable(java.awt.Graphics g, int availableWidth, int availableHeight, int nextFullPageWidth, int nextFullPageHeight)
Flowable
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.
public int usedX()
Flowable
public int usedY()
Flowable
public boolean doneX()
Flowable
public boolean doneY()
Flowable
public void resetFlowable()
Flowable
public void setComponent(java.awt.Component component)
component
- the Component to be printedpublic java.awt.Component getComponent()
public void setPanel(javax.swing.JPanel panel)
panel
- the JPanel to be printedpublic void setImage(java.awt.Image image)
image
- the Image to be printedpublic void setHorizontalAlignment(int horizontalAlignment)
horizontalAlignment
- possible values are J2PanelPrinter.LEFT, .CENTER, or .RIGHT
(default: CENTER)public int getHorizontalAlignment()
public void setVerticalAlignment(int verticalAlignment)
verticalAlignment
- possible values are J2PanelPrinter.TOP, .CENTER, or .BOTTOM
(default: TOP)public int getVerticalAlignment()
public void setPageRule(int pageRule)
pageRule
- desired page rule, recognized values are: J2PanelPrinter.SHRINK_TO_FIT
(default), .SHRINK_TO_WIDTH, .TILE, or .BREAK_ON_COMPONENTS.
public int getPageRule()
public void setWhiteBackground(boolean whiteBackground)
whiteBackground
- true means set background of JPanel, Component, or Image to white for
printing, false means use existing
JPanel, Component, or Image background (default: true)public boolean isWhiteBackground()
public void setOutsideLines(boolean showOutsideLines)
showOutsideLines
- true means print outside border lines, false if not (default: true)public boolean isOutsideLines()
public void setOutsideLineColor(java.awt.Color outsideLineColor)
outsideLineColor
- color with which to draw outside lines (default: Color.black)public java.awt.Color getOutsideLineColor()
public void setMaximumPaginationGap(double maximumPaginationGap)
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).public double getMaximumPaginationGap()
public void addPropertyChangeListener(java.beans.PropertyChangeListener l)
addPropertyChangeListener
in class J2Pageable
public void removePropertyChangeListener(java.beans.PropertyChangeListener l)
removePropertyChangeListener
in class J2Pageable
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |