From 6a4856b3de3cda8bb72c7459780ed433e4153677 Mon Sep 17 00:00:00 2001 From: Glen Mazza Date: Mon, 11 Aug 2003 23:47:22 +0000 Subject: [PATCH] 1. AWT PreviewDialog creation shifted from AWTStarter to AWTRenderer. 2. New AWTRenderer constructor -- takes an InputHandler object which is used for the document refreshing/reloading. 3. PreviewDialog's reload() functionality now handled via Driver instead of AWTStarter. 4. Class AWTStarter removed: AWT generation now activated via CommandLineStarter. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@196785 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/apps/AWTStarter.java | 131 ------------------ .../apache/fop/apps/CommandLineStarter.java | 9 +- src/java/org/apache/fop/apps/Fop.java | 6 +- .../apache/fop/render/awt/AWTRenderer.java | 53 +++++-- .../org/apache/fop/viewer/PreviewDialog.java | 44 +++--- 5 files changed, 76 insertions(+), 167 deletions(-) delete mode 100644 src/java/org/apache/fop/apps/AWTStarter.java diff --git a/src/java/org/apache/fop/apps/AWTStarter.java b/src/java/org/apache/fop/apps/AWTStarter.java deleted file mode 100644 index 8fbdd2e73..000000000 --- a/src/java/org/apache/fop/apps/AWTStarter.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * $Id: AWTStarter.java,v 1.18 2003/02/27 10:13:05 jeremias Exp $ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modifica- - * tion, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 3. The end-user documentation included with the redistribution, if any, must - * include the following acknowledgment: "This product includes software - * developed by the Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, if - * and wherever such third-party acknowledgments normally appear. - * - * 4. The names "FOP" and "Apache Software Foundation" must not be used to - * endorse or promote products derived from this software without prior - * written permission. For written permission, please contact - * apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", nor may - * "Apache" appear in their name, without prior written permission of the - * Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * ============================================================================ - * - * This software consists of voluntary contributions made by many individuals - * on behalf of the Apache Software Foundation and was originally created by - * James Tauber . For more information on the Apache - * Software Foundation, please see . - */ -package org.apache.fop.apps; - -//FOP -import org.apache.fop.render.awt.AWTRenderer; -import org.apache.fop.viewer.PreviewDialog; - -//Java -import java.awt.Dimension; -import java.awt.Toolkit; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; - -/** - * AWT Viewer starter. - * Originally contributed by: - * Juergen Verwohlt: Juergen.Verwohlt@jCatalog.com, - * Rainer Steinkuhle: Rainer.Steinkuhle@jCatalog.com, - * Stanislav Gorkhover: Stanislav.Gorkhover@jCatalog.com - * Modified to use streaming API by Mark Lillywhite, mark-fop@inomial.com - */ -public class AWTStarter extends CommandLineStarter { - private PreviewDialog frame; - private Driver driver; - - /** - * Construct an AWTStarter - * @param commandLineOptions the parsed command line options - * @throws FOPException if anything goes wrong during initialization. - */ - public AWTStarter(CommandLineOptions commandLineOptions) - throws FOPException { - super(commandLineOptions); - init(); - } - - private void init() throws FOPException { - AWTRenderer renderer = new AWTRenderer(); - frame = createPreviewDialog(renderer); - renderer.setPreviewDialog(frame); - renderer.setOptions(commandLineOptions.getRendererOptions()); - driver = new Driver(); - driver.setRenderer(renderer); - } - - /** - * Runs formatting. - * @throws FOPException FIXME should not happen. - */ - public void run() throws FOPException { - driver.reset(); - try { - driver.render(inputHandler); - } catch (Exception e) { - frame.reportException(e); - } - } - - private PreviewDialog createPreviewDialog(AWTRenderer renderer) { - PreviewDialog frame = new PreviewDialog(this, renderer); - frame.addWindowListener(new WindowAdapter() { - public void windowClosed(WindowEvent we) { - System.exit(0); - } - }); - - //Centers the window - Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - Dimension frameSize = frame.getSize(); - if (frameSize.height > screenSize.height) { - frameSize.height = screenSize.height; - } - if (frameSize.width > screenSize.width) { - frameSize.width = screenSize.width; - } - frame.setLocation((screenSize.width - frameSize.width) / 2, - (screenSize.height - frameSize.height) / 2); - frame.setVisible(true); - return frame; - } -} - diff --git a/src/java/org/apache/fop/apps/CommandLineStarter.java b/src/java/org/apache/fop/apps/CommandLineStarter.java index 579666b82..43f324211 100644 --- a/src/java/org/apache/fop/apps/CommandLineStarter.java +++ b/src/java/org/apache/fop/apps/CommandLineStarter.java @@ -54,6 +54,8 @@ package org.apache.fop.apps; import java.io.BufferedOutputStream; import java.io.FileOutputStream; +// FOP +import org.apache.fop.render.awt.AWTRenderer; /** * super class for all classes which start Fop from the commandline @@ -88,7 +90,11 @@ public class CommandLineStarter extends Starter { setupLogger(driver); try { - driver.setRenderer(commandLineOptions.getRenderer()); + if (commandLineOptions.getOutputMode() == CommandLineOptions.AWT_OUTPUT) { + driver.setRenderer(new AWTRenderer(inputHandler)); + } else { + driver.setRenderer(commandLineOptions.getRenderer()); + } try { if (commandLineOptions.getOutputFile() != null) { @@ -107,7 +113,6 @@ public class CommandLineStarter extends Starter { bos.close(); } } - System.exit(0); } catch (Exception e) { if (e instanceof FOPException) { throw (FOPException) e; diff --git a/src/java/org/apache/fop/apps/Fop.java b/src/java/org/apache/fop/apps/Fop.java index 76ec115f5..5cd55638c 100644 --- a/src/java/org/apache/fop/apps/Fop.java +++ b/src/java/org/apache/fop/apps/Fop.java @@ -67,11 +67,7 @@ public class Fop { try { options = new CommandLineOptions(args); - if (options.getOutputMode() == CommandLineOptions.AWT_OUTPUT) { - starter = new AWTStarter(options); - } else { - starter = new CommandLineStarter(options); - } + starter = new CommandLineStarter(options); starter.enableLogging(new ConsoleLogger(ConsoleLogger.LEVEL_INFO)); starter.run(); } catch (FOPException e) { diff --git a/src/java/org/apache/fop/render/awt/AWTRenderer.java b/src/java/org/apache/fop/render/awt/AWTRenderer.java index d46fca157..4314078cd 100644 --- a/src/java/org/apache/fop/render/awt/AWTRenderer.java +++ b/src/java/org/apache/fop/render/awt/AWTRenderer.java @@ -57,10 +57,15 @@ package org.apache.fop.render.awt; * Stanislav Gorkhover: Stanislav.Gorkhover@jCatalog.com */ +// Java import java.awt.Color; import java.awt.Component; +import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; +import java.awt.Toolkit; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; import java.awt.image.BufferedImage; import java.awt.print.PageFormat; import java.awt.print.Pageable; @@ -70,6 +75,8 @@ import java.io.OutputStream; import java.util.List; import java.util.Map; +// FOP +import org.apache.fop.apps.InputHandler; import org.apache.fop.layout.FontInfo; import org.apache.fop.render.AbstractRenderer; import org.apache.fop.viewer.PreviewDialog; @@ -87,6 +94,12 @@ public class AWTRenderer extends AbstractRenderer implements Printable, Pageable protected List pageList = new java.util.Vector(); //protected ProgressListener progressListener = null; + /** + The InputHandler associated with this Renderer. + Sent to the PreviewDialog for document reloading. + */ + protected InputHandler inputHandler; + /** * The resource bundle used for AWT messages. */ @@ -127,8 +140,15 @@ public class AWTRenderer extends AbstractRenderer implements Printable, Pageable */ protected PreviewDialog frame; + public AWTRenderer(InputHandler handler) { + inputHandler = handler; + translator = new Translator(); + createPreviewDialog(inputHandler); + } + public AWTRenderer() { translator = new Translator(); + createPreviewDialog(null); } public Translator getTranslator() { @@ -146,15 +166,6 @@ public class AWTRenderer extends AbstractRenderer implements Printable, Pageable FontSetup.setup(fontInfo, fontImage.createGraphics()); } - /** - * Sets the preview dialog frame used for display of the documents. - * @param frame the PreviewDialog frame - */ - public void setPreviewDialog(PreviewDialog frame) { - this.frame = frame; - frame.setStatus(translator.getString("Status.Build.FO.tree")); - } - public int getPageNumber() { return pageNumber; } @@ -201,4 +212,28 @@ public class AWTRenderer extends AbstractRenderer implements Printable, Pageable public int print(Graphics g, PageFormat format, int pos) { return 0; } + + private PreviewDialog createPreviewDialog(InputHandler handler) { + frame = new PreviewDialog(this, handler); + frame.addWindowListener(new WindowAdapter() { + public void windowClosed(WindowEvent we) { + System.exit(0); + } + }); + + //Centers the window + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + Dimension frameSize = frame.getSize(); + if (frameSize.height > screenSize.height) { + frameSize.height = screenSize.height; + } + if (frameSize.width > screenSize.width) { + frameSize.width = screenSize.width; + } + frame.setLocation((screenSize.width - frameSize.width) / 2, + (screenSize.height - frameSize.height) / 2); + frame.setVisible(true); + frame.setStatus(translator.getString("Status.Build.FO.tree")); + return frame; + } } diff --git a/src/java/org/apache/fop/viewer/PreviewDialog.java b/src/java/org/apache/fop/viewer/PreviewDialog.java index ab6d71e16..af77e286f 100644 --- a/src/java/org/apache/fop/viewer/PreviewDialog.java +++ b/src/java/org/apache/fop/viewer/PreviewDialog.java @@ -77,7 +77,8 @@ import java.awt.print.PrinterJob; import java.awt.print.PrinterException; //FOP -import org.apache.fop.apps.AWTStarter; +import org.apache.fop.apps.Driver; +import org.apache.fop.apps.InputHandler; import org.apache.fop.apps.FOPException; import org.apache.fop.render.awt.AWTRenderer; @@ -94,8 +95,10 @@ public class PreviewDialog extends JFrame { protected Translator translator; /** The AWT renderer */ protected AWTRenderer renderer; - /** The AWT starter */ - protected AWTStarter starter; + /** The InputHandler associated with this window */ + protected InputHandler inputHandler; + /** The Driver used for refreshing/reloading the view */ + protected Driver driver; private int currentPage = 0; private int pageCount = 0; @@ -105,22 +108,13 @@ public class PreviewDialog extends JFrame { private JLabel pageLabel; private JLabel infoStatus; - /** - * Creates a new PreviewDialog that uses the given starter and renderer. - * @param aStarter the to use starter - * @param aRenderer the to use renderer - */ - public PreviewDialog(AWTStarter aStarter, AWTRenderer aRenderer) { - this(aRenderer); - starter = aStarter; - } - /** * Creates a new PreviewDialog that uses the given renderer. * @param aRenderer the to use renderer */ - public PreviewDialog(AWTRenderer aRenderer) { + public PreviewDialog(AWTRenderer aRenderer, InputHandler handler) { renderer = aRenderer; + inputHandler = handler; translator = renderer.getTranslator(); //Commands aka Actions @@ -253,11 +247,14 @@ public class PreviewDialog extends JFrame { print(); } }); - menu.add(new Command(translator.getString("Menu.Reload")) { - public void doit() { - reload(); - } - }); + // inputHandler must be set to allow reloading + if (inputHandler != null) { + menu.add(new Command(translator.getString("Menu.Reload")) { + public void doit() { + reload(); + } + }); + } menu.addSeparator(); menu.add(new Command(translator.getString("Menu.Exit")) { public void doit() { @@ -415,6 +412,13 @@ public class PreviewDialog extends JFrame { */ private class Reloader extends Thread { public void run() { + if (driver == null) { + driver = new Driver(); + driver.setRenderer(renderer); + } else { + driver.reset(); + } + pageLabel.setIcon(null); infoStatus.setText(""); currentPage = 0; @@ -423,7 +427,7 @@ public class PreviewDialog extends JFrame { // renderer.removePage(0); try { setStatus(translator.getString("Status.Build.FO.tree")); - starter.run(); + driver.render(inputHandler); setStatus(translator.getString("Status.Show")); } catch (FOPException e) { reportException(e); -- 2.39.5