jcomponent.java
来自「linux下建立JAVA虚拟机的源码KAFFE」· Java 代码 · 共 2,126 行 · 第 1/5 页
JAVA
2,126 行
* <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 #paint */ boolean doubleBuffered = true; /** * 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 #getUIClassID * @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; /** * Indicates whether the current paint call is already double buffered or * not. */ static boolean isPaintingDoubleBuffered = 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(); /** * 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 ComponentInputMap inputMap_whenInFocusedWindow; private ActionMap actionMap; /** @since 1.3 */ private boolean verifyInputWhenFocusTarget; private InputVerifier inputVerifier; private TransferHandler transferHandler; /** * Indicates if this component is currently painting a tile or not. */ private boolean paintingTile; /** * A temporary buffer used for fast dragging of components. */ private Image dragBuffer; /** * Indicates if the dragBuffer is already initialized. */ private boolean dragBufferInitialized; /** * A cached Rectangle object to be reused. Be careful when you use that, * so that it doesn't get modified in another context within the same * method call chain. */ private static transient Rectangle rectCache; /** * 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(ActionListener, KeyStroke, int) */ 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(ActionListener, KeyStroke, int) */ 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(ActionListener, KeyStroke, int) */ 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(ActionListener, KeyStroke, int) */ public static final int WHEN_IN_FOCUSED_WINDOW = 2; /** * Indicates if this component is completely dirty or not. This is used * by the RepaintManager's * {@link RepaintManager#isCompletelyDirty(JComponent)} method. */ boolean isCompletelyDirty = false; /** * Creates a new <code>JComponent</code> instance. */ public JComponent() { super(); setDropTarget(new DropTarget()); defaultLocale = Locale.getDefault(); debugGraphicsOptions = DebugGraphics.NONE_OPTION; setRequestFocusEnabled(true); } /** * 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. A * {@link PropertyChangeEvent} is sent to registered listeners (with the * name of the property being <code>key.toString()</code>). * * @param key The key of the client property association to add * @param value The value of the client property association to add * * @see #clientProperties * @see #getClientProperties * @see #getClientProperty */ public final void putClientProperty(Object key, Object value) { Hashtable t = getClientProperties(); Object old = t.get(key); if (value != null) t.put(key, value); else t.remove(key); firePropertyChange(key.toString(), old, value); } /** * Unregister an <code>AncestorListener</code>. * * @param listener The listener to unregister * * @see #addAncestorListener */ public void removeAncestorListener(AncestorListener listener) { listenerList.remove(AncestorListener.class, listener); } /** * Unregister a <code>VetoableChangeChangeListener</code>. * * @param listener The listener to unregister * * @see #addVetoableChangeListener */ public void removeVetoableChangeListener(VetoableChangeListener listener) { listenerList.remove(VetoableChangeListener.class, listener); } /** * Register an <code>AncestorListener</code>. * * @param listener The listener to register * * @see #removeVetoableChangeListener */ public void addAncestorListener(AncestorListener listener) { listenerList.add(AncestorListener.class, listener); } /** * Register a <code>PropertyChangeListener</code> for a specific, named * property. To listen to all property changes, regardless of name, use * {@link #addPropertyChangeListener(PropertyChangeListener)} instead. * * @param propertyName The property name to listen to * @param listener The listener to register * * @see #removePropertyChangeListener(String, PropertyChangeListener) * @see #changeSupport */ public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { listenerList.add(PropertyChangeListener.class, listener); } /** * Register a <code>VetoableChangeListener</code>. * * @param listener The listener to register * * @see #removeVetoableChangeListener * @see #listenerList */ public void addVetoableChangeListener(VetoableChangeListener listener) { listenerList.add(VetoableChangeListener.class, listener); } /** * Returns all registered {@link EventListener}s of the given * <code>listenerType</code>. * * @param listenerType the class of listeners to filter (<code>null</code> * not permitted). * * @return An array of registered listeners. * * @throws ClassCastException if <code>listenerType</code> does not implement * the {@link EventListener} interface. * @throws NullPointerException if <code>listenerType</code> is * <code>null</code>. * * @see #getAncestorListeners() * @see #listenerList * * @since 1.3 */ public EventListener[] getListeners(Class listenerType) { if (listenerType == PropertyChangeListener.class) return getPropertyChangeListeners(); else return listenerList.getListeners(listenerType); } /** * Return all registered <code>AncestorListener</code> objects. * * @return The set of <code>AncestorListener</code> objects in {@link * #listenerList} */ public AncestorListener[] getAncestorListeners() { return (AncestorListener[]) getListeners(AncestorListener.class); } /** * Return all registered <code>VetoableChangeListener</code> objects. * * @return The set of <code>VetoableChangeListener</code> objects in {@link * #listenerList} */ public VetoableChangeListener[] getVetoableChangeListeners() { return (VetoableChangeListener[]) getListeners(VetoableChangeListener.class); } /** * A variant of {@link #firePropertyChange(String,Object,Object)} * for properties with <code>boolean</code> values. * * @specnote It seems that in JDK1.5 all property related methods have been * moved to java.awt.Component, except this and 2 others. We call * super here. I guess this will also be removed in one of the next * releases. */ public void firePropertyChange(String propertyName, boolean oldValue, boolean newValue) { super.firePropertyChange(propertyName, oldValue, newValue); } /** * A variant of {@link #firePropertyChange(String,Object,Object)} * for properties with <code>char</code> values. * * @specnote It seems that in JDK1.5 all property related methods have been * moved to java.awt.Component, except this and 2 others. We call * super here. I guess this will also be removed in one of the next * releases. */ public void firePropertyChange(String propertyName, char oldValue, char newValue) { super.firePropertyChange(propertyName, oldValue, newValue); } /** * A variant of {@link #firePropertyChange(String,Object,Object)} * for properties with <code>int</code> values. * * @specnote It seems that in JDK1.5 all property related methods have been * moved to java.awt.Component, except this and 2 others. We call * super here. I guess this will also be removed in one of the next * releases. */ public void firePropertyChange(String propertyName, int oldValue, int newValue) { super.firePropertyChange(propertyName, oldValue, newValue); } /** * Call {@link VetoableChangeListener#vetoableChange} on all listeners * registered to listen to a given property. Any method which changes * the specified property of this component should call this method. * * @param propertyName The property which changed
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?