diff options
Diffstat (limited to 'libjava/javax/swing/SwingUtilities.java')
-rw-r--r-- | libjava/javax/swing/SwingUtilities.java | 173 |
1 files changed, 153 insertions, 20 deletions
diff --git a/libjava/javax/swing/SwingUtilities.java b/libjava/javax/swing/SwingUtilities.java index feacf4fca22..8e987425fc4 100644 --- a/libjava/javax/swing/SwingUtilities.java +++ b/libjava/javax/swing/SwingUtilities.java @@ -1,5 +1,5 @@ /* SwingUtilities.java -- - Copyright (C) 2002, 2004 Free Software Foundation, Inc. + Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -42,15 +42,14 @@ import java.applet.Applet; import java.awt.Component; import java.awt.ComponentOrientation; import java.awt.Container; -import java.awt.Font; import java.awt.FontMetrics; 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; -import java.awt.Toolkit; import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.InputEvent; @@ -58,6 +57,8 @@ import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import java.lang.reflect.InvocationTargetException; +import javax.accessibility.Accessible; +import javax.accessibility.AccessibleStateSet; import javax.swing.plaf.ActionMapUIResource; import javax.swing.plaf.InputMapUIResource; @@ -67,8 +68,10 @@ import javax.swing.plaf.InputMapUIResource; * regions which need painting. * * @author Graydon Hoare (graydon@redhat.com) + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) */ -public class SwingUtilities implements SwingConstants +public class SwingUtilities + implements SwingConstants { /** * This frame should be used as parent for JWindow or JDialog @@ -129,6 +132,152 @@ public class SwingUtilities implements SwingConstants } /** + * 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; + } + + /** + * Returns the <code>Accessible</code> child of the specified component + * which appears at the supplied <code>Point</code>. If there is no + * child located at that particular pair of co-ordinates, null is returned + * instead. + * + * @param c the component whose children may be found at the specified + * point. + * @param p the point at which to look for the existence of children + * of the specified component. + * @return the <code>Accessible</code> child at the point, <code>p</code>, + * or null if there is no child at this point. + * @see javax.accessibility.AccessibleComponent#getAccessibleAt + */ + public static Accessible getAccessibleAt(Component c, Point p) + { + return c.getAccessibleContext().getAccessibleComponent().getAccessibleAt(p); + } + + /** + * <p> + * Returns the <code>Accessible</code> child of the specified component + * that has the supplied index within the parent component. The indexing + * of the children is zero-based, making the first child have an index of + * 0. + * </p> + * <p> + * Caution is advised when using this method, as its operation relies + * on the behaviour of varying implementations of an abstract method. + * For greater surety, direct use of the AWT component implementation + * of this method is advised. + * </p> + * + * @param c the component whose child should be returned. + * @param i the index of the child within the parent component. + * @return the <code>Accessible</code> child at index <code>i</code> + * in the component, <code>c</code>. + * @see javax.accessibility.AccessibleContext#getAccessibleChild + * @see java.awt.Component.AccessibleAWTComponent#getAccessibleChild + */ + public static Accessible getAccessibleChild(Component c, int i) + { + return c.getAccessibleContext().getAccessibleChild(i); + } + + /** + * <p> + * Returns the number of <code>Accessible</code> children within + * the supplied component. + * </p> + * <p> + * Caution is advised when using this method, as its operation relies + * on the behaviour of varying implementations of an abstract method. + * For greater surety, direct use of the AWT component implementation + * of this method is advised. + * </p> + * + * @param c the component whose children should be counted. + * @return the number of children belonging to the component, + * <code>c</code>. + * @see javax.accessibility.AccessibleContext#getAccessibleChildrenCount + * @see java.awt.Component.AccessibleAWTComponent#getAccessibleChildrenCount + */ + public static int getAccessibleChildrenCount(Component c) + { + return c.getAccessibleContext().getAccessibleChildrenCount(); + } + + /** + * <p> + * Returns the zero-based index of the specified component + * within its parent. If the component doesn't have a parent, + * -1 is returned. + * </p> + * <p> + * Caution is advised when using this method, as its operation relies + * on the behaviour of varying implementations of an abstract method. + * For greater surety, direct use of the AWT component implementation + * of this method is advised. + * </p> + * + * @param c the component whose parental index should be found. + * @return the index of the component within its parent, or -1 + * if the component doesn't have a parent. + * @see javax.accessibility.AccessibleContext#getAccessibleIndexInParent + * @see java.awt.Component.AccessibleAWTComponent#getAccessibleIndexInParent + */ + public static int getAccessibleIndexInParent(Component c) + { + return c.getAccessibleContext().getAccessibleIndexInParent(); + } + + /** + * <p> + * Returns a set of <code>AccessibleState</code>s, which represent + * the state of the supplied component. + * </p> + * <p> + * Caution is advised when using this method, as its operation relies + * on the behaviour of varying implementations of an abstract method. + * For greater surety, direct use of the AWT component implementation + * of this method is advised. + * </p> + * + * @param c the component whose accessible state should be retrieved. + * @return a set of <code>AccessibleState</code> objects, which represent + * the state of the supplied component. + * @see javax.accessibility.AccessibleContext#getAccessibleStateSet + * @see java.awt.Component.AccessibleAWTComponent#getAccessibleStateSet + */ + public static AccessibleStateSet getAccessibleStateSet(Component c) + { + return c.getAccessibleContext().getAccessibleStateSet(); + } + + /** * 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). @@ -144,22 +293,6 @@ public class SwingUtilities implements SwingConstants } /** - * Returns the font metrics object for a given font. The metrics can be - * used to calculate crude bounding boxes and positioning information, - * for laying out components with textual elements. - * - * @param font The font to get metrics for - * - * @return The font's metrics - * - * @see java.awt.font.GlyphMetrics - */ - public static FontMetrics getFontMetrics(Font font) - { - return Toolkit.getDefaultToolkit().getFontMetrics(font); - } - - /** * If <code>comp</code> is a RootPaneContainer, return its JRootPane. * Otherwise call <code>getAncestorOfClass(JRootPane.class, a)</code>. * |