[Patch][gui] SwingUtilities.findFocusOwner
Michael Koch
konqueror@gmx.de
Fri Jan 21 11:25:00 GMT 2005
Hi list,
I commited the attached patch to add a new method to
javax.swing.SwingUtilities.
Michael
2005-01-21 Michael Koch <konqueror@gmx.de>
* javax/swing/SwingUtilities.java
(findFocusOwner): New method.
-------------- next part --------------
Index: javax/swing/SwingUtilities.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/SwingUtilities.java,v
retrieving revision 1.6.2.17
diff -u -r1.6.2.17 SwingUtilities.java
--- javax/swing/SwingUtilities.java 21 Nov 2004 11:25:33 -0000 1.6.2.17
+++ javax/swing/SwingUtilities.java 21 Jan 2005 11:23:47 -0000
@@ -47,6 +47,7 @@
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Insets;
+import java.awt.KeyboardFocusManager;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Shape;
@@ -129,6 +130,37 @@
}
/**
+ * Returns the focus owner or <code>null</code> if <code>comp</code> is not
+ * the focus owner or a parent of it.
+ *
+ * @param comp the focus owner or a parent of it
+ *
+ * @return the focus owner, or <code>null</code>
+ *
+ * @deprecated 1.4 Replaced by
+ * <code>KeyboardFocusManager.getFocusOwner()</code>.
+ */
+ public static Component findFocusOwner(Component comp)
+ {
+ // Get real focus owner.
+ Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager()
+ .getFocusOwner();
+
+ // Check if comp is the focus owner or a parent of it.
+ Component tmp = focusOwner;
+
+ while (tmp != null)
+ {
+ if (tmp == comp)
+ return focusOwner;
+
+ tmp = tmp.getParent();
+ }
+
+ return null;
+ }
+
+ /**
* Calculates the bounds of a component in the component's own coordinate
* space. The result has the same height and width as the component's
* bounds, but its location is set to (0,0).
More information about the Java-patches
mailing list