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

📄 container.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* Container.java -- parent container class in AWT   Copyright (C) 1999, 2000, 2002, 2003, 2004, 2005  Free Software FoundationThis 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 java.awt;import java.awt.event.ComponentListener;import java.awt.event.ContainerEvent;import java.awt.event.ContainerListener;import java.awt.event.KeyEvent;import java.awt.event.MouseEvent;import java.awt.peer.ComponentPeer;import java.awt.peer.ContainerPeer;import java.awt.peer.LightweightPeer;import java.beans.PropertyChangeListener;import java.beans.PropertyChangeSupport;import java.io.IOException;import java.io.ObjectInputStream;import java.io.ObjectOutputStream;import java.io.PrintStream;import java.io.PrintWriter;import java.io.Serializable;import java.util.Collections;import java.util.EventListener;import java.util.HashSet;import java.util.Iterator;import java.util.Set;import javax.accessibility.Accessible;import gnu.java.awt.AWTUtilities;/** * A generic window toolkit object that acts as a container for other objects. * Components are tracked in a list, and new elements are at the end of the * list or bottom of the stacking order. * * @author original author unknown * @author Eric Blake (ebb9@email.byu.edu) * * @since 1.0 * * @status still missing 1.4 support */public class Container extends Component{  /**   * Compatible with JDK 1.0+.   */  private static final long serialVersionUID = 4613797578919906343L;  /* Serialized fields from the serialization spec. */  int ncomponents;  Component[] component;  LayoutManager layoutMgr;  LightweightDispatcher dispatcher;  Dimension maxSize;  /**   * @since 1.4   */  boolean focusCycleRoot;  int containerSerializedDataVersion;  /* Anything else is non-serializable, and should be declared "transient". */  transient ContainerListener containerListener;  transient PropertyChangeSupport changeSupport;   /** The focus traversal policy that determines how focus is      transferred between this Container and its children. */  private FocusTraversalPolicy focusTraversalPolicy;  /**   * The focus traversal keys, if not inherited from the parent or default   * keyboard manager. These sets will contain only AWTKeyStrokes that   * represent press and release events to use as focus control.   *   * @see #getFocusTraversalKeys(int)   * @see #setFocusTraversalKeys(int, Set)   * @since 1.4   */  transient Set[] focusTraversalKeys;  /**   * Default constructor for subclasses.   */  public Container()  {    // Nothing to do here.  }  /**   * Returns the number of components in this container.   *   * @return The number of components in this container.   */  public int getComponentCount()  {    return countComponents ();  }  /**   * Returns the number of components in this container.   *   * @return The number of components in this container.   *   * @deprecated use {@link #getComponentCount()} instead   */  public int countComponents()  {    return ncomponents;  }  /**   * Returns the component at the specified index.   *   * @param n The index of the component to retrieve.   *   * @return The requested component.   *   * @throws ArrayIndexOutOfBoundsException If the specified index is invalid   */  public Component getComponent(int n)  {    synchronized (getTreeLock ())      {        if (n < 0 || n >= ncomponents)          throw new ArrayIndexOutOfBoundsException("no such component");        return component[n];      }  }  /**   * Returns an array of the components in this container.   *   * @return The components in this container.   */  public Component[] getComponents()  {    synchronized (getTreeLock ())      {        Component[] result = new Component[ncomponents];        if (ncomponents > 0)          System.arraycopy(component, 0, result, 0, ncomponents);        return result;      }  }  /**   * Swaps the components at position i and j, in the container.   */  protected void swapComponents (int i, int j)  {       synchronized (getTreeLock ())      {        if (i < 0             || i >= component.length            || j < 0             || j >= component.length)          throw new ArrayIndexOutOfBoundsException ();        Component tmp = component[i];        component[i] = component[j];        component[j] = tmp;      }  }  /**   * Returns the insets for this container, which is the space used for   * borders, the margin, etc.   *   * @return The insets for this container.   */  public Insets getInsets()  {    return insets ();  }  /**   * Returns the insets for this container, which is the space used for   * borders, the margin, etc.   *   * @return The insets for this container.   * @deprecated use {@link #getInsets()} instead   */  public Insets insets()  {    if (peer == null)      return new Insets (0, 0, 0, 0);    return ((ContainerPeer) peer).getInsets ();  }  /**   * Adds the specified component to this container at the end of the   * component list.   *   * @param comp The component to add to the container.   *   * @return The same component that was added.   */  public Component add(Component comp)  {    addImpl(comp, null, -1);    return comp;  }  /**   * Adds the specified component to the container at the end of the   * component list.  This method should not be used. Instead, use   * <code>add(Component, Object)</code>.   *   * @param name The name of the component to be added.   * @param comp The component to be added.   *   * @return The same component that was added.   *   * @see #add(Component,Object)   */  public Component add(String name, Component comp)  {    addImpl(comp, name, -1);    return comp;  }  /**   * Adds the specified component to this container at the specified index   * in the component list.   *   * @param comp The component to be added.   * @param index The index in the component list to insert this child   * at, or -1 to add at the end of the list.   *   * @return The same component that was added.   *   * @throws ArrayIndexOutOfBoundsException If the specified index is invalid.   */  public Component add(Component comp, int index)  {    addImpl(comp, null, index);    return comp;  }  /**   * Adds the specified component to this container at the end of the   * component list.  The layout manager will use the specified constraints   * when laying out this component.   *   * @param comp The component to be added to this container.   * @param constraints The layout constraints for this component.   */  public void add(Component comp, Object constraints)  {    addImpl(comp, constraints, -1);  }  /**   * Adds the specified component to this container at the specified index   * in the component list.  The layout manager will use the specified   * constraints when layout out this component.   *   * @param comp The component to be added.   * @param constraints The layout constraints for this component.   * @param index The index in the component list to insert this child   * at, or -1 to add at the end of the list.   *   * @throws ArrayIndexOutOfBoundsException If the specified index is invalid.   */  public void add(Component comp, Object constraints, int index)  {    addImpl(comp, constraints, index);  }  /**   * This method is called by all the <code>add()</code> methods to perform   * the actual adding of the component.  Subclasses who wish to perform   * their own processing when a component is added should override this   * method.  Any subclass doing this must call the superclass version of   * this method in order to ensure proper functioning of the container.   *   * @param comp The component to be added.   * @param constraints The layout constraints for this component, or   * <code>null</code> if there are no constraints.   * @param index The index in the component list to insert this child   * at, or -1 to add at the end of the list.   *   * @throws ArrayIndexOutOfBoundsException If the specified index is invalid.   */  protected void addImpl(Component comp, Object constraints, int index)  {    synchronized (getTreeLock ())      {        if (index > ncomponents            || (index < 0 && index != -1)            || comp instanceof Window            || (comp instanceof Container                && ((Container) comp).isAncestorOf(this)))          throw new IllegalArgumentException();        // Reparent component, and make sure component is instantiated if        // we are.        if (comp.parent != null)          comp.parent.remove(comp);        comp.parent = this;        if (peer != null)          {	    // Notify the component that it has a new parent.	    comp.addNotify();            if (comp.isLightweight ())	      {		enableEvents (comp.eventMask);		if (!isLightweight ())		  enableEvents (AWTEvent.PAINT_EVENT_MASK);	      }          }        // Invalidate the layout of the added component and its ancestors.        comp.invalidate();        if (component == null)          component = new Component[4]; // FIXME, better initial size?        // This isn't the most efficient implementation.  We could do less        // copying when growing the array.  It probably doesn't matter.        if (ncomponents >= component.length)          {            int nl = component.length * 2;            Component[] c = new Component[nl];            System.arraycopy(component, 0, c, 0, ncomponents);            component = c;          }          if (index == -1)          component[ncomponents++] = comp;        else          {            System.arraycopy(component, index, component, index + 1,                             ncomponents - index);            component[index] = comp;            ++ncomponents;          }        // Notify the layout manager.        if (layoutMgr != null)          {            if (layoutMgr instanceof LayoutManager2)              {                LayoutManager2 lm2 = (LayoutManager2) layoutMgr;                lm2.addLayoutComponent(comp, constraints);              }            else if (constraints instanceof String)              layoutMgr.addLayoutComponent((String) constraints, comp);            else              layoutMgr.addLayoutComponent(null, comp);          }        // We previously only sent an event when this container is showing.        // Also, the event was posted to the event queue. A Mauve test shows        // that this event is not delivered using the event queue and it is        // also sent when the container is not showing.         ContainerEvent ce = new ContainerEvent(this,                                               ContainerEvent.COMPONENT_ADDED,                                               comp);        ContainerListener[] listeners = getContainerListeners();        for (int i = 0; i < listeners.length; i++)          listeners[i].componentAdded(ce);        // Repaint this container.        repaint(comp.getX(), comp.getY(), comp.getWidth(),                comp.getHeight());      }  }  /**   * Removes the component at the specified index from this container.   *   * @param index The index of the component to remove.   */  public void remove(int index)  {    synchronized (getTreeLock ())      {        Component r = component[index];        ComponentListener[] list = r.getComponentListeners();        for (int j = 0; j < list.length; j++)              r.removeComponentListener(list[j]);                if (r.isShowing())          r.removeNotify();        System.arraycopy(component, index + 1, component, index,                         ncomponents - index - 1);

⌨️ 快捷键说明

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