org.apache.fop.render.awt.viewer

Class PreviewPanel


public class PreviewPanel
extends 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);
 

Field Summary

static int
CONTINUOUS
Constant for setting continuous page display.
static int
CONT_FACING
Constant for displaying even/odd pages side by side in continuous form.
static int
SINGLE
Constant for setting single 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.

Constructor Summary

PreviewPanel(FOUserAgent foUserAgent, Renderable renderable, AWTRenderer renderer)
Creates a new PreviewPanel instance.

Method Summary

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

Field Details

CONTINUOUS

public static final int CONTINUOUS
Constant for setting continuous page display.
Field Value:
2

CONT_FACING

public static final int CONT_FACING
Constant for displaying even/odd pages side by side in continuous form.
Field Value:
3

SINGLE

public static final int SINGLE
Constant for setting single page display.
Field Value:
1

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 Details

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 Details

getDisplayMode

public int getDisplayMode()
Returns the display mode.
Returns:
mode One of SINGLE, CONTINUOUS or CONT_FACING.

getPage

public int getPage()
Returns:
the currently visible page

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

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

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

reload

public void reload()
Reloads and reformats document.

setDisplayMode

public void setDisplayMode(int mode)
Sets the display mode.
Parameters:
mode - One of SINGLE, CONTINUOUS or CONT_FACING.

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

setScaleFactor

public void setScaleFactor(double scale)
Scales page image
Parameters:
scale - [0;1]

showPage

public void showPage()
Starts rendering process and shows the current page.

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