Experimenting shows that we need to dispatch MOUSE_ENTERED events even when the mouse is dragging. I fixed this in the LightweightDispatcher.

There's been a comment in LightweightDispatcher why this has been disabled before. However, this was not quite right. The problem was that when you press a button and then drag to another button, this other button would become 'rollover'ed. Looking at the BasicButtonListener this should not happen because there the rollover state is only set when the mouse button #1 is not pressed (== no dragging). It seems that the SwingUtilities.isLeftMouseButton() method was the real reason for the misbehaviour. I also fixed this and now Foxhunt works and mouse dragging over buttons too :-)

2006-07-24  Roman Kennke  <[EMAIL PROTECTED]>

        * javax/swing/SwingUtilities.java
        (isLeftMouseButton): Fixed condition.
        * java/awt/LightweightDispatcher.java
        (handleMouseEvent): Dispatch MOUSE_ENTERED even when mouse
        is dragged.

/Roman
Index: java/awt/LightweightDispatcher.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/LightweightDispatcher.java,v
retrieving revision 1.12
diff -u -1 -2 -r1.12 LightweightDispatcher.java
--- java/awt/LightweightDispatcher.java	21 Jul 2006 17:27:23 -0000	1.12
+++ java/awt/LightweightDispatcher.java	24 Jul 2006 12:42:24 -0000
@@ -169,42 +169,45 @@
         // Dispatch additional MOUSE_EXITED and MOUSE_ENTERED if event target
         // is different from the last event target.
         if (target != lastTarget)
           {
             if (lastTarget != null)
               {
                 Point p1 = convertPointToChild(window, ev.getPoint(),
                                                lastTarget);
                 MouseEvent mouseExited =
                   new MouseEvent(lastTarget, MouseEvent.MOUSE_EXITED,
                                  ev.getWhen(), ev.getModifiers(), p1.x, p1.y,
                                  ev.getClickCount(), ev.isPopupTrigger());
+                //System.err.println("event: " + mouseExited);
                 lastTarget.dispatchEvent(mouseExited);
               }
             
             // If a target exists dispatch the MOUSE_ENTERED event only if
             // there is currently no component from which a drag operation
             // started (dragTarget == null) or the target is that component
             // (dragTarget == target)
             // That way a user can click and hold on a button (putting it into
             // the armed state), move the cursor above other buttons without
             // affecting their rollover state and get back to the initial
             // button.
-            if (target != null && (dragTarget == null || dragTarget == target))
+            if (target != null)
               {
                 Point p = convertPointToChild(window, ev.getPoint(), target);
                 MouseEvent mouseEntered =
-                  new MouseEvent(target, MouseEvent.MOUSE_ENTERED, ev.getWhen(),
+                  new MouseEvent(target,
+                                 MouseEvent.MOUSE_ENTERED, ev.getWhen(),
                                  ev.getModifiers(), p.x, p.y, ev.getClickCount(),
                                  ev.isPopupTrigger());
+                //System.err.println("event: " + mouseEntered);
                 target.dispatchEvent(mouseEntered);
               }
           }
         
         switch (ev.getID())
         {
           case MouseEvent.MOUSE_PRESSED:
             // Handle the start of a drag operation or discard the event if
             // one is already in progress. This prevents focus changes with the
             // other mouse buttons when one is used for dragging.
             if (dragTarget == null)
               {
Index: javax/swing/SwingUtilities.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/SwingUtilities.java,v
retrieving revision 1.54
diff -u -1 -2 -r1.54 SwingUtilities.java
--- javax/swing/SwingUtilities.java	14 Jun 2006 11:01:25 -0000	1.54
+++ javax/swing/SwingUtilities.java	24 Jul 2006 12:42:24 -0000
@@ -1036,26 +1036,25 @@
     return result;
   }
 
   /**
    * Checks if left mouse button was clicked.
    *
    * @param event the event to check
    *
    * @return true if left mouse was clicked, false otherwise.
    */
   public static boolean isLeftMouseButton(MouseEvent event)
   {
-    return ((event.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK)
-	     == InputEvent.BUTTON1_DOWN_MASK);
+    return ((event.getModifiers() & InputEvent.BUTTON1_MASK) != 0);
   }
 
   /**
    * Checks if middle mouse button was clicked.
    *
    * @param event the event to check
    *
    * @return true if middle mouse was clicked, false otherwise.
    */
   public static boolean isMiddleMouseButton(MouseEvent event)
   {
     return ((event.getModifiersEx() & InputEvent.BUTTON2_DOWN_MASK)

Reply via email to