8047799: Remove WindowClosingSupport
authorpchelko
Thu, 26 Jun 2014 13:38:38 +0400
changeset 25554 8376663d83d7
parent 25553 1082bb71e6c5
child 25555 b70a66b5b942
8047799: Remove WindowClosingSupport Reviewed-by: anthony, alexsch
jdk/src/share/classes/java/awt/Component.java
jdk/src/share/classes/java/awt/Container.java
jdk/src/share/classes/java/awt/Dialog.java
jdk/src/share/classes/sun/awt/SunToolkit.java
jdk/src/share/classes/sun/awt/WindowClosingListener.java
jdk/src/share/classes/sun/awt/WindowClosingSupport.java
--- a/jdk/src/share/classes/java/awt/Component.java	Thu Jun 26 12:05:57 2014 +0400
+++ b/jdk/src/share/classes/java/awt/Component.java	Thu Jun 26 13:38:38 2014 +0400
@@ -67,7 +67,6 @@
 import sun.awt.ConstrainableGraphics;
 import sun.awt.SubRegionShowable;
 import sun.awt.SunToolkit;
-import sun.awt.WindowClosingListener;
 import sun.awt.CausedFocusEvent;
 import sun.awt.EmbeddedFrame;
 import sun.awt.dnd.SunDropTargetEvent;
@@ -544,8 +543,6 @@
     transient MouseWheelListener mouseWheelListener;
     transient InputMethodListener inputMethodListener;
 
-    transient RuntimeException windowClosingException = null;
-
     /** Internal, constants for serialization */
     final static String actionListenerK = "actionL";
     final static String adjustmentListenerK = "adjustmentL";
@@ -4866,16 +4863,6 @@
               }
               break;
 
-          case WindowEvent.WINDOW_CLOSING:
-              if (toolkit instanceof WindowClosingListener) {
-                  windowClosingException = ((WindowClosingListener)
-                                            toolkit).windowClosingNotify((WindowEvent)e);
-                  if (checkWindowClosingException()) {
-                      return;
-                  }
-              }
-              break;
-
           default:
               break;
         }
@@ -4931,21 +4918,6 @@
         }
 
         /*
-         * 8. Special handling for 4061116 : Hook for browser to close modal
-         *    dialogs.
-         */
-        if (id == WindowEvent.WINDOW_CLOSING && !e.isConsumed()) {
-            if (toolkit instanceof WindowClosingListener) {
-                windowClosingException =
-                    ((WindowClosingListener)toolkit).
-                    windowClosingDelivered((WindowEvent)e);
-                if (checkWindowClosingException()) {
-                    return;
-                }
-            }
-        }
-
-        /*
          * 9. Allow the peer to process the event.
          * Except KeyEvents, they will be processed by peer after
          * all KeyEventPostProcessors
@@ -5052,20 +5024,6 @@
         return false;
     }
 
-    boolean checkWindowClosingException() {
-        if (windowClosingException != null) {
-            if (this instanceof Dialog) {
-                ((Dialog)this).interruptBlocking();
-            } else {
-                windowClosingException.fillInStackTrace();
-                windowClosingException.printStackTrace();
-                windowClosingException = null;
-            }
-            return true;
-        }
-        return false;
-    }
-
     boolean areInputMethodsEnabled() {
         // in 1.2, we assume input method support is required for all
         // components that handle key events, but components can turn off
--- a/jdk/src/share/classes/java/awt/Container.java	Thu Jun 26 12:05:57 2014 +0400
+++ b/jdk/src/share/classes/java/awt/Container.java	Thu Jun 26 13:38:38 2014 +0400
@@ -2899,17 +2899,10 @@
             }
         }
 
-        Runnable pumpEventsForHierarchy = new Runnable() {
-            public void run() {
-                EventDispatchThread dispatchThread =
-                    (EventDispatchThread)Thread.currentThread();
-                dispatchThread.pumpEventsForHierarchy(
-                        new Conditional() {
-                        public boolean evaluate() {
-                        return ((windowClosingException == null) && (nativeContainer.modalComp != null)) ;
-                        }
-                        }, Container.this);
-            }
+        Runnable pumpEventsForHierarchy = () -> {
+            EventDispatchThread dispatchThread = (EventDispatchThread)Thread.currentThread();
+            dispatchThread.pumpEventsForHierarchy(() -> nativeContainer.modalComp != null,
+                    Container.this);
         };
 
         if (EventQueue.isDispatchThread()) {
@@ -2927,8 +2920,7 @@
                     postEvent(new PeerEvent(this,
                                 pumpEventsForHierarchy,
                                 PeerEvent.PRIORITY_EVENT));
-                while ((windowClosingException == null) &&
-                       (nativeContainer.modalComp != null))
+                while (nativeContainer.modalComp != null)
                 {
                     try {
                         getTreeLock().wait();
@@ -2938,10 +2930,6 @@
                 }
             }
         }
-        if (windowClosingException != null) {
-            windowClosingException.fillInStackTrace();
-            throw windowClosingException;
-        }
         if (predictedFocusOwner != null) {
             KeyboardFocusManager.getCurrentKeyboardFocusManager().
                 dequeueKeyEvents(time, predictedFocusOwner);
--- a/jdk/src/share/classes/java/awt/Dialog.java	Thu Jun 26 12:05:57 2014 +0400
+++ b/jdk/src/share/classes/java/awt/Dialog.java	Thu Jun 26 13:38:38 2014 +0400
@@ -40,6 +40,7 @@
 import sun.awt.util.IdentityArrayList;
 import sun.awt.util.IdentityLinkedList;
 import java.security.AccessControlException;
+import java.util.function.BooleanSupplier;
 
 /**
  * A Dialog is a top-level window with a title and a border
@@ -1044,13 +1045,6 @@
                 predictedFocusOwner = getMostRecentFocusOwner();
                 if (conditionalShow(predictedFocusOwner, time)) {
                     modalFilter = ModalEventFilter.createFilterForDialog(this);
-                    final Conditional cond = new Conditional() {
-                        @Override
-                        public boolean evaluate() {
-                            return windowClosingException == null;
-                        }
-                    };
-
                     // if this dialog is toolkit-modal, the filter should be added
                     // to all EDTs (for all AppContexts)
                     if (modalityType == ModalityType.TOOLKIT_MODAL) {
@@ -1063,10 +1057,7 @@
                             EventQueue eventQueue = (EventQueue)appContext.get(AppContext.EVENT_QUEUE_KEY);
                             // it may occur that EDT for appContext hasn't been started yet, so
                             // we post an empty invocation event to trigger EDT initialization
-                            Runnable createEDT = new Runnable() {
-                                public void run() {};
-                            };
-                            eventQueue.postEvent(new InvocationEvent(this, createEDT));
+                            eventQueue.postEvent(new InvocationEvent(this, () -> {}));
                             EventDispatchThread edt = eventQueue.getDispatchThread();
                             edt.addEventFilter(modalFilter);
                         }
@@ -1075,12 +1066,8 @@
                     modalityPushed();
                     try {
                         final EventQueue eventQueue = AccessController.doPrivileged(
-                            new PrivilegedAction<EventQueue>() {
-                                public EventQueue run() {
-                                    return Toolkit.getDefaultToolkit().getSystemEventQueue();
-                                }
-                        });
-                        secondaryLoop = eventQueue.createSecondaryLoop(cond, modalFilter, 0);
+                                (PrivilegedAction<EventQueue>) Toolkit.getDefaultToolkit()::getSystemEventQueue);
+                        secondaryLoop = eventQueue.createSecondaryLoop(() -> true, modalFilter, 0);
                         if (!secondaryLoop.enter()) {
                             secondaryLoop = null;
                         }
@@ -1102,11 +1089,6 @@
                             edt.removeEventFilter(modalFilter);
                         }
                     }
-
-                    if (windowClosingException != null) {
-                        windowClosingException.fillInStackTrace();
-                        throw windowClosingException;
-                    }
                 }
             } finally {
                 if (predictedFocusOwner != null) {
@@ -1134,16 +1116,6 @@
         }
     }
 
-    void interruptBlocking() {
-        if (isModal()) {
-            disposeImpl();
-        } else if (windowClosingException != null) {
-            windowClosingException.fillInStackTrace();
-            windowClosingException.printStackTrace();
-            windowClosingException = null;
-        }
-    }
-
     private void hideAndDisposePreHandler() {
         isInHide = true;
         synchronized (getTreeLock()) {
--- a/jdk/src/share/classes/sun/awt/SunToolkit.java	Thu Jun 26 12:05:57 2014 +0400
+++ b/jdk/src/share/classes/sun/awt/SunToolkit.java	Thu Jun 26 13:38:38 2014 +0400
@@ -59,8 +59,7 @@
 import java.security.AccessController;
 
 public abstract class SunToolkit extends Toolkit
-    implements WindowClosingSupport, WindowClosingListener,
-    ComponentFactory, InputMethodSupport, KeyboardFocusManagerPeerProvider {
+    implements ComponentFactory, InputMethodSupport, KeyboardFocusManagerPeerProvider {
 
     // 8014718: logging has been removed from SunToolkit
 
@@ -1201,42 +1200,6 @@
         return getStartupLocale();
     }
 
-    // Support for window closing event notifications
-    private transient WindowClosingListener windowClosingListener = null;
-    /**
-     * @see sun.awt.WindowClosingSupport#getWindowClosingListener
-     */
-    public WindowClosingListener getWindowClosingListener() {
-        return windowClosingListener;
-    }
-    /**
-     * @see sun.awt.WindowClosingSupport#setWindowClosingListener
-     */
-    public void setWindowClosingListener(WindowClosingListener wcl) {
-        windowClosingListener = wcl;
-    }
-
-    /**
-     * @see sun.awt.WindowClosingListener#windowClosingNotify
-     */
-    public RuntimeException windowClosingNotify(WindowEvent event) {
-        if (windowClosingListener != null) {
-            return windowClosingListener.windowClosingNotify(event);
-        } else {
-            return null;
-        }
-    }
-    /**
-     * @see sun.awt.WindowClosingListener#windowClosingDelivered
-     */
-    public RuntimeException windowClosingDelivered(WindowEvent event) {
-        if (windowClosingListener != null) {
-            return windowClosingListener.windowClosingDelivered(event);
-        } else {
-            return null;
-        }
-    }
-
     private static DefaultMouseInfoPeer mPeer = null;
 
     protected synchronized MouseInfoPeer getMouseInfoPeer() {
--- a/jdk/src/share/classes/sun/awt/WindowClosingListener.java	Thu Jun 26 12:05:57 2014 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,53 +0,0 @@
-/*
- * Copyright (c) 1999, 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.awt;
-
-import java.awt.event.WindowEvent;
-
-/**
- * Interface for listening to WINDOW_CLOSING events before and
- * after they are posted to the queue.
- */
-public interface WindowClosingListener {
-    /**
-     * Called before a WINDOW_CLOSING event gets posted to the queue.
-     * @param event The WINDOW_CLOSING event that will be posted.
-     * @return A RuntimeException if the result of this function
-     * call needs to interrupt a blocking thread.  The exception
-     * returned will be thrown from that thread.  This function
-     * should return null otherwise.
-     */
-    RuntimeException windowClosingNotify(WindowEvent event);
-    /**
-     * Called after a WINDOW_CLOSING event gets posted to the queue.
-     * @param event The WINDOW_CLOSING event that has been posted.
-     * @return A RuntimeException if the result of this function
-     * call needs to interrupt a blocking thread.  The exception
-     * returned will be thrown from that thread.  This function
-     * should return null otherwise.
-     */
-    RuntimeException windowClosingDelivered(WindowEvent event);
-}
--- a/jdk/src/share/classes/sun/awt/WindowClosingSupport.java	Thu Jun 26 12:05:57 2014 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,35 +0,0 @@
-/*
- * Copyright (c) 1999, 2007, 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.awt;
-
-/**
- * Interface for identifying and casting toolkits that support
- * WindowClosingListeners.
- */
-public interface WindowClosingSupport {
-    WindowClosingListener getWindowClosingListener();
-    void setWindowClosingListener(WindowClosingListener wcl);
-}