0N/A/*
5638N/A * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/Apackage javax.swing;
0N/A
0N/A
0N/Aimport java.util.HashSet;
0N/Aimport java.util.Hashtable;
0N/Aimport java.util.Dictionary;
0N/Aimport java.util.Enumeration;
0N/Aimport java.util.Locale;
0N/Aimport java.util.Vector;
0N/Aimport java.util.EventListener;
0N/Aimport java.util.Set;
0N/Aimport java.util.Map;
0N/Aimport java.util.HashMap;
0N/A
0N/Aimport java.awt.*;
0N/Aimport java.awt.event.*;
0N/Aimport java.awt.image.VolatileImage;
0N/Aimport java.awt.Graphics2D;
0N/Aimport java.awt.peer.LightweightPeer;
0N/Aimport java.awt.dnd.DropTarget;
0N/Aimport java.awt.font.FontRenderContext;
243N/Aimport java.beans.PropertyChangeListener;
243N/Aimport java.beans.VetoableChangeListener;
243N/Aimport java.beans.VetoableChangeSupport;
243N/Aimport java.beans.Transient;
0N/A
0N/Aimport java.applet.Applet;
0N/A
0N/Aimport java.io.Serializable;
0N/Aimport java.io.ObjectOutputStream;
0N/Aimport java.io.ObjectInputStream;
0N/Aimport java.io.IOException;
0N/Aimport java.io.ObjectInputValidation;
0N/Aimport java.io.InvalidObjectException;
0N/A
0N/Aimport javax.swing.border.*;
0N/Aimport javax.swing.event.*;
0N/Aimport javax.swing.plaf.*;
0N/Aimport static javax.swing.ClientPropertyKey.*;
0N/Aimport javax.accessibility.*;
0N/A
0N/Aimport sun.swing.SwingUtilities2;
0N/Aimport sun.swing.UIClientPropertyKey;
0N/A
0N/A/**
0N/A * The base class for all Swing components except top-level containers.
0N/A * To use a component that inherits from <code>JComponent</code>,
0N/A * you must place the component in a containment hierarchy
0N/A * whose root is a top-level Swing container.
0N/A * Top-level Swing containers --
0N/A * such as <code>JFrame</code>, <code>JDialog</code>,
0N/A * and <code>JApplet</code> --
0N/A * are specialized components
0N/A * that provide a place for other Swing components to paint themselves.
0N/A * For an explanation of containment hierarchies, see
0N/A * <a
0N/A href="http://java.sun.com/docs/books/tutorial/uiswing/overview/hierarchy.html">Swing Components and the Containment Hierarchy</a>,
0N/A * a section in <em>The Java Tutorial</em>.
0N/A *
0N/A * <p>
0N/A * The <code>JComponent</code> class provides:
0N/A * <ul>
0N/A * <li>The base class for both standard and custom components
0N/A * that use the Swing architecture.
0N/A * <li>A "pluggable look and feel" (L&F) that can be specified by the
0N/A * programmer or (optionally) selected by the user at runtime.
0N/A * The look and feel for each component is provided by a
0N/A * <em>UI delegate</em> -- an object that descends from
0N/A * {@link javax.swing.plaf.ComponentUI}.
0N/A * See <a
0N/A * href="http://java.sun.com/docs/books/tutorial/uiswing/misc/plaf.html">How
0N/A * to Set the Look and Feel</a>
0N/A * in <em>The Java Tutorial</em>
0N/A * for more information.
0N/A * <li>Comprehensive keystroke handling.
0N/A * See the document <a
0N/A * href="http://java.sun.com/products/jfc/tsc/special_report/kestrel/keybindings.html">Keyboard
0N/A * Bindings in Swing</a>,
0N/A * an article in <em>The Swing Connection</em>,
0N/A * for more information.
0N/A * <li>Support for tool tips --
0N/A * short descriptions that pop up when the cursor lingers
0N/A * over a component.
0N/A * See <a
0N/A * href="http://java.sun.com/docs/books/tutorial/uiswing/components/tooltip.html">How
0N/A * to Use Tool Tips</a>
0N/A * in <em>The Java Tutorial</em>
0N/A * for more information.
0N/A * <li>Support for accessibility.
0N/A * <code>JComponent</code> contains all of the methods in the
0N/A * <code>Accessible</code> interface,
0N/A * but it doesn't actually implement the interface. That is the
0N/A * responsibility of the individual classes
0N/A * that extend <code>JComponent</code>.
0N/A * <li>Support for component-specific properties.
0N/A * With the {@link #putClientProperty}
0N/A * and {@link #getClientProperty} methods,
0N/A * you can associate name-object pairs
0N/A * with any object that descends from <code>JComponent</code>.
0N/A * <li>An infrastructure for painting
0N/A * that includes double buffering and support for borders.
0N/A * For more information see <a
0N/A * href="http://java.sun.com/docs/books/tutorial/uiswing/overview/draw.html">Painting</a> and
0N/A * <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/border.html">How
0N/A * to Use Borders</a>,
0N/A * both of which are sections in <em>The Java Tutorial</em>.
0N/A * </ul>
0N/A * For more information on these subjects, see the
0N/A * <a href="package-summary.html#package_description">Swing package description</a>
0N/A * and <em>The Java Tutorial</em> section
0N/A * <a href="http://java.sun.com/docs/books/tutorial/uiswing/components/jcomponent.html">The JComponent Class</a>.
0N/A * <p>
0N/A * <code>JComponent</code> and its subclasses document default values
0N/A * for certain properties. For example, <code>JTable</code> documents the
0N/A * default row height as 16. Each <code>JComponent</code> subclass
0N/A * that has a <code>ComponentUI</code> will create the
0N/A * <code>ComponentUI</code> as part of its constructor. In order
0N/A * to provide a particular look and feel each
0N/A * <code>ComponentUI</code> may set properties back on the
0N/A * <code>JComponent</code> that created it. For example, a custom
0N/A * look and feel may require <code>JTable</code>s to have a row
0N/A * height of 24. The documented defaults are the value of a property
0N/A * BEFORE the <code>ComponentUI</code> has been installed. If you
0N/A * need a specific value for a particular property you should
0N/A * explicitly set it.
0N/A * <p>
0N/A * In release 1.4, the focus subsystem was rearchitected.
0N/A * For more information, see
0N/A * <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html">
0N/A * How to Use the Focus Subsystem</a>,
0N/A * a section in <em>The Java Tutorial</em>.
0N/A * <p>
0N/A * <strong>Warning:</strong> Swing is not thread safe. For more
0N/A * information see <a
0N/A * href="package-summary.html#threading">Swing's Threading
0N/A * Policy</a>.
0N/A * <p>
0N/A * <strong>Warning:</strong>
0N/A * Serialized objects of this class will not be compatible with
0N/A * future Swing releases. The current serialization support is
0N/A * appropriate for short term storage or RMI between applications running
0N/A * the same version of Swing. As of 1.4, support for long term storage
0N/A * of all JavaBeans<sup><font size="-2">TM</font></sup>
0N/A * has been added to the <code>java.beans</code> package.
0N/A * Please see {@link java.beans.XMLEncoder}.
0N/A *
0N/A * @see KeyStroke
0N/A * @see Action
0N/A * @see #setBorder
0N/A * @see #registerKeyboardAction
0N/A * @see JOptionPane
0N/A * @see #setDebugGraphicsOptions
0N/A * @see #setToolTipText
0N/A * @see #setAutoscrolls
0N/A *
0N/A * @author Hans Muller
0N/A * @author Arnaud Weber
0N/A */
0N/Apublic abstract class JComponent extends Container implements Serializable,
0N/A TransferHandler.HasGetTransferHandler
0N/A{
0N/A /**
0N/A * @see #getUIClassID
0N/A * @see #writeObject
0N/A */
0N/A private static final String uiClassID = "ComponentUI";
0N/A
0N/A /**
0N/A * @see #readObject
0N/A */
625N/A private static final Hashtable<ObjectInputStream, ReadObjectCallback> readObjectCallbacks =
625N/A new Hashtable<ObjectInputStream, ReadObjectCallback>(1);
0N/A
0N/A /**
0N/A * Keys to use for forward focus traversal when the JComponent is
0N/A * managing focus.
0N/A */
0N/A private static Set<KeyStroke> managingFocusForwardTraversalKeys;
0N/A
0N/A /**
0N/A * Keys to use for backward focus traversal when the JComponent is
0N/A * managing focus.
0N/A */
0N/A private static Set<KeyStroke> managingFocusBackwardTraversalKeys;
0N/A
0N/A // Following are the possible return values from getObscuredState.
0N/A private static final int NOT_OBSCURED = 0;
0N/A private static final int PARTIALLY_OBSCURED = 1;
0N/A private static final int COMPLETELY_OBSCURED = 2;
0N/A
0N/A /**
0N/A * Set to true when DebugGraphics has been loaded.
0N/A */
0N/A static boolean DEBUG_GRAPHICS_LOADED;
0N/A
0N/A /**
0N/A * Key used to look up a value from the AppContext to determine the
0N/A * JComponent the InputVerifier is running for. That is, if
0N/A * AppContext.get(INPUT_VERIFIER_SOURCE_KEY) returns non-null, it
0N/A * indicates the EDT is calling into the InputVerifier from the
0N/A * returned component.
0N/A */
0N/A private static final Object INPUT_VERIFIER_SOURCE_KEY =
0N/A new StringBuilder("InputVerifierSourceKey");
0N/A
0N/A /* The following fields support set methods for the corresponding
0N/A * java.awt.Component properties.
0N/A */
0N/A private boolean isAlignmentXSet;
0N/A private float alignmentX;
0N/A private boolean isAlignmentYSet;
0N/A private float alignmentY;
0N/A
0N/A /**
0N/A * Backing store for JComponent properties and listeners
0N/A */
0N/A
0N/A /** The look and feel delegate for this component. */
0N/A protected transient ComponentUI ui;
0N/A /** A list of event listeners for this component. */
0N/A protected EventListenerList listenerList = new EventListenerList();
0N/A
0N/A private transient ArrayTable clientProperties;
0N/A private VetoableChangeSupport vetoableChangeSupport;
0N/A /**
0N/A * Whether or not autoscroll has been enabled.
0N/A */
0N/A private boolean autoscrolls;
0N/A private Border border;
0N/A private int flags;
0N/A
0N/A /* Input verifier for this component */
0N/A private InputVerifier inputVerifier = null;
0N/A
0N/A private boolean verifyInputWhenFocusTarget = true;
0N/A
0N/A /**
0N/A * Set in <code>_paintImmediately</code>.
0N/A * Will indicate the child that initiated the painting operation.
0N/A * If <code>paintingChild</code> is opaque, no need to paint
0N/A * any child components after <code>paintingChild</code>.
0N/A * Test used in <code>paintChildren</code>.
0N/A */
0N/A transient Component paintingChild;
0N/A
0N/A /**
0N/A * Constant used for <code>registerKeyboardAction</code> that
0N/A * means that the command should be invoked when
0N/A * the component has the focus.
0N/A */
0N/A public static final int WHEN_FOCUSED = 0;
0N/A
0N/A /**
0N/A * Constant used for <code>registerKeyboardAction</code> that
0N/A * means that the command should be invoked when the receiving
0N/A * component is an ancestor of the focused component or is
0N/A * itself the focused component.
0N/A */
0N/A public static final int WHEN_ANCESTOR_OF_FOCUSED_COMPONENT = 1;
0N/A
0N/A /**
0N/A * Constant used for <code>registerKeyboardAction</code> that
0N/A * means that the command should be invoked when
0N/A * the receiving component is in the window that has the focus
0N/A * or is itself the focused component.
0N/A */
0N/A public static final int WHEN_IN_FOCUSED_WINDOW = 2;
0N/A
0N/A /**
0N/A * Constant used by some of the APIs to mean that no condition is defined.
0N/A */
0N/A public static final int UNDEFINED_CONDITION = -1;
0N/A
0N/A /**
0N/A * The key used by <code>JComponent</code> to access keyboard bindings.
0N/A */
0N/A private static final String KEYBOARD_BINDINGS_KEY = "_KeyboardBindings";
0N/A
0N/A /**
0N/A * An array of <code>KeyStroke</code>s used for
0N/A * <code>WHEN_IN_FOCUSED_WINDOW</code> are stashed
0N/A * in the client properties under this string.
0N/A */
0N/A private static final String WHEN_IN_FOCUSED_WINDOW_BINDINGS = "_WhenInFocusedWindow";
0N/A
0N/A /**
0N/A * The comment to display when the cursor is over the component,
0N/A * also known as a "value tip", "flyover help", or "flyover label".
0N/A */
0N/A public static final String TOOL_TIP_TEXT_KEY = "ToolTipText";
0N/A
0N/A private static final String NEXT_FOCUS = "nextFocus";
0N/A
0N/A /**
0N/A * <code>JPopupMenu</code> assigned to this component
0N/A * and all of its childrens
0N/A */
0N/A private JPopupMenu popupMenu;
0N/A
0N/A /** Private flags **/
0N/A private static final int IS_DOUBLE_BUFFERED = 0;
0N/A private static final int ANCESTOR_USING_BUFFER = 1;
0N/A private static final int IS_PAINTING_TILE = 2;
0N/A private static final int IS_OPAQUE = 3;
0N/A private static final int KEY_EVENTS_ENABLED = 4;
0N/A private static final int FOCUS_INPUTMAP_CREATED = 5;
0N/A private static final int ANCESTOR_INPUTMAP_CREATED = 6;
0N/A private static final int WIF_INPUTMAP_CREATED = 7;
0N/A private static final int ACTIONMAP_CREATED = 8;
0N/A private static final int CREATED_DOUBLE_BUFFER = 9;
0N/A // bit 10 is free
0N/A private static final int IS_PRINTING = 11;
0N/A private static final int IS_PRINTING_ALL = 12;
0N/A private static final int IS_REPAINTING = 13;
0N/A /** Bits 14-21 are used to handle nested writeObject calls. **/
0N/A private static final int WRITE_OBJ_COUNTER_FIRST = 14;
0N/A private static final int RESERVED_1 = 15;
0N/A private static final int RESERVED_2 = 16;
0N/A private static final int RESERVED_3 = 17;
0N/A private static final int RESERVED_4 = 18;
0N/A private static final int RESERVED_5 = 19;
0N/A private static final int RESERVED_6 = 20;
0N/A private static final int WRITE_OBJ_COUNTER_LAST = 21;
0N/A
0N/A private static final int REQUEST_FOCUS_DISABLED = 22;
0N/A private static final int INHERITS_POPUP_MENU = 23;
0N/A private static final int OPAQUE_SET = 24;
0N/A private static final int AUTOSCROLLS_SET = 25;
0N/A private static final int FOCUS_TRAVERSAL_KEYS_FORWARD_SET = 26;
0N/A private static final int FOCUS_TRAVERSAL_KEYS_BACKWARD_SET = 27;
0N/A private static final int REVALIDATE_RUNNABLE_SCHEDULED = 28;
0N/A
0N/A /**
0N/A * Temporary rectangles.
0N/A */
625N/A private static java.util.List<Rectangle> tempRectangles = new java.util.ArrayList<Rectangle>(11);
0N/A
0N/A /** Used for <code>WHEN_FOCUSED</code> bindings. */
0N/A private InputMap focusInputMap;
0N/A /** Used for <code>WHEN_ANCESTOR_OF_FOCUSED_COMPONENT</code> bindings. */
0N/A private InputMap ancestorInputMap;
0N/A /** Used for <code>WHEN_IN_FOCUSED_KEY</code> bindings. */
0N/A private ComponentInputMap windowInputMap;
0N/A
0N/A /** ActionMap. */
0N/A private ActionMap actionMap;
0N/A
0N/A /** Key used to store the default locale in an AppContext **/
0N/A private static final String defaultLocale = "JComponent.defaultLocale";
0N/A
0N/A private static Component componentObtainingGraphicsFrom;
0N/A private static Object componentObtainingGraphicsFromLock = new
0N/A StringBuilder("componentObtainingGraphicsFrom");
0N/A
0N/A /**
0N/A * AA text hints.
0N/A */
0N/A transient private Object aaTextInfo;
0N/A
0N/A static Graphics safelyGetGraphics(Component c) {
0N/A return safelyGetGraphics(c, SwingUtilities.getRoot(c));
0N/A }
0N/A
0N/A static Graphics safelyGetGraphics(Component c, Component root) {
0N/A synchronized(componentObtainingGraphicsFromLock) {
0N/A componentObtainingGraphicsFrom = root;
0N/A Graphics g = c.getGraphics();
0N/A componentObtainingGraphicsFrom = null;
0N/A return g;
0N/A }
0N/A }
0N/A
0N/A static void getGraphicsInvoked(Component root) {
0N/A if (!JComponent.isComponentObtainingGraphicsFrom(root)) {
0N/A JRootPane rootPane = ((RootPaneContainer)root).getRootPane();
0N/A if (rootPane != null) {
0N/A rootPane.disableTrueDoubleBuffering();
0N/A }
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns true if {@code c} is the component the graphics is being
0N/A * requested of. This is intended for use when getGraphics is invoked.
0N/A */
0N/A private static boolean isComponentObtainingGraphicsFrom(Component c) {
0N/A synchronized(componentObtainingGraphicsFromLock) {
0N/A return (componentObtainingGraphicsFrom == c);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the Set of <code>KeyStroke</code>s to use if the component
0N/A * is managing focus for forward focus traversal.
0N/A */
0N/A static Set<KeyStroke> getManagingFocusForwardTraversalKeys() {
0N/A synchronized(JComponent.class) {
0N/A if (managingFocusForwardTraversalKeys == null) {
0N/A managingFocusForwardTraversalKeys = new HashSet<KeyStroke>(1);
0N/A managingFocusForwardTraversalKeys.add(
0N/A KeyStroke.getKeyStroke(KeyEvent.VK_TAB,
0N/A InputEvent.CTRL_MASK));
0N/A }
0N/A }
0N/A return managingFocusForwardTraversalKeys;
0N/A }
0N/A
0N/A /**
0N/A * Returns the Set of <code>KeyStroke</code>s to use if the component
0N/A * is managing focus for backward focus traversal.
0N/A */
0N/A static Set<KeyStroke> getManagingFocusBackwardTraversalKeys() {
0N/A synchronized(JComponent.class) {
0N/A if (managingFocusBackwardTraversalKeys == null) {
0N/A managingFocusBackwardTraversalKeys = new HashSet<KeyStroke>(1);
0N/A managingFocusBackwardTraversalKeys.add(
0N/A KeyStroke.getKeyStroke(KeyEvent.VK_TAB,
0N/A InputEvent.SHIFT_MASK |
0N/A InputEvent.CTRL_MASK));
0N/A }
0N/A }
0N/A return managingFocusBackwardTraversalKeys;
0N/A }
0N/A
0N/A private static Rectangle fetchRectangle() {
0N/A synchronized(tempRectangles) {
0N/A Rectangle rect;
0N/A int size = tempRectangles.size();
0N/A if (size > 0) {
625N/A rect = tempRectangles.remove(size - 1);
0N/A }
0N/A else {
0N/A rect = new Rectangle(0, 0, 0, 0);
0N/A }
0N/A return rect;
0N/A }
0N/A }
0N/A
0N/A private static void recycleRectangle(Rectangle rect) {
0N/A synchronized(tempRectangles) {
0N/A tempRectangles.add(rect);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets whether or not <code>getComponentPopupMenu</code> should delegate
0N/A * to the parent if this component does not have a <code>JPopupMenu</code>
0N/A * assigned to it.
0N/A * <p>
0N/A * The default value for this is false, but some <code>JComponent</code>
0N/A * subclasses that are implemented as a number of <code>JComponent</code>s
0N/A * may set this to true.
0N/A * <p>
0N/A * This is a bound property.
0N/A *
0N/A * @param value whether or not the JPopupMenu is inherited
0N/A * @see #setComponentPopupMenu
0N/A * @beaninfo
0N/A * bound: true
0N/A * description: Whether or not the JPopupMenu is inherited
0N/A * @since 1.5
0N/A */
0N/A public void setInheritsPopupMenu(boolean value) {
0N/A boolean oldValue = getFlag(INHERITS_POPUP_MENU);
0N/A setFlag(INHERITS_POPUP_MENU, value);
0N/A firePropertyChange("inheritsPopupMenu", oldValue, value);
0N/A }
0N/A
0N/A /**
0N/A * Returns true if the JPopupMenu should be inherited from the parent.
0N/A *
0N/A * @see #setComponentPopupMenu
0N/A * @since 1.5
0N/A */
0N/A public boolean getInheritsPopupMenu() {
0N/A return getFlag(INHERITS_POPUP_MENU);
0N/A }
0N/A
0N/A /**
0N/A * Sets the <code>JPopupMenu</code> for this <code>JComponent</code>.
0N/A * The UI is responsible for registering bindings and adding the necessary
0N/A * listeners such that the <code>JPopupMenu</code> will be shown at
0N/A * the appropriate time. When the <code>JPopupMenu</code> is shown
0N/A * depends upon the look and feel: some may show it on a mouse event,
0N/A * some may enable a key binding.
0N/A * <p>
0N/A * If <code>popup</code> is null, and <code>getInheritsPopupMenu</code>
0N/A * returns true, then <code>getComponentPopupMenu</code> will be delegated
0N/A * to the parent. This provides for a way to make all child components
0N/A * inherit the popupmenu of the parent.
0N/A * <p>
0N/A * This is a bound property.
0N/A *
0N/A * @param popup - the popup that will be assigned to this component
0N/A * may be null
0N/A * @see #getComponentPopupMenu
0N/A * @beaninfo
0N/A * bound: true
0N/A * preferred: true
0N/A * description: Popup to show
0N/A * @since 1.5
0N/A */
0N/A public void setComponentPopupMenu(JPopupMenu popup) {
0N/A if(popup != null) {
0N/A enableEvents(AWTEvent.MOUSE_EVENT_MASK);
0N/A }
0N/A JPopupMenu oldPopup = this.popupMenu;
0N/A this.popupMenu = popup;
0N/A firePropertyChange("componentPopupMenu", oldPopup, popup);
0N/A }
0N/A
0N/A /**
0N/A * Returns <code>JPopupMenu</code> that assigned for this component.
0N/A * If this component does not have a <code>JPopupMenu</code> assigned
0N/A * to it and <code>getInheritsPopupMenu</code> is true, this
0N/A * will return <code>getParent().getComponentPopupMenu()</code> (assuming
0N/A * the parent is valid.)
0N/A *
0N/A * @return <code>JPopupMenu</code> assigned for this component
0N/A * or <code>null</code> if no popup assigned
0N/A * @see #setComponentPopupMenu
0N/A * @since 1.5
0N/A */
0N/A public JPopupMenu getComponentPopupMenu() {
0N/A
0N/A if(!getInheritsPopupMenu()) {
0N/A return popupMenu;
0N/A }
0N/A
0N/A if(popupMenu == null) {
0N/A // Search parents for its popup
0N/A Container parent = getParent();
0N/A while (parent != null) {
0N/A if(parent instanceof JComponent) {
0N/A return ((JComponent)parent).getComponentPopupMenu();
0N/A }
0N/A if(parent instanceof Window ||
0N/A parent instanceof Applet) {
0N/A // Reached toplevel, break and return null
0N/A break;
0N/A }
0N/A parent = parent.getParent();
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A return popupMenu;
0N/A }
0N/A
0N/A /**
0N/A * Default <code>JComponent</code> constructor. This constructor does
0N/A * very little initialization beyond calling the <code>Container</code>
0N/A * constructor. For example, the initial layout manager is
0N/A * <code>null</code>. It does, however, set the component's locale
0N/A * property to the value returned by
0N/A * <code>JComponent.getDefaultLocale</code>.
0N/A *
0N/A * @see #getDefaultLocale
0N/A */
0N/A public JComponent() {
0N/A super();
0N/A // We enable key events on all JComponents so that accessibility
0N/A // bindings will work everywhere. This is a partial fix to BugID
0N/A // 4282211.
0N/A enableEvents(AWTEvent.KEY_EVENT_MASK);
0N/A if (isManagingFocus()) {
0N/A LookAndFeel.installProperty(this,
0N/A "focusTraversalKeysForward",
0N/A getManagingFocusForwardTraversalKeys());
0N/A LookAndFeel.installProperty(this,
0N/A "focusTraversalKeysBackward",
0N/A getManagingFocusBackwardTraversalKeys());
0N/A }
0N/A
0N/A super.setLocale( JComponent.getDefaultLocale() );
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Resets the UI property to a value from the current look and feel.
0N/A * <code>JComponent</code> subclasses must override this method
0N/A * like this:
0N/A * <pre>
0N/A * public void updateUI() {
0N/A * setUI((SliderUI)UIManager.getUI(this);
0N/A * }
0N/A * </pre>
0N/A *
0N/A * @see #setUI
0N/A * @see UIManager#getLookAndFeel
0N/A * @see UIManager#getUI
0N/A */
0N/A public void updateUI() {}
0N/A
0N/A
0N/A /**
0N/A * Sets the look and feel delegate for this component.
0N/A * <code>JComponent</code> subclasses generally override this method
0N/A * to narrow the argument type. For example, in <code>JSlider</code>:
0N/A * <pre>
0N/A * public void setUI(SliderUI newUI) {
0N/A * super.setUI(newUI);
0N/A * }
0N/A * </pre>
0N/A * <p>
0N/A * Additionally <code>JComponent</code> subclasses must provide a
0N/A * <code>getUI</code> method that returns the correct type. For example:
0N/A * <pre>
0N/A * public SliderUI getUI() {
0N/A * return (SliderUI)ui;
0N/A * }
0N/A * </pre>
0N/A *
0N/A * @param newUI the new UI delegate
0N/A * @see #updateUI
0N/A * @see UIManager#getLookAndFeel
0N/A * @see UIManager#getUI
0N/A * @beaninfo
0N/A * bound: true
0N/A * hidden: true
0N/A * attribute: visualUpdate true
0N/A * description: The component's look and feel delegate.
0N/A */
0N/A protected void setUI(ComponentUI newUI) {
0N/A /* We do not check that the UI instance is different
0N/A * before allowing the switch in order to enable the
0N/A * same UI instance *with different default settings*
0N/A * to be installed.
0N/A */
0N/A
0N/A uninstallUIAndProperties();
0N/A
0N/A // aaText shouldn't persist between look and feels, reset it.
0N/A aaTextInfo =
0N/A UIManager.getDefaults().get(SwingUtilities2.AA_TEXT_PROPERTY_KEY);
0N/A ComponentUI oldUI = ui;
0N/A ui = newUI;
0N/A if (ui != null) {
0N/A ui.installUI(this);
0N/A }
0N/A
0N/A firePropertyChange("UI", oldUI, newUI);
0N/A revalidate();
0N/A repaint();
0N/A }
0N/A
0N/A /**
0N/A * Uninstalls the UI, if any, and any client properties designated
0N/A * as being specific to the installed UI - instances of
0N/A * {@code UIClientPropertyKey}.
0N/A */
0N/A private void uninstallUIAndProperties() {
0N/A if (ui != null) {
0N/A ui.uninstallUI(this);
0N/A //clean UIClientPropertyKeys from client properties
0N/A if (clientProperties != null) {
0N/A synchronized(clientProperties) {
0N/A Object[] clientPropertyKeys =
0N/A clientProperties.getKeys(null);
0N/A if (clientPropertyKeys != null) {
0N/A for (Object key : clientPropertyKeys) {
0N/A if (key instanceof UIClientPropertyKey) {
0N/A putClientProperty(key, null);
0N/A }
0N/A }
0N/A }
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the <code>UIDefaults</code> key used to
0N/A * look up the name of the <code>swing.plaf.ComponentUI</code>
0N/A * class that defines the look and feel
0N/A * for this component. Most applications will never need to
0N/A * call this method. Subclasses of <code>JComponent</code> that support
0N/A * pluggable look and feel should override this method to
0N/A * return a <code>UIDefaults</code> key that maps to the
0N/A * <code>ComponentUI</code> subclass that defines their look and feel.
0N/A *
0N/A * @return the <code>UIDefaults</code> key for a
0N/A * <code>ComponentUI</code> subclass
0N/A * @see UIDefaults#getUI
0N/A * @beaninfo
0N/A * expert: true
0N/A * description: UIClassID
0N/A */
0N/A public String getUIClassID() {
0N/A return uiClassID;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the graphics object used to paint this component.
0N/A * If <code>DebugGraphics</code> is turned on we create a new
0N/A * <code>DebugGraphics</code> object if necessary.
0N/A * Otherwise we just configure the
0N/A * specified graphics object's foreground and font.
0N/A *
0N/A * @param g the original <code>Graphics</code> object
0N/A * @return a <code>Graphics</code> object configured for this component
0N/A */
0N/A protected Graphics getComponentGraphics(Graphics g) {
0N/A Graphics componentGraphics = g;
0N/A if (ui != null && DEBUG_GRAPHICS_LOADED) {
0N/A if ((DebugGraphics.debugComponentCount() != 0) &&
0N/A (shouldDebugGraphics() != 0) &&
0N/A !(g instanceof DebugGraphics)) {
0N/A componentGraphics = new DebugGraphics(g,this);
0N/A }
0N/A }
0N/A componentGraphics.setColor(getForeground());
0N/A componentGraphics.setFont(getFont());
0N/A
0N/A return componentGraphics;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Calls the UI delegate's paint method, if the UI delegate
0N/A * is non-<code>null</code>. We pass the delegate a copy of the
0N/A * <code>Graphics</code> object to protect the rest of the
0N/A * paint code from irrevocable changes
0N/A * (for example, <code>Graphics.translate</code>).
0N/A * <p>
0N/A * If you override this in a subclass you should not make permanent
0N/A * changes to the passed in <code>Graphics</code>. For example, you
0N/A * should not alter the clip <code>Rectangle</code> or modify the
0N/A * transform. If you need to do these operations you may find it
0N/A * easier to create a new <code>Graphics</code> from the passed in
0N/A * <code>Graphics</code> and manipulate it. Further, if you do not
0N/A * invoker super's implementation you must honor the opaque property,
0N/A * that is
0N/A * if this component is opaque, you must completely fill in the background
0N/A * in a non-opaque color. If you do not honor the opaque property you
0N/A * will likely see visual artifacts.
0N/A * <p>
0N/A * The passed in <code>Graphics</code> object might
0N/A * have a transform other than the identify transform
0N/A * installed on it. In this case, you might get
0N/A * unexpected results if you cumulatively apply
0N/A * another transform.
0N/A *
0N/A * @param g the <code>Graphics</code> object to protect
0N/A * @see #paint
0N/A * @see ComponentUI
0N/A */
0N/A protected void paintComponent(Graphics g) {
0N/A if (ui != null) {
0N/A Graphics scratchGraphics = (g == null) ? null : g.create();
0N/A try {
0N/A ui.update(scratchGraphics, this);
0N/A }
0N/A finally {
0N/A scratchGraphics.dispose();
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Paints this component's children.
0N/A * If <code>shouldUseBuffer</code> is true,
0N/A * no component ancestor has a buffer and
0N/A * the component children can use a buffer if they have one.
0N/A * Otherwise, one ancestor has a buffer currently in use and children
0N/A * should not use a buffer to paint.
0N/A * @param g the <code>Graphics</code> context in which to paint
0N/A * @see #paint
0N/A * @see java.awt.Container#paint
0N/A */
0N/A protected void paintChildren(Graphics g) {
0N/A Graphics sg = g;
0N/A
0N/A synchronized(getTreeLock()) {
0N/A int i = getComponentCount() - 1;
0N/A if (i < 0) {
0N/A return;
0N/A }
0N/A // If we are only to paint to a specific child, determine
0N/A // its index.
0N/A if (paintingChild != null &&
0N/A (paintingChild instanceof JComponent) &&
625N/A paintingChild.isOpaque()) {
0N/A for (; i >= 0; i--) {
0N/A if (getComponent(i) == paintingChild){
0N/A break;
0N/A }
0N/A }
0N/A }
0N/A Rectangle tmpRect = fetchRectangle();
0N/A boolean checkSiblings = (!isOptimizedDrawingEnabled() &&
0N/A checkIfChildObscuredBySibling());
0N/A Rectangle clipBounds = null;
0N/A if (checkSiblings) {
0N/A clipBounds = sg.getClipBounds();
0N/A if (clipBounds == null) {
0N/A clipBounds = new Rectangle(0, 0, getWidth(),
0N/A getHeight());
0N/A }
0N/A }
0N/A boolean printing = getFlag(IS_PRINTING);
1892N/A final Window window = SwingUtilities.getWindowAncestor(this);
1892N/A final boolean isWindowOpaque = window == null || window.isOpaque();
0N/A for (; i >= 0 ; i--) {
0N/A Component comp = getComponent(i);
1892N/A if (comp == null) {
1892N/A continue;
1892N/A }
1892N/A
1892N/A final boolean isJComponent = comp instanceof JComponent;
1892N/A
1892N/A // Enable painting of heavyweights in non-opaque windows.
1892N/A // See 6884960
1892N/A if ((!isWindowOpaque || isJComponent ||
1892N/A isLightweightComponent(comp)) && comp.isVisible())
1892N/A {
0N/A Rectangle cr;
0N/A
0N/A cr = comp.getBounds(tmpRect);
0N/A
0N/A boolean hitClip = g.hitClip(cr.x, cr.y, cr.width,
0N/A cr.height);
0N/A
0N/A if (hitClip) {
0N/A if (checkSiblings && i > 0) {
0N/A int x = cr.x;
0N/A int y = cr.y;
0N/A int width = cr.width;
0N/A int height = cr.height;
0N/A SwingUtilities.computeIntersection
0N/A (clipBounds.x, clipBounds.y,
0N/A clipBounds.width, clipBounds.height, cr);
0N/A
0N/A if(getObscuredState(i, cr.x, cr.y, cr.width,
0N/A cr.height) == COMPLETELY_OBSCURED) {
0N/A continue;
0N/A }
0N/A cr.x = x;
0N/A cr.y = y;
0N/A cr.width = width;
0N/A cr.height = height;
0N/A }
0N/A Graphics cg = sg.create(cr.x, cr.y, cr.width,
0N/A cr.height);
0N/A cg.setColor(comp.getForeground());
0N/A cg.setFont(comp.getFont());
0N/A boolean shouldSetFlagBack = false;
0N/A try {
0N/A if(isJComponent) {
0N/A if(getFlag(ANCESTOR_USING_BUFFER)) {
0N/A ((JComponent)comp).setFlag(
0N/A ANCESTOR_USING_BUFFER,true);
0N/A shouldSetFlagBack = true;
0N/A }
0N/A if(getFlag(IS_PAINTING_TILE)) {
0N/A ((JComponent)comp).setFlag(
0N/A IS_PAINTING_TILE,true);
0N/A shouldSetFlagBack = true;
0N/A }
0N/A if(!printing) {
625N/A comp.paint(cg);
0N/A }
0N/A else {
0N/A if (!getFlag(IS_PRINTING_ALL)) {
0N/A comp.print(cg);
0N/A }
0N/A else {
0N/A comp.printAll(cg);
0N/A }
0N/A }
0N/A } else {
1892N/A // The component is either lightweight, or
1892N/A // heavyweight in a non-opaque window
0N/A if (!printing) {
0N/A comp.paint(cg);
0N/A }
0N/A else {
0N/A if (!getFlag(IS_PRINTING_ALL)) {
0N/A comp.print(cg);
0N/A }
0N/A else {
0N/A comp.printAll(cg);
0N/A }
0N/A }
0N/A }
0N/A } finally {
0N/A cg.dispose();
0N/A if(shouldSetFlagBack) {
0N/A ((JComponent)comp).setFlag(
0N/A ANCESTOR_USING_BUFFER,false);
0N/A ((JComponent)comp).setFlag(
0N/A IS_PAINTING_TILE,false);
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A }
0N/A recycleRectangle(tmpRect);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Paints the component's border.
0N/A * <p>
0N/A * If you override this in a subclass you should not make permanent
0N/A * changes to the passed in <code>Graphics</code>. For example, you
0N/A * should not alter the clip <code>Rectangle</code> or modify the
0N/A * transform. If you need to do these operations you may find it
0N/A * easier to create a new <code>Graphics</code> from the passed in
0N/A * <code>Graphics</code> and manipulate it.
0N/A *
0N/A * @param g the <code>Graphics</code> context in which to paint
0N/A *
0N/A * @see #paint
0N/A * @see #setBorder
0N/A */
0N/A protected void paintBorder(Graphics g) {
0N/A Border border = getBorder();
0N/A if (border != null) {
0N/A border.paintBorder(this, g, 0, 0, getWidth(), getHeight());
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Calls <code>paint</code>. Doesn't clear the background but see
0N/A * <code>ComponentUI.update</code>, which is called by
0N/A * <code>paintComponent</code>.
0N/A *
0N/A * @param g the <code>Graphics</code> context in which to paint
0N/A * @see #paint
0N/A * @see #paintComponent
0N/A * @see javax.swing.plaf.ComponentUI
0N/A */
0N/A public void update(Graphics g) {
0N/A paint(g);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Invoked by Swing to draw components.
0N/A * Applications should not invoke <code>paint</code> directly,
0N/A * but should instead use the <code>repaint</code> method to
0N/A * schedule the component for redrawing.
0N/A * <p>
0N/A * This method actually delegates the work of painting to three
0N/A * protected methods: <code>paintComponent</code>,
0N/A * <code>paintBorder</code>,
0N/A * and <code>paintChildren</code>. They're called in the order
0N/A * listed to ensure that children appear on top of component itself.
0N/A * Generally speaking, the component and its children should not
0N/A * paint in the insets area allocated to the border. Subclasses can
0N/A * just override this method, as always. A subclass that just
0N/A * wants to specialize the UI (look and feel) delegate's
0N/A * <code>paint</code> method should just override
0N/A * <code>paintComponent</code>.
0N/A *
0N/A * @param g the <code>Graphics</code> context in which to paint
0N/A * @see #paintComponent
0N/A * @see #paintBorder
0N/A * @see #paintChildren
0N/A * @see #getComponentGraphics
0N/A * @see #repaint
0N/A */
0N/A public void paint(Graphics g) {
0N/A boolean shouldClearPaintFlags = false;
0N/A
0N/A if ((getWidth() <= 0) || (getHeight() <= 0)) {
0N/A return;
0N/A }
0N/A
0N/A Graphics componentGraphics = getComponentGraphics(g);
0N/A Graphics co = componentGraphics.create();
0N/A try {
0N/A RepaintManager repaintManager = RepaintManager.currentManager(this);
0N/A Rectangle clipRect = co.getClipBounds();
0N/A int clipX;
0N/A int clipY;
0N/A int clipW;
0N/A int clipH;
0N/A if (clipRect == null) {
0N/A clipX = clipY = 0;
0N/A clipW = getWidth();
0N/A clipH = getHeight();
0N/A }
0N/A else {
0N/A clipX = clipRect.x;
0N/A clipY = clipRect.y;
0N/A clipW = clipRect.width;
0N/A clipH = clipRect.height;
0N/A }
0N/A
0N/A if(clipW > getWidth()) {
0N/A clipW = getWidth();
0N/A }
0N/A if(clipH > getHeight()) {
0N/A clipH = getHeight();
0N/A }
0N/A
0N/A if(getParent() != null && !(getParent() instanceof JComponent)) {
0N/A adjustPaintFlags();
0N/A shouldClearPaintFlags = true;
0N/A }
0N/A
0N/A int bw,bh;
0N/A boolean printing = getFlag(IS_PRINTING);
1222N/A if (!printing && repaintManager.isDoubleBufferingEnabled() &&
1222N/A !getFlag(ANCESTOR_USING_BUFFER) && isDoubleBuffered() &&
1222N/A (getFlag(IS_REPAINTING) || repaintManager.isPainting()))
1222N/A {
0N/A repaintManager.beginPaint();
0N/A try {
0N/A repaintManager.paint(this, this, co, clipX, clipY, clipW,
0N/A clipH);
0N/A } finally {
0N/A repaintManager.endPaint();
0N/A }
0N/A }
0N/A else {
0N/A // Will ocassionaly happen in 1.2, especially when printing.
0N/A if (clipRect == null) {
0N/A co.setClip(clipX, clipY, clipW, clipH);
0N/A }
0N/A
0N/A if (!rectangleIsObscured(clipX,clipY,clipW,clipH)) {
0N/A if (!printing) {
0N/A paintComponent(co);
0N/A paintBorder(co);
0N/A }
0N/A else {
0N/A printComponent(co);
0N/A printBorder(co);
0N/A }
0N/A }
0N/A if (!printing) {
0N/A paintChildren(co);
0N/A }
0N/A else {
0N/A printChildren(co);
0N/A }
0N/A }
0N/A } finally {
0N/A co.dispose();
0N/A if(shouldClearPaintFlags) {
0N/A setFlag(ANCESTOR_USING_BUFFER,false);
0N/A setFlag(IS_PAINTING_TILE,false);
0N/A setFlag(IS_PRINTING,false);
0N/A setFlag(IS_PRINTING_ALL,false);
0N/A }
0N/A }
0N/A }
0N/A
0N/A // paint forcing use of the double buffer. This is used for historical
0N/A // reasons: JViewport, when scrolling, previously directly invoked paint
0N/A // while turning off double buffering at the RepaintManager level, this
0N/A // codes simulates that.
0N/A void paintForceDoubleBuffered(Graphics g) {
0N/A RepaintManager rm = RepaintManager.currentManager(this);
0N/A Rectangle clip = g.getClipBounds();
0N/A rm.beginPaint();
0N/A setFlag(IS_REPAINTING, true);
0N/A try {
0N/A rm.paint(this, this, g, clip.x, clip.y, clip.width, clip.height);
0N/A } finally {
0N/A rm.endPaint();
0N/A setFlag(IS_REPAINTING, false);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns true if this component, or any of its ancestors, are in
0N/A * the processing of painting.
0N/A */
0N/A boolean isPainting() {
0N/A Container component = this;
0N/A while (component != null) {
0N/A if (component instanceof JComponent &&
0N/A ((JComponent)component).getFlag(ANCESTOR_USING_BUFFER)) {
0N/A return true;
0N/A }
0N/A component = component.getParent();
0N/A }
0N/A return false;
0N/A }
0N/A
0N/A private void adjustPaintFlags() {
625N/A JComponent jparent;
0N/A Container parent;
0N/A for(parent = getParent() ; parent != null ; parent =
0N/A parent.getParent()) {
0N/A if(parent instanceof JComponent) {
0N/A jparent = (JComponent) parent;
0N/A if(jparent.getFlag(ANCESTOR_USING_BUFFER))
0N/A setFlag(ANCESTOR_USING_BUFFER, true);
0N/A if(jparent.getFlag(IS_PAINTING_TILE))
0N/A setFlag(IS_PAINTING_TILE, true);
0N/A if(jparent.getFlag(IS_PRINTING))
0N/A setFlag(IS_PRINTING, true);
0N/A if(jparent.getFlag(IS_PRINTING_ALL))
0N/A setFlag(IS_PRINTING_ALL, true);
0N/A break;
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Invoke this method to print the component. This method invokes
0N/A * <code>print</code> on the component.
0N/A *
0N/A * @param g the <code>Graphics</code> context in which to paint
0N/A * @see #print
0N/A * @see #printComponent
0N/A * @see #printBorder
0N/A * @see #printChildren
0N/A */
0N/A public void printAll(Graphics g) {
0N/A setFlag(IS_PRINTING_ALL, true);
0N/A try {
0N/A print(g);
0N/A }
0N/A finally {
0N/A setFlag(IS_PRINTING_ALL, false);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Invoke this method to print the component to the specified
0N/A * <code>Graphics</code>. This method will result in invocations
0N/A * of <code>printComponent</code>, <code>printBorder</code> and
0N/A * <code>printChildren</code>. It is recommended that you override
0N/A * one of the previously mentioned methods rather than this one if
0N/A * your intention is to customize the way printing looks. However,
0N/A * it can be useful to override this method should you want to prepare
0N/A * state before invoking the superclass behavior. As an example,
0N/A * if you wanted to change the component's background color before
0N/A * printing, you could do the following:
0N/A * <pre>
0N/A * public void print(Graphics g) {
0N/A * Color orig = getBackground();
0N/A * setBackground(Color.WHITE);
0N/A *
0N/A * // wrap in try/finally so that we always restore the state
0N/A * try {
0N/A * super.print(g);
0N/A * } finally {
0N/A * setBackground(orig);
0N/A * }
0N/A * }
0N/A * </pre>
0N/A * <p>
0N/A * Alternatively, or for components that delegate painting to other objects,
0N/A * you can query during painting whether or not the component is in the
0N/A * midst of a print operation. The <code>isPaintingForPrint</code> method provides
0N/A * this ability and its return value will be changed by this method: to
0N/A * <code>true</code> immediately before rendering and to <code>false</code>
0N/A * immediately after. With each change a property change event is fired on
0N/A * this component with the name <code>"paintingForPrint"</code>.
0N/A * <p>
0N/A * This method sets the component's state such that the double buffer
0N/A * will not be used: painting will be done directly on the passed in
0N/A * <code>Graphics</code>.
0N/A *
0N/A * @param g the <code>Graphics</code> context in which to paint
0N/A * @see #printComponent
0N/A * @see #printBorder
0N/A * @see #printChildren
0N/A * @see #isPaintingForPrint
0N/A */
0N/A public void print(Graphics g) {
0N/A setFlag(IS_PRINTING, true);
0N/A firePropertyChange("paintingForPrint", false, true);
0N/A try {
0N/A paint(g);
0N/A }
0N/A finally {
0N/A setFlag(IS_PRINTING, false);
0N/A firePropertyChange("paintingForPrint", true, false);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * This is invoked during a printing operation. This is implemented to
0N/A * invoke <code>paintComponent</code> on the component. Override this
0N/A * if you wish to add special painting behavior when printing.
0N/A *
0N/A * @param g the <code>Graphics</code> context in which to paint
0N/A * @see #print
0N/A * @since 1.3
0N/A */
0N/A protected void printComponent(Graphics g) {
0N/A paintComponent(g);
0N/A }
0N/A
0N/A /**
0N/A * Prints this component's children. This is implemented to invoke
0N/A * <code>paintChildren</code> on the component. Override this if you
0N/A * wish to print the children differently than painting.
0N/A *
0N/A * @param g the <code>Graphics</code> context in which to paint
0N/A * @see #print
0N/A * @since 1.3
0N/A */
0N/A protected void printChildren(Graphics g) {
0N/A paintChildren(g);
0N/A }
0N/A
0N/A /**
0N/A * Prints the component's border. This is implemented to invoke
0N/A * <code>paintBorder</code> on the component. Override this if you
0N/A * wish to print the border differently that it is painted.
0N/A *
0N/A * @param g the <code>Graphics</code> context in which to paint
0N/A * @see #print
0N/A * @since 1.3
0N/A */
0N/A protected void printBorder(Graphics g) {
0N/A paintBorder(g);
0N/A }
0N/A
0N/A /**
0N/A * Returns true if the component is currently painting a tile.
0N/A * If this method returns true, paint will be called again for another
0N/A * tile. This method returns false if you are not painting a tile or
0N/A * if the last tile is painted.
0N/A * Use this method to keep some state you might need between tiles.
0N/A *
0N/A * @return true if the component is currently painting a tile,
0N/A * false otherwise
0N/A */
0N/A public boolean isPaintingTile() {
0N/A return getFlag(IS_PAINTING_TILE);
0N/A }
0N/A
0N/A /**
0N/A * Returns <code>true</code> if the current painting operation on this
0N/A * component is part of a <code>print</code> operation. This method is
0N/A * useful when you want to customize what you print versus what you show
0N/A * on the screen.
0N/A * <p>
0N/A * You can detect changes in the value of this property by listening for
0N/A * property change events on this component with name
0N/A * <code>"paintingForPrint"</code>.
0N/A * <p>
0N/A * Note: This method provides complimentary functionality to that provided
0N/A * by other high level Swing printing APIs. However, it deals strictly with
0N/A * painting and should not be confused as providing information on higher
0N/A * level print processes. For example, a {@link javax.swing.JTable#print()}
0N/A * operation doesn't necessarily result in a continuous rendering of the
0N/A * full component, and the return value of this method can change multiple
0N/A * times during that operation. It is even possible for the component to be
0N/A * painted to the screen while the printing process is ongoing. In such a
0N/A * case, the return value of this method is <code>true</code> when, and only
0N/A * when, the table is being painted as part of the printing process.
0N/A *
0N/A * @return true if the current painting operation on this component
0N/A * is part of a print operation
0N/A * @see #print
0N/A * @since 1.6
0N/A */
0N/A public final boolean isPaintingForPrint() {
0N/A return getFlag(IS_PRINTING);
0N/A }
0N/A
0N/A /**
0N/A * In release 1.4, the focus subsystem was rearchitected.
0N/A * For more information, see
0N/A * <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html">
0N/A * How to Use the Focus Subsystem</a>,
0N/A * a section in <em>The Java Tutorial</em>.
0N/A * <p>
0N/A * Changes this <code>JComponent</code>'s focus traversal keys to
0N/A * CTRL+TAB and CTRL+SHIFT+TAB. Also prevents
0N/A * <code>SortingFocusTraversalPolicy</code> from considering descendants
0N/A * of this JComponent when computing a focus traversal cycle.
0N/A *
0N/A * @see java.awt.Component#setFocusTraversalKeys
0N/A * @see SortingFocusTraversalPolicy
0N/A * @deprecated As of 1.4, replaced by
0N/A * <code>Component.setFocusTraversalKeys(int, Set)</code> and
0N/A * <code>Container.setFocusCycleRoot(boolean)</code>.
0N/A */
0N/A @Deprecated
0N/A public boolean isManagingFocus() {
0N/A return false;
0N/A }
0N/A
0N/A private void registerNextFocusableComponent() {
0N/A registerNextFocusableComponent(getNextFocusableComponent());
0N/A }
0N/A
0N/A private void registerNextFocusableComponent(Component
0N/A nextFocusableComponent) {
0N/A if (nextFocusableComponent == null) {
0N/A return;
0N/A }
0N/A
0N/A Container nearestRoot =
0N/A (isFocusCycleRoot()) ? this : getFocusCycleRootAncestor();
0N/A FocusTraversalPolicy policy = nearestRoot.getFocusTraversalPolicy();
0N/A if (!(policy instanceof LegacyGlueFocusTraversalPolicy)) {
0N/A policy = new LegacyGlueFocusTraversalPolicy(policy);
0N/A nearestRoot.setFocusTraversalPolicy(policy);
0N/A }
0N/A ((LegacyGlueFocusTraversalPolicy)policy).
0N/A setNextFocusableComponent(this, nextFocusableComponent);
0N/A }
0N/A
0N/A private void deregisterNextFocusableComponent() {
0N/A Component nextFocusableComponent = getNextFocusableComponent();
0N/A if (nextFocusableComponent == null) {
0N/A return;
0N/A }
0N/A
0N/A Container nearestRoot =
0N/A (isFocusCycleRoot()) ? this : getFocusCycleRootAncestor();
0N/A if (nearestRoot == null) {
0N/A return;
0N/A }
0N/A FocusTraversalPolicy policy = nearestRoot.getFocusTraversalPolicy();
0N/A if (policy instanceof LegacyGlueFocusTraversalPolicy) {
0N/A ((LegacyGlueFocusTraversalPolicy)policy).
0N/A unsetNextFocusableComponent(this, nextFocusableComponent);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * In release 1.4, the focus subsystem was rearchitected.
0N/A * For more information, see
0N/A * <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html">
0N/A * How to Use the Focus Subsystem</a>,
0N/A * a section in <em>The Java Tutorial</em>.
0N/A * <p>
0N/A * Overrides the default <code>FocusTraversalPolicy</code> for this
0N/A * <code>JComponent</code>'s focus traversal cycle by unconditionally
0N/A * setting the specified <code>Component</code> as the next
0N/A * <code>Component</code> in the cycle, and this <code>JComponent</code>
0N/A * as the specified <code>Component</code>'s previous
0N/A * <code>Component</code> in the cycle.
0N/A *
0N/A * @param aComponent the <code>Component</code> that should follow this
0N/A * <code>JComponent</code> in the focus traversal cycle
0N/A *
0N/A * @see #getNextFocusableComponent
0N/A * @see java.awt.FocusTraversalPolicy
0N/A * @deprecated As of 1.4, replaced by <code>FocusTraversalPolicy</code>
0N/A */
0N/A @Deprecated
0N/A public void setNextFocusableComponent(Component aComponent) {
0N/A boolean displayable = isDisplayable();
0N/A if (displayable) {
0N/A deregisterNextFocusableComponent();
0N/A }
0N/A putClientProperty(NEXT_FOCUS, aComponent);
0N/A if (displayable) {
0N/A registerNextFocusableComponent(aComponent);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * In release 1.4, the focus subsystem was rearchitected.
0N/A * For more information, see
0N/A * <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html">
0N/A * How to Use the Focus Subsystem</a>,
0N/A * a section in <em>The Java Tutorial</em>.
0N/A * <p>
0N/A * Returns the <code>Component</code> set by a prior call to
0N/A * <code>setNextFocusableComponent(Component)</code> on this
0N/A * <code>JComponent</code>.
0N/A *
0N/A * @return the <code>Component</code> that will follow this
0N/A * <code>JComponent</code> in the focus traversal cycle, or
0N/A * <code>null</code> if none has been explicitly specified
0N/A *
0N/A * @see #setNextFocusableComponent
0N/A * @deprecated As of 1.4, replaced by <code>FocusTraversalPolicy</code>.
0N/A */
0N/A @Deprecated
0N/A public Component getNextFocusableComponent() {
0N/A return (Component)getClientProperty(NEXT_FOCUS);
0N/A }
0N/A
0N/A /**
0N/A * Provides a hint as to whether or not this <code>JComponent</code>
0N/A * should get focus. This is only a hint, and it is up to consumers that
0N/A * are requesting focus to honor this property. This is typically honored
0N/A * for mouse operations, but not keyboard operations. For example, look
0N/A * and feels could verify this property is true before requesting focus
0N/A * during a mouse operation. This would often times be used if you did
0N/A * not want a mouse press on a <code>JComponent</code> to steal focus,
0N/A * but did want the <code>JComponent</code> to be traversable via the
0N/A * keyboard. If you do not want this <code>JComponent</code> focusable at
0N/A * all, use the <code>setFocusable</code> method instead.
0N/A * <p>
0N/A * Please see
0N/A * <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html">
0N/A * How to Use the Focus Subsystem</a>,
0N/A * a section in <em>The Java Tutorial</em>,
0N/A * for more information.
0N/A *
0N/A * @param requestFocusEnabled indicates whether you want this
0N/A * <code>JComponent</code> to be focusable or not
0N/A * @see <a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a>
0N/A * @see java.awt.Component#setFocusable
0N/A */
0N/A public void setRequestFocusEnabled(boolean requestFocusEnabled) {
0N/A setFlag(REQUEST_FOCUS_DISABLED, !requestFocusEnabled);
0N/A }
0N/A
0N/A /**
0N/A * Returns <code>true</code> if this <code>JComponent</code> should
0N/A * get focus; otherwise returns <code>false</code>.
0N/A * <p>
0N/A * Please see
0N/A * <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html">
0N/A * How to Use the Focus Subsystem</a>,
0N/A * a section in <em>The Java Tutorial</em>,
0N/A * for more information.
0N/A *
0N/A * @return <code>true</code> if this component should get focus,
0N/A * otherwise returns <code>false</code>
0N/A * @see #setRequestFocusEnabled
0N/A * @see <a href="../../java/awt/doc-files/FocusSpec.html">Focus
0N/A * Specification</a>
0N/A * @see java.awt.Component#isFocusable
0N/A */
0N/A public boolean isRequestFocusEnabled() {
0N/A return !getFlag(REQUEST_FOCUS_DISABLED);
0N/A }
0N/A
0N/A /**
0N/A * Requests that this <code>Component</code> gets the input focus.
0N/A * Refer to {@link java.awt.Component#requestFocus()
0N/A * Component.requestFocus()} for a complete description of
0N/A * this method.
0N/A * <p>
0N/A * Note that the use of this method is discouraged because
0N/A * its behavior is platform dependent. Instead we recommend the
0N/A * use of {@link #requestFocusInWindow() requestFocusInWindow()}.
0N/A * If you would like more information on focus, see
0N/A * <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html">
0N/A * How to Use the Focus Subsystem</a>,
0N/A * a section in <em>The Java Tutorial</em>.
0N/A *
0N/A * @see java.awt.Component#requestFocusInWindow()
0N/A * @see java.awt.Component#requestFocusInWindow(boolean)
0N/A * @since 1.4
0N/A */
0N/A public void requestFocus() {
0N/A super.requestFocus();
0N/A }
0N/A
0N/A /**
0N/A * Requests that this <code>Component</code> gets the input focus.
0N/A * Refer to {@link java.awt.Component#requestFocus(boolean)
0N/A * Component.requestFocus(boolean)} for a complete description of
0N/A * this method.
0N/A * <p>
0N/A * Note that the use of this method is discouraged because
0N/A * its behavior is platform dependent. Instead we recommend the
0N/A * use of {@link #requestFocusInWindow(boolean)
0N/A * requestFocusInWindow(boolean)}.
0N/A * If you would like more information on focus, see
0N/A * <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html">
0N/A * How to Use the Focus Subsystem</a>,
0N/A * a section in <em>The Java Tutorial</em>.
0N/A *
0N/A * @param temporary boolean indicating if the focus change is temporary
0N/A * @return <code>false</code> if the focus change request is guaranteed to
0N/A * fail; <code>true</code> if it is likely to succeed
0N/A * @see java.awt.Component#requestFocusInWindow()
0N/A * @see java.awt.Component#requestFocusInWindow(boolean)
0N/A * @since 1.4
0N/A */
0N/A public boolean requestFocus(boolean temporary) {
0N/A return super.requestFocus(temporary);
0N/A }
0N/A
0N/A /**
0N/A * Requests that this <code>Component</code> gets the input focus.
0N/A * Refer to {@link java.awt.Component#requestFocusInWindow()
0N/A * Component.requestFocusInWindow()} for a complete description of
0N/A * this method.
0N/A * <p>
0N/A * If you would like more information on focus, see
0N/A * <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html">
0N/A * How to Use the Focus Subsystem</a>,
0N/A * a section in <em>The Java Tutorial</em>.
0N/A *
0N/A * @return <code>false</code> if the focus change request is guaranteed to
0N/A * fail; <code>true</code> if it is likely to succeed
0N/A * @see java.awt.Component#requestFocusInWindow()
0N/A * @see java.awt.Component#requestFocusInWindow(boolean)
0N/A * @since 1.4
0N/A */
0N/A public boolean requestFocusInWindow() {
0N/A return super.requestFocusInWindow();
0N/A }
0N/A
0N/A /**
0N/A * Requests that this <code>Component</code> gets the input focus.
0N/A * Refer to {@link java.awt.Component#requestFocusInWindow(boolean)
0N/A * Component.requestFocusInWindow(boolean)} for a complete description of
0N/A * this method.
0N/A * <p>
0N/A * If you would like more information on focus, see
0N/A * <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html">
0N/A * How to Use the Focus Subsystem</a>,
0N/A * a section in <em>The Java Tutorial</em>.
0N/A *
0N/A * @param temporary boolean indicating if the focus change is temporary
0N/A * @return <code>false</code> if the focus change request is guaranteed to
0N/A * fail; <code>true</code> if it is likely to succeed
0N/A * @see java.awt.Component#requestFocusInWindow()
0N/A * @see java.awt.Component#requestFocusInWindow(boolean)
0N/A * @since 1.4
0N/A */
0N/A protected boolean requestFocusInWindow(boolean temporary) {
0N/A return super.requestFocusInWindow(temporary);
0N/A }
0N/A
0N/A /**
0N/A * Requests that this Component get the input focus, and that this
0N/A * Component's top-level ancestor become the focused Window. This component
0N/A * must be displayable, visible, and focusable for the request to be
0N/A * granted.
0N/A * <p>
0N/A * This method is intended for use by focus implementations. Client code
0N/A * should not use this method; instead, it should use
0N/A * <code>requestFocusInWindow()</code>.
0N/A *
0N/A * @see #requestFocusInWindow()
0N/A */
0N/A public void grabFocus() {
0N/A requestFocus();
0N/A }
0N/A
0N/A /**
0N/A * Sets the value to indicate whether input verifier for the
0N/A * current focus owner will be called before this component requests
0N/A * focus. The default is true. Set to false on components such as a
0N/A * Cancel button or a scrollbar, which should activate even if the
0N/A * input in the current focus owner is not "passed" by the input
0N/A * verifier for that component.
0N/A *
0N/A * @param verifyInputWhenFocusTarget value for the
0N/A * <code>verifyInputWhenFocusTarget</code> property
0N/A * @see InputVerifier
0N/A * @see #setInputVerifier
0N/A * @see #getInputVerifier
0N/A * @see #getVerifyInputWhenFocusTarget
0N/A *
0N/A * @since 1.3
0N/A * @beaninfo
0N/A * bound: true
0N/A * description: Whether the Component verifies input before accepting
0N/A * focus.
0N/A */
0N/A public void setVerifyInputWhenFocusTarget(boolean
0N/A verifyInputWhenFocusTarget) {
0N/A boolean oldVerifyInputWhenFocusTarget =
0N/A this.verifyInputWhenFocusTarget;
0N/A this.verifyInputWhenFocusTarget = verifyInputWhenFocusTarget;
0N/A firePropertyChange("verifyInputWhenFocusTarget",
0N/A oldVerifyInputWhenFocusTarget,
0N/A verifyInputWhenFocusTarget);
0N/A }
0N/A
0N/A /**
0N/A * Returns the value that indicates whether the input verifier for the
0N/A * current focus owner will be called before this component requests
0N/A * focus.
0N/A *
0N/A * @return value of the <code>verifyInputWhenFocusTarget</code> property
0N/A *
0N/A * @see InputVerifier
0N/A * @see #setInputVerifier
0N/A * @see #getInputVerifier
0N/A * @see #setVerifyInputWhenFocusTarget
0N/A *
0N/A * @since 1.3
0N/A */
0N/A public boolean getVerifyInputWhenFocusTarget() {
0N/A return verifyInputWhenFocusTarget;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Gets the <code>FontMetrics</code> for the specified <code>Font</code>.
0N/A *
0N/A * @param font the font for which font metrics is to be
0N/A * obtained
0N/A * @return the font metrics for <code>font</code>
0N/A * @throws NullPointerException if <code>font</code> is null
0N/A * @since 1.5
0N/A */
0N/A public FontMetrics getFontMetrics(Font font) {
0N/A return SwingUtilities2.getFontMetrics(this, font);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Sets the preferred size of this component.
0N/A * If <code>preferredSize</code> is <code>null</code>, the UI will
0N/A * be asked for the preferred size.
0N/A * @beaninfo
0N/A * preferred: true
0N/A * bound: true
0N/A * description: The preferred size of the component.
0N/A */
0N/A public void setPreferredSize(Dimension preferredSize) {
0N/A super.setPreferredSize(preferredSize);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * If the <code>preferredSize</code> has been set to a
0N/A * non-<code>null</code> value just returns it.
0N/A * If the UI delegate's <code>getPreferredSize</code>
0N/A * method returns a non <code>null</code> value then return that;
0N/A * otherwise defer to the component's layout manager.
0N/A *
0N/A * @return the value of the <code>preferredSize</code> property
0N/A * @see #setPreferredSize
0N/A * @see ComponentUI
0N/A */
243N/A @Transient
0N/A public Dimension getPreferredSize() {
0N/A if (isPreferredSizeSet()) {
0N/A return super.getPreferredSize();
0N/A }
0N/A Dimension size = null;
0N/A if (ui != null) {
0N/A size = ui.getPreferredSize(this);
0N/A }
0N/A return (size != null) ? size : super.getPreferredSize();
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Sets the maximum size of this component to a constant
0N/A * value. Subsequent calls to <code>getMaximumSize</code> will always
0N/A * return this value; the component's UI will not be asked
0N/A * to compute it. Setting the maximum size to <code>null</code>
0N/A * restores the default behavior.
0N/A *
0N/A * @param maximumSize a <code>Dimension</code> containing the
0N/A * desired maximum allowable size
0N/A * @see #getMaximumSize
0N/A * @beaninfo
0N/A * bound: true
0N/A * description: The maximum size of the component.
0N/A */
0N/A public void setMaximumSize(Dimension maximumSize) {
0N/A super.setMaximumSize(maximumSize);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * If the maximum size has been set to a non-<code>null</code> value
0N/A * just returns it. If the UI delegate's <code>getMaximumSize</code>
0N/A * method returns a non-<code>null</code> value then return that;
0N/A * otherwise defer to the component's layout manager.
0N/A *
0N/A * @return the value of the <code>maximumSize</code> property
0N/A * @see #setMaximumSize
0N/A * @see ComponentUI
0N/A */
243N/A @Transient
0N/A public Dimension getMaximumSize() {
0N/A if (isMaximumSizeSet()) {
0N/A return super.getMaximumSize();
0N/A }
0N/A Dimension size = null;
0N/A if (ui != null) {
0N/A size = ui.getMaximumSize(this);
0N/A }
0N/A return (size != null) ? size : super.getMaximumSize();
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Sets the minimum size of this component to a constant
0N/A * value. Subsequent calls to <code>getMinimumSize</code> will always
0N/A * return this value; the component's UI will not be asked
0N/A * to compute it. Setting the minimum size to <code>null</code>
0N/A * restores the default behavior.
0N/A *
0N/A * @param minimumSize the new minimum size of this component
0N/A * @see #getMinimumSize
0N/A * @beaninfo
0N/A * bound: true
0N/A * description: The minimum size of the component.
0N/A */
0N/A public void setMinimumSize(Dimension minimumSize) {
0N/A super.setMinimumSize(minimumSize);
0N/A }
0N/A
0N/A /**
0N/A * If the minimum size has been set to a non-<code>null</code> value
0N/A * just returns it. If the UI delegate's <code>getMinimumSize</code>
0N/A * method returns a non-<code>null</code> value then return that; otherwise
0N/A * defer to the component's layout manager.
0N/A *
0N/A * @return the value of the <code>minimumSize</code> property
0N/A * @see #setMinimumSize
0N/A * @see ComponentUI
0N/A */
243N/A @Transient
0N/A public Dimension getMinimumSize() {
0N/A if (isMinimumSizeSet()) {
0N/A return super.getMinimumSize();
0N/A }
0N/A Dimension size = null;
0N/A if (ui != null) {
0N/A size = ui.getMinimumSize(this);
0N/A }
0N/A return (size != null) ? size : super.getMinimumSize();
0N/A }
0N/A
0N/A /**
0N/A * Gives the UI delegate an opportunity to define the precise
0N/A * shape of this component for the sake of mouse processing.
0N/A *
0N/A * @return true if this component logically contains x,y
0N/A * @see java.awt.Component#contains(int, int)
0N/A * @see ComponentUI
0N/A */
0N/A public boolean contains(int x, int y) {
0N/A return (ui != null) ? ui.contains(this, x, y) : super.contains(x, y);
0N/A }
0N/A
0N/A /**
0N/A * Sets the border of this component. The <code>Border</code> object is
0N/A * responsible for defining the insets for the component
0N/A * (overriding any insets set directly on the component) and
0N/A * for optionally rendering any border decorations within the
0N/A * bounds of those insets. Borders should be used (rather
0N/A * than insets) for creating both decorative and non-decorative
0N/A * (such as margins and padding) regions for a swing component.
0N/A * Compound borders can be used to nest multiple borders within a
0N/A * single component.
0N/A * <p>
0N/A * Although technically you can set the border on any object
0N/A * that inherits from <code>JComponent</code>, the look and
0N/A * feel implementation of many standard Swing components
0N/A * doesn't work well with user-set borders. In general,
0N/A * when you want to set a border on a standard Swing
0N/A * component other than <code>JPanel</code> or <code>JLabel</code>,
0N/A * we recommend that you put the component in a <code>JPanel</code>
0N/A * and set the border on the <code>JPanel</code>.
0N/A * <p>
0N/A * This is a bound property.
0N/A *
0N/A * @param border the border to be rendered for this component
0N/A * @see Border
0N/A * @see CompoundBorder
0N/A * @beaninfo
0N/A * bound: true
0N/A * preferred: true
0N/A * attribute: visualUpdate true
0N/A * description: The component's border.
0N/A */
0N/A public void setBorder(Border border) {
0N/A Border oldBorder = this.border;
0N/A
0N/A this.border = border;
0N/A firePropertyChange("border", oldBorder, border);
0N/A if (border != oldBorder) {
0N/A if (border == null || oldBorder == null ||
0N/A !(border.getBorderInsets(this).equals(oldBorder.getBorderInsets(this)))) {
0N/A revalidate();
0N/A }
0N/A repaint();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the border of this component or <code>null</code> if no
0N/A * border is currently set.
0N/A *
0N/A * @return the border object for this component
0N/A * @see #setBorder
0N/A */
0N/A public Border getBorder() {
0N/A return border;
0N/A }
0N/A
0N/A /**
0N/A * If a border has been set on this component, returns the
0N/A * border's insets; otherwise calls <code>super.getInsets</code>.
0N/A *
0N/A * @return the value of the insets property
0N/A * @see #setBorder
0N/A */
0N/A public Insets getInsets() {
0N/A if (border != null) {
0N/A return border.getBorderInsets(this);
0N/A }
0N/A return super.getInsets();
0N/A }
0N/A
0N/A /**
0N/A * Returns an <code>Insets</code> object containing this component's inset
0N/A * values. The passed-in <code>Insets</code> object will be reused
0N/A * if possible.
0N/A * Calling methods cannot assume that the same object will be returned,
0N/A * however. All existing values within this object are overwritten.
0N/A * If <code>insets</code> is null, this will allocate a new one.
0N/A *
0N/A * @param insets the <code>Insets</code> object, which can be reused
0N/A * @return the <code>Insets</code> object
0N/A * @see #getInsets
0N/A * @beaninfo
0N/A * expert: true
0N/A */
0N/A public Insets getInsets(Insets insets) {
0N/A if (insets == null) {
0N/A insets = new Insets(0, 0, 0, 0);
0N/A }
0N/A if (border != null) {
0N/A if (border instanceof AbstractBorder) {
0N/A return ((AbstractBorder)border).getBorderInsets(this, insets);
0N/A } else {
0N/A // Can't reuse border insets because the Border interface
0N/A // can't be enhanced.
0N/A return border.getBorderInsets(this);
0N/A }
0N/A } else {
0N/A // super.getInsets() always returns an Insets object with
0N/A // all of its value zeroed. No need for a new object here.
0N/A insets.left = insets.top = insets.right = insets.bottom = 0;
0N/A return insets;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Overrides <code>Container.getAlignmentY</code> to return
0N/A * the horizontal alignment.
0N/A *
0N/A * @return the value of the <code>alignmentY</code> property
0N/A * @see #setAlignmentY
0N/A * @see java.awt.Component#getAlignmentY
0N/A */
0N/A public float getAlignmentY() {
0N/A if (isAlignmentYSet) {
0N/A return alignmentY;
0N/A }
0N/A return super.getAlignmentY();
0N/A }
0N/A
0N/A /**
0N/A * Sets the the horizontal alignment.
0N/A *
0N/A * @param alignmentY the new horizontal alignment
0N/A * @see #getAlignmentY
0N/A * @beaninfo
0N/A * description: The preferred vertical alignment of the component.
0N/A */
0N/A public void setAlignmentY(float alignmentY) {
0N/A this.alignmentY = alignmentY > 1.0f ? 1.0f : alignmentY < 0.0f ? 0.0f : alignmentY;
0N/A isAlignmentYSet = true;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Overrides <code>Container.getAlignmentX</code> to return
0N/A * the vertical alignment.
0N/A *
0N/A * @return the value of the <code>alignmentX</code> property
0N/A * @see #setAlignmentX
0N/A * @see java.awt.Component#getAlignmentX
0N/A */
0N/A public float getAlignmentX() {
0N/A if (isAlignmentXSet) {
0N/A return alignmentX;
0N/A }
0N/A return super.getAlignmentX();
0N/A }
0N/A
0N/A /**
0N/A * Sets the the vertical alignment.
0N/A *
0N/A * @param alignmentX the new vertical alignment
0N/A * @see #getAlignmentX
0N/A * @beaninfo
0N/A * description: The preferred horizontal alignment of the component.
0N/A */
0N/A public void setAlignmentX(float alignmentX) {
0N/A this.alignmentX = alignmentX > 1.0f ? 1.0f : alignmentX < 0.0f ? 0.0f : alignmentX;
0N/A isAlignmentXSet = true;
0N/A }
0N/A
0N/A /**
0N/A * Sets the input verifier for this component.
0N/A *
0N/A * @param inputVerifier the new input verifier
0N/A * @since 1.3
0N/A * @see InputVerifier
0N/A * @beaninfo
0N/A * bound: true
0N/A * description: The component's input verifier.
0N/A */
0N/A public void setInputVerifier(InputVerifier inputVerifier) {
0N/A InputVerifier oldInputVerifier = (InputVerifier)getClientProperty(
0N/A JComponent_INPUT_VERIFIER);
0N/A putClientProperty(JComponent_INPUT_VERIFIER, inputVerifier);
0N/A firePropertyChange("inputVerifier", oldInputVerifier, inputVerifier);
0N/A }
0N/A
0N/A /**
0N/A * Returns the input verifier for this component.
0N/A *
0N/A * @return the <code>inputVerifier</code> property
0N/A * @since 1.3
0N/A * @see InputVerifier
0N/A */
0N/A public InputVerifier getInputVerifier() {
0N/A return (InputVerifier)getClientProperty(JComponent_INPUT_VERIFIER);
0N/A }
0N/A
0N/A /**
0N/A * Returns this component's graphics context, which lets you draw
0N/A * on a component. Use this method to get a <code>Graphics</code> object and
0N/A * then invoke operations on that object to draw on the component.
0N/A * @return this components graphics context
0N/A */
0N/A public Graphics getGraphics() {
0N/A if (DEBUG_GRAPHICS_LOADED && shouldDebugGraphics() != 0) {
0N/A DebugGraphics graphics = new DebugGraphics(super.getGraphics(),
0N/A this);
0N/A return graphics;
0N/A }
0N/A return super.getGraphics();
0N/A }
0N/A
0N/A
0N/A /** Enables or disables diagnostic information about every graphics
0N/A * operation performed within the component or one of its children.
0N/A *
0N/A * @param debugOptions determines how the component should display
0N/A * the information; one of the following options:
0N/A * <ul>
0N/A * <li>DebugGraphics.LOG_OPTION - causes a text message to be printed.
0N/A * <li>DebugGraphics.FLASH_OPTION - causes the drawing to flash several
0N/A * times.
0N/A * <li>DebugGraphics.BUFFERED_OPTION - creates an
0N/A * <code>ExternalWindow</code> that displays the operations
0N/A * performed on the View's offscreen buffer.
0N/A * <li>DebugGraphics.NONE_OPTION disables debugging.
0N/A * <li>A value of 0 causes no changes to the debugging options.
0N/A * </ul>
0N/A * <code>debugOptions</code> is bitwise OR'd into the current value
0N/A *
0N/A * @beaninfo
0N/A * preferred: true
0N/A * enum: NONE_OPTION DebugGraphics.NONE_OPTION
0N/A * LOG_OPTION DebugGraphics.LOG_OPTION
0N/A * FLASH_OPTION DebugGraphics.FLASH_OPTION
0N/A * BUFFERED_OPTION DebugGraphics.BUFFERED_OPTION
0N/A * description: Diagnostic options for graphics operations.
0N/A */
0N/A public void setDebugGraphicsOptions(int debugOptions) {
0N/A DebugGraphics.setDebugOptions(this, debugOptions);
0N/A }
0N/A
0N/A /** Returns the state of graphics debugging.
0N/A *
0N/A * @return a bitwise OR'd flag of zero or more of the following options:
0N/A * <ul>
0N/A * <li>DebugGraphics.LOG_OPTION - causes a text message to be printed.
0N/A * <li>DebugGraphics.FLASH_OPTION - causes the drawing to flash several
0N/A * times.
0N/A * <li>DebugGraphics.BUFFERED_OPTION - creates an
0N/A * <code>ExternalWindow</code> that displays the operations
0N/A * performed on the View's offscreen buffer.
0N/A * <li>DebugGraphics.NONE_OPTION disables debugging.
0N/A * <li>A value of 0 causes no changes to the debugging options.
0N/A * </ul>
0N/A * @see #setDebugGraphicsOptions
0N/A */
0N/A public int getDebugGraphicsOptions() {
0N/A return DebugGraphics.getDebugOptions(this);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns true if debug information is enabled for this
0N/A * <code>JComponent</code> or one of its parents.
0N/A */
0N/A int shouldDebugGraphics() {
0N/A return DebugGraphics.shouldComponentDebug(this);
0N/A }
0N/A
0N/A /**
0N/A * This method is now obsolete, please use a combination of
0N/A * <code>getActionMap()</code> and <code>getInputMap()</code> for
0N/A * similiar behavior. For example, to bind the <code>KeyStroke</code>
0N/A * <code>aKeyStroke</code> to the <code>Action</code> <code>anAction</code>
0N/A * now use:
0N/A * <pre>
0N/A * component.getInputMap().put(aKeyStroke, aCommand);
0N/A * component.getActionMap().put(aCommmand, anAction);
0N/A * </pre>
0N/A * The above assumes you want the binding to be applicable for
0N/A * <code>WHEN_FOCUSED</code>. To register bindings for other focus
0N/A * states use the <code>getInputMap</code> method that takes an integer.
0N/A * <p>
0N/A * Register a new keyboard action.
0N/A * <code>anAction</code> will be invoked if a key event matching
0N/A * <code>aKeyStroke</code> occurs and <code>aCondition</code> is verified.
0N/A * The <code>KeyStroke</code> object defines a
0N/A * particular combination of a keyboard key and one or more modifiers
0N/A * (alt, shift, ctrl, meta).
0N/A * <p>
0N/A * The <code>aCommand</code> will be set in the delivered event if
0N/A * specified.
0N/A * <p>
0N/A * The <code>aCondition</code> can be one of:
0N/A * <blockquote>
0N/A * <DL>
0N/A * <DT>WHEN_FOCUSED
0N/A * <DD>The action will be invoked only when the keystroke occurs
0N/A * while the component has the focus.
0N/A * <DT>WHEN_IN_FOCUSED_WINDOW
0N/A * <DD>The action will be invoked when the keystroke occurs while
0N/A * the component has the focus or if the component is in the
0N/A * window that has the focus. Note that the component need not
0N/A * be an immediate descendent of the window -- it can be
0N/A * anywhere in the window's containment hierarchy. In other
0N/A * words, whenever <em>any</em> component in the window has the focus,
0N/A * the action registered with this component is invoked.
0N/A * <DT>WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
0N/A * <DD>The action will be invoked when the keystroke occurs while the
0N/A * component has the focus or if the component is an ancestor of
0N/A * the component that has the focus.
0N/A * </DL>
0N/A * </blockquote>
0N/A * <p>
0N/A * The combination of keystrokes and conditions lets you define high
0N/A * level (semantic) action events for a specified keystroke+modifier
0N/A * combination (using the KeyStroke class) and direct to a parent or
0N/A * child of a component that has the focus, or to the component itself.
0N/A * In other words, in any hierarchical structure of components, an
0N/A * arbitrary key-combination can be immediately directed to the
0N/A * appropriate component in the hierarchy, and cause a specific method
0N/A * to be invoked (usually by way of adapter objects).
0N/A * <p>
0N/A * If an action has already been registered for the receiving
0N/A * container, with the same charCode and the same modifiers,
0N/A * <code>anAction</code> will replace the action.
0N/A *
0N/A * @param anAction the <code>Action</code> to be registered
0N/A * @param aCommand the command to be set in the delivered event
0N/A * @param aKeyStroke the <code>KeyStroke</code> to bind to the action
0N/A * @param aCondition the condition that needs to be met, see above
0N/A * @see KeyStroke
0N/A */
0N/A public void registerKeyboardAction(ActionListener anAction,String aCommand,KeyStroke aKeyStroke,int aCondition) {
0N/A
0N/A InputMap inputMap = getInputMap(aCondition, true);
0N/A
0N/A if (inputMap != null) {
0N/A ActionMap actionMap = getActionMap(true);
0N/A ActionStandin action = new ActionStandin(anAction, aCommand);
0N/A inputMap.put(aKeyStroke, action);
0N/A if (actionMap != null) {
0N/A actionMap.put(action, action);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Registers any bound <code>WHEN_IN_FOCUSED_WINDOW</code> actions with
0N/A * the <code>KeyboardManager</code>. If <code>onlyIfNew</code>
0N/A * is true only actions that haven't been registered are pushed
0N/A * to the <code>KeyboardManager</code>;
0N/A * otherwise all actions are pushed to the <code>KeyboardManager</code>.
0N/A *
0N/A * @param onlyIfNew if true, only actions that haven't been registered
0N/A * are pushed to the <code>KeyboardManager</code>
0N/A */
0N/A private void registerWithKeyboardManager(boolean onlyIfNew) {
0N/A InputMap inputMap = getInputMap(WHEN_IN_FOCUSED_WINDOW, false);
0N/A KeyStroke[] strokes;
625N/A Hashtable<KeyStroke, KeyStroke> registered = (Hashtable)getClientProperty
0N/A (WHEN_IN_FOCUSED_WINDOW_BINDINGS);
0N/A
0N/A if (inputMap != null) {
0N/A // Push any new KeyStrokes to the KeyboardManager.
0N/A strokes = inputMap.allKeys();
0N/A if (strokes != null) {
0N/A for (int counter = strokes.length - 1; counter >= 0;
0N/A counter--) {
0N/A if (!onlyIfNew || registered == null ||
0N/A registered.get(strokes[counter]) == null) {
0N/A registerWithKeyboardManager(strokes[counter]);
0N/A }
0N/A if (registered != null) {
0N/A registered.remove(strokes[counter]);
0N/A }
0N/A }
0N/A }
0N/A }
0N/A else {
0N/A strokes = null;
0N/A }
0N/A // Remove any old ones.
0N/A if (registered != null && registered.size() > 0) {
625N/A Enumeration<KeyStroke> keys = registered.keys();
0N/A
0N/A while (keys.hasMoreElements()) {
625N/A KeyStroke ks = keys.nextElement();
0N/A unregisterWithKeyboardManager(ks);
0N/A }
0N/A registered.clear();
0N/A }
0N/A // Updated the registered Hashtable.
0N/A if (strokes != null && strokes.length > 0) {
0N/A if (registered == null) {
625N/A registered = new Hashtable<KeyStroke, KeyStroke>(strokes.length);
0N/A putClientProperty(WHEN_IN_FOCUSED_WINDOW_BINDINGS, registered);
0N/A }
0N/A for (int counter = strokes.length - 1; counter >= 0; counter--) {
0N/A registered.put(strokes[counter], strokes[counter]);
0N/A }
0N/A }
0N/A else {
0N/A putClientProperty(WHEN_IN_FOCUSED_WINDOW_BINDINGS, null);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Unregisters all the previously registered
0N/A * <code>WHEN_IN_FOCUSED_WINDOW</code> <code>KeyStroke</code> bindings.
0N/A */
0N/A private void unregisterWithKeyboardManager() {
0N/A Hashtable registered = (Hashtable)getClientProperty
0N/A (WHEN_IN_FOCUSED_WINDOW_BINDINGS);
0N/A
0N/A if (registered != null && registered.size() > 0) {
0N/A Enumeration keys = registered.keys();
0N/A
0N/A while (keys.hasMoreElements()) {
0N/A KeyStroke ks = (KeyStroke)keys.nextElement();
0N/A unregisterWithKeyboardManager(ks);
0N/A }
0N/A }
0N/A putClientProperty(WHEN_IN_FOCUSED_WINDOW_BINDINGS, null);
0N/A }
0N/A
0N/A /**
0N/A * Invoked from <code>ComponentInputMap</code> when its bindings change.
0N/A * If <code>inputMap</code> is the current <code>windowInputMap</code>
0N/A * (or a parent of the window <code>InputMap</code>)
0N/A * the <code>KeyboardManager</code> is notified of the new bindings.
0N/A *
0N/A * @param inputMap the map containing the new bindings
0N/A */
0N/A void componentInputMapChanged(ComponentInputMap inputMap) {
0N/A InputMap km = getInputMap(WHEN_IN_FOCUSED_WINDOW, false);
0N/A
0N/A while (km != inputMap && km != null) {
625N/A km = km.getParent();
0N/A }
0N/A if (km != null) {
0N/A registerWithKeyboardManager(false);
0N/A }
0N/A }
0N/A
0N/A private void registerWithKeyboardManager(KeyStroke aKeyStroke) {
0N/A KeyboardManager.getCurrentManager().registerKeyStroke(aKeyStroke,this);
0N/A }
0N/A
0N/A private void unregisterWithKeyboardManager(KeyStroke aKeyStroke) {
0N/A KeyboardManager.getCurrentManager().unregisterKeyStroke(aKeyStroke,
0N/A this);
0N/A }
0N/A
0N/A /**
0N/A * This method is now obsolete, please use a combination of
0N/A * <code>getActionMap()</code> and <code>getInputMap()</code> for
0N/A * similiar behavior.
0N/A */
0N/A public void registerKeyboardAction(ActionListener anAction,KeyStroke aKeyStroke,int aCondition) {
0N/A registerKeyboardAction(anAction,null,aKeyStroke,aCondition);
0N/A }
0N/A
0N/A /**
0N/A * This method is now obsolete. To unregister an existing binding
0N/A * you can either remove the binding from the
0N/A * <code>ActionMap/InputMap</code>, or place a dummy binding the
0N/A * <code>InputMap</code>. Removing the binding from the
0N/A * <code>InputMap</code> allows bindings in parent <code>InputMap</code>s
0N/A * to be active, whereas putting a dummy binding in the
0N/A * <code>InputMap</code> effectively disables
0N/A * the binding from ever happening.
0N/A * <p>
0N/A * Unregisters a keyboard action.
0N/A * This will remove the binding from the <code>ActionMap</code>
0N/A * (if it exists) as well as the <code>InputMap</code>s.
0N/A */
0N/A public void unregisterKeyboardAction(KeyStroke aKeyStroke) {
0N/A ActionMap am = getActionMap(false);
0N/A for (int counter = 0; counter < 3; counter++) {
0N/A InputMap km = getInputMap(counter, false);
0N/A if (km != null) {
0N/A Object actionID = km.get(aKeyStroke);
0N/A
0N/A if (am != null && actionID != null) {
0N/A am.remove(actionID);
0N/A }
0N/A km.remove(aKeyStroke);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the <code>KeyStrokes</code> that will initiate
0N/A * registered actions.
0N/A *
0N/A * @return an array of <code>KeyStroke</code> objects
0N/A * @see #registerKeyboardAction
0N/A */
0N/A public KeyStroke[] getRegisteredKeyStrokes() {
0N/A int[] counts = new int[3];
0N/A KeyStroke[][] strokes = new KeyStroke[3][];
0N/A
0N/A for (int counter = 0; counter < 3; counter++) {
0N/A InputMap km = getInputMap(counter, false);
0N/A strokes[counter] = (km != null) ? km.allKeys() : null;
0N/A counts[counter] = (strokes[counter] != null) ?
0N/A strokes[counter].length : 0;
0N/A }
0N/A KeyStroke[] retValue = new KeyStroke[counts[0] + counts[1] +
0N/A counts[2]];
0N/A for (int counter = 0, last = 0; counter < 3; counter++) {
0N/A if (counts[counter] > 0) {
0N/A System.arraycopy(strokes[counter], 0, retValue, last,
0N/A counts[counter]);
0N/A last += counts[counter];
0N/A }
0N/A }
0N/A return retValue;
0N/A }
0N/A
0N/A /**
0N/A * Returns the condition that determines whether a registered action
0N/A * occurs in response to the specified keystroke.
0N/A * <p>
0N/A * For Java 2 platform v1.3, a <code>KeyStroke</code> can be associated
0N/A * with more than one condition.
0N/A * For example, 'a' could be bound for the two
0N/A * conditions <code>WHEN_FOCUSED</code> and
0N/A * <code>WHEN_IN_FOCUSED_WINDOW</code> condition.
0N/A *
0N/A * @return the action-keystroke condition
0N/A */
0N/A public int getConditionForKeyStroke(KeyStroke aKeyStroke) {
0N/A for (int counter = 0; counter < 3; counter++) {
0N/A InputMap inputMap = getInputMap(counter, false);
0N/A if (inputMap != null && inputMap.get(aKeyStroke) != null) {
0N/A return counter;
0N/A }
0N/A }
0N/A return UNDEFINED_CONDITION;
0N/A }
0N/A
0N/A /**
0N/A * Returns the object that will perform the action registered for a
0N/A * given keystroke.
0N/A *
0N/A * @return the <code>ActionListener</code>
0N/A * object invoked when the keystroke occurs
0N/A */
0N/A public ActionListener getActionForKeyStroke(KeyStroke aKeyStroke) {
0N/A ActionMap am = getActionMap(false);
0N/A
0N/A if (am == null) {
0N/A return null;
0N/A }
0N/A for (int counter = 0; counter < 3; counter++) {
0N/A InputMap inputMap = getInputMap(counter, false);
0N/A if (inputMap != null) {
0N/A Object actionBinding = inputMap.get(aKeyStroke);
0N/A
0N/A if (actionBinding != null) {
0N/A Action action = am.get(actionBinding);
0N/A if (action instanceof ActionStandin) {
0N/A return ((ActionStandin)action).actionListener;
0N/A }
0N/A return action;
0N/A }
0N/A }
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Unregisters all the bindings in the first tier <code>InputMaps</code>
0N/A * and <code>ActionMap</code>. This has the effect of removing any
0N/A * local bindings, and allowing the bindings defined in parent
0N/A * <code>InputMap/ActionMaps</code>
0N/A * (the UI is usually defined in the second tier) to persist.
0N/A */
0N/A public void resetKeyboardActions() {
0N/A // Keys
0N/A for (int counter = 0; counter < 3; counter++) {
0N/A InputMap inputMap = getInputMap(counter, false);
0N/A
0N/A if (inputMap != null) {
0N/A inputMap.clear();
0N/A }
0N/A }
0N/A
0N/A // Actions
0N/A ActionMap am = getActionMap(false);
0N/A
0N/A if (am != null) {
0N/A am.clear();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets the <code>InputMap</code> to use under the condition
0N/A * <code>condition</code> to
0N/A * <code>map</code>. A <code>null</code> value implies you
0N/A * do not want any bindings to be used, even from the UI. This will
0N/A * not reinstall the UI <code>InputMap</code> (if there was one).
0N/A * <code>condition</code> has one of the following values:
0N/A * <ul>
0N/A * <li><code>WHEN_IN_FOCUSED_WINDOW</code>
0N/A * <li><code>WHEN_FOCUSED</code>
0N/A * <li><code>WHEN_ANCESTOR_OF_FOCUSED_COMPONENT</code>
0N/A * </ul>
0N/A * If <code>condition</code> is <code>WHEN_IN_FOCUSED_WINDOW</code>
0N/A * and <code>map</code> is not a <code>ComponentInputMap</code>, an
0N/A * <code>IllegalArgumentException</code> will be thrown.
0N/A * Similarly, if <code>condition</code> is not one of the values
0N/A * listed, an <code>IllegalArgumentException</code> will be thrown.
0N/A *
0N/A * @param condition one of the values listed above
0N/A * @param map the <code>InputMap</code> to use for the given condition
0N/A * @exception IllegalArgumentException if <code>condition</code> is
0N/A * <code>WHEN_IN_FOCUSED_WINDOW</code> and <code>map</code>
0N/A * is not an instance of <code>ComponentInputMap</code>; or
0N/A * if <code>condition</code> is not one of the legal values
0N/A * specified above
0N/A * @since 1.3
0N/A */
0N/A public final void setInputMap(int condition, InputMap map) {
0N/A switch (condition) {
0N/A case WHEN_IN_FOCUSED_WINDOW:
0N/A if (map != null && !(map instanceof ComponentInputMap)) {
0N/A throw new IllegalArgumentException("WHEN_IN_FOCUSED_WINDOW InputMaps must be of type ComponentInputMap");
0N/A }
0N/A windowInputMap = (ComponentInputMap)map;
0N/A setFlag(WIF_INPUTMAP_CREATED, true);
0N/A registerWithKeyboardManager(false);
0N/A break;
0N/A case WHEN_ANCESTOR_OF_FOCUSED_COMPONENT:
0N/A ancestorInputMap = map;
0N/A setFlag(ANCESTOR_INPUTMAP_CREATED, true);
0N/A break;
0N/A case WHEN_FOCUSED:
0N/A focusInputMap = map;
0N/A setFlag(FOCUS_INPUTMAP_CREATED, true);
0N/A break;
0N/A default:
0N/A throw new IllegalArgumentException("condition must be one of JComponent.WHEN_IN_FOCUSED_WINDOW, JComponent.WHEN_FOCUSED or JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT");
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the <code>InputMap</code> that is used during
0N/A * <code>condition</code>.
0N/A *
0N/A * @param condition one of WHEN_IN_FOCUSED_WINDOW, WHEN_FOCUSED,
0N/A * WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
0N/A * @return the <code>InputMap</code> for the specified
0N/A * <code>condition</code>
0N/A * @since 1.3
0N/A */
0N/A public final InputMap getInputMap(int condition) {
0N/A return getInputMap(condition, true);
0N/A }
0N/A
0N/A /**
0N/A * Returns the <code>InputMap</code> that is used when the
0N/A * component has focus.
0N/A * This is convenience method for <code>getInputMap(WHEN_FOCUSED)</code>.
0N/A *
0N/A * @return the <code>InputMap</code> used when the component has focus
0N/A * @since 1.3
0N/A */
0N/A public final InputMap getInputMap() {
0N/A return getInputMap(WHEN_FOCUSED, true);
0N/A }
0N/A
0N/A /**
0N/A * Sets the <code>ActionMap</code> to <code>am</code>. This does not set
0N/A * the parent of the <code>am</code> to be the <code>ActionMap</code>
0N/A * from the UI (if there was one), it is up to the caller to have done this.
0N/A *
0N/A * @param am the new <code>ActionMap</code>
0N/A * @since 1.3
0N/A */
0N/A public final void setActionMap(ActionMap am) {
0N/A actionMap = am;
0N/A setFlag(ACTIONMAP_CREATED, true);
0N/A }
0N/A
0N/A /**
0N/A * Returns the <code>ActionMap</code> used to determine what
0N/A * <code>Action</code> to fire for particular <code>KeyStroke</code>
0N/A * binding. The returned <code>ActionMap</code>, unless otherwise
0N/A * set, will have the <code>ActionMap</code> from the UI set as the parent.
0N/A *
0N/A * @return the <code>ActionMap</code> containing the key/action bindings
0N/A * @since 1.3
0N/A */
0N/A public final ActionMap getActionMap() {
0N/A return getActionMap(true);
0N/A }
0N/A
0N/A /**
0N/A * Returns the <code>InputMap</code> to use for condition
0N/A * <code>condition</code>. If the <code>InputMap</code> hasn't
0N/A * been created, and <code>create</code> is
0N/A * true, it will be created.
0N/A *
0N/A * @param condition one of the following values:
0N/A * <ul>
0N/A * <li>JComponent.FOCUS_INPUTMAP_CREATED
0N/A * <li>JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
0N/A * <li>JComponent.WHEN_IN_FOCUSED_WINDOW
0N/A * </ul>
0N/A * @param create if true, create the <code>InputMap</code> if it
0N/A * is not already created
0N/A * @return the <code>InputMap</code> for the given <code>condition</code>;
0N/A * if <code>create</code> is false and the <code>InputMap</code>
0N/A * hasn't been created, returns <code>null</code>
0N/A * @exception IllegalArgumentException if <code>condition</code>
0N/A * is not one of the legal values listed above
0N/A */
0N/A final InputMap getInputMap(int condition, boolean create) {
0N/A switch (condition) {
0N/A case WHEN_FOCUSED:
0N/A if (getFlag(FOCUS_INPUTMAP_CREATED)) {
0N/A return focusInputMap;
0N/A }
0N/A // Hasn't been created yet.
0N/A if (create) {
0N/A InputMap km = new InputMap();
0N/A setInputMap(condition, km);
0N/A return km;
0N/A }
0N/A break;
0N/A case WHEN_ANCESTOR_OF_FOCUSED_COMPONENT:
0N/A if (getFlag(ANCESTOR_INPUTMAP_CREATED)) {
0N/A return ancestorInputMap;
0N/A }
0N/A // Hasn't been created yet.
0N/A if (create) {
0N/A InputMap km = new InputMap();
0N/A setInputMap(condition, km);
0N/A return km;
0N/A }
0N/A break;
0N/A case WHEN_IN_FOCUSED_WINDOW:
0N/A if (getFlag(WIF_INPUTMAP_CREATED)) {
0N/A return windowInputMap;
0N/A }
0N/A // Hasn't been created yet.
0N/A if (create) {
0N/A ComponentInputMap km = new ComponentInputMap(this);
0N/A setInputMap(condition, km);
0N/A return km;
0N/A }
0N/A break;
0N/A default:
0N/A throw new IllegalArgumentException("condition must be one of JComponent.WHEN_IN_FOCUSED_WINDOW, JComponent.WHEN_FOCUSED or JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT");
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Finds and returns the appropriate <code>ActionMap</code>.
0N/A *
0N/A * @param create if true, create the <code>ActionMap</code> if it
0N/A * is not already created
0N/A * @return the <code>ActionMap</code> for this component; if the
0N/A * <code>create</code> flag is false and there is no
0N/A * current <code>ActionMap</code>, returns <code>null</code>
0N/A */
0N/A final ActionMap getActionMap(boolean create) {
0N/A if (getFlag(ACTIONMAP_CREATED)) {
0N/A return actionMap;
0N/A }
0N/A // Hasn't been created.
0N/A if (create) {
0N/A ActionMap am = new ActionMap();
0N/A setActionMap(am);
0N/A return am;
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Returns the baseline. The baseline is measured from the top of
0N/A * the component. This method is primarily meant for
0N/A * <code>LayoutManager</code>s to align components along their
0N/A * baseline. A return value less than 0 indicates this component
0N/A * does not have a reasonable baseline and that
0N/A * <code>LayoutManager</code>s should not align this component on
0N/A * its baseline.
0N/A * <p>
0N/A * This method calls into the <code>ComponentUI</code> method of the
0N/A * same name. If this component does not have a <code>ComponentUI</code>
0N/A * -1 will be returned. If a value &gt;= 0 is
0N/A * returned, then the component has a valid baseline for any
0N/A * size &gt;= the minimum size and <code>getBaselineResizeBehavior</code>
0N/A * can be used to determine how the baseline changes with size.
0N/A *
0N/A * @throws IllegalArgumentException {@inheritDoc}
0N/A * @see #getBaselineResizeBehavior
0N/A * @see java.awt.FontMetrics
0N/A * @since 1.6
0N/A */
0N/A public int getBaseline(int width, int height) {
0N/A // check size.
0N/A super.getBaseline(width, height);
0N/A if (ui != null) {
0N/A return ui.getBaseline(this, width, height);
0N/A }
0N/A return -1;
0N/A }
0N/A
0N/A /**
0N/A * Returns an enum indicating how the baseline of the component
0N/A * changes as the size changes. This method is primarily meant for
0N/A * layout managers and GUI builders.
0N/A * <p>
0N/A * This method calls into the <code>ComponentUI</code> method of
0N/A * the same name. If this component does not have a
0N/A * <code>ComponentUI</code>
0N/A * <code>BaselineResizeBehavior.OTHER</code> will be
0N/A * returned. Subclasses should
0N/A * never return <code>null</code>; if the baseline can not be
0N/A * calculated return <code>BaselineResizeBehavior.OTHER</code>. Callers
0N/A * should first ask for the baseline using
0N/A * <code>getBaseline</code> and if a value &gt;= 0 is returned use
0N/A * this method. It is acceptable for this method to return a
0N/A * value other than <code>BaselineResizeBehavior.OTHER</code> even if
0N/A * <code>getBaseline</code> returns a value less than 0.
0N/A *
0N/A * @see #getBaseline(int, int)
0N/A * @since 1.6
0N/A */
0N/A public BaselineResizeBehavior getBaselineResizeBehavior() {
0N/A if (ui != null) {
0N/A return ui.getBaselineResizeBehavior(this);
0N/A }
0N/A return BaselineResizeBehavior.OTHER;
0N/A }
0N/A
0N/A /**
0N/A * In release 1.4, the focus subsystem was rearchitected.
0N/A * For more information, see
0N/A * <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html">
0N/A * How to Use the Focus Subsystem</a>,
0N/A * a section in <em>The Java Tutorial</em>.
0N/A * <p>
0N/A * Requests focus on this <code>JComponent</code>'s
0N/A * <code>FocusTraversalPolicy</code>'s default <code>Component</code>.
0N/A * If this <code>JComponent</code> is a focus cycle root, then its
0N/A * <code>FocusTraversalPolicy</code> is used. Otherwise, the
0N/A * <code>FocusTraversalPolicy</code> of this <code>JComponent</code>'s
0N/A * focus-cycle-root ancestor is used.
0N/A *
0N/A * @see java.awt.FocusTraversalPolicy#getDefaultComponent
0N/A * @deprecated As of 1.4, replaced by
0N/A * <code>FocusTraversalPolicy.getDefaultComponent(Container).requestFocus()</code>
0N/A */
0N/A @Deprecated
0N/A public boolean requestDefaultFocus() {
0N/A Container nearestRoot =
0N/A (isFocusCycleRoot()) ? this : getFocusCycleRootAncestor();
0N/A if (nearestRoot == null) {
0N/A return false;
0N/A }
0N/A Component comp = nearestRoot.getFocusTraversalPolicy().
0N/A getDefaultComponent(nearestRoot);
0N/A if (comp != null) {
0N/A comp.requestFocus();
0N/A return true;
0N/A } else {
0N/A return false;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Makes the component visible or invisible.
0N/A * Overrides <code>Component.setVisible</code>.
0N/A *
0N/A * @param aFlag true to make the component visible; false to
0N/A * make it invisible
0N/A *
0N/A * @beaninfo
0N/A * attribute: visualUpdate true
0N/A */
0N/A public void setVisible(boolean aFlag) {
5243N/A if (aFlag != isVisible()) {
0N/A super.setVisible(aFlag);
5243N/A if (aFlag) {
5243N/A Container parent = getParent();
5243N/A if (parent != null) {
5243N/A Rectangle r = getBounds();
5243N/A parent.repaint(r.x, r.y, r.width, r.height);
5243N/A }
5243N/A revalidate();
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets whether or not this component is enabled.
0N/A * A component that is enabled may respond to user input,
0N/A * while a component that is not enabled cannot respond to
0N/A * user input. Some components may alter their visual
0N/A * representation when they are disabled in order to
0N/A * provide feedback to the user that they cannot take input.
0N/A * <p>Note: Disabling a component does not disable its children.
0N/A *
0N/A * <p>Note: Disabling a lightweight component does not prevent it from
0N/A * receiving MouseEvents.
0N/A *
0N/A * @param enabled true if this component should be enabled, false otherwise
0N/A * @see java.awt.Component#isEnabled
0N/A * @see java.awt.Component#isLightweight
0N/A *
0N/A * @beaninfo
0N/A * preferred: true
0N/A * bound: true
0N/A * attribute: visualUpdate true
0N/A * description: The enabled state of the component.
0N/A */
0N/A public void setEnabled(boolean enabled) {
0N/A boolean oldEnabled = isEnabled();
0N/A super.setEnabled(enabled);
0N/A firePropertyChange("enabled", oldEnabled, enabled);
0N/A if (enabled != oldEnabled) {
0N/A repaint();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets the foreground color of this component. It is up to the
0N/A * look and feel to honor this property, some may choose to ignore
0N/A * it.
0N/A *
0N/A * @param fg the desired foreground <code>Color</code>
0N/A * @see java.awt.Component#getForeground
0N/A *
0N/A * @beaninfo
0N/A * preferred: true
0N/A * bound: true
0N/A * attribute: visualUpdate true
0N/A * description: The foreground color of the component.
0N/A */
0N/A public void setForeground(Color fg) {
0N/A Color oldFg = getForeground();
0N/A super.setForeground(fg);
0N/A if ((oldFg != null) ? !oldFg.equals(fg) : ((fg != null) && !fg.equals(oldFg))) {
0N/A // foreground already bound in AWT1.2
0N/A repaint();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets the background color of this component. The background
0N/A * color is used only if the component is opaque, and only
0N/A * by subclasses of <code>JComponent</code> or
0N/A * <code>ComponentUI</code> implementations. Direct subclasses of
0N/A * <code>JComponent</code> must override
0N/A * <code>paintComponent</code> to honor this property.
0N/A * <p>
0N/A * It is up to the look and feel to honor this property, some may
0N/A * choose to ignore it.
0N/A *
0N/A * @param bg the desired background <code>Color</code>
0N/A * @see java.awt.Component#getBackground
0N/A * @see #setOpaque
0N/A *
0N/A * @beaninfo
0N/A * preferred: true
0N/A * bound: true
0N/A * attribute: visualUpdate true
0N/A * description: The background color of the component.
0N/A */
0N/A public void setBackground(Color bg) {
0N/A Color oldBg = getBackground();
0N/A super.setBackground(bg);
0N/A if ((oldBg != null) ? !oldBg.equals(bg) : ((bg != null) && !bg.equals(oldBg))) {
0N/A // background already bound in AWT1.2
0N/A repaint();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets the font for this component.
0N/A *
0N/A * @param font the desired <code>Font</code> for this component
0N/A * @see java.awt.Component#getFont
0N/A *
0N/A * @beaninfo
0N/A * preferred: true
0N/A * bound: true
0N/A * attribute: visualUpdate true
0N/A * description: The font for the component.
0N/A */
0N/A public void setFont(Font font) {
0N/A Font oldFont = getFont();
0N/A super.setFont(font);
0N/A // font already bound in AWT1.2
0N/A if (font != oldFont) {
0N/A revalidate();
0N/A repaint();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the default locale used to initialize each JComponent's
0N/A * locale property upon creation.
0N/A *
0N/A * The default locale has "AppContext" scope so that applets (and
0N/A * potentially multiple lightweight applications running in a single VM)
0N/A * can have their own setting. An applet can safely alter its default
0N/A * locale because it will have no affect on other applets (or the browser).
0N/A *
0N/A * @return the default <code>Locale</code>.
0N/A * @see #setDefaultLocale
0N/A * @see java.awt.Component#getLocale
0N/A * @see #setLocale
0N/A * @since 1.4
0N/A */
0N/A static public Locale getDefaultLocale() {
0N/A Locale l = (Locale) SwingUtilities.appContextGet(defaultLocale);
0N/A if( l == null ) {
0N/A //REMIND(bcb) choosing the default value is more complicated
0N/A //than this.
0N/A l = Locale.getDefault();
0N/A JComponent.setDefaultLocale( l );
0N/A }
0N/A return l;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Sets the default locale used to initialize each JComponent's locale
0N/A * property upon creation. The initial value is the VM's default locale.
0N/A *
0N/A * The default locale has "AppContext" scope so that applets (and
0N/A * potentially multiple lightweight applications running in a single VM)
0N/A * can have their own setting. An applet can safely alter its default
0N/A * locale because it will have no affect on other applets (or the browser).
0N/A *
0N/A * @param l the desired default <code>Locale</code> for new components.
0N/A * @see #getDefaultLocale
0N/A * @see java.awt.Component#getLocale
0N/A * @see #setLocale
0N/A * @since 1.4
0N/A */
0N/A static public void setDefaultLocale( Locale l ) {
0N/A SwingUtilities.appContextPut(defaultLocale, l);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Processes any key events that the component itself
0N/A * recognizes. This is called after the focus
0N/A * manager and any interested listeners have been
0N/A * given a chance to steal away the event. This
0N/A * method is called only if the event has not
0N/A * yet been consumed. This method is called prior
0N/A * to the keyboard UI logic.
0N/A * <p>
0N/A * This method is implemented to do nothing. Subclasses would
0N/A * normally override this method if they process some
0N/A * key events themselves. If the event is processed,
0N/A * it should be consumed.
0N/A */
0N/A protected void processComponentKeyEvent(KeyEvent e) {
0N/A }
0N/A
0N/A /** Overrides <code>processKeyEvent</code> to process events. **/
0N/A protected void processKeyEvent(KeyEvent e) {
0N/A boolean result;
0N/A boolean shouldProcessKey;
0N/A
0N/A // This gives the key event listeners a crack at the event
0N/A super.processKeyEvent(e);
0N/A
0N/A // give the component itself a crack at the event
0N/A if (! e.isConsumed()) {
0N/A processComponentKeyEvent(e);
0N/A }
0N/A
0N/A shouldProcessKey = KeyboardState.shouldProcess(e);
0N/A
0N/A if(e.isConsumed()) {
0N/A return;
0N/A }
0N/A
0N/A if (shouldProcessKey && processKeyBindings(e, e.getID() ==
0N/A KeyEvent.KEY_PRESSED)) {
0N/A e.consume();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Invoked to process the key bindings for <code>ks</code> as the result
0N/A * of the <code>KeyEvent</code> <code>e</code>. This obtains
0N/A * the appropriate <code>InputMap</code>,
0N/A * gets the binding, gets the action from the <code>ActionMap</code>,
0N/A * and then (if the action is found and the component
0N/A * is enabled) invokes <code>notifyAction</code> to notify the action.
0N/A *
0N/A * @param ks the <code>KeyStroke</code> queried
0N/A * @param e the <code>KeyEvent</code>
0N/A * @param condition one of the following values:
0N/A * <ul>
0N/A * <li>JComponent.WHEN_FOCUSED
0N/A * <li>JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
0N/A * <li>JComponent.WHEN_IN_FOCUSED_WINDOW
0N/A * </ul>
0N/A * @param pressed true if the key is pressed
0N/A * @return true if there was a binding to an action, and the action
0N/A * was enabled
0N/A *
0N/A * @since 1.3
0N/A */
0N/A protected boolean processKeyBinding(KeyStroke ks, KeyEvent e,
0N/A int condition, boolean pressed) {
0N/A InputMap map = getInputMap(condition, false);
0N/A ActionMap am = getActionMap(false);
0N/A
0N/A if(map != null && am != null && isEnabled()) {
0N/A Object binding = map.get(ks);
0N/A Action action = (binding == null) ? null : am.get(binding);
0N/A if (action != null) {
0N/A return SwingUtilities.notifyAction(action, ks, e, this,
0N/A e.getModifiers());
0N/A }
0N/A }
0N/A return false;
0N/A }
0N/A
0N/A /**
0N/A * This is invoked as the result of a <code>KeyEvent</code>
0N/A * that was not consumed by the <code>FocusManager</code>,
0N/A * <code>KeyListeners</code>, or the component. It will first try
0N/A * <code>WHEN_FOCUSED</code> bindings,
0N/A * then <code>WHEN_ANCESTOR_OF_FOCUSED_COMPONENT</code> bindings,
0N/A * and finally <code>WHEN_IN_FOCUSED_WINDOW</code> bindings.
0N/A *
0N/A * @param e the unconsumed <code>KeyEvent</code>
0N/A * @param pressed true if the key is pressed
0N/A * @return true if there is a key binding for <code>e</code>
0N/A */
0N/A boolean processKeyBindings(KeyEvent e, boolean pressed) {
0N/A if (!SwingUtilities.isValidKeyEventForKeyBindings(e)) {
0N/A return false;
0N/A }
0N/A // Get the KeyStroke
1067N/A // There may be two keystrokes associated with a low-level key event;
1067N/A // in this case a keystroke made of an extended key code has a priority.
0N/A KeyStroke ks;
1067N/A KeyStroke ksE = null;
0N/A
0N/A if (e.getID() == KeyEvent.KEY_TYPED) {
0N/A ks = KeyStroke.getKeyStroke(e.getKeyChar());
0N/A }
0N/A else {
0N/A ks = KeyStroke.getKeyStroke(e.getKeyCode(),e.getModifiers(),
0N/A (pressed ? false:true));
1067N/A if (e.getKeyCode() != e.getExtendedKeyCode()) {
1067N/A ksE = KeyStroke.getKeyStroke(e.getExtendedKeyCode(),e.getModifiers(),
1067N/A (pressed ? false:true));
1067N/A }
0N/A }
0N/A
1067N/A // Do we have a key binding for e?
1067N/A // If we have a binding by an extended code, use it.
1067N/A // If not, check for regular code binding.
1067N/A if(ksE != null && processKeyBinding(ksE, e, WHEN_FOCUSED, pressed)) {
1067N/A return true;
1067N/A }
0N/A if(processKeyBinding(ks, e, WHEN_FOCUSED, pressed))
0N/A return true;
0N/A
0N/A /* We have no key binding. Let's try the path from our parent to the
0N/A * window excluded. We store the path components so we can avoid
0N/A * asking the same component twice.
0N/A */
0N/A Container parent = this;
0N/A while (parent != null && !(parent instanceof Window) &&
0N/A !(parent instanceof Applet)) {
0N/A if(parent instanceof JComponent) {
1067N/A if(ksE != null && ((JComponent)parent).processKeyBinding(ksE, e,
1067N/A WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, pressed))
1067N/A return true;
0N/A if(((JComponent)parent).processKeyBinding(ks, e,
0N/A WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, pressed))
0N/A return true;
0N/A }
0N/A // This is done so that the children of a JInternalFrame are
0N/A // given precedence for WHEN_IN_FOCUSED_WINDOW bindings before
0N/A // other components WHEN_IN_FOCUSED_WINDOW bindings. This also gives
0N/A // more precedence to the WHEN_IN_FOCUSED_WINDOW bindings of the
0N/A // JInternalFrame's children vs the
0N/A // WHEN_ANCESTOR_OF_FOCUSED_COMPONENT bindings of the parents.
0N/A // maybe generalize from JInternalFrame (like isFocusCycleRoot).
0N/A if ((parent instanceof JInternalFrame) &&
0N/A JComponent.processKeyBindingsForAllComponents(e,parent,pressed)){
0N/A return true;
0N/A }
0N/A parent = parent.getParent();
0N/A }
0N/A
0N/A /* No components between the focused component and the window is
0N/A * actually interested by the key event. Let's try the other
0N/A * JComponent in this window.
0N/A */
0N/A if(parent != null) {
0N/A return JComponent.processKeyBindingsForAllComponents(e,parent,pressed);
0N/A }
0N/A return false;
0N/A }
0N/A
0N/A static boolean processKeyBindingsForAllComponents(KeyEvent e,
0N/A Container container, boolean pressed) {
0N/A while (true) {
0N/A if (KeyboardManager.getCurrentManager().fireKeyboardAction(
0N/A e, pressed, container)) {
0N/A return true;
0N/A }
0N/A if (container instanceof Popup.HeavyWeightWindow) {
0N/A container = ((Window)container).getOwner();
0N/A }
0N/A else {
0N/A return false;
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Registers the text to display in a tool tip.
0N/A * The text displays when the cursor lingers over the component.
0N/A * <p>
0N/A * See <a href="http://java.sun.com/docs/books/tutorial/uiswing/components/tooltip.html">How to Use Tool Tips</a>
0N/A * in <em>The Java Tutorial</em>
0N/A * for further documentation.
0N/A *
0N/A * @param text the string to display; if the text is <code>null</code>,
0N/A * the tool tip is turned off for this component
0N/A * @see #TOOL_TIP_TEXT_KEY
0N/A * @beaninfo
0N/A * preferred: true
0N/A * description: The text to display in a tool tip.
0N/A */
0N/A public void setToolTipText(String text) {
0N/A String oldText = getToolTipText();
0N/A putClientProperty(TOOL_TIP_TEXT_KEY, text);
0N/A ToolTipManager toolTipManager = ToolTipManager.sharedInstance();
0N/A if (text != null) {
0N/A if (oldText == null) {
0N/A toolTipManager.registerComponent(this);
0N/A }
0N/A } else {
0N/A toolTipManager.unregisterComponent(this);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the tooltip string that has been set with
0N/A * <code>setToolTipText</code>.
0N/A *
0N/A * @return the text of the tool tip
0N/A * @see #TOOL_TIP_TEXT_KEY
0N/A */
0N/A public String getToolTipText() {
0N/A return (String)getClientProperty(TOOL_TIP_TEXT_KEY);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the string to be used as the tooltip for <i>event</i>.
0N/A * By default this returns any string set using
0N/A * <code>setToolTipText</code>. If a component provides
0N/A * more extensive API to support differing tooltips at different locations,
0N/A * this method should be overridden.
0N/A */
0N/A public String getToolTipText(MouseEvent event) {
0N/A return getToolTipText();
0N/A }
0N/A
0N/A /**
0N/A * Returns the tooltip location in this component's coordinate system.
0N/A * If <code>null</code> is returned, Swing will choose a location.
0N/A * The default implementation returns <code>null</code>.
0N/A *
0N/A * @param event the <code>MouseEvent</code> that caused the
0N/A * <code>ToolTipManager</code> to show the tooltip
0N/A * @return always returns <code>null</code>
0N/A */
0N/A public Point getToolTipLocation(MouseEvent event) {
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Returns the preferred location to display the popup menu in this
0N/A * component's coordinate system. It is up to the look and feel to
0N/A * honor this property, some may choose to ignore it.
0N/A * If {@code null}, the look and feel will choose a suitable location.
0N/A *
0N/A * @param event the {@code MouseEvent} that triggered the popup to be
0N/A * shown, or {@code null} if the popup is not being shown as the
0N/A * result of a mouse event
0N/A * @return location to display the {@code JPopupMenu}, or {@code null}
0N/A * @since 1.5
0N/A */
0N/A public Point getPopupLocation(MouseEvent event) {
0N/A return null;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the instance of <code>JToolTip</code> that should be used
0N/A * to display the tooltip.
0N/A * Components typically would not override this method,
0N/A * but it can be used to
0N/A * cause different tooltips to be displayed differently.
0N/A *
0N/A * @return the <code>JToolTip</code> used to display this toolTip
0N/A */
0N/A public JToolTip createToolTip() {
0N/A JToolTip tip = new JToolTip();
0N/A tip.setComponent(this);
0N/A return tip;
0N/A }
0N/A
0N/A /**
0N/A * Forwards the <code>scrollRectToVisible()</code> message to the
0N/A * <code>JComponent</code>'s parent. Components that can service
0N/A * the request, such as <code>JViewport</code>,
0N/A * override this method and perform the scrolling.
0N/A *
0N/A * @param aRect the visible <code>Rectangle</code>
0N/A * @see JViewport
0N/A */
0N/A public void scrollRectToVisible(Rectangle aRect) {
0N/A Container parent;
0N/A int dx = getX(), dy = getY();
0N/A
0N/A for (parent = getParent();
0N/A !(parent == null) &&
0N/A !(parent instanceof JComponent) &&
0N/A !(parent instanceof CellRendererPane);
0N/A parent = parent.getParent()) {
0N/A Rectangle bounds = parent.getBounds();
0N/A
0N/A dx += bounds.x;
0N/A dy += bounds.y;
0N/A }
0N/A
0N/A if (!(parent == null) && !(parent instanceof CellRendererPane)) {
0N/A aRect.x += dx;
0N/A aRect.y += dy;
0N/A
0N/A ((JComponent)parent).scrollRectToVisible(aRect);
0N/A aRect.x -= dx;
0N/A aRect.y -= dy;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets the <code>autoscrolls</code> property.
0N/A * If <code>true</code> mouse dragged events will be
0N/A * synthetically generated when the mouse is dragged
0N/A * outside of the component's bounds and mouse motion
0N/A * has paused (while the button continues to be held
0N/A * down). The synthetic events make it appear that the
0N/A * drag gesture has resumed in the direction established when
0N/A * the component's boundary was crossed. Components that
0N/A * support autoscrolling must handle <code>mouseDragged</code>
0N/A * events by calling <code>scrollRectToVisible</code> with a
0N/A * rectangle that contains the mouse event's location. All of
0N/A * the Swing components that support item selection and are
0N/A * typically displayed in a <code>JScrollPane</code>
0N/A * (<code>JTable</code>, <code>JList</code>, <code>JTree</code>,
0N/A * <code>JTextArea</code>, and <code>JEditorPane</code>)
0N/A * already handle mouse dragged events in this way. To enable
0N/A * autoscrolling in any other component, add a mouse motion
0N/A * listener that calls <code>scrollRectToVisible</code>.
0N/A * For example, given a <code>JPanel</code>, <code>myPanel</code>:
0N/A * <pre>
0N/A * MouseMotionListener doScrollRectToVisible = new MouseMotionAdapter() {
0N/A * public void mouseDragged(MouseEvent e) {
0N/A * Rectangle r = new Rectangle(e.getX(), e.getY(), 1, 1);
0N/A * ((JPanel)e.getSource()).scrollRectToVisible(r);
0N/A * }
0N/A * };
0N/A * myPanel.addMouseMotionListener(doScrollRectToVisible);
0N/A * </pre>
0N/A * The default value of the <code>autoScrolls</code>
0N/A * property is <code>false</code>.
0N/A *
0N/A * @param autoscrolls if true, synthetic mouse dragged events
0N/A * are generated when the mouse is dragged outside of a component's
0N/A * bounds and the mouse button continues to be held down; otherwise
0N/A * false
0N/A * @see #getAutoscrolls
0N/A * @see JViewport
0N/A * @see JScrollPane
0N/A *
0N/A * @beaninfo
0N/A * expert: true
0N/A * description: Determines if this component automatically scrolls its contents when dragged.
0N/A */
0N/A public void setAutoscrolls(boolean autoscrolls) {
0N/A setFlag(AUTOSCROLLS_SET, true);
0N/A if (this.autoscrolls != autoscrolls) {
0N/A this.autoscrolls = autoscrolls;
0N/A if (autoscrolls) {
0N/A enableEvents(AWTEvent.MOUSE_EVENT_MASK);
0N/A enableEvents(AWTEvent.MOUSE_MOTION_EVENT_MASK);
0N/A }
0N/A else {
0N/A Autoscroller.stop(this);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Gets the <code>autoscrolls</code> property.
0N/A *
0N/A * @return the value of the <code>autoscrolls</code> property
0N/A * @see JViewport
0N/A * @see #setAutoscrolls
0N/A */
0N/A public boolean getAutoscrolls() {
0N/A return autoscrolls;
0N/A }
0N/A
0N/A /**
0N/A * Sets the {@code TransferHandler}, which provides support for transfer
0N/A * of data into and out of this component via cut/copy/paste and drag
0N/A * and drop. This may be {@code null} if the component does not support
0N/A * data transfer operations.
0N/A * <p>
0N/A * If the new {@code TransferHandler} is not {@code null}, this method
0N/A * also installs a <b>new</b> {@code DropTarget} on the component to
0N/A * activate drop handling through the {@code TransferHandler} and activate
0N/A * any built-in support (such as calculating and displaying potential drop
0N/A * locations). If you do not wish for this component to respond in any way
0N/A * to drops, you can disable drop support entirely either by removing the
0N/A * drop target ({@code setDropTarget(null)}) or by de-activating it
0N/A * ({@code getDropTaget().setActive(false)}).
0N/A * <p>
0N/A * If the new {@code TransferHandler} is {@code null}, this method removes
0N/A * the drop target.
0N/A * <p>
0N/A * Under two circumstances, this method does not modify the drop target:
0N/A * First, if the existing drop target on this component was explicitly
0N/A * set by the developer to a {@code non-null} value. Second, if the
0N/A * system property {@code suppressSwingDropSupport} is {@code true}. The
0N/A * default value for the system property is {@code false}.
0N/A * <p>
0N/A * Please see
0N/A * <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/dnd.html">
0N/A * How to Use Drag and Drop and Data Transfer</a>,
0N/A * a section in <em>The Java Tutorial</em>, for more information.
0N/A *
0N/A * @param newHandler the new {@code TransferHandler}
0N/A *
0N/A * @see TransferHandler
0N/A * @see #getTransferHandler
0N/A * @since 1.4
0N/A * @beaninfo
0N/A * bound: true
0N/A * hidden: true
0N/A * description: Mechanism for transfer of data to and from the component
0N/A */
0N/A public void setTransferHandler(TransferHandler newHandler) {
0N/A TransferHandler oldHandler = (TransferHandler)getClientProperty(
0N/A JComponent_TRANSFER_HANDLER);
0N/A putClientProperty(JComponent_TRANSFER_HANDLER, newHandler);
0N/A
0N/A SwingUtilities.installSwingDropTargetAsNecessary(this, newHandler);
0N/A firePropertyChange("transferHandler", oldHandler, newHandler);
0N/A }
0N/A
0N/A /**
0N/A * Gets the <code>transferHandler</code> property.
0N/A *
0N/A * @return the value of the <code>transferHandler</code> property
0N/A *
0N/A * @see TransferHandler
0N/A * @see #setTransferHandler
0N/A * @since 1.4
0N/A */
0N/A public TransferHandler getTransferHandler() {
0N/A return (TransferHandler)getClientProperty(JComponent_TRANSFER_HANDLER);
0N/A }
0N/A
0N/A /**
0N/A * Calculates a custom drop location for this type of component,
0N/A * representing where a drop at the given point should insert data.
0N/A * <code>null</code> is returned if this component doesn't calculate
0N/A * custom drop locations. In this case, <code>TransferHandler</code>
0N/A * will provide a default <code>DropLocation</code> containing just
0N/A * the point.
0N/A *
0N/A * @param p the point to calculate a drop location for
0N/A * @return the drop location, or <code>null</code>
0N/A */
0N/A TransferHandler.DropLocation dropLocationForPoint(Point p) {
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Called to set or clear the drop location during a DnD operation.
0N/A * In some cases, the component may need to use its internal selection
0N/A * temporarily to indicate the drop location. To help facilitate this,
0N/A * this method returns and accepts as a parameter a state object.
0N/A * This state object can be used to store, and later restore, the selection
0N/A * state. Whatever this method returns will be passed back to it in
0N/A * future calls, as the state parameter. If it wants the DnD system to
0N/A * continue storing the same state, it must pass it back every time.
0N/A * Here's how this is used:
0N/A * <p>
0N/A * Let's say that on the first call to this method the component decides
0N/A * to save some state (because it is about to use the selection to show
0N/A * a drop index). It can return a state object to the caller encapsulating
0N/A * any saved selection state. On a second call, let's say the drop location
0N/A * is being changed to something else. The component doesn't need to
0N/A * restore anything yet, so it simply passes back the same state object
0N/A * to have the DnD system continue storing it. Finally, let's say this
0N/A * method is messaged with <code>null</code>. This means DnD
0N/A * is finished with this component for now, meaning it should restore
0N/A * state. At this point, it can use the state parameter to restore
0N/A * said state, and of course return <code>null</code> since there's
0N/A * no longer anything to store.
0N/A *
0N/A * @param location the drop location (as calculated by
0N/A * <code>dropLocationForPoint</code>) or <code>null</code>
0N/A * if there's no longer a valid drop location
0N/A * @param state the state object saved earlier for this component,
0N/A * or <code>null</code>
0N/A * @param forDrop whether or not the method is being called because an
0N/A * actual drop occurred
0N/A * @return any saved state for this component, or <code>null</code> if none
0N/A */
0N/A Object setDropLocation(TransferHandler.DropLocation location,
0N/A Object state,
0N/A boolean forDrop) {
0N/A
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Called to indicate to this component that DnD is done.
0N/A * Needed by <code>JTree</code>.
0N/A */
0N/A void dndDone() {
0N/A }
0N/A
0N/A /**
0N/A * Processes mouse events occurring on this component by
0N/A * dispatching them to any registered
0N/A * <code>MouseListener</code> objects, refer to
0N/A * {@link java.awt.Component#processMouseEvent(MouseEvent)}
0N/A * for a complete description of this method.
0N/A *
0N/A * @param e the mouse event
0N/A * @see java.awt.Component#processMouseEvent
0N/A * @since 1.5
0N/A */
0N/A protected void processMouseEvent(MouseEvent e) {
0N/A if (autoscrolls && e.getID() == MouseEvent.MOUSE_RELEASED) {
0N/A Autoscroller.stop(this);
0N/A }
0N/A super.processMouseEvent(e);
0N/A }
0N/A
0N/A /**
0N/A * Processes mouse motion events, such as MouseEvent.MOUSE_DRAGGED.
0N/A *
0N/A * @param e the <code>MouseEvent</code>
0N/A * @see MouseEvent
0N/A */
0N/A protected void processMouseMotionEvent(MouseEvent e) {
0N/A boolean dispatch = true;
0N/A if (autoscrolls && e.getID() == MouseEvent.MOUSE_DRAGGED) {
0N/A // We don't want to do the drags when the mouse moves if we're
0N/A // autoscrolling. It makes it feel spastic.
0N/A dispatch = !Autoscroller.isRunning(this);
0N/A Autoscroller.processMouseDragged(e);
0N/A }
0N/A if (dispatch) {
0N/A super.processMouseMotionEvent(e);
0N/A }
0N/A }
0N/A
0N/A // Inner classes can't get at this method from a super class
0N/A void superProcessMouseMotionEvent(MouseEvent e) {
0N/A super.processMouseMotionEvent(e);
0N/A }
0N/A
0N/A /**
0N/A * This is invoked by the <code>RepaintManager</code> if
0N/A * <code>createImage</code> is called on the component.
0N/A *
0N/A * @param newValue true if the double buffer image was created from this component
0N/A */
0N/A void setCreatedDoubleBuffer(boolean newValue) {
0N/A setFlag(CREATED_DOUBLE_BUFFER, newValue);
0N/A }
0N/A
0N/A /**
0N/A * Returns true if the <code>RepaintManager</code>
0N/A * created the double buffer image from the component.
0N/A *
0N/A * @return true if this component had a double buffer image, false otherwise
0N/A */
0N/A boolean getCreatedDoubleBuffer() {
0N/A return getFlag(CREATED_DOUBLE_BUFFER);
0N/A }
0N/A
0N/A /**
0N/A * <code>ActionStandin</code> is used as a standin for
0N/A * <code>ActionListeners</code> that are
0N/A * added via <code>registerKeyboardAction</code>.
0N/A */
0N/A final class ActionStandin implements Action {
0N/A private final ActionListener actionListener;
0N/A private final String command;
0N/A // This will be non-null if actionListener is an Action.
0N/A private final Action action;
0N/A
0N/A ActionStandin(ActionListener actionListener, String command) {
0N/A this.actionListener = actionListener;
0N/A if (actionListener instanceof Action) {
0N/A this.action = (Action)actionListener;
0N/A }
0N/A else {
0N/A this.action = null;
0N/A }
0N/A this.command = command;
0N/A }
0N/A
0N/A public Object getValue(String key) {
0N/A if (key != null) {
0N/A if (key.equals(Action.ACTION_COMMAND_KEY)) {
0N/A return command;
0N/A }
0N/A if (action != null) {
0N/A return action.getValue(key);
0N/A }
0N/A if (key.equals(NAME)) {
0N/A return "ActionStandin";
0N/A }
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A public boolean isEnabled() {
0N/A if (actionListener == null) {
0N/A // This keeps the old semantics where
0N/A // registerKeyboardAction(null) would essentialy remove
0N/A // the binding. We don't remove the binding from the
0N/A // InputMap as that would still allow parent InputMaps
0N/A // bindings to be accessed.
0N/A return false;
0N/A }
0N/A if (action == null) {
0N/A return true;
0N/A }
0N/A return action.isEnabled();
0N/A }
0N/A
0N/A public void actionPerformed(ActionEvent ae) {
0N/A if (actionListener != null) {
0N/A actionListener.actionPerformed(ae);
0N/A }
0N/A }
0N/A
0N/A // We don't allow any values to be added.
0N/A public void putValue(String key, Object value) {}
0N/A
0N/A // Does nothing, our enabledness is determiend from our asociated
0N/A // action.
0N/A public void setEnabled(boolean b) { }
0N/A
0N/A public void addPropertyChangeListener
0N/A (PropertyChangeListener listener) {}
0N/A public void removePropertyChangeListener
0N/A (PropertyChangeListener listener) {}
0N/A }
0N/A
0N/A
0N/A // This class is used by the KeyboardState class to provide a single
0N/A // instance that can be stored in the AppContext.
0N/A static final class IntVector {
0N/A int array[] = null;
0N/A int count = 0;
0N/A int capacity = 0;
0N/A
0N/A int size() {
0N/A return count;
0N/A }
0N/A
0N/A int elementAt(int index) {
0N/A return array[index];
0N/A }
0N/A
0N/A void addElement(int value) {
0N/A if (count == capacity) {
0N/A capacity = (capacity + 2) * 2;
0N/A int[] newarray = new int[capacity];
0N/A if (count > 0) {
0N/A System.arraycopy(array, 0, newarray, 0, count);
0N/A }
0N/A array = newarray;
0N/A }
0N/A array[count++] = value;
0N/A }
0N/A
0N/A void setElementAt(int value, int index) {
0N/A array[index] = value;
0N/A }
0N/A }
0N/A
0N/A static class KeyboardState implements Serializable {
0N/A private static final Object keyCodesKey =
0N/A JComponent.KeyboardState.class;
0N/A
0N/A // Get the array of key codes from the AppContext.
0N/A static IntVector getKeyCodeArray() {
0N/A IntVector iv =
0N/A (IntVector)SwingUtilities.appContextGet(keyCodesKey);
0N/A if (iv == null) {
0N/A iv = new IntVector();
0N/A SwingUtilities.appContextPut(keyCodesKey, iv);
0N/A }
0N/A return iv;
0N/A }
0N/A
0N/A static void registerKeyPressed(int keyCode) {
0N/A IntVector kca = getKeyCodeArray();
0N/A int count = kca.size();
0N/A int i;
0N/A for(i=0;i<count;i++) {
0N/A if(kca.elementAt(i) == -1){
0N/A kca.setElementAt(keyCode, i);
0N/A return;
0N/A }
0N/A }
0N/A kca.addElement(keyCode);
0N/A }
0N/A
0N/A static void registerKeyReleased(int keyCode) {
0N/A IntVector kca = getKeyCodeArray();
0N/A int count = kca.size();
0N/A int i;
0N/A for(i=0;i<count;i++) {
0N/A if(kca.elementAt(i) == keyCode) {
0N/A kca.setElementAt(-1, i);
0N/A return;
0N/A }
0N/A }
0N/A }
0N/A
0N/A static boolean keyIsPressed(int keyCode) {
0N/A IntVector kca = getKeyCodeArray();
0N/A int count = kca.size();
0N/A int i;
0N/A for(i=0;i<count;i++) {
0N/A if(kca.elementAt(i) == keyCode) {
0N/A return true;
0N/A }
0N/A }
0N/A return false;
0N/A }
0N/A
0N/A /**
0N/A * Updates internal state of the KeyboardState and returns true
0N/A * if the event should be processed further.
0N/A */
0N/A static boolean shouldProcess(KeyEvent e) {
0N/A switch (e.getID()) {
0N/A case KeyEvent.KEY_PRESSED:
0N/A if (!keyIsPressed(e.getKeyCode())) {
0N/A registerKeyPressed(e.getKeyCode());
0N/A }
0N/A return true;
0N/A case KeyEvent.KEY_RELEASED:
0N/A // We are forced to process VK_PRINTSCREEN separately because
0N/A // the Windows doesn't generate the key pressed event for
0N/A // printscreen and it block the processing of key release
0N/A // event for printscreen.
0N/A if (keyIsPressed(e.getKeyCode()) || e.getKeyCode()==KeyEvent.VK_PRINTSCREEN) {
0N/A registerKeyReleased(e.getKeyCode());
0N/A return true;
0N/A }
0N/A return false;
0N/A case KeyEvent.KEY_TYPED:
0N/A return true;
0N/A default:
0N/A // Not a known KeyEvent type, bail.
0N/A return false;
0N/A }
0N/A }
0N/A }
0N/A
0N/A static final sun.awt.RequestFocusController focusController =
0N/A new sun.awt.RequestFocusController() {
0N/A public boolean acceptRequestFocus(Component from, Component to,
0N/A boolean temporary, boolean focusedWindowChangeAllowed,
0N/A sun.awt.CausedFocusEvent.Cause cause)
0N/A {
0N/A if ((to == null) || !(to instanceof JComponent)) {
0N/A return true;
0N/A }
0N/A
0N/A if ((from == null) || !(from instanceof JComponent)) {
0N/A return true;
0N/A }
0N/A
0N/A JComponent target = (JComponent) to;
0N/A if (!target.getVerifyInputWhenFocusTarget()) {
0N/A return true;
0N/A }
0N/A
0N/A JComponent jFocusOwner = (JComponent)from;
0N/A InputVerifier iv = jFocusOwner.getInputVerifier();
0N/A
0N/A if (iv == null) {
0N/A return true;
0N/A } else {
0N/A Object currentSource = SwingUtilities.appContextGet(
0N/A INPUT_VERIFIER_SOURCE_KEY);
0N/A if (currentSource == jFocusOwner) {
0N/A // We're currently calling into the InputVerifier
0N/A // for this component, so allow the focus change.
0N/A return true;
0N/A }
0N/A SwingUtilities.appContextPut(INPUT_VERIFIER_SOURCE_KEY,
0N/A jFocusOwner);
0N/A try {
0N/A return iv.shouldYieldFocus(jFocusOwner);
0N/A } finally {
0N/A if (currentSource != null) {
0N/A // We're already in the InputVerifier for
0N/A // currentSource. By resetting the currentSource
0N/A // we ensure that if the InputVerifier for
0N/A // currentSource does a requestFocus, we don't
0N/A // try and run the InputVerifier again.
0N/A SwingUtilities.appContextPut(
0N/A INPUT_VERIFIER_SOURCE_KEY, currentSource);
0N/A } else {
0N/A SwingUtilities.appContextRemove(
0N/A INPUT_VERIFIER_SOURCE_KEY);
0N/A }
0N/A }
0N/A }
0N/A }
0N/A };
0N/A
0N/A /*
0N/A * --- Accessibility Support ---
0N/A */
0N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1,
0N/A * replaced by <code>java.awt.Component.setEnabled(boolean)</code>.
0N/A */
0N/A @Deprecated
0N/A public void enable() {
0N/A if (isEnabled() != true) {
0N/A super.enable();
0N/A if (accessibleContext != null) {
0N/A accessibleContext.firePropertyChange(
0N/A AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
0N/A null, AccessibleState.ENABLED);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1,
0N/A * replaced by <code>java.awt.Component.setEnabled(boolean)</code>.
0N/A */
0N/A @Deprecated
0N/A public void disable() {
0N/A if (isEnabled() != false) {
0N/A super.disable();
0N/A if (accessibleContext != null) {
0N/A accessibleContext.firePropertyChange(
0N/A AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
0N/A AccessibleState.ENABLED, null);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * The <code>AccessibleContext</code> associated with this
0N/A * <code>JComponent</code>.
0N/A */
0N/A protected AccessibleContext accessibleContext = null;
0N/A
0N/A /**
0N/A * Returns the <code>AccessibleContext</code> associated with this
0N/A * <code>JComponent</code>. The method implemented by this base
0N/A * class returns null. Classes that extend <code>JComponent</code>
0N/A * should implement this method to return the
0N/A * <code>AccessibleContext</code> associated with the subclass.
0N/A *
0N/A * @return the <code>AccessibleContext</code> of this
0N/A * <code>JComponent</code>
0N/A */
0N/A public AccessibleContext getAccessibleContext() {
0N/A return accessibleContext;
0N/A }
0N/A
0N/A /**
0N/A * Inner class of JComponent used to provide default support for
0N/A * accessibility. This class is not meant to be used directly by
0N/A * application developers, but is instead meant only to be
0N/A * subclassed by component developers.
0N/A * <p>
0N/A * <strong>Warning:</strong>
0N/A * Serialized objects of this class will not be compatible with
0N/A * future Swing releases. The current serialization support is
0N/A * appropriate for short term storage or RMI between applications running
0N/A * the same version of Swing. As of 1.4, support for long term storage
0N/A * of all JavaBeans<sup><font size="-2">TM</font></sup>
0N/A * has been added to the <code>java.beans</code> package.
0N/A * Please see {@link java.beans.XMLEncoder}.
0N/A */
0N/A public abstract class AccessibleJComponent extends AccessibleAWTContainer
0N/A implements AccessibleExtendedComponent
0N/A {
0N/A /**
0N/A * Though the class is abstract, this should be called by
0N/A * all sub-classes.
0N/A */
0N/A protected AccessibleJComponent() {
0N/A super();
0N/A }
0N/A
0N/A protected FocusListener accessibleFocusHandler = null;
0N/A
0N/A /**
0N/A * Fire PropertyChange listener, if one is registered,
0N/A * when children added/removed.
0N/A */
0N/A protected class AccessibleContainerHandler
0N/A implements ContainerListener {
0N/A public void componentAdded(ContainerEvent e) {
0N/A Component c = e.getChild();
0N/A if (c != null && c instanceof Accessible) {
0N/A AccessibleJComponent.this.firePropertyChange(
0N/A AccessibleContext.ACCESSIBLE_CHILD_PROPERTY,
625N/A null, c.getAccessibleContext());
0N/A }
0N/A }
0N/A public void componentRemoved(ContainerEvent e) {
0N/A Component c = e.getChild();
0N/A if (c != null && c instanceof Accessible) {
0N/A AccessibleJComponent.this.firePropertyChange(
0N/A AccessibleContext.ACCESSIBLE_CHILD_PROPERTY,
625N/A c.getAccessibleContext(), null);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Fire PropertyChange listener, if one is registered,
0N/A * when focus events happen
0N/A * @since 1.3
0N/A */
0N/A protected class AccessibleFocusHandler implements FocusListener {
0N/A public void focusGained(FocusEvent event) {
0N/A if (accessibleContext != null) {
0N/A accessibleContext.firePropertyChange(
0N/A AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
0N/A null, AccessibleState.FOCUSED);
0N/A }
0N/A }
0N/A public void focusLost(FocusEvent event) {
0N/A if (accessibleContext != null) {
0N/A accessibleContext.firePropertyChange(
0N/A AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
0N/A AccessibleState.FOCUSED, null);
0N/A }
0N/A }
0N/A } // inner class AccessibleFocusHandler
0N/A
0N/A
0N/A /**
0N/A * Adds a PropertyChangeListener to the listener list.
0N/A *
0N/A * @param listener the PropertyChangeListener to be added
0N/A */
0N/A public void addPropertyChangeListener(PropertyChangeListener listener) {
0N/A if (accessibleFocusHandler == null) {
0N/A accessibleFocusHandler = new AccessibleFocusHandler();
0N/A JComponent.this.addFocusListener(accessibleFocusHandler);
0N/A }
0N/A if (accessibleContainerHandler == null) {
0N/A accessibleContainerHandler = new AccessibleContainerHandler();
0N/A JComponent.this.addContainerListener(accessibleContainerHandler);
0N/A }
0N/A super.addPropertyChangeListener(listener);
0N/A }
0N/A
0N/A /**
0N/A * Removes a PropertyChangeListener from the listener list.
0N/A * This removes a PropertyChangeListener that was registered
0N/A * for all properties.
0N/A *
0N/A * @param listener the PropertyChangeListener to be removed
0N/A */
0N/A public void removePropertyChangeListener(PropertyChangeListener listener) {
0N/A if (accessibleFocusHandler != null) {
0N/A JComponent.this.removeFocusListener(accessibleFocusHandler);
0N/A accessibleFocusHandler = null;
0N/A }
0N/A super.removePropertyChangeListener(listener);
0N/A }
0N/A
0N/A
0N/A
0N/A /**
0N/A * Recursively search through the border hierarchy (if it exists)
0N/A * for a TitledBorder with a non-null title. This does a depth
0N/A * first search on first the inside borders then the outside borders.
0N/A * The assumption is that titles make really pretty inside borders
0N/A * but not very pretty outside borders in compound border situations.
0N/A * It's rather arbitrary, but hopefully decent UI programmers will
0N/A * not create multiple titled borders for the same component.
0N/A */
0N/A protected String getBorderTitle(Border b) {
0N/A String s;
0N/A if (b instanceof TitledBorder) {
0N/A return ((TitledBorder) b).getTitle();
0N/A } else if (b instanceof CompoundBorder) {
0N/A s = getBorderTitle(((CompoundBorder) b).getInsideBorder());
0N/A if (s == null) {
0N/A s = getBorderTitle(((CompoundBorder) b).getOutsideBorder());
0N/A }
0N/A return s;
0N/A } else {
0N/A return null;
0N/A }
0N/A }
0N/A
0N/A // AccessibleContext methods
0N/A //
0N/A /**
0N/A * Gets the accessible name of this object. This should almost never
0N/A * return java.awt.Component.getName(), as that generally isn't
0N/A * a localized name, and doesn't have meaning for the user. If the
0N/A * object is fundamentally a text object (such as a menu item), the
0N/A * accessible name should be the text of the object (for example,
0N/A * "save").
0N/A * If the object has a tooltip, the tooltip text may also be an
0N/A * appropriate String to return.
0N/A *
0N/A * @return the localized name of the object -- can be null if this
0N/A * object does not have a name
0N/A * @see AccessibleContext#setAccessibleName
0N/A */
0N/A public String getAccessibleName() {
0N/A String name = accessibleName;
0N/A
0N/A // fallback to the client name property
0N/A //
0N/A if (name == null) {
0N/A name = (String)getClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY);
0N/A }
0N/A
0N/A // fallback to the titled border if it exists
0N/A //
0N/A if (name == null) {
0N/A name = getBorderTitle(getBorder());
0N/A }
0N/A
0N/A // fallback to the label labeling us if it exists
0N/A //
0N/A if (name == null) {
0N/A Object o = getClientProperty(JLabel.LABELED_BY_PROPERTY);
0N/A if (o instanceof Accessible) {
0N/A AccessibleContext ac = ((Accessible) o).getAccessibleContext();
0N/A if (ac != null) {
0N/A name = ac.getAccessibleName();
0N/A }
0N/A }
0N/A }
0N/A return name;
0N/A }
0N/A
0N/A /**
0N/A * Gets the accessible description of this object. This should be
0N/A * a concise, localized description of what this object is - what
0N/A * is its meaning to the user. If the object has a tooltip, the
0N/A * tooltip text may be an appropriate string to return, assuming
0N/A * it contains a concise description of the object (instead of just
0N/A * the name of the object - for example a "Save" icon on a toolbar that
0N/A * had "save" as the tooltip text shouldn't return the tooltip
0N/A * text as the description, but something like "Saves the current
0N/A * text document" instead).
0N/A *
0N/A * @return the localized description of the object -- can be null if
0N/A * this object does not have a description
0N/A * @see AccessibleContext#setAccessibleDescription
0N/A */
0N/A public String getAccessibleDescription() {
0N/A String description = accessibleDescription;
0N/A
0N/A // fallback to the client description property
0N/A //
0N/A if (description == null) {
0N/A description = (String)getClientProperty(AccessibleContext.ACCESSIBLE_DESCRIPTION_PROPERTY);
0N/A }
0N/A
0N/A // fallback to the tool tip text if it exists
0N/A //
0N/A if (description == null) {
0N/A try {
0N/A description = getToolTipText();
0N/A } catch (Exception e) {
0N/A // Just in case the subclass overrode the
0N/A // getToolTipText method and actually
0N/A // requires a MouseEvent.
0N/A // [[[FIXME: WDW - we probably should require this
0N/A // method to take a MouseEvent and just pass it on
0N/A // to getToolTipText. The swing-feedback traffic
0N/A // leads me to believe getToolTipText might change,
0N/A // though, so I was hesitant to make this change at
0N/A // this time.]]]
0N/A }
0N/A }
0N/A
0N/A // fallback to the label labeling us if it exists
0N/A //
0N/A if (description == null) {
0N/A Object o = getClientProperty(JLabel.LABELED_BY_PROPERTY);
0N/A if (o instanceof Accessible) {
0N/A AccessibleContext ac = ((Accessible) o).getAccessibleContext();
0N/A if (ac != null) {
0N/A description = ac.getAccessibleDescription();
0N/A }
0N/A }
0N/A }
0N/A
0N/A return description;
0N/A }
0N/A
0N/A /**
0N/A * Gets the role of this object.
0N/A *
0N/A * @return an instance of AccessibleRole describing the role of the
0N/A * object
0N/A * @see AccessibleRole
0N/A */
0N/A public AccessibleRole getAccessibleRole() {
0N/A return AccessibleRole.SWING_COMPONENT;
0N/A }
0N/A
0N/A /**
0N/A * Gets the state of this object.
0N/A *
0N/A * @return an instance of AccessibleStateSet containing the current
0N/A * state set of the object
0N/A * @see AccessibleState
0N/A */
0N/A public AccessibleStateSet getAccessibleStateSet() {
0N/A AccessibleStateSet states = super.getAccessibleStateSet();
0N/A if (JComponent.this.isOpaque()) {
0N/A states.add(AccessibleState.OPAQUE);
0N/A }
0N/A return states;
0N/A }
0N/A
0N/A /**
0N/A * Returns the number of accessible children in the object. If all
0N/A * of the children of this object implement Accessible, than this
0N/A * method should return the number of children of this object.
0N/A *
0N/A * @return the number of accessible children in the object.
0N/A */
0N/A public int getAccessibleChildrenCount() {
0N/A return super.getAccessibleChildrenCount();
0N/A }
0N/A
0N/A /**
0N/A * Returns the nth Accessible child of the object.
0N/A *
0N/A * @param i zero-based index of child
0N/A * @return the nth Accessible child of the object
0N/A */
0N/A public Accessible getAccessibleChild(int i) {
0N/A return super.getAccessibleChild(i);
0N/A }
0N/A
0N/A // ----- AccessibleExtendedComponent
0N/A
0N/A /**
0N/A * Returns the AccessibleExtendedComponent
0N/A *
0N/A * @return the AccessibleExtendedComponent
0N/A */
0N/A AccessibleExtendedComponent getAccessibleExtendedComponent() {
0N/A return this;
0N/A }
0N/A
0N/A /**
0N/A * Returns the tool tip text
0N/A *
0N/A * @return the tool tip text, if supported, of the object;
0N/A * otherwise, null
0N/A * @since 1.4
0N/A */
0N/A public String getToolTipText() {
0N/A return JComponent.this.getToolTipText();
0N/A }
0N/A
0N/A /**
0N/A * Returns the titled border text
0N/A *
0N/A * @return the titled border text, if supported, of the object;
0N/A * otherwise, null
0N/A * @since 1.4
0N/A */
0N/A public String getTitledBorderText() {
0N/A Border border = JComponent.this.getBorder();
0N/A if (border instanceof TitledBorder) {
0N/A return ((TitledBorder)border).getTitle();
0N/A } else {
0N/A return null;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns key bindings associated with this object
0N/A *
0N/A * @return the key bindings, if supported, of the object;
0N/A * otherwise, null
0N/A * @see AccessibleKeyBinding
0N/A * @since 1.4
0N/A */
0N/A public AccessibleKeyBinding getAccessibleKeyBinding() {
0N/A return null;
0N/A }
0N/A } // inner class AccessibleJComponent
0N/A
0N/A
0N/A /**
0N/A * Returns an <code>ArrayTable</code> used for
0N/A * key/value "client properties" for this component. If the
0N/A * <code>clientProperties</code> table doesn't exist, an empty one
0N/A * will be created.
0N/A *
0N/A * @return an ArrayTable
0N/A * @see #putClientProperty
0N/A * @see #getClientProperty
0N/A */
0N/A private ArrayTable getClientProperties() {
0N/A if (clientProperties == null) {
0N/A clientProperties = new ArrayTable();
0N/A }
0N/A return clientProperties;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the value of the property with the specified key. Only
0N/A * properties added with <code>putClientProperty</code> will return
0N/A * a non-<code>null</code> value.
0N/A *
0N/A * @param key the being queried
0N/A * @return the value of this property or <code>null</code>
0N/A * @see #putClientProperty
0N/A */
0N/A public final Object getClientProperty(Object key) {
0N/A if (key == SwingUtilities2.AA_TEXT_PROPERTY_KEY) {
0N/A return aaTextInfo;
0N/A } else if (key == SwingUtilities2.COMPONENT_UI_PROPERTY_KEY) {
0N/A return ui;
0N/A }
0N/A if(clientProperties == null) {
0N/A return null;
0N/A } else {
0N/A synchronized(clientProperties) {
0N/A return clientProperties.get(key);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Adds an arbitrary key/value "client property" to this component.
0N/A * <p>
0N/A * The <code>get/putClientProperty</code> methods provide access to
0N/A * a small per-instance hashtable. Callers can use get/putClientProperty
0N/A * to annotate components that were created by another module.
0N/A * For example, a
0N/A * layout manager might store per child constraints this way. For example:
0N/A * <pre>
0N/A * componentA.putClientProperty("to the left of", componentB);
0N/A * </pre>
0N/A * If value is <code>null</code> this method will remove the property.
0N/A * Changes to client properties are reported with
0N/A * <code>PropertyChange</code> events.
0N/A * The name of the property (for the sake of PropertyChange
0N/A * events) is <code>key.toString()</code>.
0N/A * <p>
0N/A * The <code>clientProperty</code> dictionary is not intended to
0N/A * support large
0N/A * scale extensions to JComponent nor should be it considered an
0N/A * alternative to subclassing when designing a new component.
0N/A *
0N/A * @param key the new client property key
0N/A * @param value the new client property value; if <code>null</code>
0N/A * this method will remove the property
0N/A * @see #getClientProperty
0N/A * @see #addPropertyChangeListener
0N/A */
0N/A public final void putClientProperty(Object key, Object value) {
0N/A if (key == SwingUtilities2.AA_TEXT_PROPERTY_KEY) {
0N/A aaTextInfo = value;
0N/A return;
0N/A }
0N/A if (value == null && clientProperties == null) {
0N/A // Both the value and ArrayTable are null, implying we don't
0N/A // have to do anything.
0N/A return;
0N/A }
0N/A ArrayTable clientProperties = getClientProperties();
0N/A Object oldValue;
0N/A synchronized(clientProperties) {
0N/A oldValue = clientProperties.get(key);
0N/A if (value != null) {
0N/A clientProperties.put(key, value);
0N/A } else if (oldValue != null) {
0N/A clientProperties.remove(key);
0N/A } else {
0N/A // old == new == null
0N/A return;
0N/A }
0N/A }
0N/A clientPropertyChanged(key, oldValue, value);
0N/A firePropertyChange(key.toString(), oldValue, value);
0N/A }
0N/A
0N/A // Invoked from putClientProperty. This is provided for subclasses
0N/A // in Swing.
0N/A void clientPropertyChanged(Object key, Object oldValue,
0N/A Object newValue) {
0N/A }
0N/A
0N/A
0N/A /*
0N/A * Sets the property with the specified name to the specified value if
0N/A * the property has not already been set by the client program.
0N/A * This method is used primarily to set UI defaults for properties
0N/A * with primitive types, where the values cannot be marked with
0N/A * UIResource.
0N/A * @see LookAndFeel#installProperty
0N/A * @param propertyName String containing the name of the property
0N/A * @param value Object containing the property value
0N/A */
0N/A void setUIProperty(String propertyName, Object value) {
0N/A if (propertyName == "opaque") {
0N/A if (!getFlag(OPAQUE_SET)) {
0N/A setOpaque(((Boolean)value).booleanValue());
0N/A setFlag(OPAQUE_SET, false);
0N/A }
0N/A } else if (propertyName == "autoscrolls") {
0N/A if (!getFlag(AUTOSCROLLS_SET)) {
0N/A setAutoscrolls(((Boolean)value).booleanValue());
0N/A setFlag(AUTOSCROLLS_SET, false);
0N/A }
0N/A } else if (propertyName == "focusTraversalKeysForward") {
0N/A if (!getFlag(FOCUS_TRAVERSAL_KEYS_FORWARD_SET)) {
0N/A super.setFocusTraversalKeys(KeyboardFocusManager.
0N/A FORWARD_TRAVERSAL_KEYS,
0N/A (Set)value);
0N/A }
0N/A } else if (propertyName == "focusTraversalKeysBackward") {
0N/A if (!getFlag(FOCUS_TRAVERSAL_KEYS_BACKWARD_SET)) {
0N/A super.setFocusTraversalKeys(KeyboardFocusManager.
0N/A BACKWARD_TRAVERSAL_KEYS,
0N/A (Set)value);
0N/A }
0N/A } else {
0N/A throw new IllegalArgumentException("property \""+
0N/A propertyName+ "\" cannot be set using this method");
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Sets the focus traversal keys for a given traversal operation for this
0N/A * Component.
0N/A * Refer to
0N/A * {@link java.awt.Component#setFocusTraversalKeys}
0N/A * for a complete description of this method.
0N/A *
0N/A * @param id one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
0N/A * KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, or
0N/A * KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS
0N/A * @param keystrokes the Set of AWTKeyStroke for the specified operation
0N/A * @see java.awt.KeyboardFocusManager#FORWARD_TRAVERSAL_KEYS
0N/A * @see java.awt.KeyboardFocusManager#BACKWARD_TRAVERSAL_KEYS
0N/A * @see java.awt.KeyboardFocusManager#UP_CYCLE_TRAVERSAL_KEYS
0N/A * @throws IllegalArgumentException if id is not one of
0N/A * KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
0N/A * KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, or
0N/A * KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or if keystrokes
0N/A * contains null, or if any Object in keystrokes is not an
0N/A * AWTKeyStroke, or if any keystroke represents a KEY_TYPED event,
0N/A * or if any keystroke already maps to another focus traversal
0N/A * operation for this Component
0N/A * @since 1.5
0N/A * @beaninfo
0N/A * bound: true
0N/A */
0N/A public void
0N/A setFocusTraversalKeys(int id, Set<? extends AWTKeyStroke> keystrokes)
0N/A {
0N/A if (id == KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS) {
0N/A setFlag(FOCUS_TRAVERSAL_KEYS_FORWARD_SET,true);
0N/A } else if (id == KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS) {
0N/A setFlag(FOCUS_TRAVERSAL_KEYS_BACKWARD_SET,true);
0N/A }
0N/A super.setFocusTraversalKeys(id,keystrokes);
0N/A }
0N/A
0N/A /* --- Transitional java.awt.Component Support ---
0N/A * The methods and fields in this section will migrate to
0N/A * java.awt.Component in the next JDK release.
0N/A */
0N/A
0N/A /**
0N/A * Returns true if this component is lightweight, that is, if it doesn't
0N/A * have a native window system peer.
0N/A *
0N/A * @return true if this component is lightweight
0N/A */
0N/A public static boolean isLightweightComponent(Component c) {
0N/A return c.getPeer() instanceof LightweightPeer;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * @deprecated As of JDK 5,
0N/A * replaced by <code>Component.setBounds(int, int, int, int)</code>.
0N/A * <p>
0N/A * Moves and resizes this component.
0N/A *
0N/A * @param x the new horizontal location
0N/A * @param y the new vertical location
0N/A * @param w the new width
0N/A * @param h the new height
0N/A * @see java.awt.Component#setBounds
0N/A */
0N/A @Deprecated
0N/A public void reshape(int x, int y, int w, int h) {
0N/A super.reshape(x, y, w, h);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Stores the bounds of this component into "return value"
0N/A * <code>rv</code> and returns <code>rv</code>.
0N/A * If <code>rv</code> is <code>null</code> a new <code>Rectangle</code>
0N/A * is allocated. This version of <code>getBounds</code> is useful
0N/A * if the caller wants to avoid allocating a new <code>Rectangle</code>
0N/A * object on the heap.
0N/A *
0N/A * @param rv the return value, modified to the component's bounds
0N/A * @return <code>rv</code>; if <code>rv</code> is <code>null</code>
0N/A * return a newly created <code>Rectangle</code> with this
0N/A * component's bounds
0N/A */
0N/A public Rectangle getBounds(Rectangle rv) {
0N/A if (rv == null) {
0N/A return new Rectangle(getX(), getY(), getWidth(), getHeight());
0N/A }
0N/A else {
0N/A rv.setBounds(getX(), getY(), getWidth(), getHeight());
0N/A return rv;
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Stores the width/height of this component into "return value"
0N/A * <code>rv</code> and returns <code>rv</code>.
0N/A * If <code>rv</code> is <code>null</code> a new <code>Dimension</code>
0N/A * object is allocated. This version of <code>getSize</code>
0N/A * is useful if the caller wants to avoid allocating a new
0N/A * <code>Dimension</code> object on the heap.
0N/A *
0N/A * @param rv the return value, modified to the component's size
0N/A * @return <code>rv</code>
0N/A */
0N/A public Dimension getSize(Dimension rv) {
0N/A if (rv == null) {
0N/A return new Dimension(getWidth(), getHeight());
0N/A }
0N/A else {
0N/A rv.setSize(getWidth(), getHeight());
0N/A return rv;
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Stores the x,y origin of this component into "return value"
0N/A * <code>rv</code> and returns <code>rv</code>.
0N/A * If <code>rv</code> is <code>null</code> a new <code>Point</code>
0N/A * is allocated. This version of <code>getLocation</code> is useful
0N/A * if the caller wants to avoid allocating a new <code>Point</code>
0N/A * object on the heap.
0N/A *
0N/A * @param rv the return value, modified to the component's location
0N/A * @return <code>rv</code>
0N/A */
0N/A public Point getLocation(Point rv) {
0N/A if (rv == null) {
0N/A return new Point(getX(), getY());
0N/A }
0N/A else {
0N/A rv.setLocation(getX(), getY());
0N/A return rv;
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the current x coordinate of the component's origin.
0N/A * This method is preferable to writing
0N/A * <code>component.getBounds().x</code>, or
0N/A * <code>component.getLocation().x</code> because it doesn't cause any
0N/A * heap allocations.
0N/A *
0N/A * @return the current x coordinate of the component's origin
0N/A */
0N/A public int getX() { return super.getX(); }
0N/A
0N/A
0N/A /**
0N/A * Returns the current y coordinate of the component's origin.
0N/A * This method is preferable to writing
0N/A * <code>component.getBounds().y</code>, or
0N/A * <code>component.getLocation().y</code> because it doesn't cause any
0N/A * heap allocations.
0N/A *
0N/A * @return the current y coordinate of the component's origin
0N/A */
0N/A public int getY() { return super.getY(); }
0N/A
0N/A
0N/A /**
0N/A * Returns the current width of this component.
0N/A * This method is preferable to writing
0N/A * <code>component.getBounds().width</code>, or
0N/A * <code>component.getSize().width</code> because it doesn't cause any
0N/A * heap allocations.
0N/A *
0N/A * @return the current width of this component
0N/A */
0N/A public int getWidth() { return super.getWidth(); }
0N/A
0N/A
0N/A /**
0N/A * Returns the current height of this component.
0N/A * This method is preferable to writing
0N/A * <code>component.getBounds().height</code>, or
0N/A * <code>component.getSize().height</code> because it doesn't cause any
0N/A * heap allocations.
0N/A *
0N/A * @return the current height of this component
0N/A */
0N/A public int getHeight() { return super.getHeight(); }
0N/A
0N/A /**
0N/A * Returns true if this component is completely opaque.
0N/A * <p>
0N/A * An opaque component paints every pixel within its
0N/A * rectangular bounds. A non-opaque component paints only a subset of
0N/A * its pixels or none at all, allowing the pixels underneath it to
0N/A * "show through". Therefore, a component that does not fully paint
0N/A * its pixels provides a degree of transparency.
0N/A * <p>
0N/A * Subclasses that guarantee to always completely paint their contents
0N/A * should override this method and return true.
0N/A *
0N/A * @return true if this component is completely opaque
0N/A * @see #setOpaque
0N/A */
0N/A public boolean isOpaque() {
0N/A return getFlag(IS_OPAQUE);
0N/A }
0N/A
0N/A /**
0N/A * If true the component paints every pixel within its bounds.
0N/A * Otherwise, the component may not paint some or all of its
0N/A * pixels, allowing the underlying pixels to show through.
0N/A * <p>
0N/A * The default value of this property is false for <code>JComponent</code>.
0N/A * However, the default value for this property on most standard
0N/A * <code>JComponent</code> subclasses (such as <code>JButton</code> and
0N/A * <code>JTree</code>) is look-and-feel dependent.
0N/A *
0N/A * @param isOpaque true if this component should be opaque
0N/A * @see #isOpaque
0N/A * @beaninfo
0N/A * bound: true
0N/A * expert: true
0N/A * description: The component's opacity
0N/A */
0N/A public void setOpaque(boolean isOpaque) {
0N/A boolean oldValue = getFlag(IS_OPAQUE);
0N/A setFlag(IS_OPAQUE, isOpaque);
0N/A setFlag(OPAQUE_SET, true);
0N/A firePropertyChange("opaque", oldValue, isOpaque);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * If the specified rectangle is completely obscured by any of this
0N/A * component's opaque children then returns true. Only direct children
0N/A * are considered, more distant descendants are ignored. A
0N/A * <code>JComponent</code> is opaque if
0N/A * <code>JComponent.isOpaque()</code> returns true, other lightweight
0N/A * components are always considered transparent, and heavyweight components
0N/A * are always considered opaque.
0N/A *
0N/A * @param x x value of specified rectangle
0N/A * @param y y value of specified rectangle
0N/A * @param width width of specified rectangle
0N/A * @param height height of specified rectangle
0N/A * @return true if the specified rectangle is obscured by an opaque child
0N/A */
0N/A boolean rectangleIsObscured(int x,int y,int width,int height)
0N/A {
0N/A int numChildren = getComponentCount();
0N/A
0N/A for(int i = 0; i < numChildren; i++) {
0N/A Component child = getComponent(i);
0N/A int cx, cy, cw, ch;
0N/A
0N/A cx = child.getX();
0N/A cy = child.getY();
0N/A cw = child.getWidth();
0N/A ch = child.getHeight();
0N/A
0N/A if (x >= cx && (x + width) <= (cx + cw) &&
0N/A y >= cy && (y + height) <= (cy + ch) && child.isVisible()) {
0N/A
0N/A if(child instanceof JComponent) {
0N/A// System.out.println("A) checking opaque: " + ((JComponent)child).isOpaque() + " " + child);
0N/A// System.out.print("B) ");
0N/A// Thread.dumpStack();
625N/A return child.isOpaque();
0N/A } else {
0N/A /** Sometimes a heavy weight can have a bound larger than its peer size
0N/A * so we should always draw under heavy weights
0N/A */
0N/A return false;
0N/A }
0N/A }
0N/A }
0N/A
0N/A return false;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the <code>Component</code>'s "visible rect rectangle" - the
0N/A * intersection of the visible rectangles for the component <code>c</code>
0N/A * and all of its ancestors. The return value is stored in
0N/A * <code>visibleRect</code>.
0N/A *
0N/A * @param c the component
0N/A * @param visibleRect a <code>Rectangle</code> computed as the
0N/A * intersection of all visible rectangles for the component
0N/A * <code>c</code> and all of its ancestors -- this is the
0N/A * return value for this method
0N/A * @see #getVisibleRect
0N/A */
0N/A static final void computeVisibleRect(Component c, Rectangle visibleRect) {
0N/A Container p = c.getParent();
0N/A Rectangle bounds = c.getBounds();
0N/A
0N/A if (p == null || p instanceof Window || p instanceof Applet) {
0N/A visibleRect.setBounds(0, 0, bounds.width, bounds.height);
0N/A } else {
0N/A computeVisibleRect(p, visibleRect);
0N/A visibleRect.x -= bounds.x;
0N/A visibleRect.y -= bounds.y;
0N/A SwingUtilities.computeIntersection(0,0,bounds.width,bounds.height,visibleRect);
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the <code>Component</code>'s "visible rect rectangle" - the
0N/A * intersection of the visible rectangles for this component
0N/A * and all of its ancestors. The return value is stored in
0N/A * <code>visibleRect</code>.
0N/A *
0N/A * @param visibleRect a <code>Rectangle</code> computed as the
0N/A * intersection of all visible rectangles for this
0N/A * component and all of its ancestors -- this is the return
0N/A * value for this method
0N/A * @see #getVisibleRect
0N/A */
0N/A public void computeVisibleRect(Rectangle visibleRect) {
0N/A computeVisibleRect(this, visibleRect);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the <code>Component</code>'s "visible rectangle" - the
0N/A * intersection of this component's visible rectangle,
0N/A * <code>new Rectangle(0, 0, getWidth(), getHeight())</code>,
0N/A * and all of its ancestors' visible rectangles.
0N/A *
0N/A * @return the visible rectangle
0N/A */
0N/A public Rectangle getVisibleRect() {
0N/A Rectangle visibleRect = new Rectangle();
0N/A
0N/A computeVisibleRect(visibleRect);
0N/A return visibleRect;
0N/A }
0N/A
0N/A /**
0N/A * Support for reporting bound property changes for boolean properties.
0N/A * This method can be called when a bound property has changed and it will
0N/A * send the appropriate PropertyChangeEvent to any registered
0N/A * PropertyChangeListeners.
0N/A *
0N/A * @param propertyName the property whose value has changed
0N/A * @param oldValue the property's previous value
0N/A * @param newValue the property's new value
0N/A */
0N/A public void firePropertyChange(String propertyName,
0N/A boolean oldValue, boolean newValue) {
0N/A super.firePropertyChange(propertyName, oldValue, newValue);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Support for reporting bound property changes for integer properties.
0N/A * This method can be called when a bound property has changed and it will
0N/A * send the appropriate PropertyChangeEvent to any registered
0N/A * PropertyChangeListeners.
0N/A *
0N/A * @param propertyName the property whose value has changed
0N/A * @param oldValue the property's previous value
0N/A * @param newValue the property's new value
0N/A */
0N/A public void firePropertyChange(String propertyName,
0N/A int oldValue, int newValue) {
0N/A super.firePropertyChange(propertyName, oldValue, newValue);
0N/A }
0N/A
0N/A // XXX This method is implemented as a workaround to a JLS issue with ambiguous
0N/A // methods. This should be removed once 4758654 is resolved.
0N/A public void firePropertyChange(String propertyName, char oldValue, char newValue) {
0N/A super.firePropertyChange(propertyName, oldValue, newValue);
0N/A }
0N/A
0N/A /**
0N/A * Supports reporting constrained property changes.
0N/A * This method can be called when a constrained property has changed
0N/A * and it will send the appropriate <code>PropertyChangeEvent</code>
0N/A * to any registered <code>VetoableChangeListeners</code>.
0N/A *
0N/A * @param propertyName the name of the property that was listened on
0N/A * @param oldValue the old value of the property
0N/A * @param newValue the new value of the property
0N/A * @exception PropertyVetoException when the attempt to set the
0N/A * property is vetoed by the component
0N/A */
0N/A protected void fireVetoableChange(String propertyName, Object oldValue, Object newValue)
0N/A throws java.beans.PropertyVetoException
0N/A {
0N/A if (vetoableChangeSupport == null) {
0N/A return;
0N/A }
0N/A vetoableChangeSupport.fireVetoableChange(propertyName, oldValue, newValue);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Adds a <code>VetoableChangeListener</code> to the listener list.
0N/A * The listener is registered for all properties.
0N/A *
0N/A * @param listener the <code>VetoableChangeListener</code> to be added
0N/A */
0N/A public synchronized void addVetoableChangeListener(VetoableChangeListener listener) {
0N/A if (vetoableChangeSupport == null) {
0N/A vetoableChangeSupport = new java.beans.VetoableChangeSupport(this);
0N/A }
0N/A vetoableChangeSupport.addVetoableChangeListener(listener);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Removes a <code>VetoableChangeListener</code> from the listener list.
0N/A * This removes a <code>VetoableChangeListener</code> that was registered
0N/A * for all properties.
0N/A *
0N/A * @param listener the <code>VetoableChangeListener</code> to be removed
0N/A */
0N/A public synchronized void removeVetoableChangeListener(VetoableChangeListener listener) {
0N/A if (vetoableChangeSupport == null) {
0N/A return;
0N/A }
0N/A vetoableChangeSupport.removeVetoableChangeListener(listener);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns an array of all the vetoable change listeners
0N/A * registered on this component.
0N/A *
0N/A * @return all of the component's <code>VetoableChangeListener</code>s
0N/A * or an empty
0N/A * array if no vetoable change listeners are currently registered
0N/A *
0N/A * @see #addVetoableChangeListener
0N/A * @see #removeVetoableChangeListener
0N/A *
0N/A * @since 1.4
0N/A */
0N/A public synchronized VetoableChangeListener[] getVetoableChangeListeners() {
0N/A if (vetoableChangeSupport == null) {
0N/A return new VetoableChangeListener[0];
0N/A }
0N/A return vetoableChangeSupport.getVetoableChangeListeners();
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the top-level ancestor of this component (either the
0N/A * containing <code>Window</code> or <code>Applet</code>),
0N/A * or <code>null</code> if this component has not
0N/A * been added to any container.
0N/A *
0N/A * @return the top-level <code>Container</code> that this component is in,
0N/A * or <code>null</code> if not in any container
0N/A */
0N/A public Container getTopLevelAncestor() {
0N/A for(Container p = this; p != null; p = p.getParent()) {
0N/A if(p instanceof Window || p instanceof Applet) {
0N/A return p;
0N/A }
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A private AncestorNotifier getAncestorNotifier() {
0N/A return (AncestorNotifier)
0N/A getClientProperty(JComponent_ANCESTOR_NOTIFIER);
0N/A }
0N/A
0N/A /**
0N/A * Registers <code>listener</code> so that it will receive
0N/A * <code>AncestorEvents</code> when it or any of its ancestors
0N/A * move or are made visible or invisible.
0N/A * Events are also sent when the component or its ancestors are added
0N/A * or removed from the containment hierarchy.
0N/A *
0N/A * @param listener the <code>AncestorListener</code> to register
0N/A * @see AncestorEvent
0N/A */
0N/A public void addAncestorListener(AncestorListener listener) {
0N/A AncestorNotifier ancestorNotifier = getAncestorNotifier();
0N/A if (ancestorNotifier == null) {
0N/A ancestorNotifier = new AncestorNotifier(this);
0N/A putClientProperty(JComponent_ANCESTOR_NOTIFIER,
0N/A ancestorNotifier);
0N/A }
0N/A ancestorNotifier.addAncestorListener(listener);
0N/A }
0N/A
0N/A /**
0N/A * Unregisters <code>listener</code> so that it will no longer receive
0N/A * <code>AncestorEvents</code>.
0N/A *
0N/A * @param listener the <code>AncestorListener</code> to be removed
0N/A * @see #addAncestorListener
0N/A */
0N/A public void removeAncestorListener(AncestorListener listener) {
0N/A AncestorNotifier ancestorNotifier = getAncestorNotifier();
0N/A if (ancestorNotifier == null) {
0N/A return;
0N/A }
0N/A ancestorNotifier.removeAncestorListener(listener);
0N/A if (ancestorNotifier.listenerList.getListenerList().length == 0) {
0N/A ancestorNotifier.removeAllListeners();
0N/A putClientProperty(JComponent_ANCESTOR_NOTIFIER, null);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns an array of all the ancestor listeners
0N/A * registered on this component.
0N/A *
0N/A * @return all of the component's <code>AncestorListener</code>s
0N/A * or an empty
0N/A * array if no ancestor listeners are currently registered
0N/A *
0N/A * @see #addAncestorListener
0N/A * @see #removeAncestorListener
0N/A *
0N/A * @since 1.4
0N/A */
0N/A public AncestorListener[] getAncestorListeners() {
0N/A AncestorNotifier ancestorNotifier = getAncestorNotifier();
0N/A if (ancestorNotifier == null) {
0N/A return new AncestorListener[0];
0N/A }
0N/A return ancestorNotifier.getAncestorListeners();
0N/A }
0N/A
0N/A /**
0N/A * Returns an array of all the objects currently registered
0N/A * as <code><em>Foo</em>Listener</code>s
0N/A * upon this <code>JComponent</code>.
0N/A * <code><em>Foo</em>Listener</code>s are registered using the
0N/A * <code>add<em>Foo</em>Listener</code> method.
0N/A *
0N/A * <p>
0N/A *
0N/A * You can specify the <code>listenerType</code> argument
0N/A * with a class literal,
0N/A * such as
0N/A * <code><em>Foo</em>Listener.class</code>.
0N/A * For example, you can query a
0N/A * <code>JComponent</code> <code>c</code>
0N/A * for its mouse listeners with the following code:
0N/A * <pre>MouseListener[] mls = (MouseListener[])(c.getListeners(MouseListener.class));</pre>
0N/A * If no such listeners exist, this method returns an empty array.
0N/A *
0N/A * @param listenerType the type of listeners requested; this parameter
0N/A * should specify an interface that descends from
0N/A * <code>java.util.EventListener</code>
0N/A * @return an array of all objects registered as
0N/A * <code><em>Foo</em>Listener</code>s on this component,
0N/A * or an empty array if no such
0N/A * listeners have been added
0N/A * @exception ClassCastException if <code>listenerType</code>
0N/A * doesn't specify a class or interface that implements
0N/A * <code>java.util.EventListener</code>
0N/A *
0N/A * @since 1.3
0N/A *
0N/A * @see #getVetoableChangeListeners
0N/A * @see #getAncestorListeners
0N/A */
0N/A public <T extends EventListener> T[] getListeners(Class<T> listenerType) {
0N/A T[] result;
0N/A if (listenerType == AncestorListener.class) {
0N/A // AncestorListeners are handled by the AncestorNotifier
0N/A result = (T[])getAncestorListeners();
0N/A }
0N/A else if (listenerType == VetoableChangeListener.class) {
0N/A // VetoableChangeListeners are handled by VetoableChangeSupport
0N/A result = (T[])getVetoableChangeListeners();
0N/A }
0N/A else if (listenerType == PropertyChangeListener.class) {
0N/A // PropertyChangeListeners are handled by PropertyChangeSupport
0N/A result = (T[])getPropertyChangeListeners();
0N/A }
0N/A else {
625N/A result = listenerList.getListeners(listenerType);
0N/A }
0N/A
0N/A if (result.length == 0) {
0N/A return super.getListeners(listenerType);
0N/A }
0N/A return result;
0N/A }
0N/A
0N/A /**
0N/A * Notifies this component that it now has a parent component.
0N/A * When this method is invoked, the chain of parent components is
0N/A * set up with <code>KeyboardAction</code> event listeners.
3030N/A * This method is called by the toolkit internally and should
3030N/A * not be called directly by programs.
0N/A *
0N/A * @see #registerKeyboardAction
0N/A */
0N/A public void addNotify() {
0N/A super.addNotify();
0N/A firePropertyChange("ancestor", null, getParent());
0N/A
0N/A registerWithKeyboardManager(false);
0N/A registerNextFocusableComponent();
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Notifies this component that it no longer has a parent component.
0N/A * When this method is invoked, any <code>KeyboardAction</code>s
0N/A * set up in the the chain of parent components are removed.
3030N/A * This method is called by the toolkit internally and should
3030N/A * not be called directly by programs.
0N/A *
0N/A * @see #registerKeyboardAction
0N/A */
0N/A public void removeNotify() {
0N/A super.removeNotify();
0N/A // This isn't strictly correct. The event shouldn't be
0N/A // fired until *after* the parent is set to null. But
0N/A // we only get notified before that happens
0N/A firePropertyChange("ancestor", getParent(), null);
0N/A
0N/A unregisterWithKeyboardManager();
0N/A deregisterNextFocusableComponent();
0N/A
0N/A if (getCreatedDoubleBuffer()) {
0N/A RepaintManager.currentManager(this).resetDoubleBuffer();
0N/A setCreatedDoubleBuffer(false);
0N/A }
0N/A if (autoscrolls) {
0N/A Autoscroller.stop(this);
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Adds the specified region to the dirty region list if the component
0N/A * is showing. The component will be repainted after all of the
0N/A * currently pending events have been dispatched.
0N/A *
0N/A * @param tm this parameter is not used
0N/A * @param x the x value of the dirty region
0N/A * @param y the y value of the dirty region
0N/A * @param width the width of the dirty region
0N/A * @param height the height of the dirty region
2964N/A * @see #isPaintingOrigin()
0N/A * @see java.awt.Component#isShowing
0N/A * @see RepaintManager#addDirtyRegion
0N/A */
0N/A public void repaint(long tm, int x, int y, int width, int height) {
0N/A RepaintManager.currentManager(this).addDirtyRegion(this, x, y, width, height);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Adds the specified region to the dirty region list if the component
0N/A * is showing. The component will be repainted after all of the
0N/A * currently pending events have been dispatched.
0N/A *
0N/A * @param r a <code>Rectangle</code> containing the dirty region
2964N/A * @see #isPaintingOrigin()
0N/A * @see java.awt.Component#isShowing
0N/A * @see RepaintManager#addDirtyRegion
0N/A */
0N/A public void repaint(Rectangle r) {
0N/A repaint(0,r.x,r.y,r.width,r.height);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Supports deferred automatic layout.
0N/A * <p>
0N/A * Calls <code>invalidate</code> and then adds this component's
0N/A * <code>validateRoot</code> to a list of components that need to be
0N/A * validated. Validation will occur after all currently pending
0N/A * events have been dispatched. In other words after this method
0N/A * is called, the first validateRoot (if any) found when walking
0N/A * up the containment hierarchy of this component will be validated.
0N/A * By default, <code>JRootPane</code>, <code>JScrollPane</code>,
0N/A * and <code>JTextField</code> return true
0N/A * from <code>isValidateRoot</code>.
0N/A * <p>
0N/A * This method will automatically be called on this component
0N/A * when a property value changes such that size, location, or
0N/A * internal layout of this component has been affected. This automatic
0N/A * updating differs from the AWT because programs generally no
0N/A * longer need to invoke <code>validate</code> to get the contents of the
0N/A * GUI to update.
0N/A * <p>
0N/A *
0N/A * @see java.awt.Component#invalidate
0N/A * @see java.awt.Container#validate
0N/A * @see #isValidateRoot
0N/A * @see RepaintManager#addInvalidComponent
0N/A */
0N/A public void revalidate() {
0N/A if (getParent() == null) {
0N/A // Note: We don't bother invalidating here as once added
0N/A // to a valid parent invalidate will be invoked (addImpl
0N/A // invokes addNotify which will invoke invalidate on the
0N/A // new Component). Also, if we do add a check to isValid
0N/A // here it can potentially be called before the constructor
0N/A // which was causing some people grief.
0N/A return;
0N/A }
0N/A if (SwingUtilities.isEventDispatchThread()) {
0N/A invalidate();
0N/A RepaintManager.currentManager(this).addInvalidComponent(this);
0N/A }
0N/A else {
0N/A // To avoid a flood of Runnables when constructing GUIs off
0N/A // the EDT, a flag is maintained as to whether or not
0N/A // a Runnable has been scheduled.
0N/A synchronized(this) {
0N/A if (getFlag(REVALIDATE_RUNNABLE_SCHEDULED)) {
0N/A return;
0N/A }
0N/A setFlag(REVALIDATE_RUNNABLE_SCHEDULED, true);
0N/A }
0N/A Runnable callRevalidate = new Runnable() {
0N/A public void run() {
0N/A synchronized(JComponent.this) {
0N/A setFlag(REVALIDATE_RUNNABLE_SCHEDULED, false);
0N/A }
0N/A revalidate();
0N/A }
0N/A };
0N/A SwingUtilities.invokeLater(callRevalidate);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * If this method returns true, <code>revalidate</code> calls by
0N/A * descendants of this component will cause the entire tree
0N/A * beginning with this root to be validated.
0N/A * Returns false by default. <code>JScrollPane</code> overrides
0N/A * this method and returns true.
0N/A *
0N/A * @return always returns false
0N/A * @see #revalidate
0N/A * @see java.awt.Component#invalidate
0N/A * @see java.awt.Container#validate
1895N/A * @see java.awt.Container#isValidateRoot
1895N/A */
1895N/A @Override
0N/A public boolean isValidateRoot() {
0N/A return false;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns true if this component tiles its children -- that is, if
0N/A * it can guarantee that the children will not overlap. The
0N/A * repainting system is substantially more efficient in this
0N/A * common case. <code>JComponent</code> subclasses that can't make this
0N/A * guarantee, such as <code>JLayeredPane</code>,
0N/A * should override this method to return false.
0N/A *
0N/A * @return always returns true
0N/A */
0N/A public boolean isOptimizedDrawingEnabled() {
0N/A return true;
0N/A }
0N/A
0N/A /**
2964N/A * Returns {@code true} if a paint triggered on a child component should cause
0N/A * painting to originate from this Component, or one of its ancestors.
2964N/A * <p/>
3555N/A * Calling {@link #repaint} or {@link #paintImmediately(int, int, int, int)}
3555N/A * on a Swing component will result in calling
3555N/A * the {@link JComponent#paintImmediately(int, int, int, int)} method of
3565N/A * the first ancestor which {@code isPaintingOrigin()} returns {@code true}, if there are any.
2964N/A * <p/>
3555N/A * {@code JComponent} subclasses that need to be painted when any of their
2964N/A * children are repainted should override this method to return {@code true}.
0N/A *
2964N/A * @return always returns {@code false}
3555N/A *
3555N/A * @see #paintImmediately(int, int, int, int)
2964N/A */
2964N/A protected boolean isPaintingOrigin() {
0N/A return false;
0N/A }
0N/A
0N/A /**
0N/A * Paints the specified region in this component and all of its
0N/A * descendants that overlap the region, immediately.
0N/A * <p>
0N/A * It's rarely necessary to call this method. In most cases it's
0N/A * more efficient to call repaint, which defers the actual painting
0N/A * and can collapse redundant requests into a single paint call.
0N/A * This method is useful if one needs to update the display while
0N/A * the current event is being dispatched.
3555N/A * <p>
3555N/A * This method is to be overridden when the dirty region needs to be changed
3555N/A * for components that are painting origins.
0N/A *
0N/A * @param x the x value of the region to be painted
0N/A * @param y the y value of the region to be painted
0N/A * @param w the width of the region to be painted
0N/A * @param h the height of the region to be painted
0N/A * @see #repaint
3555N/A * @see #isPaintingOrigin()
0N/A */
0N/A public void paintImmediately(int x,int y,int w, int h) {
0N/A Component c = this;
0N/A Component parent;
0N/A
0N/A if(!isShowing()) {
0N/A return;
0N/A }
3555N/A
3555N/A JComponent paintingOigin = SwingUtilities.getPaintingOrigin(this);
3555N/A if (paintingOigin != null) {
3555N/A Rectangle rectangle = SwingUtilities.convertRectangle(
3555N/A c, new Rectangle(x, y, w, h), paintingOigin);
3555N/A paintingOigin.paintImmediately(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
3555N/A return;
3555N/A }
3555N/A
625N/A while(!c.isOpaque()) {
0N/A parent = c.getParent();
0N/A if(parent != null) {
0N/A x += c.getX();
0N/A y += c.getY();
0N/A c = parent;
0N/A } else {
0N/A break;
0N/A }
0N/A
0N/A if(!(c instanceof JComponent)) {
0N/A break;
0N/A }
0N/A }
0N/A if(c instanceof JComponent) {
0N/A ((JComponent)c)._paintImmediately(x,y,w,h);
0N/A } else {
0N/A c.repaint(x,y,w,h);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Paints the specified region now.
0N/A *
0N/A * @param r a <code>Rectangle</code> containing the region to be painted
0N/A */
0N/A public void paintImmediately(Rectangle r) {
0N/A paintImmediately(r.x,r.y,r.width,r.height);
0N/A }
0N/A
0N/A /**
0N/A * Returns whether this component should be guaranteed to be on top.
0N/A * For example, it would make no sense for <code>Menu</code>s to pop up
0N/A * under another component, so they would always return true.
0N/A * Most components will want to return false, hence that is the default.
0N/A *
0N/A * @return always returns false
0N/A */
0N/A // package private
0N/A boolean alwaysOnTop() {
0N/A return false;
0N/A }
0N/A
0N/A void setPaintingChild(Component paintingChild) {
0N/A this.paintingChild = paintingChild;
0N/A }
0N/A
0N/A void _paintImmediately(int x, int y, int w, int h) {
0N/A Graphics g;
0N/A Container c;
0N/A Rectangle b;
0N/A
0N/A int tmpX, tmpY, tmpWidth, tmpHeight;
0N/A int offsetX=0,offsetY=0;
0N/A
0N/A boolean hasBuffer = false;
0N/A
0N/A JComponent bufferedComponent = null;
0N/A JComponent paintingComponent = this;
0N/A
0N/A RepaintManager repaintManager = RepaintManager.currentManager(this);
0N/A // parent Container's up to Window or Applet. First container is
0N/A // the direct parent. Note that in testing it was faster to
0N/A // alloc a new Vector vs keeping a stack of them around, and gc
0N/A // seemed to have a minimal effect on this.
0N/A java.util.List<Component> path = new java.util.ArrayList<Component>(7);
0N/A int pIndex = -1;
0N/A int pCount = 0;
0N/A
0N/A tmpX = tmpY = tmpWidth = tmpHeight = 0;
0N/A
0N/A Rectangle paintImmediatelyClip = fetchRectangle();
0N/A paintImmediatelyClip.x = x;
0N/A paintImmediatelyClip.y = y;
0N/A paintImmediatelyClip.width = w;
0N/A paintImmediatelyClip.height = h;
0N/A
0N/A
0N/A // System.out.println("1) ************* in _paintImmediately for " + this);
0N/A
0N/A boolean ontop = alwaysOnTop() && isOpaque();
0N/A if (ontop) {
0N/A SwingUtilities.computeIntersection(0, 0, getWidth(), getHeight(),
0N/A paintImmediatelyClip);
0N/A if (paintImmediatelyClip.width == 0) {
0N/A recycleRectangle(paintImmediatelyClip);
0N/A return;
0N/A }
0N/A }
0N/A Component child;
0N/A for (c = this, child = null;
0N/A c != null && !(c instanceof Window) && !(c instanceof Applet);
0N/A child = c, c = c.getParent()) {
0N/A JComponent jc = (c instanceof JComponent) ? (JComponent)c :
0N/A null;
0N/A path.add(c);
0N/A if(!ontop && jc != null && !jc.isOptimizedDrawingEnabled()) {
0N/A boolean resetPC;
0N/A
0N/A // Children of c may overlap, three possible cases for the
0N/A // painting region:
0N/A // . Completely obscured by an opaque sibling, in which
0N/A // case there is no need to paint.
0N/A // . Partially obscured by a sibling: need to start
0N/A // painting from c.
0N/A // . Otherwise we aren't obscured and thus don't need to
0N/A // start painting from parent.
0N/A if (c != this) {
0N/A if (jc.isPaintingOrigin()) {
0N/A resetPC = true;
0N/A }
0N/A else {
0N/A Component[] children = c.getComponents();
0N/A int i = 0;
0N/A for (; i<children.length; i++) {
0N/A if (children[i] == child) break;
0N/A }
0N/A switch (jc.getObscuredState(i,
0N/A paintImmediatelyClip.x,
0N/A paintImmediatelyClip.y,
0N/A paintImmediatelyClip.width,
0N/A paintImmediatelyClip.height)) {
0N/A case NOT_OBSCURED:
0N/A resetPC = false;
0N/A break;
0N/A case COMPLETELY_OBSCURED:
0N/A recycleRectangle(paintImmediatelyClip);
0N/A return;
0N/A default:
0N/A resetPC = true;
0N/A break;
0N/A }
0N/A }
0N/A }
0N/A else {
0N/A resetPC = false;
0N/A }
0N/A
0N/A if (resetPC) {
0N/A // Get rid of any buffer since we draw from here and
0N/A // we might draw something larger
0N/A paintingComponent = jc;
0N/A pIndex = pCount;
0N/A offsetX = offsetY = 0;
0N/A hasBuffer = false;
0N/A }
0N/A }
0N/A pCount++;
0N/A
0N/A // look to see if the parent (and therefor this component)
0N/A // is double buffered
0N/A if(repaintManager.isDoubleBufferingEnabled() && jc != null &&
0N/A jc.isDoubleBuffered()) {
0N/A hasBuffer = true;
0N/A bufferedComponent = jc;
0N/A }
0N/A
0N/A // if we aren't on top, include the parent's clip
0N/A if (!ontop) {
0N/A int bx = c.getX();
0N/A int by = c.getY();
0N/A tmpWidth = c.getWidth();
0N/A tmpHeight = c.getHeight();
0N/A SwingUtilities.computeIntersection(tmpX,tmpY,tmpWidth,tmpHeight,paintImmediatelyClip);
0N/A paintImmediatelyClip.x += bx;
0N/A paintImmediatelyClip.y += by;
0N/A offsetX += bx;
0N/A offsetY += by;
0N/A }
0N/A }
0N/A
0N/A // If the clip width or height is negative, don't bother painting
0N/A if(c == null || c.getPeer() == null ||
0N/A paintImmediatelyClip.width <= 0 ||
0N/A paintImmediatelyClip.height <= 0) {
0N/A recycleRectangle(paintImmediatelyClip);
0N/A return;
0N/A }
0N/A
0N/A paintingComponent.setFlag(IS_REPAINTING, true);
0N/A
0N/A paintImmediatelyClip.x -= offsetX;
0N/A paintImmediatelyClip.y -= offsetY;
0N/A
0N/A // Notify the Components that are going to be painted of the
0N/A // child component to paint to.
0N/A if(paintingComponent != this) {
0N/A Component comp;
0N/A int i = pIndex;
0N/A for(; i > 0 ; i--) {
0N/A comp = path.get(i);
0N/A if(comp instanceof JComponent) {
0N/A ((JComponent)comp).setPaintingChild(path.get(i-1));
0N/A }
0N/A }
0N/A }
0N/A try {
3634N/A if ((g = safelyGetGraphics(paintingComponent, c)) != null) {
3634N/A try {
3634N/A if (hasBuffer) {
3634N/A RepaintManager rm = RepaintManager.currentManager(
3634N/A bufferedComponent);
3634N/A rm.beginPaint();
3634N/A try {
3634N/A rm.paint(paintingComponent, bufferedComponent, g,
3634N/A paintImmediatelyClip.x,
3634N/A paintImmediatelyClip.y,
3634N/A paintImmediatelyClip.width,
3634N/A paintImmediatelyClip.height);
3634N/A } finally {
3634N/A rm.endPaint();
3634N/A }
3634N/A } else {
3634N/A g.setClip(paintImmediatelyClip.x, paintImmediatelyClip.y,
3634N/A paintImmediatelyClip.width, paintImmediatelyClip.height);
3634N/A paintingComponent.paint(g);
0N/A }
3634N/A } finally {
3634N/A g.dispose();
0N/A }
0N/A }
0N/A }
0N/A finally {
0N/A // Reset the painting child for the parent components.
0N/A if(paintingComponent != this) {
0N/A Component comp;
0N/A int i = pIndex;
0N/A for(; i > 0 ; i--) {
0N/A comp = path.get(i);
0N/A if(comp instanceof JComponent) {
0N/A ((JComponent)comp).setPaintingChild(null);
0N/A }
0N/A }
0N/A }
0N/A paintingComponent.setFlag(IS_REPAINTING, false);
0N/A }
0N/A recycleRectangle(paintImmediatelyClip);
0N/A }
0N/A
0N/A /**
0N/A * Paints to the specified graphics. This does not set the clip and it
0N/A * does not adjust the Graphics in anyway, callers must do that first.
0N/A * This method is package-private for RepaintManager.PaintManager and
0N/A * its subclasses to call, it is NOT intended for general use outside
0N/A * of that.
0N/A */
0N/A void paintToOffscreen(Graphics g, int x, int y, int w, int h, int maxX,
0N/A int maxY) {
0N/A try {
0N/A setFlag(ANCESTOR_USING_BUFFER, true);
0N/A if ((y + h) < maxY || (x + w) < maxX) {
0N/A setFlag(IS_PAINTING_TILE, true);
0N/A }
0N/A if (getFlag(IS_REPAINTING)) {
0N/A // Called from paintImmediately (RepaintManager) to fill
0N/A // repaint request
0N/A paint(g);
0N/A } else {
0N/A // Called from paint() (AWT) to repair damage
0N/A if(!rectangleIsObscured(x, y, w, h)) {
0N/A paintComponent(g);
0N/A paintBorder(g);
0N/A }
0N/A paintChildren(g);
0N/A }
0N/A } finally {
0N/A setFlag(ANCESTOR_USING_BUFFER, false);
0N/A setFlag(IS_PAINTING_TILE, false);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns whether or not the region of the specified component is
0N/A * obscured by a sibling.
0N/A *
0N/A * @return NOT_OBSCURED if non of the siblings above the Component obscure
0N/A * it, COMPLETELY_OBSCURED if one of the siblings completely
0N/A * obscures the Component or PARTIALLY_OBSCURED if the Comonent is
0N/A * only partially obscured.
0N/A */
0N/A private int getObscuredState(int compIndex, int x, int y, int width,
0N/A int height) {
0N/A int retValue = NOT_OBSCURED;
0N/A Rectangle tmpRect = fetchRectangle();
0N/A
0N/A for (int i = compIndex - 1 ; i >= 0 ; i--) {
0N/A Component sibling = getComponent(i);
0N/A if (!sibling.isVisible()) {
0N/A continue;
0N/A }
0N/A Rectangle siblingRect;
0N/A boolean opaque;
0N/A if (sibling instanceof JComponent) {
625N/A opaque = sibling.isOpaque();
0N/A if (!opaque) {
0N/A if (retValue == PARTIALLY_OBSCURED) {
0N/A continue;
0N/A }
0N/A }
0N/A }
0N/A else {
0N/A opaque = true;
0N/A }
0N/A siblingRect = sibling.getBounds(tmpRect);
0N/A if (opaque && x >= siblingRect.x && (x + width) <=
0N/A (siblingRect.x + siblingRect.width) &&
0N/A y >= siblingRect.y && (y + height) <=
0N/A (siblingRect.y + siblingRect.height)) {
0N/A recycleRectangle(tmpRect);
0N/A return COMPLETELY_OBSCURED;
0N/A }
0N/A else if (retValue == NOT_OBSCURED &&
0N/A !((x + width <= siblingRect.x) ||
0N/A (y + height <= siblingRect.y) ||
0N/A (x >= siblingRect.x + siblingRect.width) ||
0N/A (y >= siblingRect.y + siblingRect.height))) {
0N/A retValue = PARTIALLY_OBSCURED;
0N/A }
0N/A }
0N/A recycleRectangle(tmpRect);
0N/A return retValue;
0N/A }
0N/A
0N/A /**
0N/A * Returns true, which implies that before checking if a child should
0N/A * be painted it is first check that the child is not obscured by another
0N/A * sibling. This is only checked if <code>isOptimizedDrawingEnabled</code>
0N/A * returns false.
0N/A *
0N/A * @return always returns true
0N/A */
0N/A boolean checkIfChildObscuredBySibling() {
0N/A return true;
0N/A }
0N/A
0N/A
0N/A private void setFlag(int aFlag, boolean aValue) {
0N/A if(aValue) {
0N/A flags |= (1 << aFlag);
0N/A } else {
0N/A flags &= ~(1 << aFlag);
0N/A }
0N/A }
0N/A private boolean getFlag(int aFlag) {
0N/A int mask = (1 << aFlag);
0N/A return ((flags & mask) == mask);
0N/A }
0N/A // These functions must be static so that they can be called from
0N/A // subclasses inside the package, but whose inheritance hierarhcy includes
0N/A // classes outside of the package below JComponent (e.g., JTextArea).
0N/A static void setWriteObjCounter(JComponent comp, byte count) {
0N/A comp.flags = (comp.flags & ~(0xFF << WRITE_OBJ_COUNTER_FIRST)) |
0N/A (count << WRITE_OBJ_COUNTER_FIRST);
0N/A }
0N/A static byte getWriteObjCounter(JComponent comp) {
0N/A return (byte)((comp.flags >> WRITE_OBJ_COUNTER_FIRST) & 0xFF);
0N/A }
0N/A
0N/A /** Buffering **/
0N/A
0N/A /**
0N/A * Sets whether this component should use a buffer to paint.
0N/A * If set to true, all the drawing from this component will be done
0N/A * in an offscreen painting buffer. The offscreen painting buffer will
0N/A * the be copied onto the screen.
0N/A * If a <code>Component</code> is buffered and one of its ancestor
0N/A * is also buffered, the ancestor buffer will be used.
0N/A *
0N/A * @param aFlag if true, set this component to be double buffered
0N/A */
0N/A public void setDoubleBuffered(boolean aFlag) {
0N/A setFlag(IS_DOUBLE_BUFFERED,aFlag);
0N/A }
0N/A
0N/A /**
0N/A * Returns whether this component should use a buffer to paint.
0N/A *
0N/A * @return true if this component is double buffered, otherwise false
0N/A */
0N/A public boolean isDoubleBuffered() {
0N/A return getFlag(IS_DOUBLE_BUFFERED);
0N/A }
0N/A
0N/A /**
0N/A * Returns the <code>JRootPane</code> ancestor for this component.
0N/A *
0N/A * @return the <code>JRootPane</code> that contains this component,
0N/A * or <code>null</code> if no <code>JRootPane</code> is found
0N/A */
0N/A public JRootPane getRootPane() {
0N/A return SwingUtilities.getRootPane(this);
0N/A }
0N/A
0N/A
0N/A /** Serialization **/
0N/A
0N/A /**
0N/A * This is called from Component by way of reflection. Do NOT change
0N/A * the name unless you change the code in Component as well.
0N/A */
0N/A void compWriteObjectNotify() {
0N/A byte count = JComponent.getWriteObjCounter(this);
0N/A JComponent.setWriteObjCounter(this, (byte)(count + 1));
0N/A if (count != 0) {
0N/A return;
0N/A }
0N/A
0N/A uninstallUIAndProperties();
0N/A
0N/A /* JTableHeader is in a separate package, which prevents it from
0N/A * being able to override this package-private method the way the
0N/A * other components can. We don't want to make this method protected
0N/A * because it would introduce public-api for a less-than-desirable
0N/A * serialization scheme, so we compromise with this 'instanceof' hack
0N/A * for now.
0N/A */
0N/A if (getToolTipText() != null ||
0N/A this instanceof javax.swing.table.JTableHeader) {
0N/A ToolTipManager.sharedInstance().unregisterComponent(JComponent.this);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * This object is the <code>ObjectInputStream</code> callback
0N/A * that's called after a complete graph of objects (including at least
0N/A * one <code>JComponent</code>) has been read.
0N/A * It sets the UI property of each Swing component
0N/A * that was read to the current default with <code>updateUI</code>.
0N/A * <p>
0N/A * As each component is read in we keep track of the current set of
0N/A * root components here, in the roots vector. Note that there's only one
0N/A * <code>ReadObjectCallback</code> per <code>ObjectInputStream</code>,
0N/A * they're stored in the static <code>readObjectCallbacks</code>
0N/A * hashtable.
0N/A *
0N/A * @see java.io.ObjectInputStream#registerValidation
0N/A * @see SwingUtilities#updateComponentTreeUI
0N/A */
0N/A private class ReadObjectCallback implements ObjectInputValidation
0N/A {
625N/A private final Vector<JComponent> roots = new Vector<JComponent>(1);
0N/A private final ObjectInputStream inputStream;
0N/A
0N/A ReadObjectCallback(ObjectInputStream s) throws Exception {
0N/A inputStream = s;
0N/A s.registerValidation(this, 0);
0N/A }
0N/A
0N/A /**
0N/A * This is the method that's called after the entire graph
0N/A * of objects has been read in. It initializes
0N/A * the UI property of all of the copmonents with
0N/A * <code>SwingUtilities.updateComponentTreeUI</code>.
0N/A */
0N/A public void validateObject() throws InvalidObjectException {
0N/A try {
625N/A for (JComponent root : roots) {
0N/A SwingUtilities.updateComponentTreeUI(root);
0N/A }
0N/A }
0N/A finally {
0N/A readObjectCallbacks.remove(inputStream);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * If <code>c</code> isn't a descendant of a component we've already
0N/A * seen, then add it to the roots <code>Vector</code>.
0N/A *
0N/A * @param c the <code>JComponent</code> to add
0N/A */
0N/A private void registerComponent(JComponent c)
0N/A {
0N/A /* If the Component c is a descendant of one of the
0N/A * existing roots (or it IS an existing root), we're done.
0N/A */
625N/A for (JComponent root : roots) {
0N/A for(Component p = c; p != null; p = p.getParent()) {
0N/A if (p == root) {
0N/A return;
0N/A }
0N/A }
0N/A }
0N/A
0N/A /* Otherwise: if Component c is an ancestor of any of the
0N/A * existing roots then remove them and add c (the "new root")
0N/A * to the roots vector.
0N/A */
0N/A for(int i = 0; i < roots.size(); i++) {
625N/A JComponent root = roots.elementAt(i);
0N/A for(Component p = root.getParent(); p != null; p = p.getParent()) {
0N/A if (p == c) {
0N/A roots.removeElementAt(i--); // !!
0N/A break;
0N/A }
0N/A }
0N/A }
0N/A
0N/A roots.addElement(c);
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * We use the <code>ObjectInputStream</code> "registerValidation"
0N/A * callback to update the UI for the entire tree of components
0N/A * after they've all been read in.
0N/A *
0N/A * @param s the <code>ObjectInputStream</code> from which to read
0N/A */
0N/A private void readObject(ObjectInputStream s)
0N/A throws IOException, ClassNotFoundException
0N/A {
0N/A s.defaultReadObject();
0N/A
0N/A /* If there's no ReadObjectCallback for this stream yet, that is, if
0N/A * this is the first call to JComponent.readObject() for this
0N/A * graph of objects, then create a callback and stash it
0N/A * in the readObjectCallbacks table. Note that the ReadObjectCallback
0N/A * constructor takes care of calling s.registerValidation().
0N/A */
625N/A ReadObjectCallback cb = readObjectCallbacks.get(s);
0N/A if (cb == null) {
0N/A try {
0N/A readObjectCallbacks.put(s, cb = new ReadObjectCallback(s));
0N/A }
0N/A catch (Exception e) {
0N/A throw new IOException(e.toString());
0N/A }
0N/A }
0N/A cb.registerComponent(this);
0N/A
0N/A // Read back the client properties.
0N/A int cpCount = s.readInt();
0N/A if (cpCount > 0) {
0N/A clientProperties = new ArrayTable();
0N/A for (int counter = 0; counter < cpCount; counter++) {
0N/A clientProperties.put(s.readObject(),
0N/A s.readObject());
0N/A }
0N/A }
0N/A if (getToolTipText() != null) {
0N/A ToolTipManager.sharedInstance().registerComponent(this);
0N/A }
0N/A setWriteObjCounter(this, (byte)0);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Before writing a <code>JComponent</code> to an
0N/A * <code>ObjectOutputStream</code> we temporarily uninstall its UI.
0N/A * This is tricky to do because we want to uninstall
0N/A * the UI before any of the <code>JComponent</code>'s children
0N/A * (or its <code>LayoutManager</code> etc.) are written,
0N/A * and we don't want to restore the UI until the most derived
0N/A * <code>JComponent</code> subclass has been been stored.
0N/A *
0N/A * @param s the <code>ObjectOutputStream</code> in which to write
0N/A */
0N/A private void writeObject(ObjectOutputStream s) throws IOException {
0N/A s.defaultWriteObject();
0N/A if (getUIClassID().equals(uiClassID)) {
0N/A byte count = JComponent.getWriteObjCounter(this);
0N/A JComponent.setWriteObjCounter(this, --count);
0N/A if (count == 0 && ui != null) {
0N/A ui.installUI(this);
0N/A }
0N/A }
0N/A ArrayTable.writeArrayTable(s, clientProperties);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns a string representation of this <code>JComponent</code>.
0N/A * This method
0N/A * is intended to be used only for debugging purposes, and the
0N/A * content and format of the returned string may vary between
0N/A * implementations. The returned string may be empty but may not
0N/A * be <code>null</code>.
0N/A *
0N/A * @return a string representation of this <code>JComponent</code>
0N/A */
0N/A protected String paramString() {
0N/A String preferredSizeString = (isPreferredSizeSet() ?
0N/A getPreferredSize().toString() : "");
0N/A String minimumSizeString = (isMinimumSizeSet() ?
0N/A getMinimumSize().toString() : "");
0N/A String maximumSizeString = (isMaximumSizeSet() ?
0N/A getMaximumSize().toString() : "");
0N/A String borderString = (border == null ? ""
0N/A : (border == this ? "this" : border.toString()));
0N/A
0N/A return super.paramString() +
0N/A ",alignmentX=" + alignmentX +
0N/A ",alignmentY=" + alignmentY +
0N/A ",border=" + borderString +
0N/A ",flags=" + flags + // should beef this up a bit
0N/A ",maximumSize=" + maximumSizeString +
0N/A ",minimumSize=" + minimumSizeString +
0N/A ",preferredSize=" + preferredSizeString;
0N/A }
0N/A
5243N/A /**
5243N/A * {@inheritDoc}
5243N/A */
5243N/A @Override
5244N/A @Deprecated
5243N/A public void hide() {
5243N/A boolean showing = isShowing();
5243N/A super.hide();
5243N/A if (showing) {
5243N/A Container parent = getParent();
5243N/A if (parent != null) {
5243N/A Rectangle r = getBounds();
5243N/A parent.repaint(r.x, r.y, r.width, r.height);
5243N/A }
5243N/A revalidate();
5243N/A }
5243N/A }
5243N/A
0N/A}