aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/render
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2008-04-17 13:33:07 +0000
committerJeremias Maerki <jeremias@apache.org>2008-04-17 13:33:07 +0000
commite5ee5c2bcf5872ecaf03c6e6e8c5a73904ee4a67 (patch)
treead01d4137cef97518339231cfd6c8d5b40ff9f85 /src/java/org/apache/fop/render
parent54e844c8c55d8f4adc7a4579771276dc7229794b (diff)
downloadxmlgraphics-fop-e5ee5c2bcf5872ecaf03c6e6e8c5a73904ee4a67.tar.gz
xmlgraphics-fop-e5ee5c2bcf5872ecaf03c6e6e8c5a73904ee4a67.zip
Bugzilla #44678:
Added ability to pass in the PrinterJob instance through the renderer options. Submitted by: Antti Karanta <Antti.Karanta.at.napa.fi> Modifications/Additions to patch: - Don't remove the contructor with the PrinterJob parameter, just deprecate it. - Adjust old-style print example to use renderer options git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@649091 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/render')
-rw-r--r--src/java/org/apache/fop/render/print/PrintRenderer.java67
1 files changed, 53 insertions, 14 deletions
diff --git a/src/java/org/apache/fop/render/print/PrintRenderer.java b/src/java/org/apache/fop/render/print/PrintRenderer.java
index e4c159815..b70bb21aa 100644
--- a/src/java/org/apache/fop/render/print/PrintRenderer.java
+++ b/src/java/org/apache/fop/render/print/PrintRenderer.java
@@ -27,9 +27,11 @@ import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.io.IOException;
+import java.util.Map;
import java.util.Vector;
import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.render.java2d.Java2DRenderer;
/**
@@ -40,6 +42,13 @@ import org.apache.fop.render.java2d.Java2DRenderer;
*/
public class PrintRenderer extends Java2DRenderer implements Pageable {
+ /**
+ * Printing parameter: the preconfigured PrinterJob to use,
+ * datatype: java.awt.print.PrinterJob
+ */
+ public static final String PRINTER_JOB = "printerjob";
+
+
private static final int EVEN_AND_ALL = 0;
private static final int EVEN = 1;
@@ -57,23 +66,42 @@ public class PrintRenderer extends Java2DRenderer implements Pageable {
private PrinterJob printerJob;
/**
- * Creates a new PrintRenderer with the options set from system properties.
+ * Creates a new PrintRenderer with the options set from system properties if a custom
+ * PrinterJob is not given in FOUserAgent's renderer options.
*/
public PrintRenderer() {
- initializePrinterJob();
+ setupFromSystemProperties();
}
-
+
/**
* Creates a new PrintRenderer and allows you to pass in a specific PrinterJob instance
* that this renderer should work with.
* @param printerJob the PrinterJob instance
+ * @deprecated Please use the rendering options on the user agent to pass in the PrinterJob!
*/
public PrintRenderer(PrinterJob printerJob) {
+ this();
this.printerJob = printerJob;
printerJob.setPageable(this);
}
- private void initializePrinterJob() throws IllegalArgumentException {
+ private void initializePrinterJob() {
+ if (this.printerJob == null) {
+ printerJob = PrinterJob.getPrinterJob();
+ printerJob.setJobName("FOP Document");
+ printerJob.setCopies(copies);
+ if (System.getProperty("dialog") != null) {
+ if (!printerJob.printDialog()) {
+ throw new RuntimeException(
+ "Printing cancelled by operator");
+ }
+ }
+ printerJob.setPageable(this);
+ }
+ }
+
+ private void setupFromSystemProperties() {
+ //TODO Remove me! This is not a beautiful way to do this.
// read from command-line options
copies = getIntProperty("copies", 1);
startNumber = getIntProperty("start", 1) - 1;
@@ -82,19 +110,28 @@ public class PrintRenderer extends Java2DRenderer implements Pageable {
if (str != null) {
mode = Boolean.valueOf(str).booleanValue() ? EVEN : ODD;
}
-
- printerJob = PrinterJob.getPrinterJob();
- printerJob.setJobName("FOP Document");
- printerJob.setCopies(copies);
- if (System.getProperty("dialog") != null) {
- if (!printerJob.printDialog()) {
+ }
+
+ /** {@inheritDoc} */
+ public void setUserAgent(FOUserAgent agent) {
+ super.setUserAgent(agent);
+
+ Map rendererOptions = agent.getRendererOptions();
+
+ Object printerJobO = rendererOptions.get(PrintRenderer.PRINTER_JOB);
+ if (printerJobO != null) {
+ if (!(printerJobO instanceof PrinterJob)) {
throw new IllegalArgumentException(
- "Printing cancelled by operator");
+ "Renderer option " + PrintRenderer.PRINTER_JOB
+ + " must be an instance of java.awt.print.PrinterJob, but an instance of "
+ + printerJobO.getClass().getName() + " was given.");
}
+ printerJob = (PrinterJob)printerJobO;
+ printerJob.setPageable(this);
}
- printerJob.setPageable(this);
+ initializePrinterJob();
}
-
+
/** @return the PrinterJob instance that this renderer prints to */
public PrinterJob getPrinterJob() {
return this.printerJob;
@@ -126,6 +163,7 @@ public class PrintRenderer extends Java2DRenderer implements Pageable {
this.startNumber = start;
}
+ /** {@inheritDoc} */
public void stopRenderer() throws IOException {
super.stopRenderer();
@@ -149,7 +187,7 @@ public class PrintRenderer extends Java2DRenderer implements Pageable {
clearViewportList();
}
- public static int getIntProperty(String name, int def) {
+ private static int getIntProperty(String name, int def) {
String propValue = System.getProperty(name);
if (propValue != null) {
try {
@@ -219,6 +257,7 @@ public class PrintRenderer extends Java2DRenderer implements Pageable {
}
}
+ /** {@inheritDoc} */
public Printable getPrintable(int pageIndex)
throws IndexOutOfBoundsException {
return this;