📄 jcomponent.java
字号:
/* 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., 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 javax.swing;import java.applet.Applet;import java.awt.AWTEvent;import java.awt.Color;import java.awt.Component;import java.awt.Container;import java.awt.Dimension;import java.awt.EventQueue;import java.awt.FlowLayout;import java.awt.FocusTraversalPolicy;import java.awt.Font;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.Image;import java.awt.Insets;import java.awt.Point;import java.awt.Rectangle;import java.awt.Shape;import java.awt.Window;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.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 java.util.Set;import javax.accessibility.Accessible;import javax.accessibility.AccessibleContext;import javax.accessibility.AccessibleExtendedComponent;import javax.accessibility.AccessibleKeyBinding;import javax.accessibility.AccessibleRole;import javax.accessibility.AccessibleStateSet;import javax.swing.border.Border;import javax.swing.border.CompoundBorder;import javax.swing.border.TitledBorder;import javax.swing.event.AncestorEvent;import javax.swing.event.AncestorListener;import javax.swing.event.EventListenerList;import javax.swing.event.SwingPropertyChangeSupport;import javax.swing.plaf.ComponentUI;/** * The base class of all Swing components. * 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; /** * Basic accessibility support for <code>JComponent</code> derived * widgets. */ public abstract class AccessibleJComponent extends AccessibleAWTContainer implements AccessibleExtendedComponent { /** * Accessibility support for <code>JComponent</code>'s focus handler. */ protected class AccessibleFocusHandler implements FocusListener { protected AccessibleFocusHandler() { // TODO: Implement this properly. } public void focusGained(FocusEvent event) { // TODO: Implement this properly. } public void focusLost(FocusEvent valevent) { // TODO: Implement this properly. } } /** * Accessibility support for <code>JComponent</code>'s container handler. */ protected class AccessibleContainerHandler implements ContainerListener { protected AccessibleContainerHandler() { // TODO: Implement this properly. } public void componentAdded(ContainerEvent event) { // TODO: Implement this properly. } public void componentRemoved(ContainerEvent valevent) { // TODO: Implement this properly. } } private static final long serialVersionUID = -7047089700479897799L; protected ContainerListener accessibleContainerHandler; protected FocusListener accessibleFocusHandler; /** * Manages the property change listeners; */ private SwingPropertyChangeSupport changeSupport; protected AccessibleJComponent() { changeSupport = new SwingPropertyChangeSupport(this); } /** * Adds a property change listener to the list of registered listeners. * * @param listener the listener to add */ public void addPropertyChangeListener(PropertyChangeListener listener) { changeSupport.addPropertyChangeListener(listener); } /** * Removes a propery change listener from the list of registered listeners. * * @param listener the listener to remove */ public void removePropertyChangeListener(PropertyChangeListener listener) { changeSupport.removePropertyChangeListener(listener); } /** * Returns the number of accessible children of this object. * * @return the number of accessible children of this object */ public int getAccessibleChildrenCount() { int count = 0; Component[] children = getComponents(); for (int i = 0; i < children.length; ++i) { if (children[i] instanceof Accessible) count++; } return count; } /** * Returns the accessible child component at index <code>i</code>. * * @param i the index of the accessible child to return * * @return the accessible child component at index <code>i</code> */ public Accessible getAccessibleChild(int i) { int index = 0; Component[] children = getComponents(); Accessible found = null; for (int j = 0; index != i; j++) { if (children[j] instanceof Accessible) index++; if (index == i) found = (Accessible) children[index]; } // TODO: Figure out what to do when i is not a valid index. return found; } /** * Returns the accessible state set of this component. * * @return the accessible state set of this component */ public AccessibleStateSet getAccessibleStateSet() { // FIXME: Figure out which states should be set here, and which are // inherited from the super class. return super.getAccessibleStateSet(); } /** * Returns the localized name for this object. Generally this should * almost never return {@link Component#getName()} since that is not * a localized name. If the object is some kind of text component (like * a menu item), then the value of the object may be returned. Also, if * the object has a tooltip, the value of the tooltip may also be * appropriate. * * @return the localized name for this object or <code>null</code> if this * object has no name */ public String getAccessibleName() { // TODO: Figure out what exactly to return here. It's possible that this // method simply should return null. return null; } /** * Returns the localized description of this object. * * @return the localized description of this object or <code>null</code> * if this object has no description */ public String getAccessibleDescription() { // TODO: Figure out what exactly to return here. It's possible that this // method simply should return null. return null; } /** * Returns the accessible role of this component. * * @return the accessible role of this component * * @see AccessibleRole */ public AccessibleRole getAccessibleRole() { // TODO: Check if this is correct. return AccessibleRole.SWING_COMPONENT; } /** * Recursivly searches a border hierarchy (starting at <code>border) for * a titled border and returns the title if one is found, <code>null</code> * otherwise. * * @param border the border to start search from * * @return the border title of a possibly found titled border */ protected String getBorderTitle(Border border) { String title = null; if (border instanceof CompoundBorder) { CompoundBorder compound = (CompoundBorder) border; Border inner = compound.getInsideBorder(); title = getBorderTitle(inner); if (title == null) { Border outer = compound.getOutsideBorder(); title = getBorderTitle(outer); } } else if (border instanceof TitledBorder) { TitledBorder titled = (TitledBorder) border; title = titled.getTitle(); } return title; } /** * Returns the tooltip text for this accessible component. * * @return the tooltip text for this accessible component */ public String getToolTipText() { return JComponent.this.getToolTipText(); } /** * Returns the title of the border of this accessible component if * this component has a titled border, otherwise returns <code>null</code>. * * @return the title of the border of this accessible component if * this component has a titled border, otherwise returns * <code>null</code> */ public String getTitledBorderText() { return getBorderTitle(getBorder()); } /** * Returns the keybindings associated with this accessible component or * <code>null</code> if the component does not support key bindings. * * @return the keybindings associated with this accessible component */ public AccessibleKeyBinding getAccessibleKeyBinding() { // TODO: Implement this properly. 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 = -1.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 = -1.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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -