classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] [patch] prevent bogus casts in DefaultKeyboardFocusManager.


From: Thomas Fitzsimmons
Subject: [cp-patches] [patch] prevent bogus casts in DefaultKeyboardFocusManager.dispatchEvent
Date: Tue, 05 Jul 2005 15:16:49 -0400

Hi,

This patch adds the check Jeroen and I discussed in this thread:

http://lists.gnu.org/archive/html/classpath-patches/2005-06/msg00363.html

It should prevent bogus casts to Window during KeyEvent dispatch.  I
committed this to mainline.

Tom

2005-07-05  Thomas Fitzsimmons  <address@hidden>

        * java/awt/DefaultKeyboardFocusManager.java (dispatchEvent): Check
        parent and target before casting target to Window.

Index: java/awt/DefaultKeyboardFocusManager.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/java/awt/DefaultKeyboardFocusManager.java,v
retrieving revision 1.14
diff -u -r1.14 DefaultKeyboardFocusManager.java
--- java/awt/DefaultKeyboardFocusManager.java   2 Jul 2005 20:32:24 -0000       
1.14
+++ java/awt/DefaultKeyboardFocusManager.java   5 Jul 2005 19:10:53 -0000
@@ -187,20 +187,26 @@
 
             // Keep track of this window's focus owner.
 
-            // Find the target Component's top-level ancestor.
+            // Find the target Component's top-level ancestor.  target
+            // may be a window.
             Container parent = target.getParent ();
 
             while (parent != null
                    && !(parent instanceof Window))
               parent = parent.getParent ();
 
-            Window toplevel = parent == null ?
-              (Window) target : (Window) parent;
+            // If the parent is null and target is not a window, then target 
is an
+            // unanchored component and so we don't want to set the focus 
owner.
+            if (! (parent == null && ! (target instanceof Window)))
+              {
+                Window toplevel = parent == null ?
+                  (Window) target : (Window) parent;
 
-            Component focusOwner = getFocusOwner ();
-            if (focusOwner != null
-                && ! (focusOwner instanceof Window))
-              toplevel.setFocusOwner (focusOwner);
+                Component focusOwner = getFocusOwner ();
+                if (focusOwner != null
+                    && ! (focusOwner instanceof Window))
+                  toplevel.setFocusOwner (focusOwner);
+              }
           }
         else if (e.id == FocusEvent.FOCUS_LOST)
           {

reply via email to

[Prev in Thread] Current Thread [Next in Thread]