component.java

来自「gcc3.2.1源代码」· Java 代码 · 共 2,479 行 · 第 1/5 页

JAVA
2,479
字号
/* Copyright (C) 1999, 2000, 2001, 2002  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., 59 Temple Place, Suite 330, Boston, MA02111-1307 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.*;import java.awt.image.*;import java.io.PrintStream;import java.io.PrintWriter;import java.lang.reflect.*;import java.util.EventListener;import java.util.Locale;import java.util.ResourceBundle;import java.util.Vector;import java.awt.peer.ComponentPeer;import java.awt.peer.LightweightPeer;import java.beans.PropertyChangeSupport;import java.beans.PropertyChangeListener;// import javax.accessibility.AccessibleContext;/**  * The root of all evil.  *  * Status: Incomplete. The event dispatch mechanism is implemented. All   * other methods defined in the J2SE 1.3 API javadoc exist, but are mostly   * incomplete or only stubs; except for methods relating to the Drag and Drop,   * Input Method, and Accessibility frameworks: These methods are present but   * commented out.  */public abstract class Component implements ImageObserver, MenuContainer, 					   java.io.Serializable{  /**   * Constant returned by the <code>getAlignmentY</code> method to indicate   * that the component wishes to be aligned to the bottom relative to   * other components.   */  public static final float BOTTOM_ALIGNMENT = (float)1.0;  /**   * Constant returned by the <code>getAlignmentY</code> and    * <code>getAlignmentX</code> methods to indicate   * that the component wishes to be aligned to the center relative to   * other components.   */  public static final float CENTER_ALIGNMENT = (float)0.5;  /**   * Constant returned by the <code>getAlignmentY</code> method to indicate   * that the component wishes to be aligned to the top relative to   * other components.   */  public static final float TOP_ALIGNMENT = (float)0.0;  /**   * Constant returned by the <code>getAlignmentX</code> method to indicate   * that the component wishes to be aligned to the right relative to   * other components.   */  public static final float RIGHT_ALIGNMENT = (float)1.0;  /**   * Constant returned by the <code>getAlignmentX</code> method to indicate   * that the component wishes to be aligned to the left relative to   * other components.   */  public static final float LEFT_ALIGNMENT = (float)0.0;  /* Make the treelock a String so that it can easily be identified     in debug dumps. We clone the String in order to avoid a conflict in      the unlikely event that some other package uses exactly the same string     as a lock object. */  static Object treeLock = new String("AWT_TREE_LOCK");  /* Serialized fields from the serialization spec. */  // FIXME: Default values?  int x;  int y;  int width;  int height;  Color foreground;  Color background;  Font font;  Font peerFont;  Cursor cursor;  Locale locale;  boolean visible = true; // default (except for Window)  boolean enabled = true;  boolean valid;  boolean hasFocus;  //DropTarget dropTarget;  Vector popups;  String name;  boolean nameExplicitlySet;  Dimension minSize;  Dimension prefSize;  boolean newEventsOnly;    long eventMask = AWTEvent.PAINT_EVENT_MASK;  PropertyChangeSupport changeSupport;  boolean isPacked;  int componentSerializedDataVersion;  /* AccessibleContext accessibleContext; */  /* Anything else is non-serializable, and should be declared "transient". */  transient Container parent;  transient java.awt.peer.ComponentPeer peer;  transient ComponentListener componentListener;  transient FocusListener focusListener;  transient KeyListener keyListener;  transient MouseListener mouseListener;  transient MouseMotionListener mouseMotionListener;  transient InputMethodListener inputMethodListener;  transient HierarchyListener hierarchyListener;  transient HierarchyBoundsListener hierarchyBoundsListener;  transient ComponentOrientation orientation = ComponentOrientation.UNKNOWN;  /**   * Default constructor for subclasses.   */  protected Component()  {  }  /**   * Returns the name of this component.   *   * @return The name of this component.   */  public String getName()  {    if (name == null && !nameExplicitlySet)      name = generateName();    return name;  }  /**   * Sets the name of this component to the specified name.   *   * @param name The new name of this component.   */  public void setName(String name)  {    nameExplicitlySet = true;    this.name = name;  }    /** Subclasses should override this to return unique component names like     * "menuitem0".    */  String generateName()  {    // Component is abstract.    return null;  }  /**   * Returns the parent of this component.   *    * @return The parent of this component.   */  public Container getParent()  {    return parent;    }  // Sets the peer for this component.  final void setPeer (ComponentPeer peer)  {    this.peer = peer;  }  /**   * Returns the native windowing system peer for this component.   *   * @return The peer for this component.   * @deprecated   */  // Classpath's Gtk peers rely on this.  public java.awt.peer.ComponentPeer getPeer()  {    return peer;  }  // FIXME: java.awt.dnd classes not yet implemented  /*  public void setDropTarget(DropTarget dt)  {    this.dropTarget = dt;  }    public DropTarget getDropTarget()  {    return dropTarget;  }  */    /** @since 1.3 */  public GraphicsConfiguration getGraphicsConfiguration()  {    return getGraphicsConfigurationImpl();  }  /** Implementation method that allows classes such as Canvas and      Window to override the graphics configuration without violating      the published API. */  GraphicsConfiguration getGraphicsConfigurationImpl()  {    if (peer != null)      {	GraphicsConfiguration config = peer.getGraphicsConfiguration();	if (config != null)	  return config;      }    if (parent != null)      return parent.getGraphicsConfiguration();    return null;  }  /**   * Returns the object used for synchronization locks on this component   * when performing tree and layout functions.   *   * @return The synchronization lock for this component.   */  public final Object getTreeLock()  {    return treeLock;  }  // The sync lock object for this component.  final void setTreeLock(Object tree_lock)  {    this.treeLock = tree_lock;  }  /**   * Returns the toolkit in use for this component.   *   * @return The toolkit for this component.   */  public Toolkit getToolkit()  {    if (peer != null)      {	Toolkit tk = peer.getToolkit();	if (tk != null)	  return tk;      }    if (parent != null)      return parent.getToolkit ();    return Toolkit.getDefaultToolkit ();  }  /**   * Tests whether or not this component is valid.  A invalid component needs   * to have its layout redone.   *   * @return <code>true</code> if this component is valid, <code>false</code>   * otherwise.   */  public boolean isValid()  {    return valid;  }    /** @since 1.2 */  public boolean isDisplayable()  {    if (parent != null)      return parent.isDisplayable();    return false;  }  /**   * Tests whether or not this component is visible.   *   * @return <code>true</code> if the component is visible,   * <code>false</code> otherwise.   */  public boolean isVisible()  {    return visible;  }  /**   * Tests whether or not this component is actually being shown on   * the screen.  This will be true if and only if it this component is   * visible and its parent components are all visible.   *   * @return <code>true</code> if the component is showing on the screen,   * <code>false</code> otherwise.   */  public boolean isShowing()  {    if (! visible || peer == null)      return false;    return parent == null ? true : parent.isShowing ();  }  /**   * Tests whether or not this component is enabled.   *   * @return <code>true</code> if the component is enabled,   * <code>false</code> otherwise.   */  public boolean isEnabled()  {    return enabled;  }  /**   * Enables or disables this component.   *   * @param enabled <code>true</code> to enable this component,    * <code>false</code> to disable it.   *   * @deprecated Deprecated in favor of <code>setEnabled()</code>.   */  public void setEnabled(boolean b)  {    this.enabled = b;    if (peer != null)      peer.setEnabled(b);  }  /**   * Enables this component.   *   * @deprecated Deprecated in favor of <code>setEnabled()</code>.   */  public void enable()  {    setEnabled(true);  }  /**   * Enables or disables this component.   *   * @param enabled <code>true</code> to enable this component,    * <code>false</code> to disable it.   *   * @deprecated Deprecated in favor of <code>setEnabled()</code>.   */  public void enable(boolean b)  {    setEnabled(b);  }  /**   * Disables this component.   *   * @deprecated Deprecated in favor of <code>setEnabled()</code>.   */  public void disable()  {    setEnabled(false);  }  public boolean isDoubleBuffered()  {    return false;  }  /** @since 1.2 */  public void enableInputMethods(boolean enable)  {    // FIXME  }  /**   * Makes this component visible or invisible.   *   * @param visible <code>true</code> to make this component visible,   * </code>false</code> to make it invisible.   * @specnote  Inspection by subclassing shows that Sun's implementation   * calls show(boolean) which then calls show() or hide(). It is   * the show() method that is overriden in subclasses like Window.   * We do the same to preserve compatibility for subclasses.   */  public void setVisible(boolean b)  {    if (peer != null)      peer.setVisible (b);    this.visible = b;  }  /**   * Makes this component visible on the screen.   *   * @deprecated Deprecated in favor of <code>setVisible()</code>.   */  public void show()  {    setVisible (true);  }  /**   * Makes this component visible or invisible.   *   * @param visible <code>true</code> to make this component visible,   * </code>false</code> to make it invisible.   *   * @deprecated Deprecated in favor of <code>setVisible()</code>.   */  public void show(boolean b)  {    setVisible (b);  }  /**   * Hides this component so that it is no longer shown on the screen.   *   * @deprecated Deprecated in favor of <code>setVisible()</code>.   */  public void hide()  {    setVisible (false);  }  /**   * Returns this component's foreground color.   *   * @return This component's foreground color.   */  public Color getForeground()  {    if (foreground != null)      return foreground;    if (parent != null)      return parent.getForeground();    return null;  }  /**   * Sets this component's foreground color to the specified color.   *   * @param foreground_color The new foreground color.   */  public void setForeground(Color c)  {    if (peer != null)      peer.setForeground(c);    this.foreground = c;  }  /**   * Returns this component's background color.   *   * @return the background color of the component. null may be   * returned instead of the actual background color, if this   * method is called before the component is added to the   * component hierarchy.   */  public Color getBackground()  {    if (background != null)      return background;    if (parent != null)      return parent.getBackground();

⌨️ 快捷键说明

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