diff options
Diffstat (limited to 'src/java/org/apache/fop/render')
4 files changed, 87 insertions, 8 deletions
diff --git a/src/java/org/apache/fop/render/awt/AWTRenderer.java b/src/java/org/apache/fop/render/awt/AWTRenderer.java index b790d43a1..5287bd15d 100644 --- a/src/java/org/apache/fop/render/awt/AWTRenderer.java +++ b/src/java/org/apache/fop/render/awt/AWTRenderer.java @@ -44,6 +44,7 @@ import org.apache.fop.area.PageViewport; import org.apache.fop.datatypes.ColorType; import org.apache.fop.fo.properties.ColorTypeProperty; import org.apache.fop.render.awt.viewer.PreviewDialog; +import org.apache.fop.render.awt.viewer.Renderable; import org.apache.fop.render.awt.viewer.Translator; import org.apache.fop.render.java2d.Java2DRenderer; @@ -73,6 +74,12 @@ public class AWTRenderer extends Java2DRenderer implements Pageable { protected PreviewDialog frame; /** + * Renderable instance that can be used to reload and re-render a document after + * modifications. + */ + protected Renderable renderable; + + /** * Creates a new AWTRenderer instance. */ public AWTRenderer() { @@ -88,6 +95,15 @@ public class AWTRenderer extends Java2DRenderer implements Pageable { } /** + * A Renderable instance can be set so the Preview Dialog can enable the "Reload" button + * which causes the current document to be reprocessed and redisplayed. + * @param renderable the Renderable instance. + */ + public void setRenderable(Renderable renderable) { + this.renderable = renderable; + } + + /** * Sets whether the preview dialog should be created and displayed when * the rendering is finished. * @param show If false, preview dialog is not shown. True by default @@ -135,7 +151,7 @@ public class AWTRenderer extends Java2DRenderer implements Pageable { /** Creates and initialize the AWT Viewer main window */ private PreviewDialog createPreviewDialog() { - frame = new PreviewDialog(userAgent); + frame = new PreviewDialog(userAgent, this.renderable); frame.addWindowListener(new WindowAdapter() { public void windowClosed(WindowEvent we) { System.exit(0); diff --git a/src/java/org/apache/fop/render/awt/viewer/PreviewDialog.java b/src/java/org/apache/fop/render/awt/viewer/PreviewDialog.java index 6992689bf..5c0b29faf 100644 --- a/src/java/org/apache/fop/render/awt/viewer/PreviewDialog.java +++ b/src/java/org/apache/fop/render/awt/viewer/PreviewDialog.java @@ -68,6 +68,11 @@ public class PreviewDialog extends JFrame { protected AWTRenderer renderer; /** The FOUserAgent associated with this window */ protected FOUserAgent foUserAgent; + /** + * Renderable instance that can be used to reload and re-render a document after + * modifications. + */ + protected Renderable renderable; /** The JCombobox to rescale the rendered page view */ private JComboBox scale; @@ -87,10 +92,13 @@ public class PreviewDialog extends JFrame { /** * Creates a new PreviewDialog that uses the given renderer. * @param foUserAgent the user agent + * @param renderable the Renderable instance that is used to reload/re-render a document + * after modifications. */ - public PreviewDialog(FOUserAgent foUserAgent) { + public PreviewDialog(FOUserAgent foUserAgent, Renderable renderable) { renderer = (AWTRenderer) foUserAgent.getRendererOverride(); this.foUserAgent = foUserAgent; + this.renderable = renderable; translator = renderer.getTranslator(); //Commands aka Actions @@ -156,7 +164,7 @@ public class PreviewDialog extends JFrame { setSize(screen.width * 61 / 100, screen.height * 9 / 10); //Page view stuff - previewPanel = new PreviewPanel(foUserAgent, renderer); + previewPanel = new PreviewPanel(foUserAgent, renderable, renderer); getContentPane().add(previewPanel, BorderLayout.CENTER); //Scaling combobox @@ -232,6 +240,14 @@ public class PreviewDialog extends JFrame { } /** + * Creates a new PreviewDialog that uses the given renderer. + * @param foUserAgent the user agent + */ + public PreviewDialog(FOUserAgent foUserAgent) { + this(foUserAgent, null); + } + + /** * Creates a new menubar to be shown in this window. * @return the newly created menubar */ @@ -246,7 +262,7 @@ public class PreviewDialog extends JFrame { } }); // inputHandler must be set to allow reloading - if (foUserAgent.getInputHandler() != null) { + if (renderable != null) { menu.add(new Command(translator.getString("Menu.Reload"), KeyEvent.VK_R) { public void doit() { reload(); diff --git a/src/java/org/apache/fop/render/awt/viewer/PreviewPanel.java b/src/java/org/apache/fop/render/awt/viewer/PreviewPanel.java index b568ddeb2..18436ac53 100644 --- a/src/java/org/apache/fop/render/awt/viewer/PreviewPanel.java +++ b/src/java/org/apache/fop/render/awt/viewer/PreviewPanel.java @@ -13,6 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + +/* $Id$ */ + package org.apache.fop.render.awt.viewer; import java.awt.Color; @@ -100,6 +103,11 @@ public class PreviewPanel extends JPanel { /** The FOUserAgent associated with this panel - often shared with PreviewDialog */ protected FOUserAgent foUserAgent; + /** + * Renderable instance that can be used to reload and re-render a document after + * modifications. + */ + protected Renderable renderable; /** The number of the page which is currently selected */ private int currentPage = 0; @@ -136,10 +144,13 @@ public class PreviewPanel extends JPanel { /** * Creates a new PreviewPanel instance. * @param foUserAgent the user agent + * @param renderable the Renderable instance that is used to reload/re-render a document + * after modifications. * @param renderer the AWT Renderer instance to paint with */ - public PreviewPanel(FOUserAgent foUserAgent, AWTRenderer renderer) { + public PreviewPanel(FOUserAgent foUserAgent, Renderable renderable, AWTRenderer renderer) { super(new GridLayout(1, 1)); + this.renderable = renderable; this.renderer = renderer; this.foUserAgent = foUserAgent; @@ -284,7 +295,7 @@ public class PreviewPanel extends JPanel { // do not allow the reloading while FOP is still rendering JOptionPane.showMessageDialog(previewArea, "Cannot perform the requested operation until " - + "all page are rendererd. Please wait", + + "all page are rendered. Please wait", "Please wait ", 1 /* INFORMATION_MESSAGE */); return; } @@ -325,9 +336,9 @@ public class PreviewPanel extends JPanel { } try { - if (foUserAgent.getInputHandler() != null) { + if (renderable != null) { renderer.clearViewportList(); - foUserAgent.getInputHandler().render(fop); + renderable.render(fop); } } catch (FOPException e) { e.printStackTrace(); diff --git a/src/java/org/apache/fop/render/awt/viewer/Renderable.java b/src/java/org/apache/fop/render/awt/viewer/Renderable.java new file mode 100644 index 000000000..dc25243ee --- /dev/null +++ b/src/java/org/apache/fop/render/awt/viewer/Renderable.java @@ -0,0 +1,36 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.fop.render.awt.viewer; + +import org.apache.fop.apps.FOPException; +import org.apache.fop.apps.Fop; + +/** + * The interface is used by the AWT preview dialog to reload a document. + */ +public interface Renderable { + + /** + * Renders the pre-setup document. + * @param fop the Fop instance to do the FO processing with + * @exception FOPException if the FO processing fails + */ + void render(Fop fop) throws FOPException; + +} |