Side of Software
Print Preview Library 1.8.1

sos.preview
Class JPrintPreviewPane

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--sos.preview.JPrintPreviewPane
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, javax.swing.Scrollable, java.io.Serializable

public class JPrintPreviewPane
extends javax.swing.JComponent
implements javax.accessibility.Accessible, javax.swing.Scrollable

A component that displays printable pages.

The print preview pane is intended to show the user what his or her document looks like in a paged format ready to be sent to the printer. It does not allow any editing of the pages.

From the print preview pane, the user can:

  • Print the pages
  • Change the default page format, which includes the page layout, page size, and margins
  • Change the arrangement of pages on the screen
  • Zoom in and out on the pages
  • Select pages
  • JPrintPreviewPane automatically installs its own component descendants based on the pageable property. Clients need not invoke methods like add, remove, and removeAll. The installed page components may not necessarily be the direct children of this print preview pane. Therefore, clients should not invoke methods like getComponent and findComponentAt to retrieve page components. Instead, they should use the methods getPageComponent and getPageIndexAt. This class uses JPrintPreviewPage components to render its pages. Subclasses, however, may change this behavior by overriding createPageComponent. Consequently, clients should not rely on specific types of the objects returned by getPageComponent.

    The print preview pane's scrolling behavior typically depends on its layout. Therefore, if its layout implements ScrollableLayoutManager, it delegates all javax.swing.Scrollable methods to its layout; otherwise, it returns default values.

    Clients may respond to changes to a JPrintPreviewPane by registering a property change listener and listening for any of the following properties:

    LAYOUT_PROPERTYThe page layout manager has changed.
    MARGINS_ARE_SHOWN_PROPERTYPage margins are now displayed or are no longer displayed.
    MODE_PROPERTYThe mode has changed.
    PAGEABLE_PROPERTYThe pages to preview have changed.
    PAGE_NUMBER_RENDERER_PROPERTYThe page number renderer has changed.
    PAGE_NUMBERS_ARE_SHOWN_PROPERTYPage numbers are now displayed or are no longer displayed.
    PAGE_SELECTION_ALLOWED_PROPERTYPage selection is now allowed or is no longer allowed.
    SCALE_PROPERTYThe amount the pages are scaled has changed.
    SELECTION_BACKGROUND_PROPERTYThe selection background color has changed.
    SELECTION_FOREGROUND_PROPERTYThe selection foreground color has changed.
    SELECTION_MODEL_PROPERTYThe page selection model has changed.
    ZOOM_FUNCTION_PROPERTYThe zoom function has changed.

    Appearance

    The following methods deal with a print preview pane's appearance:

     Color getSelectionBackground()
     void setSelectionBackground(Color selectionBackground)
     Color getSelectionForeground()
     void setSelectionForeground(Color selectionForeground)
     void setPageNumberRenderer(PageNumberRenderer renderer)
     void setPageNumbersAreShown(boolean pageNumbersAreShown)
     boolean getPageNumbersAreShown()
     PageNumberRenderer getPageNumberRenderer()
     boolean getMarginsAreShown()
     void setMarginsAreShown(boolean marginsAreShown)
     

    Page Layout and Zooming

    The following methods deal with a print preview pane's page layout and the size of the pages:

     double getScale()
     void setLayout(LayoutManager layout)
     boolean zoom(double scale)
     boolean zoom(double scale,Point point)
     boolean zoomIn()
     void zoomIn(int pageIndex)
     boolean zoomIn(Point point)
     boolean zoomOut()
     void zoomOut(int pageIndex)
     boolean zoomOut(Point point)
     void centerPage(int pageIndex)
     void ensurePageIsVisible(int pageIndex)
     ZoomFunction getZoomFunction()
     void setZoomFunction(ZoomFunction zoomFunction)
     

    Page Selection

    The following methods deal with the selection of pages:

     boolean isPageSelected(int pageIndex)
     boolean getPageSelectionAllowed()
     ListSelectionModel getPageSelectionModel()
     void setPageSelectionModel(ListSelectionModel selectionModel)
     int getSelectedPageIndex()
     void setPageSelectionAllowed()
     

    Printing

    For convenience, there are three methods involving printing and page setup:

     PageFormat pageSetup(int pageIndex)
     boolean print()
     void printAll()
     

    For more information on how to use and customize a JPrintPreviewPane, see Side of Software's online tutorial.

    Since:
    1.0
    See Also:
    ScrollableLayoutManager, JPrintPreviewPage

    Nested Class Summary
    protected  class JPrintPreviewPane.AccessibleJPrintPreviewPane
              A class that implements accessibility support for a JPrintPreviewPane.
     
    Field Summary
    static java.lang.String LAYOUT_PROPERTY
              Constant used by property change events to signal that the a JPrintPreviewPane's layout manager has changed.
    static java.lang.String MARGINS_ARE_SHOWN_PROPERTY
              Constant used by property change events to signal that the a JPrintPreviewPane has changed whether or not it draws margins.
    static java.lang.String MODE_PROPERTY
              Constant used by property change events to signal that a JPrintPreviewPane's mode has changed.
    static java.lang.String PAGE_NUMBER_RENDERER_PROPERTY
              Constant used by property change events to signal that a JPrintPreviewPane has changed the way it renders page numbers.
    static java.lang.String PAGE_NUMBERS_ARE_SHOWN_PROPERTY
              Constant used by property change events to signal that a JPrintPreviewPane changed whether or not it displays page numbers.
    static java.lang.String PAGE_SELECTION_ALLOWED_PROPERTY
              Constant used by property change events to signal that a JPrintPreviewPane changed whether or not it allows its pages to be selected.
    static java.lang.String PAGEABLE_PROPERTY
              Constant used by property change events to signal that a JPrintPreviewPane's underlying pages have changed.
    static java.lang.String SCALE_PROPERTY
              Constant used by property change events to signal that a JPrintPreviewPane's scale has changed.
    static java.lang.String SELECTION_BACKGROUND_PROPERTY
              Constant used by property change events to signal that a JPrintPreviewPane's selection background color has changed.
    static java.lang.String SELECTION_FOREGROUND_PROPERTY
              Constant used by property change events to signal that a JPrintPreviewPane's selection foreground color has changed.
    static int SELECTION_MODE
              Constant used for setMode that means the print preview pane is prepared to select its pages.
    static java.lang.String SELECTION_MODEL_PROPERTY
              Constant used by property change events to signal that a JPrintPreviewPane's selection model has changed.
    static java.lang.String ZOOM_FUNCTION_PROPERTY
              Constant used by property change events to signal that a JPrintPreviewPane's zoom function has changed.
    static int ZOOM_IN_MODE
              Constant used for setMode that means the print preview pane is prepared to zoom in.
    static int ZOOM_MODE
              Constant used for setMode that means the print preview pane is prepared to zoom in and out.
    static int ZOOM_OUT_MODE
              Constant used for setMode that means the print preview pane is prepared to zoom out.
     
    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.image.ImageObserver
    ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
     
    Constructor Summary
    JPrintPreviewPane()
              Creates a JPrintPreviewPane with zero pages.
    JPrintPreviewPane(java.awt.print.Pageable pageable)
              Creates a JPrintPreviewPane with the specified pages laid out one page at a time.
    JPrintPreviewPane(java.awt.print.Pageable pageable, java.awt.LayoutManager pageLayout)
              Creates a JPrintPreviewPane with the specified pages laid out by the specified layout manager.
     
    Method Summary
     void centerPage(int pageIndex)
              Centers the page given by pageIndex the best it can.
    protected  ZoomFunction createDefaultZoomFunction()
              Creates and returns a default zoom function.
    protected  java.awt.Component createPageComponent(java.awt.print.Printable page, java.awt.print.PageFormat pageFormat, int pageIndex)
              Creates and returns a graphical component for the specified page.
    protected  PageNumberRenderer createPageNumberRenderer()
              Creates and returns a default page number renderer.
    protected  javax.swing.ListSelectionModel createPageSelectionModel()
              Creates and returns a default page selection model.
     void doLayout()
              Causes this container to lay out its components.
     void ensurePageIsVisible(int pageIndex)
              Scrolls this print preview pane as necessary to ensure that a portion of the specified page is visible.
     javax.accessibility.AccessibleContext getAccessibleContext()
              Gets the AccessibleContext associated with this JPrintPreviewPane.
     boolean getMarginsAreShown()
              Returns true if this object should display page margins.
     int getMode()
              Return this print preview pane's mode--either ZOOM_MODE, ZOOM_IN_MODE, ZOOM_OUT_MODE, or SELECTION_MODE.
     java.awt.print.Pageable getPageable()
              Returns the pages displayed by this print preview pane.
     java.awt.Component getPageComponent(int pageIndex)
              Returns the component that is used to render the specified page.
     int getPageIndexAt(int x, int y)
              Returns the index of the page that lies at the specified point, or -1 if no such page exists.
     int getPageIndexAt(java.awt.Point point)
              Returns the index of the page that lies at the specified point, or -1 if no such page exists.
     PageNumberRenderer getPageNumberRenderer()
              Returns the object that knows how to render the page numbers, or null if no such object exists.
     boolean getPageNumbersAreShown()
              Returns true if this object should display page numbers.
     boolean getPageSelectionAllowed()
              Returns true if pages can be selected.
     javax.swing.ListSelectionModel getPageSelectionModel()
              Returns the way pages are selected in this print preview pane.
     java.awt.Dimension getPreferredScrollableViewportSize()
              Returns the preferred size of the viewport for a view component.
     java.awt.Dimension getPreferredSize()
              Returns this component's preferred size.
     double getScale()
              Returns the amount the pages are being scaled.
     int getScrollableBlockIncrement(java.awt.Rectangle rectangle, int orientation, int direction)
              Returns the scrollable block increment.
     boolean getScrollableTracksViewportHeight()
              Returns true if a viewport should always force this component's height to match the height of the viewport.
     boolean getScrollableTracksViewportWidth()
              Returns true if a viewport should always force this component's width to match the width of the viewport.
     int getScrollableUnitIncrement(java.awt.Rectangle rectangle, int orientation, int direction)
              Returns the scrollable unit increment.
     int getSelectedPageIndex()
              Returns the index of the first selected page, or -1 if no selection exists.
     java.awt.Color getSelectionBackground()
              Returns the selection background color.
     java.awt.Color getSelectionForeground()
              Returns the selection foreground color.
     PrintPreviewPaneUI getUI()
              Returns the look and feel delegate that renders this object.
     java.lang.String getUIClassID()
              Returns the UIDefaults key used to look up the name of the swing.plaf.ComponentUI class that defines the look and feel for this component.
     ZoomFunction getZoomFunction()
              Returns the object that controls the amount of zooming.
     boolean isPageSelected(int pageIndex)
              Returns true if the page corresponding to pageIndex is selected.
     java.awt.print.PageFormat pageSetup(int pageIndex)
              Displays the page setup dialog and returns the new page format, or null if the user cancelled the dialog.
     boolean print()
              Sends pages to the printer by way of the print dialog.
     void printAll()
              Sends all pages to the printer without showing the print dialog.
     void setLayout(java.awt.LayoutManager layout)
              Sets the layout manager for this print preview pane.
     void setMarginsAreShown(boolean marginsAreShown)
              Sets whether or not the margins are drawn on the print preview pages.
     void setMode(int mode)
              Sets the print preview mode.
     void setPageable(java.awt.print.Pageable pageable)
              Sets the pages to be displayed by this print preview pane.
     void setPageNumberRenderer(PageNumberRenderer pageNumberRenderer)
              Sets the page number renderer for this print preview pane.
     void setPageNumbersAreShown(boolean pageNumbersAreShown)
              Sets whether or not this print preview pane should render page numbers.
     void setPageSelectionAllowed(boolean pageSelectionAllowed)
              Sets whether or not pages in this print preview pane can be selected.
     void setPageSelectionModel(javax.swing.ListSelectionModel selectionModel)
              Set the page selection model.
     void setSelectionBackground(java.awt.Color selectionBackground)
              Sets the selection background color.
     void setSelectionForeground(java.awt.Color selectionForeground)
              Sets the selection foreground color.
     void setUI(PrintPreviewPaneUI newUI)
              Sets the look and feel delegate for this print preview pane.
     void setZoomFunction(ZoomFunction zoomFunction)
              Sets the zoom function, which is used to determine how much the print preview should zoom.
     void updateUI()
              Resets the UI property with the value from the current look and feel.
     boolean zoom(double scale)
              Zooms the pages within this print preview pane to the specified scale.
     boolean zoom(double scale, java.awt.Point point)
              Zooms the pages within this print preview pane to the specified scale, centering on the specified point.
     boolean zoomIn()
              Zooms in on the pages within this print preview pane.
     void zoomIn(int pageIndex)
              Zooms in on the specified page.
     boolean zoomIn(java.awt.Point point)
              Zooms in on the pages within this print preview pane, centering on the specified point.
     boolean zoomOut()
              Zooms out on the pages within this print preview pane.
     void zoomOut(int pageIndex)
              Zooms out on the specified page.
     boolean zoomOut(java.awt.Point point)
              Zooms out on the pages within this print preview pane, centering on the specified point.
     
    Methods inherited from class javax.swing.JComponent
    addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, 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
     
    Methods inherited from class java.awt.Container
    add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, 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, 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, setLocale, 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

    SELECTION_MODE

    public static final int SELECTION_MODE
    Constant used for setMode that means the print preview pane is prepared to select its pages.

    See Also:
    Constant Field Values

    ZOOM_MODE

    public static final int ZOOM_MODE
    Constant used for setMode that means the print preview pane is prepared to zoom in and out.

    See Also:
    Constant Field Values

    ZOOM_IN_MODE

    public static final int ZOOM_IN_MODE
    Constant used for setMode that means the print preview pane is prepared to zoom in.

    See Also:
    Constant Field Values

    ZOOM_OUT_MODE

    public static final int ZOOM_OUT_MODE
    Constant used for setMode that means the print preview pane is prepared to zoom out.

    See Also:
    Constant Field Values

    LAYOUT_PROPERTY

    public static final java.lang.String LAYOUT_PROPERTY
    Constant used by property change events to signal that the a JPrintPreviewPane's layout manager has changed.

    See Also:
    Constant Field Values

    MARGINS_ARE_SHOWN_PROPERTY

    public static final java.lang.String MARGINS_ARE_SHOWN_PROPERTY
    Constant used by property change events to signal that the a JPrintPreviewPane has changed whether or not it draws margins.

    See Also:
    Constant Field Values

    MODE_PROPERTY

    public static final java.lang.String MODE_PROPERTY
    Constant used by property change events to signal that a JPrintPreviewPane's mode has changed.

    See Also:
    Constant Field Values

    PAGEABLE_PROPERTY

    public static final java.lang.String PAGEABLE_PROPERTY
    Constant used by property change events to signal that a JPrintPreviewPane's underlying pages have changed.

    See Also:
    Constant Field Values

    PAGE_NUMBER_RENDERER_PROPERTY

    public static final java.lang.String PAGE_NUMBER_RENDERER_PROPERTY
    Constant used by property change events to signal that a JPrintPreviewPane has changed the way it renders page numbers.

    See Also:
    Constant Field Values

    PAGE_NUMBERS_ARE_SHOWN_PROPERTY

    public static final java.lang.String PAGE_NUMBERS_ARE_SHOWN_PROPERTY
    Constant used by property change events to signal that a JPrintPreviewPane changed whether or not it displays page numbers.

    See Also:
    Constant Field Values

    PAGE_SELECTION_ALLOWED_PROPERTY

    public static final java.lang.String PAGE_SELECTION_ALLOWED_PROPERTY
    Constant used by property change events to signal that a JPrintPreviewPane changed whether or not it allows its pages to be selected.

    See Also:
    Constant Field Values

    SCALE_PROPERTY

    public static final java.lang.String SCALE_PROPERTY
    Constant used by property change events to signal that a JPrintPreviewPane's scale has changed.

    See Also:
    Constant Field Values

    SELECTION_BACKGROUND_PROPERTY

    public static final java.lang.String SELECTION_BACKGROUND_PROPERTY
    Constant used by property change events to signal that a JPrintPreviewPane's selection background color has changed.

    See Also:
    Constant Field Values

    SELECTION_FOREGROUND_PROPERTY

    public static final java.lang.String SELECTION_FOREGROUND_PROPERTY
    Constant used by property change events to signal that a JPrintPreviewPane's selection foreground color has changed.

    See Also:
    Constant Field Values

    SELECTION_MODEL_PROPERTY

    public static final java.lang.String SELECTION_MODEL_PROPERTY
    Constant used by property change events to signal that a JPrintPreviewPane's selection model has changed.

    See Also:
    Constant Field Values

    ZOOM_FUNCTION_PROPERTY

    public static final java.lang.String ZOOM_FUNCTION_PROPERTY
    Constant used by property change events to signal that a JPrintPreviewPane's zoom function has changed.

    See Also:
    Constant Field Values
    Constructor Detail

    JPrintPreviewPane

    public JPrintPreviewPane()
    Creates a JPrintPreviewPane with zero pages.


    JPrintPreviewPane

    public JPrintPreviewPane(java.awt.print.Pageable pageable)
                      throws java.lang.NullPointerException
    Creates a JPrintPreviewPane with the specified pages laid out one page at a time.

    Parameters:
    pageable - the pages to be viewed in the print preview pane
    Throws:
    java.lang.NullPointerException - if pageable is null

    JPrintPreviewPane

    public JPrintPreviewPane(java.awt.print.Pageable pageable,
                             java.awt.LayoutManager pageLayout)
                      throws java.lang.NullPointerException
    Creates a JPrintPreviewPane with the specified pages laid out by the specified layout manager.

    Parameters:
    pageable - the pages to be viewed in the print preview pane
    pageLayout - layout that will organize the pages in the pane
    Throws:
    java.lang.NullPointerException - if pageable is null
    Method Detail

    centerPage

    public void centerPage(int pageIndex)
                    throws java.lang.IllegalArgumentException
    Centers the page given by pageIndex the best it can.

    Parameters:
    pageIndex - page to be centered
    Throws:
    java.lang.IllegalArgumentException - if pageIndex is less than 0 or greather than the number of pages - 1

    createDefaultZoomFunction

    protected ZoomFunction createDefaultZoomFunction()
    Creates and returns a default zoom function. This is a hook method that subclasses may override if they wish to change the default zoom function.

    Returns:
    the default zoom function

    createPageComponent

    protected java.awt.Component createPageComponent(java.awt.print.Printable page,
                                                     java.awt.print.PageFormat pageFormat,
                                                     int pageIndex)
    Creates and returns a graphical component for the specified page. This is a hook method that subclasses may override if they do not wish to use JPrintPreviewPage for the page components.

    Parameters:
    page - the object that renders the contents of the page
    pageFormat - the size, layout, and margins of the page
    pageIndex - the index of the page
    Returns:
    a graphical component that will render the page in the print preview pane

    createPageNumberRenderer

    protected PageNumberRenderer createPageNumberRenderer()
    Creates and returns a default page number renderer. This is a hook method that subclasses may override in order to change the default page number renderer.

    Returns:
    the default page number renderer

    createPageSelectionModel

    protected javax.swing.ListSelectionModel createPageSelectionModel()
    Creates and returns a default page selection model. This is a hook method that subclasses may override in order to change the default selection behavior.

    Returns:
    the default page selection model

    doLayout

    public void doLayout()
    Causes this container to lay out its components.

    Overrides:
    doLayout in class java.awt.Container

    ensurePageIsVisible

    public void ensurePageIsVisible(int pageIndex)
                             throws java.lang.IllegalArgumentException
    Scrolls this print preview pane as necessary to ensure that a portion of the specified page is visible.

    Parameters:
    pageIndex - page to be made visible
    Throws:
    java.lang.IllegalArgumentException - if pageIndex is less than 0 or greather than the number of pages - 1

    getAccessibleContext

    public javax.accessibility.AccessibleContext getAccessibleContext()
    Gets the AccessibleContext associated with this JPrintPreviewPane.

    Specified by:
    getAccessibleContext in interface javax.accessibility.Accessible
    Overrides:
    getAccessibleContext in class javax.swing.JComponent
    Returns:
    the AccessibleContext associated with this JPrintPreviewPane

    getMarginsAreShown

    public boolean getMarginsAreShown()
    Returns true if this object should display page margins.

    Returns:
    true if page margins are shown
    See Also:
    setMarginsAreShown(boolean)

    getMode

    public int getMode()
    Return this print preview pane's mode--either ZOOM_MODE, ZOOM_IN_MODE, ZOOM_OUT_MODE, or SELECTION_MODE.

    Returns:
    this object's mode
    See Also:
    setMode(int)

    getPageComponent

    public java.awt.Component getPageComponent(int pageIndex)
                                        throws java.lang.IndexOutOfBoundsException
    Returns the component that is used to render the specified page.

    Parameters:
    pageIndex - the index of the page whose component is desired
    Returns:
    the component that is used to render the page corresponding to pageIndex
    Throws:
    java.lang.IndexOutOfBoundsException - if pageIndex is less than 0 or greather than the number of pages - 1

    getPageIndexAt

    public int getPageIndexAt(java.awt.Point point)
                       throws java.lang.NullPointerException
    Returns the index of the page that lies at the specified point, or -1 if no such page exists.

    Parameters:
    point - the point at which to look for a page
    Returns:
    the index of the page that lies at the specified point, or -1 if no such page exists
    Throws:
    java.lang.NullPointerException - if point is null
    See Also:
    getPageIndexAt(int,int)

    getPageIndexAt

    public int getPageIndexAt(int x,
                              int y)
    Returns the index of the page that lies at the specified point, or -1 if no such page exists.

    Parameters:
    x - offset along the x axis
    y - offset along the y axis
    Returns:
    the index of the page that lies at the specified point, or -1 if no such page exists
    See Also:
    getPageIndexAt(Point)

    getPageable

    public java.awt.print.Pageable getPageable()
    Returns the pages displayed by this print preview pane.

    Returns:
    this object's pages
    See Also:
    setPageable(java.awt.print.Pageable)

    getPageNumberRenderer

    public PageNumberRenderer getPageNumberRenderer()
    Returns the object that knows how to render the page numbers, or null if no such object exists.

    Returns:
    the print preview pane's page number renderer (may be null)
    See Also:
    setPageNumberRenderer(sos.preview.PageNumberRenderer)

    getPageNumbersAreShown

    public boolean getPageNumbersAreShown()
    Returns true if this object should display page numbers.

    Returns:
    true if page numbers are shown
    See Also:
    setPageNumbersAreShown(boolean)

    getPageSelectionAllowed

    public boolean getPageSelectionAllowed()
    Returns true if pages can be selected.

    Returns:
    true if pages can be selected
    See Also:
    setPageSelectionAllowed(boolean)

    getPageSelectionModel

    public javax.swing.ListSelectionModel getPageSelectionModel()
    Returns the way pages are selected in this print preview pane.

    Returns:
    the page selection model
    See Also:
    setPageSelectionModel(javax.swing.ListSelectionModel)

    getPreferredScrollableViewportSize

    public java.awt.Dimension getPreferredScrollableViewportSize()
    Returns the preferred size of the viewport for a view component. If the current layout manager implements ScrollableLayoutManager, the request gets forwarded to it.

    Specified by:
    getPreferredScrollableViewportSize in interface javax.swing.Scrollable
    Returns:
    the preferred size of a JViewport whose view is this Scrollable
    See Also:
    ScrollableLayoutManager.getPreferredScrollableViewportSize(java.awt.Container)

    getPreferredSize

    public java.awt.Dimension getPreferredSize()
    Returns this component's preferred size.

    Overrides:
    getPreferredSize in class javax.swing.JComponent
    Returns:
    the preferred size of this component

    getScale

    public double getScale()
    Returns the amount the pages are being scaled.

    Returns:
    the zoom factor (must be positive)
    See Also:
    setLayout(java.awt.LayoutManager)

    getScrollableBlockIncrement

    public int getScrollableBlockIncrement(java.awt.Rectangle rectangle,
                                           int orientation,
                                           int direction)
    Returns the scrollable block increment. If the current layout manager implements ScrollableLayoutManager, this request gets forwared to it.

    Specified by:
    getScrollableBlockIncrement in interface javax.swing.Scrollable
    Parameters:
    rectangle - The view area visible within the viewport
    orientation - The axis of the scrolling--either SwingConstants.VERTICAL or SwingConstants.HORIZONTAL
    direction - A negative number to indicate scrolling left or up, or a positive number to indicate scrolling right or down
    Returns:
    The amount the viewport should scroll as a result of a "block" increment. It should be positive.
    See Also:
    ScrollableLayoutManager.getScrollableBlockIncrement(java.awt.Container, java.awt.Rectangle, int, int)

    getScrollableTracksViewportHeight

    public boolean getScrollableTracksViewportHeight()
    Returns true if a viewport should always force this component's height to match the height of the viewport. If the current layout manager implements ScrollableLayoutManager, this request gets forwared to it.

    Specified by:
    getScrollableTracksViewportHeight in interface javax.swing.Scrollable
    Returns:
    true if a viewport should keep the container's height the same height of the viewport
    See Also:
    ScrollableLayoutManager.getScrollableTracksViewportHeight(java.awt.Container)

    getScrollableTracksViewportWidth

    public boolean getScrollableTracksViewportWidth()
    Returns true if a viewport should always force this component's width to match the width of the viewport. If the current layout manager implements ScrollableLayoutManager, this request gets forwared to it.

    Specified by:
    getScrollableTracksViewportWidth in interface javax.swing.Scrollable
    Returns:
    true if a viewport should keep the container's width the same width of the viewport
    See Also:
    ScrollableLayoutManager.getScrollableTracksViewportWidth(java.awt.Container)

    getScrollableUnitIncrement

    public int getScrollableUnitIncrement(java.awt.Rectangle rectangle,
                                          int orientation,
                                          int direction)
    Returns the scrollable unit increment. If the current layout manager implements ScrollableLayoutManager, this request gets forwared to it.

    Specified by:
    getScrollableUnitIncrement in interface javax.swing.Scrollable
    Parameters:
    rectangle - The view area visible within the viewport
    orientation - The axis of the scrolling--either SwingConstants.VERTICAL or SwingConstants.HORIZONTAL
    direction - A negative number to indicate scrolling left or up, or a positive number to indicate scrolling right or down
    Returns:
    The amount the viewport should scroll as a result of a "unit" increment. It should be positive.
    See Also:
    ScrollableLayoutManager.getScrollableUnitIncrement(java.awt.Container, java.awt.Rectangle, int, int)

    getSelectedPageIndex

    public int getSelectedPageIndex()
    Returns the index of the first selected page, or -1 if no selection exists.

    Returns:
    the index of the first selected page, or -1 if no selection exists.


    getSelectionBackground

    public java.awt.Color getSelectionBackground()
    Returns the selection background color. The returned color may be used by the UI when rendering a selected page.

    Returns:
    the selection background color
    See Also:
    setSelectionBackground(java.awt.Color)

    getSelectionForeground

    public java.awt.Color getSelectionForeground()
    Returns the selection foreground color. The returned color may be used by the UI when rendering a selected page.

    Returns:
    the selection foregound color
    See Also:
    setSelectionForeground(java.awt.Color)

    getUI

    public PrintPreviewPaneUI getUI()
    Returns the look and feel delegate that renders this object.

    Returns:
    the UI for this print preview pane

    getUIClassID

    public java.lang.String getUIClassID()
    Returns the UIDefaults key used to look up the name of the swing.plaf.ComponentUI class that defines the look and feel for this component.

    Overrides:
    getUIClassID in class javax.swing.JComponent
    Returns:
    the UIDefaults key for a ComponentUI subclass

    getZoomFunction

    public ZoomFunction getZoomFunction()
    Returns the object that controls the amount of zooming.

    Returns:
    the zoom function
    See Also:
    setZoomFunction(sos.preview.ZoomFunction)

    isPageSelected

    public boolean isPageSelected(int pageIndex)
    Returns true if the page corresponding to pageIndex is selected. This is equivalent to testing the page selection model (if one exists) for selection.

    Parameters:
    pageIndex - page to test for selection
    Returns:
    true if the specified page is selected

    pageSetup

    public java.awt.print.PageFormat pageSetup(int pageIndex)
                                        throws java.lang.IllegalArgumentException
    Displays the page setup dialog and returns the new page format, or null if the user cancelled the dialog.

    Parameters:
    pageIndex - the index of the page whose page format is to be shown in the dialog, or -1 if the default page format should be used
    Returns:
    the new page format, or null if the user did not accept the dialog
    Throws:
    java.lang.IllegalArgumentException - if pageIndex is not -1 or a valid page index

    print

    public boolean print()
                  throws java.awt.print.PrinterException
    Sends pages to the printer by way of the print dialog.

    Returns:
    true if something was printed
    Throws:
    java.awt.print.PrinterException - an error in the print system caused the page to be aborted
    See Also:
    printAll()

    printAll

    public void printAll()
                  throws java.awt.print.PrinterException
    Sends all pages to the printer without showing the print dialog.

    Throws:
    java.awt.print.PrinterException - an error in the print system caused the page to be aborted
    See Also:
    print()

    setLayout

    public void setLayout(java.awt.LayoutManager layout)
    Sets the layout manager for this print preview pane. The layout manager is responsible for arranging the pages within the pane.

    Overrides:
    setLayout in class java.awt.Container
    Parameters:
    layout - the desired layout manager

    setMarginsAreShown

    public void setMarginsAreShown(boolean marginsAreShown)
    Sets whether or not the margins are drawn on the print preview pages.

    Parameters:
    marginsAreShown - true if the page components should show the margins
    See Also:
    getMarginsAreShown()

    setMode

    public void setMode(int mode)
                 throws java.lang.IllegalArgumentException
    Sets the print preview mode.

    Parameters:
    mode - desired print preview mode
    Throws:
    java.lang.IllegalArgumentException - if mode is not one of SELECTION_MODE, ZOOM_MODE, ZOOM_IN_MODE, or ZOOM_OUT_MODE
    See Also:
    getMode()

    setPageable

    public void setPageable(java.awt.print.Pageable pageable)
                     throws java.lang.NullPointerException
    Sets the pages to be displayed by this print preview pane. The pageable object may contain any number of pages.

    Parameters:
    pageable - contents of the pages to be rendered (may not be null)
    Throws:
    java.lang.NullPointerException - if pageable is null
    See Also:
    getPageable()

    setPageNumberRenderer

    public void setPageNumberRenderer(PageNumberRenderer pageNumberRenderer)
    Sets the page number renderer for this print preview pane.

    Parameters:
    pageNumberRenderer - object that can draw the page numbers for each page in this print preview pane
    See Also:
    getPageNumberRenderer()

    setPageNumbersAreShown

    public void setPageNumbersAreShown(boolean pageNumbersAreShown)
    Sets whether or not this print preview pane should render page numbers.

    Parameters:
    pageNumbersAreShown - true if page numbers should be shown
    See Also:
    getPageNumbersAreShown()

    setPageSelectionAllowed

    public void setPageSelectionAllowed(boolean pageSelectionAllowed)
    Sets whether or not pages in this print preview pane can be selected.

    Parameters:
    pageSelectionAllowed - true if pages can be selected
    See Also:
    getPageSelectionAllowed()

    setPageSelectionModel

    public void setPageSelectionModel(javax.swing.ListSelectionModel selectionModel)
    Set the page selection model. The model describes how the pages of this print preview pane may be selected.

    Parameters:
    selectionModel - desired page selection behavior
    See Also:
    getPageSelectionModel()

    setSelectionBackground

    public void setSelectionBackground(java.awt.Color selectionBackground)
    Sets the selection background color. This color may be used by the UI when rendering selected pages.

    Parameters:
    selectionBackground - desired selection background color
    See Also:
    getSelectionBackground()

    setSelectionForeground

    public void setSelectionForeground(java.awt.Color selectionForeground)
    Sets the selection foreground color. This color may be used by the UI when rendering selected pages.

    Parameters:
    selectionForeground - desired selection foreground color
    See Also:
    getSelectionForeground()

    setZoomFunction

    public void setZoomFunction(ZoomFunction zoomFunction)
                         throws java.lang.NullPointerException
    Sets the zoom function, which is used to determine how much the print preview should zoom.

    Parameters:
    zoomFunction - an object that dictates how far the print preview pane should zoom in or out at each zoom step
    Throws:
    java.lang.NullPointerException - if zoomFunction is null
    See Also:
    getZoomFunction()

    setUI

    public void setUI(PrintPreviewPaneUI newUI)
    Sets the look and feel delegate for this print preview pane.

    Parameters:
    newUI - the new UI delegate

    updateUI

    public void updateUI()
    Resets the UI property with the value from the current look and feel.

    Overrides:
    updateUI in class javax.swing.JComponent

    zoom

    public boolean zoom(double scale)
                 throws java.lang.IllegalArgumentException
    Zooms the pages within this print preview pane to the specified scale. It zooms to the point on the page component that is closest to the center of the visible region. This method has no effect if there are no pages being rendered.

    Parameters:
    scale - the amount to scale the pages
    Returns:
    true if zooming occurred
    Throws:
    java.lang.IllegalArgumentException - if scale <= 0.0
    See Also:
    zoom(double,Point)

    zoom

    public boolean zoom(double scale,
                        java.awt.Point point)
                 throws java.lang.IllegalArgumentException,
                        java.lang.NullPointerException
    Zooms the pages within this print preview pane to the specified scale, centering on the specified point. This method has no effect if the specified point does not lie in a page component.

    Parameters:
    scale - the amount to scale the pages
    point - point on a page component for which to center the new view
    Returns:
    true if zooming occurred
    Throws:
    java.lang.IllegalArgumentException - if scale <= 0.0
    java.lang.NullPointerException - if point is null
    See Also:
    zoom(double)

    zoomIn

    public boolean zoomIn()
    Zooms in on the pages within this print preview pane. It zooms to the point on the page component that is closest to the center of the visible region. The current zoom function determines the amount of the zoom. This method has no effect if there are no pages being rendered.

    Returns:
    true if zooming occurred

    zoomIn

    public void zoomIn(int pageIndex)
                throws java.lang.IllegalArgumentException
    Zooms in on the specified page. The current zoom function determines the amount of the zoom.

    Parameters:
    pageIndex - index of the page to zoom in on
    Throws:
    java.lang.IllegalArgumentException - if pageIndex is less than 0 or greather than the number of pages - 1

    zoomIn

    public boolean zoomIn(java.awt.Point point)
                   throws java.lang.NullPointerException
    Zooms in on the pages within this print preview pane, centering on the specified point. This method has no effect if the specified point does not lie in a page component.

    Parameters:
    point - point on a page component to zoom in on
    Returns:
    true if zooming occurred
    Throws:
    java.lang.NullPointerException - if point is null

    zoomOut

    public boolean zoomOut()
    Zooms out on the pages within this print preview pane. It zooms to the point on the page component that is closest to the center of the visible region. The current zoom function determines the amount of the zoom. This method has no effect if there are no pages being rendered.

    Returns:
    true if zooming occurred

    zoomOut

    public void zoomOut(int pageIndex)
                 throws java.lang.IllegalArgumentException
    Zooms out on the specified page. The current zoom function determines the amount of the zoom.

    Parameters:
    pageIndex - index of the page to zoom out on
    Throws:
    java.lang.IllegalArgumentException - if pageIndex is less than 0 or greather than the number of pages - 1

    zoomOut

    public boolean zoomOut(java.awt.Point point)
                    throws java.lang.NullPointerException
    Zooms out on the pages within this print preview pane, centering on the specified point. This method has no effect if the specified point does not lie in a page component.

    Parameters:
    point - point on a page component to zoom out on
    Returns:
    true if zooming occurred
    Throws:
    java.lang.NullPointerException - if point is null

    Side of Software
    Print Preview Library 1.8.1

    Copyright 2003-07 Side of Software (SOS). All rights reserved.