From 959ddfce4a7840aa855d6351961badff298a2c29 Mon Sep 17 00:00:00 2001 From: Petr Pchelko Date: Wed, 13 Feb 2013 15:32:50 +0000 Subject: [PATCH] 8005629: javac warnings compiling java.awt.EventDispatchThread and sun.awt.X11.XIconWindow Removed macosx specific workaround from shared code and made macosx use public API Reviewed-by: art, serb --- .../classes/sun/lwawt/macosx/CPrinterJob.java | 36 +++++++++++++---- .../sun/lwawt/macosx/EventDispatchAccess.java | 39 ------------------- jdk/src/macosx/native/sun/awt/CPrinterJob.m | 25 ------------ .../classes/java/awt/EventDispatchThread.java | 28 ------------- .../classes/sun/awt/X11/XIconWindow.java | 2 +- 5 files changed, 30 insertions(+), 100 deletions(-) delete mode 100644 jdk/src/macosx/classes/sun/lwawt/macosx/EventDispatchAccess.java diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CPrinterJob.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CPrinterJob.java index 56f5ac7ecc6..791182c1565 100644 --- a/jdk/src/macosx/classes/sun/lwawt/macosx/CPrinterJob.java +++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CPrinterJob.java @@ -30,6 +30,8 @@ import java.awt.*; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import java.awt.print.*; +import java.security.AccessController; +import java.security.PrivilegedAction; import javax.print.*; import javax.print.attribute.PrintRequestAttributeSet; @@ -47,6 +49,8 @@ public class CPrinterJob extends RasterPrinterJob { private static String sShouldNotReachHere = "Should not reach here."; + private volatile SecondaryLoop printingLoop; + private boolean noDefaultPrinter = false; private static Font defaultFont; @@ -160,11 +164,22 @@ public class CPrinterJob extends RasterPrinterJob { volatile boolean onEventThread; + @Override + protected void cancelDoc() throws PrinterAbortException { + super.cancelDoc(); + if (printingLoop != null) { + printingLoop.exit(); + } + } + private void completePrintLoop() { Runnable r = new Runnable() { public void run() { synchronized(this) { performingPrinting = false; } + if (printingLoop != null) { + printingLoop.exit(); + } }}; if (onEventThread) { @@ -219,17 +234,21 @@ public class CPrinterJob extends RasterPrinterJob { onEventThread = true; + printingLoop = AccessController.doPrivileged(new PrivilegedAction() { + @Override + public SecondaryLoop run() { + return Toolkit.getDefaultToolkit() + .getSystemEventQueue() + .createSecondaryLoop(); + } + }); + 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(); @@ -253,6 +272,9 @@ public class CPrinterJob extends RasterPrinterJob { performingPrinting = false; notify(); } + if (printingLoop != null) { + printingLoop.exit(); + } } // Normalize the collated, # copies, numPages, first/last pages. Need to diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/EventDispatchAccess.java b/jdk/src/macosx/classes/sun/lwawt/macosx/EventDispatchAccess.java deleted file mode 100644 index 1124d123757..00000000000 --- a/jdk/src/macosx/classes/sun/lwawt/macosx/EventDispatchAccess.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package sun.lwawt.macosx; - -// This exists strictly to work around the fact that java.awt.Conditional isn't a public class. -// It uses java reflection to get the EventDispatchThread class and call a MacOSX only -// method on it. -// -// NOTE: This uses reflection in its implementation, so it is not for performance critical code. -// -// See java.awt.EventDispatchThread and apple.awt.CPrintJob for more. -// -public abstract class EventDispatchAccess { - public native void pumpEventsAndWait(); - public abstract boolean evaluate(); -} diff --git a/jdk/src/macosx/native/sun/awt/CPrinterJob.m b/jdk/src/macosx/native/sun/awt/CPrinterJob.m index 52976f31d26..3935240ff78 100644 --- a/jdk/src/macosx/native/sun/awt/CPrinterJob.m +++ b/jdk/src/macosx/native/sun/awt/CPrinterJob.m @@ -383,31 +383,6 @@ static void javaPrinterJobToNSPrintInfo(JNIEnv* env, jobject srcPrinterJob, jobj } } -/* - * Class: sun_lwawt_macosx_EventDispatchAccess - * Method: pumpEventsAndWait - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_sun_lwawt_macosx_EventDispatchAccess_pumpEventsAndWait -(JNIEnv *env, jobject eda) -{ - static JNF_CLASS_CACHE(jc_Thread, "java/lang/Thread"); - static JNF_STATIC_MEMBER_CACHE(jm_currentThread, jc_Thread, "currentThread", "()Ljava/lang/Thread;"); - static JNF_CLASS_CACHE(jc_EventDispatchThread, "java/awt/EventDispatchThread"); - static JNF_MEMBER_CACHE(jm_macosxGetConditional, jc_EventDispatchThread, "_macosxGetConditional", "(Ljava/lang/Object;)Ljava/awt/Conditional;"); - static JNF_MEMBER_CACHE(jm_pumpEvents, jc_EventDispatchThread, "pumpEvents", "(Ljava/awt/Conditional;)V"); - -JNF_COCOA_DURING(env); - - jobject thread = JNFCallStaticObjectMethod(env, jm_currentThread); - jobject conditional = JNFCallObjectMethod(env, thread, jm_macosxGetConditional, eda); - if (conditional != NULL) { - JNFCallVoidMethod(env, thread, jm_pumpEvents, conditional); - } - -JNF_COCOA_HANDLE(env); -} - /* * Class: sun_lwawt_macosx_CPrinterJob * Method: abortDoc diff --git a/jdk/src/share/classes/java/awt/EventDispatchThread.java b/jdk/src/share/classes/java/awt/EventDispatchThread.java index 427ad7efeb7..c707f02abdb 100644 --- a/jdk/src/share/classes/java/awt/EventDispatchThread.java +++ b/jdk/src/share/classes/java/awt/EventDispatchThread.java @@ -107,34 +107,6 @@ class EventDispatchThread extends Thread { } } - // MacOSX change: - // This was added because this class (and java.awt.Conditional) are package private. - // There are certain instances where classes in other packages need to block the - // AWTEventQueue while still allowing it to process events. This uses reflection - // to call back into the caller in order to remove dependencies. - // - // NOTE: This uses reflection in its implementation, so it is not for performance critical code. - // - // cond is an instance of sun.lwawt.macosx.EventDispatchAccess - // - private Conditional _macosxGetConditional(final Object cond) { - try { - return new Conditional() { - final Method evaluateMethod = Class.forName("sun.lwawt.macosx.EventDispatchAccess").getMethod("evaluate", null); - public boolean evaluate() { - try { - return ((Boolean)evaluateMethod.invoke(cond, null)).booleanValue(); - } catch (Exception e) { - return false; - } - } - }; - } catch (Exception e) { - return new Conditional() { public boolean evaluate() { return false; } }; - } - } - - void pumpEvents(Conditional cond) { pumpEvents(ANY_EVENT, cond); } diff --git a/jdk/src/solaris/classes/sun/awt/X11/XIconWindow.java b/jdk/src/solaris/classes/sun/awt/X11/XIconWindow.java index 1d0e55d31ef..bf521db3b72 100644 --- a/jdk/src/solaris/classes/sun/awt/X11/XIconWindow.java +++ b/jdk/src/solaris/classes/sun/awt/X11/XIconWindow.java @@ -92,7 +92,7 @@ public class XIconWindow extends XBaseWindow { } XIconSize[] sizeList = getIconSizes(); - log.finest("Icon sizes: {0}", sizeList); + log.finest("Icon sizes: {0}", (Object[]) sizeList); if (sizeList == null) { // No icon sizes so we simply fall back to 16x16 return new Dimension(16, 16);