Some time ago I added special handling for JPopupMenus to the
BasicLookAndFeel so they are autoclosed just like the JMenus. Yesterday
I checked in a patch that makes the JPopupMenu handling done in the
MenuSelectionManager framework, so this special handling is no longer
needed. This should slightly improve overall mouse processing in Swing,
since no extra check is needed for popup menus.

2006-03-18  Roman Kennke  <[EMAIL PROTECTED]>

        * javax/swing/plaf/basic/BasicLookAndFeel.java
        (PopupHelper.autoClosePopups): Removed field.
        (PopupHelper.mousePressed): Removed processing of registered
        autoclose popups.
        (registerForAutoClose): Removed unneeded method.
        (autoClosePopups): Removed unneeded method.
        (registerForAutoClose): Removed unneeded method.

/Roman

-- 
“Improvement makes straight roads, but the crooked roads, without
Improvement, are roads of Genius.” - William Blake
Index: javax/swing/plaf/basic/BasicLookAndFeel.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicLookAndFeel.java,v
retrieving revision 1.86
diff -u -r1.86 BasicLookAndFeel.java
--- javax/swing/plaf/basic/BasicLookAndFeel.java	24 Feb 2006 12:01:32 -0000	1.86
+++ javax/swing/plaf/basic/BasicLookAndFeel.java	18 Mar 2006 13:37:56 -0000
@@ -52,10 +52,7 @@
 import java.io.InputStream;
 import java.io.Serializable;
 import java.util.Enumeration;
-import java.util.Iterator;
 import java.util.ResourceBundle;
-import java.util.Set;
-import java.util.WeakHashMap;
 
 import javax.sound.sampled.AudioInputStream;
 import javax.sound.sampled.AudioSystem;
@@ -66,11 +63,9 @@
 import javax.swing.Action;
 import javax.swing.ActionMap;
 import javax.swing.BorderFactory;
-import javax.swing.JPopupMenu;
 import javax.swing.KeyStroke;
 import javax.swing.LookAndFeel;
 import javax.swing.MenuSelectionManager;
-import javax.swing.SwingUtilities;
 import javax.swing.UIDefaults;
 import javax.swing.UIManager;
 import javax.swing.border.BevelBorder;
@@ -104,11 +99,6 @@
   {
 
     /**
-     * Registered popups for autoclose.
-     */
-    private WeakHashMap autoClosePopups = new WeakHashMap();
-
-    /**
      * Receives an event from the event queue.
      *
      * @param event
@@ -137,46 +127,8 @@
         target = ((Container) target).findComponentAt(ev.getPoint());
       if (! m.isComponentPartOfCurrentMenu(target))
         m.clearSelectedPath();
-
-      // Handle other registered popup instances, like ComboBox popups.
-      autoClosePopups(ev, target);
     }
 
-    /**
-     * Registers Popup and its content to be autoclosed when a mouseclick
-     * occurs outside of the popup.
-     *
-     * @param popup the popup to be autoclosed when clicked outside
-     */
-    void registerForAutoClose(JPopupMenu popup)
-    {
-      autoClosePopups.put(popup, null);
-    }
-
-    /**
-     * Automatically closes all popups that are not 'hit' by the mouse event.
-     *
-     * @param ev the mouse event
-     * @param target the target of the mouse event
-     */
-    private void autoClosePopups(MouseEvent ev, Component target)
-    {
-      if (autoClosePopups.size() != 0)
-        {
-          Set popups = autoClosePopups.keySet();
-          Iterator i = popups.iterator();
-          while (i.hasNext())
-            {
-              JPopupMenu popup = (JPopupMenu) i.next();
-              if (!(target == popup
-                    || SwingUtilities.isDescendingFrom(target, popup)))
-                {
-                  popup.setVisible(false);
-                  i.remove();
-                }
-            }
-        }
-    }
   }
 
   /**
@@ -1648,17 +1600,4 @@
     toolkit.removeAWTEventListener(popupHelper);
     popupHelper = null;
   }
-
-  /**
-   * Registers a JPopupMenu for autoclosing when a mouseclick occurs outside
-   * of the JPopupMenu. This must be called when the popup gets opened. The
-   * popup is unregistered from autoclosing as soon as it either got closed
-   * by this helper, or when it has been garbage collected.
-   *
-   * @param popup the popup menu to autoclose
-   */
-  void registerForAutoClose(JPopupMenu popup)
-  {
-    popupHelper.registerForAutoClose(popup);
-  }
 }

Attachment: signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil

Reply via email to