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-ffa450edef68tags/fop-0_90-alpha1
@@ -428,7 +428,7 @@ list of possible build targets. | |||
<jar jarfile="${build.dir}/fop.jar" basedir="${build.classes.dir}" includes="org/**"> | |||
<manifest> | |||
<attribute name="Main-Class" value="org.apache.fop.apps.Fop"/> | |||
<attribute name="Main-Class" value="org.apache.fop.cli.Main"/> | |||
<!--attribute name="Class-Path" value="${manifest-classpath}"/--> | |||
<attribute name="Implementation-Title" value="${Name}"/> | |||
<attribute name="Implementation-Version" value="${version}"/> |
@@ -54,5 +54,5 @@ set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\jai_codec.jar | |||
set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\fop-hyph.jar | |||
set LOCALCLASSPATH=%LOCALCLASSPATH%;%FOP_HYPHENATION_PATH% | |||
java %LOGCHOICE% %LOGLEVEL% -cp "%LOCALCLASSPATH%" org.apache.fop.apps.Fop %FOP_CMD_LINE_ARGS% | |||
java %LOGCHOICE% %LOGLEVEL% -cp "%LOCALCLASSPATH%" org.apache.fop.cli.Main %FOP_CMD_LINE_ARGS% | |||
@@ -122,5 +122,5 @@ LOGLEVEL= | |||
# Possible SimpleLog values: "trace", "debug", "info" (default), "warn", "error", or "fatal". | |||
# LOGLEVEL=-Dorg.apache.commons.logging.simplelog.defaultlog=INFO | |||
$JAVACMD $LOGCHOICE $LOGLEVEL -classpath "$LOCALCLASSPATH" $FOP_OPTS org.apache.fop.apps.Fop "$@" | |||
$JAVACMD $LOGCHOICE $LOGLEVEL -classpath "$LOCALCLASSPATH" $FOP_OPTS org.apache.fop.cli.Main "$@" | |||
@@ -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; | |||
@@ -122,23 +121,6 @@ public class FOUserAgent { | |||
/** Set of keywords applicable to this document. */ | |||
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. |
@@ -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) | |||
@@ -160,161 +151,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 |
@@ -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> |
@@ -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,9 +125,23 @@ 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 |
@@ -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 { |
@@ -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); | |||
} | |||
} | |||
} |
@@ -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> |
@@ -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; | |||
@@ -72,6 +73,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. | |||
*/ | |||
@@ -87,6 +94,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. | |||
@@ -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); |
@@ -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 | |||
@@ -231,6 +239,14 @@ public class PreviewDialog extends JFrame { | |||
getContentPane().add(statusBar, BorderLayout.SOUTH); | |||
} | |||
/** | |||
* 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(); |
@@ -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(); |
@@ -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; | |||
} |
@@ -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; |
@@ -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; |
@@ -29,7 +29,7 @@ import javax.xml.transform.stream.StreamSource; | |||
import org.apache.commons.io.output.ByteArrayOutputStream; | |||
import org.apache.fop.apps.Fop; | |||
import org.apache.fop.apps.InputHandler; | |||
import org.apache.fop.cli.InputHandler; | |||
/** | |||
* Basic runtime test for the old Fop class. It is used to verify that |