jcomponent.java
来自「Mac OS X 10.4.9 for x86 Source Code gcc」· Java 代码 · 共 2,217 行 · 第 1/5 页
JAVA
2,217 行
/* JComponent.java -- Every component in swing inherits from this class. 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., 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 javax.swing;import java.awt.AWTEvent;import java.awt.Color;import java.awt.Component;import java.awt.Container;import java.awt.Dimension;import java.awt.FlowLayout;import java.awt.Font;import java.awt.Graphics;import java.awt.Image;import java.awt.Insets;import java.awt.Point;import java.awt.Rectangle;import java.awt.dnd.DropTarget;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.ContainerEvent;import java.awt.event.ContainerListener;import java.awt.event.FocusEvent;import java.awt.event.FocusListener;import java.awt.event.KeyEvent;import java.awt.event.MouseEvent;import java.awt.geom.Rectangle2D;import java.awt.image.ImageObserver;import java.awt.peer.LightweightPeer;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import java.beans.PropertyVetoException;import java.beans.VetoableChangeListener;import java.io.Serializable;import java.util.EventListener;import java.util.Hashtable;import java.util.Locale;import javax.accessibility.Accessible;import javax.accessibility.AccessibleContext;import javax.accessibility.AccessibleKeyBinding;import javax.accessibility.AccessibleRole;import javax.accessibility.AccessibleStateSet;import javax.swing.border.Border;import javax.swing.event.AncestorListener;import javax.swing.event.EventListenerList;import javax.swing.event.SwingPropertyChangeSupport;import javax.swing.plaf.ComponentUI;/** * Every component in swing inherits from this class (JLabel, JButton, etc). * It contains generic methods to manage events, properties and sizes. Actual * drawing of the component is channeled to a look-and-feel class that is * implemented elsewhere. * * @author Ronald Veldema (rveldema&064;cs.vu.nl) * @author Graydon Hoare (graydon&064;redhat.com) */public abstract class JComponent extends Container implements Serializable{ private static final long serialVersionUID = -7908749299918704233L; /** * Accessibility support is currently missing. */ protected AccessibleContext accessibleContext; public abstract class AccessibleJComponent extends AccessibleAWTContainer { protected class AccessibleFocusHandler implements FocusListener { protected AccessibleFocusHandler(){} public void focusGained(FocusEvent event){} public void focusLost(FocusEvent valevent){} } protected class AccessibleContainerHandler implements ContainerListener { protected AccessibleContainerHandler() {} public void componentAdded(ContainerEvent event) {} public void componentRemoved(ContainerEvent valevent) {} } private static final long serialVersionUID = -7047089700479897799L; protected ContainerListener accessibleContainerHandler; protected FocusListener accessibleFocusHandler; protected AccessibleJComponent() {} public void addPropertyChangeListener(PropertyChangeListener listener) {} public void removePropertyChangeListener(PropertyChangeListener listener) {} public int getAccessibleChildrenCount() { return 0; } public Accessible getAccessibleChild(int value0) { return null; } public AccessibleStateSet getAccessibleStateSet() { return null; } public String getAccessibleName() { return null; } public String getAccessibleDescription() { return null; } public AccessibleRole getAccessibleRole() { return null; } protected String getBorderTitle(Border value0) { return null; } public String getToolTipText() { return null; } public String getTitledBorderText() { return null; } public AccessibleKeyBinding getAccessibleKeyBinding() { return null; } } /** * An explicit value for the component's preferred size; if not set by a * user, this is calculated on the fly by delegating to the {@link * ComponentUI.getPreferredSize} method on the {@link #ui} property. */ Dimension preferredSize; /** * An explicit value for the component's minimum size; if not set by a * user, this is calculated on the fly by delegating to the {@link * ComponentUI.getMinimumSize} method on the {@link #ui} property. */ Dimension minimumSize; /** * An explicit value for the component's maximum size; if not set by a * user, this is calculated on the fly by delegating to the {@link * ComponentUI.getMaximumSize} method on the {@link #ui} property. */ Dimension maximumSize; /** * A value between 0.0 and 1.0 indicating the preferred horizontal * alignment of the component, relative to its siblings. The values * {@link #LEFT_ALIGNMENT}, {@link #CENTER_ALIGNMENT}, and {@link * #RIGHT_ALIGNMENT} can also be used, as synonyms for <code>0.0</code>, * <code>0.5</code>, and <code>1.0</code>, respectively. Not all layout * managers use this property. * * @see #getAlignmentX * @see #setAlignmentX * @see javax.swing.OverlayLayout * @see javax.swing.BoxLayout */ float alignmentX = 0.0f; /** * A value between 0.0 and 1.0 indicating the preferred vertical * alignment of the component, relative to its siblings. The values * {@link #TOP_ALIGNMENT}, {@link #CENTER_ALIGNMENT}, and {@link * #BOTTOM_ALIGNMENT} can also be used, as synonyms for <code>0.0</code>, * <code>0.5</code>, and <code>1.0</code>, respectively. Not all layout * managers use this property. * * @see #getAlignmentY * @see #setAlignmentY * @see javax.swing.OverlayLayout * @see javax.swing.BoxLayout */ float alignmentY = 0.0f; /** * The border painted around this component. * * @see #paintBorder */ Border border; /** * The text to show in the tooltip associated with this component. * * @see #setToolTipText * @see #getToolTipText */ String toolTipText; /** * <p>Whether to double buffer this component when painting. This flag * should generally be <code>false</code>, except for top level * components such as {@link JFrame} or {@link JApplet}.</p> * * <p>All children of a double buffered component are painted into the * double buffer automatically, so only the top widget in a window needs * to be double buffered.</p> * * @see #setDoubleBuffered * @see #isDoubleBuffered * @see #paintLock * @see #paint */ boolean doubleBuffered = false; /** * A set of flags indicating which debugging graphics facilities should * be enabled on this component. The values should be a combination of * {@link DebugGraphics.NONE_OPTION}, {@link DebugGraphics.LOG_OPTION}, * {@link DebugGraphics.FLASH_OPTION}, or {@link * DebugGraphics.BUFFERED_OPTION}. * * @see setDebugGraphicsOptions * @see getDebugGraphicsOptions * @see DebugGraphics * @see getComponentGraphics */ int debugGraphicsOptions; /** * <p>This property controls two independent behaviors simultaneously.</p> * * <p>First, it controls whether to fill the background of this widget * when painting its body. This affects calls to {@link * JComponent#paintComponent}, which in turn calls {@link * ComponentUI#update} on the component's {@link #ui} property. If the * component is opaque during this call, the background will be filled * before calling {@link ComponentUI#paint}. This happens merely as a * convenience; you may fill the component's background yourself too, * but there is no need to do so if you will be filling with the same * color.</p> * * <p>Second, it the opaque property informs swing's repaint system * whether it will be necessary to paint the components "underneath" this * component, in Z-order. If the component is opaque, it is considered to * completely occlude components "underneath" it, so they will not be * repainted along with the opaque component.</p> * * <p>The default value for this property is <code>false</code>, but most * components will want to set it to <code>true</code> when installing UI * defaults in {@link ComponentUI#installUI}.</p> * * @see #setOpaque * @see #isOpaque * @see #paintComponent */ boolean opaque = false; /** * The user interface delegate for this component. Event delivery and * repainting of the component are usually delegated to this object. * * @see #setUI * @see #getUI * @see #updateUI */ protected ComponentUI ui; /** * A hint to the focus system that this component should or should not * get focus. If this is <code>false</code>, swing will not try to * request focus on this component; if <code>true</code>, swing might * try to request focus, but the request might fail. Thus it is only * a hint guiding swing's behavior. * * @see #requestFocus * @see #isRequestFocusEnabled * @see #setRequestFocusEnabled */ boolean requestFocusEnabled; /** * Flag indicating behavior of this component when the mouse is dragged * outside the component and the mouse <em>stops moving</em>. If * <code>true</code>, synthetic mouse events will be delivered on regular * timed intervals, continuing off in the direction the mouse exited the * component, until the mouse is released or re-enters the component. * * @see setAutoscrolls * @see getAutoscrolls */ boolean autoscrolls = false; /** * Listeners for events other than {@link PropertyChangeEvent} are * handled by this listener list. PropertyChangeEvents are handled in * {@link #changeSupport}. */ protected EventListenerList listenerList = new EventListenerList(); /** * Support for {@link PropertyChangeEvent} events. This is constructed * lazily when the component gets its first {@link * PropertyChangeListener} subscription; until then it's an empty slot. */ private SwingPropertyChangeSupport changeSupport; /** * Storage for "client properties", which are key/value pairs associated * with this component by a "client", such as a user application or a * layout manager. This is lazily constructed when the component gets its * first client property. */ private Hashtable clientProperties; private InputMap inputMap_whenFocused; private InputMap inputMap_whenAncestorOfFocused; private InputMap inputMap_whenInFocusedWindow; private ActionMap actionMap; /** @since 1.3 */ private boolean verifyInputWhenFocusTarget; private InputVerifier inputVerifier; private TransferHandler transferHandler; /** * A lock held during recursive painting; this is used to serialize * access to the double buffer, and also to select the "top level" * object which should acquire the double buffer in a given widget * tree (which may have multiple double buffered children). * * @see #doubleBuffered * @see #paint */ private static final Object paintLock = new Object(); /** * The default locale of the component. * * @see #getDefaultLocale * @see #setDefaultLocale */ private static Locale defaultLocale; public static final String TOOL_TIP_TEXT_KEY = "ToolTipText"; /** * Constant used to indicate that no condition has been assigned to a * particular action. * * @see #registerKeyboardAction */ public static final int UNDEFINED_CONDITION = -1; /** * Constant used to indicate that an action should be performed only when * the component has focus. * * @see #registerKeyboardAction */ public static final int WHEN_FOCUSED = 0; /** * Constant used to indicate that an action should be performed only when * the component is an ancestor of the component which has focus. * * @see #registerKeyboardAction */ public static final int WHEN_ANCESTOR_OF_FOCUSED_COMPONENT = 1; /** * Constant used to indicate that an action should be performed only when * the component is in the window which has focus. * * @see #registerKeyboardAction */ public static final int WHEN_IN_FOCUSED_WINDOW = 2; /** * Creates a new <code>JComponent</code> instance. */ public JComponent() { super(); super.setLayout(new FlowLayout()); setDropTarget(new DropTarget()); defaultLocale = Locale.getDefault(); debugGraphicsOptions = DebugGraphics.NONE_OPTION; } /** * Helper to lazily construct and return the client properties table. * * @return The current client properties table * * @see #clientProperties * @see #getClientProperty * @see #putClientProperty */ private Hashtable getClientProperties() { if (clientProperties == null) clientProperties = new Hashtable(); return clientProperties; } /** * Get a client property associated with this component and a particular * key. * * @param key The key with which to look up the client property * * @return A client property associated with this object and key * * @see #clientProperties * @see #getClientProperties * @see #putClientProperty */ public final Object getClientProperty(Object key) { return getClientProperties().get(key); } /** * Add a client property <code>value</code> to this component, associated * with <code>key</code>. If there is an existing client property * associated with <code>key</code>, it will be replaced. * * @param key The key of the client property association to add * @param value The value of the client property association to add *
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?