📄 component.java
字号:
/* Component.java -- a graphics component Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 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.dnd.DropTarget;import java.awt.event.ActionEvent;import java.awt.event.ComponentEvent;import java.awt.event.ComponentListener;import java.awt.event.FocusEvent;import java.awt.event.FocusListener;import java.awt.event.HierarchyBoundsListener;import java.awt.event.HierarchyEvent;import java.awt.event.HierarchyListener;import java.awt.event.InputEvent;import java.awt.event.InputMethodEvent;import java.awt.event.InputMethodListener;import java.awt.event.KeyEvent;import java.awt.event.KeyListener;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import java.awt.event.MouseMotionListener;import java.awt.event.MouseWheelEvent;import java.awt.event.MouseWheelListener;import java.awt.event.PaintEvent;import java.awt.event.WindowEvent;import java.awt.im.InputContext;import java.awt.im.InputMethodRequests;import java.awt.image.BufferStrategy;import java.awt.image.ColorModel;import java.awt.image.ImageObserver;import java.awt.image.ImageProducer;import java.awt.image.VolatileImage;import java.awt.peer.ComponentPeer;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.lang.reflect.Array;import java.util.Collections;import java.util.EventListener;import java.util.HashSet;import java.util.Iterator;import java.util.Locale;import java.util.Set;import java.util.Vector;import javax.accessibility.Accessible;import javax.accessibility.AccessibleComponent;import javax.accessibility.AccessibleContext;import javax.accessibility.AccessibleRole;import javax.accessibility.AccessibleState;import javax.accessibility.AccessibleStateSet;/** * The root of all evil. All graphical representations are subclasses of this * giant class, which is designed for screen display and user interaction. * This class can be extended directly to build a lightweight component (one * not associated with a native window); lightweight components must reside * inside a heavyweight window. * * <p>This class is Serializable, which has some big implications. A user can * save the state of all graphical components in one VM, and reload them in * another. Note that this class will only save Serializable listeners, and * ignore the rest, without causing any serialization exceptions. However, by * making a listener serializable, and adding it to another element, you link * in that entire element to the state of this component. To get around this, * use the idiom shown in the example below - make listeners non-serializable * in inner classes, rather than using this object itself as the listener, if * external objects do not need to save the state of this object. * * <pre> * import java.awt.*; * import java.awt.event.*; * import java.io.Serializable; * class MyApp implements Serializable * { * BigObjectThatShouldNotBeSerializedWithAButton bigOne; * // Serializing aButton will not suck in an instance of MyApp, with its * // accompanying field bigOne. * Button aButton = new Button(); * class MyActionListener implements ActionListener * { * public void actionPerformed(ActionEvent e) * { * System.out.println("Hello There"); * } * } * MyApp() * { * aButton.addActionListener(new MyActionListener()); * } * } * </pre> * * <p>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. * * @author original author unknown * @author Eric Blake (ebb9@email.byu.edu) * @since 1.0 * @status still missing 1.4 support */public abstract class Component implements ImageObserver, MenuContainer, Serializable{ // Word to the wise - this file is huge. Search for '\f' (^L) for logical // sectioning by fields, public API, private API, and nested classes. /** * Compatible with JDK 1.0+. */ private static final long serialVersionUID = -7644114512714619750L; /** * Constant returned by the <code>getAlignmentY</code> method to indicate * that the component wishes to be aligned to the top relative to * other components. * * @see #getAlignmentY() */ public static final float TOP_ALIGNMENT = 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. * * @see #getAlignmentX() * @see #getAlignmentY() */ public static final float CENTER_ALIGNMENT = 0.5f; /** * Constant returned by the <code>getAlignmentY</code> method to indicate * that the component wishes to be aligned to the bottom relative to * other components. * * @see #getAlignmentY() */ public static final float BOTTOM_ALIGNMENT = 1; /** * Constant returned by the <code>getAlignmentX</code> method to indicate * that the component wishes to be aligned to the right relative to * other components. * * @see #getAlignmentX() */ public static final float RIGHT_ALIGNMENT = 1; /** * Constant returned by the <code>getAlignmentX</code> method to indicate * that the component wishes to be aligned to the left relative to * other components. * * @see #getAlignmentX() */ public static final float LEFT_ALIGNMENT = 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 final Object treeLock = new String("AWT_TREE_LOCK"); // Serialized fields from the serialization spec. /** * The x position of the component in the parent's coordinate system. * * @see #getLocation() * @serial the x position */ int x; /** * The y position of the component in the parent's coordinate system. * * @see #getLocation() * @serial the y position */ int y; /** * The component width. * * @see #getSize() * @serial the width */ int width; /** * The component height. * * @see #getSize() * @serial the height */ int height; /** * The foreground color for the component. This may be null. * * @see #getForeground() * @see #setForeground(Color) * @serial the foreground color */ Color foreground; /** * The background color for the component. This may be null. * * @see #getBackground() * @see #setBackground(Color) * @serial the background color */ Color background; /** * The default font used in the component. This may be null. * * @see #getFont() * @see #setFont(Font) * @serial the font */ Font font; /** * The font in use by the peer, or null if there is no peer. * * @serial the peer's font */ Font peerFont; /** * The cursor displayed when the pointer is over this component. This may * be null. * * @see #getCursor() * @see #setCursor(Cursor) */ Cursor cursor; /** * The locale for the component. * * @see #getLocale() * @see #setLocale(Locale) */ Locale locale = Locale.getDefault (); /** * True if the object should ignore repaint events (usually because it is * not showing). * * @see #getIgnoreRepaint() * @see #setIgnoreRepaint(boolean) * @serial true to ignore repaints * @since 1.4 */ boolean ignoreRepaint; /** * True when the object is visible (although it is only showing if all * ancestors are likewise visible). For component, this defaults to true. * * @see #isVisible() * @see #setVisible(boolean) * @serial true if visible */ boolean visible = true; /** * True if the object is enabled, meaning it can interact with the user. * For component, this defaults to true. * * @see #isEnabled() * @see #setEnabled(boolean) * @serial true if enabled */ boolean enabled = true; /** * True if the object is valid. This is set to false any time a size * adjustment means the component need to be layed out again. * * @see #isValid() * @see #validate() * @see #invalidate() * @serial true if layout is valid */ boolean valid; /** * The DropTarget for drag-and-drop operations. * * @see #getDropTarget() * @see #setDropTarget(DropTarget) * @serial the drop target, or null * @since 1.2 */ DropTarget dropTarget; /** * The list of popup menus for this component. * * @see #add(PopupMenu) * @serial the list of popups */ Vector popups; /** * The component's name. May be null, in which case a default name is * generated on the first use. * * @see #getName() * @see #setName(String) * @serial the name */ String name; /** * True once the user has set the name. Note that the user may set the name * to null. * * @see #name * @see #getName() * @see #setName(String) * @serial true if the name has been explicitly set */ boolean nameExplicitlySet; /** * Indicates if the object can be focused. Defaults to true for components. * * @see #isFocusable() * @see #setFocusable(boolean) * @since 1.4 */ boolean focusable = true; /** * Tracks whether this component's {@link #isFocusTraversable} * method has been overridden. * * @since 1.4 */ int isFocusTraversableOverridden; /** * The focus traversal keys, if not inherited from the parent or * default keyboard focus 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 */ Set[] focusTraversalKeys; /** * True if focus traversal keys are enabled. This defaults to true for * Component. If this is true, keystrokes in focusTraversalKeys are trapped * and processed automatically rather than being passed on to the component. * * @see #getFocusTraversalKeysEnabled() * @see #setFocusTraversalKeysEnabled(boolean) * @since 1.4 */ boolean focusTraversalKeysEnabled = true; /** * Cached information on the minimum size. Should have been transient. * * @serial ignore */ Dimension minSize; /** * Cached information on the preferred size. Should have been transient. * * @serial ignore */ Dimension prefSize; /** * Set to true if an event is to be handled by this component, false if * it is to be passed up the hierarcy. * * @see #dispatchEvent(AWTEvent) * @serial true to process event locally */ boolean newEventsOnly; /** * Set by subclasses to enable event handling of particular events, and * left alone when modifying listeners. For component, this defaults to * enabling only input methods. * * @see #enableInputMethods(boolean) * @see AWTEvent * @serial the mask of events to process */ long eventMask = AWTEvent.INPUT_ENABLED_EVENT_MASK; /** * Describes all registered PropertyChangeListeners. * * @see #addPropertyChangeListener(PropertyChangeListener) * @see #removePropertyChangeListener(PropertyChangeListener) * @see #firePropertyChange(String, Object, Object) * @serial the property change listeners * @since 1.2 */ PropertyChangeSupport changeSupport; /** * True if the component has been packed (layed out). * * @serial true if this is packed */ boolean isPacked;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -