The DefaultKeyboardFocusManager must notify the old focus owner when a new component receives the focus.

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

        * java/awt/DefaultKeyboardFocusManager.java
        (dispatchEvent): Notify old focus owner when it has lost
        focus.

/Roman
Index: java/awt/DefaultKeyboardFocusManager.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/DefaultKeyboardFocusManager.java,v
retrieving revision 1.20
diff -u -1 -2 -r1.20 DefaultKeyboardFocusManager.java
--- java/awt/DefaultKeyboardFocusManager.java	25 Jul 2006 22:07:35 -0000	1.20
+++ java/awt/DefaultKeyboardFocusManager.java	26 Jul 2006 11:13:09 -0000
@@ -170,28 +170,39 @@
             if (toFocus != null)
               toFocus.requestFocusInWindow();
           }
         else if (e.id != WindowEvent.WINDOW_LOST_FOCUS
                  && e.id != WindowEvent.WINDOW_DEACTIVATED)
           return false;
 
         redispatchEvent(target, e);
         return true;
       }
     else if (e instanceof FocusEvent)
       {
-        Component target = (Component) e.getSource ();
+        FocusEvent fe = (FocusEvent) e;
+        Component target = fe.getComponent ();
 
         if (e.id == FocusEvent.FOCUS_GAINED)
           {
+            // If old focus owner != new focus owner, notify old focus
+            // owner that it has lost focus.
+            Component oldFocusOwner = getGlobalFocusOwner();
+            if (oldFocusOwner != null && oldFocusOwner != target)
+              {
+                FocusEvent lost = new FocusEvent(oldFocusOwner,
+                                                 FocusEvent.FOCUS_LOST,
+                                                 fe.isTemporary(), target);
+                oldFocusOwner.dispatchEvent(lost);
+              }
             if (! (target instanceof Window))
               {
                 if (((FocusEvent) e).isTemporary ())
                   setGlobalFocusOwner (target);
                 else
                   setGlobalPermanentFocusOwner (target);
               }
 
             // Keep track of this window's focus owner.
 
             // Find the target Component's top-level ancestor.  target
             // may be a window.

Reply via email to