Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| fop 1.0
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.fop.render.awt.viewer
Class PreviewPanel

    java.lang.Object
      java.awt.Component
          java.awt.Container
              javax.swing.JComponent
                  javax.swing.JPanel
                      org.apache.fop.render.awt.viewer.PreviewPanel

All Implemented Interfaces:
  javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class PreviewPanel
extends javax.swing.JPanel

Holds a scrollpane with the rendered page(s) and handles actions performed to alter the display of the page.

Use PreviewPanel when you want to embed a preview in your own application with your own controls. Use PreviewDialog when you want to use the standard Fop controls.

In order to embed a PreviewPanel in your own app, create your own renderer, and your own agent. In order to support reloads, you may also implement your own Renderable extension or the default InputHandler. Setting the Renderable to null works fine though. Then call setPreviewDialogDisplayed(false) to hide the default dialog. Finally create a preview panel with the agent, renderable and renderer and add it to your gui:

     FopFactory fopFactory = FopFactory.newInstance();
     AWTRenderer renderer = new AWTRenderer();
     FOUserAgent agent = fopFactory.newFOUserAgent();
     agent.setRendererOverride(renderer);
     renderer.setPreviewDialogDisplayed(false);
     renderer.setUserAgent(agent);
     renderer.setUserAgent(agent);
     previewPanel = new PreviewPanel(agent, null, renderer);
     previewPanel = new PreviewPanel(ua);
     myGui.add(previewPanel);

In order to set options and display a page do:

     renderer.clearViewportList();
     // build report xml here
     reload(); // optional if setting changed

If you wan't to change settings, don't call reload. A good example is to set the page to fill the screen and set the scrolling mode:

     double scale = previewPanel.getScaleToFitWindow();
     previewPanel.setScaleFactor(scale);
     previewPanel.setDisplayMode(PreviewPanel.CONTINUOUS);

See Also:
  Serialized Form

Nested Class Summary

Nested classes inherited from class javax.swing.JPanel
`javax.swing.JPanel.AccessibleJPanel`

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` | `CONT_FACING` Constant for displaying even/odd pages side by side in continuous form.
`static int` | `CONTINUOUS` Constant for setting continuous page display.
`protected FOUserAgent` | `foUserAgent` The FOUserAgent associated with this panel - often shared with PreviewDialog
`protected Renderable` | `renderable` Renderable instance that can be used to reload and re-render a document after modifications.
`static int` | `SINGLE` Constant for setting single page display.

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
`PreviewPanel(FOUserAgent foUserAgent, Renderable renderable, AWTRenderer renderer)` Creates a new PreviewPanel instance.

Method Summary
`void` | `addPageChangeListener(PageChangeListener l)` Add a listener to receive notification of page change events.
`protected void` | `firePageChange(int oldPage, int newPage)` Notify all registered listeners of a page change event.
`int` | `getDisplayMode()` Returns the display mode.
`int` | `getPage()`
`double` | `getScaleToFit(double viewWidth, double viewHeight)` Returns the scale factor required in order to fit either the current page or two adjacent pages within a window of the given height and width, depending on the display mode.
`double` | `getScaleToFitWidth()` As getScaleToFitWindow, but ignoring the Y axis.
`double` | `getScaleToFitWindow()` Returns the scale factor required in order to fit either the current page within the current window or to fit two adjacent pages within the display if the displaymode is continuous.
`void` | `reload()` Reloads and reformats document.
`void` | `removePageChangeListener(PageChangeListener l)` Removes a page change listener.
`void` | `setDisplayMode(int mode)` Sets the display mode.
`void` | `setPage(int number)` Selects the given page, displays it on screen and notifies listeners about the change in selection.
`void` | `setScaleFactor(double scale)` Scales page image
`void` | `showPage()` Starts rendering process and shows the current page.

Methods inherited from class javax.swing.JPanel
`getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI`

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, getPreferredSize, 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, 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, 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, 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

### SINGLE

    public static final int SINGLE

  Constant for setting single page display.

  See Also:
    Constant Field Values

### CONTINUOUS

    public static final int CONTINUOUS

  Constant for setting continuous page display.

  See Also:
    Constant Field Values

### CONT_FACING

    public static final int CONT_FACING

  Constant for displaying even/odd pages side by side in continuous form.

  See Also:
    Constant Field Values

### foUserAgent

    protected FOUserAgent foUserAgent

  The FOUserAgent associated with this panel - often shared with PreviewDialog

### renderable

    protected Renderable renderable

  Renderable instance that can be used to reload and re-render a document after modifications.

Constructor Detail

### PreviewPanel

    public PreviewPanel(FOUserAgent foUserAgent,
                        Renderable renderable,
                        AWTRenderer renderer)

  Creates a new PreviewPanel instance.

Parameters:
  `foUserAgent` - the user agent
  `renderable` - the Renderable instance that is used to reload/re-render a document after modifications.
  `renderer` - the AWT Renderer instance to paint with

Method Detail

### getPage

    public int getPage()

  Returns:
    the currently visible page

### setPage

    public void setPage(int number)

  Selects the given page, displays it on screen and notifies listeners about the change in selection.

  Parameters:
    `number` - the page number

### setDisplayMode

    public void setDisplayMode(int mode)

  Sets the display mode.

  Parameters:
    `mode` - One of SINGLE, CONTINUOUS or CONT_FACING.

### getDisplayMode

    public int getDisplayMode()

  Returns the display mode.

  Returns:
    mode One of SINGLE, CONTINUOUS or CONT_FACING.

### reload

    public void reload()

  Reloads and reformats document.

### addPageChangeListener

    public void addPageChangeListener(PageChangeListener l)

  Add a listener to receive notification of page change events. Events will be fired whenever the currentPage value is changed. The values recorded are 0-based.

  Parameters:
    `l` - the page change listener to add

### removePageChangeListener

    public void removePageChangeListener(PageChangeListener l)

  Removes a page change listener.

  Parameters:
    `l` - the page change listener to remove

### firePageChange

    protected void firePageChange(int oldPage,
                                  int newPage)

  Notify all registered listeners of a page change event.

  Parameters:
    `oldPage` - the old page
    `newPage` - the new page

### setScaleFactor

    public void setScaleFactor(double scale)

  Scales page image

  Parameters:
    `scale` - [0;1]

### getScaleToFitWindow

    public double getScaleToFitWindow()
                               throws FOPException

  Returns the scale factor required in order to fit either the current page within the current window or to fit two adjacent pages within the display if the displaymode is continuous.

  Returns:
    the requested scale factor
  Throws:
    `FOPException` - in case of an error while fetching the PageViewport

### getScaleToFitWidth

    public double getScaleToFitWidth()
                              throws FOPException

  As getScaleToFitWindow, but ignoring the Y axis.

  Returns:
    the requested scale factor
  Throws:
    `FOPException` - in case of an error while fetching the PageViewport

### getScaleToFit

    public double getScaleToFit(double viewWidth,
                                double viewHeight)
                         throws FOPException

  Returns the scale factor required in order to fit either the current page or two adjacent pages within a window of the given height and width, depending on the display mode. In order to ignore either dimension, just specify it as Double.MAX_VALUE.

  Parameters:
    `viewWidth` - width of the view
    `viewHeight` - height of the view
  Returns:
    the requested scale factor
  Throws:
    `FOPException` - in case of an error while fetching the PageViewport

### showPage

    public void showPage()

  Starts rendering process and shows the current page.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| fop 1.0
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright 1999-2010 The Apache Software Foundation. All Rights Reserved.