+++ /dev/null
-/*
- * $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 <jtauber@jtauber.com>. For more information on the Apache
- * Software Foundation, please see <http://www.apache.org/>.
- */
-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;
- }
-}
-
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
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) {
bos.close();
}
}
- System.exit(0);
} catch (Exception e) {
if (e instanceof FOPException) {
throw (FOPException) e;
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) {
* 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;
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;
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.
*/
*/
protected PreviewDialog frame;
+ public AWTRenderer(InputHandler handler) {
+ inputHandler = handler;
+ translator = new Translator();
+ createPreviewDialog(inputHandler);
+ }
+
public AWTRenderer() {
translator = new Translator();
+ createPreviewDialog(null);
}
public Translator getTranslator() {
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;
}
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;
+ }
}
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;
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;
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
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() {
*/
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;
// 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);