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

📄 awtutilities.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* AWTUtilities.java -- Common utility methods for AWT and Swing.   Copyright (C) 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 gnu.java.awt;import java.applet.Applet;import java.awt.Component;import java.awt.Container;import java.awt.Font;import java.awt.FontMetrics;import java.awt.Insets;import java.awt.Point;import java.awt.Rectangle;import java.awt.Toolkit;import java.awt.Window;import java.awt.event.MouseEvent;import java.util.AbstractSequentialList;import java.util.List;import java.util.ListIterator;import java.util.NoSuchElementException;import java.util.WeakHashMap;import java.lang.reflect.InvocationTargetException;/** * This class mirrors the javax.swing.SwingUtilities class. It  * provides commonly needed functionalities for AWT classes without * the need to reference classes in the javax.swing package. */public class AWTUtilities{  /**   * This List implementation wraps the Component[] returned by   * {@link Container#getComponents()} and iterates over the visible Components   * in that array. This class is used in {@link #getVisibleChildren}.   */  static class VisibleComponentList extends AbstractSequentialList  {    /**     * The ListIterator for this List.     */    class VisibleComponentIterator implements ListIterator    {      /** The current index in the Component[]. */      int index;      /** The index in the List of visible Components. */      int listIndex;      /**       * Creates a new VisibleComponentIterator that starts at the specified       * <code>listIndex</code>. The array of Components is searched from       * the beginning to find the matching array index.       *       * @param listIndex the index from where to begin iterating       */      VisibleComponentIterator(int listIndex)      {	this.listIndex = listIndex;	int visibleComponentsFound = 0;	for (index = 0; visibleComponentsFound != listIndex; index++)	  {	    if (components[index].isVisible())	      visibleComponentsFound++;	  }      }      /**       * Returns <code>true</code> if there are more visible components in the       * array, <code>false</code> otherwise.       *       * @return <code>true</code> if there are more visible components in the       *     array, <code>false</code> otherwise       */      public boolean hasNext()      {	boolean hasNext = false;	for (int i = index; i < components.length; i++)	  {	    if (components[i].isVisible())	      {		hasNext = true;		break;	      }	  }	return hasNext;      }      /**       * Returns the next visible <code>Component</code> in the List.       *       * @return the next visible <code>Component</code> in the List       *       * @throws if there is no next element       */      public Object next()      {	Object o = null;	for (; index < components.length; index++)	  {	    if (components[index].isVisible())	      {		o = components[index];		break;	      }	  }	if (o != null)	  {	    index++;	    listIndex++;	    return o;	  }	else	  throw new NoSuchElementException();      }      /**       * Returns <code>true</code> if there are more visible components in the       * array in the reverse direction, <code>false</code> otherwise.       *       * @return <code>true</code> if there are more visible components in the       *     array in the reverse direction, <code>false</code> otherwise       */      public boolean hasPrevious()      {	boolean hasPrevious = false;	for (int i = index - 1; i >= 0; i--)	  {	    if (components[i].isVisible())	      {		hasPrevious = true;		break;	      }	  }	return hasPrevious;      }      /**       * Returns the previous visible <code>Component</code> in the List.       *       * @return the previous visible <code>Component</code> in the List       *       * @throws NoSuchElementException if there is no previous element       */      public Object previous()      {	Object o = null;	for (index--; index >= 0; index--)	  {	    if (components[index].isVisible())	      {		o = components[index];		break;	      }	  }	if (o != null)	  {	    listIndex--;	    return o;	  }	else	  throw new NoSuchElementException();      }      /**       * Returns the index of the next element in the List.       *       * @return the index of the next element in the List       */      public int nextIndex()      {	return listIndex + 1;      }      /**       * Returns the index of the previous element in the List.       *       * @return the index of the previous element in the List       */      public int previousIndex()      {	return listIndex - 1;      }      /**       * This operation is not supported because the List is immutable.       *       * @throws UnsupportedOperationException because the List is immutable       */      public void remove()      {	throw new UnsupportedOperationException	  ("VisibleComponentList is immutable");      }      /**       * This operation is not supported because the List is immutable.       *       * @param o not used here       *       * @throws UnsupportedOperationException because the List is immutable       */      public void set(Object o)      {	throw new UnsupportedOperationException	  ("VisibleComponentList is immutable");      }      /**       * This operation is not supported because the List is immutable.       *       * @param o not used here       *       * @throws UnsupportedOperationException because the List is immutable       */      public void add(Object o)      {	throw new UnsupportedOperationException	  ("VisibleComponentList is immutable");      }    }    /**     * The components over which we iterate. Only the visible components     * are returned by this List.     */    Component[] components;    /**     * Creates a new instance of VisibleComponentList that wraps the specified     * <code>Component[]</code>.     *     * @param c the <code>Component[]</code> to be wrapped.     */    VisibleComponentList(Component[] c)    {      components = c;    }    /**     * Returns a {@link ListIterator} for iterating over this List.     *     * @return a {@link ListIterator} for iterating over this List     */    public ListIterator listIterator(int index)    {      return new VisibleComponentIterator(index);    }    /**     * Returns the number of visible components in the wrapped Component[].     *     * @return the number of visible components     */    public int size()    {      int visibleComponents = 0;      for (int i = 0; i < components.length; i++)	if (components[i].isVisible())	  visibleComponents++;      return visibleComponents;    }  }  /**   * The cache for our List instances. We try to hold one instance of   * VisibleComponentList for each Component[] that is requested. Note   * that we use a WeakHashMap for caching, so that the cache itself   * does not keep the array or the List from beeing garbage collected   * if no other objects hold references to it.   */  static WeakHashMap visibleChildrenCache = new WeakHashMap();  /**   * Returns the visible children of a {@link Container}. This method is   * commonly needed in LayoutManagers, because they only have to layout   * the visible children of a Container.   *   * @param c the Container from which to extract the visible children   *   * @return the visible children of <code>c</code>   */  public static List getVisibleChildren(Container c)  {    Component[] children = c.getComponents();    Object o = visibleChildrenCache.get(children);    VisibleComponentList visibleChildren = null;    if (o == null)      {	visibleChildren = new VisibleComponentList(children);	visibleChildrenCache.put(children, visibleChildren);      }    else      visibleChildren = (VisibleComponentList) o;    return visibleChildren;  }  /**   * 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)  {

⌨️ 快捷键说明

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