8005629: javac warnings compiling java.awt.EventDispatchThread and sun.awt.X11.XIconWindow
authorpchelko
Wed, 13 Feb 2013 15:32:50 +0000
changeset 15639 0ff6be5c9730
parent 15638 014faa554d7a
child 15640 20892a2bbcbc
8005629: javac warnings compiling java.awt.EventDispatchThread and sun.awt.X11.XIconWindow Summary: Removed macosx specific workaround from shared code and made macosx use public API Reviewed-by: art, serb
jdk/src/macosx/classes/sun/lwawt/macosx/CPrinterJob.java
jdk/src/macosx/classes/sun/lwawt/macosx/EventDispatchAccess.java
jdk/src/macosx/native/sun/awt/CPrinterJob.m
jdk/src/share/classes/java/awt/EventDispatchThread.java
jdk/src/solaris/classes/sun/awt/X11/XIconWindow.java
--- a/jdk/src/macosx/classes/sun/lwawt/macosx/CPrinterJob.java	Wed Feb 13 15:27:29 2013 +0000
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CPrinterJob.java	Wed Feb 13 15:32:50 2013 +0000
@@ -30,6 +30,8 @@
 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 @@
 
     private static String sShouldNotReachHere = "Should not reach here.";
 
+    private volatile SecondaryLoop printingLoop;
+
     private boolean noDefaultPrinter = false;
 
     private static Font defaultFont;
@@ -160,11 +164,22 @@
 
     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 @@
 
                 onEventThread = true;
 
+                printingLoop = AccessController.doPrivileged(new PrivilegedAction<SecondaryLoop>() {
+                    @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 @@
                 performingPrinting = false;
                 notify();
             }
+            if (printingLoop != null) {
+                printingLoop.exit();
+            }
         }
 
         // Normalize the collated, # copies, numPages, first/last pages. Need to
--- a/jdk/src/macosx/classes/sun/lwawt/macosx/EventDispatchAccess.java	Wed Feb 13 15:27:29 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -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();
-}
--- a/jdk/src/macosx/native/sun/awt/CPrinterJob.m	Wed Feb 13 15:27:29 2013 +0000
+++ b/jdk/src/macosx/native/sun/awt/CPrinterJob.m	Wed Feb 13 15:32:50 2013 +0000
@@ -384,31 +384,6 @@
 }
 
 /*
- * 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
  * Signature: ()V
--- a/jdk/src/share/classes/java/awt/EventDispatchThread.java	Wed Feb 13 15:27:29 2013 +0000
+++ b/jdk/src/share/classes/java/awt/EventDispatchThread.java	Wed Feb 13 15:32:50 2013 +0000
@@ -107,34 +107,6 @@
         }
     }
 
-    // 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);
     }
--- a/jdk/src/solaris/classes/sun/awt/X11/XIconWindow.java	Wed Feb 13 15:27:29 2013 +0000
+++ b/jdk/src/solaris/classes/sun/awt/X11/XIconWindow.java	Wed Feb 13 15:32:50 2013 +0000
@@ -92,7 +92,7 @@
         }
 
         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);