changeset 9009:dc8ba0a4d669

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
author pchelko
date Wed, 19 Oct 2016 05:21:41 +0100
parents fb281fa4e44c
children afd05eb46a5c
files src/macosx/classes/sun/lwawt/macosx/CPrinterJob.java src/macosx/classes/sun/lwawt/macosx/EventDispatchAccess.java src/macosx/native/sun/awt/CPrinterJob.m src/share/classes/java/awt/EventDispatchThread.java src/solaris/classes/sun/awt/X11/XIconWindow.java
diffstat 5 files changed, 31 insertions(+), 101 deletions(-) [+]
line wrap: on
line diff
--- a/src/macosx/classes/sun/lwawt/macosx/CPrinterJob.java	Wed Oct 19 04:33:16 2016 +0100
+++ b/src/macosx/classes/sun/lwawt/macosx/CPrinterJob.java	Wed Oct 19 05:21:41 2016 +0100
@@ -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;
@@ -48,6 +50,8 @@
 
     private static String sShouldNotReachHere = "Should not reach here.";
 
+    private volatile SecondaryLoop printingLoop;
+
     private boolean noDefaultPrinter = false;
 
     private static Font defaultFont;
@@ -176,11 +180,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) {
@@ -249,22 +264,26 @@
 
                     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();
                     }
-                } else {
+              } else {
                     // Fire off the print rendering loop on the AppKit, and block this thread
                     //  until it is done.
                     // But don't actually block... we need to come back here!
@@ -288,6 +307,9 @@
                 performingPrinting = false;
                 notify();
             }
+            if (printingLoop != null) {
+                printingLoop.exit();
+            }
         }
 
         // Normalize the collated, # copies, numPages, first/last pages. Need to
--- a/src/macosx/classes/sun/lwawt/macosx/EventDispatchAccess.java	Wed Oct 19 04:33:16 2016 +0100
+++ /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/src/macosx/native/sun/awt/CPrinterJob.m	Wed Oct 19 04:33:16 2016 +0100
+++ b/src/macosx/native/sun/awt/CPrinterJob.m	Wed Oct 19 05:21:41 2016 +0100
@@ -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/src/share/classes/java/awt/EventDispatchThread.java	Wed Oct 19 04:33:16 2016 +0100
+++ b/src/share/classes/java/awt/EventDispatchThread.java	Wed Oct 19 05:21:41 2016 +0100
@@ -106,34 +106,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/src/solaris/classes/sun/awt/X11/XIconWindow.java	Wed Oct 19 04:33:16 2016 +0100
+++ b/src/solaris/classes/sun/awt/X11/XIconWindow.java	Wed Oct 19 05:21:41 2016 +0100
@@ -93,7 +93,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);