]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
PrinterJob setup and construction moved from Driver to AWTPrintRenderer class. AWTPr...
authorGlen Mazza <gmazza@apache.org>
Sat, 2 Aug 2003 21:26:53 +0000 (21:26 +0000)
committerGlen Mazza <gmazza@apache.org>
Sat, 2 Aug 2003 21:26:53 +0000 (21:26 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@196770 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/apps/Driver.java
src/java/org/apache/fop/render/awt/AWTPrintRenderer.java
src/java/org/apache/fop/servlet/FopPrintServlet.java

index acf863a5409ce57385d71f7e1c5278355e4f2ccf..8ea305751d749d5011824e0b6d659a7c403116e5 100644 (file)
@@ -50,9 +50,6 @@
  */
 package org.apache.fop.apps;
 
-// Java
-import java.awt.print.PrinterJob;
-
 // FOP
 import org.apache.fop.fo.ElementMapping;
 import org.apache.fop.fo.FOTreeBuilder;
@@ -391,6 +388,7 @@ public class Driver implements LogEnabled {
      * <ul>
      * <li>RENDER_PDF</li>
      * <li>RENDER_AWT</li>
+     * <li>RENDER_PRINT</li>
      * <li>RENDER_MIF</li>
      * <li>RENDER_XML</li>
      * <li>RENDER_PCL</li>
@@ -411,16 +409,7 @@ public class Driver implements LogEnabled {
         case RENDER_AWT:
             throw new IllegalArgumentException("Use renderer form of setRenderer() for AWT");
         case RENDER_PRINT:
-            // a PrinterJob object is needed to create this renderer
-            PrinterJob pj = PrinterJob.getPrinterJob();
-            int copies = AWTPrintRenderer.getIntProperty("copies", 1);
-            pj.setCopies(copies);
-            if (System.getProperty("dialog") != null) {
-                if (!pj.printDialog()) {
-                    throw new IllegalArgumentException("Printing cancelled by operator");
-                }
-            }
-            setRenderer(new AWTPrintRenderer(pj));
+            setRenderer("org.apache.fop.render.awt.AWTPrintRenderer");
             break;
         case RENDER_PCL:
             setRenderer("org.apache.fop.render.pcl.PCLRenderer");
index f205bdf31dd676d2336c7d253cf9099d9b9df9d1..189ec1481fc2d6944dce52ccbfcd9acf0b1d369f 100644 (file)
@@ -67,18 +67,30 @@ public class AWTPrintRenderer extends AWTRenderer {
     private int copies = 1;
     private PrinterJob printerJob;
 
-    public AWTPrintRenderer(PrinterJob printerJob) {
+    public AWTPrintRenderer() {
         super(null);
-        this.printerJob = printerJob;
+        initialize();
+    }
+
+    private void initialize() throws IllegalArgumentException {
+        // read from command-line options
+        copies = getIntProperty("copies", 1);
         startNumber = getIntProperty("start", 1) - 1;
         endNumber = getIntProperty("end", -1);
-        printerJob.setPageable(this);
-        mode = EVEN_AND_ALL;
         String str = System.getProperty("even");
         if (str != null) {
             mode = Boolean.valueOf(str).booleanValue() ? EVEN : ODD;
         }
-    }
+        
+        printerJob = PrinterJob.getPrinterJob();
+        printerJob.setCopies(copies);
+        if (System.getProperty("dialog") != null) {
+            if (!printerJob.printDialog()) {
+                throw new IllegalArgumentException("Printing cancelled by operator");
+            }
+        }
+        printerJob.setPageable(this);
+    }   
 
     public void stopRenderer() throws IOException {
         super.stopRenderer();
@@ -137,14 +149,5 @@ public class AWTPrintRenderer extends AWTRenderer {
         }
         return vec;
     }
-
-    /* TODO: I'm not totally sure that this is necessary -Mark
-       void setCopies(int val) {
-               copies = val;
-               Vector copie = tree.getPages();
-               for (int i = 1; i < copies; i++) {
-                       tree.getPages().addAll(copie);
-               }
-    } */
 } // class AWTPrintRenderer
 
index 1b030f51e17da4870c83247b9329d1e64331ba75..fc4f3c3c8e4fb6b0ea531c03fd114f9851714208 100644 (file)
@@ -56,8 +56,6 @@ import java.io.InputStream;
 import java.io.PrintWriter;
 import java.util.List;
 
-import java.awt.print.PrinterJob;
-
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
@@ -171,8 +169,7 @@ public class FopPrintServlet extends HttpServlet {
                          HttpServletResponse response) throws ServletException {
         try {
             Driver driver = new Driver(foFile, null);
-            PrinterJob pj = PrinterJob.getPrinterJob();
-            AWTPrintRenderer renderer = new AWTPrintRenderer(pj);
+            AWTPrintRenderer renderer = new AWTPrintRenderer();
 
             driver.enableLogging(log);
             driver.setRenderer(renderer);
@@ -194,10 +191,7 @@ public class FopPrintServlet extends HttpServlet {
                           HttpServletResponse response) throws ServletException {
         try {
             Driver driver = new Driver();
-            PrinterJob pj = PrinterJob.getPrinterJob();
-            AWTPrintRenderer renderer = new AWTPrintRenderer(pj);
-
-            pj.setCopies(1);
+            AWTPrintRenderer renderer = new AWTPrintRenderer();
 
             driver.enableLogging(log);
             driver.setRenderer(renderer);