Hi Francis,

> After talking to rkennke, here is an alternate implementation to fix the
> same bug, which does not involve removing and re-adding listeners, nor
> consuming the mouseclick event (since this breaks other functionality).

What I meant was something along the line of the attached patch. This
has the advantage that we can also flag other components that shouldn't
close the popup (I'm thinking of the editor of a ComboBox editor for
example).

This also reverts my previous fix for this, which was obviously wrong.

2006-06-13  Roman Kennke  <[EMAIL PROTECTED]>

        * java/awt/Component.java
        (dispatchEvent): Handle events even when consumed (this might be
        picked up later in the dispatching chain).
        * javax/swing/plaf/basic/BasicLookAndFeel.java
        (PopupHelper.mousePressed): Don't consume event. Only close
popup
        when target component isn't flagged as DONT_CANCEL_POPUP.
        (DONT_CANCEL_POPUP): New package private constant for flagging
        special components that don't trigger popup closing.
        * javax/swing/plaf/basic/BasicArrowButton.java
        (BasicArrowButton): Set client property for not triggering
closing
        of popups.

/Roman

Index: java/awt/Component.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/Component.java,v
retrieving revision 1.121
diff -u -r1.121 Component.java
--- java/awt/Component.java	13 Jun 2006 12:37:54 -0000	1.121
+++ java/awt/Component.java	13 Jun 2006 19:36:42 -0000
@@ -2314,8 +2314,7 @@
 
     // Some subclasses in the AWT package need to override this behavior,
     // hence the use of dispatchEventImpl().
-    if (! e.isConsumed())
-      dispatchEventImpl(e);
+    dispatchEventImpl(e);
   }
 
   /**
Index: javax/swing/plaf/basic/BasicLookAndFeel.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicLookAndFeel.java,v
retrieving revision 1.94
diff -u -r1.94 BasicLookAndFeel.java
--- javax/swing/plaf/basic/BasicLookAndFeel.java	13 Jun 2006 12:37:53 -0000	1.94
+++ javax/swing/plaf/basic/BasicLookAndFeel.java	13 Jun 2006 19:36:42 -0000
@@ -132,7 +132,6 @@
           && ! m.isComponentPartOfCurrentMenu(target))
         {
           m.clearSelectedPath();
-          ev.consume();
         }
     }
 
@@ -199,6 +198,14 @@
   static final long serialVersionUID = -6096995660290287879L;
 
   /**
+   * This is a key for a client property that tells the PopupHelper that
+   * it shouldn't close popups when the mouse event target has this
+   * property set. This is used when the component handles popup closing
+   * itself.
+   */
+  static final String DONT_CANCEL_POPUP = "noCancelPopup";
+
+  /**
    * Helps closing menu popups when user clicks outside of the menu area.
    */
   private transient PopupHelper popupHelper;
Index: javax/swing/plaf/basic/BasicArrowButton.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicArrowButton.java,v
retrieving revision 1.17
diff -u -r1.17 BasicArrowButton.java
--- javax/swing/plaf/basic/BasicArrowButton.java	24 Nov 2005 18:19:18 -0000	1.17
+++ javax/swing/plaf/basic/BasicArrowButton.java	13 Jun 2006 19:36:42 -0000
@@ -116,6 +116,8 @@
     this.shadow = shadow;
     this.darkShadow = darkShadow;
     this.highlight = highlight;
+    // Mark the button as not closing the popup, we handle this ourselves.
+    putClientProperty(BasicLookAndFeel.DONT_CANCEL_POPUP, Boolean.TRUE);
   }
 
   /**

Reply via email to