--- old/src/macosx/classes/sun/lwawt/macosx/CPrinterJob.java 2013-01-24 20:09:25.000000000 +0400 +++ new/src/macosx/classes/sun/lwawt/macosx/CPrinterJob.java 2013-01-24 20:09:25.000000000 +0400 @@ -47,6 +47,10 @@ private static String sShouldNotReachHere = "Should not reach here."; + private final SecondaryLoop printingLoop = Toolkit.getDefaultToolkit() + .getSystemEventQueue() + .createSecondaryLoop(); + private boolean noDefaultPrinter = false; private static Font defaultFont; @@ -160,11 +164,24 @@ 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) { @@ -223,13 +240,8 @@ // 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(); @@ -251,6 +263,7 @@ // NOTE: Native code shouldn't allow exceptions out while // printing. They should cancel the print loop. performingPrinting = false; + printingLoop.exit(); notify(); } }