⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 swingutilities.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/* SwingUtilities.java --   Copyright (C) 2002, 2004, 2005  Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. */package javax.swing;import java.applet.Applet;import java.awt.Component;import java.awt.ComponentOrientation;import java.awt.Container;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.Window;import java.awt.event.ActionEvent;import java.awt.event.InputEvent;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;/** * A number of static utility functions which are * useful when drawing swing components, dispatching events, or calculating * regions which need painting. * * @author Graydon Hoare (graydon@redhat.com) * @author Andrew John Hughes (gnu_andrew@member.fsf.org) */public class SwingUtilities  implements SwingConstants{  /**    * This frame should be used as parent for JWindow or JDialog    * that doesn't an owner   */  private static OwnerFrame ownerFrame;  private SwingUtilities()  {    // Do nothing.  }    /**   * Calculates the portion of the base rectangle which is inside the   * insets.   *   * @param base The rectangle to apply the insets to   * @param insets The insets to apply to the base rectangle   * @param ret A rectangle to use for storing the return value, or   * <code>null</code>   *   * @return The calculated area inside the base rectangle and its insets,   * either stored in ret or a new Rectangle if ret is <code>null</code>   *   * @see #calculateInnerArea   */  public static Rectangle calculateInsetArea(Rectangle base, Insets insets,                                             Rectangle ret)  {    if (ret == null)      ret = new Rectangle();    ret.setBounds(base.x + insets.left, base.y + insets.top,                  base.width - (insets.left + insets.right),                  base.height - (insets.top + insets.bottom));    return ret;  }  /**   * Calculates the portion of the component's bounds which is inside the   * component's border insets. This area is usually the area a component   * should confine its painting to. The coordinates are returned in terms   * of the <em>component's</em> coordinate system, where (0,0) is the   * upper left corner of the component's bounds.   *   * @param c The component to measure the bounds of   * @param r A Rectangle to store the return value in, or   * <code>null</code>   *   * @return The calculated area inside the component and its border   * insets   *   * @see #calculateInsetArea   */  public static Rectangle calculateInnerArea(JComponent c, Rectangle r)  {    Rectangle b = getLocalBounds(c);    return calculateInsetArea(b, c.getInsets(), r);  }  /**   * 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).   *   * @param aComponent The component to measure   *   * @return The component's bounds in its local coordinate space   */  public static Rectangle getLocalBounds(Component aComponent)  {    Rectangle bounds = aComponent.getBounds();    return new Rectangle(0, 0, bounds.width, bounds.height);  }  /**   * If <code>comp</code> is a RootPaneContainer, return its JRootPane.   * Otherwise call <code>getAncestorOfClass(JRootPane.class, a)</code>.   *   * @param comp The component to get the JRootPane of   *   * @return a suitable JRootPane for <code>comp</code>, or <code>null</code>   *    * @see javax.swing.RootPaneContainer#getRootPane   * @see #getAncestorOfClass   */  public static JRootPane getRootPane(Component comp)  {    if (comp instanceof RootPaneContainer)      return ((RootPaneContainer)comp).getRootPane();    else      return (JRootPane) getAncestorOfClass(JRootPane.class, comp);  }  /**   * Returns the least ancestor of <code>comp</code> which has the   * specified name.   *   * @param name The name to search for   * @param comp The component to search the ancestors of   *   * @return The nearest ancestor of <code>comp</code> with the given   * name, or <code>null</code> if no such ancestor exists   *   * @see java.awt.Component#getName   * @see #getAncestorOfClass   */  public static Container getAncestorNamed(String name, Component comp)  {    while (comp != null && (comp.getName() != name))      comp = comp.getParent();    return (Container) comp;  }  /**   * Returns the least ancestor of <code>comp</code> which is an instance   * of the specified class.   *   * @param c The class to search for   * @param comp The component to search the ancestors of   *   * @return The nearest ancestor of <code>comp</code> which is an instance   * of the given class, or <code>null</code> if no such ancestor exists   *   * @see #getAncestorOfClass   * @see #windowForComponent   */  public static Container getAncestorOfClass(Class c, Component comp)  {    while (comp != null && (! c.isInstance(comp)))      comp = comp.getParent();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -