aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2005-08-23 14:06:25 +0000
committerJeremias Maerki <jeremias@apache.org>2005-08-23 14:06:25 +0000
commitd23dad3ac526243651ecfc64e5ba42f2b76c959c (patch)
tree52820c77727ad46685477114b339f33631d283b3 /src/java/org/apache
parentc4aa8acd9cffd99ba4858d54991a00e338fb1e5b (diff)
downloadxmlgraphics-fop-d23dad3ac526243651ecfc64e5ba42f2b76c959c.tar.gz
xmlgraphics-fop-d23dad3ac526243651ecfc64e5ba42f2b76c959c.zip
Moved CLI to its own package. New main class is org.apache.fop.cli.Main.
InputHandler is not passed through the FOUserAgent anymore. IMO it doesn't belong there. Instead I defined an interface "Renderable" in the AWT preview that InputHandler implements. This is used exclusively for reloading the document inside the preview dialog. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@239409 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache')
-rw-r--r--src/java/org/apache/fop/apps/FOUserAgent.java18
-rw-r--r--src/java/org/apache/fop/apps/Fop.java166
-rw-r--r--src/java/org/apache/fop/apps/package.html3
-rw-r--r--src/java/org/apache/fop/cli/CommandLineOptions.java (renamed from src/java/org/apache/fop/apps/CommandLineOptions.java)24
-rw-r--r--src/java/org/apache/fop/cli/InputHandler.java (renamed from src/java/org/apache/fop/apps/InputHandler.java)19
-rw-r--r--src/java/org/apache/fop/cli/Main.java192
-rw-r--r--src/java/org/apache/fop/cli/package.html6
-rw-r--r--src/java/org/apache/fop/render/awt/AWTRenderer.java18
-rw-r--r--src/java/org/apache/fop/render/awt/viewer/PreviewDialog.java22
-rw-r--r--src/java/org/apache/fop/render/awt/viewer/PreviewPanel.java19
-rw-r--r--src/java/org/apache/fop/render/awt/viewer/Renderable.java36
-rw-r--r--src/java/org/apache/fop/tools/TestConverter.java4
-rw-r--r--src/java/org/apache/fop/tools/anttasks/Fop.java4
13 files changed, 325 insertions, 206 deletions
diff --git a/src/java/org/apache/fop/apps/FOUserAgent.java b/src/java/org/apache/fop/apps/FOUserAgent.java
index c371a42b6..328087f3b 100644
--- a/src/java/org/apache/fop/apps/FOUserAgent.java
+++ b/src/java/org/apache/fop/apps/FOUserAgent.java
@@ -81,7 +81,6 @@ public class FOUserAgent {
private PDFEncryptionParams pdfEncryptionParams;
private float px2mm = DEFAULT_PX2MM;
private Map rendererOptions = new java.util.HashMap();
- private InputHandler inputHandler = null;
private File outputFile = null;
private Renderer rendererOverride = null;
private FOEventHandler foEventHandlerOverride = null;
@@ -123,23 +122,6 @@ public class FOUserAgent {
protected String keywords = null;
/**
- * Sets the InputHandler object for this process
- * @param inputHandler holding input file name information
- */
- public void setInputHandler(InputHandler inputHandler) {
- this.inputHandler = inputHandler;
- }
-
- /**
- * Returns the apps.InputHandler object created during command-line
- * processing
- * @return InputHandler object
- */
- public InputHandler getInputHandler() {
- return inputHandler;
- }
-
- /**
* Add the element mapping with the given class name.
* @param elementMapping the class name representing the element mapping.
*/
diff --git a/src/java/org/apache/fop/apps/Fop.java b/src/java/org/apache/fop/apps/Fop.java
index b359e23b7..bef2b4a3e 100644
--- a/src/java/org/apache/fop/apps/Fop.java
+++ b/src/java/org/apache/fop/apps/Fop.java
@@ -19,15 +19,7 @@
package org.apache.fop.apps;
// Java
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileFilter;
-import java.io.FileOutputStream;
import java.io.OutputStream;
-import java.lang.reflect.Method;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.List;
// XML
import org.xml.sax.helpers.DefaultHandler;
@@ -37,8 +29,7 @@ import org.apache.fop.fo.Constants;
import org.apache.fop.fo.FOTreeBuilder;
/**
- * Primary class that activates the FOP process for both command line
- * and embedded usage.
+ * Primary class that activates the FOP process for embedded usage.
* <P>
* JAXP is the standard method of embedding FOP in Java programs.
* Please check our embedding page (http://xml.apache.org/fop/embedding.html)
@@ -161,161 +152,6 @@ public class Fop implements Constants {
}
/**
- * @return the list of URLs to all libraries.
- * @throws MalformedURLException In case there is a problem converting java.io.File
- * instances to URLs.
- */
- public static URL[] getJARList() throws MalformedURLException {
- File baseDir = new File(".").getAbsoluteFile().getParentFile();
- File buildDir;
- if ("build".equals(baseDir.getName())) {
- buildDir = baseDir;
- baseDir = baseDir.getParentFile();
- } else {
- buildDir = new File(baseDir, "build");
- }
- File fopJar = new File(buildDir, "fop.jar");
- if (!fopJar.exists()) {
- fopJar = new File(baseDir, "fop.jar");
- }
- if (!fopJar.exists()) {
- throw new RuntimeException("fop.jar not found in directory: "
- + baseDir.getAbsolutePath() + " (or below)");
- }
- List jars = new java.util.ArrayList();
- jars.add(fopJar.toURL());
- File[] files;
- FileFilter filter = new FileFilter() {
- public boolean accept(File pathname) {
- return pathname.getName().endsWith(".jar");
- }
- };
- File libDir = new File(baseDir, "lib");
- if (!libDir.exists()) {
- libDir = baseDir;
- }
- files = libDir.listFiles(filter);
- if (files != null) {
- for (int i = 0, size = files.length; i < size; i++) {
- jars.add(files[i].toURL());
- }
- }
- String optionalLib = System.getProperty("fop.optional.lib");
- if (optionalLib != null) {
- files = new File(optionalLib).listFiles(filter);
- if (files != null) {
- for (int i = 0, size = files.length; i < size; i++) {
- jars.add(files[i].toURL());
- }
- }
- }
- URL[] urls = (URL[])jars.toArray(new URL[jars.size()]);
- /*
- for (int i = 0, c = urls.length; i < c; i++) {
- System.out.println(urls[i]);
- }*/
- return urls;
- }
-
- /**
- * @return true if FOP's dependecies are available in the current ClassLoader setup.
- */
- public static boolean checkDependencies() {
- try {
- //System.out.println(Thread.currentThread().getContextClassLoader());
- Class clazz = Class.forName("org.apache.batik.Version");
- if (clazz != null) {
- clazz = Class.forName("org.apache.avalon.framework.configuration.Configuration");
- }
- return (clazz != null);
- } catch (Exception e) {
- return false;
- }
- }
-
- /**
- * Dynamically builds a ClassLoader and executes FOP.
- * @param args command-line arguments
- */
- public static void startFOPWithDynamicClasspath(String[] args) {
- try {
- URL[] urls = getJARList();
- //System.out.println("CCL: "
- // + Thread.currentThread().getContextClassLoader().toString());
- ClassLoader loader = new java.net.URLClassLoader(urls, null);
- Thread.currentThread().setContextClassLoader(loader);
- Class clazz = Class.forName("org.apache.fop.apps.Fop", true, loader);
- //System.out.println("CL: " + clazz.getClassLoader().toString());
- Method mainMethod = clazz.getMethod("startFOP", new Class[] {String[].class});
- mainMethod.invoke(null, new Object[] {args});
- } catch (Exception e) {
- System.err.println("Unable to start FOP:");
- e.printStackTrace();
- System.exit(-1);
- }
- }
-
- /**
- * Executes FOP with the given ClassLoader setup.
- * @param args command-line arguments
- */
- public static void startFOP(String[] args) {
- //System.out.println("static CCL: "
- // + Thread.currentThread().getContextClassLoader().toString());
- //System.out.println("static CL: " + Fop.class.getClassLoader().toString());
- CommandLineOptions options = null;
- FOUserAgent foUserAgent = null;
- BufferedOutputStream bos = null;
-
- try {
- options = new CommandLineOptions();
- options.parse(args);
- foUserAgent = options.getFOUserAgent();
-
- Fop fop = new Fop(options.getRenderer(), foUserAgent);
-
- try {
- if (options.getOutputFile() != null) {
- bos = new BufferedOutputStream(new FileOutputStream(
- options.getOutputFile()));
- fop.setOutputStream(bos);
- foUserAgent.setOutputFile(options.getOutputFile());
- }
- foUserAgent.getInputHandler().render(fop);
- } finally {
- if (bos != null) {
- bos.close();
- }
- }
-
- // System.exit(0) called to close AWT/SVG-created threads, if any.
- // AWTRenderer closes with window shutdown, so exit() should not
- // be called here
- if (options.getOutputMode() != CommandLineOptions.RENDER_AWT) {
- System.exit(0);
- }
- } catch (Exception e) {
- if (options != null) {
- options.getLogger().error("Exception", e);
- }
- System.exit(1);
- }
- }
-
- /**
- * The main routine for the command line interface
- * @param args the command line parameters
- */
- public static void main(String[] args) {
- if (checkDependencies()) {
- startFOP(args);
- } else {
- startFOPWithDynamicClasspath(args);
- }
- }
-
-
- /**
* Get the version of FOP
* @return the version string
*/
diff --git a/src/java/org/apache/fop/apps/package.html b/src/java/org/apache/fop/apps/package.html
index c8a9798d5..2bf75de3f 100644
--- a/src/java/org/apache/fop/apps/package.html
+++ b/src/java/org/apache/fop/apps/package.html
@@ -1,7 +1,6 @@
<HTML>
<TITLE>org.apache.fop.apps Package</TITLE>
<BODY>
-<P>Application classes used for running FOP both on the command line and
-embedded in other applications.</P>
+<P>Application classes used for running FOP embedded in other applications.</P>
</BODY>
</HTML> \ No newline at end of file
diff --git a/src/java/org/apache/fop/apps/CommandLineOptions.java b/src/java/org/apache/fop/cli/CommandLineOptions.java
index 434fb8be1..3eb70b577 100644
--- a/src/java/org/apache/fop/apps/CommandLineOptions.java
+++ b/src/java/org/apache/fop/cli/CommandLineOptions.java
@@ -16,7 +16,7 @@
/* $Id$ */
-package org.apache.fop.apps;
+package org.apache.fop.cli;
// java
import java.io.File;
@@ -25,7 +25,11 @@ import java.io.IOException;
import java.util.Locale;
import java.util.Vector;
+import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.Fop;
import org.apache.fop.fo.Constants;
+import org.apache.fop.render.awt.AWTRenderer;
import org.apache.fop.util.CommandLineLogger;
// commons logging
@@ -68,6 +72,8 @@ public class CommandLineOptions implements Constants {
private FOUserAgent foUserAgent;
+ private InputHandler inputHandler;
+
private Log log;
private Vector xsltParams = null;
@@ -119,10 +125,24 @@ public class CommandLineOptions implements Constants {
throw e;
}
- foUserAgent.setInputHandler(createInputHandler());
+ inputHandler = createInputHandler();
+
+ if (outputmode == RENDER_AWT) {
+ AWTRenderer renderer = new AWTRenderer();
+ renderer.setRenderable(inputHandler); //set before user agent!
+ renderer.setUserAgent(foUserAgent);
+ foUserAgent.setRendererOverride(renderer);
+ }
}
/**
+ * @return the InputHandler instance defined by the command-line options.
+ */
+ public InputHandler getInputHandler() {
+ return inputHandler;
+ }
+
+ /**
* Get the logger.
* @return the logger
*/
diff --git a/src/java/org/apache/fop/apps/InputHandler.java b/src/java/org/apache/fop/cli/InputHandler.java
index ec4daa5e7..0de3cc9fe 100644
--- a/src/java/org/apache/fop/apps/InputHandler.java
+++ b/src/java/org/apache/fop/cli/InputHandler.java
@@ -16,7 +16,7 @@
/* $Id$ */
-package org.apache.fop.apps;
+package org.apache.fop.cli;
// Imported java.io classes
import java.io.File;
@@ -34,13 +34,17 @@ import javax.xml.transform.stream.StreamSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.Fop;
+import org.apache.fop.render.awt.viewer.Renderable;
/**
* Class for handling files input from command line
* either with XML and XSLT files (and optionally xsl
* parameters) or FO File input alone
*/
-public class InputHandler implements ErrorListener {
+public class InputHandler implements ErrorListener, Renderable {
+
private File sourcefile = null; // either FO or XML/XSLT usage
private File stylesheet = null; // for XML/XSLT usage
private Vector xsltParams = null; // for XML/XSLT usage
@@ -80,8 +84,7 @@ public class InputHandler implements ErrorListener {
String baseURL = null;
try {
- baseURL =
- new File(sourcefile.getAbsolutePath()).
+ baseURL = new File(sourcefile.getAbsolutePath()).
getParentFile().toURL().toExternalForm();
} catch (Exception e) {
baseURL = "";
@@ -124,22 +127,24 @@ public class InputHandler implements ErrorListener {
}
}
+ // --- Implementation of the ErrorListener interface ---
+
/**
- * Implementation of the ErrorListener interface.
+ * @see javax.xml.transform.ErrorListener#warning(javax.xml.transform.TransformerException)
*/
public void warning(TransformerException exc) {
log.warn(exc.toString());
}
/**
- * Implementation of the ErrorListener interface.
+ * @see javax.xml.transform.ErrorListener#error(javax.xml.transform.TransformerException)
*/
public void error(TransformerException exc) {
log.error(exc.toString());
}
/**
- * Implementation of the ErrorListener interface.
+ * @see javax.xml.transform.ErrorListener#fatalError(javax.xml.transform.TransformerException)
*/
public void fatalError(TransformerException exc)
throws TransformerException {
diff --git a/src/java/org/apache/fop/cli/Main.java b/src/java/org/apache/fop/cli/Main.java
new file mode 100644
index 000000000..4f05dcab1
--- /dev/null
+++ b/src/java/org/apache/fop/cli/Main.java
@@ -0,0 +1,192 @@
+/*
+ * 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.cli;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileOutputStream;
+import java.lang.reflect.Method;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.List;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.Fop;
+
+/**
+ * Main command-line class for Apache FOP.
+ */
+public class Main {
+
+ /**
+ * @return the list of URLs to all libraries.
+ * @throws MalformedURLException In case there is a problem converting java.io.File
+ * instances to URLs.
+ */
+ public static URL[] getJARList() throws MalformedURLException {
+ File baseDir = new File(".").getAbsoluteFile().getParentFile();
+ File buildDir;
+ if ("build".equals(baseDir.getName())) {
+ buildDir = baseDir;
+ baseDir = baseDir.getParentFile();
+ } else {
+ buildDir = new File(baseDir, "build");
+ }
+ File fopJar = new File(buildDir, "fop.jar");
+ if (!fopJar.exists()) {
+ fopJar = new File(baseDir, "fop.jar");
+ }
+ if (!fopJar.exists()) {
+ throw new RuntimeException("fop.jar not found in directory: "
+ + baseDir.getAbsolutePath() + " (or below)");
+ }
+ List jars = new java.util.ArrayList();
+ jars.add(fopJar.toURL());
+ File[] files;
+ FileFilter filter = new FileFilter() {
+ public boolean accept(File pathname) {
+ return pathname.getName().endsWith(".jar");
+ }
+ };
+ File libDir = new File(baseDir, "lib");
+ if (!libDir.exists()) {
+ libDir = baseDir;
+ }
+ files = libDir.listFiles(filter);
+ if (files != null) {
+ for (int i = 0, size = files.length; i < size; i++) {
+ jars.add(files[i].toURL());
+ }
+ }
+ String optionalLib = System.getProperty("fop.optional.lib");
+ if (optionalLib != null) {
+ files = new File(optionalLib).listFiles(filter);
+ if (files != null) {
+ for (int i = 0, size = files.length; i < size; i++) {
+ jars.add(files[i].toURL());
+ }
+ }
+ }
+ URL[] urls = (URL[])jars.toArray(new URL[jars.size()]);
+ /*
+ for (int i = 0, c = urls.length; i < c; i++) {
+ System.out.println(urls[i]);
+ }*/
+ return urls;
+ }
+
+ /**
+ * @return true if FOP's dependecies are available in the current ClassLoader setup.
+ */
+ public static boolean checkDependencies() {
+ try {
+ //System.out.println(Thread.currentThread().getContextClassLoader());
+ Class clazz = Class.forName("org.apache.batik.Version");
+ if (clazz != null) {
+ clazz = Class.forName("org.apache.avalon.framework.configuration.Configuration");
+ }
+ return (clazz != null);
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+ /**
+ * Dynamically builds a ClassLoader and executes FOP.
+ * @param args command-line arguments
+ */
+ public static void startFOPWithDynamicClasspath(String[] args) {
+ try {
+ URL[] urls = getJARList();
+ //System.out.println("CCL: "
+ // + Thread.currentThread().getContextClassLoader().toString());
+ ClassLoader loader = new java.net.URLClassLoader(urls, null);
+ Thread.currentThread().setContextClassLoader(loader);
+ Class clazz = Class.forName("org.apache.fop.cli.Main", true, loader);
+ //System.out.println("CL: " + clazz.getClassLoader().toString());
+ Method mainMethod = clazz.getMethod("startFOP", new Class[] {String[].class});
+ mainMethod.invoke(null, new Object[] {args});
+ } catch (Exception e) {
+ System.err.println("Unable to start FOP:");
+ e.printStackTrace();
+ System.exit(-1);
+ }
+ }
+
+ /**
+ * Executes FOP with the given ClassLoader setup.
+ * @param args command-line arguments
+ */
+ public static void startFOP(String[] args) {
+ //System.out.println("static CCL: "
+ // + Thread.currentThread().getContextClassLoader().toString());
+ //System.out.println("static CL: " + Fop.class.getClassLoader().toString());
+ CommandLineOptions options = null;
+ FOUserAgent foUserAgent = null;
+ BufferedOutputStream bos = null;
+
+ try {
+ options = new CommandLineOptions();
+ options.parse(args);
+ foUserAgent = options.getFOUserAgent();
+
+ Fop fop = new Fop(options.getRenderer(), foUserAgent);
+
+ try {
+ if (options.getOutputFile() != null) {
+ bos = new BufferedOutputStream(new FileOutputStream(
+ options.getOutputFile()));
+ fop.setOutputStream(bos);
+ foUserAgent.setOutputFile(options.getOutputFile());
+ }
+ options.getInputHandler().render(fop);
+ } finally {
+ if (bos != null) {
+ bos.close();
+ }
+ }
+
+ // System.exit(0) called to close AWT/SVG-created threads, if any.
+ // AWTRenderer closes with window shutdown, so exit() should not
+ // be called here
+ if (options.getOutputMode() != CommandLineOptions.RENDER_AWT) {
+ System.exit(0);
+ }
+ } catch (Exception e) {
+ if (options != null) {
+ options.getLogger().error("Exception", e);
+ }
+ System.exit(1);
+ }
+ }
+
+ /**
+ * The main routine for the command line interface
+ * @param args the command line parameters
+ */
+ public static void main(String[] args) {
+ if (checkDependencies()) {
+ startFOP(args);
+ } else {
+ startFOPWithDynamicClasspath(args);
+ }
+ }
+
+}
diff --git a/src/java/org/apache/fop/cli/package.html b/src/java/org/apache/fop/cli/package.html
new file mode 100644
index 000000000..8363121fd
--- /dev/null
+++ b/src/java/org/apache/fop/cli/package.html
@@ -0,0 +1,6 @@
+<HTML>
+<TITLE>org.apache.fop.cli Package</TITLE>
+<BODY>
+<P>This package contains the command-line client for Apache FOP.</P>
+</BODY>
+</HTML> \ No newline at end of file
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;
+
+}
diff --git a/src/java/org/apache/fop/tools/TestConverter.java b/src/java/org/apache/fop/tools/TestConverter.java
index 601c14944..04bcac275 100644
--- a/src/java/org/apache/fop/tools/TestConverter.java
+++ b/src/java/org/apache/fop/tools/TestConverter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-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.
@@ -27,7 +27,7 @@ import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.fop.apps.Fop;
import org.apache.fop.apps.FOUserAgent;
-import org.apache.fop.apps.InputHandler;
+import org.apache.fop.cli.InputHandler;
import org.apache.fop.tools.anttasks.FileCompare;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
diff --git a/src/java/org/apache/fop/tools/anttasks/Fop.java b/src/java/org/apache/fop/tools/anttasks/Fop.java
index a26febb40..49d64c961 100644
--- a/src/java/org/apache/fop/tools/anttasks/Fop.java
+++ b/src/java/org/apache/fop/tools/anttasks/Fop.java
@@ -1,5 +1,5 @@
/*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-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.
@@ -34,10 +34,10 @@ import java.net.MalformedURLException;
import java.util.List;
// FOP
-import org.apache.fop.apps.InputHandler;
import org.apache.fop.fo.Constants;
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.cli.InputHandler;
import org.apache.commons.logging.impl.SimpleLog;
import org.apache.commons.logging.Log;