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(); FOUserAgent agent = fopFactory.newFOUserAgent(); AWTRenderer renderer = new AWTRenderer(agent); agent.setRendererOverride(renderer); 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 changedIf 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);
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
java.awt.Container.AccessibleAWTContainer
Modifier and Type | Field | Description |
---|---|---|
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.
|
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Constructor | Description |
---|---|
PreviewPanel(FOUserAgent foUserAgent,
Renderable renderable,
AWTRenderer renderer) |
Creates a new PreviewPanel instance.
|
Modifier and Type | Method | Description |
---|---|---|
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.
|
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, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, 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, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
public static final int SINGLE
public static final int CONTINUOUS
public static final int CONT_FACING
protected FOUserAgent foUserAgent
protected Renderable renderable
public PreviewPanel(FOUserAgent foUserAgent, Renderable renderable, AWTRenderer renderer)
foUserAgent
- the user agentrenderable
- the Renderable instance that is used to reload/re-render a document
after modifications.renderer
- the AWT Renderer instance to paint withpublic int getPage()
public void setPage(int number)
number
- the page numberpublic void setDisplayMode(int mode)
mode
- One of SINGLE, CONTINUOUS or CONT_FACING.public int getDisplayMode()
public void reload()
public void addPageChangeListener(PageChangeListener l)
l
- the page change listener to addpublic void removePageChangeListener(PageChangeListener l)
l
- the page change listener to removeprotected void firePageChange(int oldPage, int newPage)
oldPage
- the old pagenewPage
- the new pagepublic void setScaleFactor(double scale)
scale
- [0;1]public double getScaleToFitWindow() throws FOPException
FOPException
- in case of an error while fetching the PageViewportpublic double getScaleToFitWidth() throws FOPException
FOPException
- in case of an error while fetching the PageViewportpublic double getScaleToFit(double viewWidth, double viewHeight) throws FOPException
viewWidth
- width of the viewviewHeight
- height of the viewFOPException
- in case of an error while fetching the PageViewportpublic void showPage()
Copyright 1999-2016 The Apache Software Foundation. All Rights Reserved.