src/macosx/classes/sun/lwawt/macosx/CPrinterJob.java

Print this page

        

@@ -45,10 +45,14 @@
     // are handled by the native printing. RasterPrinterJob is kept for
     // future compatibility and the state keeping that it handles.
 
     private static String sShouldNotReachHere = "Should not reach here.";
 
+    private final SecondaryLoop printingLoop = Toolkit.getDefaultToolkit()
+                                                      .getSystemEventQueue()
+                                                      .createSecondaryLoop();
+
     private boolean noDefaultPrinter = false;
 
     private static Font defaultFont;
 
     // This is the NSPrintInfo for this PrinterJob. Protect multi thread

@@ -158,15 +162,28 @@
         }
     }
 
     volatile boolean onEventThread;
 
+    @Override
+    public void cancel() {
+        super.cancel();
+        printingLoop.exit();
+    }
+
+    @Override
+    protected void cancelDoc() throws PrinterAbortException {
+        super.cancelDoc();
+        printingLoop.exit();
+    }
+
     private void completePrintLoop() {
         Runnable r = new Runnable() { public void run() {
             synchronized(this) {
                 performingPrinting = false;
             }
+            printingLoop.exit();
         }};
 
         if (onEventThread) {
             try { EventQueue.invokeAndWait(r); } catch (Exception e) { e.printStackTrace(); }
         } else {

@@ -221,17 +238,12 @@
 
                 try {
                     // Fire off the print rendering loop on the AppKit thread, and don't have
                     //  it wait and block this thread.
                     if (printLoop(false, firstPage, lastPage)) {
-                        // Fire off the EventConditional that will what until the condition is met,
-                        //  but will still process AWTEvent's as they occur.
-                        new EventDispatchAccess() {
-                            public boolean evaluate() {
-                                return performingPrinting;
-                            }
-                        }.pumpEventsAndWait();
+                        // Start a secondary loop on EDT until printing operation is finished or cancelled
+                        printingLoop.enter();
                     }
                 } catch (Exception e) {
                     e.printStackTrace();
                 }
             } else {

@@ -249,10 +261,11 @@
         } finally {
             synchronized (this) {
                 // NOTE: Native code shouldn't allow exceptions out while
                 // printing. They should cancel the print loop.
                 performingPrinting = false;
+                printingLoop.exit();
                 notify();
             }
         }
 
         // Normalize the collated, # copies, numPages, first/last pages. Need to