Component.java revision 218
0N/A/*
0N/A * Copyright 1995-2007 Sun Microsystems, Inc. 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
0N/A * published by the Free Software Foundation. Sun designates this
0N/A * particular file as subject to the "Classpath" exception as provided
0N/A * by Sun 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 *
0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0N/A * CA 95054 USA or visit www.sun.com if you need additional information or
0N/A * have any questions.
0N/A */
0N/Apackage java.awt;
0N/A
0N/Aimport java.io.PrintStream;
0N/Aimport java.io.PrintWriter;
0N/Aimport java.util.Vector;
0N/Aimport java.util.Locale;
0N/Aimport java.util.EventListener;
0N/Aimport java.util.Iterator;
0N/Aimport java.util.HashSet;
0N/Aimport java.util.Map;
0N/Aimport java.util.Set;
0N/Aimport java.util.Collections;
0N/Aimport java.awt.peer.ComponentPeer;
0N/Aimport java.awt.peer.ContainerPeer;
0N/Aimport java.awt.peer.LightweightPeer;
0N/Aimport java.awt.image.BufferStrategy;
0N/Aimport java.awt.image.ImageObserver;
0N/Aimport java.awt.image.ImageProducer;
0N/Aimport java.awt.image.ColorModel;
0N/Aimport java.awt.image.VolatileImage;
0N/Aimport java.awt.event.*;
0N/Aimport java.io.Serializable;
0N/Aimport java.io.ObjectOutputStream;
0N/Aimport java.io.ObjectInputStream;
0N/Aimport java.io.IOException;
0N/Aimport java.beans.PropertyChangeListener;
0N/Aimport java.beans.PropertyChangeSupport;
0N/Aimport java.awt.event.InputMethodListener;
0N/Aimport java.awt.event.InputMethodEvent;
0N/Aimport java.awt.im.InputContext;
0N/Aimport java.awt.im.InputMethodRequests;
0N/Aimport java.awt.dnd.DropTarget;
0N/Aimport java.lang.reflect.InvocationTargetException;
0N/Aimport java.lang.reflect.Method;
0N/Aimport java.security.AccessController;
0N/Aimport java.security.PrivilegedAction;
0N/Aimport javax.accessibility.*;
0N/Aimport java.util.logging.*;
0N/Aimport java.applet.Applet;
0N/A
0N/Aimport sun.security.action.GetPropertyAction;
0N/Aimport sun.awt.AppContext;
0N/Aimport sun.awt.ConstrainableGraphics;
0N/Aimport sun.awt.SubRegionShowable;
0N/Aimport sun.awt.WindowClosingListener;
0N/Aimport sun.awt.CausedFocusEvent;
0N/Aimport sun.awt.EmbeddedFrame;
0N/Aimport sun.awt.dnd.SunDropTargetEvent;
0N/Aimport sun.awt.im.CompositionArea;
0N/Aimport sun.java2d.SunGraphics2D;
0N/Aimport sun.java2d.pipe.Region;
0N/Aimport sun.awt.RequestFocusController;
0N/A
0N/A/**
0N/A * A <em>component</em> is an object having a graphical representation
0N/A * that can be displayed on the screen and that can interact with the
0N/A * user. Examples of components are the buttons, checkboxes, and scrollbars
0N/A * of a typical graphical user interface. <p>
0N/A * The <code>Component</code> class is the abstract superclass of
0N/A * the nonmenu-related Abstract Window Toolkit components. Class
0N/A * <code>Component</code> can also be extended directly to create a
0N/A * lightweight component. A lightweight component is a component that is
0N/A * not associated with a native opaque window.
0N/A * <p>
0N/A * <h3>Serialization</h3>
0N/A * It is important to note that only AWT listeners which conform
0N/A * to the <code>Serializable</code> protocol will be saved when
0N/A * the object is stored. If an AWT object has listeners that
0N/A * aren't marked serializable, they will be dropped at
0N/A * <code>writeObject</code> time. Developers will need, as always,
0N/A * to consider the implications of making an object serializable.
0N/A * One situation to watch out for is this:
0N/A * <pre>
0N/A * import java.awt.*;
0N/A * import java.awt.event.*;
0N/A * import java.io.Serializable;
0N/A *
0N/A * class MyApp implements ActionListener, Serializable
0N/A * {
0N/A * BigObjectThatShouldNotBeSerializedWithAButton bigOne;
0N/A * Button aButton = new Button();
0N/A *
0N/A * MyApp()
0N/A * {
0N/A * // Oops, now aButton has a listener with a reference
0N/A * // to bigOne!
0N/A * aButton.addActionListener(this);
0N/A * }
0N/A *
0N/A * public void actionPerformed(ActionEvent e)
0N/A * {
0N/A * System.out.println("Hello There");
0N/A * }
0N/A * }
0N/A * </pre>
0N/A * In this example, serializing <code>aButton</code> by itself
0N/A * will cause <code>MyApp</code> and everything it refers to
0N/A * to be serialized as well. The problem is that the listener
0N/A * is serializable by coincidence, not by design. To separate
0N/A * the decisions about <code>MyApp</code> and the
0N/A * <code>ActionListener</code> being serializable one can use a
0N/A * nested class, as in the following example:
0N/A * <pre>
0N/A * import java.awt.*;
0N/A * import java.awt.event.*;
0N/A * import java.io.Serializable;
0N/A *
0N/A * class MyApp java.io.Serializable
0N/A * {
0N/A * BigObjectThatShouldNotBeSerializedWithAButton bigOne;
0N/A * Button aButton = new Button();
0N/A *
0N/A * static class MyActionListener implements ActionListener
0N/A * {
0N/A * public void actionPerformed(ActionEvent e)
0N/A * {
0N/A * System.out.println("Hello There");
0N/A * }
0N/A * }
0N/A *
0N/A * MyApp()
0N/A * {
0N/A * aButton.addActionListener(new MyActionListener());
0N/A * }
0N/A * }
0N/A * </pre>
0N/A * <p>
0N/A * <b>Note</b>: For more information on the paint mechanisms utilitized
0N/A * by AWT and Swing, including information on how to write the most
0N/A * efficient painting code, see
0N/A * <a href="http://java.sun.com/products/jfc/tsc/articles/painting/index.html">Painting in AWT and Swing</a>.
0N/A * <p>
0N/A * For details on the focus subsystem, 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>, and the
0N/A * <a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a>
0N/A * for more information.
0N/A *
0N/A * @author Arthur van Hoff
0N/A * @author Sami Shaio
0N/A */
0N/Apublic abstract class Component implements ImageObserver, MenuContainer,
0N/A Serializable
0N/A{
0N/A
0N/A private static final Logger log = Logger.getLogger("java.awt.Component");
0N/A private static final Logger eventLog = Logger.getLogger("java.awt.event.Component");
0N/A private static final Logger focusLog = Logger.getLogger("java.awt.focus.Component");
0N/A private static final Logger mixingLog = Logger.getLogger("java.awt.mixing.Component");
0N/A
0N/A /**
0N/A * The peer of the component. The peer implements the component's
0N/A * behavior. The peer is set when the <code>Component</code> is
0N/A * added to a container that also is a peer.
0N/A * @see #addNotify
0N/A * @see #removeNotify
0N/A */
0N/A transient ComponentPeer peer;
0N/A
0N/A /**
0N/A * The parent of the object. It may be <code>null</code>
0N/A * for top-level components.
0N/A * @see #getParent
0N/A */
0N/A transient Container parent;
0N/A
0N/A /**
0N/A * The <code>AppContext</code> of the component. Applets/Plugin may
0N/A * change the AppContext.
0N/A */
0N/A transient AppContext appContext;
0N/A
0N/A /**
0N/A * The x position of the component in the parent's coordinate system.
0N/A *
0N/A * @serial
0N/A * @see #getLocation
0N/A */
0N/A int x;
0N/A
0N/A /**
0N/A * The y position of the component in the parent's coordinate system.
0N/A *
0N/A * @serial
0N/A * @see #getLocation
0N/A */
0N/A int y;
0N/A
0N/A /**
0N/A * The width of the component.
0N/A *
0N/A * @serial
0N/A * @see #getSize
0N/A */
0N/A int width;
0N/A
0N/A /**
0N/A * The height of the component.
0N/A *
0N/A * @serial
0N/A * @see #getSize
0N/A */
0N/A int height;
0N/A
0N/A /**
0N/A * The foreground color for this component.
0N/A * <code>foreground</code> can be <code>null</code>.
0N/A *
0N/A * @serial
0N/A * @see #getForeground
0N/A * @see #setForeground
0N/A */
0N/A Color foreground;
0N/A
0N/A /**
0N/A * The background color for this component.
0N/A * <code>background</code> can be <code>null</code>.
0N/A *
0N/A * @serial
0N/A * @see #getBackground
0N/A * @see #setBackground
0N/A */
0N/A Color background;
0N/A
0N/A /**
0N/A * The font used by this component.
0N/A * The <code>font</code> can be <code>null</code>.
0N/A *
0N/A * @serial
0N/A * @see #getFont
0N/A * @see #setFont
0N/A */
0N/A Font font;
0N/A
0N/A /**
0N/A * The font which the peer is currently using.
0N/A * (<code>null</code> if no peer exists.)
0N/A */
0N/A Font peerFont;
0N/A
0N/A /**
0N/A * The cursor displayed when pointer is over this component.
0N/A * This value can be <code>null</code>.
0N/A *
0N/A * @serial
0N/A * @see #getCursor
0N/A * @see #setCursor
0N/A */
0N/A Cursor cursor;
0N/A
0N/A /**
0N/A * The locale for the component.
0N/A *
0N/A * @serial
0N/A * @see #getLocale
0N/A * @see #setLocale
0N/A */
0N/A Locale locale;
0N/A
0N/A /**
0N/A * A reference to a <code>GraphicsConfiguration</code> object
0N/A * used to describe the characteristics of a graphics
0N/A * destination.
0N/A * This value can be <code>null</code>.
0N/A *
0N/A * @since 1.3
0N/A * @serial
0N/A * @see GraphicsConfiguration
0N/A * @see #getGraphicsConfiguration
0N/A */
0N/A transient GraphicsConfiguration graphicsConfig = null;
0N/A
0N/A /**
0N/A * A reference to a <code>BufferStrategy</code> object
0N/A * used to manipulate the buffers on this component.
0N/A *
0N/A * @since 1.4
0N/A * @see java.awt.image.BufferStrategy
0N/A * @see #getBufferStrategy()
0N/A */
0N/A transient BufferStrategy bufferStrategy = null;
0N/A
0N/A /**
0N/A * True when the object should ignore all repaint events.
0N/A *
0N/A * @since 1.4
0N/A * @serial
0N/A * @see #setIgnoreRepaint
0N/A * @see #getIgnoreRepaint
0N/A */
0N/A boolean ignoreRepaint = false;
0N/A
0N/A /**
0N/A * True when the object is visible. An object that is not
0N/A * visible is not drawn on the screen.
0N/A *
0N/A * @serial
0N/A * @see #isVisible
0N/A * @see #setVisible
0N/A */
0N/A boolean visible = true;
0N/A
0N/A /**
0N/A * True when the object is enabled. An object that is not
0N/A * enabled does not interact with the user.
0N/A *
0N/A * @serial
0N/A * @see #isEnabled
0N/A * @see #setEnabled
0N/A */
0N/A boolean enabled = true;
0N/A
0N/A /**
0N/A * True when the object is valid. An invalid object needs to
0N/A * be layed out. This flag is set to false when the object
0N/A * size is changed.
0N/A *
0N/A * @serial
0N/A * @see #isValid
0N/A * @see #validate
0N/A * @see #invalidate
0N/A */
0N/A volatile boolean valid = false;
0N/A
0N/A /**
0N/A * The <code>DropTarget</code> associated with this component.
0N/A *
0N/A * @since 1.2
0N/A * @serial
0N/A * @see #setDropTarget
0N/A * @see #getDropTarget
0N/A */
0N/A DropTarget dropTarget;
0N/A
0N/A /**
0N/A * @serial
0N/A * @see #add
0N/A */
0N/A Vector popups;
0N/A
0N/A /**
0N/A * A component's name.
0N/A * This field can be <code>null</code>.
0N/A *
0N/A * @serial
0N/A * @see #getName
0N/A * @see #setName(String)
0N/A */
0N/A private String name;
0N/A
0N/A /**
0N/A * A bool to determine whether the name has
0N/A * been set explicitly. <code>nameExplicitlySet</code> will
0N/A * be false if the name has not been set and
0N/A * true if it has.
0N/A *
0N/A * @serial
0N/A * @see #getName
0N/A * @see #setName(String)
0N/A */
0N/A private boolean nameExplicitlySet = false;
0N/A
0N/A /**
0N/A * Indicates whether this Component can be focused.
0N/A *
0N/A * @serial
0N/A * @see #setFocusable
0N/A * @see #isFocusable
0N/A * @since 1.4
0N/A */
0N/A private boolean focusable = true;
0N/A
0N/A private static final int FOCUS_TRAVERSABLE_UNKNOWN = 0;
0N/A private static final int FOCUS_TRAVERSABLE_DEFAULT = 1;
0N/A private static final int FOCUS_TRAVERSABLE_SET = 2;
0N/A
0N/A /**
0N/A * Tracks whether this Component is relying on default focus travesability.
0N/A *
0N/A * @serial
0N/A * @since 1.4
0N/A */
0N/A private int isFocusTraversableOverridden = FOCUS_TRAVERSABLE_UNKNOWN;
0N/A
0N/A /**
0N/A * The focus traversal keys. These keys will generate focus traversal
0N/A * behavior for Components for which focus traversal keys are enabled. If a
0N/A * value of null is specified for a traversal key, this Component inherits
0N/A * that traversal key from its parent. If all ancestors of this Component
0N/A * have null specified for that traversal key, then the current
0N/A * KeyboardFocusManager's default traversal key is used.
0N/A *
0N/A * @serial
0N/A * @see #setFocusTraversalKeys
0N/A * @see #getFocusTraversalKeys
0N/A * @since 1.4
0N/A */
0N/A Set[] focusTraversalKeys;
0N/A
0N/A private static final String[] focusTraversalKeyPropertyNames = {
0N/A "forwardFocusTraversalKeys",
0N/A "backwardFocusTraversalKeys",
0N/A "upCycleFocusTraversalKeys",
0N/A "downCycleFocusTraversalKeys"
0N/A };
0N/A
0N/A /**
0N/A * Indicates whether focus traversal keys are enabled for this Component.
0N/A * Components for which focus traversal keys are disabled receive key
0N/A * events for focus traversal keys. Components for which focus traversal
0N/A * keys are enabled do not see these events; instead, the events are
0N/A * automatically converted to traversal operations.
0N/A *
0N/A * @serial
0N/A * @see #setFocusTraversalKeysEnabled
0N/A * @see #getFocusTraversalKeysEnabled
0N/A * @since 1.4
0N/A */
0N/A private boolean focusTraversalKeysEnabled = true;
0N/A
0N/A /**
0N/A * The locking object for AWT component-tree and layout operations.
0N/A *
0N/A * @see #getTreeLock
0N/A */
0N/A static final Object LOCK = new AWTTreeLock();
0N/A static class AWTTreeLock {}
0N/A
0N/A /**
0N/A * Minimum size.
0N/A * (This field perhaps should have been transient).
0N/A *
0N/A * @serial
0N/A */
0N/A Dimension minSize;
0N/A
0N/A /**
0N/A * Whether or not setMinimumSize has been invoked with a non-null value.
0N/A */
0N/A boolean minSizeSet;
0N/A
0N/A /**
0N/A * Preferred size.
0N/A * (This field perhaps should have been transient).
0N/A *
0N/A * @serial
0N/A */
0N/A Dimension prefSize;
0N/A
0N/A /**
0N/A * Whether or not setPreferredSize has been invoked with a non-null value.
0N/A */
0N/A boolean prefSizeSet;
0N/A
0N/A /**
0N/A * Maximum size
0N/A *
0N/A * @serial
0N/A */
0N/A Dimension maxSize;
0N/A
0N/A /**
0N/A * Whether or not setMaximumSize has been invoked with a non-null value.
0N/A */
0N/A boolean maxSizeSet;
0N/A
0N/A /**
0N/A * The orientation for this component.
0N/A * @see #getComponentOrientation
0N/A * @see #setComponentOrientation
0N/A */
0N/A transient ComponentOrientation componentOrientation
0N/A = ComponentOrientation.UNKNOWN;
0N/A
0N/A /**
0N/A * <code>newEventsOnly</code> will be true if the event is
0N/A * one of the event types enabled for the component.
0N/A * It will then allow for normal processing to
0N/A * continue. If it is false the event is passed
0N/A * to the component's parent and up the ancestor
0N/A * tree until the event has been consumed.
0N/A *
0N/A * @serial
0N/A * @see #dispatchEvent
0N/A */
0N/A boolean newEventsOnly = false;
0N/A transient ComponentListener componentListener;
0N/A transient FocusListener focusListener;
0N/A transient HierarchyListener hierarchyListener;
0N/A transient HierarchyBoundsListener hierarchyBoundsListener;
0N/A transient KeyListener keyListener;
0N/A transient MouseListener mouseListener;
0N/A transient MouseMotionListener mouseMotionListener;
0N/A transient MouseWheelListener mouseWheelListener;
0N/A transient InputMethodListener inputMethodListener;
0N/A
0N/A transient RuntimeException windowClosingException = null;
0N/A
0N/A /** Internal, constants for serialization */
0N/A final static String actionListenerK = "actionL";
0N/A final static String adjustmentListenerK = "adjustmentL";
0N/A final static String componentListenerK = "componentL";
0N/A final static String containerListenerK = "containerL";
0N/A final static String focusListenerK = "focusL";
0N/A final static String itemListenerK = "itemL";
0N/A final static String keyListenerK = "keyL";
0N/A final static String mouseListenerK = "mouseL";
0N/A final static String mouseMotionListenerK = "mouseMotionL";
0N/A final static String mouseWheelListenerK = "mouseWheelL";
0N/A final static String textListenerK = "textL";
0N/A final static String ownedWindowK = "ownedL";
0N/A final static String windowListenerK = "windowL";
0N/A final static String inputMethodListenerK = "inputMethodL";
0N/A final static String hierarchyListenerK = "hierarchyL";
0N/A final static String hierarchyBoundsListenerK = "hierarchyBoundsL";
0N/A final static String windowStateListenerK = "windowStateL";
0N/A final static String windowFocusListenerK = "windowFocusL";
0N/A
0N/A /**
0N/A * The <code>eventMask</code> is ONLY set by subclasses via
0N/A * <code>enableEvents</code>.
0N/A * The mask should NOT be set when listeners are registered
0N/A * so that we can distinguish the difference between when
0N/A * listeners request events and subclasses request them.
0N/A * One bit is used to indicate whether input methods are
0N/A * enabled; this bit is set by <code>enableInputMethods</code> and is
0N/A * on by default.
0N/A *
0N/A * @serial
0N/A * @see #enableInputMethods
0N/A * @see AWTEvent
0N/A */
0N/A long eventMask = AWTEvent.INPUT_METHODS_ENABLED_MASK;
0N/A
0N/A /**
0N/A * Static properties for incremental drawing.
0N/A * @see #imageUpdate
0N/A */
0N/A static boolean isInc;
0N/A static int incRate;
0N/A static {
0N/A /* ensure that the necessary native libraries are loaded */
0N/A Toolkit.loadLibraries();
0N/A /* initialize JNI field and method ids */
0N/A if (!GraphicsEnvironment.isHeadless()) {
0N/A initIDs();
0N/A }
0N/A
0N/A String s = (String) java.security.AccessController.doPrivileged(
0N/A new GetPropertyAction("awt.image.incrementaldraw"));
0N/A isInc = (s == null || s.equals("true"));
0N/A
0N/A s = (String) java.security.AccessController.doPrivileged(
0N/A new GetPropertyAction("awt.image.redrawrate"));
0N/A incRate = (s != null) ? Integer.parseInt(s) : 100;
0N/A }
0N/A
0N/A /**
0N/A * Ease-of-use constant for <code>getAlignmentY()</code>.
0N/A * Specifies an alignment to the top of the component.
0N/A * @see #getAlignmentY
0N/A */
0N/A public static final float TOP_ALIGNMENT = 0.0f;
0N/A
0N/A /**
0N/A * Ease-of-use constant for <code>getAlignmentY</code> and
0N/A * <code>getAlignmentX</code>. Specifies an alignment to
0N/A * the center of the component
0N/A * @see #getAlignmentX
0N/A * @see #getAlignmentY
0N/A */
0N/A public static final float CENTER_ALIGNMENT = 0.5f;
0N/A
0N/A /**
0N/A * Ease-of-use constant for <code>getAlignmentY</code>.
0N/A * Specifies an alignment to the bottom of the component.
0N/A * @see #getAlignmentY
0N/A */
0N/A public static final float BOTTOM_ALIGNMENT = 1.0f;
0N/A
0N/A /**
0N/A * Ease-of-use constant for <code>getAlignmentX</code>.
0N/A * Specifies an alignment to the left side of the component.
0N/A * @see #getAlignmentX
0N/A */
0N/A public static final float LEFT_ALIGNMENT = 0.0f;
0N/A
0N/A /**
0N/A * Ease-of-use constant for <code>getAlignmentX</code>.
0N/A * Specifies an alignment to the right side of the component.
0N/A * @see #getAlignmentX
0N/A */
0N/A public static final float RIGHT_ALIGNMENT = 1.0f;
0N/A
0N/A /*
0N/A * JDK 1.1 serialVersionUID
0N/A */
0N/A private static final long serialVersionUID = -7644114512714619750L;
0N/A
0N/A /**
0N/A * If any <code>PropertyChangeListeners</code> have been registered,
0N/A * the <code>changeSupport</code> field describes them.
0N/A *
0N/A * @serial
0N/A * @since 1.2
0N/A * @see #addPropertyChangeListener
0N/A * @see #removePropertyChangeListener
0N/A * @see #firePropertyChange
0N/A */
0N/A private PropertyChangeSupport changeSupport;
0N/A
209N/A // Note: this field is considered final, though readObject() prohibits
209N/A // initializing final fields.
209N/A private transient Object changeSupportLock = new Object();
100N/A private Object getChangeSupportLock() {
100N/A return changeSupportLock;
100N/A }
100N/A
0N/A boolean isPacked = false;
0N/A
0N/A /**
0N/A * Pseudoparameter for direct Geometry API (setLocation, setBounds setSize
0N/A * to signal setBounds what's changing. Should be used under TreeLock.
0N/A * This is only needed due to the inability to change the cross-calling
0N/A * order of public and deprecated methods.
0N/A */
0N/A private int boundsOp = ComponentPeer.DEFAULT_OPERATION;
0N/A
0N/A /**
0N/A * Enumeration of the common ways the baseline of a component can
0N/A * change as the size changes. The baseline resize behavior is
0N/A * primarily for layout managers that need to know how the
0N/A * position of the baseline changes as the component size changes.
0N/A * In general the baseline resize behavior will be valid for sizes
0N/A * greater than or equal to the minimum size (the actual minimum
0N/A * size; not a developer specified minimum size). For sizes
0N/A * smaller than the minimum size the baseline may change in a way
0N/A * other than the baseline resize behavior indicates. Similarly,
0N/A * as the size approaches <code>Integer.MAX_VALUE</code> and/or
0N/A * <code>Short.MAX_VALUE</code> the baseline may change in a way
0N/A * other than the baseline resize behavior indicates.
0N/A *
0N/A * @see #getBaselineResizeBehavior
0N/A * @see #getBaseline(int,int)
0N/A * @since 1.6
0N/A */
0N/A public enum BaselineResizeBehavior {
0N/A /**
0N/A * Indicates the baseline remains fixed relative to the
0N/A * y-origin. That is, <code>getBaseline</code> returns
0N/A * the same value regardless of the height or width. For example, a
0N/A * <code>JLabel</code> containing non-empty text with a
0N/A * vertical alignment of <code>TOP</code> should have a
0N/A * baseline type of <code>CONSTANT_ASCENT</code>.
0N/A */
0N/A CONSTANT_ASCENT,
0N/A
0N/A /**
0N/A * Indicates the baseline remains fixed relative to the height
0N/A * and does not change as the width is varied. That is, for
0N/A * any height H the difference between H and
0N/A * <code>getBaseline(w, H)</code> is the same. For example, a
0N/A * <code>JLabel</code> containing non-empty text with a
0N/A * vertical alignment of <code>BOTTOM</code> should have a
0N/A * baseline type of <code>CONSTANT_DESCENT</code>.
0N/A */
0N/A CONSTANT_DESCENT,
0N/A
0N/A /**
0N/A * Indicates the baseline remains a fixed distance from
0N/A * the center of the component. That is, for any height H the
0N/A * difference between <code>getBaseline(w, H)</code> and
0N/A * <code>H / 2</code> is the same (plus or minus one depending upon
0N/A * rounding error).
0N/A * <p>
0N/A * Because of possible rounding errors it is recommended
0N/A * you ask for the baseline with two consecutive heights and use
0N/A * the return value to determine if you need to pad calculations
0N/A * by 1. The following shows how to calculate the baseline for
0N/A * any height:
0N/A * <pre>
0N/A * Dimension preferredSize = component.getPreferredSize();
0N/A * int baseline = getBaseline(preferredSize.width,
0N/A * preferredSize.height);
0N/A * int nextBaseline = getBaseline(preferredSize.width,
0N/A * preferredSize.height + 1);
0N/A * // Amount to add to height when calculating where baseline
0N/A * // lands for a particular height:
0N/A * int padding = 0;
0N/A * // Where the baseline is relative to the mid point
0N/A * int baselineOffset = baseline - height / 2;
0N/A * if (preferredSize.height % 2 == 0 &amp;&amp;
0N/A * baseline != nextBaseline) {
0N/A * padding = 1;
0N/A * }
0N/A * else if (preferredSize.height % 2 == 1 &amp;&amp;
0N/A * baseline == nextBaseline) {
0N/A * baselineOffset--;
0N/A * padding = 1;
0N/A * }
0N/A * // The following calculates where the baseline lands for
0N/A * // the height z:
0N/A * int calculatedBaseline = (z + padding) / 2 + baselineOffset;
0N/A * </pre>
0N/A */
0N/A CENTER_OFFSET,
0N/A
0N/A /**
0N/A * Indicates the baseline resize behavior can not be expressed using
0N/A * any of the other constants. This may also indicate the baseline
0N/A * varies with the width of the component. This is also returned
0N/A * by components that do not have a baseline.
0N/A */
0N/A OTHER
0N/A }
0N/A
0N/A /*
0N/A * The shape set with the applyCompoundShape() method. It uncludes the result
0N/A * of the HW/LW mixing related shape computation. It may also include
0N/A * the user-specified shape of the component.
0N/A */
0N/A private transient Region compoundShape = null;
0N/A
0N/A /*
0N/A * Indicates whether addNotify() is complete
0N/A * (i.e. the peer is created).
0N/A */
0N/A private transient boolean isAddNotifyComplete = false;
0N/A
0N/A private static final PropertyChangeListener opaquePropertyChangeListener =
0N/A new PropertyChangeListener() {
0N/A public void propertyChange(java.beans.PropertyChangeEvent evt) {
0N/A ((Component)evt.getSource()).mixOnOpaqueChanging();
0N/A }
0N/A };
0N/A
0N/A /**
0N/A * Should only be used in subclass getBounds to check that part of bounds
0N/A * is actualy changing
0N/A */
0N/A int getBoundsOp() {
0N/A assert Thread.holdsLock(getTreeLock());
0N/A return boundsOp;
0N/A }
0N/A
0N/A void setBoundsOp(int op) {
0N/A assert Thread.holdsLock(getTreeLock());
0N/A if (op == ComponentPeer.RESET_OPERATION) {
0N/A boundsOp = ComponentPeer.DEFAULT_OPERATION;
0N/A } else
0N/A if (boundsOp == ComponentPeer.DEFAULT_OPERATION) {
0N/A boundsOp = op;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Constructs a new component. Class <code>Component</code> can be
0N/A * extended directly to create a lightweight component that does not
0N/A * utilize an opaque native window. A lightweight component must be
0N/A * hosted by a native container somewhere higher up in the component
0N/A * tree (for example, by a <code>Frame</code> object).
0N/A */
0N/A protected Component() {
0N/A appContext = AppContext.getAppContext();
0N/A }
0N/A
0N/A void initializeFocusTraversalKeys() {
0N/A focusTraversalKeys = new Set[3];
0N/A }
0N/A
0N/A /**
0N/A * Constructs a name for this component. Called by <code>getName</code>
0N/A * when the name is <code>null</code>.
0N/A */
0N/A String constructComponentName() {
0N/A return null; // For strict compliance with prior platform versions, a Component
0N/A // that doesn't set its name should return null from
0N/A // getName()
0N/A }
0N/A
0N/A /**
0N/A * Gets the name of the component.
0N/A * @return this component's name
0N/A * @see #setName
0N/A * @since JDK1.1
0N/A */
0N/A public String getName() {
0N/A if (name == null && !nameExplicitlySet) {
0N/A synchronized(this) {
0N/A if (name == null && !nameExplicitlySet)
0N/A name = constructComponentName();
0N/A }
0N/A }
0N/A return name;
0N/A }
0N/A
0N/A /**
0N/A * Sets the name of the component to the specified string.
0N/A * @param name the string that is to be this
0N/A * component's name
0N/A * @see #getName
0N/A * @since JDK1.1
0N/A */
0N/A public void setName(String name) {
0N/A String oldName;
0N/A synchronized(this) {
0N/A oldName = this.name;
0N/A this.name = name;
0N/A nameExplicitlySet = true;
0N/A }
0N/A firePropertyChange("name", oldName, name);
0N/A }
0N/A
0N/A /**
0N/A * Gets the parent of this component.
0N/A * @return the parent container of this component
0N/A * @since JDK1.0
0N/A */
0N/A public Container getParent() {
0N/A return getParent_NoClientCode();
0N/A }
0N/A
0N/A // NOTE: This method may be called by privileged threads.
0N/A // This functionality is implemented in a package-private method
0N/A // to insure that it cannot be overridden by client subclasses.
0N/A // DO NOT INVOKE CLIENT CODE ON THIS THREAD!
0N/A final Container getParent_NoClientCode() {
0N/A return parent;
0N/A }
0N/A
0N/A // This method is overriden in the Window class to return null,
0N/A // because the parent field of the Window object contains
0N/A // the owner of the window, not its parent.
0N/A Container getContainer() {
0N/A return getParent();
0N/A }
0N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1,
0N/A * programs should not directly manipulate peers;
0N/A * replaced by <code>boolean isDisplayable()</code>.
0N/A */
0N/A @Deprecated
0N/A public ComponentPeer getPeer() {
0N/A return peer;
0N/A }
0N/A
0N/A /**
0N/A * Associate a <code>DropTarget</code> with this component.
0N/A * The <code>Component</code> will receive drops only if it
0N/A * is enabled.
0N/A *
0N/A * @see #isEnabled
0N/A * @param dt The DropTarget
0N/A */
0N/A
0N/A public synchronized void setDropTarget(DropTarget dt) {
0N/A if (dt == dropTarget || (dropTarget != null && dropTarget.equals(dt)))
0N/A return;
0N/A
0N/A DropTarget old;
0N/A
0N/A if ((old = dropTarget) != null) {
0N/A if (peer != null) dropTarget.removeNotify(peer);
0N/A
0N/A DropTarget t = dropTarget;
0N/A
0N/A dropTarget = null;
0N/A
0N/A try {
0N/A t.setComponent(null);
0N/A } catch (IllegalArgumentException iae) {
0N/A // ignore it.
0N/A }
0N/A }
0N/A
0N/A // if we have a new one, and we have a peer, add it!
0N/A
0N/A if ((dropTarget = dt) != null) {
0N/A try {
0N/A dropTarget.setComponent(this);
0N/A if (peer != null) dropTarget.addNotify(peer);
0N/A } catch (IllegalArgumentException iae) {
0N/A if (old != null) {
0N/A try {
0N/A old.setComponent(this);
0N/A if (peer != null) dropTarget.addNotify(peer);
0N/A } catch (IllegalArgumentException iae1) {
0N/A // ignore it!
0N/A }
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Gets the <code>DropTarget</code> associated with this
0N/A * <code>Component</code>.
0N/A */
0N/A
0N/A public synchronized DropTarget getDropTarget() { return dropTarget; }
0N/A
0N/A /**
0N/A * Gets the <code>GraphicsConfiguration</code> associated with this
0N/A * <code>Component</code>.
0N/A * If the <code>Component</code> has not been assigned a specific
0N/A * <code>GraphicsConfiguration</code>,
0N/A * the <code>GraphicsConfiguration</code> of the
0N/A * <code>Component</code> object's top-level container is
0N/A * returned.
0N/A * If the <code>Component</code> has been created, but not yet added
0N/A * to a <code>Container</code>, this method returns <code>null</code>.
0N/A *
0N/A * @return the <code>GraphicsConfiguration</code> used by this
0N/A * <code>Component</code> or <code>null</code>
0N/A * @since 1.3
0N/A */
0N/A public GraphicsConfiguration getGraphicsConfiguration() {
0N/A synchronized(getTreeLock()) {
96N/A if (graphicsConfig != null) {
96N/A return graphicsConfig;
96N/A } else if (getParent() != null) {
96N/A return getParent().getGraphicsConfiguration();
96N/A } else {
96N/A return null;
96N/A }
0N/A }
0N/A }
0N/A
0N/A final GraphicsConfiguration getGraphicsConfiguration_NoClientCode() {
96N/A GraphicsConfiguration graphicsConfig = this.graphicsConfig;
96N/A Container parent = this.parent;
96N/A if (graphicsConfig != null) {
96N/A return graphicsConfig;
96N/A } else if (parent != null) {
96N/A return parent.getGraphicsConfiguration_NoClientCode();
96N/A } else {
96N/A return null;
96N/A }
0N/A }
0N/A
0N/A /**
0N/A * Resets this <code>Component</code>'s
0N/A * <code>GraphicsConfiguration</code> back to a default
0N/A * value. For most componenets, this is <code>null</code>.
0N/A * Called from the Toolkit thread, so NO CLIENT CODE.
0N/A */
0N/A void resetGC() {
0N/A synchronized(getTreeLock()) {
0N/A graphicsConfig = null;
0N/A }
0N/A }
0N/A
0N/A /*
0N/A * Not called on Component, but needed for Canvas and Window
0N/A */
0N/A void setGCFromPeer() {
0N/A synchronized(getTreeLock()) {
0N/A if (peer != null) { // can't imagine how this will be false,
0N/A // but just in case
0N/A graphicsConfig = peer.getGraphicsConfiguration();
0N/A } else {
0N/A graphicsConfig = null;
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Checks that this component's <code>GraphicsDevice</code>
0N/A * <code>idString</code> matches the string argument.
0N/A */
0N/A void checkGD(String stringID) {
0N/A if (graphicsConfig != null) {
0N/A if (!graphicsConfig.getDevice().getIDstring().equals(stringID)) {
0N/A throw new IllegalArgumentException(
0N/A "adding a container to a container on a different GraphicsDevice");
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Gets this component's locking object (the object that owns the thread
212N/A * synchronization monitor) for AWT component-tree and layout
0N/A * operations.
0N/A * @return this component's locking object
0N/A */
0N/A public final Object getTreeLock() {
0N/A return LOCK;
0N/A }
0N/A
0N/A final void checkTreeLock() {
0N/A if (!Thread.holdsLock(getTreeLock())) {
0N/A throw new IllegalStateException("This function should be called while holding treeLock");
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Gets the toolkit of this component. Note that
0N/A * the frame that contains a component controls which
0N/A * toolkit is used by that component. Therefore if the component
0N/A * is moved from one frame to another, the toolkit it uses may change.
0N/A * @return the toolkit of this component
0N/A * @since JDK1.0
0N/A */
0N/A public Toolkit getToolkit() {
0N/A return getToolkitImpl();
0N/A }
0N/A
0N/A /*
0N/A * This is called by the native code, so client code can't
0N/A * be called on the toolkit thread.
0N/A */
0N/A final Toolkit getToolkitImpl() {
0N/A ComponentPeer peer = this.peer;
0N/A if ((peer != null) && ! (peer instanceof LightweightPeer)){
0N/A return peer.getToolkit();
0N/A }
0N/A Container parent = this.parent;
0N/A if (parent != null) {
0N/A return parent.getToolkitImpl();
0N/A }
0N/A return Toolkit.getDefaultToolkit();
0N/A }
0N/A
0N/A /**
0N/A * Determines whether this component is valid. A component is valid
0N/A * when it is correctly sized and positioned within its parent
0N/A * container and all its children are also valid.
0N/A * In order to account for peers' size requirements, components are invalidated
0N/A * before they are first shown on the screen. By the time the parent container
0N/A * is fully realized, all its components will be valid.
0N/A * @return <code>true</code> if the component is valid, <code>false</code>
0N/A * otherwise
0N/A * @see #validate
0N/A * @see #invalidate
0N/A * @since JDK1.0
0N/A */
0N/A public boolean isValid() {
0N/A return (peer != null) && valid;
0N/A }
0N/A
0N/A /**
0N/A * Determines whether this component is displayable. A component is
0N/A * displayable when it is connected to a native screen resource.
0N/A * <p>
0N/A * A component is made displayable either when it is added to
0N/A * a displayable containment hierarchy or when its containment
0N/A * hierarchy is made displayable.
0N/A * A containment hierarchy is made displayable when its ancestor
0N/A * window is either packed or made visible.
0N/A * <p>
0N/A * A component is made undisplayable either when it is removed from
0N/A * a displayable containment hierarchy or when its containment hierarchy
0N/A * is made undisplayable. A containment hierarchy is made
0N/A * undisplayable when its ancestor window is disposed.
0N/A *
0N/A * @return <code>true</code> if the component is displayable,
0N/A * <code>false</code> otherwise
0N/A * @see Container#add(Component)
0N/A * @see Window#pack
0N/A * @see Window#show
0N/A * @see Container#remove(Component)
0N/A * @see Window#dispose
0N/A * @since 1.2
0N/A */
0N/A public boolean isDisplayable() {
0N/A return getPeer() != null;
0N/A }
0N/A
0N/A /**
0N/A * Determines whether this component should be visible when its
0N/A * parent is visible. Components are
0N/A * initially visible, with the exception of top level components such
0N/A * as <code>Frame</code> objects.
0N/A * @return <code>true</code> if the component is visible,
0N/A * <code>false</code> otherwise
0N/A * @see #setVisible
0N/A * @since JDK1.0
0N/A */
0N/A public boolean isVisible() {
0N/A return isVisible_NoClientCode();
0N/A }
0N/A final boolean isVisible_NoClientCode() {
0N/A return visible;
0N/A }
0N/A
0N/A /**
0N/A * Determines whether this component will be displayed on the screen.
0N/A * @return <code>true</code> if the component and all of its ancestors
0N/A * until a toplevel window or null parent are visible,
0N/A * <code>false</code> otherwise
0N/A */
0N/A boolean isRecursivelyVisible() {
0N/A return visible && (parent == null || parent.isRecursivelyVisible());
0N/A }
0N/A
0N/A /**
0N/A * Translates absolute coordinates into coordinates in the coordinate
0N/A * space of this component.
0N/A */
0N/A Point pointRelativeToComponent(Point absolute) {
0N/A Point compCoords = getLocationOnScreen();
0N/A return new Point(absolute.x - compCoords.x,
0N/A absolute.y - compCoords.y);
0N/A }
0N/A
0N/A /**
0N/A * Assuming that mouse location is stored in PointerInfo passed
0N/A * to this method, it finds a Component that is in the same
0N/A * Window as this Component and is located under the mouse pointer.
0N/A * If no such Component exists, null is returned.
0N/A * NOTE: this method should be called under the protection of
0N/A * tree lock, as it is done in Component.getMousePosition() and
0N/A * Container.getMousePosition(boolean).
0N/A */
0N/A Component findUnderMouseInWindow(PointerInfo pi) {
0N/A if (!isShowing()) {
0N/A return null;
0N/A }
0N/A Window win = getContainingWindow();
0N/A if (!Toolkit.getDefaultToolkit().getMouseInfoPeer().isWindowUnderMouse(win)) {
0N/A return null;
0N/A }
0N/A final boolean INCLUDE_DISABLED = true;
0N/A Point relativeToWindow = win.pointRelativeToComponent(pi.getLocation());
0N/A Component inTheSameWindow = win.findComponentAt(relativeToWindow.x,
0N/A relativeToWindow.y,
0N/A INCLUDE_DISABLED);
0N/A return inTheSameWindow;
0N/A }
0N/A
0N/A /**
0N/A * Returns the position of the mouse pointer in this <code>Component</code>'s
0N/A * coordinate space if the <code>Component</code> is directly under the mouse
0N/A * pointer, otherwise returns <code>null</code>.
0N/A * If the <code>Component</code> is not showing on the screen, this method
0N/A * returns <code>null</code> even if the mouse pointer is above the area
0N/A * where the <code>Component</code> would be displayed.
0N/A * If the <code>Component</code> is partially or fully obscured by other
0N/A * <code>Component</code>s or native windows, this method returns a non-null
0N/A * value only if the mouse pointer is located above the unobscured part of the
0N/A * <code>Component</code>.
0N/A * <p>
0N/A * For <code>Container</code>s it returns a non-null value if the mouse is
0N/A * above the <code>Container</code> itself or above any of its descendants.
0N/A * Use {@link Container#getMousePosition(boolean)} if you need to exclude children.
0N/A * <p>
0N/A * Sometimes the exact mouse coordinates are not important, and the only thing
0N/A * that matters is whether a specific <code>Component</code> is under the mouse
0N/A * pointer. If the return value of this method is <code>null</code>, mouse
0N/A * pointer is not directly above the <code>Component</code>.
0N/A *
0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless() returns true
0N/A * @see #isShowing
0N/A * @see Container#getMousePosition
0N/A * @return mouse coordinates relative to this <code>Component</code>, or null
0N/A * @since 1.5
0N/A */
0N/A public Point getMousePosition() throws HeadlessException {
0N/A if (GraphicsEnvironment.isHeadless()) {
0N/A throw new HeadlessException();
0N/A }
0N/A
0N/A PointerInfo pi = (PointerInfo)java.security.AccessController.doPrivileged(
0N/A new java.security.PrivilegedAction() {
0N/A public Object run() {
0N/A return MouseInfo.getPointerInfo();
0N/A }
0N/A }
0N/A );
0N/A
0N/A synchronized (getTreeLock()) {
0N/A Component inTheSameWindow = findUnderMouseInWindow(pi);
0N/A if (!isSameOrAncestorOf(inTheSameWindow, true)) {
0N/A return null;
0N/A }
0N/A return pointRelativeToComponent(pi.getLocation());
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Overridden in Container. Must be called under TreeLock.
0N/A */
0N/A boolean isSameOrAncestorOf(Component comp, boolean allowChildren) {
0N/A return comp == this;
0N/A }
0N/A
0N/A /**
0N/A * Determines whether this component is showing on screen. This means
0N/A * that the component must be visible, and it must be in a container
0N/A * that is visible and showing.
0N/A * <p>
0N/A * <strong>Note:</strong> sometimes there is no way to detect whether the
0N/A * {@code Component} is actually visible to the user. This can happen when:
0N/A * <ul>
0N/A * <li>the component has been added to a visible {@code ScrollPane} but
0N/A * the {@code Component} is not currently in the scroll pane's view port.
0N/A * <li>the {@code Component} is obscured by another {@code Component} or
0N/A * {@code Container}.
0N/A * </ul>
0N/A * @return <code>true</code> if the component is showing,
0N/A * <code>false</code> otherwise
0N/A * @see #setVisible
0N/A * @since JDK1.0
0N/A */
0N/A public boolean isShowing() {
0N/A if (visible && (peer != null)) {
0N/A Container parent = this.parent;
0N/A return (parent == null) || parent.isShowing();
0N/A }
0N/A return false;
0N/A }
0N/A
0N/A /**
0N/A * Determines whether this component is enabled. An enabled component
0N/A * can respond to user input and generate events. Components are
0N/A * enabled initially by default. A component may be enabled or disabled by
0N/A * calling its <code>setEnabled</code> method.
0N/A * @return <code>true</code> if the component is enabled,
0N/A * <code>false</code> otherwise
0N/A * @see #setEnabled
0N/A * @since JDK1.0
0N/A */
0N/A public boolean isEnabled() {
0N/A return isEnabledImpl();
0N/A }
0N/A
0N/A /*
0N/A * This is called by the native code, so client code can't
0N/A * be called on the toolkit thread.
0N/A */
0N/A final boolean isEnabledImpl() {
0N/A return enabled;
0N/A }
0N/A
0N/A /**
0N/A * Enables or disables this component, depending on the value of the
0N/A * parameter <code>b</code>. An enabled component can respond to user
0N/A * input and generate events. Components are enabled initially by default.
0N/A *
0N/A * <p>Note: Disabling a lightweight component does not prevent it from
0N/A * receiving MouseEvents.
0N/A * <p>Note: Disabling a heavyweight container prevents all components
0N/A * in this container from receiving any input events. But disabling a
0N/A * lightweight container affects only this container.
0N/A *
0N/A * @param b If <code>true</code>, this component is
0N/A * enabled; otherwise this component is disabled
0N/A * @see #isEnabled
0N/A * @see #isLightweight
0N/A * @since JDK1.1
0N/A */
0N/A public void setEnabled(boolean b) {
0N/A enable(b);
0N/A }
0N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1,
0N/A * replaced by <code>setEnabled(boolean)</code>.
0N/A */
0N/A @Deprecated
0N/A public void enable() {
0N/A if (!enabled) {
0N/A synchronized (getTreeLock()) {
0N/A enabled = true;
0N/A ComponentPeer peer = this.peer;
0N/A if (peer != null) {
0N/A peer.enable();
0N/A if (visible) {
0N/A updateCursorImmediately();
0N/A }
0N/A }
0N/A }
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>setEnabled(boolean)</code>.
0N/A */
0N/A @Deprecated
0N/A public void enable(boolean b) {
0N/A if (b) {
0N/A enable();
0N/A } else {
0N/A disable();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1,
0N/A * replaced by <code>setEnabled(boolean)</code>.
0N/A */
0N/A @Deprecated
0N/A public void disable() {
0N/A if (enabled) {
0N/A KeyboardFocusManager.clearMostRecentFocusOwner(this);
0N/A synchronized (getTreeLock()) {
0N/A enabled = false;
218N/A // A disabled lw container is allowed to contain a focus owner.
218N/A if ((isFocusOwner() || (containsFocus() && !isLightweight())) &&
218N/A KeyboardFocusManager.isAutoFocusTransferEnabled())
218N/A {
0N/A // Don't clear the global focus owner. If transferFocus
0N/A // fails, we want the focus to stay on the disabled
0N/A // Component so that keyboard traversal, et. al. still
0N/A // makes sense to the user.
218N/A transferFocus(false);
0N/A }
0N/A ComponentPeer peer = this.peer;
0N/A if (peer != null) {
0N/A peer.disable();
0N/A if (visible) {
0N/A updateCursorImmediately();
0N/A }
0N/A }
0N/A }
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 * Returns true if this component is painted to an offscreen image
0N/A * ("buffer") that's copied to the screen later. Component
0N/A * subclasses that support double buffering should override this
0N/A * method to return true if double buffering is enabled.
0N/A *
0N/A * @return false by default
0N/A */
0N/A public boolean isDoubleBuffered() {
0N/A return false;
0N/A }
0N/A
0N/A /**
0N/A * Enables or disables input method support for this component. If input
0N/A * method support is enabled and the component also processes key events,
0N/A * incoming events are offered to
0N/A * the current input method and will only be processed by the component or
0N/A * dispatched to its listeners if the input method does not consume them.
0N/A * By default, input method support is enabled.
0N/A *
0N/A * @param enable true to enable, false to disable
0N/A * @see #processKeyEvent
0N/A * @since 1.2
0N/A */
0N/A public void enableInputMethods(boolean enable) {
0N/A if (enable) {
0N/A if ((eventMask & AWTEvent.INPUT_METHODS_ENABLED_MASK) != 0)
0N/A return;
0N/A
0N/A // If this component already has focus, then activate the
0N/A // input method by dispatching a synthesized focus gained
0N/A // event.
0N/A if (isFocusOwner()) {
0N/A InputContext inputContext = getInputContext();
0N/A if (inputContext != null) {
0N/A FocusEvent focusGainedEvent =
0N/A new FocusEvent(this, FocusEvent.FOCUS_GAINED);
0N/A inputContext.dispatchEvent(focusGainedEvent);
0N/A }
0N/A }
0N/A
0N/A eventMask |= AWTEvent.INPUT_METHODS_ENABLED_MASK;
0N/A } else {
0N/A if ((eventMask & AWTEvent.INPUT_METHODS_ENABLED_MASK) != 0) {
0N/A InputContext inputContext = getInputContext();
0N/A if (inputContext != null) {
0N/A inputContext.endComposition();
0N/A inputContext.removeNotify(this);
0N/A }
0N/A }
0N/A eventMask &= ~AWTEvent.INPUT_METHODS_ENABLED_MASK;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Shows or hides this component depending on the value of parameter
0N/A * <code>b</code>.
0N/A * @param b if <code>true</code>, shows this component;
0N/A * otherwise, hides this component
0N/A * @see #isVisible
0N/A * @since JDK1.1
0N/A */
0N/A public void setVisible(boolean b) {
0N/A show(b);
0N/A }
0N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1,
0N/A * replaced by <code>setVisible(boolean)</code>.
0N/A */
0N/A @Deprecated
0N/A public void show() {
0N/A if (!visible) {
0N/A synchronized (getTreeLock()) {
0N/A visible = true;
0N/A mixOnShowing();
0N/A ComponentPeer peer = this.peer;
0N/A if (peer != null) {
0N/A peer.show();
0N/A createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED,
0N/A this, parent,
0N/A HierarchyEvent.SHOWING_CHANGED,
0N/A Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK));
0N/A if (peer instanceof LightweightPeer) {
0N/A repaint();
0N/A }
0N/A updateCursorImmediately();
0N/A }
0N/A
0N/A if (componentListener != null ||
0N/A (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 ||
0N/A Toolkit.enabledOnToolkit(AWTEvent.COMPONENT_EVENT_MASK)) {
0N/A ComponentEvent e = new ComponentEvent(this,
0N/A ComponentEvent.COMPONENT_SHOWN);
0N/A Toolkit.getEventQueue().postEvent(e);
0N/A }
0N/A }
0N/A Container parent = this.parent;
0N/A if (parent != null) {
0N/A parent.invalidate();
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1,
0N/A * replaced by <code>setVisible(boolean)</code>.
0N/A */
0N/A @Deprecated
0N/A public void show(boolean b) {
0N/A if (b) {
0N/A show();
0N/A } else {
0N/A hide();
0N/A }
0N/A }
0N/A
0N/A boolean containsFocus() {
0N/A return isFocusOwner();
0N/A }
0N/A
0N/A void clearMostRecentFocusOwnerOnHide() {
0N/A KeyboardFocusManager.clearMostRecentFocusOwner(this);
0N/A }
0N/A
0N/A void clearCurrentFocusCycleRootOnHide() {
0N/A /* do nothing */
0N/A }
0N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1,
0N/A * replaced by <code>setVisible(boolean)</code>.
0N/A */
0N/A @Deprecated
0N/A public void hide() {
0N/A isPacked = false;
0N/A
0N/A if (visible) {
0N/A clearCurrentFocusCycleRootOnHide();
0N/A clearMostRecentFocusOwnerOnHide();
0N/A synchronized (getTreeLock()) {
0N/A visible = false;
0N/A mixOnHiding(isLightweight());
218N/A if (containsFocus() && KeyboardFocusManager.isAutoFocusTransferEnabled()) {
218N/A transferFocus(true);
0N/A }
0N/A ComponentPeer peer = this.peer;
0N/A if (peer != null) {
0N/A peer.hide();
0N/A createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED,
0N/A this, parent,
0N/A HierarchyEvent.SHOWING_CHANGED,
0N/A Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK));
0N/A if (peer instanceof LightweightPeer) {
0N/A repaint();
0N/A }
0N/A updateCursorImmediately();
0N/A }
0N/A if (componentListener != null ||
0N/A (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 ||
0N/A Toolkit.enabledOnToolkit(AWTEvent.COMPONENT_EVENT_MASK)) {
0N/A ComponentEvent e = new ComponentEvent(this,
0N/A ComponentEvent.COMPONENT_HIDDEN);
0N/A Toolkit.getEventQueue().postEvent(e);
0N/A }
0N/A }
0N/A Container parent = this.parent;
0N/A if (parent != null) {
0N/A parent.invalidate();
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Gets the foreground color of this component.
0N/A * @return this component's foreground color; if this component does
0N/A * not have a foreground color, the foreground color of its parent
0N/A * is returned
0N/A * @see #setForeground
0N/A * @since JDK1.0
0N/A * @beaninfo
0N/A * bound: true
0N/A */
0N/A public Color getForeground() {
0N/A Color foreground = this.foreground;
0N/A if (foreground != null) {
0N/A return foreground;
0N/A }
0N/A Container parent = this.parent;
0N/A return (parent != null) ? parent.getForeground() : null;
0N/A }
0N/A
0N/A /**
0N/A * Sets the foreground color of this component.
0N/A * @param c the color to become this component's
0N/A * foreground color; if this parameter is <code>null</code>
0N/A * then this component will inherit
0N/A * the foreground color of its parent
0N/A * @see #getForeground
0N/A * @since JDK1.0
0N/A */
0N/A public void setForeground(Color c) {
0N/A Color oldColor = foreground;
0N/A ComponentPeer peer = this.peer;
0N/A foreground = c;
0N/A if (peer != null) {
0N/A c = getForeground();
0N/A if (c != null) {
0N/A peer.setForeground(c);
0N/A }
0N/A }
0N/A // This is a bound property, so report the change to
0N/A // any registered listeners. (Cheap if there are none.)
0N/A firePropertyChange("foreground", oldColor, c);
0N/A }
0N/A
0N/A /**
0N/A * Returns whether the foreground color has been explicitly set for this
0N/A * Component. If this method returns <code>false</code>, this Component is
0N/A * inheriting its foreground color from an ancestor.
0N/A *
0N/A * @return <code>true</code> if the foreground color has been explicitly
0N/A * set for this Component; <code>false</code> otherwise.
0N/A * @since 1.4
0N/A */
0N/A public boolean isForegroundSet() {
0N/A return (foreground != null);
0N/A }
0N/A
0N/A /**
0N/A * Gets the background color of this component.
0N/A * @return this component's background color; if this component does
0N/A * not have a background color,
0N/A * the background color of its parent is returned
0N/A * @see #setBackground
0N/A * @since JDK1.0
0N/A */
0N/A public Color getBackground() {
0N/A Color background = this.background;
0N/A if (background != null) {
0N/A return background;
0N/A }
0N/A Container parent = this.parent;
0N/A return (parent != null) ? parent.getBackground() : null;
0N/A }
0N/A
0N/A /**
0N/A * Sets the background color of this component.
0N/A * <p>
0N/A * The background color affects each component differently and the
0N/A * parts of the component that are affected by the background color
0N/A * may differ between operating systems.
0N/A *
0N/A * @param c the color to become this component's color;
0N/A * if this parameter is <code>null</code>, then this
0N/A * component will inherit the background color of its parent
0N/A * @see #getBackground
0N/A * @since JDK1.0
0N/A * @beaninfo
0N/A * bound: true
0N/A */
0N/A public void setBackground(Color c) {
0N/A Color oldColor = background;
0N/A ComponentPeer peer = this.peer;
0N/A background = c;
0N/A if (peer != null) {
0N/A c = getBackground();
0N/A if (c != null) {
0N/A peer.setBackground(c);
0N/A }
0N/A }
0N/A // This is a bound property, so report the change to
0N/A // any registered listeners. (Cheap if there are none.)
0N/A firePropertyChange("background", oldColor, c);
0N/A }
0N/A
0N/A /**
0N/A * Returns whether the background color has been explicitly set for this
0N/A * Component. If this method returns <code>false</code>, this Component is
0N/A * inheriting its background color from an ancestor.
0N/A *
0N/A * @return <code>true</code> if the background color has been explicitly
0N/A * set for this Component; <code>false</code> otherwise.
0N/A * @since 1.4
0N/A */
0N/A public boolean isBackgroundSet() {
0N/A return (background != null);
0N/A }
0N/A
0N/A /**
0N/A * Gets the font of this component.
0N/A * @return this component's font; if a font has not been set
0N/A * for this component, the font of its parent is returned
0N/A * @see #setFont
0N/A * @since JDK1.0
0N/A */
0N/A public Font getFont() {
0N/A return getFont_NoClientCode();
0N/A }
0N/A
0N/A // NOTE: This method may be called by privileged threads.
0N/A // This functionality is implemented in a package-private method
0N/A // to insure that it cannot be overridden by client subclasses.
0N/A // DO NOT INVOKE CLIENT CODE ON THIS THREAD!
0N/A final Font getFont_NoClientCode() {
0N/A Font font = this.font;
0N/A if (font != null) {
0N/A return font;
0N/A }
0N/A Container parent = this.parent;
0N/A return (parent != null) ? parent.getFont_NoClientCode() : null;
0N/A }
0N/A
0N/A /**
0N/A * Sets the font of this component.
0N/A * @param f the font to become this component's font;
0N/A * if this parameter is <code>null</code> then this
0N/A * component will inherit the font of its parent
0N/A * @see #getFont
0N/A * @since JDK1.0
0N/A * @beaninfo
0N/A * bound: true
0N/A */
0N/A public void setFont(Font f) {
0N/A Font oldFont, newFont;
0N/A synchronized(getTreeLock()) {
0N/A synchronized (this) {
0N/A oldFont = font;
0N/A newFont = font = f;
0N/A }
0N/A ComponentPeer peer = this.peer;
0N/A if (peer != null) {
0N/A f = getFont();
0N/A if (f != null) {
0N/A peer.setFont(f);
0N/A peerFont = f;
0N/A }
0N/A }
0N/A }
0N/A // This is a bound property, so report the change to
0N/A // any registered listeners. (Cheap if there are none.)
0N/A firePropertyChange("font", oldFont, newFont);
0N/A
0N/A // This could change the preferred size of the Component.
0N/A // Fix for 6213660. Should compare old and new fonts and do not
0N/A // call invalidate() if they are equal.
0N/A if (valid && f != oldFont && (oldFont == null ||
0N/A !oldFont.equals(f))) {
0N/A invalidate();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns whether the font has been explicitly set for this Component. If
0N/A * this method returns <code>false</code>, this Component is inheriting its
0N/A * font from an ancestor.
0N/A *
0N/A * @return <code>true</code> if the font has been explicitly set for this
0N/A * Component; <code>false</code> otherwise.
0N/A * @since 1.4
0N/A */
0N/A public boolean isFontSet() {
0N/A return (font != null);
0N/A }
0N/A
0N/A /**
0N/A * Gets the locale of this component.
0N/A * @return this component's locale; if this component does not
0N/A * have a locale, the locale of its parent is returned
0N/A * @see #setLocale
0N/A * @exception IllegalComponentStateException if the <code>Component</code>
0N/A * does not have its own locale and has not yet been added to
0N/A * a containment hierarchy such that the locale can be determined
0N/A * from the containing parent
0N/A * @since JDK1.1
0N/A */
0N/A public Locale getLocale() {
0N/A Locale locale = this.locale;
0N/A if (locale != null) {
0N/A return locale;
0N/A }
0N/A Container parent = this.parent;
0N/A
0N/A if (parent == null) {
0N/A throw new IllegalComponentStateException("This component must have a parent in order to determine its locale");
0N/A } else {
0N/A return parent.getLocale();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets the locale of this component. This is a bound property.
0N/A * @param l the locale to become this component's locale
0N/A * @see #getLocale
0N/A * @since JDK1.1
0N/A */
0N/A public void setLocale(Locale l) {
0N/A Locale oldValue = locale;
0N/A locale = l;
0N/A
0N/A // This is a bound property, so report the change to
0N/A // any registered listeners. (Cheap if there are none.)
0N/A firePropertyChange("locale", oldValue, l);
0N/A
0N/A // This could change the preferred size of the Component.
0N/A if (valid) {
0N/A invalidate();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Gets the instance of <code>ColorModel</code> used to display
0N/A * the component on the output device.
0N/A * @return the color model used by this component
0N/A * @see java.awt.image.ColorModel
0N/A * @see java.awt.peer.ComponentPeer#getColorModel()
0N/A * @see Toolkit#getColorModel()
0N/A * @since JDK1.0
0N/A */
0N/A public ColorModel getColorModel() {
0N/A ComponentPeer peer = this.peer;
0N/A if ((peer != null) && ! (peer instanceof LightweightPeer)) {
0N/A return peer.getColorModel();
0N/A } else if (GraphicsEnvironment.isHeadless()) {
0N/A return ColorModel.getRGBdefault();
0N/A } // else
0N/A return getToolkit().getColorModel();
0N/A }
0N/A
0N/A /**
0N/A * Gets the location of this component in the form of a
0N/A * point specifying the component's top-left corner.
0N/A * The location will be relative to the parent's coordinate space.
0N/A * <p>
0N/A * Due to the asynchronous nature of native event handling, this
0N/A * method can return outdated values (for instance, after several calls
0N/A * of <code>setLocation()</code> in rapid succession). For this
0N/A * reason, the recommended method of obtaining a component's position is
0N/A * within <code>java.awt.event.ComponentListener.componentMoved()</code>,
0N/A * which is called after the operating system has finished moving the
0N/A * component.
0N/A * </p>
0N/A * @return an instance of <code>Point</code> representing
0N/A * the top-left corner of the component's bounds in
0N/A * the coordinate space of the component's parent
0N/A * @see #setLocation
0N/A * @see #getLocationOnScreen
0N/A * @since JDK1.1
0N/A */
0N/A public Point getLocation() {
0N/A return location();
0N/A }
0N/A
0N/A /**
0N/A * Gets the location of this component in the form of a point
0N/A * specifying the component's top-left corner in the screen's
0N/A * coordinate space.
0N/A * @return an instance of <code>Point</code> representing
0N/A * the top-left corner of the component's bounds in the
0N/A * coordinate space of the screen
0N/A * @throws <code>IllegalComponentStateException</code> if the
0N/A * component is not showing on the screen
0N/A * @see #setLocation
0N/A * @see #getLocation
0N/A */
0N/A public Point getLocationOnScreen() {
0N/A synchronized (getTreeLock()) {
0N/A return getLocationOnScreen_NoTreeLock();
0N/A }
0N/A }
0N/A
0N/A /*
0N/A * a package private version of getLocationOnScreen
0N/A * used by GlobalCursormanager to update cursor
0N/A */
0N/A final Point getLocationOnScreen_NoTreeLock() {
0N/A
0N/A if (peer != null && isShowing()) {
0N/A if (peer instanceof LightweightPeer) {
0N/A // lightweight component location needs to be translated
0N/A // relative to a native component.
0N/A Container host = getNativeContainer();
0N/A Point pt = host.peer.getLocationOnScreen();
0N/A for(Component c = this; c != host; c = c.getParent()) {
0N/A pt.x += c.x;
0N/A pt.y += c.y;
0N/A }
0N/A return pt;
0N/A } else {
0N/A Point pt = peer.getLocationOnScreen();
0N/A return pt;
0N/A }
0N/A } else {
0N/A throw new IllegalComponentStateException("component must be showing on the screen to determine its location");
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1,
0N/A * replaced by <code>getLocation()</code>.
0N/A */
0N/A @Deprecated
0N/A public Point location() {
0N/A return location_NoClientCode();
0N/A }
0N/A
0N/A private Point location_NoClientCode() {
0N/A return new Point(x, y);
0N/A }
0N/A
0N/A /**
0N/A * Moves this component to a new location. The top-left corner of
0N/A * the new location is specified by the <code>x</code> and <code>y</code>
0N/A * parameters in the coordinate space of this component's parent.
0N/A * @param x the <i>x</i>-coordinate of the new location's
0N/A * top-left corner in the parent's coordinate space
0N/A * @param y the <i>y</i>-coordinate of the new location's
0N/A * top-left corner in the parent's coordinate space
0N/A * @see #getLocation
0N/A * @see #setBounds
0N/A * @since JDK1.1
0N/A */
0N/A public void setLocation(int x, int y) {
0N/A move(x, y);
0N/A }
0N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1,
0N/A * replaced by <code>setLocation(int, int)</code>.
0N/A */
0N/A @Deprecated
0N/A public void move(int x, int y) {
0N/A synchronized(getTreeLock()) {
0N/A setBoundsOp(ComponentPeer.SET_LOCATION);
0N/A setBounds(x, y, width, height);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Moves this component to a new location. The top-left corner of
0N/A * the new location is specified by point <code>p</code>. Point
0N/A * <code>p</code> is given in the parent's coordinate space.
0N/A * @param p the point defining the top-left corner
0N/A * of the new location, given in the coordinate space of this
0N/A * component's parent
0N/A * @see #getLocation
0N/A * @see #setBounds
0N/A * @since JDK1.1
0N/A */
0N/A public void setLocation(Point p) {
0N/A setLocation(p.x, p.y);
0N/A }
0N/A
0N/A /**
0N/A * Returns the size of this component in the form of a
0N/A * <code>Dimension</code> object. The <code>height</code>
0N/A * field of the <code>Dimension</code> object contains
0N/A * this component's height, and the <code>width</code>
0N/A * field of the <code>Dimension</code> object contains
0N/A * this component's width.
0N/A * @return a <code>Dimension</code> object that indicates the
0N/A * size of this component
0N/A * @see #setSize
0N/A * @since JDK1.1
0N/A */
0N/A public Dimension getSize() {
0N/A return size();
0N/A }
0N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1,
0N/A * replaced by <code>getSize()</code>.
0N/A */
0N/A @Deprecated
0N/A public Dimension size() {
0N/A return new Dimension(width, height);
0N/A }
0N/A
0N/A /**
0N/A * Resizes this component so that it has width <code>width</code>
0N/A * and height <code>height</code>.
0N/A * @param width the new width of this component in pixels
0N/A * @param height the new height of this component in pixels
0N/A * @see #getSize
0N/A * @see #setBounds
0N/A * @since JDK1.1
0N/A */
0N/A public void setSize(int width, int height) {
0N/A resize(width, height);
0N/A }
0N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1,
0N/A * replaced by <code>setSize(int, int)</code>.
0N/A */
0N/A @Deprecated
0N/A public void resize(int width, int height) {
0N/A synchronized(getTreeLock()) {
0N/A setBoundsOp(ComponentPeer.SET_SIZE);
0N/A setBounds(x, y, width, height);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Resizes this component so that it has width <code>d.width</code>
0N/A * and height <code>d.height</code>.
0N/A * @param d the dimension specifying the new size
0N/A * of this component
0N/A * @see #setSize
0N/A * @see #setBounds
0N/A * @since JDK1.1
0N/A */
0N/A public void setSize(Dimension d) {
0N/A resize(d);
0N/A }
0N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1,
0N/A * replaced by <code>setSize(Dimension)</code>.
0N/A */
0N/A @Deprecated
0N/A public void resize(Dimension d) {
0N/A setSize(d.width, d.height);
0N/A }
0N/A
0N/A /**
0N/A * Gets the bounds of this component in the form of a
0N/A * <code>Rectangle</code> object. The bounds specify this
0N/A * component's width, height, and location relative to
0N/A * its parent.
0N/A * @return a rectangle indicating this component's bounds
0N/A * @see #setBounds
0N/A * @see #getLocation
0N/A * @see #getSize
0N/A */
0N/A public Rectangle getBounds() {
0N/A return bounds();
0N/A }
0N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1,
0N/A * replaced by <code>getBounds()</code>.
0N/A */
0N/A @Deprecated
0N/A public Rectangle bounds() {
0N/A return new Rectangle(x, y, width, height);
0N/A }
0N/A
0N/A /**
0N/A * Moves and resizes this component. The new location of the top-left
0N/A * corner is specified by <code>x</code> and <code>y</code>, and the
0N/A * new size is specified by <code>width</code> and <code>height</code>.
0N/A * @param x the new <i>x</i>-coordinate of this component
0N/A * @param y the new <i>y</i>-coordinate of this component
0N/A * @param width the new <code>width</code> of this component
0N/A * @param height the new <code>height</code> of this
0N/A * component
0N/A * @see #getBounds
0N/A * @see #setLocation(int, int)
0N/A * @see #setLocation(Point)
0N/A * @see #setSize(int, int)
0N/A * @see #setSize(Dimension)
0N/A * @since JDK1.1
0N/A */
0N/A public void setBounds(int x, int y, int width, int height) {
0N/A reshape(x, y, width, height);
0N/A }
0N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1,
0N/A * replaced by <code>setBounds(int, int, int, int)</code>.
0N/A */
0N/A @Deprecated
0N/A public void reshape(int x, int y, int width, int height) {
0N/A synchronized (getTreeLock()) {
0N/A try {
0N/A setBoundsOp(ComponentPeer.SET_BOUNDS);
0N/A boolean resized = (this.width != width) || (this.height != height);
0N/A boolean moved = (this.x != x) || (this.y != y);
0N/A if (!resized && !moved) {
0N/A return;
0N/A }
0N/A int oldX = this.x;
0N/A int oldY = this.y;
0N/A int oldWidth = this.width;
0N/A int oldHeight = this.height;
0N/A this.x = x;
0N/A this.y = y;
0N/A this.width = width;
0N/A this.height = height;
0N/A
0N/A if (resized) {
0N/A isPacked = false;
0N/A }
0N/A
0N/A boolean needNotify = true;
0N/A mixOnReshaping();
0N/A if (peer != null) {
0N/A // LightwightPeer is an empty stub so can skip peer.reshape
0N/A if (!(peer instanceof LightweightPeer)) {
0N/A reshapeNativePeer(x, y, width, height, getBoundsOp());
0N/A // Check peer actualy changed coordinates
0N/A resized = (oldWidth != this.width) || (oldHeight != this.height);
0N/A moved = (oldX != this.x) || (oldY != this.y);
0N/A // fix for 5025858: do not send ComponentEvents for toplevel
0N/A // windows here as it is done from peer or native code when
0N/A // the window is really resized or moved, otherwise some
0N/A // events may be sent twice
0N/A if (this instanceof Window) {
0N/A needNotify = false;
0N/A }
0N/A }
0N/A if (resized) {
0N/A invalidate();
0N/A }
0N/A if (parent != null && parent.valid) {
0N/A parent.invalidate();
0N/A }
0N/A }
0N/A if (needNotify) {
0N/A notifyNewBounds(resized, moved);
0N/A }
0N/A repaintParentIfNeeded(oldX, oldY, oldWidth, oldHeight);
0N/A } finally {
0N/A setBoundsOp(ComponentPeer.RESET_OPERATION);
0N/A }
0N/A }
0N/A }
0N/A
0N/A private void repaintParentIfNeeded(int oldX, int oldY, int oldWidth,
0N/A int oldHeight)
0N/A {
0N/A if (parent != null && peer instanceof LightweightPeer && isShowing()) {
0N/A // Have the parent redraw the area this component occupied.
0N/A parent.repaint(oldX, oldY, oldWidth, oldHeight);
0N/A // Have the parent redraw the area this component *now* occupies.
0N/A repaint();
0N/A }
0N/A }
0N/A
0N/A private void reshapeNativePeer(int x, int y, int width, int height, int op) {
0N/A // native peer might be offset by more than direct
0N/A // parent since parent might be lightweight.
0N/A int nativeX = x;
0N/A int nativeY = y;
0N/A for (Component c = parent;
0N/A (c != null) && (c.peer instanceof LightweightPeer);
0N/A c = c.parent)
0N/A {
0N/A nativeX += c.x;
0N/A nativeY += c.y;
0N/A }
0N/A peer.setBounds(nativeX, nativeY, width, height, op);
0N/A }
0N/A
0N/A
0N/A private void notifyNewBounds(boolean resized, boolean moved) {
0N/A if (componentListener != null
0N/A || (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0
0N/A || Toolkit.enabledOnToolkit(AWTEvent.COMPONENT_EVENT_MASK))
0N/A {
0N/A if (resized) {
0N/A ComponentEvent e = new ComponentEvent(this,
0N/A ComponentEvent.COMPONENT_RESIZED);
0N/A Toolkit.getEventQueue().postEvent(e);
0N/A }
0N/A if (moved) {
0N/A ComponentEvent e = new ComponentEvent(this,
0N/A ComponentEvent.COMPONENT_MOVED);
0N/A Toolkit.getEventQueue().postEvent(e);
0N/A }
0N/A } else {
0N/A if (this instanceof Container && ((Container)this).ncomponents > 0) {
0N/A boolean enabledOnToolkit =
0N/A Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK);
0N/A if (resized) {
0N/A
0N/A ((Container)this).createChildHierarchyEvents(
0N/A HierarchyEvent.ANCESTOR_RESIZED, 0, enabledOnToolkit);
0N/A }
0N/A if (moved) {
0N/A ((Container)this).createChildHierarchyEvents(
0N/A HierarchyEvent.ANCESTOR_MOVED, 0, enabledOnToolkit);
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Moves and resizes this component to conform to the new
0N/A * bounding rectangle <code>r</code>. This component's new
0N/A * position is specified by <code>r.x</code> and <code>r.y</code>,
0N/A * and its new size is specified by <code>r.width</code> and
0N/A * <code>r.height</code>
0N/A * @param r the new bounding rectangle for this component
0N/A * @see #getBounds
0N/A * @see #setLocation(int, int)
0N/A * @see #setLocation(Point)
0N/A * @see #setSize(int, int)
0N/A * @see #setSize(Dimension)
0N/A * @since JDK1.1
0N/A */
0N/A public void setBounds(Rectangle r) {
0N/A setBounds(r.x, r.y, r.width, r.height);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the current x coordinate of the components origin.
0N/A * This method is preferable to writing
0N/A * <code>component.getBounds().x</code>,
0N/A * or <code>component.getLocation().x</code> because it doesn't
0N/A * cause any heap allocations.
0N/A *
0N/A * @return the current x coordinate of the components origin
0N/A * @since 1.2
0N/A */
0N/A public int getX() {
0N/A return x;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the current y coordinate of the components origin.
0N/A * This method is preferable to writing
0N/A * <code>component.getBounds().y</code>,
0N/A * or <code>component.getLocation().y</code> because it
0N/A * doesn't cause any heap allocations.
0N/A *
0N/A * @return the current y coordinate of the components origin
0N/A * @since 1.2
0N/A */
0N/A public int getY() {
0N/A return y;
0N/A }
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>,
0N/A * or <code>component.getSize().width</code> because it
0N/A * doesn't cause any heap allocations.
0N/A *
0N/A * @return the current width of this component
0N/A * @since 1.2
0N/A */
0N/A public int getWidth() {
0N/A return width;
0N/A }
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>,
0N/A * or <code>component.getSize().height</code> because it
0N/A * doesn't cause any heap allocations.
0N/A *
0N/A * @return the current height of this component
0N/A * @since 1.2
0N/A */
0N/A public int getHeight() {
0N/A return height;
0N/A }
0N/A
0N/A /**
0N/A * Stores the bounds of this component into "return value" <b>rv</b> and
0N/A * return <b>rv</b>. If rv is <code>null</code> a new
0N/A * <code>Rectangle</code> is allocated.
0N/A * This version of <code>getBounds</code> is useful if the caller
0N/A * wants to avoid allocating a new <code>Rectangle</code> object
0N/A * on the heap.
0N/A *
0N/A * @param rv the return value, modified to the components bounds
0N/A * @return rv
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 * Stores the width/height of this component into "return value" <b>rv</b>
0N/A * and return <b>rv</b>. If rv is <code>null</code> a new
0N/A * <code>Dimension</code> object is allocated. This version of
0N/A * <code>getSize</code> is useful if the caller wants to avoid
0N/A * allocating a new <code>Dimension</code> object on the heap.
0N/A *
0N/A * @param rv the return value, modified to the components size
0N/A * @return rv
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 * Stores the x,y origin of this component into "return value" <b>rv</b>
0N/A * and return <b>rv</b>. If rv is <code>null</code> a new
0N/A * <code>Point</code> is allocated.
0N/A * This version of <code>getLocation</code> is useful if the
0N/A * 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 components location
0N/A * @return rv
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 * Returns true if this component is completely opaque, returns
0N/A * false by default.
0N/A * <p>
0N/A * An opaque component paints every pixel within its
0N/A * rectangular region. A non-opaque component paints only some of
0N/A * its pixels, allowing the pixels underneath it to "show through".
0N/A * A component that does not fully paint its pixels therefore
0N/A * provides a degree of transparency. Only lightweight
0N/A * components can be transparent.
0N/A * <p>
0N/A * Subclasses that guarantee to always completely paint their
0N/A * contents should override this method and return true. All
0N/A * of the "heavyweight" AWT components are opaque.
0N/A *
0N/A * @return true if this component is completely opaque
0N/A * @see #isLightweight
0N/A * @since 1.2
0N/A */
0N/A public boolean isOpaque() {
0N/A if (getPeer() == null) {
0N/A return false;
0N/A }
0N/A else {
0N/A return !isLightweight();
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * A lightweight component doesn't have a native toolkit peer.
0N/A * Subclasses of <code>Component</code> and <code>Container</code>,
0N/A * other than the ones defined in this package like <code>Button</code>
0N/A * or <code>Scrollbar</code>, are lightweight.
0N/A * All of the Swing components are lightweights.
0N/A * <p>
0N/A * This method will always return <code>false</code> if this component
0N/A * is not displayable because it is impossible to determine the
0N/A * weight of an undisplayable component.
0N/A *
0N/A * @return true if this component has a lightweight peer; false if
0N/A * it has a native peer or no peer
0N/A * @see #isDisplayable
0N/A * @since 1.2
0N/A */
0N/A public boolean isLightweight() {
0N/A return getPeer() instanceof LightweightPeer;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Sets the preferred size of this component to a constant
0N/A * value. Subsequent calls to <code>getPreferredSize</code> will always
0N/A * return this value. Setting the preferred size to <code>null</code>
0N/A * restores the default behavior.
0N/A *
0N/A * @param preferredSize The new preferred size, or null
0N/A * @see #getPreferredSize
0N/A * @see #isPreferredSizeSet
0N/A * @since 1.5
0N/A */
0N/A public void setPreferredSize(Dimension preferredSize) {
0N/A Dimension old;
0N/A // If the preferred size was set, use it as the old value, otherwise
0N/A // use null to indicate we didn't previously have a set preferred
0N/A // size.
0N/A if (prefSizeSet) {
0N/A old = this.prefSize;
0N/A }
0N/A else {
0N/A old = null;
0N/A }
0N/A this.prefSize = preferredSize;
0N/A prefSizeSet = (preferredSize != null);
0N/A firePropertyChange("preferredSize", old, preferredSize);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns true if the preferred size has been set to a
0N/A * non-<code>null</code> value otherwise returns false.
0N/A *
0N/A * @return true if <code>setPreferredSize</code> has been invoked
0N/A * with a non-null value.
0N/A * @since 1.5
0N/A */
0N/A public boolean isPreferredSizeSet() {
0N/A return prefSizeSet;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Gets the preferred size of this component.
0N/A * @return a dimension object indicating this component's preferred size
0N/A * @see #getMinimumSize
0N/A * @see LayoutManager
0N/A */
0N/A public Dimension getPreferredSize() {
0N/A return preferredSize();
0N/A }
0N/A
0N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1,
0N/A * replaced by <code>getPreferredSize()</code>.
0N/A */
0N/A @Deprecated
0N/A public Dimension preferredSize() {
0N/A /* Avoid grabbing the lock if a reasonable cached size value
0N/A * is available.
0N/A */
0N/A Dimension dim = prefSize;
0N/A if (dim == null || !(isPreferredSizeSet() || isValid())) {
0N/A synchronized (getTreeLock()) {
0N/A prefSize = (peer != null) ?
0N/A peer.preferredSize() :
0N/A getMinimumSize();
0N/A dim = prefSize;
0N/A }
0N/A }
0N/A return new Dimension(dim);
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. 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 * @see #isMinimumSizeSet
0N/A * @since 1.5
0N/A */
0N/A public void setMinimumSize(Dimension minimumSize) {
0N/A Dimension old;
0N/A // If the minimum size was set, use it as the old value, otherwise
0N/A // use null to indicate we didn't previously have a set minimum
0N/A // size.
0N/A if (minSizeSet) {
0N/A old = this.minSize;
0N/A }
0N/A else {
0N/A old = null;
0N/A }
0N/A this.minSize = minimumSize;
0N/A minSizeSet = (minimumSize != null);
0N/A firePropertyChange("minimumSize", old, minimumSize);
0N/A }
0N/A
0N/A /**
0N/A * Returns whether or not <code>setMinimumSize</code> has been
0N/A * invoked with a non-null value.
0N/A *
0N/A * @return true if <code>setMinimumSize</code> has been invoked with a
0N/A * non-null value.
0N/A * @since 1.5
0N/A */
0N/A public boolean isMinimumSizeSet() {
0N/A return minSizeSet;
0N/A }
0N/A
0N/A /**
0N/A * Gets the mininimum size of this component.
0N/A * @return a dimension object indicating this component's minimum size
0N/A * @see #getPreferredSize
0N/A * @see LayoutManager
0N/A */
0N/A public Dimension getMinimumSize() {
0N/A return minimumSize();
0N/A }
0N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1,
0N/A * replaced by <code>getMinimumSize()</code>.
0N/A */
0N/A @Deprecated
0N/A public Dimension minimumSize() {
0N/A /* Avoid grabbing the lock if a reasonable cached size value
0N/A * is available.
0N/A */
0N/A Dimension dim = minSize;
0N/A if (dim == null || !(isMinimumSizeSet() || isValid())) {
0N/A synchronized (getTreeLock()) {
0N/A minSize = (peer != null) ?
0N/A peer.minimumSize() :
0N/A size();
0N/A dim = minSize;
0N/A }
0N/A }
0N/A return new Dimension(dim);
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. 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 * @see #isMaximumSizeSet
0N/A * @since 1.5
0N/A */
0N/A public void setMaximumSize(Dimension maximumSize) {
0N/A // If the maximum size was set, use it as the old value, otherwise
0N/A // use null to indicate we didn't previously have a set maximum
0N/A // size.
0N/A Dimension old;
0N/A if (maxSizeSet) {
0N/A old = this.maxSize;
0N/A }
0N/A else {
0N/A old = null;
0N/A }
0N/A this.maxSize = maximumSize;
0N/A maxSizeSet = (maximumSize != null);
0N/A firePropertyChange("maximumSize", old, maximumSize);
0N/A }
0N/A
0N/A /**
0N/A * Returns true if the maximum size has been set to a non-<code>null</code>
0N/A * value otherwise returns false.
0N/A *
0N/A * @return true if <code>maximumSize</code> is non-<code>null</code>,
0N/A * false otherwise
0N/A * @since 1.5
0N/A */
0N/A public boolean isMaximumSizeSet() {
0N/A return maxSizeSet;
0N/A }
0N/A
0N/A /**
0N/A * Gets the maximum size of this component.
0N/A * @return a dimension object indicating this component's maximum size
0N/A * @see #getMinimumSize
0N/A * @see #getPreferredSize
0N/A * @see LayoutManager
0N/A */
0N/A public Dimension getMaximumSize() {
0N/A if (isMaximumSizeSet()) {
0N/A return new Dimension(maxSize);
0N/A }
0N/A return new Dimension(Short.MAX_VALUE, Short.MAX_VALUE);
0N/A }
0N/A
0N/A /**
0N/A * Returns the alignment along the x axis. This specifies how
0N/A * the component would like to be aligned relative to other
0N/A * components. The value should be a number between 0 and 1
0N/A * where 0 represents alignment along the origin, 1 is aligned
0N/A * the furthest away from the origin, 0.5 is centered, etc.
0N/A */
0N/A public float getAlignmentX() {
0N/A return CENTER_ALIGNMENT;
0N/A }
0N/A
0N/A /**
0N/A * Returns the alignment along the y axis. This specifies how
0N/A * the component would like to be aligned relative to other
0N/A * components. The value should be a number between 0 and 1
0N/A * where 0 represents alignment along the origin, 1 is aligned
0N/A * the furthest away from the origin, 0.5 is centered, etc.
0N/A */
0N/A public float getAlignmentY() {
0N/A return CENTER_ALIGNMENT;
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 * The default implementation returns -1. Subclasses that support
0N/A * baseline should override appropriately. 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 * @param width the width to get the baseline for
0N/A * @param height the height to get the baseline for
0N/A * @return the baseline or &lt; 0 indicating there is no reasonable
0N/A * baseline
0N/A * @throws IllegalArgumentException if width or height is &lt; 0
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 if (width < 0 || height < 0) {
0N/A throw new IllegalArgumentException(
0N/A "Width and height must be >= 0");
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 * The default implementation returns
0N/A * <code>BaselineResizeBehavior.OTHER</code>. Subclasses that have a
0N/A * baseline should override appropriately. 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 * @return an enum indicating how the baseline changes as the component
0N/A * size changes
0N/A * @see #getBaseline(int, int)
0N/A * @since 1.6
0N/A */
0N/A public BaselineResizeBehavior getBaselineResizeBehavior() {
0N/A return BaselineResizeBehavior.OTHER;
0N/A }
0N/A
0N/A /**
0N/A * Prompts the layout manager to lay out this component. This is
0N/A * usually called when the component (more specifically, container)
0N/A * is validated.
0N/A * @see #validate
0N/A * @see LayoutManager
0N/A */
0N/A public void doLayout() {
0N/A layout();
0N/A }
0N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1,
0N/A * replaced by <code>doLayout()</code>.
0N/A */
0N/A @Deprecated
0N/A public void layout() {
0N/A }
0N/A
0N/A /**
0N/A * Ensures that this component has a valid layout. This method is
0N/A * primarily intended to operate on instances of <code>Container</code>.
0N/A * @see #invalidate
0N/A * @see #doLayout()
0N/A * @see LayoutManager
0N/A * @see Container#validate
0N/A * @since JDK1.0
0N/A */
0N/A public void validate() {
0N/A synchronized (getTreeLock()) {
0N/A ComponentPeer peer = this.peer;
0N/A if (!valid && peer != null) {
0N/A Font newfont = getFont();
0N/A Font oldfont = peerFont;
0N/A if (newfont != oldfont && (oldfont == null
0N/A || !oldfont.equals(newfont))) {
0N/A peer.setFont(newfont);
0N/A peerFont = newfont;
0N/A }
0N/A peer.layout();
0N/A }
0N/A valid = true;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Invalidates this component. This component and all parents
0N/A * above it are marked as needing to be laid out. This method can
0N/A * be called often, so it needs to execute quickly.
0N/A * @see #validate
0N/A * @see #doLayout
0N/A * @see LayoutManager
0N/A * @since JDK1.0
0N/A */
0N/A public void invalidate() {
0N/A synchronized (getTreeLock()) {
0N/A /* Nullify cached layout and size information.
0N/A * For efficiency, propagate invalidate() upwards only if
0N/A * some other component hasn't already done so first.
0N/A */
0N/A valid = false;
0N/A if (!isPreferredSizeSet()) {
0N/A prefSize = null;
0N/A }
0N/A if (!isMinimumSizeSet()) {
0N/A minSize = null;
0N/A }
0N/A if (!isMaximumSizeSet()) {
0N/A maxSize = null;
0N/A }
0N/A if (parent != null && parent.valid) {
0N/A parent.invalidate();
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Creates a graphics context for this component. This method will
0N/A * return <code>null</code> if this component is currently not
0N/A * displayable.
0N/A * @return a graphics context for this component, or <code>null</code>
0N/A * if it has none
0N/A * @see #paint
0N/A * @since JDK1.0
0N/A */
0N/A public Graphics getGraphics() {
0N/A if (peer instanceof LightweightPeer) {
0N/A // This is for a lightweight component, need to
0N/A // translate coordinate spaces and clip relative
0N/A // to the parent.
0N/A if (parent == null) return null;
0N/A Graphics g = parent.getGraphics();
0N/A if (g == null) return null;
0N/A if (g instanceof ConstrainableGraphics) {
0N/A ((ConstrainableGraphics) g).constrain(x, y, width, height);
0N/A } else {
0N/A g.translate(x,y);
0N/A g.setClip(0, 0, width, height);
0N/A }
0N/A g.setFont(getFont());
0N/A return g;
0N/A } else {
0N/A ComponentPeer peer = this.peer;
0N/A return (peer != null) ? peer.getGraphics() : null;
0N/A }
0N/A }
0N/A
0N/A final Graphics getGraphics_NoClientCode() {
0N/A ComponentPeer peer = this.peer;
0N/A if (peer instanceof LightweightPeer) {
0N/A // This is for a lightweight component, need to
0N/A // translate coordinate spaces and clip relative
0N/A // to the parent.
0N/A Container parent = this.parent;
0N/A if (parent == null) return null;
0N/A Graphics g = parent.getGraphics_NoClientCode();
0N/A if (g == null) return null;
0N/A if (g instanceof ConstrainableGraphics) {
0N/A ((ConstrainableGraphics) g).constrain(x, y, width, height);
0N/A } else {
0N/A g.translate(x,y);
0N/A g.setClip(0, 0, width, height);
0N/A }
0N/A g.setFont(getFont_NoClientCode());
0N/A return g;
0N/A } else {
0N/A return (peer != null) ? peer.getGraphics() : null;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Gets the font metrics for the specified font.
0N/A * Warning: Since Font metrics are affected by the
0N/A * {@link java.awt.font.FontRenderContext FontRenderContext} and
0N/A * this method does not provide one, it can return only metrics for
0N/A * the default render context which may not match that used when
0N/A * rendering on the Component if {@link Graphics2D} functionality is being
0N/A * used. Instead metrics can be obtained at rendering time by calling
0N/A * {@link Graphics#getFontMetrics()} or text measurement APIs on the
0N/A * {@link Font Font} class.
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 * @see #getFont
0N/A * @see #getPeer
0N/A * @see java.awt.peer.ComponentPeer#getFontMetrics(Font)
0N/A * @see Toolkit#getFontMetrics(Font)
0N/A * @since JDK1.0
0N/A */
0N/A public FontMetrics getFontMetrics(Font font) {
0N/A // REMIND: PlatformFont flag should be obsolete soon...
0N/A if (sun.font.FontManager.usePlatformFontMetrics()) {
0N/A if (peer != null &&
0N/A !(peer instanceof LightweightPeer)) {
0N/A return peer.getFontMetrics(font);
0N/A }
0N/A }
0N/A return sun.font.FontDesignMetrics.getMetrics(font);
0N/A }
0N/A
0N/A /**
0N/A * Sets the cursor image to the specified cursor. This cursor
0N/A * image is displayed when the <code>contains</code> method for
0N/A * this component returns true for the current cursor location, and
0N/A * this Component is visible, displayable, and enabled. Setting the
0N/A * cursor of a <code>Container</code> causes that cursor to be displayed
0N/A * within all of the container's subcomponents, except for those
0N/A * that have a non-<code>null</code> cursor.
0N/A * <p>
0N/A * The method may have no visual effect if the Java platform
0N/A * implementation and/or the native system do not support
0N/A * changing the mouse cursor shape.
0N/A * @param cursor One of the constants defined
0N/A * by the <code>Cursor</code> class;
0N/A * if this parameter is <code>null</code>
0N/A * then this component will inherit
0N/A * the cursor of its parent
0N/A * @see #isEnabled
0N/A * @see #isShowing
0N/A * @see #getCursor
0N/A * @see #contains
0N/A * @see Toolkit#createCustomCursor
0N/A * @see Cursor
0N/A * @since JDK1.1
0N/A */
0N/A public void setCursor(Cursor cursor) {
0N/A this.cursor = cursor;
0N/A updateCursorImmediately();
0N/A }
0N/A
0N/A /**
0N/A * Updates the cursor. May not be invoked from the native
0N/A * message pump.
0N/A */
0N/A final void updateCursorImmediately() {
0N/A if (peer instanceof LightweightPeer) {
0N/A Container nativeContainer = getNativeContainer();
0N/A
0N/A if (nativeContainer == null) return;
0N/A
0N/A ComponentPeer cPeer = nativeContainer.getPeer();
0N/A
0N/A if (cPeer != null) {
0N/A cPeer.updateCursorImmediately();
0N/A }
0N/A } else if (peer != null) {
0N/A peer.updateCursorImmediately();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Gets the cursor set in the component. If the component does
0N/A * not have a cursor set, the cursor of its parent is returned.
0N/A * If no cursor is set in the entire hierarchy,
0N/A * <code>Cursor.DEFAULT_CURSOR</code> is returned.
0N/A * @see #setCursor
0N/A * @since JDK1.1
0N/A */
0N/A public Cursor getCursor() {
0N/A return getCursor_NoClientCode();
0N/A }
0N/A
0N/A final Cursor getCursor_NoClientCode() {
0N/A Cursor cursor = this.cursor;
0N/A if (cursor != null) {
0N/A return cursor;
0N/A }
0N/A Container parent = this.parent;
0N/A if (parent != null) {
0N/A return parent.getCursor_NoClientCode();
0N/A } else {
0N/A return Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns whether the cursor has been explicitly set for this Component.
0N/A * If this method returns <code>false</code>, this Component is inheriting
0N/A * its cursor from an ancestor.
0N/A *
0N/A * @return <code>true</code> if the cursor has been explicitly set for this
0N/A * Component; <code>false</code> otherwise.
0N/A * @since 1.4
0N/A */
0N/A public boolean isCursorSet() {
0N/A return (cursor != null);
0N/A }
0N/A
0N/A /**
0N/A * Paints this component.
0N/A * <p>
0N/A * This method is called when the contents of the component should
0N/A * be painted; such as when the component is first being shown or
0N/A * is damaged and in need of repair. The clip rectangle in the
0N/A * <code>Graphics</code> parameter is set to the area
0N/A * which needs to be painted.
0N/A * Subclasses of <code>Component</code> that override this
0N/A * method need not call <code>super.paint(g)</code>.
0N/A * <p>
0N/A * For performance reasons, <code>Component</code>s with zero width
0N/A * or height aren't considered to need painting when they are first shown,
0N/A * and also aren't considered to need repair.
0N/A * <p>
0N/A * <b>Note</b>: For more information on the paint mechanisms utilitized
0N/A * by AWT and Swing, including information on how to write the most
0N/A * efficient painting code, see
0N/A * <a href="http://java.sun.com/products/jfc/tsc/articles/painting/index.html">Painting in AWT and Swing</a>.
0N/A *
0N/A * @param g the graphics context to use for painting
0N/A * @see #update
0N/A * @since JDK1.0
0N/A */
0N/A public void paint(Graphics g) {
0N/A }
0N/A
0N/A /**
0N/A * Updates this component.
0N/A * <p>
0N/A * If this component is not a lightweight component, the
0N/A * AWT calls the <code>update</code> method in response to
0N/A * a call to <code>repaint</code>. You can assume that
0N/A * the background is not cleared.
0N/A * <p>
0N/A * The <code>update</code> method of <code>Component</code>
0N/A * calls this component's <code>paint</code> method to redraw
0N/A * this component. This method is commonly overridden by subclasses
0N/A * which need to do additional work in response to a call to
0N/A * <code>repaint</code>.
0N/A * Subclasses of Component that override this method should either
0N/A * call <code>super.update(g)</code>, or call <code>paint(g)</code>
0N/A * directly from their <code>update</code> method.
0N/A * <p>
0N/A * The origin of the graphics context, its
0N/A * (<code>0</code>,&nbsp;<code>0</code>) coordinate point, is the
0N/A * top-left corner of this component. The clipping region of the
0N/A * graphics context is the bounding rectangle of this component.
0N/A *
0N/A * <p>
0N/A * <b>Note</b>: For more information on the paint mechanisms utilitized
0N/A * by AWT and Swing, including information on how to write the most
0N/A * efficient painting code, see
0N/A * <a href="http://java.sun.com/products/jfc/tsc/articles/painting/index.html">Painting in AWT and Swing</a>.
0N/A *
0N/A * @param g the specified context to use for updating
0N/A * @see #paint
0N/A * @see #repaint()
0N/A * @since JDK1.0
0N/A */
0N/A public void update(Graphics g) {
0N/A paint(g);
0N/A }
0N/A
0N/A /**
0N/A * Paints this component and all of its subcomponents.
0N/A * <p>
0N/A * The origin of the graphics context, its
0N/A * (<code>0</code>,&nbsp;<code>0</code>) coordinate point, is the
0N/A * top-left corner of this component. The clipping region of the
0N/A * graphics context is the bounding rectangle of this component.
0N/A *
0N/A * @param g the graphics context to use for painting
0N/A * @see #paint
0N/A * @since JDK1.0
0N/A */
0N/A public void paintAll(Graphics g) {
0N/A if (isShowing()) {
0N/A GraphicsCallback.PeerPaintCallback.getInstance().
0N/A runOneComponent(this, new Rectangle(0, 0, width, height),
0N/A g, g.getClip(),
0N/A GraphicsCallback.LIGHTWEIGHTS |
0N/A GraphicsCallback.HEAVYWEIGHTS);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Simulates the peer callbacks into java.awt for painting of
0N/A * lightweight Components.
0N/A * @param g the graphics context to use for painting
0N/A * @see #paintAll
0N/A */
0N/A void lightweightPaint(Graphics g) {
0N/A paint(g);
0N/A }
0N/A
0N/A /**
0N/A * Paints all the heavyweight subcomponents.
0N/A */
0N/A void paintHeavyweightComponents(Graphics g) {
0N/A }
0N/A
0N/A /**
0N/A * Repaints this component.
0N/A * <p>
0N/A * If this component is a lightweight component, this method
0N/A * causes a call to this component's <code>paint</code>
0N/A * method as soon as possible. Otherwise, this method causes
0N/A * a call to this component's <code>update</code> method as soon
0N/A * as possible.
0N/A * <p>
0N/A * <b>Note</b>: For more information on the paint mechanisms utilitized
0N/A * by AWT and Swing, including information on how to write the most
0N/A * efficient painting code, see
0N/A * <a href="http://java.sun.com/products/jfc/tsc/articles/painting/index.html">Painting in AWT and Swing</a>.
0N/A
0N/A *
0N/A * @see #update(Graphics)
0N/A * @since JDK1.0
0N/A */
0N/A public void repaint() {
0N/A repaint(0, 0, 0, width, height);
0N/A }
0N/A
0N/A /**
0N/A * Repaints the component. If this component is a lightweight
0N/A * component, this results in a call to <code>paint</code>
0N/A * within <code>tm</code> milliseconds.
0N/A * <p>
0N/A * <b>Note</b>: For more information on the paint mechanisms utilitized
0N/A * by AWT and Swing, including information on how to write the most
0N/A * efficient painting code, see
0N/A * <a href="http://java.sun.com/products/jfc/tsc/articles/painting/index.html">Painting in AWT and Swing</a>.
0N/A *
0N/A * @param tm maximum time in milliseconds before update
0N/A * @see #paint
0N/A * @see #update(Graphics)
0N/A * @since JDK1.0
0N/A */
0N/A public void repaint(long tm) {
0N/A repaint(tm, 0, 0, width, height);
0N/A }
0N/A
0N/A /**
0N/A * Repaints the specified rectangle of this component.
0N/A * <p>
0N/A * If this component is a lightweight component, this method
0N/A * causes a call to this component's <code>paint</code> method
0N/A * as soon as possible. Otherwise, this method causes a call to
0N/A * this component's <code>update</code> method as soon as possible.
0N/A * <p>
0N/A * <b>Note</b>: For more information on the paint mechanisms utilitized
0N/A * by AWT and Swing, including information on how to write the most
0N/A * efficient painting code, see
0N/A * <a href="http://java.sun.com/products/jfc/tsc/articles/painting/index.html">Painting in AWT and Swing</a>.
0N/A *
0N/A * @param x the <i>x</i> coordinate
0N/A * @param y the <i>y</i> coordinate
0N/A * @param width the width
0N/A * @param height the height
0N/A * @see #update(Graphics)
0N/A * @since JDK1.0
0N/A */
0N/A public void repaint(int x, int y, int width, int height) {
0N/A repaint(0, x, y, width, height);
0N/A }
0N/A
0N/A /**
0N/A * Repaints the specified rectangle of this component within
0N/A * <code>tm</code> milliseconds.
0N/A * <p>
0N/A * If this component is a lightweight component, this method causes
0N/A * a call to this component's <code>paint</code> method.
0N/A * Otherwise, this method causes a call to this component's
0N/A * <code>update</code> method.
0N/A * <p>
0N/A * <b>Note</b>: For more information on the paint mechanisms utilitized
0N/A * by AWT and Swing, including information on how to write the most
0N/A * efficient painting code, see
0N/A * <a href="http://java.sun.com/products/jfc/tsc/articles/painting/index.html">Painting in AWT and Swing</a>.
0N/A *
0N/A * @param tm maximum time in milliseconds before update
0N/A * @param x the <i>x</i> coordinate
0N/A * @param y the <i>y</i> coordinate
0N/A * @param width the width
0N/A * @param height the height
0N/A * @see #update(Graphics)
0N/A * @since JDK1.0
0N/A */
0N/A public void repaint(long tm, int x, int y, int width, int height) {
0N/A if (this.peer instanceof LightweightPeer) {
0N/A // Needs to be translated to parent coordinates since
0N/A // a parent native container provides the actual repaint
0N/A // services. Additionally, the request is restricted to
0N/A // the bounds of the component.
0N/A if (parent != null) {
0N/A int px = this.x + ((x < 0) ? 0 : x);
0N/A int py = this.y + ((y < 0) ? 0 : y);
0N/A int pwidth = (width > this.width) ? this.width : width;
0N/A int pheight = (height > this.height) ? this.height : height;
0N/A parent.repaint(tm, px, py, pwidth, pheight);
0N/A }
0N/A } else {
0N/A if (isVisible() && (this.peer != null) &&
0N/A (width > 0) && (height > 0)) {
0N/A PaintEvent e = new PaintEvent(this, PaintEvent.UPDATE,
0N/A new Rectangle(x, y, width, height));
0N/A Toolkit.getEventQueue().postEvent(e);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Prints this component. Applications should override this method
0N/A * for components that must do special processing before being
0N/A * printed or should be printed differently than they are painted.
0N/A * <p>
0N/A * The default implementation of this method calls the
0N/A * <code>paint</code> method.
0N/A * <p>
0N/A * The origin of the graphics context, its
0N/A * (<code>0</code>,&nbsp;<code>0</code>) coordinate point, is the
0N/A * top-left corner of this component. The clipping region of the
0N/A * graphics context is the bounding rectangle of this component.
0N/A * @param g the graphics context to use for printing
0N/A * @see #paint(Graphics)
0N/A * @since JDK1.0
0N/A */
0N/A public void print(Graphics g) {
0N/A paint(g);
0N/A }
0N/A
0N/A /**
0N/A * Prints this component and all of its subcomponents.
0N/A * <p>
0N/A * The origin of the graphics context, its
0N/A * (<code>0</code>,&nbsp;<code>0</code>) coordinate point, is the
0N/A * top-left corner of this component. The clipping region of the
0N/A * graphics context is the bounding rectangle of this component.
0N/A * @param g the graphics context to use for printing
0N/A * @see #print(Graphics)
0N/A * @since JDK1.0
0N/A */
0N/A public void printAll(Graphics g) {
0N/A if (isShowing()) {
0N/A GraphicsCallback.PeerPrintCallback.getInstance().
0N/A runOneComponent(this, new Rectangle(0, 0, width, height),
0N/A g, g.getClip(),
0N/A GraphicsCallback.LIGHTWEIGHTS |
0N/A GraphicsCallback.HEAVYWEIGHTS);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Simulates the peer callbacks into java.awt for printing of
0N/A * lightweight Components.
0N/A * @param g the graphics context to use for printing
0N/A * @see #printAll
0N/A */
0N/A void lightweightPrint(Graphics g) {
0N/A print(g);
0N/A }
0N/A
0N/A /**
0N/A * Prints all the heavyweight subcomponents.
0N/A */
0N/A void printHeavyweightComponents(Graphics g) {
0N/A }
0N/A
0N/A private Insets getInsets_NoClientCode() {
0N/A ComponentPeer peer = this.peer;
0N/A if (peer instanceof ContainerPeer) {
0N/A return (Insets)((ContainerPeer)peer).insets().clone();
0N/A }
0N/A return new Insets(0, 0, 0, 0);
0N/A }
0N/A
0N/A /**
0N/A * Repaints the component when the image has changed.
0N/A * This <code>imageUpdate</code> method of an <code>ImageObserver</code>
0N/A * is called when more information about an
0N/A * image which had been previously requested using an asynchronous
0N/A * routine such as the <code>drawImage</code> method of
0N/A * <code>Graphics</code> becomes available.
0N/A * See the definition of <code>imageUpdate</code> for
0N/A * more information on this method and its arguments.
0N/A * <p>
0N/A * The <code>imageUpdate</code> method of <code>Component</code>
0N/A * incrementally draws an image on the component as more of the bits
0N/A * of the image are available.
0N/A * <p>
0N/A * If the system property <code>awt.image.incrementaldraw</code>
0N/A * is missing or has the value <code>true</code>, the image is
0N/A * incrementally drawn. If the system property has any other value,
0N/A * then the image is not drawn until it has been completely loaded.
0N/A * <p>
0N/A * Also, if incremental drawing is in effect, the value of the
0N/A * system property <code>awt.image.redrawrate</code> is interpreted
0N/A * as an integer to give the maximum redraw rate, in milliseconds. If
0N/A * the system property is missing or cannot be interpreted as an
0N/A * integer, the redraw rate is once every 100ms.
0N/A * <p>
0N/A * The interpretation of the <code>x</code>, <code>y</code>,
0N/A * <code>width</code>, and <code>height</code> arguments depends on
0N/A * the value of the <code>infoflags</code> argument.
0N/A *
0N/A * @param img the image being observed
0N/A * @param infoflags see <code>imageUpdate</code> for more information
0N/A * @param x the <i>x</i> coordinate
0N/A * @param y the <i>y</i> coordinate
0N/A * @param w the width
0N/A * @param h the height
0N/A * @return <code>false</code> if the infoflags indicate that the
0N/A * image is completely loaded; <code>true</code> otherwise.
0N/A *
0N/A * @see java.awt.image.ImageObserver
0N/A * @see Graphics#drawImage(Image, int, int, Color, java.awt.image.ImageObserver)
0N/A * @see Graphics#drawImage(Image, int, int, java.awt.image.ImageObserver)
0N/A * @see Graphics#drawImage(Image, int, int, int, int, Color, java.awt.image.ImageObserver)
0N/A * @see Graphics#drawImage(Image, int, int, int, int, java.awt.image.ImageObserver)
0N/A * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
0N/A * @since JDK1.0
0N/A */
0N/A public boolean imageUpdate(Image img, int infoflags,
0N/A int x, int y, int w, int h) {
0N/A int rate = -1;
0N/A if ((infoflags & (FRAMEBITS|ALLBITS)) != 0) {
0N/A rate = 0;
0N/A } else if ((infoflags & SOMEBITS) != 0) {
0N/A if (isInc) {
0N/A rate = incRate;
0N/A if (rate < 0) {
0N/A rate = 0;
0N/A }
0N/A }
0N/A }
0N/A if (rate >= 0) {
0N/A repaint(rate, 0, 0, width, height);
0N/A }
0N/A return (infoflags & (ALLBITS|ABORT)) == 0;
0N/A }
0N/A
0N/A /**
0N/A * Creates an image from the specified image producer.
0N/A * @param producer the image producer
0N/A * @return the image produced
0N/A * @since JDK1.0
0N/A */
0N/A public Image createImage(ImageProducer producer) {
0N/A ComponentPeer peer = this.peer;
0N/A if ((peer != null) && ! (peer instanceof LightweightPeer)) {
0N/A return peer.createImage(producer);
0N/A }
0N/A return getToolkit().createImage(producer);
0N/A }
0N/A
0N/A /**
0N/A * Creates an off-screen drawable image
0N/A * to be used for double buffering.
0N/A * @param width the specified width
0N/A * @param height the specified height
0N/A * @return an off-screen drawable image, which can be used for double
0N/A * buffering. The return value may be <code>null</code> if the
0N/A * component is not displayable. This will always happen if
0N/A * <code>GraphicsEnvironment.isHeadless()</code> returns
0N/A * <code>true</code>.
0N/A * @see #isDisplayable
0N/A * @see GraphicsEnvironment#isHeadless
0N/A * @since JDK1.0
0N/A */
0N/A public Image createImage(int width, int height) {
0N/A ComponentPeer peer = this.peer;
0N/A if (peer instanceof LightweightPeer) {
0N/A if (parent != null) { return parent.createImage(width, height); }
0N/A else { return null;}
0N/A } else {
0N/A return (peer != null) ? peer.createImage(width, height) : null;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Creates a volatile off-screen drawable image
0N/A * to be used for double buffering.
0N/A * @param width the specified width.
0N/A * @param height the specified height.
0N/A * @return an off-screen drawable image, which can be used for double
0N/A * buffering. The return value may be <code>null</code> if the
0N/A * component is not displayable. This will always happen if
0N/A * <code>GraphicsEnvironment.isHeadless()</code> returns
0N/A * <code>true</code>.
0N/A * @see java.awt.image.VolatileImage
0N/A * @see #isDisplayable
0N/A * @see GraphicsEnvironment#isHeadless
0N/A * @since 1.4
0N/A */
0N/A public VolatileImage createVolatileImage(int width, int height) {
0N/A ComponentPeer peer = this.peer;
0N/A if (peer instanceof LightweightPeer) {
0N/A if (parent != null) {
0N/A return parent.createVolatileImage(width, height);
0N/A }
0N/A else { return null;}
0N/A } else {
0N/A return (peer != null) ?
0N/A peer.createVolatileImage(width, height) : null;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Creates a volatile off-screen drawable image, with the given capabilities.
0N/A * The contents of this image may be lost at any time due
0N/A * to operating system issues, so the image must be managed
0N/A * via the <code>VolatileImage</code> interface.
0N/A * @param width the specified width.
0N/A * @param height the specified height.
0N/A * @param caps the image capabilities
0N/A * @exception AWTException if an image with the specified capabilities cannot
0N/A * be created
0N/A * @return a VolatileImage object, which can be used
0N/A * to manage surface contents loss and capabilities.
0N/A * @see java.awt.image.VolatileImage
0N/A * @since 1.4
0N/A */
0N/A public VolatileImage createVolatileImage(int width, int height,
0N/A ImageCapabilities caps) throws AWTException {
0N/A // REMIND : check caps
0N/A return createVolatileImage(width, height);
0N/A }
0N/A
0N/A /**
0N/A * Prepares an image for rendering on this component. The image
0N/A * data is downloaded asynchronously in another thread and the
0N/A * appropriate screen representation of the image is generated.
0N/A * @param image the <code>Image</code> for which to
0N/A * prepare a screen representation
0N/A * @param observer the <code>ImageObserver</code> object
0N/A * to be notified as the image is being prepared
0N/A * @return <code>true</code> if the image has already been fully
0N/A * prepared; <code>false</code> otherwise
0N/A * @since JDK1.0
0N/A */
0N/A public boolean prepareImage(Image image, ImageObserver observer) {
0N/A return prepareImage(image, -1, -1, observer);
0N/A }
0N/A
0N/A /**
0N/A * Prepares an image for rendering on this component at the
0N/A * specified width and height.
0N/A * <p>
0N/A * The image data is downloaded asynchronously in another thread,
0N/A * and an appropriately scaled screen representation of the image is
0N/A * generated.
0N/A * @param image the instance of <code>Image</code>
0N/A * for which to prepare a screen representation
0N/A * @param width the width of the desired screen representation
0N/A * @param height the height of the desired screen representation
0N/A * @param observer the <code>ImageObserver</code> object
0N/A * to be notified as the image is being prepared
0N/A * @return <code>true</code> if the image has already been fully
0N/A * prepared; <code>false</code> otherwise
0N/A * @see java.awt.image.ImageObserver
0N/A * @since JDK1.0
0N/A */
0N/A public boolean prepareImage(Image image, int width, int height,
0N/A ImageObserver observer) {
0N/A ComponentPeer peer = this.peer;
0N/A if (peer instanceof LightweightPeer) {
0N/A return (parent != null)
0N/A ? parent.prepareImage(image, width, height, observer)
0N/A : getToolkit().prepareImage(image, width, height, observer);
0N/A } else {
0N/A return (peer != null)
0N/A ? peer.prepareImage(image, width, height, observer)
0N/A : getToolkit().prepareImage(image, width, height, observer);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the status of the construction of a screen representation
0N/A * of the specified image.
0N/A * <p>
0N/A * This method does not cause the image to begin loading. An
0N/A * application must use the <code>prepareImage</code> method
0N/A * to force the loading of an image.
0N/A * <p>
0N/A * Information on the flags returned by this method can be found
0N/A * with the discussion of the <code>ImageObserver</code> interface.
0N/A * @param image the <code>Image</code> object whose status
0N/A * is being checked
0N/A * @param observer the <code>ImageObserver</code>
0N/A * object to be notified as the image is being prepared
0N/A * @return the bitwise inclusive <b>OR</b> of
0N/A * <code>ImageObserver</code> flags indicating what
0N/A * information about the image is currently available
0N/A * @see #prepareImage(Image, int, int, java.awt.image.ImageObserver)
0N/A * @see Toolkit#checkImage(Image, int, int, java.awt.image.ImageObserver)
0N/A * @see java.awt.image.ImageObserver
0N/A * @since JDK1.0
0N/A */
0N/A public int checkImage(Image image, ImageObserver observer) {
0N/A return checkImage(image, -1, -1, observer);
0N/A }
0N/A
0N/A /**
0N/A * Returns the status of the construction of a screen representation
0N/A * of the specified image.
0N/A * <p>
0N/A * This method does not cause the image to begin loading. An
0N/A * application must use the <code>prepareImage</code> method
0N/A * to force the loading of an image.
0N/A * <p>
0N/A * The <code>checkImage</code> method of <code>Component</code>
0N/A * calls its peer's <code>checkImage</code> method to calculate
0N/A * the flags. If this component does not yet have a peer, the
0N/A * component's toolkit's <code>checkImage</code> method is called
0N/A * instead.
0N/A * <p>
0N/A * Information on the flags returned by this method can be found
0N/A * with the discussion of the <code>ImageObserver</code> interface.
0N/A * @param image the <code>Image</code> object whose status
0N/A * is being checked
0N/A * @param width the width of the scaled version
0N/A * whose status is to be checked
0N/A * @param height the height of the scaled version
0N/A * whose status is to be checked
0N/A * @param observer the <code>ImageObserver</code> object
0N/A * to be notified as the image is being prepared
0N/A * @return the bitwise inclusive <b>OR</b> of
0N/A * <code>ImageObserver</code> flags indicating what
0N/A * information about the image is currently available
0N/A * @see #prepareImage(Image, int, int, java.awt.image.ImageObserver)
0N/A * @see Toolkit#checkImage(Image, int, int, java.awt.image.ImageObserver)
0N/A * @see java.awt.image.ImageObserver
0N/A * @since JDK1.0
0N/A */
0N/A public int checkImage(Image image, int width, int height,
0N/A ImageObserver observer) {
0N/A ComponentPeer peer = this.peer;
0N/A if (peer instanceof LightweightPeer) {
0N/A return (parent != null)
0N/A ? parent.checkImage(image, width, height, observer)
0N/A : getToolkit().checkImage(image, width, height, observer);
0N/A } else {
0N/A return (peer != null)
0N/A ? peer.checkImage(image, width, height, observer)
0N/A : getToolkit().checkImage(image, width, height, observer);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Creates a new strategy for multi-buffering on this component.
0N/A * Multi-buffering is useful for rendering performance. This method
0N/A * attempts to create the best strategy available with the number of
0N/A * buffers supplied. It will always create a <code>BufferStrategy</code>
0N/A * with that number of buffers.
0N/A * A page-flipping strategy is attempted first, then a blitting strategy
0N/A * using accelerated buffers. Finally, an unaccelerated blitting
0N/A * strategy is used.
0N/A * <p>
0N/A * Each time this method is called,
0N/A * the existing buffer strategy for this component is discarded.
0N/A * @param numBuffers number of buffers to create, including the front buffer
0N/A * @exception IllegalArgumentException if numBuffers is less than 1.
0N/A * @exception IllegalStateException if the component is not displayable
0N/A * @see #isDisplayable
0N/A * @see Window#getBufferStrategy()
0N/A * @see Canvas#getBufferStrategy()
0N/A * @since 1.4
0N/A */
0N/A void createBufferStrategy(int numBuffers) {
0N/A BufferCapabilities bufferCaps;
0N/A if (numBuffers > 1) {
0N/A // Try to create a page-flipping strategy
0N/A bufferCaps = new BufferCapabilities(new ImageCapabilities(true),
0N/A new ImageCapabilities(true),
0N/A BufferCapabilities.FlipContents.UNDEFINED);
0N/A try {
0N/A createBufferStrategy(numBuffers, bufferCaps);
0N/A return; // Success
0N/A } catch (AWTException e) {
0N/A // Failed
0N/A }
0N/A }
0N/A // Try a blitting (but still accelerated) strategy
0N/A bufferCaps = new BufferCapabilities(new ImageCapabilities(true),
0N/A new ImageCapabilities(true),
0N/A null);
0N/A try {
0N/A createBufferStrategy(numBuffers, bufferCaps);
0N/A return; // Success
0N/A } catch (AWTException e) {
0N/A // Failed
0N/A }
0N/A // Try an unaccelerated blitting strategy
0N/A bufferCaps = new BufferCapabilities(new ImageCapabilities(false),
0N/A new ImageCapabilities(false),
0N/A null);
0N/A try {
0N/A createBufferStrategy(numBuffers, bufferCaps);
0N/A return; // Success
0N/A } catch (AWTException e) {
0N/A // Failed
0N/A }
0N/A // Code should never reach here (an unaccelerated blitting
0N/A // strategy should always work)
0N/A throw new InternalError("Could not create a buffer strategy");
0N/A }
0N/A
0N/A /**
0N/A * Creates a new strategy for multi-buffering on this component with the
0N/A * required buffer capabilities. This is useful, for example, if only
0N/A * accelerated memory or page flipping is desired (as specified by the
0N/A * buffer capabilities).
0N/A * <p>
0N/A * Each time this method
0N/A * is called, <code>dispose</code> will be invoked on the existing
0N/A * <code>BufferStrategy</code>.
0N/A * @param numBuffers number of buffers to create
0N/A * @param caps the required capabilities for creating the buffer strategy;
0N/A * cannot be <code>null</code>
0N/A * @exception AWTException if the capabilities supplied could not be
0N/A * supported or met; this may happen, for example, if there is not enough
0N/A * accelerated memory currently available, or if page flipping is specified
0N/A * but not possible.
0N/A * @exception IllegalArgumentException if numBuffers is less than 1, or if
0N/A * caps is <code>null</code>
0N/A * @see Window#getBufferStrategy()
0N/A * @see Canvas#getBufferStrategy()
0N/A * @since 1.4
0N/A */
0N/A void createBufferStrategy(int numBuffers,
0N/A BufferCapabilities caps) throws AWTException {
0N/A // Check arguments
0N/A if (numBuffers < 1) {
0N/A throw new IllegalArgumentException(
0N/A "Number of buffers must be at least 1");
0N/A }
0N/A if (caps == null) {
0N/A throw new IllegalArgumentException("No capabilities specified");
0N/A }
0N/A // Destroy old buffers
0N/A if (bufferStrategy != null) {
0N/A bufferStrategy.dispose();
0N/A }
0N/A if (numBuffers == 1) {
0N/A bufferStrategy = new SingleBufferStrategy(caps);
0N/A } else {
0N/A // assert numBuffers > 1;
0N/A if (caps.isPageFlipping()) {
0N/A bufferStrategy = new FlipSubRegionBufferStrategy(numBuffers, caps);
0N/A } else {
0N/A bufferStrategy = new BltSubRegionBufferStrategy(numBuffers, caps);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * @return the buffer strategy used by this component
0N/A * @see Window#createBufferStrategy
0N/A * @see Canvas#createBufferStrategy
0N/A * @since 1.4
0N/A */
0N/A BufferStrategy getBufferStrategy() {
0N/A return bufferStrategy;
0N/A }
0N/A
0N/A /**
0N/A * @return the back buffer currently used by this component's
0N/A * BufferStrategy. If there is no BufferStrategy or no
0N/A * back buffer, this method returns null.
0N/A */
0N/A Image getBackBuffer() {
0N/A if (bufferStrategy != null) {
0N/A if (bufferStrategy instanceof BltBufferStrategy) {
0N/A BltBufferStrategy bltBS = (BltBufferStrategy)bufferStrategy;
0N/A return bltBS.getBackBuffer();
0N/A } else if (bufferStrategy instanceof FlipBufferStrategy) {
0N/A FlipBufferStrategy flipBS = (FlipBufferStrategy)bufferStrategy;
0N/A return flipBS.getBackBuffer();
0N/A }
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Inner class for flipping buffers on a component. That component must
0N/A * be a <code>Canvas</code> or <code>Window</code>.
0N/A * @see Canvas
0N/A * @see Window
0N/A * @see java.awt.image.BufferStrategy
0N/A * @author Michael Martak
0N/A * @since 1.4
0N/A */
0N/A protected class FlipBufferStrategy extends BufferStrategy {
0N/A /**
0N/A * The number of buffers
0N/A */
0N/A protected int numBuffers; // = 0
0N/A /**
0N/A * The buffering capabilities
0N/A */
0N/A protected BufferCapabilities caps; // = null
0N/A /**
0N/A * The drawing buffer
0N/A */
0N/A protected Image drawBuffer; // = null
0N/A /**
0N/A * The drawing buffer as a volatile image
0N/A */
0N/A protected VolatileImage drawVBuffer; // = null
0N/A /**
0N/A * Whether or not the drawing buffer has been recently restored from
0N/A * a lost state.
0N/A */
0N/A protected boolean validatedContents; // = false
0N/A /**
0N/A * Size of the back buffers. (Note: these fields were added in 6.0
0N/A * but kept package-private to avoid exposing them in the spec.
0N/A * None of these fields/methods really should have been marked
0N/A * protected when they were introduced in 1.4, but now we just have
0N/A * to live with that decision.)
0N/A */
0N/A int width;
0N/A int height;
0N/A
0N/A /**
0N/A * Creates a new flipping buffer strategy for this component.
0N/A * The component must be a <code>Canvas</code> or <code>Window</code>.
0N/A * @see Canvas
0N/A * @see Window
0N/A * @param numBuffers the number of buffers
0N/A * @param caps the capabilities of the buffers
0N/A * @exception AWTException if the capabilities supplied could not be
0N/A * supported or met
0N/A * @exception ClassCastException if the component is not a canvas or
0N/A * window.
0N/A */
0N/A protected FlipBufferStrategy(int numBuffers, BufferCapabilities caps)
0N/A throws AWTException
0N/A {
0N/A if (!(Component.this instanceof Window) &&
0N/A !(Component.this instanceof Canvas))
0N/A {
0N/A throw new ClassCastException(
0N/A "Component must be a Canvas or Window");
0N/A }
0N/A this.numBuffers = numBuffers;
0N/A this.caps = caps;
0N/A createBuffers(numBuffers, caps);
0N/A }
0N/A
0N/A /**
0N/A * Creates one or more complex, flipping buffers with the given
0N/A * capabilities.
0N/A * @param numBuffers number of buffers to create; must be greater than
0N/A * one
0N/A * @param caps the capabilities of the buffers.
0N/A * <code>BufferCapabilities.isPageFlipping</code> must be
0N/A * <code>true</code>.
0N/A * @exception AWTException if the capabilities supplied could not be
0N/A * supported or met
0N/A * @exception IllegalStateException if the component has no peer
0N/A * @exception IllegalArgumentException if numBuffers is less than two,
0N/A * or if <code>BufferCapabilities.isPageFlipping</code> is not
0N/A * <code>true</code>.
0N/A * @see java.awt.BufferCapabilities#isPageFlipping()
0N/A */
0N/A protected void createBuffers(int numBuffers, BufferCapabilities caps)
0N/A throws AWTException
0N/A {
0N/A if (numBuffers < 2) {
0N/A throw new IllegalArgumentException(
0N/A "Number of buffers cannot be less than two");
0N/A } else if (peer == null) {
0N/A throw new IllegalStateException(
0N/A "Component must have a valid peer");
0N/A } else if (caps == null || !caps.isPageFlipping()) {
0N/A throw new IllegalArgumentException(
0N/A "Page flipping capabilities must be specified");
0N/A }
0N/A
0N/A // save the current bounds
0N/A width = getWidth();
0N/A height = getHeight();
0N/A
0N/A if (drawBuffer == null) {
0N/A peer.createBuffers(numBuffers, caps);
0N/A } else {
0N/A // dispose the existing backbuffers
0N/A drawBuffer = null;
0N/A drawVBuffer = null;
0N/A destroyBuffers();
0N/A // ... then recreate the backbuffers
0N/A peer.createBuffers(numBuffers, caps);
0N/A }
0N/A updateInternalBuffers();
0N/A }
0N/A
0N/A /**
0N/A * Updates internal buffers (both volatile and non-volatile)
0N/A * by requesting the back-buffer from the peer.
0N/A */
0N/A private void updateInternalBuffers() {
0N/A // get the images associated with the draw buffer
0N/A drawBuffer = getBackBuffer();
0N/A if (drawBuffer instanceof VolatileImage) {
0N/A drawVBuffer = (VolatileImage)drawBuffer;
0N/A } else {
0N/A drawVBuffer = null;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * @return direct access to the back buffer, as an image.
0N/A * @exception IllegalStateException if the buffers have not yet
0N/A * been created
0N/A */
0N/A protected Image getBackBuffer() {
0N/A if (peer != null) {
0N/A return peer.getBackBuffer();
0N/A } else {
0N/A throw new IllegalStateException(
0N/A "Component must have a valid peer");
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Flipping moves the contents of the back buffer to the front buffer,
0N/A * either by copying or by moving the video pointer.
0N/A * @param flipAction an integer value describing the flipping action
0N/A * for the contents of the back buffer. This should be one of the
0N/A * values of the <code>BufferCapabilities.FlipContents</code>
0N/A * property.
0N/A * @exception IllegalStateException if the buffers have not yet
0N/A * been created
0N/A * @see java.awt.BufferCapabilities#getFlipContents()
0N/A */
0N/A protected void flip(BufferCapabilities.FlipContents flipAction) {
0N/A if (peer != null) {
0N/A peer.flip(flipAction);
0N/A } else {
0N/A throw new IllegalStateException(
0N/A "Component must have a valid peer");
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Destroys the buffers created through this object
0N/A */
0N/A protected void destroyBuffers() {
0N/A if (peer != null) {
0N/A peer.destroyBuffers();
0N/A } else {
0N/A throw new IllegalStateException(
0N/A "Component must have a valid peer");
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * @return the buffering capabilities of this strategy
0N/A */
0N/A public BufferCapabilities getCapabilities() {
0N/A return caps;
0N/A }
0N/A
0N/A /**
0N/A * @return the graphics on the drawing buffer. This method may not
0N/A * be synchronized for performance reasons; use of this method by multiple
0N/A * threads should be handled at the application level. Disposal of the
0N/A * graphics object must be handled by the application.
0N/A */
0N/A public Graphics getDrawGraphics() {
0N/A revalidate();
0N/A return drawBuffer.getGraphics();
0N/A }
0N/A
0N/A /**
0N/A * Restore the drawing buffer if it has been lost
0N/A */
0N/A protected void revalidate() {
0N/A revalidate(true);
0N/A }
0N/A
0N/A void revalidate(boolean checkSize) {
0N/A validatedContents = false;
0N/A
0N/A if (checkSize && (getWidth() != width || getHeight() != height)) {
0N/A // component has been resized; recreate the backbuffers
0N/A try {
0N/A createBuffers(numBuffers, caps);
0N/A } catch (AWTException e) {
0N/A // shouldn't be possible
0N/A }
0N/A validatedContents = true;
0N/A }
0N/A
0N/A // get the buffers from the peer every time since they
0N/A // might have been replaced in response to a display change event
0N/A updateInternalBuffers();
0N/A
0N/A // now validate the backbuffer
0N/A if (drawVBuffer != null) {
0N/A GraphicsConfiguration gc =
0N/A getGraphicsConfiguration_NoClientCode();
0N/A int returnCode = drawVBuffer.validate(gc);
0N/A if (returnCode == VolatileImage.IMAGE_INCOMPATIBLE) {
0N/A try {
0N/A createBuffers(numBuffers, caps);
0N/A } catch (AWTException e) {
0N/A // shouldn't be possible
0N/A }
0N/A if (drawVBuffer != null) {
0N/A // backbuffers were recreated, so validate again
0N/A drawVBuffer.validate(gc);
0N/A }
0N/A validatedContents = true;
0N/A } else if (returnCode == VolatileImage.IMAGE_RESTORED) {
0N/A validatedContents = true;
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * @return whether the drawing buffer was lost since the last call to
0N/A * <code>getDrawGraphics</code>
0N/A */
0N/A public boolean contentsLost() {
0N/A if (drawVBuffer == null) {
0N/A return false;
0N/A }
0N/A return drawVBuffer.contentsLost();
0N/A }
0N/A
0N/A /**
0N/A * @return whether the drawing buffer was recently restored from a lost
0N/A * state and reinitialized to the default background color (white)
0N/A */
0N/A public boolean contentsRestored() {
0N/A return validatedContents;
0N/A }
0N/A
0N/A /**
0N/A * Makes the next available buffer visible by either blitting or
0N/A * flipping.
0N/A */
0N/A public void show() {
0N/A flip(caps.getFlipContents());
0N/A }
0N/A
0N/A /**
0N/A * {@inheritDoc}
0N/A * @since 1.6
0N/A */
0N/A public void dispose() {
0N/A if (Component.this.bufferStrategy == this) {
0N/A Component.this.bufferStrategy = null;
0N/A if (peer != null) {
0N/A destroyBuffers();
0N/A }
0N/A }
0N/A }
0N/A
0N/A } // Inner class FlipBufferStrategy
0N/A
0N/A /**
0N/A * Inner class for blitting offscreen surfaces to a component.
0N/A *
0N/A * @author Michael Martak
0N/A * @since 1.4
0N/A */
0N/A protected class BltBufferStrategy extends BufferStrategy {
0N/A
0N/A /**
0N/A * The buffering capabilities
0N/A */
0N/A protected BufferCapabilities caps; // = null
0N/A /**
0N/A * The back buffers
0N/A */
0N/A protected VolatileImage[] backBuffers; // = null
0N/A /**
0N/A * Whether or not the drawing buffer has been recently restored from
0N/A * a lost state.
0N/A */
0N/A protected boolean validatedContents; // = false
0N/A /**
0N/A * Size of the back buffers
0N/A */
0N/A protected int width;
0N/A protected int height;
0N/A
0N/A /**
0N/A * Insets for the hosting Component. The size of the back buffer
0N/A * is constrained by these.
0N/A */
0N/A private Insets insets;
0N/A
0N/A /**
0N/A * Creates a new blt buffer strategy around a component
0N/A * @param numBuffers number of buffers to create, including the
0N/A * front buffer
0N/A * @param caps the capabilities of the buffers
0N/A */
0N/A protected BltBufferStrategy(int numBuffers, BufferCapabilities caps) {
0N/A this.caps = caps;
0N/A createBackBuffers(numBuffers - 1);
0N/A }
0N/A
0N/A /**
0N/A * {@inheritDoc}
0N/A * @since 1.6
0N/A */
0N/A public void dispose() {
0N/A if (backBuffers != null) {
0N/A for (int counter = backBuffers.length - 1; counter >= 0;
0N/A counter--) {
0N/A if (backBuffers[counter] != null) {
0N/A backBuffers[counter].flush();
0N/A backBuffers[counter] = null;
0N/A }
0N/A }
0N/A }
0N/A if (Component.this.bufferStrategy == this) {
0N/A Component.this.bufferStrategy = null;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Creates the back buffers
0N/A */
0N/A protected void createBackBuffers(int numBuffers) {
0N/A if (numBuffers == 0) {
0N/A backBuffers = null;
0N/A } else {
0N/A // save the current bounds
0N/A width = getWidth();
0N/A height = getHeight();
0N/A insets = getInsets_NoClientCode();
0N/A int iWidth = width - insets.left - insets.right;
0N/A int iHeight = height - insets.top - insets.bottom;
0N/A
0N/A // It is possible for the component's width and/or height
0N/A // to be 0 here. Force the size of the backbuffers to
0N/A // be > 0 so that creating the image won't fail.
0N/A iWidth = Math.max(1, iWidth);
0N/A iHeight = Math.max(1, iHeight);
0N/A if (backBuffers == null) {
0N/A backBuffers = new VolatileImage[numBuffers];
0N/A } else {
0N/A // flush any existing backbuffers
0N/A for (int i = 0; i < numBuffers; i++) {
0N/A if (backBuffers[i] != null) {
0N/A backBuffers[i].flush();
0N/A backBuffers[i] = null;
0N/A }
0N/A }
0N/A }
0N/A
0N/A // create the backbuffers
0N/A for (int i = 0; i < numBuffers; i++) {
0N/A backBuffers[i] = createVolatileImage(iWidth, iHeight);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * @return the buffering capabilities of this strategy
0N/A */
0N/A public BufferCapabilities getCapabilities() {
0N/A return caps;
0N/A }
0N/A
0N/A /**
0N/A * @return the draw graphics
0N/A */
0N/A public Graphics getDrawGraphics() {
0N/A revalidate();
0N/A Image backBuffer = getBackBuffer();
0N/A if (backBuffer == null) {
0N/A return getGraphics();
0N/A }
0N/A SunGraphics2D g = (SunGraphics2D)backBuffer.getGraphics();
0N/A g.constrain(-insets.left, -insets.top,
0N/A backBuffer.getWidth(null) + insets.left,
0N/A backBuffer.getHeight(null) + insets.top);
0N/A return g;
0N/A }
0N/A
0N/A /**
0N/A * @return direct access to the back buffer, as an image.
0N/A * If there is no back buffer, returns null.
0N/A */
0N/A Image getBackBuffer() {
0N/A if (backBuffers != null) {
0N/A return backBuffers[backBuffers.length - 1];
0N/A } else {
0N/A return null;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Makes the next available buffer visible.
0N/A */
0N/A public void show() {
0N/A showSubRegion(insets.left, insets.top,
0N/A width - insets.right,
0N/A height - insets.bottom);
0N/A }
0N/A
0N/A /**
0N/A * Package-private method to present a specific rectangular area
0N/A * of this buffer. This class currently shows only the entire
0N/A * buffer, by calling showSubRegion() with the full dimensions of
0N/A * the buffer. Subclasses (e.g., BltSubRegionBufferStrategy
0N/A * and FlipSubRegionBufferStrategy) may have region-specific show
0N/A * methods that call this method with actual sub regions of the
0N/A * buffer.
0N/A */
0N/A void showSubRegion(int x1, int y1, int x2, int y2) {
0N/A if (backBuffers == null) {
0N/A return;
0N/A }
0N/A // Adjust location to be relative to client area.
0N/A x1 -= insets.left;
0N/A x2 -= insets.left;
0N/A y1 -= insets.top;
0N/A y2 -= insets.top;
0N/A Graphics g = getGraphics_NoClientCode();
0N/A if (g == null) {
0N/A // Not showing, bail
0N/A return;
0N/A }
0N/A try {
0N/A // First image copy is in terms of Frame's coordinates, need
0N/A // to translate to client area.
0N/A g.translate(insets.left, insets.top);
0N/A for (int i = 0; i < backBuffers.length; i++) {
0N/A g.drawImage(backBuffers[i],
0N/A x1, y1, x2, y2,
0N/A x1, y1, x2, y2,
0N/A null);
0N/A g.dispose();
0N/A g = null;
0N/A g = backBuffers[i].getGraphics();
0N/A }
0N/A } finally {
0N/A if (g != null) {
0N/A g.dispose();
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Restore the drawing buffer if it has been lost
0N/A */
0N/A protected void revalidate() {
0N/A revalidate(true);
0N/A }
0N/A
0N/A void revalidate(boolean checkSize) {
0N/A validatedContents = false;
0N/A
0N/A if (backBuffers == null) {
0N/A return;
0N/A }
0N/A
0N/A if (checkSize) {
0N/A Insets insets = getInsets_NoClientCode();
0N/A if (getWidth() != width || getHeight() != height ||
0N/A !insets.equals(this.insets)) {
0N/A // component has been resized; recreate the backbuffers
0N/A createBackBuffers(backBuffers.length);
0N/A validatedContents = true;
0N/A }
0N/A }
0N/A
0N/A // now validate the backbuffer
0N/A GraphicsConfiguration gc = getGraphicsConfiguration_NoClientCode();
0N/A int returnCode =
0N/A backBuffers[backBuffers.length - 1].validate(gc);
0N/A if (returnCode == VolatileImage.IMAGE_INCOMPATIBLE) {
0N/A if (checkSize) {
0N/A createBackBuffers(backBuffers.length);
0N/A // backbuffers were recreated, so validate again
0N/A backBuffers[backBuffers.length - 1].validate(gc);
0N/A }
0N/A // else case means we're called from Swing on the toolkit
0N/A // thread, don't recreate buffers as that'll deadlock
0N/A // (creating VolatileImages invokes getting GraphicsConfig
0N/A // which grabs treelock).
0N/A validatedContents = true;
0N/A } else if (returnCode == VolatileImage.IMAGE_RESTORED) {
0N/A validatedContents = true;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * @return whether the drawing buffer was lost since the last call to
0N/A * <code>getDrawGraphics</code>
0N/A */
0N/A public boolean contentsLost() {
0N/A if (backBuffers == null) {
0N/A return false;
0N/A } else {
0N/A return backBuffers[backBuffers.length - 1].contentsLost();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * @return whether the drawing buffer was recently restored from a lost
0N/A * state and reinitialized to the default background color (white)
0N/A */
0N/A public boolean contentsRestored() {
0N/A return validatedContents;
0N/A }
0N/A } // Inner class BltBufferStrategy
0N/A
0N/A /**
0N/A * Private class to perform sub-region flipping.
0N/A * REMIND: this subclass currently punts on subregions and
0N/A * flips the entire buffer.
0N/A */
0N/A private class FlipSubRegionBufferStrategy extends FlipBufferStrategy
0N/A implements SubRegionShowable
0N/A {
0N/A
0N/A protected FlipSubRegionBufferStrategy(int numBuffers,
0N/A BufferCapabilities caps)
0N/A throws AWTException
0N/A {
0N/A super(numBuffers, caps);
0N/A }
0N/A
0N/A public void show(int x1, int y1, int x2, int y2) {
0N/A show();
0N/A }
0N/A
0N/A // This is invoked by Swing on the toolkit thread.
0N/A public boolean validateAndShow(int x1, int y1, int x2, int y2) {
0N/A revalidate(false);
0N/A if (!contentsRestored() && !contentsLost()) {
0N/A show();
0N/A return !contentsLost();
0N/A }
0N/A return false;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Private class to perform sub-region blitting. Swing will use
0N/A * this subclass via the SubRegionShowable interface in order to
0N/A * copy only the area changed during a repaint.
0N/A * @see javax.swing.BufferStrategyPaintManager
0N/A */
0N/A private class BltSubRegionBufferStrategy extends BltBufferStrategy
0N/A implements SubRegionShowable
0N/A {
0N/A
0N/A protected BltSubRegionBufferStrategy(int numBuffers,
0N/A BufferCapabilities caps)
0N/A {
0N/A super(numBuffers, caps);
0N/A }
0N/A
0N/A public void show(int x1, int y1, int x2, int y2) {
0N/A showSubRegion(x1, y1, x2, y2);
0N/A }
0N/A
0N/A // This method is called by Swing on the toolkit thread.
0N/A public boolean validateAndShow(int x1, int y1, int x2, int y2) {
0N/A revalidate(false);
0N/A if (!contentsRestored() && !contentsLost()) {
0N/A showSubRegion(x1, y1, x2, y2);
0N/A return !contentsLost();
0N/A }
0N/A return false;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Inner class for flipping buffers on a component. That component must
0N/A * be a <code>Canvas</code> or <code>Window</code>.
0N/A * @see Canvas
0N/A * @see Window
0N/A * @see java.awt.image.BufferStrategy
0N/A * @author Michael Martak
0N/A * @since 1.4
0N/A */
0N/A private class SingleBufferStrategy extends BufferStrategy {
0N/A
0N/A private BufferCapabilities caps;
0N/A
0N/A public SingleBufferStrategy(BufferCapabilities caps) {
0N/A this.caps = caps;
0N/A }
0N/A public BufferCapabilities getCapabilities() {
0N/A return caps;
0N/A }
0N/A public Graphics getDrawGraphics() {
0N/A return getGraphics();
0N/A }
0N/A public boolean contentsLost() {
0N/A return false;
0N/A }
0N/A public boolean contentsRestored() {
0N/A return false;
0N/A }
0N/A public void show() {
0N/A // Do nothing
0N/A }
0N/A } // Inner class SingleBufferStrategy
0N/A
0N/A /**
0N/A * Sets whether or not paint messages received from the operating system
0N/A * should be ignored. This does not affect paint events generated in
0N/A * software by the AWT, unless they are an immediate response to an
0N/A * OS-level paint message.
0N/A * <p>
0N/A * This is useful, for example, if running under full-screen mode and
0N/A * better performance is desired, or if page-flipping is used as the
0N/A * buffer strategy.
0N/A *
0N/A * @since 1.4
0N/A * @see #getIgnoreRepaint
0N/A * @see Canvas#createBufferStrategy
0N/A * @see Window#createBufferStrategy
0N/A * @see java.awt.image.BufferStrategy
0N/A * @see GraphicsDevice#setFullScreenWindow
0N/A */
0N/A public void setIgnoreRepaint(boolean ignoreRepaint) {
0N/A this.ignoreRepaint = ignoreRepaint;
0N/A }
0N/A
0N/A /**
0N/A * @return whether or not paint messages received from the operating system
0N/A * should be ignored.
0N/A *
0N/A * @since 1.4
0N/A * @see #setIgnoreRepaint
0N/A */
0N/A public boolean getIgnoreRepaint() {
0N/A return ignoreRepaint;
0N/A }
0N/A
0N/A /**
0N/A * Checks whether this component "contains" the specified point,
0N/A * where <code>x</code> and <code>y</code> are defined to be
0N/A * relative to the coordinate system of this component.
0N/A * @param x the <i>x</i> coordinate of the point
0N/A * @param y the <i>y</i> coordinate of the point
0N/A * @see #getComponentAt(int, int)
0N/A * @since JDK1.1
0N/A */
0N/A public boolean contains(int x, int y) {
0N/A return inside(x, y);
0N/A }
0N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1,
0N/A * replaced by contains(int, int).
0N/A */
0N/A @Deprecated
0N/A public boolean inside(int x, int y) {
0N/A return (x >= 0) && (x < width) && (y >= 0) && (y < height);
0N/A }
0N/A
0N/A /**
0N/A * Checks whether this component "contains" the specified point,
0N/A * where the point's <i>x</i> and <i>y</i> coordinates are defined
0N/A * to be relative to the coordinate system of this component.
0N/A * @param p the point
0N/A * @see #getComponentAt(Point)
0N/A * @since JDK1.1
0N/A */
0N/A public boolean contains(Point p) {
0N/A return contains(p.x, p.y);
0N/A }
0N/A
0N/A /**
0N/A * Determines if this component or one of its immediate
0N/A * subcomponents contains the (<i>x</i>,&nbsp;<i>y</i>) location,
0N/A * and if so, returns the containing component. This method only
0N/A * looks one level deep. If the point (<i>x</i>,&nbsp;<i>y</i>) is
0N/A * inside a subcomponent that itself has subcomponents, it does not
0N/A * go looking down the subcomponent tree.
0N/A * <p>
0N/A * The <code>locate</code> method of <code>Component</code> simply
0N/A * returns the component itself if the (<i>x</i>,&nbsp;<i>y</i>)
0N/A * coordinate location is inside its bounding box, and <code>null</code>
0N/A * otherwise.
0N/A * @param x the <i>x</i> coordinate
0N/A * @param y the <i>y</i> coordinate
0N/A * @return the component or subcomponent that contains the
0N/A * (<i>x</i>,&nbsp;<i>y</i>) location;
0N/A * <code>null</code> if the location
0N/A * is outside this component
0N/A * @see #contains(int, int)
0N/A * @since JDK1.0
0N/A */
0N/A public Component getComponentAt(int x, int y) {
0N/A return locate(x, y);
0N/A }
0N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1,
0N/A * replaced by getComponentAt(int, int).
0N/A */
0N/A @Deprecated
0N/A public Component locate(int x, int y) {
0N/A return contains(x, y) ? this : null;
0N/A }
0N/A
0N/A /**
0N/A * Returns the component or subcomponent that contains the
0N/A * specified point.
0N/A * @param p the point
0N/A * @see java.awt.Component#contains
0N/A * @since JDK1.1
0N/A */
0N/A public Component getComponentAt(Point p) {
0N/A return getComponentAt(p.x, p.y);
0N/A }
0N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1,
0N/A * replaced by <code>dispatchEvent(AWTEvent e)</code>.
0N/A */
0N/A @Deprecated
0N/A public void deliverEvent(Event e) {
0N/A postEvent(e);
0N/A }
0N/A
0N/A /**
0N/A * Dispatches an event to this component or one of its sub components.
0N/A * Calls <code>processEvent</code> before returning for 1.1-style
0N/A * events which have been enabled for the <code>Component</code>.
0N/A * @param e the event
0N/A */
0N/A public final void dispatchEvent(AWTEvent e) {
0N/A dispatchEventImpl(e);
0N/A }
0N/A
0N/A void dispatchEventImpl(AWTEvent e) {
0N/A int id = e.getID();
0N/A
0N/A // Check that this component belongs to this app-context
0N/A AppContext compContext = appContext;
0N/A if (compContext != null && !compContext.equals(AppContext.getAppContext())) {
0N/A if (eventLog.isLoggable(Level.FINE)) {
0N/A eventLog.log(Level.FINE, "Event " + e + " is being dispatched on the wrong AppContext");
0N/A }
0N/A }
0N/A
0N/A if (eventLog.isLoggable(Level.FINEST)) {
0N/A eventLog.log(Level.FINEST, "{0}", e);
0N/A }
0N/A
0N/A /*
0N/A * 0. Set timestamp and modifiers of current event.
0N/A */
0N/A EventQueue.setCurrentEventAndMostRecentTime(e);
0N/A
0N/A /*
0N/A * 1. Pre-dispatchers. Do any necessary retargeting/reordering here
0N/A * before we notify AWTEventListeners.
0N/A */
0N/A
0N/A if (e instanceof SunDropTargetEvent) {
0N/A ((SunDropTargetEvent)e).dispatch();
0N/A return;
0N/A }
0N/A
0N/A if (!e.focusManagerIsDispatching) {
0N/A // Invoke the private focus retargeting method which provides
0N/A // lightweight Component support
0N/A if (e.isPosted) {
0N/A e = KeyboardFocusManager.retargetFocusEvent(e);
0N/A e.isPosted = true;
0N/A }
0N/A
0N/A // Now, with the event properly targeted to a lightweight
0N/A // descendant if necessary, invoke the public focus retargeting
0N/A // and dispatching function
0N/A if (KeyboardFocusManager.getCurrentKeyboardFocusManager().
0N/A dispatchEvent(e))
0N/A {
0N/A return;
0N/A }
0N/A }
0N/A if ((e instanceof FocusEvent) && focusLog.isLoggable(Level.FINEST)) {
0N/A focusLog.log(Level.FINEST, "" + e);
0N/A }
0N/A // MouseWheel may need to be retargeted here so that
0N/A // AWTEventListener sees the event go to the correct
0N/A // Component. If the MouseWheelEvent needs to go to an ancestor,
0N/A // the event is dispatched to the ancestor, and dispatching here
0N/A // stops.
0N/A if (id == MouseEvent.MOUSE_WHEEL &&
0N/A (!eventTypeEnabled(id)) &&
0N/A (peer != null && !peer.handlesWheelScrolling()) &&
0N/A (dispatchMouseWheelToAncestor((MouseWheelEvent)e)))
0N/A {
0N/A return;
0N/A }
0N/A
0N/A /*
0N/A * 2. Allow the Toolkit to pass this to AWTEventListeners.
0N/A */
0N/A Toolkit toolkit = Toolkit.getDefaultToolkit();
0N/A toolkit.notifyAWTEventListeners(e);
0N/A
0N/A
0N/A /*
0N/A * 3. If no one has consumed a key event, allow the
0N/A * KeyboardFocusManager to process it.
0N/A */
0N/A if (!e.isConsumed()) {
0N/A if (e instanceof java.awt.event.KeyEvent) {
0N/A KeyboardFocusManager.getCurrentKeyboardFocusManager().
0N/A processKeyEvent(this, (KeyEvent)e);
0N/A if (e.isConsumed()) {
0N/A return;
0N/A }
0N/A }
0N/A }
0N/A
0N/A /*
0N/A * 4. Allow input methods to process the event
0N/A */
0N/A if (areInputMethodsEnabled()) {
0N/A // We need to pass on InputMethodEvents since some host
0N/A // input method adapters send them through the Java
0N/A // event queue instead of directly to the component,
0N/A // and the input context also handles the Java composition window
0N/A if(((e instanceof InputMethodEvent) && !(this instanceof CompositionArea))
0N/A ||
0N/A // Otherwise, we only pass on input and focus events, because
0N/A // a) input methods shouldn't know about semantic or component-level events
0N/A // b) passing on the events takes time
0N/A // c) isConsumed() is always true for semantic events.
0N/A (e instanceof InputEvent) || (e instanceof FocusEvent)) {
0N/A InputContext inputContext = getInputContext();
0N/A
0N/A
0N/A if (inputContext != null) {
0N/A inputContext.dispatchEvent(e);
0N/A if (e.isConsumed()) {
0N/A if ((e instanceof FocusEvent) && focusLog.isLoggable(Level.FINEST)) {
0N/A focusLog.log(Level.FINEST, "3579: Skipping " + e);
0N/A }
0N/A return;
0N/A }
0N/A }
0N/A }
0N/A } else {
0N/A // When non-clients get focus, we need to explicitly disable the native
0N/A // input method. The native input method is actually not disabled when
0N/A // the active/passive/peered clients loose focus.
0N/A if (id == FocusEvent.FOCUS_GAINED) {
0N/A InputContext inputContext = getInputContext();
0N/A if (inputContext != null && inputContext instanceof sun.awt.im.InputContext) {
0N/A ((sun.awt.im.InputContext)inputContext).disableNativeIM();
0N/A }
0N/A }
0N/A }
0N/A
0N/A
0N/A /*
0N/A * 5. Pre-process any special events before delivery
0N/A */
0N/A switch(id) {
0N/A // Handling of the PAINT and UPDATE events is now done in the
0N/A // peer's handleEvent() method so the background can be cleared
0N/A // selectively for non-native components on Windows only.
0N/A // - Fred.Ecks@Eng.sun.com, 5-8-98
0N/A
0N/A case KeyEvent.KEY_PRESSED:
0N/A case KeyEvent.KEY_RELEASED:
0N/A Container p = (Container)((this instanceof Container) ? this : parent);
0N/A if (p != null) {
0N/A p.preProcessKeyEvent((KeyEvent)e);
0N/A if (e.isConsumed()) {
0N/A if (focusLog.isLoggable(Level.FINEST)) {
0N/A focusLog.log(Level.FINEST, "Pre-process consumed event");
0N/A }
0N/A return;
0N/A }
0N/A }
0N/A break;
0N/A
0N/A case WindowEvent.WINDOW_CLOSING:
0N/A if (toolkit instanceof WindowClosingListener) {
0N/A windowClosingException = ((WindowClosingListener)
0N/A toolkit).windowClosingNotify((WindowEvent)e);
0N/A if (checkWindowClosingException()) {
0N/A return;
0N/A }
0N/A }
0N/A break;
0N/A
0N/A default:
0N/A break;
0N/A }
0N/A
0N/A /*
0N/A * 6. Deliver event for normal processing
0N/A */
0N/A if (newEventsOnly) {
0N/A // Filtering needs to really be moved to happen at a lower
0N/A // level in order to get maximum performance gain; it is
0N/A // here temporarily to ensure the API spec is honored.
0N/A //
0N/A if (eventEnabled(e)) {
0N/A processEvent(e);
0N/A }
0N/A } else if (id == MouseEvent.MOUSE_WHEEL) {
0N/A // newEventsOnly will be false for a listenerless ScrollPane, but
0N/A // MouseWheelEvents still need to be dispatched to it so scrolling
0N/A // can be done.
0N/A autoProcessMouseWheel((MouseWheelEvent)e);
0N/A } else if (!(e instanceof MouseEvent && !postsOldMouseEvents())) {
0N/A //
0N/A // backward compatibility
0N/A //
0N/A Event olde = e.convertToOld();
0N/A if (olde != null) {
0N/A int key = olde.key;
0N/A int modifiers = olde.modifiers;
0N/A
0N/A postEvent(olde);
0N/A if (olde.isConsumed()) {
0N/A e.consume();
0N/A }
0N/A // if target changed key or modifier values, copy them
0N/A // back to original event
0N/A //
0N/A switch(olde.id) {
0N/A case Event.KEY_PRESS:
0N/A case Event.KEY_RELEASE:
0N/A case Event.KEY_ACTION:
0N/A case Event.KEY_ACTION_RELEASE:
0N/A if (olde.key != key) {
0N/A ((KeyEvent)e).setKeyChar(olde.getKeyEventChar());
0N/A }
0N/A if (olde.modifiers != modifiers) {
0N/A ((KeyEvent)e).setModifiers(olde.modifiers);
0N/A }
0N/A break;
0N/A default:
0N/A break;
0N/A }
0N/A }
0N/A }
0N/A
0N/A /*
0N/A * 8. Special handling for 4061116 : Hook for browser to close modal
0N/A * dialogs.
0N/A */
0N/A if (id == WindowEvent.WINDOW_CLOSING && !e.isConsumed()) {
0N/A if (toolkit instanceof WindowClosingListener) {
0N/A windowClosingException =
0N/A ((WindowClosingListener)toolkit).
0N/A windowClosingDelivered((WindowEvent)e);
0N/A if (checkWindowClosingException()) {
0N/A return;
0N/A }
0N/A }
0N/A }
0N/A
0N/A /*
0N/A * 9. Allow the peer to process the event.
0N/A * Except KeyEvents, they will be processed by peer after
0N/A * all KeyEventPostProcessors
0N/A * (see DefaultKeyboardFocusManager.dispatchKeyEvent())
0N/A */
0N/A if (!(e instanceof KeyEvent)) {
0N/A ComponentPeer tpeer = peer;
0N/A if (e instanceof FocusEvent && (tpeer == null || tpeer instanceof LightweightPeer)) {
0N/A // if focus owner is lightweight then its native container
0N/A // processes event
0N/A Component source = (Component)e.getSource();
0N/A if (source != null) {
0N/A Container target = source.getNativeContainer();
0N/A if (target != null) {
0N/A tpeer = target.getPeer();
0N/A }
0N/A }
0N/A }
0N/A if (tpeer != null) {
0N/A tpeer.handleEvent(e);
0N/A }
0N/A }
0N/A } // dispatchEventImpl()
0N/A
0N/A /*
0N/A * If newEventsOnly is false, method is called so that ScrollPane can
0N/A * override it and handle common-case mouse wheel scrolling. NOP
0N/A * for Component.
0N/A */
0N/A void autoProcessMouseWheel(MouseWheelEvent e) {}
0N/A
0N/A /*
0N/A * Dispatch given MouseWheelEvent to the first ancestor for which
0N/A * MouseWheelEvents are enabled.
0N/A *
0N/A * Returns whether or not event was dispatched to an ancestor
0N/A */
0N/A boolean dispatchMouseWheelToAncestor(MouseWheelEvent e) {
0N/A int newX, newY;
0N/A newX = e.getX() + getX(); // Coordinates take into account at least
0N/A newY = e.getY() + getY(); // the cursor's position relative to this
0N/A // Component (e.getX()), and this Component's
0N/A // position relative to its parent.
0N/A MouseWheelEvent newMWE;
0N/A
0N/A if (eventLog.isLoggable(Level.FINEST)) {
0N/A eventLog.log(Level.FINEST, "dispatchMouseWheelToAncestor");
0N/A eventLog.log(Level.FINEST, "orig event src is of " + e.getSource().getClass());
0N/A }
0N/A
0N/A /* parent field for Window refers to the owning Window.
0N/A * MouseWheelEvents should NOT be propagated into owning Windows
0N/A */
0N/A synchronized (getTreeLock()) {
0N/A Container anc = getParent();
0N/A while (anc != null && !anc.eventEnabled(e)) {
0N/A // fix coordinates to be relative to new event source
0N/A newX += anc.getX();
0N/A newY += anc.getY();
0N/A
0N/A if (!(anc instanceof Window)) {
0N/A anc = anc.getParent();
0N/A }
0N/A else {
0N/A break;
0N/A }
0N/A }
0N/A
0N/A if (eventLog.isLoggable(Level.FINEST)) {
0N/A eventLog.log(Level.FINEST, "new event src is " + anc.getClass());
0N/A }
0N/A
0N/A if (anc != null && anc.eventEnabled(e)) {
0N/A // Change event to be from new source, with new x,y
0N/A // For now, just create a new event - yucky
0N/A
0N/A newMWE = new MouseWheelEvent(anc, // new source
0N/A e.getID(),
0N/A e.getWhen(),
0N/A e.getModifiers(),
0N/A newX, // x relative to new source
0N/A newY, // y relative to new source
0N/A e.getXOnScreen(),
0N/A e.getYOnScreen(),
0N/A e.getClickCount(),
0N/A e.isPopupTrigger(),
0N/A e.getScrollType(),
0N/A e.getScrollAmount(),
98N/A e.getWheelRotation(),
98N/A e.getPreciseWheelRotation());
0N/A ((AWTEvent)e).copyPrivateDataInto(newMWE);
0N/A // When dispatching a wheel event to
0N/A // ancestor, there is no need trying to find descendant
0N/A // lightweights to dispatch event to.
0N/A // If we dispatch the event to toplevel ancestor,
0N/A // this could encolse the loop: 6480024.
0N/A anc.dispatchEventToSelf(newMWE);
0N/A }
0N/A }
0N/A return true;
0N/A }
0N/A
0N/A boolean checkWindowClosingException() {
0N/A if (windowClosingException != null) {
0N/A if (this instanceof Dialog) {
0N/A ((Dialog)this).interruptBlocking();
0N/A } else {
0N/A windowClosingException.fillInStackTrace();
0N/A windowClosingException.printStackTrace();
0N/A windowClosingException = null;
0N/A }
0N/A return true;
0N/A }
0N/A return false;
0N/A }
0N/A
0N/A boolean areInputMethodsEnabled() {
0N/A // in 1.2, we assume input method support is required for all
0N/A // components that handle key events, but components can turn off
0N/A // input methods by calling enableInputMethods(false).
0N/A return ((eventMask & AWTEvent.INPUT_METHODS_ENABLED_MASK) != 0) &&
0N/A ((eventMask & AWTEvent.KEY_EVENT_MASK) != 0 || keyListener != null);
0N/A }
0N/A
0N/A // REMIND: remove when filtering is handled at lower level
0N/A boolean eventEnabled(AWTEvent e) {
0N/A return eventTypeEnabled(e.id);
0N/A }
0N/A
0N/A boolean eventTypeEnabled(int type) {
0N/A switch(type) {
0N/A case ComponentEvent.COMPONENT_MOVED:
0N/A case ComponentEvent.COMPONENT_RESIZED:
0N/A case ComponentEvent.COMPONENT_SHOWN:
0N/A case ComponentEvent.COMPONENT_HIDDEN:
0N/A if ((eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 ||
0N/A componentListener != null) {
0N/A return true;
0N/A }
0N/A break;
0N/A case FocusEvent.FOCUS_GAINED:
0N/A case FocusEvent.FOCUS_LOST:
0N/A if ((eventMask & AWTEvent.FOCUS_EVENT_MASK) != 0 ||
0N/A focusListener != null) {
0N/A return true;
0N/A }
0N/A break;
0N/A case KeyEvent.KEY_PRESSED:
0N/A case KeyEvent.KEY_RELEASED:
0N/A case KeyEvent.KEY_TYPED:
0N/A if ((eventMask & AWTEvent.KEY_EVENT_MASK) != 0 ||
0N/A keyListener != null) {
0N/A return true;
0N/A }
0N/A break;
0N/A case MouseEvent.MOUSE_PRESSED:
0N/A case MouseEvent.MOUSE_RELEASED:
0N/A case MouseEvent.MOUSE_ENTERED:
0N/A case MouseEvent.MOUSE_EXITED:
0N/A case MouseEvent.MOUSE_CLICKED:
0N/A if ((eventMask & AWTEvent.MOUSE_EVENT_MASK) != 0 ||
0N/A mouseListener != null) {
0N/A return true;
0N/A }
0N/A break;
0N/A case MouseEvent.MOUSE_MOVED:
0N/A case MouseEvent.MOUSE_DRAGGED:
0N/A if ((eventMask & AWTEvent.MOUSE_MOTION_EVENT_MASK) != 0 ||
0N/A mouseMotionListener != null) {
0N/A return true;
0N/A }
0N/A break;
0N/A case MouseEvent.MOUSE_WHEEL:
0N/A if ((eventMask & AWTEvent.MOUSE_WHEEL_EVENT_MASK) != 0 ||
0N/A mouseWheelListener != null) {
0N/A return true;
0N/A }
0N/A break;
0N/A case InputMethodEvent.INPUT_METHOD_TEXT_CHANGED:
0N/A case InputMethodEvent.CARET_POSITION_CHANGED:
0N/A if ((eventMask & AWTEvent.INPUT_METHOD_EVENT_MASK) != 0 ||
0N/A inputMethodListener != null) {
0N/A return true;
0N/A }
0N/A break;
0N/A case HierarchyEvent.HIERARCHY_CHANGED:
0N/A if ((eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0 ||
0N/A hierarchyListener != null) {
0N/A return true;
0N/A }
0N/A break;
0N/A case HierarchyEvent.ANCESTOR_MOVED:
0N/A case HierarchyEvent.ANCESTOR_RESIZED:
0N/A if ((eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0 ||
0N/A hierarchyBoundsListener != null) {
0N/A return true;
0N/A }
0N/A break;
0N/A case ActionEvent.ACTION_PERFORMED:
0N/A if ((eventMask & AWTEvent.ACTION_EVENT_MASK) != 0) {
0N/A return true;
0N/A }
0N/A break;
0N/A case TextEvent.TEXT_VALUE_CHANGED:
0N/A if ((eventMask & AWTEvent.TEXT_EVENT_MASK) != 0) {
0N/A return true;
0N/A }
0N/A break;
0N/A case ItemEvent.ITEM_STATE_CHANGED:
0N/A if ((eventMask & AWTEvent.ITEM_EVENT_MASK) != 0) {
0N/A return true;
0N/A }
0N/A break;
0N/A case AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED:
0N/A if ((eventMask & AWTEvent.ADJUSTMENT_EVENT_MASK) != 0) {
0N/A return true;
0N/A }
0N/A break;
0N/A default:
0N/A break;
0N/A }
0N/A //
0N/A // Always pass on events defined by external programs.
0N/A //
0N/A if (type > AWTEvent.RESERVED_ID_MAX) {
0N/A return true;
0N/A }
0N/A return false;
0N/A }
0N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1,
0N/A * replaced by dispatchEvent(AWTEvent).
0N/A */
0N/A @Deprecated
0N/A public boolean postEvent(Event e) {
0N/A ComponentPeer peer = this.peer;
0N/A
0N/A if (handleEvent(e)) {
0N/A e.consume();
0N/A return true;
0N/A }
0N/A
0N/A Component parent = this.parent;
0N/A int eventx = e.x;
0N/A int eventy = e.y;
0N/A if (parent != null) {
0N/A e.translate(x, y);
0N/A if (parent.postEvent(e)) {
0N/A e.consume();
0N/A return true;
0N/A }
0N/A // restore coords
0N/A e.x = eventx;
0N/A e.y = eventy;
0N/A }
0N/A return false;
0N/A }
0N/A
0N/A // Event source interfaces
0N/A
0N/A /**
0N/A * Adds the specified component listener to receive component events from
0N/A * this component.
0N/A * If listener <code>l</code> is <code>null</code>,
0N/A * no exception is thrown and no action is performed.
0N/A * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
0N/A * >AWT Threading Issues</a> for details on AWT's threading model.
0N/A *
0N/A * @param l the component listener
0N/A * @see java.awt.event.ComponentEvent
0N/A * @see java.awt.event.ComponentListener
0N/A * @see #removeComponentListener
0N/A * @see #getComponentListeners
0N/A * @since JDK1.1
0N/A */
0N/A public synchronized void addComponentListener(ComponentListener l) {
0N/A if (l == null) {
0N/A return;
0N/A }
0N/A componentListener = AWTEventMulticaster.add(componentListener, l);
0N/A newEventsOnly = true;
0N/A }
0N/A
0N/A /**
0N/A * Removes the specified component listener so that it no longer
0N/A * receives component events from this component. This method performs
0N/A * no function, nor does it throw an exception, if the listener
0N/A * specified by the argument was not previously added to this component.
0N/A * If listener <code>l</code> is <code>null</code>,
0N/A * no exception is thrown and no action is performed.
0N/A * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
0N/A * >AWT Threading Issues</a> for details on AWT's threading model.
0N/A * @param l the component listener
0N/A * @see java.awt.event.ComponentEvent
0N/A * @see java.awt.event.ComponentListener
0N/A * @see #addComponentListener
0N/A * @see #getComponentListeners
0N/A * @since JDK1.1
0N/A */
0N/A public synchronized void removeComponentListener(ComponentListener l) {
0N/A if (l == null) {
0N/A return;
0N/A }
0N/A componentListener = AWTEventMulticaster.remove(componentListener, l);
0N/A }
0N/A
0N/A /**
0N/A * Returns an array of all the component listeners
0N/A * registered on this component.
0N/A *
0N/A * @return all of this comonent's <code>ComponentListener</code>s
0N/A * or an empty array if no component
0N/A * listeners are currently registered
0N/A *
0N/A * @see #addComponentListener
0N/A * @see #removeComponentListener
0N/A * @since 1.4
0N/A */
0N/A public synchronized ComponentListener[] getComponentListeners() {
0N/A return (ComponentListener[]) (getListeners(ComponentListener.class));
0N/A }
0N/A
0N/A /**
0N/A * Adds the specified focus listener to receive focus events from
0N/A * this component when this component gains input focus.
0N/A * If listener <code>l</code> is <code>null</code>,
0N/A * no exception is thrown and no action is performed.
0N/A * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
0N/A * >AWT Threading Issues</a> for details on AWT's threading model.
0N/A *
0N/A * @param l the focus listener
0N/A * @see java.awt.event.FocusEvent
0N/A * @see java.awt.event.FocusListener
0N/A * @see #removeFocusListener
0N/A * @see #getFocusListeners
0N/A * @since JDK1.1
0N/A */
0N/A public synchronized void addFocusListener(FocusListener l) {
0N/A if (l == null) {
0N/A return;
0N/A }
0N/A focusListener = AWTEventMulticaster.add(focusListener, l);
0N/A newEventsOnly = true;
0N/A
0N/A // if this is a lightweight component, enable focus events
0N/A // in the native container.
0N/A if (peer instanceof LightweightPeer) {
0N/A parent.proxyEnableEvents(AWTEvent.FOCUS_EVENT_MASK);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Removes the specified focus listener so that it no longer
0N/A * receives focus events from this component. This method performs
0N/A * no function, nor does it throw an exception, if the listener
0N/A * specified by the argument was not previously added to this component.
0N/A * If listener <code>l</code> is <code>null</code>,
0N/A * no exception is thrown and no action is performed.
0N/A * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
0N/A * >AWT Threading Issues</a> for details on AWT's threading model.
0N/A *
0N/A * @param l the focus listener
0N/A * @see java.awt.event.FocusEvent
0N/A * @see java.awt.event.FocusListener
0N/A * @see #addFocusListener
0N/A * @see #getFocusListeners
0N/A * @since JDK1.1
0N/A */
0N/A public synchronized void removeFocusListener(FocusListener l) {
0N/A if (l == null) {
0N/A return;
0N/A }
0N/A focusListener = AWTEventMulticaster.remove(focusListener, l);
0N/A }
0N/A
0N/A /**
0N/A * Returns an array of all the focus listeners
0N/A * registered on this component.
0N/A *
0N/A * @return all of this component's <code>FocusListener</code>s
0N/A * or an empty array if no component
0N/A * listeners are currently registered
0N/A *
0N/A * @see #addFocusListener
0N/A * @see #removeFocusListener
0N/A * @since 1.4
0N/A */
0N/A public synchronized FocusListener[] getFocusListeners() {
0N/A return (FocusListener[]) (getListeners(FocusListener.class));
0N/A }
0N/A
0N/A /**
0N/A * Adds the specified hierarchy listener to receive hierarchy changed
0N/A * events from this component when the hierarchy to which this container
0N/A * belongs changes.
0N/A * If listener <code>l</code> is <code>null</code>,
0N/A * no exception is thrown and no action is performed.
0N/A * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
0N/A * >AWT Threading Issues</a> for details on AWT's threading model.
0N/A *
0N/A * @param l the hierarchy listener
0N/A * @see java.awt.event.HierarchyEvent
0N/A * @see java.awt.event.HierarchyListener
0N/A * @see #removeHierarchyListener
0N/A * @see #getHierarchyListeners
0N/A * @since 1.3
0N/A */
0N/A public void addHierarchyListener(HierarchyListener l) {
0N/A if (l == null) {
0N/A return;
0N/A }
0N/A boolean notifyAncestors;
0N/A synchronized (this) {
0N/A notifyAncestors =
0N/A (hierarchyListener == null &&
0N/A (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) == 0);
0N/A hierarchyListener = AWTEventMulticaster.add(hierarchyListener, l);
0N/A notifyAncestors = (notifyAncestors && hierarchyListener != null);
0N/A newEventsOnly = true;
0N/A }
0N/A if (notifyAncestors) {
0N/A synchronized (getTreeLock()) {
0N/A adjustListeningChildrenOnParent(AWTEvent.HIERARCHY_EVENT_MASK,
0N/A 1);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Removes the specified hierarchy listener so that it no longer
0N/A * receives hierarchy changed events from this component. This method
0N/A * performs no function, nor does it throw an exception, if the listener
0N/A * specified by the argument was not previously added to this component.
0N/A * If listener <code>l</code> is <code>null</code>,
0N/A * no exception is thrown and no action is performed.
0N/A * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
0N/A * >AWT Threading Issues</a> for details on AWT's threading model.
0N/A *
0N/A * @param l the hierarchy listener
0N/A * @see java.awt.event.HierarchyEvent
0N/A * @see java.awt.event.HierarchyListener
0N/A * @see #addHierarchyListener
0N/A * @see #getHierarchyListeners
0N/A * @since 1.3
0N/A */
0N/A public void removeHierarchyListener(HierarchyListener l) {
0N/A if (l == null) {
0N/A return;
0N/A }
0N/A boolean notifyAncestors;
0N/A synchronized (this) {
0N/A notifyAncestors =
0N/A (hierarchyListener != null &&
0N/A (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) == 0);
0N/A hierarchyListener =
0N/A AWTEventMulticaster.remove(hierarchyListener, l);
0N/A notifyAncestors = (notifyAncestors && hierarchyListener == null);
0N/A }
0N/A if (notifyAncestors) {
0N/A synchronized (getTreeLock()) {
0N/A adjustListeningChildrenOnParent(AWTEvent.HIERARCHY_EVENT_MASK,
0N/A -1);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns an array of all the hierarchy listeners
0N/A * registered on this component.
0N/A *
0N/A * @return all of this component's <code>HierarchyListener</code>s
0N/A * or an empty array if no hierarchy
0N/A * listeners are currently registered
0N/A *
0N/A * @see #addHierarchyListener
0N/A * @see #removeHierarchyListener
0N/A * @since 1.4
0N/A */
0N/A public synchronized HierarchyListener[] getHierarchyListeners() {
0N/A return (HierarchyListener[])(getListeners(HierarchyListener.class));
0N/A }
0N/A
0N/A /**
0N/A * Adds the specified hierarchy bounds listener to receive hierarchy
0N/A * bounds events from this component when the hierarchy to which this
0N/A * container belongs changes.
0N/A * If listener <code>l</code> is <code>null</code>,
0N/A * no exception is thrown and no action is performed.
0N/A * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
0N/A * >AWT Threading Issues</a> for details on AWT's threading model.
0N/A *
0N/A * @param l the hierarchy bounds listener
0N/A * @see java.awt.event.HierarchyEvent
0N/A * @see java.awt.event.HierarchyBoundsListener
0N/A * @see #removeHierarchyBoundsListener
0N/A * @see #getHierarchyBoundsListeners
0N/A * @since 1.3
0N/A */
0N/A public void addHierarchyBoundsListener(HierarchyBoundsListener l) {
0N/A if (l == null) {
0N/A return;
0N/A }
0N/A boolean notifyAncestors;
0N/A synchronized (this) {
0N/A notifyAncestors =
0N/A (hierarchyBoundsListener == null &&
0N/A (eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) == 0);
0N/A hierarchyBoundsListener =
0N/A AWTEventMulticaster.add(hierarchyBoundsListener, l);
0N/A notifyAncestors = (notifyAncestors &&
0N/A hierarchyBoundsListener != null);
0N/A newEventsOnly = true;
0N/A }
0N/A if (notifyAncestors) {
0N/A synchronized (getTreeLock()) {
0N/A adjustListeningChildrenOnParent(
0N/A AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK, 1);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Removes the specified hierarchy bounds listener so that it no longer
0N/A * receives hierarchy bounds events from this component. This method
0N/A * performs no function, nor does it throw an exception, if the listener
0N/A * specified by the argument was not previously added to this component.
0N/A * If listener <code>l</code> is <code>null</code>,
0N/A * no exception is thrown and no action is performed.
0N/A * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
0N/A * >AWT Threading Issues</a> for details on AWT's threading model.
0N/A *
0N/A * @param l the hierarchy bounds listener
0N/A * @see java.awt.event.HierarchyEvent
0N/A * @see java.awt.event.HierarchyBoundsListener
0N/A * @see #addHierarchyBoundsListener
0N/A * @see #getHierarchyBoundsListeners
0N/A * @since 1.3
0N/A */
0N/A public void removeHierarchyBoundsListener(HierarchyBoundsListener l) {
0N/A if (l == null) {
0N/A return;
0N/A }
0N/A boolean notifyAncestors;
0N/A synchronized (this) {
0N/A notifyAncestors =
0N/A (hierarchyBoundsListener != null &&
0N/A (eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) == 0);
0N/A hierarchyBoundsListener =
0N/A AWTEventMulticaster.remove(hierarchyBoundsListener, l);
0N/A notifyAncestors = (notifyAncestors &&
0N/A hierarchyBoundsListener == null);
0N/A }
0N/A if (notifyAncestors) {
0N/A synchronized (getTreeLock()) {
0N/A adjustListeningChildrenOnParent(
0N/A AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK, -1);
0N/A }
0N/A }
0N/A }
0N/A
0N/A // Should only be called while holding the tree lock
0N/A int numListening(long mask) {
0N/A // One mask or the other, but not neither or both.
0N/A if (eventLog.isLoggable(Level.FINE)) {
0N/A if ((mask != AWTEvent.HIERARCHY_EVENT_MASK) &&
0N/A (mask != AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK))
0N/A {
0N/A eventLog.log(Level.FINE, "Assertion failed");
0N/A }
0N/A }
0N/A if ((mask == AWTEvent.HIERARCHY_EVENT_MASK &&
0N/A (hierarchyListener != null ||
0N/A (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0)) ||
0N/A (mask == AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK &&
0N/A (hierarchyBoundsListener != null ||
0N/A (eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0))) {
0N/A return 1;
0N/A } else {
0N/A return 0;
0N/A }
0N/A }
0N/A
0N/A // Should only be called while holding tree lock
0N/A int countHierarchyMembers() {
0N/A return 1;
0N/A }
0N/A // Should only be called while holding the tree lock
0N/A int createHierarchyEvents(int id, Component changed,
0N/A Container changedParent, long changeFlags,
0N/A boolean enabledOnToolkit) {
0N/A switch (id) {
0N/A case HierarchyEvent.HIERARCHY_CHANGED:
0N/A if (hierarchyListener != null ||
0N/A (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0 ||
0N/A enabledOnToolkit) {
0N/A HierarchyEvent e = new HierarchyEvent(this, id, changed,
0N/A changedParent,
0N/A changeFlags);
0N/A dispatchEvent(e);
0N/A return 1;
0N/A }
0N/A break;
0N/A case HierarchyEvent.ANCESTOR_MOVED:
0N/A case HierarchyEvent.ANCESTOR_RESIZED:
0N/A if (eventLog.isLoggable(Level.FINE)) {
0N/A if (changeFlags != 0) {
0N/A eventLog.log(Level.FINE, "Assertion (changeFlags == 0) failed");
0N/A }
0N/A }
0N/A if (hierarchyBoundsListener != null ||
0N/A (eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0 ||
0N/A enabledOnToolkit) {
0N/A HierarchyEvent e = new HierarchyEvent(this, id, changed,
0N/A changedParent);
0N/A dispatchEvent(e);
0N/A return 1;
0N/A }
0N/A break;
0N/A default:
0N/A // assert false
0N/A if (eventLog.isLoggable(Level.FINE)) {
0N/A eventLog.log(Level.FINE, "This code must never be reached");
0N/A }
0N/A break;
0N/A }
0N/A return 0;
0N/A }
0N/A
0N/A /**
0N/A * Returns an array of all the hierarchy bounds listeners
0N/A * registered on this component.
0N/A *
0N/A * @return all of this component's <code>HierarchyBoundsListener</code>s
0N/A * or an empty array if no hierarchy bounds
0N/A * listeners are currently registered
0N/A *
0N/A * @see #addHierarchyBoundsListener
0N/A * @see #removeHierarchyBoundsListener
0N/A * @since 1.4
0N/A */
0N/A public synchronized HierarchyBoundsListener[] getHierarchyBoundsListeners() {
0N/A return (HierarchyBoundsListener[])
0N/A (getListeners(HierarchyBoundsListener.class));
0N/A }
0N/A
0N/A /*
0N/A * Should only be called while holding the tree lock.
0N/A * It's added only for overriding in java.awt.Window
0N/A * because parent in Window is owner.
0N/A */
0N/A void adjustListeningChildrenOnParent(long mask, int num) {
0N/A if (parent != null) {
0N/A parent.adjustListeningChildren(mask, num);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Adds the specified key listener to receive key events from
0N/A * this component.
0N/A * If l is null, no exception is thrown and no action is performed.
0N/A * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
0N/A * >AWT Threading Issues</a> for details on AWT's threading model.
0N/A *
0N/A * @param l the key listener.
0N/A * @see java.awt.event.KeyEvent
0N/A * @see java.awt.event.KeyListener
0N/A * @see #removeKeyListener
0N/A * @see #getKeyListeners
0N/A * @since JDK1.1
0N/A */
0N/A public synchronized void addKeyListener(KeyListener l) {
0N/A if (l == null) {
0N/A return;
0N/A }
0N/A keyListener = AWTEventMulticaster.add(keyListener, l);
0N/A newEventsOnly = true;
0N/A
0N/A // if this is a lightweight component, enable key events
0N/A // in the native container.
0N/A if (peer instanceof LightweightPeer) {
0N/A parent.proxyEnableEvents(AWTEvent.KEY_EVENT_MASK);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Removes the specified key listener so that it no longer
0N/A * receives key events from this component. This method performs
0N/A * no function, nor does it throw an exception, if the listener
0N/A * specified by the argument was not previously added to this component.
0N/A * If listener <code>l</code> is <code>null</code>,
0N/A * no exception is thrown and no action is performed.
0N/A * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
0N/A * >AWT Threading Issues</a> for details on AWT's threading model.
0N/A *
0N/A * @param l the key listener
0N/A * @see java.awt.event.KeyEvent
0N/A * @see java.awt.event.KeyListener
0N/A * @see #addKeyListener
0N/A * @see #getKeyListeners
0N/A * @since JDK1.1
0N/A */
0N/A public synchronized void removeKeyListener(KeyListener l) {
0N/A if (l == null) {
0N/A return;
0N/A }
0N/A keyListener = AWTEventMulticaster.remove(keyListener, l);
0N/A }
0N/A
0N/A /**
0N/A * Returns an array of all the key listeners
0N/A * registered on this component.
0N/A *
0N/A * @return all of this component's <code>KeyListener</code>s
0N/A * or an empty array if no key
0N/A * listeners are currently registered
0N/A *
0N/A * @see #addKeyListener
0N/A * @see #removeKeyListener
0N/A * @since 1.4
0N/A */
0N/A public synchronized KeyListener[] getKeyListeners() {
0N/A return (KeyListener[]) (getListeners(KeyListener.class));
0N/A }
0N/A
0N/A /**
0N/A * Adds the specified mouse listener to receive mouse events from
0N/A * this component.
0N/A * If listener <code>l</code> is <code>null</code>,
0N/A * no exception is thrown and no action is performed.
0N/A * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
0N/A * >AWT Threading Issues</a> for details on AWT's threading model.
0N/A *
0N/A * @param l the mouse listener
0N/A * @see java.awt.event.MouseEvent
0N/A * @see java.awt.event.MouseListener
0N/A * @see #removeMouseListener
0N/A * @see #getMouseListeners
0N/A * @since JDK1.1
0N/A */
0N/A public synchronized void addMouseListener(MouseListener l) {
0N/A if (l == null) {
0N/A return;
0N/A }
0N/A mouseListener = AWTEventMulticaster.add(mouseListener,l);
0N/A newEventsOnly = true;
0N/A
0N/A // if this is a lightweight component, enable mouse events
0N/A // in the native container.
0N/A if (peer instanceof LightweightPeer) {
0N/A parent.proxyEnableEvents(AWTEvent.MOUSE_EVENT_MASK);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Removes the specified mouse listener so that it no longer
0N/A * receives mouse events from this component. This method performs
0N/A * no function, nor does it throw an exception, if the listener
0N/A * specified by the argument was not previously added to this component.
0N/A * If listener <code>l</code> is <code>null</code>,
0N/A * no exception is thrown and no action is performed.
0N/A * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
0N/A * >AWT Threading Issues</a> for details on AWT's threading model.
0N/A *
0N/A * @param l the mouse listener
0N/A * @see java.awt.event.MouseEvent
0N/A * @see java.awt.event.MouseListener
0N/A * @see #addMouseListener
0N/A * @see #getMouseListeners
0N/A * @since JDK1.1
0N/A */
0N/A public synchronized void removeMouseListener(MouseListener l) {
0N/A if (l == null) {
0N/A return;
0N/A }
0N/A mouseListener = AWTEventMulticaster.remove(mouseListener, l);
0N/A }
0N/A
0N/A /**
0N/A * Returns an array of all the mouse listeners
0N/A * registered on this component.
0N/A *
0N/A * @return all of this component's <code>MouseListener</code>s
0N/A * or an empty array if no mouse
0N/A * listeners are currently registered
0N/A *
0N/A * @see #addMouseListener
0N/A * @see #removeMouseListener
0N/A * @since 1.4
0N/A */
0N/A public synchronized MouseListener[] getMouseListeners() {
0N/A return (MouseListener[]) (getListeners(MouseListener.class));
0N/A }
0N/A
0N/A /**
0N/A * Adds the specified mouse motion listener to receive mouse motion
0N/A * events from this component.
0N/A * If listener <code>l</code> is <code>null</code>,
0N/A * no exception is thrown and no action is performed.
0N/A * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
0N/A * >AWT Threading Issues</a> for details on AWT's threading model.
0N/A *
0N/A * @param l the mouse motion listener
0N/A * @see java.awt.event.MouseEvent
0N/A * @see java.awt.event.MouseMotionListener
0N/A * @see #removeMouseMotionListener
0N/A * @see #getMouseMotionListeners
0N/A * @since JDK1.1
0N/A */
0N/A public synchronized void addMouseMotionListener(MouseMotionListener l) {
0N/A if (l == null) {
0N/A return;
0N/A }
0N/A mouseMotionListener = AWTEventMulticaster.add(mouseMotionListener,l);
0N/A newEventsOnly = true;
0N/A
0N/A // if this is a lightweight component, enable mouse events
0N/A // in the native container.
0N/A if (peer instanceof LightweightPeer) {
0N/A parent.proxyEnableEvents(AWTEvent.MOUSE_MOTION_EVENT_MASK);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Removes the specified mouse motion listener so that it no longer
0N/A * receives mouse motion events from this component. This method performs
0N/A * no function, nor does it throw an exception, if the listener
0N/A * specified by the argument was not previously added to this component.
0N/A * If listener <code>l</code> is <code>null</code>,
0N/A * no exception is thrown and no action is performed.
0N/A * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
0N/A * >AWT Threading Issues</a> for details on AWT's threading model.
0N/A *
0N/A * @param l the mouse motion listener
0N/A * @see java.awt.event.MouseEvent
0N/A * @see java.awt.event.MouseMotionListener
0N/A * @see #addMouseMotionListener
0N/A * @see #getMouseMotionListeners
0N/A * @since JDK1.1
0N/A */
0N/A public synchronized void removeMouseMotionListener(MouseMotionListener l) {
0N/A if (l == null) {
0N/A return;
0N/A }
0N/A mouseMotionListener = AWTEventMulticaster.remove(mouseMotionListener, l);
0N/A }
0N/A
0N/A /**
0N/A * Returns an array of all the mouse motion listeners
0N/A * registered on this component.
0N/A *
0N/A * @return all of this component's <code>MouseMotionListener</code>s
0N/A * or an empty array if no mouse motion
0N/A * listeners are currently registered
0N/A *
0N/A * @see #addMouseMotionListener
0N/A * @see #removeMouseMotionListener
0N/A * @since 1.4
0N/A */
0N/A public synchronized MouseMotionListener[] getMouseMotionListeners() {
0N/A return (MouseMotionListener[]) (getListeners(MouseMotionListener.class));
0N/A }
0N/A
0N/A /**
0N/A * Adds the specified mouse wheel listener to receive mouse wheel events
0N/A * from this component. Containers also receive mouse wheel events from
0N/A * sub-components.
0N/A * <p>
0N/A * For information on how mouse wheel events are dispatched, see
0N/A * the class description for {@link MouseWheelEvent}.
0N/A * <p>
0N/A * If l is <code>null</code>, no exception is thrown and no
0N/A * action is performed.
0N/A * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
0N/A * >AWT Threading Issues</a> for details on AWT's threading model.
0N/A *
0N/A * @param l the mouse wheel listener
0N/A * @see java.awt.event.MouseWheelEvent
0N/A * @see java.awt.event.MouseWheelListener
0N/A * @see #removeMouseWheelListener
0N/A * @see #getMouseWheelListeners
0N/A * @since 1.4
0N/A */
0N/A public synchronized void addMouseWheelListener(MouseWheelListener l) {
0N/A if (l == null) {
0N/A return;
0N/A }
0N/A mouseWheelListener = AWTEventMulticaster.add(mouseWheelListener,l);
0N/A newEventsOnly = true;
0N/A
0N/A // if this is a lightweight component, enable mouse events
0N/A // in the native container.
0N/A if (peer instanceof LightweightPeer) {
0N/A parent.proxyEnableEvents(AWTEvent.MOUSE_WHEEL_EVENT_MASK);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Removes the specified mouse wheel listener so that it no longer
0N/A * receives mouse wheel events from this component. This method performs
0N/A * no function, nor does it throw an exception, if the listener
0N/A * specified by the argument was not previously added to this component.
0N/A * If l is null, no exception is thrown and no action is performed.
0N/A * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
0N/A * >AWT Threading Issues</a> for details on AWT's threading model.
0N/A *
0N/A * @param l the mouse wheel listener.
0N/A * @see java.awt.event.MouseWheelEvent
0N/A * @see java.awt.event.MouseWheelListener
0N/A * @see #addMouseWheelListener
0N/A * @see #getMouseWheelListeners
0N/A * @since 1.4
0N/A */
0N/A public synchronized void removeMouseWheelListener(MouseWheelListener l) {
0N/A if (l == null) {
0N/A return;
0N/A }
0N/A mouseWheelListener = AWTEventMulticaster.remove(mouseWheelListener, l);
0N/A }
0N/A
0N/A /**
0N/A * Returns an array of all the mouse wheel listeners
0N/A * registered on this component.
0N/A *
0N/A * @return all of this component's <code>MouseWheelListener</code>s
0N/A * or an empty array if no mouse wheel
0N/A * listeners are currently registered
0N/A *
0N/A * @see #addMouseWheelListener
0N/A * @see #removeMouseWheelListener
0N/A * @since 1.4
0N/A */
0N/A public synchronized MouseWheelListener[] getMouseWheelListeners() {
0N/A return (MouseWheelListener[]) (getListeners(MouseWheelListener.class));
0N/A }
0N/A
0N/A /**
0N/A * Adds the specified input method listener to receive
0N/A * input method events from this component. A component will
0N/A * only receive input method events from input methods
0N/A * if it also overrides <code>getInputMethodRequests</code> to return an
0N/A * <code>InputMethodRequests</code> instance.
0N/A * If listener <code>l</code> is <code>null</code>,
0N/A * no exception is thrown and no action is performed.
0N/A * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
0N/A * >AWT Threading Issues</a> for details on AWT's threading model.
0N/A *
0N/A * @param l the input method listener
0N/A * @see java.awt.event.InputMethodEvent
0N/A * @see java.awt.event.InputMethodListener
0N/A * @see #removeInputMethodListener
0N/A * @see #getInputMethodListeners
0N/A * @see #getInputMethodRequests
0N/A * @since 1.2
0N/A */
0N/A public synchronized void addInputMethodListener(InputMethodListener l) {
0N/A if (l == null) {
0N/A return;
0N/A }
0N/A inputMethodListener = AWTEventMulticaster.add(inputMethodListener, l);
0N/A newEventsOnly = true;
0N/A }
0N/A
0N/A /**
0N/A * Removes the specified input method listener so that it no longer
0N/A * receives input method events from this component. This method performs
0N/A * no function, nor does it throw an exception, if the listener
0N/A * specified by the argument was not previously added to this component.
0N/A * If listener <code>l</code> is <code>null</code>,
0N/A * no exception is thrown and no action is performed.
0N/A * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
0N/A * >AWT Threading Issues</a> for details on AWT's threading model.
0N/A *
0N/A * @param l the input method listener
0N/A * @see java.awt.event.InputMethodEvent
0N/A * @see java.awt.event.InputMethodListener
0N/A * @see #addInputMethodListener
0N/A * @see #getInputMethodListeners
0N/A * @since 1.2
0N/A */
0N/A public synchronized void removeInputMethodListener(InputMethodListener l) {
0N/A if (l == null) {
0N/A return;
0N/A }
0N/A inputMethodListener = AWTEventMulticaster.remove(inputMethodListener, l);
0N/A }
0N/A
0N/A /**
0N/A * Returns an array of all the input method listeners
0N/A * registered on this component.
0N/A *
0N/A * @return all of this component's <code>InputMethodListener</code>s
0N/A * or an empty array if no input method
0N/A * listeners are currently registered
0N/A *
0N/A * @see #addInputMethodListener
0N/A * @see #removeInputMethodListener
0N/A * @since 1.4
0N/A */
0N/A public synchronized InputMethodListener[] getInputMethodListeners() {
0N/A return (InputMethodListener[]) (getListeners(InputMethodListener.class));
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>Component</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 * You can specify the <code>listenerType</code> argument
0N/A * with a class literal, such as
0N/A * <code><em>Foo</em>Listener.class</code>.
0N/A * For example, you can query a
0N/A * <code>Component</code> <code>c</code>
0N/A * for its mouse listeners with the following code:
0N/A *
0N/A * <pre>MouseListener[] mls = (MouseListener[])(c.getListeners(MouseListener.class));</pre>
0N/A *
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 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 * @see #getComponentListeners
0N/A * @see #getFocusListeners
0N/A * @see #getHierarchyListeners
0N/A * @see #getHierarchyBoundsListeners
0N/A * @see #getKeyListeners
0N/A * @see #getMouseListeners
0N/A * @see #getMouseMotionListeners
0N/A * @see #getMouseWheelListeners
0N/A * @see #getInputMethodListeners
0N/A * @see #getPropertyChangeListeners
0N/A *
0N/A * @since 1.3
0N/A */
0N/A public <T extends EventListener> T[] getListeners(Class<T> listenerType) {
0N/A EventListener l = null;
0N/A if (listenerType == ComponentListener.class) {
0N/A l = componentListener;
0N/A } else if (listenerType == FocusListener.class) {
0N/A l = focusListener;
0N/A } else if (listenerType == HierarchyListener.class) {
0N/A l = hierarchyListener;
0N/A } else if (listenerType == HierarchyBoundsListener.class) {
0N/A l = hierarchyBoundsListener;
0N/A } else if (listenerType == KeyListener.class) {
0N/A l = keyListener;
0N/A } else if (listenerType == MouseListener.class) {
0N/A l = mouseListener;
0N/A } else if (listenerType == MouseMotionListener.class) {
0N/A l = mouseMotionListener;
0N/A } else if (listenerType == MouseWheelListener.class) {
0N/A l = mouseWheelListener;
0N/A } else if (listenerType == InputMethodListener.class) {
0N/A l = inputMethodListener;
0N/A } else if (listenerType == PropertyChangeListener.class) {
0N/A return (T[])getPropertyChangeListeners();
0N/A }
0N/A return AWTEventMulticaster.getListeners(l, listenerType);
0N/A }
0N/A
0N/A /**
0N/A * Gets the input method request handler which supports
0N/A * requests from input methods for this component. A component
0N/A * that supports on-the-spot text input must override this
0N/A * method to return an <code>InputMethodRequests</code> instance.
0N/A * At the same time, it also has to handle input method events.
0N/A *
0N/A * @return the input method request handler for this component,
0N/A * <code>null</code> by default
0N/A * @see #addInputMethodListener
0N/A * @since 1.2
0N/A */
0N/A public InputMethodRequests getInputMethodRequests() {
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Gets the input context used by this component for handling
0N/A * the communication with input methods when text is entered
0N/A * in this component. By default, the input context used for
0N/A * the parent component is returned. Components may
0N/A * override this to return a private input context.
0N/A *
0N/A * @return the input context used by this component;
0N/A * <code>null</code> if no context can be determined
0N/A * @since 1.2
0N/A */
0N/A public InputContext getInputContext() {
0N/A Container parent = this.parent;
0N/A if (parent == null) {
0N/A return null;
0N/A } else {
0N/A return parent.getInputContext();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Enables the events defined by the specified event mask parameter
0N/A * to be delivered to this component.
0N/A * <p>
0N/A * Event types are automatically enabled when a listener for
0N/A * that event type is added to the component.
0N/A * <p>
0N/A * This method only needs to be invoked by subclasses of
0N/A * <code>Component</code> which desire to have the specified event
0N/A * types delivered to <code>processEvent</code> regardless of whether
0N/A * or not a listener is registered.
0N/A * @param eventsToEnable the event mask defining the event types
0N/A * @see #processEvent
0N/A * @see #disableEvents
0N/A * @see AWTEvent
0N/A * @since JDK1.1
0N/A */
0N/A protected final void enableEvents(long eventsToEnable) {
0N/A long notifyAncestors = 0;
0N/A synchronized (this) {
0N/A if ((eventsToEnable & AWTEvent.HIERARCHY_EVENT_MASK) != 0 &&
0N/A hierarchyListener == null &&
0N/A (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) == 0) {
0N/A notifyAncestors |= AWTEvent.HIERARCHY_EVENT_MASK;
0N/A }
0N/A if ((eventsToEnable & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0 &&
0N/A hierarchyBoundsListener == null &&
0N/A (eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) == 0) {
0N/A notifyAncestors |= AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK;
0N/A }
0N/A eventMask |= eventsToEnable;
0N/A newEventsOnly = true;
0N/A }
0N/A
0N/A // if this is a lightweight component, enable mouse events
0N/A // in the native container.
0N/A if (peer instanceof LightweightPeer) {
0N/A parent.proxyEnableEvents(eventMask);
0N/A }
0N/A if (notifyAncestors != 0) {
0N/A synchronized (getTreeLock()) {
0N/A adjustListeningChildrenOnParent(notifyAncestors, 1);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Disables the events defined by the specified event mask parameter
0N/A * from being delivered to this component.
0N/A * @param eventsToDisable the event mask defining the event types
0N/A * @see #enableEvents
0N/A * @since JDK1.1
0N/A */
0N/A protected final void disableEvents(long eventsToDisable) {
0N/A long notifyAncestors = 0;
0N/A synchronized (this) {
0N/A if ((eventsToDisable & AWTEvent.HIERARCHY_EVENT_MASK) != 0 &&
0N/A hierarchyListener == null &&
0N/A (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0) {
0N/A notifyAncestors |= AWTEvent.HIERARCHY_EVENT_MASK;
0N/A }
0N/A if ((eventsToDisable & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK)!=0 &&
0N/A hierarchyBoundsListener == null &&
0N/A (eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0) {
0N/A notifyAncestors |= AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK;
0N/A }
0N/A eventMask &= ~eventsToDisable;
0N/A }
0N/A if (notifyAncestors != 0) {
0N/A synchronized (getTreeLock()) {
0N/A adjustListeningChildrenOnParent(notifyAncestors, -1);
0N/A }
0N/A }
0N/A }
0N/A
0N/A transient EventQueueItem[] eventCache;
0N/A
0N/A /**
0N/A * @see #isCoalescingEnabled
0N/A * @see #checkCoalescing
0N/A */
0N/A transient private boolean coalescingEnabled = checkCoalescing();
0N/A
0N/A /**
0N/A * Weak map of known coalesceEvent overriders.
0N/A * Value indicates whether overriden.
0N/A * Bootstrap classes are not included.
0N/A */
0N/A private static final Map<Class<?>, Boolean> coalesceMap =
0N/A new java.util.WeakHashMap<Class<?>, Boolean>();
0N/A
0N/A /**
0N/A * Indicates whether this class overrides coalesceEvents.
0N/A * It is assumed that all classes that are loaded from the bootstrap
0N/A * do not.
0N/A * The boostrap class loader is assumed to be represented by null.
0N/A * We do not check that the method really overrides
0N/A * (it might be static, private or package private).
0N/A */
0N/A private boolean checkCoalescing() {
0N/A if (getClass().getClassLoader()==null) {
0N/A return false;
0N/A }
0N/A final Class<? extends Component> clazz = getClass();
0N/A synchronized (coalesceMap) {
0N/A // Check cache.
0N/A Boolean value = coalesceMap.get(clazz);
0N/A if (value != null) {
0N/A return value;
0N/A }
0N/A
0N/A // Need to check non-bootstraps.
0N/A Boolean enabled = java.security.AccessController.doPrivileged(
0N/A new java.security.PrivilegedAction<Boolean>() {
0N/A public Boolean run() {
0N/A return isCoalesceEventsOverriden(clazz);
0N/A }
0N/A }
0N/A );
0N/A coalesceMap.put(clazz, enabled);
0N/A return enabled;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Parameter types of coalesceEvents(AWTEvent,AWTEVent).
0N/A */
0N/A private static final Class[] coalesceEventsParams = {
0N/A AWTEvent.class, AWTEvent.class
0N/A };
0N/A
0N/A /**
0N/A * Indicates whether a class or its superclasses override coalesceEvents.
0N/A * Must be called with lock on coalesceMap and privileged.
0N/A * @see checkCoalsecing
0N/A */
0N/A private static boolean isCoalesceEventsOverriden(Class<?> clazz) {
0N/A assert Thread.holdsLock(coalesceMap);
0N/A
0N/A // First check superclass - we may not need to bother ourselves.
0N/A Class<?> superclass = clazz.getSuperclass();
0N/A if (superclass == null) {
0N/A // Only occurs on implementations that
0N/A // do not use null to represent the bootsrap class loader.
0N/A return false;
0N/A }
0N/A if (superclass.getClassLoader() != null) {
0N/A Boolean value = coalesceMap.get(superclass);
0N/A if (value == null) {
0N/A // Not done already - recurse.
0N/A if (isCoalesceEventsOverriden(superclass)) {
0N/A coalesceMap.put(superclass, true);
0N/A return true;
0N/A }
0N/A } else if (value) {
0N/A return true;
0N/A }
0N/A }
0N/A
0N/A try {
0N/A // Throws if not overriden.
0N/A clazz.getDeclaredMethod(
0N/A "coalesceEvents", coalesceEventsParams
0N/A );
0N/A return true;
0N/A } catch (NoSuchMethodException e) {
0N/A // Not present in this class.
0N/A return false;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Indicates whether coalesceEvents may do something.
0N/A */
0N/A final boolean isCoalescingEnabled() {
0N/A return coalescingEnabled;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Potentially coalesce an event being posted with an existing
0N/A * event. This method is called by <code>EventQueue.postEvent</code>
0N/A * if an event with the same ID as the event to be posted is found in
0N/A * the queue (both events must have this component as their source).
0N/A * This method either returns a coalesced event which replaces
0N/A * the existing event (and the new event is then discarded), or
0N/A * <code>null</code> to indicate that no combining should be done
0N/A * (add the second event to the end of the queue). Either event
0N/A * parameter may be modified and returned, as the other one is discarded
0N/A * unless <code>null</code> is returned.
0N/A * <p>
0N/A * This implementation of <code>coalesceEvents</code> coalesces
0N/A * two event types: mouse move (and drag) events,
0N/A * and paint (and update) events.
0N/A * For mouse move events the last event is always returned, causing
0N/A * intermediate moves to be discarded. For paint events, the new
0N/A * event is coalesced into a complex <code>RepaintArea</code> in the peer.
0N/A * The new <code>AWTEvent</code> is always returned.
0N/A *
0N/A * @param existingEvent the event already on the <code>EventQueue</code>
0N/A * @param newEvent the event being posted to the
0N/A * <code>EventQueue</code>
0N/A * @return a coalesced event, or <code>null</code> indicating that no
0N/A * coalescing was done
0N/A */
0N/A protected AWTEvent coalesceEvents(AWTEvent existingEvent,
0N/A AWTEvent newEvent) {
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Processes events occurring on this component. By default this
0N/A * method calls the appropriate
0N/A * <code>process&lt;event&nbsp;type&gt;Event</code>
0N/A * method for the given class of event.
0N/A * <p>Note that if the event parameter is <code>null</code>
0N/A * the behavior is unspecified and may result in an
0N/A * exception.
0N/A *
0N/A * @param e the event
0N/A * @see #processComponentEvent
0N/A * @see #processFocusEvent
0N/A * @see #processKeyEvent
0N/A * @see #processMouseEvent
0N/A * @see #processMouseMotionEvent
0N/A * @see #processInputMethodEvent
0N/A * @see #processHierarchyEvent
0N/A * @see #processMouseWheelEvent
0N/A * @since JDK1.1
0N/A */
0N/A protected void processEvent(AWTEvent e) {
0N/A if (e instanceof FocusEvent) {
0N/A processFocusEvent((FocusEvent)e);
0N/A
0N/A } else if (e instanceof MouseEvent) {
0N/A switch(e.getID()) {
0N/A case MouseEvent.MOUSE_PRESSED:
0N/A case MouseEvent.MOUSE_RELEASED:
0N/A case MouseEvent.MOUSE_CLICKED:
0N/A case MouseEvent.MOUSE_ENTERED:
0N/A case MouseEvent.MOUSE_EXITED:
0N/A processMouseEvent((MouseEvent)e);
0N/A break;
0N/A case MouseEvent.MOUSE_MOVED:
0N/A case MouseEvent.MOUSE_DRAGGED:
0N/A processMouseMotionEvent((MouseEvent)e);
0N/A break;
0N/A case MouseEvent.MOUSE_WHEEL:
0N/A processMouseWheelEvent((MouseWheelEvent)e);
0N/A break;
0N/A }
0N/A
0N/A } else if (e instanceof KeyEvent) {
0N/A processKeyEvent((KeyEvent)e);
0N/A
0N/A } else if (e instanceof ComponentEvent) {
0N/A processComponentEvent((ComponentEvent)e);
0N/A } else if (e instanceof InputMethodEvent) {
0N/A processInputMethodEvent((InputMethodEvent)e);
0N/A } else if (e instanceof HierarchyEvent) {
0N/A switch (e.getID()) {
0N/A case HierarchyEvent.HIERARCHY_CHANGED:
0N/A processHierarchyEvent((HierarchyEvent)e);
0N/A break;
0N/A case HierarchyEvent.ANCESTOR_MOVED:
0N/A case HierarchyEvent.ANCESTOR_RESIZED:
0N/A processHierarchyBoundsEvent((HierarchyEvent)e);
0N/A break;
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Processes component events occurring on this component by
0N/A * dispatching them to any registered
0N/A * <code>ComponentListener</code> objects.
0N/A * <p>
0N/A * This method is not called unless component events are
0N/A * enabled for this component. Component events are enabled
0N/A * when one of the following occurs:
0N/A * <p><ul>
0N/A * <li>A <code>ComponentListener</code> object is registered
0N/A * via <code>addComponentListener</code>.
0N/A * <li>Component events are enabled via <code>enableEvents</code>.
0N/A * </ul>
0N/A * <p>Note that if the event parameter is <code>null</code>
0N/A * the behavior is unspecified and may result in an
0N/A * exception.
0N/A *
0N/A * @param e the component event
0N/A * @see java.awt.event.ComponentEvent
0N/A * @see java.awt.event.ComponentListener
0N/A * @see #addComponentListener
0N/A * @see #enableEvents
0N/A * @since JDK1.1
0N/A */
0N/A protected void processComponentEvent(ComponentEvent e) {
0N/A ComponentListener listener = componentListener;
0N/A if (listener != null) {
0N/A int id = e.getID();
0N/A switch(id) {
0N/A case ComponentEvent.COMPONENT_RESIZED:
0N/A listener.componentResized(e);
0N/A break;
0N/A case ComponentEvent.COMPONENT_MOVED:
0N/A listener.componentMoved(e);
0N/A break;
0N/A case ComponentEvent.COMPONENT_SHOWN:
0N/A listener.componentShown(e);
0N/A break;
0N/A case ComponentEvent.COMPONENT_HIDDEN:
0N/A listener.componentHidden(e);
0N/A break;
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Processes focus events occurring on this component by
0N/A * dispatching them to any registered
0N/A * <code>FocusListener</code> objects.
0N/A * <p>
0N/A * This method is not called unless focus events are
0N/A * enabled for this component. Focus events are enabled
0N/A * when one of the following occurs:
0N/A * <p><ul>
0N/A * <li>A <code>FocusListener</code> object is registered
0N/A * via <code>addFocusListener</code>.
0N/A * <li>Focus events are enabled via <code>enableEvents</code>.
0N/A * </ul>
0N/A * <p>
0N/A * If focus events are enabled for a <code>Component</code>,
0N/A * the current <code>KeyboardFocusManager</code> determines
0N/A * whether or not a focus event should be dispatched to
0N/A * registered <code>FocusListener</code> objects. If the
0N/A * events are to be dispatched, the <code>KeyboardFocusManager</code>
0N/A * calls the <code>Component</code>'s <code>dispatchEvent</code>
0N/A * method, which results in a call to the <code>Component</code>'s
0N/A * <code>processFocusEvent</code> method.
0N/A * <p>
0N/A * If focus events are enabled for a <code>Component</code>, calling
0N/A * the <code>Component</code>'s <code>dispatchEvent</code> method
0N/A * with a <code>FocusEvent</code> as the argument will result in a
0N/A * call to the <code>Component</code>'s <code>processFocusEvent</code>
0N/A * method regardless of the current <code>KeyboardFocusManager</code>.
0N/A * <p>
0N/A * <p>Note that if the event parameter is <code>null</code>
0N/A * the behavior is unspecified and may result in an
0N/A * exception.
0N/A *
0N/A * @param e the focus event
0N/A * @see java.awt.event.FocusEvent
0N/A * @see java.awt.event.FocusListener
0N/A * @see java.awt.KeyboardFocusManager
0N/A * @see #addFocusListener
0N/A * @see #enableEvents
0N/A * @see #dispatchEvent
0N/A * @since JDK1.1
0N/A */
0N/A protected void processFocusEvent(FocusEvent e) {
0N/A FocusListener listener = focusListener;
0N/A if (listener != null) {
0N/A int id = e.getID();
0N/A switch(id) {
0N/A case FocusEvent.FOCUS_GAINED:
0N/A listener.focusGained(e);
0N/A break;
0N/A case FocusEvent.FOCUS_LOST:
0N/A listener.focusLost(e);
0N/A break;
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Processes key events occurring on this component by
0N/A * dispatching them to any registered
0N/A * <code>KeyListener</code> objects.
0N/A * <p>
0N/A * This method is not called unless key events are
0N/A * enabled for this component. Key events are enabled
0N/A * when one of the following occurs:
0N/A * <p><ul>
0N/A * <li>A <code>KeyListener</code> object is registered
0N/A * via <code>addKeyListener</code>.
0N/A * <li>Key events are enabled via <code>enableEvents</code>.
0N/A * </ul>
0N/A *
0N/A * <p>
0N/A * If key events are enabled for a <code>Component</code>,
0N/A * the current <code>KeyboardFocusManager</code> determines
0N/A * whether or not a key event should be dispatched to
0N/A * registered <code>KeyListener</code> objects. The
0N/A * <code>DefaultKeyboardFocusManager</code> will not dispatch
0N/A * key events to a <code>Component</code> that is not the focus
0N/A * owner or is not showing.
0N/A * <p>
0N/A * As of J2SE 1.4, <code>KeyEvent</code>s are redirected to
0N/A * the focus owner. Please see the
0N/A * <a href="doc-files/FocusSpec.html">Focus Specification</a>
0N/A * for further information.
0N/A * <p>
0N/A * Calling a <code>Component</code>'s <code>dispatchEvent</code>
0N/A * method with a <code>KeyEvent</code> as the argument will
0N/A * result in a call to the <code>Component</code>'s
0N/A * <code>processKeyEvent</code> method regardless of the
0N/A * current <code>KeyboardFocusManager</code> as long as the
0N/A * component is showing, focused, and enabled, and key events
0N/A * are enabled on it.
0N/A * <p>If the event parameter is <code>null</code>
0N/A * the behavior is unspecified and may result in an
0N/A * exception.
0N/A *
0N/A * @param e the key event
0N/A * @see java.awt.event.KeyEvent
0N/A * @see java.awt.event.KeyListener
0N/A * @see java.awt.KeyboardFocusManager
0N/A * @see java.awt.DefaultKeyboardFocusManager
0N/A * @see #processEvent
0N/A * @see #dispatchEvent
0N/A * @see #addKeyListener
0N/A * @see #enableEvents
0N/A * @see #isShowing
0N/A * @since JDK1.1
0N/A */
0N/A protected void processKeyEvent(KeyEvent e) {
0N/A KeyListener listener = keyListener;
0N/A if (listener != null) {
0N/A int id = e.getID();
0N/A switch(id) {
0N/A case KeyEvent.KEY_TYPED:
0N/A listener.keyTyped(e);
0N/A break;
0N/A case KeyEvent.KEY_PRESSED:
0N/A listener.keyPressed(e);
0N/A break;
0N/A case KeyEvent.KEY_RELEASED:
0N/A listener.keyReleased(e);
0N/A break;
0N/A }
0N/A }
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.
0N/A * <p>
0N/A * This method is not called unless mouse events are
0N/A * enabled for this component. Mouse events are enabled
0N/A * when one of the following occurs:
0N/A * <p><ul>
0N/A * <li>A <code>MouseListener</code> object is registered
0N/A * via <code>addMouseListener</code>.
0N/A * <li>Mouse events are enabled via <code>enableEvents</code>.
0N/A * </ul>
0N/A * <p>Note that if the event parameter is <code>null</code>
0N/A * the behavior is unspecified and may result in an
0N/A * exception.
0N/A *
0N/A * @param e the mouse event
0N/A * @see java.awt.event.MouseEvent
0N/A * @see java.awt.event.MouseListener
0N/A * @see #addMouseListener
0N/A * @see #enableEvents
0N/A * @since JDK1.1
0N/A */
0N/A protected void processMouseEvent(MouseEvent e) {
0N/A MouseListener listener = mouseListener;
0N/A if (listener != null) {
0N/A int id = e.getID();
0N/A switch(id) {
0N/A case MouseEvent.MOUSE_PRESSED:
0N/A listener.mousePressed(e);
0N/A break;
0N/A case MouseEvent.MOUSE_RELEASED:
0N/A listener.mouseReleased(e);
0N/A break;
0N/A case MouseEvent.MOUSE_CLICKED:
0N/A listener.mouseClicked(e);
0N/A break;
0N/A case MouseEvent.MOUSE_EXITED:
0N/A listener.mouseExited(e);
0N/A break;
0N/A case MouseEvent.MOUSE_ENTERED:
0N/A listener.mouseEntered(e);
0N/A break;
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Processes mouse motion events occurring on this component by
0N/A * dispatching them to any registered
0N/A * <code>MouseMotionListener</code> objects.
0N/A * <p>
0N/A * This method is not called unless mouse motion events are
0N/A * enabled for this component. Mouse motion events are enabled
0N/A * when one of the following occurs:
0N/A * <p><ul>
0N/A * <li>A <code>MouseMotionListener</code> object is registered
0N/A * via <code>addMouseMotionListener</code>.
0N/A * <li>Mouse motion events are enabled via <code>enableEvents</code>.
0N/A * </ul>
0N/A * <p>Note that if the event parameter is <code>null</code>
0N/A * the behavior is unspecified and may result in an
0N/A * exception.
0N/A *
0N/A * @param e the mouse motion event
0N/A * @see java.awt.event.MouseEvent
0N/A * @see java.awt.event.MouseMotionListener
0N/A * @see #addMouseMotionListener
0N/A * @see #enableEvents
0N/A * @since JDK1.1
0N/A */
0N/A protected void processMouseMotionEvent(MouseEvent e) {
0N/A MouseMotionListener listener = mouseMotionListener;
0N/A if (listener != null) {
0N/A int id = e.getID();
0N/A switch(id) {
0N/A case MouseEvent.MOUSE_MOVED:
0N/A listener.mouseMoved(e);
0N/A break;
0N/A case MouseEvent.MOUSE_DRAGGED:
0N/A listener.mouseDragged(e);
0N/A break;
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Processes mouse wheel events occurring on this component by
0N/A * dispatching them to any registered
0N/A * <code>MouseWheelListener</code> objects.
0N/A * <p>
0N/A * This method is not called unless mouse wheel events are
0N/A * enabled for this component. Mouse wheel events are enabled
0N/A * when one of the following occurs:
0N/A * <p><ul>
0N/A * <li>A <code>MouseWheelListener</code> object is registered
0N/A * via <code>addMouseWheelListener</code>.
0N/A * <li>Mouse wheel events are enabled via <code>enableEvents</code>.
0N/A * </ul>
0N/A * <p>
0N/A * For information on how mouse wheel events are dispatched, see
0N/A * the class description for {@link MouseWheelEvent}.
0N/A * <p>
0N/A * Note that if the event parameter is <code>null</code>
0N/A * the behavior is unspecified and may result in an
0N/A * exception.
0N/A *
0N/A * @param e the mouse wheel event
0N/A * @see java.awt.event.MouseWheelEvent
0N/A * @see java.awt.event.MouseWheelListener
0N/A * @see #addMouseWheelListener
0N/A * @see #enableEvents
0N/A * @since 1.4
0N/A */
0N/A protected void processMouseWheelEvent(MouseWheelEvent e) {
0N/A MouseWheelListener listener = mouseWheelListener;
0N/A if (listener != null) {
0N/A int id = e.getID();
0N/A switch(id) {
0N/A case MouseEvent.MOUSE_WHEEL:
0N/A listener.mouseWheelMoved(e);
0N/A break;
0N/A }
0N/A }
0N/A }
0N/A
0N/A boolean postsOldMouseEvents() {
0N/A return false;
0N/A }
0N/A
0N/A /**
0N/A * Processes input method events occurring on this component by
0N/A * dispatching them to any registered
0N/A * <code>InputMethodListener</code> objects.
0N/A * <p>
0N/A * This method is not called unless input method events
0N/A * are enabled for this component. Input method events are enabled
0N/A * when one of the following occurs:
0N/A * <p><ul>
0N/A * <li>An <code>InputMethodListener</code> object is registered
0N/A * via <code>addInputMethodListener</code>.
0N/A * <li>Input method events are enabled via <code>enableEvents</code>.
0N/A * </ul>
0N/A * <p>Note that if the event parameter is <code>null</code>
0N/A * the behavior is unspecified and may result in an
0N/A * exception.
0N/A *
0N/A * @param e the input method event
0N/A * @see java.awt.event.InputMethodEvent
0N/A * @see java.awt.event.InputMethodListener
0N/A * @see #addInputMethodListener
0N/A * @see #enableEvents
0N/A * @since 1.2
0N/A */
0N/A protected void processInputMethodEvent(InputMethodEvent e) {
0N/A InputMethodListener listener = inputMethodListener;
0N/A if (listener != null) {
0N/A int id = e.getID();
0N/A switch (id) {
0N/A case InputMethodEvent.INPUT_METHOD_TEXT_CHANGED:
0N/A listener.inputMethodTextChanged(e);
0N/A break;
0N/A case InputMethodEvent.CARET_POSITION_CHANGED:
0N/A listener.caretPositionChanged(e);
0N/A break;
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Processes hierarchy events occurring on this component by
0N/A * dispatching them to any registered
0N/A * <code>HierarchyListener</code> objects.
0N/A * <p>
0N/A * This method is not called unless hierarchy events
0N/A * are enabled for this component. Hierarchy events are enabled
0N/A * when one of the following occurs:
0N/A * <p><ul>
0N/A * <li>An <code>HierarchyListener</code> object is registered
0N/A * via <code>addHierarchyListener</code>.
0N/A * <li>Hierarchy events are enabled via <code>enableEvents</code>.
0N/A * </ul>
0N/A * <p>Note that if the event parameter is <code>null</code>
0N/A * the behavior is unspecified and may result in an
0N/A * exception.
0N/A *
0N/A * @param e the hierarchy event
0N/A * @see java.awt.event.HierarchyEvent
0N/A * @see java.awt.event.HierarchyListener
0N/A * @see #addHierarchyListener
0N/A * @see #enableEvents
0N/A * @since 1.3
0N/A */
0N/A protected void processHierarchyEvent(HierarchyEvent e) {
0N/A HierarchyListener listener = hierarchyListener;
0N/A if (listener != null) {
0N/A int id = e.getID();
0N/A switch (id) {
0N/A case HierarchyEvent.HIERARCHY_CHANGED:
0N/A listener.hierarchyChanged(e);
0N/A break;
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Processes hierarchy bounds events occurring on this component by
0N/A * dispatching them to any registered
0N/A * <code>HierarchyBoundsListener</code> objects.
0N/A * <p>
0N/A * This method is not called unless hierarchy bounds events
0N/A * are enabled for this component. Hierarchy bounds events are enabled
0N/A * when one of the following occurs:
0N/A * <p><ul>
0N/A * <li>An <code>HierarchyBoundsListener</code> object is registered
0N/A * via <code>addHierarchyBoundsListener</code>.
0N/A * <li>Hierarchy bounds events are enabled via <code>enableEvents</code>.
0N/A * </ul>
0N/A * <p>Note that if the event parameter is <code>null</code>
0N/A * the behavior is unspecified and may result in an
0N/A * exception.
0N/A *
0N/A * @param e the hierarchy event
0N/A * @see java.awt.event.HierarchyEvent
0N/A * @see java.awt.event.HierarchyBoundsListener
0N/A * @see #addHierarchyBoundsListener
0N/A * @see #enableEvents
0N/A * @since 1.3
0N/A */
0N/A protected void processHierarchyBoundsEvent(HierarchyEvent e) {
0N/A HierarchyBoundsListener listener = hierarchyBoundsListener;
0N/A if (listener != null) {
0N/A int id = e.getID();
0N/A switch (id) {
0N/A case HierarchyEvent.ANCESTOR_MOVED:
0N/A listener.ancestorMoved(e);
0N/A break;
0N/A case HierarchyEvent.ANCESTOR_RESIZED:
0N/A listener.ancestorResized(e);
0N/A break;
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1
0N/A * replaced by processEvent(AWTEvent).
0N/A */
0N/A @Deprecated
0N/A public boolean handleEvent(Event evt) {
0N/A switch (evt.id) {
0N/A case Event.MOUSE_ENTER:
0N/A return mouseEnter(evt, evt.x, evt.y);
0N/A
0N/A case Event.MOUSE_EXIT:
0N/A return mouseExit(evt, evt.x, evt.y);
0N/A
0N/A case Event.MOUSE_MOVE:
0N/A return mouseMove(evt, evt.x, evt.y);
0N/A
0N/A case Event.MOUSE_DOWN:
0N/A return mouseDown(evt, evt.x, evt.y);
0N/A
0N/A case Event.MOUSE_DRAG:
0N/A return mouseDrag(evt, evt.x, evt.y);
0N/A
0N/A case Event.MOUSE_UP:
0N/A return mouseUp(evt, evt.x, evt.y);
0N/A
0N/A case Event.KEY_PRESS:
0N/A case Event.KEY_ACTION:
0N/A return keyDown(evt, evt.key);
0N/A
0N/A case Event.KEY_RELEASE:
0N/A case Event.KEY_ACTION_RELEASE:
0N/A return keyUp(evt, evt.key);
0N/A
0N/A case Event.ACTION_EVENT:
0N/A return action(evt, evt.arg);
0N/A case Event.GOT_FOCUS:
0N/A return gotFocus(evt, evt.arg);
0N/A case Event.LOST_FOCUS:
0N/A return lostFocus(evt, evt.arg);
0N/A }
0N/A return false;
0N/A }
0N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1,
0N/A * replaced by processMouseEvent(MouseEvent).
0N/A */
0N/A @Deprecated
0N/A public boolean mouseDown(Event evt, int x, int y) {
0N/A return false;
0N/A }
0N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1,
0N/A * replaced by processMouseMotionEvent(MouseEvent).
0N/A */
0N/A @Deprecated
0N/A public boolean mouseDrag(Event evt, int x, int y) {
0N/A return false;
0N/A }
0N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1,
0N/A * replaced by processMouseEvent(MouseEvent).
0N/A */
0N/A @Deprecated
0N/A public boolean mouseUp(Event evt, int x, int y) {
0N/A return false;
0N/A }
0N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1,
0N/A * replaced by processMouseMotionEvent(MouseEvent).
0N/A */
0N/A @Deprecated
0N/A public boolean mouseMove(Event evt, int x, int y) {
0N/A return false;
0N/A }
0N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1,
0N/A * replaced by processMouseEvent(MouseEvent).
0N/A */
0N/A @Deprecated
0N/A public boolean mouseEnter(Event evt, int x, int y) {
0N/A return false;
0N/A }
0N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1,
0N/A * replaced by processMouseEvent(MouseEvent).
0N/A */
0N/A @Deprecated
0N/A public boolean mouseExit(Event evt, int x, int y) {
0N/A return false;
0N/A }
0N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1,
0N/A * replaced by processKeyEvent(KeyEvent).
0N/A */
0N/A @Deprecated
0N/A public boolean keyDown(Event evt, int key) {
0N/A return false;
0N/A }
0N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1,
0N/A * replaced by processKeyEvent(KeyEvent).
0N/A */
0N/A @Deprecated
0N/A public boolean keyUp(Event evt, int key) {
0N/A return false;
0N/A }
0N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1,
0N/A * should register this component as ActionListener on component
0N/A * which fires action events.
0N/A */
0N/A @Deprecated
0N/A public boolean action(Event evt, Object what) {
0N/A return false;
0N/A }
0N/A
0N/A /**
0N/A * Makes this <code>Component</code> displayable by connecting it to a
0N/A * native screen resource.
0N/A * This method is called internally by the toolkit and should
0N/A * not be called directly by programs.
0N/A * @see #isDisplayable
0N/A * @see #removeNotify
0N/A * @since JDK1.0
0N/A */
0N/A public void addNotify() {
0N/A synchronized (getTreeLock()) {
0N/A ComponentPeer peer = this.peer;
0N/A if (peer == null || peer instanceof LightweightPeer){
0N/A if (peer == null) {
0N/A // Update both the Component's peer variable and the local
0N/A // variable we use for thread safety.
0N/A this.peer = peer = getToolkit().createComponent(this);
0N/A }
0N/A
0N/A // This is a lightweight component which means it won't be
0N/A // able to get window-related events by itself. If any
0N/A // have been enabled, then the nearest native container must
0N/A // be enabled.
0N/A if (parent != null) {
0N/A long mask = 0;
0N/A if ((mouseListener != null) || ((eventMask & AWTEvent.MOUSE_EVENT_MASK) != 0)) {
0N/A mask |= AWTEvent.MOUSE_EVENT_MASK;
0N/A }
0N/A if ((mouseMotionListener != null) ||
0N/A ((eventMask & AWTEvent.MOUSE_MOTION_EVENT_MASK) != 0)) {
0N/A mask |= AWTEvent.MOUSE_MOTION_EVENT_MASK;
0N/A }
0N/A if ((mouseWheelListener != null ) ||
0N/A ((eventMask & AWTEvent.MOUSE_WHEEL_EVENT_MASK) != 0)) {
0N/A mask |= AWTEvent.MOUSE_WHEEL_EVENT_MASK;
0N/A }
0N/A if (focusListener != null || (eventMask & AWTEvent.FOCUS_EVENT_MASK) != 0) {
0N/A mask |= AWTEvent.FOCUS_EVENT_MASK;
0N/A }
0N/A if (keyListener != null || (eventMask & AWTEvent.KEY_EVENT_MASK) != 0) {
0N/A mask |= AWTEvent.KEY_EVENT_MASK;
0N/A }
0N/A if (mask != 0) {
0N/A parent.proxyEnableEvents(mask);
0N/A }
0N/A }
0N/A } else {
0N/A // It's native. If the parent is lightweight it
0N/A // will need some help.
0N/A Container parent = this.parent;
0N/A if (parent != null && parent.peer instanceof LightweightPeer) {
107N/A relocateComponent();
0N/A }
0N/A }
0N/A invalidate();
0N/A
0N/A int npopups = (popups != null? popups.size() : 0);
0N/A for (int i = 0 ; i < npopups ; i++) {
0N/A PopupMenu popup = (PopupMenu)popups.elementAt(i);
0N/A popup.addNotify();
0N/A }
0N/A
0N/A if (dropTarget != null) dropTarget.addNotify(peer);
0N/A
0N/A peerFont = getFont();
0N/A
0N/A if (getContainer() != null && !isAddNotifyComplete) {
0N/A getContainer().increaseComponentCount(this);
0N/A }
0N/A
0N/A
0N/A // Update stacking order
0N/A if (parent != null && parent.peer != null) {
0N/A ContainerPeer parentContPeer = (ContainerPeer) parent.peer;
0N/A // if our parent is lightweight and we are not
0N/A // we should call restack on nearest heavyweight
0N/A // container.
0N/A if (parentContPeer instanceof LightweightPeer
0N/A && ! (peer instanceof LightweightPeer))
0N/A {
0N/A Container hwParent = getNativeContainer();
0N/A if (hwParent != null && hwParent.peer != null) {
0N/A parentContPeer = (ContainerPeer) hwParent.peer;
0N/A }
0N/A }
0N/A if (parentContPeer.isRestackSupported()) {
0N/A parentContPeer.restack();
0N/A }
0N/A }
0N/A
0N/A if (!isAddNotifyComplete) {
0N/A addPropertyChangeListener("opaque", opaquePropertyChangeListener);
0N/A mixOnShowing();
0N/A }
0N/A
0N/A isAddNotifyComplete = true;
0N/A
0N/A if (hierarchyListener != null ||
0N/A (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0 ||
0N/A Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK)) {
0N/A HierarchyEvent e =
0N/A new HierarchyEvent(this, HierarchyEvent.HIERARCHY_CHANGED,
0N/A this, parent,
0N/A HierarchyEvent.DISPLAYABILITY_CHANGED |
0N/A ((isRecursivelyVisible())
0N/A ? HierarchyEvent.SHOWING_CHANGED
0N/A : 0));
0N/A dispatchEvent(e);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Makes this <code>Component</code> undisplayable by destroying it native
0N/A * screen resource.
0N/A * <p>
0N/A * This method is called by the toolkit internally and should
0N/A * not be called directly by programs. Code overriding
0N/A * this method should call <code>super.removeNotify</code> as
0N/A * the first line of the overriding method.
0N/A *
0N/A * @see #isDisplayable
0N/A * @see #addNotify
0N/A * @since JDK1.0
0N/A */
0N/A public void removeNotify() {
0N/A KeyboardFocusManager.clearMostRecentFocusOwner(this);
0N/A if (KeyboardFocusManager.getCurrentKeyboardFocusManager().
0N/A getPermanentFocusOwner() == this)
0N/A {
0N/A KeyboardFocusManager.getCurrentKeyboardFocusManager().
0N/A setGlobalPermanentFocusOwner(null);
0N/A }
0N/A
0N/A synchronized (getTreeLock()) {
218N/A if (isFocusOwner() && KeyboardFocusManager.isAutoFocusTransferEnabledFor(this)) {
218N/A transferFocus(true);
0N/A }
0N/A
0N/A if (getContainer() != null && isAddNotifyComplete) {
0N/A getContainer().decreaseComponentCount(this);
0N/A }
0N/A
0N/A int npopups = (popups != null? popups.size() : 0);
0N/A for (int i = 0 ; i < npopups ; i++) {
0N/A PopupMenu popup = (PopupMenu)popups.elementAt(i);
0N/A popup.removeNotify();
0N/A }
0N/A // If there is any input context for this component, notify
0N/A // that this component is being removed. (This has to be done
0N/A // before hiding peer.)
0N/A if ((eventMask & AWTEvent.INPUT_METHODS_ENABLED_MASK) != 0) {
0N/A InputContext inputContext = getInputContext();
0N/A if (inputContext != null) {
0N/A inputContext.removeNotify(this);
0N/A }
0N/A }
0N/A
0N/A ComponentPeer p = peer;
0N/A if (p != null) {
0N/A boolean isLightweight = isLightweight();
0N/A
0N/A if (bufferStrategy instanceof FlipBufferStrategy) {
0N/A ((FlipBufferStrategy)bufferStrategy).destroyBuffers();
0N/A }
0N/A
0N/A if (dropTarget != null) dropTarget.removeNotify(peer);
0N/A
0N/A // Hide peer first to stop system events such as cursor moves.
0N/A if (visible) {
0N/A p.hide();
0N/A }
0N/A
0N/A peer = null; // Stop peer updates.
0N/A peerFont = null;
0N/A
0N/A Toolkit.getEventQueue().removeSourceEvents(this, false);
0N/A KeyboardFocusManager.getCurrentKeyboardFocusManager().
0N/A discardKeyEvents(this);
0N/A
0N/A p.dispose();
0N/A
0N/A mixOnHiding(isLightweight);
0N/A removePropertyChangeListener("opaque", opaquePropertyChangeListener);
0N/A
0N/A isAddNotifyComplete = false;
0N/A }
0N/A
0N/A if (hierarchyListener != null ||
0N/A (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0 ||
0N/A Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK)) {
0N/A HierarchyEvent e =
0N/A new HierarchyEvent(this, HierarchyEvent.HIERARCHY_CHANGED,
0N/A this, parent,
0N/A HierarchyEvent.DISPLAYABILITY_CHANGED |
0N/A ((isRecursivelyVisible())
0N/A ? HierarchyEvent.SHOWING_CHANGED
0N/A : 0));
0N/A dispatchEvent(e);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1,
0N/A * replaced by processFocusEvent(FocusEvent).
0N/A */
0N/A @Deprecated
0N/A public boolean gotFocus(Event evt, Object what) {
0N/A return false;
0N/A }
0N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1,
0N/A * replaced by processFocusEvent(FocusEvent).
0N/A */
0N/A @Deprecated
0N/A public boolean lostFocus(Event evt, Object what) {
0N/A return false;
0N/A }
0N/A
0N/A /**
0N/A * Returns whether this <code>Component</code> can become the focus
0N/A * owner.
0N/A *
0N/A * @return <code>true</code> if this <code>Component</code> is
0N/A * focusable; <code>false</code> otherwise
0N/A * @see #setFocusable
0N/A * @since JDK1.1
0N/A * @deprecated As of 1.4, replaced by <code>isFocusable()</code>.
0N/A */
0N/A @Deprecated
0N/A public boolean isFocusTraversable() {
0N/A if (isFocusTraversableOverridden == FOCUS_TRAVERSABLE_UNKNOWN) {
0N/A isFocusTraversableOverridden = FOCUS_TRAVERSABLE_DEFAULT;
0N/A }
0N/A return focusable;
0N/A }
0N/A
0N/A /**
0N/A * Returns whether this Component can be focused.
0N/A *
0N/A * @return <code>true</code> if this Component is focusable;
0N/A * <code>false</code> otherwise.
0N/A * @see #setFocusable
0N/A * @since 1.4
0N/A */
0N/A public boolean isFocusable() {
0N/A return isFocusTraversable();
0N/A }
0N/A
0N/A /**
0N/A * Sets the focusable state of this Component to the specified value. This
0N/A * value overrides the Component's default focusability.
0N/A *
0N/A * @param focusable indicates whether this Component is focusable
0N/A * @see #isFocusable
0N/A * @since 1.4
0N/A * @beaninfo
0N/A * bound: true
0N/A */
0N/A public void setFocusable(boolean focusable) {
0N/A boolean oldFocusable;
0N/A synchronized (this) {
0N/A oldFocusable = this.focusable;
0N/A this.focusable = focusable;
0N/A }
0N/A isFocusTraversableOverridden = FOCUS_TRAVERSABLE_SET;
0N/A
0N/A firePropertyChange("focusable", oldFocusable, focusable);
0N/A if (oldFocusable && !focusable) {
218N/A if (isFocusOwner() && KeyboardFocusManager.isAutoFocusTransferEnabled()) {
218N/A transferFocus(true);
0N/A }
0N/A KeyboardFocusManager.clearMostRecentFocusOwner(this);
0N/A }
0N/A }
0N/A
0N/A final boolean isFocusTraversableOverridden() {
0N/A return (isFocusTraversableOverridden != FOCUS_TRAVERSABLE_DEFAULT);
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 * <p>
0N/A * The default values for a Component's focus traversal keys are
0N/A * implementation-dependent. Sun recommends that all implementations for a
0N/A * particular native platform use the same default values. The
0N/A * recommendations for Windows and Unix are listed below. These
0N/A * recommendations are used in the Sun AWT implementations.
0N/A *
0N/A * <table border=1 summary="Recommended default values for a Component's focus traversal keys">
0N/A * <tr>
0N/A * <th>Identifier</th>
0N/A * <th>Meaning</th>
0N/A * <th>Default</th>
0N/A * </tr>
0N/A * <tr>
0N/A * <td>KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS</td>
0N/A * <td>Normal forward keyboard traversal</td>
0N/A * <td>TAB on KEY_PRESSED, CTRL-TAB on KEY_PRESSED</td>
0N/A * </tr>
0N/A * <tr>
0N/A * <td>KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS</td>
0N/A * <td>Normal reverse keyboard traversal</td>
0N/A * <td>SHIFT-TAB on KEY_PRESSED, CTRL-SHIFT-TAB on KEY_PRESSED</td>
0N/A * </tr>
0N/A * <tr>
0N/A * <td>KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS</td>
0N/A * <td>Go up one focus traversal cycle</td>
0N/A * <td>none</td>
0N/A * </tr>
0N/A * </table>
0N/A *
0N/A * To disable a traversal key, use an empty Set; Collections.EMPTY_SET is
0N/A * recommended.
0N/A * <p>
0N/A * Using the AWTKeyStroke API, client code can specify on which of two
0N/A * specific KeyEvents, KEY_PRESSED or KEY_RELEASED, the focus traversal
0N/A * operation will occur. Regardless of which KeyEvent is specified,
0N/A * however, all KeyEvents related to the focus traversal key, including the
0N/A * associated KEY_TYPED event, will be consumed, and will not be dispatched
0N/A * to any Component. It is a runtime error to specify a KEY_TYPED event as
0N/A * mapping to a focus traversal operation, or to map the same event to
0N/A * multiple default focus traversal operations.
0N/A * <p>
0N/A * If a value of null is specified for the Set, this Component inherits the
0N/A * Set from its parent. If all ancestors of this Component have null
0N/A * specified for the Set, then the current KeyboardFocusManager's default
0N/A * Set is used.
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 #getFocusTraversalKeys
0N/A * @see KeyboardFocusManager#FORWARD_TRAVERSAL_KEYS
0N/A * @see KeyboardFocusManager#BACKWARD_TRAVERSAL_KEYS
0N/A * @see 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.4
0N/A * @beaninfo
0N/A * bound: true
0N/A */
0N/A public void setFocusTraversalKeys(int id,
0N/A Set<? extends AWTKeyStroke> keystrokes)
0N/A {
0N/A if (id < 0 || id >= KeyboardFocusManager.TRAVERSAL_KEY_LENGTH - 1) {
0N/A throw new IllegalArgumentException("invalid focus traversal key identifier");
0N/A }
0N/A
0N/A setFocusTraversalKeys_NoIDCheck(id, keystrokes);
0N/A }
0N/A
0N/A /**
0N/A * Returns the Set of focus traversal keys for a given traversal operation
0N/A * for this Component. (See
0N/A * <code>setFocusTraversalKeys</code> for a full description of each key.)
0N/A * <p>
0N/A * If a Set of traversal keys has not been explicitly defined for this
0N/A * Component, then this Component's parent's Set is returned. If no Set
0N/A * has been explicitly defined for any of this Component's ancestors, then
0N/A * the current KeyboardFocusManager's default Set is returned.
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 * @return the Set of AWTKeyStrokes for the specified operation. The Set
0N/A * will be unmodifiable, and may be empty. null will never be
0N/A * returned.
0N/A * @see #setFocusTraversalKeys
0N/A * @see KeyboardFocusManager#FORWARD_TRAVERSAL_KEYS
0N/A * @see KeyboardFocusManager#BACKWARD_TRAVERSAL_KEYS
0N/A * @see 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
0N/A * @since 1.4
0N/A */
0N/A public Set<AWTKeyStroke> getFocusTraversalKeys(int id) {
0N/A if (id < 0 || id >= KeyboardFocusManager.TRAVERSAL_KEY_LENGTH - 1) {
0N/A throw new IllegalArgumentException("invalid focus traversal key identifier");
0N/A }
0N/A
0N/A return getFocusTraversalKeys_NoIDCheck(id);
0N/A }
0N/A
0N/A // We define these methods so that Container does not need to repeat this
0N/A // code. Container cannot call super.<method> because Container allows
0N/A // DOWN_CYCLE_TRAVERSAL_KEY while Component does not. The Component method
0N/A // would erroneously generate an IllegalArgumentException for
0N/A // DOWN_CYCLE_TRAVERSAL_KEY.
0N/A final void setFocusTraversalKeys_NoIDCheck(int id, Set<? extends AWTKeyStroke> keystrokes) {
0N/A Set oldKeys;
0N/A
0N/A synchronized (this) {
0N/A if (focusTraversalKeys == null) {
0N/A initializeFocusTraversalKeys();
0N/A }
0N/A
0N/A if (keystrokes != null) {
0N/A for (Iterator iter = keystrokes.iterator(); iter.hasNext(); ) {
0N/A Object obj = iter.next();
0N/A
0N/A if (obj == null) {
0N/A throw new IllegalArgumentException("cannot set null focus traversal key");
0N/A }
0N/A
0N/A // Fix for 6195828:
0N/A //According to javadoc this method should throw IAE instead of ClassCastException
0N/A if (!(obj instanceof AWTKeyStroke)) {
0N/A throw new IllegalArgumentException("object is expected to be AWTKeyStroke");
0N/A }
0N/A AWTKeyStroke keystroke = (AWTKeyStroke)obj;
0N/A
0N/A if (keystroke.getKeyChar() != KeyEvent.CHAR_UNDEFINED) {
0N/A throw new IllegalArgumentException("focus traversal keys cannot map to KEY_TYPED events");
0N/A }
0N/A
0N/A for (int i = 0; i < focusTraversalKeys.length; i++) {
0N/A if (i == id) {
0N/A continue;
0N/A }
0N/A
0N/A if (getFocusTraversalKeys_NoIDCheck(i).contains(keystroke))
0N/A {
0N/A throw new IllegalArgumentException("focus traversal keys must be unique for a Component");
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A oldKeys = focusTraversalKeys[id];
0N/A focusTraversalKeys[id] = (keystrokes != null)
0N/A ? Collections.unmodifiableSet(new HashSet(keystrokes))
0N/A : null;
0N/A }
0N/A
0N/A firePropertyChange(focusTraversalKeyPropertyNames[id], oldKeys,
0N/A keystrokes);
0N/A }
0N/A final Set getFocusTraversalKeys_NoIDCheck(int id) {
0N/A // Okay to return Set directly because it is an unmodifiable view
0N/A Set keystrokes = (focusTraversalKeys != null)
0N/A ? focusTraversalKeys[id]
0N/A : null;
0N/A
0N/A if (keystrokes != null) {
0N/A return keystrokes;
0N/A } else {
0N/A Container parent = this.parent;
0N/A if (parent != null) {
0N/A return parent.getFocusTraversalKeys(id);
0N/A } else {
0N/A return KeyboardFocusManager.getCurrentKeyboardFocusManager().
0N/A getDefaultFocusTraversalKeys(id);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns whether the Set of focus traversal keys for the given focus
0N/A * traversal operation has been explicitly defined for this Component. If
0N/A * this method returns <code>false</code>, this Component is inheriting the
0N/A * Set from an ancestor, or from the current KeyboardFocusManager.
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 * @return <code>true</code> if the the Set of focus traversal keys for the
0N/A * given focus traversal operation has been explicitly defined for
0N/A * this Component; <code>false</code> otherwise.
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
0N/A * @since 1.4
0N/A */
0N/A public boolean areFocusTraversalKeysSet(int id) {
0N/A if (id < 0 || id >= KeyboardFocusManager.TRAVERSAL_KEY_LENGTH - 1) {
0N/A throw new IllegalArgumentException("invalid focus traversal key identifier");
0N/A }
0N/A
0N/A return (focusTraversalKeys != null && focusTraversalKeys[id] != null);
0N/A }
0N/A
0N/A /**
0N/A * Sets whether focus traversal keys are enabled for this Component.
0N/A * Components for which focus traversal keys are disabled receive key
0N/A * events for focus traversal keys. Components for which focus traversal
0N/A * keys are enabled do not see these events; instead, the events are
0N/A * automatically converted to traversal operations.
0N/A *
0N/A * @param focusTraversalKeysEnabled whether focus traversal keys are
0N/A * enabled for this Component
0N/A * @see #getFocusTraversalKeysEnabled
0N/A * @see #setFocusTraversalKeys
0N/A * @see #getFocusTraversalKeys
0N/A * @since 1.4
0N/A * @beaninfo
0N/A * bound: true
0N/A */
0N/A public void setFocusTraversalKeysEnabled(boolean
0N/A focusTraversalKeysEnabled) {
0N/A boolean oldFocusTraversalKeysEnabled;
0N/A synchronized (this) {
0N/A oldFocusTraversalKeysEnabled = this.focusTraversalKeysEnabled;
0N/A this.focusTraversalKeysEnabled = focusTraversalKeysEnabled;
0N/A }
0N/A firePropertyChange("focusTraversalKeysEnabled",
0N/A oldFocusTraversalKeysEnabled,
0N/A focusTraversalKeysEnabled);
0N/A }
0N/A
0N/A /**
0N/A * Returns whether focus traversal keys are enabled for this Component.
0N/A * Components for which focus traversal keys are disabled receive key
0N/A * events for focus traversal keys. Components for which focus traversal
0N/A * keys are enabled do not see these events; instead, the events are
0N/A * automatically converted to traversal operations.
0N/A *
0N/A * @return whether focus traversal keys are enabled for this Component
0N/A * @see #setFocusTraversalKeysEnabled
0N/A * @see #setFocusTraversalKeys
0N/A * @see #getFocusTraversalKeys
0N/A * @since 1.4
0N/A */
0N/A public boolean getFocusTraversalKeysEnabled() {
0N/A return focusTraversalKeysEnabled;
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
0N/A * component must be displayable, focusable, visible and all of
0N/A * its ancestors (with the exception of the top-level Window) must
0N/A * be visible for the request to be granted. Every effort will be
0N/A * made to honor the request; however, in some cases it may be
0N/A * impossible to do so. Developers must never assume that this
0N/A * Component is the focus owner until this Component receives a
0N/A * FOCUS_GAINED event. If this request is denied because this
0N/A * Component's top-level Window cannot become the focused Window,
0N/A * the request will be remembered and will be granted when the
0N/A * Window is later focused by the user.
0N/A * <p>
0N/A * This method cannot be used to set the focus owner to no Component at
0N/A * all. Use <code>KeyboardFocusManager.clearGlobalFocusOwner()</code>
0N/A * instead.
0N/A * <p>
0N/A * Because the focus behavior of this method is platform-dependent,
0N/A * developers are strongly encouraged to use
0N/A * <code>requestFocusInWindow</code> when possible.
0N/A *
0N/A * <p>Note: Not all focus transfers result from invoking this method. As
0N/A * such, a component may receive focus without this or any of the other
0N/A * {@code requestFocus} methods of {@code Component} being invoked.
0N/A *
0N/A * @see #requestFocusInWindow
0N/A * @see java.awt.event.FocusEvent
0N/A * @see #addFocusListener
0N/A * @see #isFocusable
0N/A * @see #isDisplayable
0N/A * @see KeyboardFocusManager#clearGlobalFocusOwner
0N/A * @since JDK1.0
0N/A */
0N/A public void requestFocus() {
0N/A requestFocusHelper(false, true);
0N/A }
0N/A
0N/A void requestFocus(CausedFocusEvent.Cause cause) {
0N/A requestFocusHelper(false, true, cause);
0N/A }
0N/A
0N/A /**
0N/A * Requests that this <code>Component</code> get the input focus,
0N/A * and that this <code>Component</code>'s top-level ancestor
0N/A * become the focused <code>Window</code>. This component must be
0N/A * displayable, focusable, visible and all of its ancestors (with
0N/A * the exception of the top-level Window) must be visible for the
0N/A * request to be granted. Every effort will be made to honor the
0N/A * request; however, in some cases it may be impossible to do
0N/A * so. Developers must never assume that this component is the
0N/A * focus owner until this component receives a FOCUS_GAINED
0N/A * event. If this request is denied because this component's
0N/A * top-level window cannot become the focused window, the request
0N/A * will be remembered and will be granted when the window is later
0N/A * focused by the user.
0N/A * <p>
0N/A * This method returns a boolean value. If <code>false</code> is returned,
0N/A * the request is <b>guaranteed to fail</b>. If <code>true</code> is
0N/A * returned, the request will succeed <b>unless</b> it is vetoed, or an
0N/A * extraordinary event, such as disposal of the component's peer, occurs
0N/A * before the request can be granted by the native windowing system. Again,
0N/A * while a return value of <code>true</code> indicates that the request is
0N/A * likely to succeed, developers must never assume that this component is
0N/A * the focus owner until this component receives a FOCUS_GAINED event.
0N/A * <p>
0N/A * This method cannot be used to set the focus owner to no component at
0N/A * all. Use <code>KeyboardFocusManager.clearGlobalFocusOwner</code>
0N/A * instead.
0N/A * <p>
0N/A * Because the focus behavior of this method is platform-dependent,
0N/A * developers are strongly encouraged to use
0N/A * <code>requestFocusInWindow</code> when possible.
0N/A * <p>
0N/A * Every effort will be made to ensure that <code>FocusEvent</code>s
0N/A * generated as a
0N/A * result of this request will have the specified temporary value. However,
0N/A * because specifying an arbitrary temporary state may not be implementable
0N/A * on all native windowing systems, correct behavior for this method can be
0N/A * guaranteed only for lightweight <code>Component</code>s.
0N/A * This method is not intended
0N/A * for general use, but exists instead as a hook for lightweight component
0N/A * libraries, such as Swing.
0N/A *
0N/A * <p>Note: Not all focus transfers result from invoking this method. As
0N/A * such, a component may receive focus without this or any of the other
0N/A * {@code requestFocus} methods of {@code Component} being invoked.
0N/A *
0N/A * @param temporary true if the focus change is temporary,
0N/A * such as when the window loses the focus; for
0N/A * more information on temporary focus changes see the
0N/A *<a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</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.event.FocusEvent
0N/A * @see #addFocusListener
0N/A * @see #isFocusable
0N/A * @see #isDisplayable
0N/A * @see KeyboardFocusManager#clearGlobalFocusOwner
0N/A * @since 1.4
0N/A */
0N/A protected boolean requestFocus(boolean temporary) {
0N/A return requestFocusHelper(temporary, true);
0N/A }
0N/A
0N/A boolean requestFocus(boolean temporary, CausedFocusEvent.Cause cause) {
0N/A return requestFocusHelper(temporary, true, cause);
0N/A }
0N/A /**
0N/A * Requests that this Component get the input focus, if this
0N/A * Component's top-level ancestor is already the focused
0N/A * Window. This component must be displayable, focusable, visible
0N/A * and all of its ancestors (with the exception of the top-level
0N/A * Window) must be visible for the request to be granted. Every
0N/A * effort will be made to honor the request; however, in some
0N/A * cases it may be impossible to do so. Developers must never
0N/A * assume that this Component is the focus owner until this
0N/A * Component receives a FOCUS_GAINED event.
0N/A * <p>
0N/A * This method returns a boolean value. If <code>false</code> is returned,
0N/A * the request is <b>guaranteed to fail</b>. If <code>true</code> is
0N/A * returned, the request will succeed <b>unless</b> it is vetoed, or an
0N/A * extraordinary event, such as disposal of the Component's peer, occurs
0N/A * before the request can be granted by the native windowing system. Again,
0N/A * while a return value of <code>true</code> indicates that the request is
0N/A * likely to succeed, developers must never assume that this Component is
0N/A * the focus owner until this Component receives a FOCUS_GAINED event.
0N/A * <p>
0N/A * This method cannot be used to set the focus owner to no Component at
0N/A * all. Use <code>KeyboardFocusManager.clearGlobalFocusOwner()</code>
0N/A * instead.
0N/A * <p>
0N/A * The focus behavior of this method can be implemented uniformly across
0N/A * platforms, and thus developers are strongly encouraged to use this
0N/A * method over <code>requestFocus</code> when possible. Code which relies
0N/A * on <code>requestFocus</code> may exhibit different focus behavior on
0N/A * different platforms.
0N/A *
0N/A * <p>Note: Not all focus transfers result from invoking this method. As
0N/A * such, a component may receive focus without this or any of the other
0N/A * {@code requestFocus} methods of {@code Component} being invoked.
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 #requestFocus
0N/A * @see java.awt.event.FocusEvent
0N/A * @see #addFocusListener
0N/A * @see #isFocusable
0N/A * @see #isDisplayable
0N/A * @see KeyboardFocusManager#clearGlobalFocusOwner
0N/A * @since 1.4
0N/A */
0N/A public boolean requestFocusInWindow() {
0N/A return requestFocusHelper(false, false);
0N/A }
0N/A
0N/A boolean requestFocusInWindow(CausedFocusEvent.Cause cause) {
0N/A return requestFocusHelper(false, false, cause);
0N/A }
0N/A
0N/A /**
0N/A * Requests that this <code>Component</code> get the input focus,
0N/A * if this <code>Component</code>'s top-level ancestor is already
0N/A * the focused <code>Window</code>. This component must be
0N/A * displayable, focusable, visible and all of its ancestors (with
0N/A * the exception of the top-level Window) must be visible for the
0N/A * request to be granted. Every effort will be made to honor the
0N/A * request; however, in some cases it may be impossible to do
0N/A * so. Developers must never assume that this component is the
0N/A * focus owner until this component receives a FOCUS_GAINED event.
0N/A * <p>
0N/A * This method returns a boolean value. If <code>false</code> is returned,
0N/A * the request is <b>guaranteed to fail</b>. If <code>true</code> is
0N/A * returned, the request will succeed <b>unless</b> it is vetoed, or an
0N/A * extraordinary event, such as disposal of the component's peer, occurs
0N/A * before the request can be granted by the native windowing system. Again,
0N/A * while a return value of <code>true</code> indicates that the request is
0N/A * likely to succeed, developers must never assume that this component is
0N/A * the focus owner until this component receives a FOCUS_GAINED event.
0N/A * <p>
0N/A * This method cannot be used to set the focus owner to no component at
0N/A * all. Use <code>KeyboardFocusManager.clearGlobalFocusOwner</code>
0N/A * instead.
0N/A * <p>
0N/A * The focus behavior of this method can be implemented uniformly across
0N/A * platforms, and thus developers are strongly encouraged to use this
0N/A * method over <code>requestFocus</code> when possible. Code which relies
0N/A * on <code>requestFocus</code> may exhibit different focus behavior on
0N/A * different platforms.
0N/A * <p>
0N/A * Every effort will be made to ensure that <code>FocusEvent</code>s
0N/A * generated as a
0N/A * result of this request will have the specified temporary value. However,
0N/A * because specifying an arbitrary temporary state may not be implementable
0N/A * on all native windowing systems, correct behavior for this method can be
0N/A * guaranteed only for lightweight components. This method is not intended
0N/A * for general use, but exists instead as a hook for lightweight component
0N/A * libraries, such as Swing.
0N/A *
0N/A * <p>Note: Not all focus transfers result from invoking this method. As
0N/A * such, a component may receive focus without this or any of the other
0N/A * {@code requestFocus} methods of {@code Component} being invoked.
0N/A *
0N/A * @param temporary true if the focus change is temporary,
0N/A * such as when the window loses the focus; for
0N/A * more information on temporary focus changes see the
0N/A *<a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</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 #requestFocus
0N/A * @see java.awt.event.FocusEvent
0N/A * @see #addFocusListener
0N/A * @see #isFocusable
0N/A * @see #isDisplayable
0N/A * @see KeyboardFocusManager#clearGlobalFocusOwner
0N/A * @since 1.4
0N/A */
0N/A protected boolean requestFocusInWindow(boolean temporary) {
0N/A return requestFocusHelper(temporary, false);
0N/A }
0N/A
0N/A boolean requestFocusInWindow(boolean temporary, CausedFocusEvent.Cause cause) {
0N/A return requestFocusHelper(temporary, false, cause);
0N/A }
0N/A
0N/A final boolean requestFocusHelper(boolean temporary,
0N/A boolean focusedWindowChangeAllowed) {
0N/A return requestFocusHelper(temporary, focusedWindowChangeAllowed, CausedFocusEvent.Cause.UNKNOWN);
0N/A }
0N/A
0N/A final boolean requestFocusHelper(boolean temporary,
0N/A boolean focusedWindowChangeAllowed,
0N/A CausedFocusEvent.Cause cause)
0N/A {
0N/A if (!isRequestFocusAccepted(temporary, focusedWindowChangeAllowed, cause)) {
0N/A if (focusLog.isLoggable(Level.FINEST)) {
0N/A focusLog.log(Level.FINEST, "requestFocus is not accepted");
0N/A }
0N/A return false;
0N/A }
0N/A
0N/A // Update most-recent map
0N/A KeyboardFocusManager.setMostRecentFocusOwner(this);
0N/A
0N/A Component window = this;
0N/A while ( (window != null) && !(window instanceof Window)) {
0N/A if (!window.isVisible()) {
0N/A if (focusLog.isLoggable(Level.FINEST)) {
0N/A focusLog.log(Level.FINEST, "component is recurively invisible");
0N/A }
0N/A return false;
0N/A }
0N/A window = window.parent;
0N/A }
0N/A
0N/A ComponentPeer peer = this.peer;
0N/A Component heavyweight = (peer instanceof LightweightPeer)
0N/A ? getNativeContainer() : this;
0N/A if (heavyweight == null || !heavyweight.isVisible()) {
0N/A if (focusLog.isLoggable(Level.FINEST)) {
0N/A focusLog.log(Level.FINEST, "Component is not a part of visible hierarchy");
0N/A }
0N/A return false;
0N/A }
0N/A peer = heavyweight.peer;
0N/A if (peer == null) {
0N/A if (focusLog.isLoggable(Level.FINEST)) {
0N/A focusLog.log(Level.FINEST, "Peer is null");
0N/A }
0N/A return false;
0N/A }
0N/A
0N/A // Focus this Component
0N/A long time = EventQueue.getMostRecentEventTime();
0N/A boolean success = peer.requestFocus
0N/A (this, temporary, focusedWindowChangeAllowed, time, cause);
0N/A if (!success) {
0N/A KeyboardFocusManager.getCurrentKeyboardFocusManager
0N/A (appContext).dequeueKeyEvents(time, this);
0N/A if (focusLog.isLoggable(Level.FINEST)) {
0N/A focusLog.log(Level.FINEST, "Peer request failed");
0N/A }
0N/A } else {
0N/A if (focusLog.isLoggable(Level.FINEST)) {
0N/A focusLog.log(Level.FINEST, "Pass for " + this);
0N/A }
0N/A }
0N/A return success;
0N/A }
0N/A
0N/A private boolean isRequestFocusAccepted(boolean temporary,
0N/A boolean focusedWindowChangeAllowed,
0N/A CausedFocusEvent.Cause cause)
0N/A {
0N/A if (!isFocusable() || !isVisible()) {
0N/A if (focusLog.isLoggable(Level.FINEST)) {
0N/A focusLog.log(Level.FINEST, "Not focusable or not visible");
0N/A }
0N/A return false;
0N/A }
0N/A
0N/A ComponentPeer peer = this.peer;
0N/A if (peer == null) {
0N/A if (focusLog.isLoggable(Level.FINEST)) {
0N/A focusLog.log(Level.FINEST, "peer is null");
0N/A }
0N/A return false;
0N/A }
0N/A
0N/A Window window = getContainingWindow();
0N/A if (window == null || !((Window)window).isFocusableWindow()) {
0N/A if (focusLog.isLoggable(Level.FINEST)) {
0N/A focusLog.log(Level.FINEST, "Component doesn't have toplevel");
0N/A }
0N/A return false;
0N/A }
0N/A
0N/A // We have passed all regular checks for focus request,
0N/A // now let's call RequestFocusController and see what it says.
0N/A Component focusOwner = KeyboardFocusManager.getMostRecentFocusOwner(window);
0N/A if (focusOwner == null) {
0N/A // sometimes most recent focus owner may be null, but focus owner is not
0N/A // e.g. we reset most recent focus owner if user removes focus owner
0N/A focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
0N/A if (focusOwner != null && getContainingWindow(focusOwner) != window) {
0N/A focusOwner = null;
0N/A }
0N/A }
0N/A
0N/A if (focusOwner == this || focusOwner == null) {
0N/A // Controller is supposed to verify focus transfers and for this it
0N/A // should know both from and to components. And it shouldn't verify
0N/A // transfers from when these components are equal.
0N/A if (focusLog.isLoggable(Level.FINEST)) {
0N/A focusLog.log(Level.FINEST, "focus owner is null or this");
0N/A }
0N/A return true;
0N/A }
0N/A
0N/A if (CausedFocusEvent.Cause.ACTIVATION == cause) {
0N/A // we shouldn't call RequestFocusController in case we are
0N/A // in activation. We do request focus on component which
0N/A // has got temporary focus lost and then on component which is
0N/A // most recent focus owner. But most recent focus owner can be
0N/A // changed by requestFocsuXXX() call only, so this transfer has
0N/A // been already approved.
0N/A if (focusLog.isLoggable(Level.FINEST)) {
0N/A focusLog.log(Level.FINEST, "cause is activation");
0N/A }
0N/A return true;
0N/A }
0N/A
0N/A boolean ret = Component.requestFocusController.acceptRequestFocus(focusOwner,
0N/A this,
0N/A temporary,
0N/A focusedWindowChangeAllowed,
0N/A cause);
0N/A if (focusLog.isLoggable(Level.FINEST)) {
0N/A focusLog.log(Level.FINEST, "RequestFocusController returns {0}", ret);
0N/A }
0N/A
0N/A return ret;
0N/A }
0N/A
0N/A private static RequestFocusController requestFocusController = new DummyRequestFocusController();
0N/A
0N/A // Swing access this method through reflection to implement InputVerifier's functionality.
0N/A // Perhaps, we should make this method public (later ;)
0N/A private static class DummyRequestFocusController implements RequestFocusController {
0N/A public boolean acceptRequestFocus(Component from, Component to,
0N/A boolean temporary, boolean focusedWindowChangeAllowed,
0N/A CausedFocusEvent.Cause cause)
0N/A {
0N/A return true;
0N/A }
0N/A };
0N/A
0N/A synchronized static void setRequestFocusController(RequestFocusController requestController)
0N/A {
0N/A if (requestController == null) {
0N/A requestFocusController = new DummyRequestFocusController();
0N/A } else {
0N/A requestFocusController = requestController;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the Container which is the focus cycle root of this Component's
0N/A * focus traversal cycle. Each focus traversal cycle has only a single
0N/A * focus cycle root and each Component which is not a Container belongs to
0N/A * only a single focus traversal cycle. Containers which are focus cycle
0N/A * roots belong to two cycles: one rooted at the Container itself, and one
0N/A * rooted at the Container's nearest focus-cycle-root ancestor. For such
0N/A * Containers, this method will return the Container's nearest focus-cycle-
0N/A * root ancestor.
0N/A *
0N/A * @return this Component's nearest focus-cycle-root ancestor
0N/A * @see Container#isFocusCycleRoot()
0N/A * @since 1.4
0N/A */
0N/A public Container getFocusCycleRootAncestor() {
0N/A Container rootAncestor = this.parent;
0N/A while (rootAncestor != null && !rootAncestor.isFocusCycleRoot()) {
0N/A rootAncestor = rootAncestor.parent;
0N/A }
0N/A return rootAncestor;
0N/A }
0N/A
0N/A /**
0N/A * Returns whether the specified Container is the focus cycle root of this
0N/A * Component's focus traversal cycle. Each focus traversal cycle has only
0N/A * a single focus cycle root and each Component which is not a Container
0N/A * belongs to only a single focus traversal cycle.
0N/A *
0N/A * @param container the Container to be tested
0N/A * @return <code>true</code> if the specified Container is a focus-cycle-
0N/A * root of this Component; <code>false</code> otherwise
0N/A * @see Container#isFocusCycleRoot()
0N/A * @since 1.4
0N/A */
0N/A public boolean isFocusCycleRoot(Container container) {
0N/A Container rootAncestor = getFocusCycleRootAncestor();
0N/A return (rootAncestor == container);
0N/A }
0N/A
218N/A Container getTraversalRoot() {
218N/A return getFocusCycleRootAncestor();
218N/A }
218N/A
218N/A /**
218N/A * Transfers the focus to the next component, as though this Component were
218N/A * the focus owner.
218N/A * @see #requestFocus()
218N/A * @since JDK1.1
218N/A */
218N/A public void transferFocus() {
218N/A nextFocus();
218N/A }
218N/A
0N/A /**
0N/A * @deprecated As of JDK version 1.1,
0N/A * replaced by transferFocus().
0N/A */
0N/A @Deprecated
0N/A public void nextFocus() {
218N/A transferFocus(false);
218N/A }
218N/A
218N/A boolean transferFocus(boolean clearOnFailure) {
0N/A if (focusLog.isLoggable(Level.FINER)) {
218N/A focusLog.finer("clearOnFailure = " + clearOnFailure);
218N/A }
218N/A Component toFocus = getNextFocusCandidate();
218N/A boolean res = false;
218N/A if (toFocus != null && !toFocus.isFocusOwner() && toFocus != this) {
218N/A res = toFocus.requestFocusInWindow(CausedFocusEvent.Cause.TRAVERSAL_FORWARD);
218N/A }
218N/A if (clearOnFailure && !res) {
218N/A if (focusLog.isLoggable(Level.FINER)) {
218N/A focusLog.finer("clear global focus owner");
218N/A }
218N/A KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner();
218N/A }
218N/A if (focusLog.isLoggable(Level.FINER)) {
218N/A focusLog.finer("returning result: " + res);
218N/A }
218N/A return res;
218N/A }
218N/A
218N/A final Component getNextFocusCandidate() {
0N/A Container rootAncestor = getTraversalRoot();
0N/A Component comp = this;
0N/A while (rootAncestor != null &&
0N/A !(rootAncestor.isShowing() &&
0N/A rootAncestor.isFocusable() &&
0N/A rootAncestor.isEnabled()))
0N/A {
0N/A comp = rootAncestor;
0N/A rootAncestor = comp.getFocusCycleRootAncestor();
0N/A }
0N/A if (focusLog.isLoggable(Level.FINER)) {
218N/A focusLog.finer("comp = " + comp + ", root = " + rootAncestor);
218N/A }
218N/A Component candidate = null;
0N/A if (rootAncestor != null) {
0N/A FocusTraversalPolicy policy = rootAncestor.getFocusTraversalPolicy();
0N/A Component toFocus = policy.getComponentAfter(rootAncestor, comp);
0N/A if (focusLog.isLoggable(Level.FINER)) {
218N/A focusLog.finer("component after is " + toFocus);
0N/A }
0N/A if (toFocus == null) {
0N/A toFocus = policy.getDefaultComponent(rootAncestor);
0N/A if (focusLog.isLoggable(Level.FINER)) {
218N/A focusLog.finer("default component is " + toFocus);
0N/A }
0N/A }
0N/A if (toFocus == null) {
0N/A Applet applet = EmbeddedFrame.getAppletIfAncestorOf(this);
0N/A if (applet != null) {
0N/A toFocus = applet;
0N/A }
0N/A }
218N/A candidate = toFocus;
218N/A }
218N/A if (focusLog.isLoggable(Level.FINER)) {
218N/A focusLog.finer("Focus transfer candidate: " + candidate);
218N/A }
218N/A return candidate;
0N/A }
0N/A
0N/A /**
0N/A * Transfers the focus to the previous component, as though this Component
0N/A * were the focus owner.
0N/A * @see #requestFocus()
0N/A * @since 1.4
0N/A */
0N/A public void transferFocusBackward() {
218N/A transferFocusBackward(false);
218N/A }
218N/A
218N/A boolean transferFocusBackward(boolean clearOnFailure) {
0N/A Container rootAncestor = getTraversalRoot();
0N/A Component comp = this;
0N/A while (rootAncestor != null &&
0N/A !(rootAncestor.isShowing() &&
0N/A rootAncestor.isFocusable() &&
0N/A rootAncestor.isEnabled()))
0N/A {
0N/A comp = rootAncestor;
0N/A rootAncestor = comp.getFocusCycleRootAncestor();
0N/A }
218N/A boolean res = false;
0N/A if (rootAncestor != null) {
0N/A FocusTraversalPolicy policy = rootAncestor.getFocusTraversalPolicy();
0N/A Component toFocus = policy.getComponentBefore(rootAncestor, comp);
0N/A if (toFocus == null) {
0N/A toFocus = policy.getDefaultComponent(rootAncestor);
0N/A }
0N/A if (toFocus != null) {
218N/A res = toFocus.requestFocusInWindow(CausedFocusEvent.Cause.TRAVERSAL_BACKWARD);
218N/A }
218N/A }
218N/A if (!res) {
218N/A if (focusLog.isLoggable(Level.FINER)) {
218N/A focusLog.finer("clear global focus owner");
218N/A }
218N/A KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner();
218N/A }
218N/A if (focusLog.isLoggable(Level.FINER)) {
218N/A focusLog.finer("returning result: " + res);
218N/A }
218N/A return res;
0N/A }
0N/A
0N/A /**
0N/A * Transfers the focus up one focus traversal cycle. Typically, the focus
0N/A * owner is set to this Component's focus cycle root, and the current focus
0N/A * cycle root is set to the new focus owner's focus cycle root. If,
0N/A * however, this Component's focus cycle root is a Window, then the focus
0N/A * owner is set to the focus cycle root's default Component to focus, and
0N/A * the current focus cycle root is unchanged.
0N/A *
0N/A * @see #requestFocus()
0N/A * @see Container#isFocusCycleRoot()
0N/A * @see Container#setFocusCycleRoot(boolean)
0N/A * @since 1.4
0N/A */
0N/A public void transferFocusUpCycle() {
0N/A Container rootAncestor;
0N/A for (rootAncestor = getFocusCycleRootAncestor();
0N/A rootAncestor != null && !(rootAncestor.isShowing() &&
0N/A rootAncestor.isFocusable() &&
0N/A rootAncestor.isEnabled());
0N/A rootAncestor = rootAncestor.getFocusCycleRootAncestor()) {
0N/A }
0N/A
0N/A if (rootAncestor != null) {
0N/A Container rootAncestorRootAncestor =
0N/A rootAncestor.getFocusCycleRootAncestor();
0N/A KeyboardFocusManager.getCurrentKeyboardFocusManager().
0N/A setGlobalCurrentFocusCycleRoot(
0N/A (rootAncestorRootAncestor != null)
0N/A ? rootAncestorRootAncestor
0N/A : rootAncestor);
0N/A rootAncestor.requestFocus(CausedFocusEvent.Cause.TRAVERSAL_UP);
0N/A } else {
0N/A Window window = getContainingWindow();
0N/A
0N/A if (window != null) {
0N/A Component toFocus = window.getFocusTraversalPolicy().
0N/A getDefaultComponent(window);
0N/A if (toFocus != null) {
0N/A KeyboardFocusManager.getCurrentKeyboardFocusManager().
0N/A setGlobalCurrentFocusCycleRoot(window);
0N/A toFocus.requestFocus(CausedFocusEvent.Cause.TRAVERSAL_UP);
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns <code>true</code> if this <code>Component</code> is the
0N/A * focus owner. This method is obsolete, and has been replaced by
0N/A * <code>isFocusOwner()</code>.
0N/A *
0N/A * @return <code>true</code> if this <code>Component</code> is the
0N/A * focus owner; <code>false</code> otherwise
0N/A * @since 1.2
0N/A */
0N/A public boolean hasFocus() {
0N/A return (KeyboardFocusManager.getCurrentKeyboardFocusManager().
0N/A getFocusOwner() == this);
0N/A }
0N/A
0N/A /**
0N/A * Returns <code>true</code> if this <code>Component</code> is the
0N/A * focus owner.
0N/A *
0N/A * @return <code>true</code> if this <code>Component</code> is the
0N/A * focus owner; <code>false</code> otherwise
0N/A * @since 1.4
0N/A */
0N/A public boolean isFocusOwner() {
0N/A return hasFocus();
0N/A }
0N/A
218N/A /*
218N/A * Used to disallow auto-focus-transfer on disposal of the focus owner
218N/A * in the process of disposing its parent container.
218N/A */
218N/A private boolean autoFocusTransferOnDisposal = true;
218N/A
218N/A void setAutoFocusTransferOnDisposal(boolean value) {
218N/A autoFocusTransferOnDisposal = value;
218N/A }
218N/A
218N/A boolean isAutoFocusTransferOnDisposal() {
218N/A return autoFocusTransferOnDisposal;
218N/A }
218N/A
0N/A /**
0N/A * Adds the specified popup menu to the component.
0N/A * @param popup the popup menu to be added to the component.
0N/A * @see #remove(MenuComponent)
0N/A * @exception NullPointerException if {@code popup} is {@code null}
0N/A * @since JDK1.1
0N/A */
0N/A public void add(PopupMenu popup) {
0N/A synchronized (getTreeLock()) {
0N/A if (popup.parent != null) {
0N/A popup.parent.remove(popup);
0N/A }
0N/A if (popups == null) {
0N/A popups = new Vector();
0N/A }
0N/A popups.addElement(popup);
0N/A popup.parent = this;
0N/A
0N/A if (peer != null) {
0N/A if (popup.peer == null) {
0N/A popup.addNotify();
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Removes the specified popup menu from the component.
0N/A * @param popup the popup menu to be removed
0N/A * @see #add(PopupMenu)
0N/A * @since JDK1.1
0N/A */
0N/A public void remove(MenuComponent popup) {
0N/A synchronized (getTreeLock()) {
0N/A if (popups == null) {
0N/A return;
0N/A }
0N/A int index = popups.indexOf(popup);
0N/A if (index >= 0) {
0N/A PopupMenu pmenu = (PopupMenu)popup;
0N/A if (pmenu.peer != null) {
0N/A pmenu.removeNotify();
0N/A }
0N/A pmenu.parent = null;
0N/A popups.removeElementAt(index);
0N/A if (popups.size() == 0) {
0N/A popups = null;
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns a string representing the state of this component. This
0N/A * method 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 be
0N/A * <code>null</code>.
0N/A *
0N/A * @return a string representation of this component's state
0N/A * @since JDK1.0
0N/A */
0N/A protected String paramString() {
0N/A String thisName = getName();
0N/A String str = (thisName != null? thisName : "") + "," + x + "," + y + "," + width + "x" + height;
0N/A if (!valid) {
0N/A str += ",invalid";
0N/A }
0N/A if (!visible) {
0N/A str += ",hidden";
0N/A }
0N/A if (!enabled) {
0N/A str += ",disabled";
0N/A }
0N/A return str;
0N/A }
0N/A
0N/A /**
0N/A * Returns a string representation of this component and its values.
0N/A * @return a string representation of this component
0N/A * @since JDK1.0
0N/A */
0N/A public String toString() {
0N/A return getClass().getName() + "[" + paramString() + "]";
0N/A }
0N/A
0N/A /**
0N/A * Prints a listing of this component to the standard system output
0N/A * stream <code>System.out</code>.
0N/A * @see java.lang.System#out
0N/A * @since JDK1.0
0N/A */
0N/A public void list() {
0N/A list(System.out, 0);
0N/A }
0N/A
0N/A /**
0N/A * Prints a listing of this component to the specified output
0N/A * stream.
0N/A * @param out a print stream
0N/A * @since JDK1.0
0N/A */
0N/A public void list(PrintStream out) {
0N/A list(out, 0);
0N/A }
0N/A
0N/A /**
0N/A * Prints out a list, starting at the specified indentation, to the
0N/A * specified print stream.
0N/A * @param out a print stream
0N/A * @param indent number of spaces to indent
0N/A * @see java.io.PrintStream#println(java.lang.Object)
0N/A * @since JDK1.0
0N/A */
0N/A public void list(PrintStream out, int indent) {
0N/A for (int i = 0 ; i < indent ; i++) {
0N/A out.print(" ");
0N/A }
0N/A out.println(this);
0N/A }
0N/A
0N/A /**
0N/A * Prints a listing to the specified print writer.
0N/A * @param out the print writer to print to
0N/A * @since JDK1.1
0N/A */
0N/A public void list(PrintWriter out) {
0N/A list(out, 0);
0N/A }
0N/A
0N/A /**
0N/A * Prints out a list, starting at the specified indentation, to
0N/A * the specified print writer.
0N/A * @param out the print writer to print to
0N/A * @param indent the number of spaces to indent
0N/A * @see java.io.PrintStream#println(java.lang.Object)
0N/A * @since JDK1.1
0N/A */
0N/A public void list(PrintWriter out, int indent) {
0N/A for (int i = 0 ; i < indent ; i++) {
0N/A out.print(" ");
0N/A }
0N/A out.println(this);
0N/A }
0N/A
0N/A /*
0N/A * Fetches the native container somewhere higher up in the component
0N/A * tree that contains this component.
0N/A */
0N/A Container getNativeContainer() {
0N/A Container p = parent;
0N/A while (p != null && p.peer instanceof LightweightPeer) {
0N/A p = p.getParent();
0N/A }
0N/A return p;
0N/A }
0N/A
0N/A /**
0N/A * Adds a PropertyChangeListener to the listener list. The listener is
0N/A * registered for all bound properties of this class, including the
0N/A * following:
0N/A * <ul>
0N/A * <li>this Component's font ("font")</li>
0N/A * <li>this Component's background color ("background")</li>
0N/A * <li>this Component's foreground color ("foreground")</li>
0N/A * <li>this Component's focusability ("focusable")</li>
0N/A * <li>this Component's focus traversal keys enabled state
0N/A * ("focusTraversalKeysEnabled")</li>
0N/A * <li>this Component's Set of FORWARD_TRAVERSAL_KEYS
0N/A * ("forwardFocusTraversalKeys")</li>
0N/A * <li>this Component's Set of BACKWARD_TRAVERSAL_KEYS
0N/A * ("backwardFocusTraversalKeys")</li>
0N/A * <li>this Component's Set of UP_CYCLE_TRAVERSAL_KEYS
0N/A * ("upCycleFocusTraversalKeys")</li>
0N/A * <li>this Component's preferred size ("preferredSize")</li>
0N/A * <li>this Component's minimum size ("minimumSize")</li>
0N/A * <li>this Component's maximum size ("maximumSize")</li>
0N/A * <li>this Component's name ("name")</li>
0N/A * </ul>
0N/A * Note that if this <code>Component</code> is inheriting a bound property, then no
0N/A * event will be fired in response to a change in the inherited property.
0N/A * <p>
0N/A * If <code>listener</code> is <code>null</code>,
0N/A * no exception is thrown and no action is performed.
0N/A *
0N/A * @param listener the property change listener to be added
0N/A *
0N/A * @see #removePropertyChangeListener
0N/A * @see #getPropertyChangeListeners
0N/A * @see #addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
0N/A */
100N/A public void addPropertyChangeListener(
0N/A PropertyChangeListener listener) {
100N/A synchronized (getChangeSupportLock()) {
100N/A if (listener == null) {
100N/A return;
100N/A }
100N/A if (changeSupport == null) {
100N/A changeSupport = new PropertyChangeSupport(this);
100N/A }
100N/A changeSupport.addPropertyChangeListener(listener);
100N/A }
0N/A }
0N/A
0N/A /**
0N/A * Removes a PropertyChangeListener from the listener list. This method
0N/A * should be used to remove PropertyChangeListeners that were registered
0N/A * for all bound properties of this class.
0N/A * <p>
0N/A * If listener is null, no exception is thrown and no action is performed.
0N/A *
0N/A * @param listener the PropertyChangeListener to be removed
0N/A *
0N/A * @see #addPropertyChangeListener
0N/A * @see #getPropertyChangeListeners
0N/A * @see #removePropertyChangeListener(java.lang.String,java.beans.PropertyChangeListener)
0N/A */
100N/A public void removePropertyChangeListener(
0N/A PropertyChangeListener listener) {
100N/A synchronized (getChangeSupportLock()) {
100N/A if (listener == null || changeSupport == null) {
100N/A return;
100N/A }
100N/A changeSupport.removePropertyChangeListener(listener);
100N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns an array of all the property change listeners
0N/A * registered on this component.
0N/A *
0N/A * @return all of this component's <code>PropertyChangeListener</code>s
0N/A * or an empty array if no property change
0N/A * listeners are currently registered
0N/A *
0N/A * @see #addPropertyChangeListener
0N/A * @see #removePropertyChangeListener
0N/A * @see #getPropertyChangeListeners(java.lang.String)
0N/A * @see java.beans.PropertyChangeSupport#getPropertyChangeListeners
0N/A * @since 1.4
0N/A */
100N/A public PropertyChangeListener[] getPropertyChangeListeners() {
100N/A synchronized (getChangeSupportLock()) {
100N/A if (changeSupport == null) {
100N/A return new PropertyChangeListener[0];
100N/A }
100N/A return changeSupport.getPropertyChangeListeners();
100N/A }
0N/A }
0N/A
0N/A /**
0N/A * Adds a PropertyChangeListener to the listener list for a specific
0N/A * property. The specified property may be user-defined, or one of the
0N/A * following:
0N/A * <ul>
0N/A * <li>this Component's font ("font")</li>
0N/A * <li>this Component's background color ("background")</li>
0N/A * <li>this Component's foreground color ("foreground")</li>
0N/A * <li>this Component's focusability ("focusable")</li>
0N/A * <li>this Component's focus traversal keys enabled state
0N/A * ("focusTraversalKeysEnabled")</li>
0N/A * <li>this Component's Set of FORWARD_TRAVERSAL_KEYS
0N/A * ("forwardFocusTraversalKeys")</li>
0N/A * <li>this Component's Set of BACKWARD_TRAVERSAL_KEYS
0N/A * ("backwardFocusTraversalKeys")</li>
0N/A * <li>this Component's Set of UP_CYCLE_TRAVERSAL_KEYS
0N/A * ("upCycleFocusTraversalKeys")</li>
0N/A * </ul>
0N/A * Note that if this <code>Component</code> is inheriting a bound property, then no
0N/A * event will be fired in response to a change in the inherited property.
0N/A * <p>
0N/A * If <code>propertyName</code> or <code>listener</code> is <code>null</code>,
0N/A * no exception is thrown and no action is taken.
0N/A *
0N/A * @param propertyName one of the property names listed above
0N/A * @param listener the property change listener to be added
0N/A *
0N/A * @see #removePropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
0N/A * @see #getPropertyChangeListeners(java.lang.String)
0N/A * @see #addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
0N/A */
100N/A public void addPropertyChangeListener(
0N/A String propertyName,
0N/A PropertyChangeListener listener) {
100N/A synchronized (getChangeSupportLock()) {
100N/A if (listener == null) {
100N/A return;
100N/A }
100N/A if (changeSupport == null) {
100N/A changeSupport = new PropertyChangeSupport(this);
100N/A }
100N/A changeSupport.addPropertyChangeListener(propertyName, listener);
100N/A }
0N/A }
0N/A
0N/A /**
0N/A * Removes a <code>PropertyChangeListener</code> from the listener
0N/A * list for a specific property. This method should be used to remove
0N/A * <code>PropertyChangeListener</code>s
0N/A * that were registered for a specific bound property.
0N/A * <p>
0N/A * If <code>propertyName</code> or <code>listener</code> is <code>null</code>,
0N/A * no exception is thrown and no action is taken.
0N/A *
0N/A * @param propertyName a valid property name
0N/A * @param listener the PropertyChangeListener to be removed
0N/A *
0N/A * @see #addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
0N/A * @see #getPropertyChangeListeners(java.lang.String)
0N/A * @see #removePropertyChangeListener(java.beans.PropertyChangeListener)
0N/A */
100N/A public void removePropertyChangeListener(
0N/A String propertyName,
0N/A PropertyChangeListener listener) {
100N/A synchronized (getChangeSupportLock()) {
100N/A if (listener == null || changeSupport == null) {
100N/A return;
100N/A }
100N/A changeSupport.removePropertyChangeListener(propertyName, listener);
100N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns an array of all the listeners which have been associated
0N/A * with the named property.
0N/A *
0N/A * @return all of the <code>PropertyChangeListener</code>s associated with
0N/A * the named property; if no such listeners have been added or
0N/A * if <code>propertyName</code> is <code>null</code>, an empty
0N/A * array is returned
0N/A *
0N/A * @see #addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
0N/A * @see #removePropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
0N/A * @see #getPropertyChangeListeners
0N/A * @since 1.4
0N/A */
100N/A public PropertyChangeListener[] getPropertyChangeListeners(
0N/A String propertyName) {
100N/A synchronized (getChangeSupportLock()) {
100N/A if (changeSupport == null) {
100N/A return new PropertyChangeListener[0];
100N/A }
100N/A return changeSupport.getPropertyChangeListeners(propertyName);
100N/A }
0N/A }
0N/A
0N/A /**
0N/A * Support for reporting bound property changes for Object 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 protected void firePropertyChange(String propertyName,
0N/A Object oldValue, Object newValue) {
100N/A PropertyChangeSupport changeSupport;
100N/A synchronized (getChangeSupportLock()) {
100N/A changeSupport = this.changeSupport;
100N/A }
0N/A if (changeSupport == null ||
0N/A (oldValue != null && newValue != null && oldValue.equals(newValue))) {
0N/A return;
0N/A }
0N/A changeSupport.firePropertyChange(propertyName, oldValue, newValue);
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 * @since 1.4
0N/A */
0N/A protected void firePropertyChange(String propertyName,
0N/A boolean oldValue, boolean newValue) {
0N/A PropertyChangeSupport changeSupport = this.changeSupport;
0N/A if (changeSupport == null || oldValue == newValue) {
0N/A return;
0N/A }
0N/A changeSupport.firePropertyChange(propertyName, oldValue, newValue);
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 * @since 1.4
0N/A */
0N/A protected void firePropertyChange(String propertyName,
0N/A int oldValue, int newValue) {
0N/A PropertyChangeSupport changeSupport = this.changeSupport;
0N/A if (changeSupport == null || oldValue == newValue) {
0N/A return;
0N/A }
0N/A changeSupport.firePropertyChange(propertyName, oldValue, newValue);
0N/A }
0N/A
0N/A /**
0N/A * Reports a bound property change.
0N/A *
0N/A * @param propertyName the programmatic name of the property
0N/A * that was changed
0N/A * @param oldValue the old value of the property (as a byte)
0N/A * @param newValue the new value of the property (as a byte)
0N/A * @see #firePropertyChange(java.lang.String, java.lang.Object,
0N/A * java.lang.Object)
0N/A * @since 1.5
0N/A */
0N/A public void firePropertyChange(String propertyName, byte oldValue, byte newValue) {
0N/A if (changeSupport == null || oldValue == newValue) {
0N/A return;
0N/A }
0N/A firePropertyChange(propertyName, Byte.valueOf(oldValue), Byte.valueOf(newValue));
0N/A }
0N/A
0N/A /**
0N/A * Reports a bound property change.
0N/A *
0N/A * @param propertyName the programmatic name of the property
0N/A * that was changed
0N/A * @param oldValue the old value of the property (as a char)
0N/A * @param newValue the new value of the property (as a char)
0N/A * @see #firePropertyChange(java.lang.String, java.lang.Object,
0N/A * java.lang.Object)
0N/A * @since 1.5
0N/A */
0N/A public void firePropertyChange(String propertyName, char oldValue, char newValue) {
0N/A if (changeSupport == null || oldValue == newValue) {
0N/A return;
0N/A }
0N/A firePropertyChange(propertyName, new Character(oldValue), new Character(newValue));
0N/A }
0N/A
0N/A /**
0N/A * Reports a bound property change.
0N/A *
0N/A * @param propertyName the programmatic name of the property
0N/A * that was changed
0N/A * @param oldValue the old value of the property (as a short)
0N/A * @param newValue the old value of the property (as a short)
0N/A * @see #firePropertyChange(java.lang.String, java.lang.Object,
0N/A * java.lang.Object)
0N/A * @since 1.5
0N/A */
0N/A public void firePropertyChange(String propertyName, short oldValue, short newValue) {
0N/A if (changeSupport == null || oldValue == newValue) {
0N/A return;
0N/A }
0N/A firePropertyChange(propertyName, Short.valueOf(oldValue), Short.valueOf(newValue));
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Reports a bound property change.
0N/A *
0N/A * @param propertyName the programmatic name of the property
0N/A * that was changed
0N/A * @param oldValue the old value of the property (as a long)
0N/A * @param newValue the new value of the property (as a long)
0N/A * @see #firePropertyChange(java.lang.String, java.lang.Object,
0N/A * java.lang.Object)
0N/A * @since 1.5
0N/A */
0N/A public void firePropertyChange(String propertyName, long oldValue, long newValue) {
0N/A if (changeSupport == null || oldValue == newValue) {
0N/A return;
0N/A }
0N/A firePropertyChange(propertyName, Long.valueOf(oldValue), Long.valueOf(newValue));
0N/A }
0N/A
0N/A /**
0N/A * Reports a bound property change.
0N/A *
0N/A * @param propertyName the programmatic name of the property
0N/A * that was changed
0N/A * @param oldValue the old value of the property (as a float)
0N/A * @param newValue the new value of the property (as a float)
0N/A * @see #firePropertyChange(java.lang.String, java.lang.Object,
0N/A * java.lang.Object)
0N/A * @since 1.5
0N/A */
0N/A public void firePropertyChange(String propertyName, float oldValue, float newValue) {
0N/A if (changeSupport == null || oldValue == newValue) {
0N/A return;
0N/A }
0N/A firePropertyChange(propertyName, Float.valueOf(oldValue), Float.valueOf(newValue));
0N/A }
0N/A
0N/A /**
0N/A * Reports a bound property change.
0N/A *
0N/A * @param propertyName the programmatic name of the property
0N/A * that was changed
0N/A * @param oldValue the old value of the property (as a double)
0N/A * @param newValue the new value of the property (as a double)
0N/A * @see #firePropertyChange(java.lang.String, java.lang.Object,
0N/A * java.lang.Object)
0N/A * @since 1.5
0N/A */
0N/A public void firePropertyChange(String propertyName, double oldValue, double newValue) {
0N/A if (changeSupport == null || oldValue == newValue) {
0N/A return;
0N/A }
0N/A firePropertyChange(propertyName, Double.valueOf(oldValue), Double.valueOf(newValue));
0N/A }
0N/A
0N/A
0N/A // Serialization support.
0N/A
0N/A /**
0N/A * Component Serialized Data Version.
0N/A *
0N/A * @serial
0N/A */
0N/A private int componentSerializedDataVersion = 4;
0N/A
0N/A /**
0N/A * This hack is for Swing serialization. It will invoke
0N/A * the Swing package private method <code>compWriteObjectNotify</code>.
0N/A */
0N/A private void doSwingSerialization() {
0N/A Package swingPackage = Package.getPackage("javax.swing");
0N/A // For Swing serialization to correctly work Swing needs to
0N/A // be notified before Component does it's serialization. This
0N/A // hack accomodates this.
0N/A //
0N/A // Swing classes MUST be loaded by the bootstrap class loader,
0N/A // otherwise we don't consider them.
0N/A for (Class klass = Component.this.getClass(); klass != null;
0N/A klass = klass.getSuperclass()) {
0N/A if (klass.getPackage() == swingPackage &&
0N/A klass.getClassLoader() == null) {
0N/A final Class swingClass = klass;
0N/A // Find the first override of the compWriteObjectNotify method
0N/A Method[] methods = (Method[])AccessController.doPrivileged(
0N/A new PrivilegedAction() {
0N/A public Object run() {
0N/A return swingClass.getDeclaredMethods();
0N/A }
0N/A });
0N/A for (int counter = methods.length - 1; counter >= 0;
0N/A counter--) {
0N/A final Method method = methods[counter];
0N/A if (method.getName().equals("compWriteObjectNotify")){
0N/A // We found it, use doPrivileged to make it accessible
0N/A // to use.
0N/A AccessController.doPrivileged(new PrivilegedAction() {
0N/A public Object run() {
0N/A method.setAccessible(true);
0N/A return null;
0N/A }
0N/A });
0N/A // Invoke the method
0N/A try {
0N/A method.invoke(this, (Object[]) null);
0N/A } catch (IllegalAccessException iae) {
0N/A } catch (InvocationTargetException ite) {
0N/A }
0N/A // We're done, bail.
0N/A return;
0N/A }
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Writes default serializable fields to stream. Writes
0N/A * a variety of serializable listeners as optional data.
0N/A * The non-serializable listeners are detected and
0N/A * no attempt is made to serialize them.
0N/A *
0N/A * @param s the <code>ObjectOutputStream</code> to write
0N/A * @serialData <code>null</code> terminated sequence of
0N/A * 0 or more pairs; the pair consists of a <code>String</code>
0N/A * and an <code>Object</code>; the <code>String</code> indicates
0N/A * the type of object and is one of the following (as of 1.4):
0N/A * <code>componentListenerK</code> indicating an
0N/A * <code>ComponentListener</code> object;
0N/A * <code>focusListenerK</code> indicating an
0N/A * <code>FocusListener</code> object;
0N/A * <code>keyListenerK</code> indicating an
0N/A * <code>KeyListener</code> object;
0N/A * <code>mouseListenerK</code> indicating an
0N/A * <code>MouseListener</code> object;
0N/A * <code>mouseMotionListenerK</code> indicating an
0N/A * <code>MouseMotionListener</code> object;
0N/A * <code>inputMethodListenerK</code> indicating an
0N/A * <code>InputMethodListener</code> object;
0N/A * <code>hierarchyListenerK</code> indicating an
0N/A * <code>HierarchyListener</code> object;
0N/A * <code>hierarchyBoundsListenerK</code> indicating an
0N/A * <code>HierarchyBoundsListener</code> object;
0N/A * <code>mouseWheelListenerK</code> indicating an
0N/A * <code>MouseWheelListener</code> object
0N/A * @serialData an optional <code>ComponentOrientation</code>
0N/A * (after <code>inputMethodListener</code>, as of 1.2)
0N/A *
0N/A * @see AWTEventMulticaster#save(java.io.ObjectOutputStream, java.lang.String, java.util.EventListener)
0N/A * @see #componentListenerK
0N/A * @see #focusListenerK
0N/A * @see #keyListenerK
0N/A * @see #mouseListenerK
0N/A * @see #mouseMotionListenerK
0N/A * @see #inputMethodListenerK
0N/A * @see #hierarchyListenerK
0N/A * @see #hierarchyBoundsListenerK
0N/A * @see #mouseWheelListenerK
0N/A * @see #readObject(ObjectInputStream)
0N/A */
0N/A private void writeObject(ObjectOutputStream s)
0N/A throws IOException
0N/A {
0N/A doSwingSerialization();
0N/A
0N/A s.defaultWriteObject();
0N/A
0N/A AWTEventMulticaster.save(s, componentListenerK, componentListener);
0N/A AWTEventMulticaster.save(s, focusListenerK, focusListener);
0N/A AWTEventMulticaster.save(s, keyListenerK, keyListener);
0N/A AWTEventMulticaster.save(s, mouseListenerK, mouseListener);
0N/A AWTEventMulticaster.save(s, mouseMotionListenerK, mouseMotionListener);
0N/A AWTEventMulticaster.save(s, inputMethodListenerK, inputMethodListener);
0N/A
0N/A s.writeObject(null);
0N/A s.writeObject(componentOrientation);
0N/A
0N/A AWTEventMulticaster.save(s, hierarchyListenerK, hierarchyListener);
0N/A AWTEventMulticaster.save(s, hierarchyBoundsListenerK,
0N/A hierarchyBoundsListener);
0N/A s.writeObject(null);
0N/A
0N/A AWTEventMulticaster.save(s, mouseWheelListenerK, mouseWheelListener);
0N/A s.writeObject(null);
0N/A
0N/A }
0N/A
0N/A /**
0N/A * Reads the <code>ObjectInputStream</code> and if it isn't
0N/A * <code>null</code> adds a listener to receive a variety
0N/A * of events fired by the component.
0N/A * Unrecognized keys or values will be ignored.
0N/A *
0N/A * @param s the <code>ObjectInputStream</code> to read
0N/A * @see #writeObject(ObjectOutputStream)
0N/A */
0N/A private void readObject(ObjectInputStream s)
0N/A throws ClassNotFoundException, IOException
0N/A {
209N/A changeSupportLock = new Object();
209N/A
0N/A s.defaultReadObject();
0N/A
0N/A appContext = AppContext.getAppContext();
0N/A coalescingEnabled = checkCoalescing();
0N/A if (componentSerializedDataVersion < 4) {
0N/A // These fields are non-transient and rely on default
0N/A // serialization. However, the default values are insufficient,
0N/A // so we need to set them explicitly for object data streams prior
0N/A // to 1.4.
0N/A focusable = true;
0N/A isFocusTraversableOverridden = FOCUS_TRAVERSABLE_UNKNOWN;
0N/A initializeFocusTraversalKeys();
0N/A focusTraversalKeysEnabled = true;
0N/A }
0N/A
0N/A Object keyOrNull;
0N/A while(null != (keyOrNull = s.readObject())) {
0N/A String key = ((String)keyOrNull).intern();
0N/A
0N/A if (componentListenerK == key)
0N/A addComponentListener((ComponentListener)(s.readObject()));
0N/A
0N/A else if (focusListenerK == key)
0N/A addFocusListener((FocusListener)(s.readObject()));
0N/A
0N/A else if (keyListenerK == key)
0N/A addKeyListener((KeyListener)(s.readObject()));
0N/A
0N/A else if (mouseListenerK == key)
0N/A addMouseListener((MouseListener)(s.readObject()));
0N/A
0N/A else if (mouseMotionListenerK == key)
0N/A addMouseMotionListener((MouseMotionListener)(s.readObject()));
0N/A
0N/A else if (inputMethodListenerK == key)
0N/A addInputMethodListener((InputMethodListener)(s.readObject()));
0N/A
0N/A else // skip value for unrecognized key
0N/A s.readObject();
0N/A
0N/A }
0N/A
0N/A // Read the component's orientation if it's present
0N/A Object orient = null;
0N/A
0N/A try {
0N/A orient = s.readObject();
0N/A } catch (java.io.OptionalDataException e) {
0N/A // JDK 1.1 instances will not have this optional data.
0N/A // e.eof will be true to indicate that there is no more
0N/A // data available for this object.
0N/A // If e.eof is not true, throw the exception as it
0N/A // might have been caused by reasons unrelated to
0N/A // componentOrientation.
0N/A
0N/A if (!e.eof) {
0N/A throw (e);
0N/A }
0N/A }
0N/A
0N/A if (orient != null) {
0N/A componentOrientation = (ComponentOrientation)orient;
0N/A } else {
0N/A componentOrientation = ComponentOrientation.UNKNOWN;
0N/A }
0N/A
0N/A try {
0N/A while(null != (keyOrNull = s.readObject())) {
0N/A String key = ((String)keyOrNull).intern();
0N/A
0N/A if (hierarchyListenerK == key) {
0N/A addHierarchyListener((HierarchyListener)(s.readObject()));
0N/A }
0N/A else if (hierarchyBoundsListenerK == key) {
0N/A addHierarchyBoundsListener((HierarchyBoundsListener)
0N/A (s.readObject()));
0N/A }
0N/A else {
0N/A // skip value for unrecognized key
0N/A s.readObject();
0N/A }
0N/A }
0N/A } catch (java.io.OptionalDataException e) {
0N/A // JDK 1.1/1.2 instances will not have this optional data.
0N/A // e.eof will be true to indicate that there is no more
0N/A // data available for this object.
0N/A // If e.eof is not true, throw the exception as it
0N/A // might have been caused by reasons unrelated to
0N/A // hierarchy and hierarchyBounds listeners.
0N/A
0N/A if (!e.eof) {
0N/A throw (e);
0N/A }
0N/A }
0N/A
0N/A try {
0N/A while (null != (keyOrNull = s.readObject())) {
0N/A String key = ((String)keyOrNull).intern();
0N/A
0N/A if (mouseWheelListenerK == key) {
0N/A addMouseWheelListener((MouseWheelListener)(s.readObject()));
0N/A }
0N/A else {
0N/A // skip value for unrecognized key
0N/A s.readObject();
0N/A }
0N/A }
0N/A } catch (java.io.OptionalDataException e) {
0N/A // pre-1.3 instances will not have this optional data.
0N/A // e.eof will be true to indicate that there is no more
0N/A // data available for this object.
0N/A // If e.eof is not true, throw the exception as it
0N/A // might have been caused by reasons unrelated to
0N/A // mouse wheel listeners
0N/A
0N/A if (!e.eof) {
0N/A throw (e);
0N/A }
0N/A }
0N/A
0N/A if (popups != null) {
0N/A int npopups = popups.size();
0N/A for (int i = 0 ; i < npopups ; i++) {
0N/A PopupMenu popup = (PopupMenu)popups.elementAt(i);
0N/A popup.parent = this;
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets the language-sensitive orientation that is to be used to order
0N/A * the elements or text within this component. Language-sensitive
0N/A * <code>LayoutManager</code> and <code>Component</code>
0N/A * subclasses will use this property to
0N/A * determine how to lay out and draw components.
0N/A * <p>
0N/A * At construction time, a component's orientation is set to
0N/A * <code>ComponentOrientation.UNKNOWN</code>,
0N/A * indicating that it has not been specified
0N/A * explicitly. The UNKNOWN orientation behaves the same as
0N/A * <code>ComponentOrientation.LEFT_TO_RIGHT</code>.
0N/A * <p>
0N/A * To set the orientation of a single component, use this method.
0N/A * To set the orientation of an entire component
0N/A * hierarchy, use
0N/A * {@link #applyComponentOrientation applyComponentOrientation}.
0N/A *
0N/A * @see ComponentOrientation
0N/A *
0N/A * @author Laura Werner, IBM
0N/A * @beaninfo
0N/A * bound: true
0N/A */
0N/A public void setComponentOrientation(ComponentOrientation o) {
0N/A ComponentOrientation oldValue = componentOrientation;
0N/A componentOrientation = o;
0N/A
0N/A // This is a bound property, so report the change to
0N/A // any registered listeners. (Cheap if there are none.)
0N/A firePropertyChange("componentOrientation", oldValue, o);
0N/A
0N/A // This could change the preferred size of the Component.
0N/A if (valid) {
0N/A invalidate();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Retrieves the language-sensitive orientation that is to be used to order
0N/A * the elements or text within this component. <code>LayoutManager</code>
0N/A * and <code>Component</code>
0N/A * subclasses that wish to respect orientation should call this method to
0N/A * get the component's orientation before performing layout or drawing.
0N/A *
0N/A * @see ComponentOrientation
0N/A *
0N/A * @author Laura Werner, IBM
0N/A */
0N/A public ComponentOrientation getComponentOrientation() {
0N/A return componentOrientation;
0N/A }
0N/A
0N/A /**
0N/A * Sets the <code>ComponentOrientation</code> property of this component
0N/A * and all components contained within it.
0N/A *
0N/A * @param orientation the new component orientation of this component and
0N/A * the components contained within it.
0N/A * @exception NullPointerException if <code>orientation</code> is null.
0N/A * @see #setComponentOrientation
0N/A * @see #getComponentOrientation
0N/A * @since 1.4
0N/A */
0N/A public void applyComponentOrientation(ComponentOrientation orientation) {
0N/A if (orientation == null) {
0N/A throw new NullPointerException();
0N/A }
0N/A setComponentOrientation(orientation);
0N/A }
0N/A
0N/A /**
0N/A * Checks that this component meets the prerequesites to be focus owner:
0N/A * - it is enabled, visible, focusable
0N/A * - it's parents are all enabled and showing
0N/A * - top-level window is focusable
0N/A * - if focus cycle root has DefaultFocusTraversalPolicy then it also checks that this policy accepts
0N/A * this component as focus owner
0N/A * @since 1.5
0N/A */
0N/A final boolean canBeFocusOwner() {
0N/A // - it is enabled, visible, focusable
0N/A if (!(isEnabled() && isDisplayable() && isVisible() && isFocusable())) {
0N/A return false;
0N/A }
0N/A
0N/A // - it's parents are all enabled and showing
0N/A synchronized(getTreeLock()) {
0N/A if (parent != null) {
0N/A return parent.canContainFocusOwner(this);
0N/A }
0N/A }
0N/A return true;
0N/A }
0N/A
0N/A /**
107N/A * Fix the location of the HW component in a LW container hierarchy.
107N/A */
107N/A final void relocateComponent() {
107N/A synchronized (getTreeLock()) {
107N/A if (peer == null) {
107N/A return;
107N/A }
107N/A int nativeX = x;
107N/A int nativeY = y;
107N/A for (Component cont = getContainer();
107N/A cont != null && cont.isLightweight();
107N/A cont = cont.getContainer())
0N/A {
107N/A nativeX += cont.x;
107N/A nativeY += cont.y;
107N/A }
107N/A peer.setBounds(nativeX, nativeY, width, height,
107N/A ComponentPeer.SET_LOCATION);
107N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the <code>Window</code> ancestor of the component.
0N/A * @return Window ancestor of the component or component by itself if it is Window;
0N/A * null, if component is not a part of window hierarchy
0N/A */
0N/A Window getContainingWindow() {
0N/A return getContainingWindow(this);
0N/A }
0N/A /**
0N/A * Returns the <code>Window</code> ancestor of the component <code>comp</code>.
0N/A * @return Window ancestor of the component or component by itself if it is Window;
0N/A * null, if component is not a part of window hierarchy
0N/A */
0N/A static Window getContainingWindow(Component comp) {
0N/A while (comp != null && !(comp instanceof Window)) {
0N/A comp = comp.getParent();
0N/A }
0N/A
0N/A return (Window)comp;
0N/A }
0N/A
0N/A
0N/A
0N/A
0N/A
0N/A
0N/A
0N/A
0N/A
0N/A
0N/A
0N/A /**
0N/A * Initialize JNI field and method IDs
0N/A */
0N/A private static native void initIDs();
0N/A
0N/A /*
0N/A * --- Accessibility Support ---
0N/A *
0N/A * Component will contain all of the methods in interface Accessible,
0N/A * though it won't actually implement the interface - that will be up
0N/A * to the individual objects which extend Component.
0N/A */
0N/A
0N/A AccessibleContext accessibleContext = null;
0N/A
0N/A /**
0N/A * Gets the <code>AccessibleContext</code> associated
0N/A * with this <code>Component</code>.
0N/A * The method implemented by this base
0N/A * class returns null. Classes that extend <code>Component</code>
0N/A * should implement this method to return the
0N/A * <code>AccessibleContext</code> associated with the subclass.
0N/A *
0N/A *
0N/A * @return the <code>AccessibleContext</code> of this
0N/A * <code>Component</code>
0N/A * @since 1.3
0N/A */
0N/A public AccessibleContext getAccessibleContext() {
0N/A return accessibleContext;
0N/A }
0N/A
0N/A /**
0N/A * Inner class of Component 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 * The class used to obtain the accessible role for this object.
0N/A * @since 1.3
0N/A */
0N/A protected abstract class AccessibleAWTComponent extends AccessibleContext
0N/A implements Serializable, AccessibleComponent {
0N/A
0N/A private static final long serialVersionUID = 642321655757800191L;
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 AccessibleAWTComponent() {
0N/A }
0N/A
0N/A protected ComponentListener accessibleAWTComponentHandler = null;
0N/A protected FocusListener accessibleAWTFocusHandler = null;
0N/A
0N/A /**
0N/A * Fire PropertyChange listener, if one is registered,
0N/A * when shown/hidden..
0N/A * @since 1.3
0N/A */
0N/A protected class AccessibleAWTComponentHandler implements ComponentListener {
0N/A public void componentHidden(ComponentEvent e) {
0N/A if (accessibleContext != null) {
0N/A accessibleContext.firePropertyChange(
0N/A AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
0N/A AccessibleState.VISIBLE, null);
0N/A }
0N/A }
0N/A
0N/A public void componentShown(ComponentEvent e) {
0N/A if (accessibleContext != null) {
0N/A accessibleContext.firePropertyChange(
0N/A AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
0N/A null, AccessibleState.VISIBLE);
0N/A }
0N/A }
0N/A
0N/A public void componentMoved(ComponentEvent e) {
0N/A }
0N/A
0N/A public void componentResized(ComponentEvent e) {
0N/A }
0N/A } // inner class AccessibleAWTComponentHandler
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 AccessibleAWTFocusHandler 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 AccessibleAWTFocusHandler
0N/A
0N/A
0N/A /**
0N/A * Adds a <code>PropertyChangeListener</code> to the listener list.
0N/A *
0N/A * @param listener the property change listener to be added
0N/A */
0N/A public void addPropertyChangeListener(PropertyChangeListener listener) {
0N/A if (accessibleAWTComponentHandler == null) {
0N/A accessibleAWTComponentHandler = new AccessibleAWTComponentHandler();
0N/A Component.this.addComponentListener(accessibleAWTComponentHandler);
0N/A }
0N/A if (accessibleAWTFocusHandler == null) {
0N/A accessibleAWTFocusHandler = new AccessibleAWTFocusHandler();
0N/A Component.this.addFocusListener(accessibleAWTFocusHandler);
0N/A }
0N/A super.addPropertyChangeListener(listener);
0N/A }
0N/A
0N/A /**
0N/A * Remove 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 (accessibleAWTComponentHandler != null) {
0N/A Component.this.removeComponentListener(accessibleAWTComponentHandler);
0N/A accessibleAWTComponentHandler = null;
0N/A }
0N/A if (accessibleAWTFocusHandler != null) {
0N/A Component.this.removeFocusListener(accessibleAWTFocusHandler);
0N/A accessibleAWTFocusHandler = null;
0N/A }
0N/A super.removePropertyChangeListener(listener);
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 <code>java.awt.Component.getName()</code>,
0N/A * as that generally isn't a localized name,
0N/A * and doesn't have meaning for the user. If the
0N/A * object is fundamentally a text object (e.g. a menu item), the
0N/A * accessible name should be the text of the object (e.g. "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
0N/A * <code>null</code> if this
0N/A * object does not have a name
0N/A * @see javax.accessibility.AccessibleContext#setAccessibleName
0N/A */
0N/A public String getAccessibleName() {
0N/A return accessibleName;
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 - e.g. 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
0N/A * <code>null</code> if this object does not have a description
0N/A * @see javax.accessibility.AccessibleContext#setAccessibleDescription
0N/A */
0N/A public String getAccessibleDescription() {
0N/A return accessibleDescription;
0N/A }
0N/A
0N/A /**
0N/A * Gets the role of this object.
0N/A *
0N/A * @return an instance of <code>AccessibleRole</code>
0N/A * describing the role of the object
0N/A * @see javax.accessibility.AccessibleRole
0N/A */
0N/A public AccessibleRole getAccessibleRole() {
0N/A return AccessibleRole.AWT_COMPONENT;
0N/A }
0N/A
0N/A /**
0N/A * Gets the state of this object.
0N/A *
0N/A * @return an instance of <code>AccessibleStateSet</code>
0N/A * containing the current state set of the object
0N/A * @see javax.accessibility.AccessibleState
0N/A */
0N/A public AccessibleStateSet getAccessibleStateSet() {
0N/A return Component.this.getAccessibleStateSet();
0N/A }
0N/A
0N/A /**
0N/A * Gets the <code>Accessible</code> parent of this object.
0N/A * If the parent of this object implements <code>Accessible</code>,
0N/A * this method should simply return <code>getParent</code>.
0N/A *
0N/A * @return the <code>Accessible</code> parent of this
0N/A * object -- can be <code>null</code> if this
0N/A * object does not have an <code>Accessible</code> parent
0N/A */
0N/A public Accessible getAccessibleParent() {
0N/A if (accessibleParent != null) {
0N/A return accessibleParent;
0N/A } else {
0N/A Container parent = getParent();
0N/A if (parent instanceof Accessible) {
0N/A return (Accessible) parent;
0N/A }
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Gets the index of this object in its accessible parent.
0N/A *
0N/A * @return the index of this object in its parent; or -1 if this
0N/A * object does not have an accessible parent
0N/A * @see #getAccessibleParent
0N/A */
0N/A public int getAccessibleIndexInParent() {
0N/A return Component.this.getAccessibleIndexInParent();
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 <code>Accessible</code>,
0N/A * then this 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 0; // Components don't have children
0N/A }
0N/A
0N/A /**
0N/A * Returns the nth <code>Accessible</code> child of the object.
0N/A *
0N/A * @param i zero-based index of child
0N/A * @return the nth <code>Accessible</code> child of the object
0N/A */
0N/A public Accessible getAccessibleChild(int i) {
0N/A return null; // Components don't have children
0N/A }
0N/A
0N/A /**
0N/A * Returns the locale of this object.
0N/A *
0N/A * @return the locale of this object
0N/A */
0N/A public Locale getLocale() {
0N/A return Component.this.getLocale();
0N/A }
0N/A
0N/A /**
0N/A * Gets the <code>AccessibleComponent</code> associated
0N/A * with this object if one exists.
0N/A * Otherwise return <code>null</code>.
0N/A *
0N/A * @return the component
0N/A */
0N/A public AccessibleComponent getAccessibleComponent() {
0N/A return this;
0N/A }
0N/A
0N/A
0N/A // AccessibleComponent methods
0N/A //
0N/A /**
0N/A * Gets the background color of this object.
0N/A *
0N/A * @return the background color, if supported, of the object;
0N/A * otherwise, <code>null</code>
0N/A */
0N/A public Color getBackground() {
0N/A return Component.this.getBackground();
0N/A }
0N/A
0N/A /**
0N/A * Sets the background color of this object.
0N/A * (For transparency, see <code>isOpaque</code>.)
0N/A *
0N/A * @param c the new <code>Color</code> for the background
0N/A * @see Component#isOpaque
0N/A */
0N/A public void setBackground(Color c) {
0N/A Component.this.setBackground(c);
0N/A }
0N/A
0N/A /**
0N/A * Gets the foreground color of this object.
0N/A *
0N/A * @return the foreground color, if supported, of the object;
0N/A * otherwise, <code>null</code>
0N/A */
0N/A public Color getForeground() {
0N/A return Component.this.getForeground();
0N/A }
0N/A
0N/A /**
0N/A * Sets the foreground color of this object.
0N/A *
0N/A * @param c the new <code>Color</code> for the foreground
0N/A */
0N/A public void setForeground(Color c) {
0N/A Component.this.setForeground(c);
0N/A }
0N/A
0N/A /**
0N/A * Gets the <code>Cursor</code> of this object.
0N/A *
0N/A * @return the <code>Cursor</code>, if supported,
0N/A * of the object; otherwise, <code>null</code>
0N/A */
0N/A public Cursor getCursor() {
0N/A return Component.this.getCursor();
0N/A }
0N/A
0N/A /**
0N/A * Sets the <code>Cursor</code> of this object.
0N/A * <p>
0N/A * The method may have no visual effect if the Java platform
0N/A * implementation and/or the native system do not support
0N/A * changing the mouse cursor shape.
0N/A * @param cursor the new <code>Cursor</code> for the object
0N/A */
0N/A public void setCursor(Cursor cursor) {
0N/A Component.this.setCursor(cursor);
0N/A }
0N/A
0N/A /**
0N/A * Gets the <code>Font</code> of this object.
0N/A *
0N/A * @return the <code>Font</code>, if supported,
0N/A * for the object; otherwise, <code>null</code>
0N/A */
0N/A public Font getFont() {
0N/A return Component.this.getFont();
0N/A }
0N/A
0N/A /**
0N/A * Sets the <code>Font</code> of this object.
0N/A *
0N/A * @param f the new <code>Font</code> for the object
0N/A */
0N/A public void setFont(Font f) {
0N/A Component.this.setFont(f);
0N/A }
0N/A
0N/A /**
0N/A * Gets the <code>FontMetrics</code> of this object.
0N/A *
0N/A * @param f the <code>Font</code>
0N/A * @return the <code>FontMetrics</code>, if supported,
0N/A * the object; otherwise, <code>null</code>
0N/A * @see #getFont
0N/A */
0N/A public FontMetrics getFontMetrics(Font f) {
0N/A if (f == null) {
0N/A return null;
0N/A } else {
0N/A return Component.this.getFontMetrics(f);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Determines if the object is enabled.
0N/A *
0N/A * @return true if object is enabled; otherwise, false
0N/A */
0N/A public boolean isEnabled() {
0N/A return Component.this.isEnabled();
0N/A }
0N/A
0N/A /**
0N/A * Sets the enabled state of the object.
0N/A *
0N/A * @param b if true, enables this object; otherwise, disables it
0N/A */
0N/A public void setEnabled(boolean b) {
0N/A boolean old = Component.this.isEnabled();
0N/A Component.this.setEnabled(b);
0N/A if (b != old) {
0N/A if (accessibleContext != null) {
0N/A if (b) {
0N/A accessibleContext.firePropertyChange(
0N/A AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
0N/A null, AccessibleState.ENABLED);
0N/A } else {
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 /**
0N/A * Determines if the object is visible. Note: this means that the
0N/A * object intends to be visible; however, it may not in fact be
0N/A * showing on the screen because one of the objects that this object
0N/A * is contained by is not visible. To determine if an object is
0N/A * showing on the screen, use <code>isShowing</code>.
0N/A *
0N/A * @return true if object is visible; otherwise, false
0N/A */
0N/A public boolean isVisible() {
0N/A return Component.this.isVisible();
0N/A }
0N/A
0N/A /**
0N/A * Sets the visible state of the object.
0N/A *
0N/A * @param b if true, shows this object; otherwise, hides it
0N/A */
0N/A public void setVisible(boolean b) {
0N/A boolean old = Component.this.isVisible();
0N/A Component.this.setVisible(b);
0N/A if (b != old) {
0N/A if (accessibleContext != null) {
0N/A if (b) {
0N/A accessibleContext.firePropertyChange(
0N/A AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
0N/A null, AccessibleState.VISIBLE);
0N/A } else {
0N/A accessibleContext.firePropertyChange(
0N/A AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
0N/A AccessibleState.VISIBLE, null);
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Determines if the object is showing. This is determined by checking
0N/A * the visibility of the object and ancestors of the object. Note:
0N/A * this will return true even if the object is obscured by another
0N/A * (for example, it happens to be underneath a menu that was pulled
0N/A * down).
0N/A *
0N/A * @return true if object is showing; otherwise, false
0N/A */
0N/A public boolean isShowing() {
0N/A return Component.this.isShowing();
0N/A }
0N/A
0N/A /**
0N/A * Checks whether the specified point is within this object's bounds,
0N/A * where the point's x and y coordinates are defined to be relative to
0N/A * the coordinate system of the object.
0N/A *
0N/A * @param p the <code>Point</code> relative to the
0N/A * coordinate system of the object
0N/A * @return true if object contains <code>Point</code>; otherwise false
0N/A */
0N/A public boolean contains(Point p) {
0N/A return Component.this.contains(p);
0N/A }
0N/A
0N/A /**
0N/A * Returns the location of the object on the screen.
0N/A *
0N/A * @return location of object on screen -- can be
0N/A * <code>null</code> if this object is not on the screen
0N/A */
0N/A public Point getLocationOnScreen() {
0N/A synchronized (Component.this.getTreeLock()) {
0N/A if (Component.this.isShowing()) {
0N/A return Component.this.getLocationOnScreen();
0N/A } else {
0N/A return null;
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Gets the location of the object relative to the parent in the form
0N/A * of a point specifying the object's top-left corner in the screen's
0N/A * coordinate space.
0N/A *
0N/A * @return an instance of Point representing the top-left corner of
0N/A * the object's bounds in the coordinate space of the screen;
0N/A * <code>null</code> if this object or its parent are not on the screen
0N/A */
0N/A public Point getLocation() {
0N/A return Component.this.getLocation();
0N/A }
0N/A
0N/A /**
0N/A * Sets the location of the object relative to the parent.
0N/A * @param p the coordinates of the object
0N/A */
0N/A public void setLocation(Point p) {
0N/A Component.this.setLocation(p);
0N/A }
0N/A
0N/A /**
0N/A * Gets the bounds of this object in the form of a Rectangle object.
0N/A * The bounds specify this object's width, height, and location
0N/A * relative to its parent.
0N/A *
0N/A * @return a rectangle indicating this component's bounds;
0N/A * <code>null</code> if this object is not on the screen
0N/A */
0N/A public Rectangle getBounds() {
0N/A return Component.this.getBounds();
0N/A }
0N/A
0N/A /**
0N/A * Sets the bounds of this object in the form of a
0N/A * <code>Rectangle</code> object.
0N/A * The bounds specify this object's width, height, and location
0N/A * relative to its parent.
0N/A *
0N/A * @param r a rectangle indicating this component's bounds
0N/A */
0N/A public void setBounds(Rectangle r) {
0N/A Component.this.setBounds(r);
0N/A }
0N/A
0N/A /**
0N/A * Returns the size of this object in the form of a
0N/A * <code>Dimension</code> object. The height field of the
0N/A * <code>Dimension</code> object contains this objects's
0N/A * height, and the width field of the <code>Dimension</code>
0N/A * object contains this object's width.
0N/A *
0N/A * @return a <code>Dimension</code> object that indicates
0N/A * the size of this component; <code>null</code> if
0N/A * this object is not on the screen
0N/A */
0N/A public Dimension getSize() {
0N/A return Component.this.getSize();
0N/A }
0N/A
0N/A /**
0N/A * Resizes this object so that it has width and height.
0N/A *
0N/A * @param d - the dimension specifying the new size of the object
0N/A */
0N/A public void setSize(Dimension d) {
0N/A Component.this.setSize(d);
0N/A }
0N/A
0N/A /**
0N/A * Returns the <code>Accessible</code> child,
0N/A * if one exists, contained at the local
0N/A * coordinate <code>Point</code>. Otherwise returns
0N/A * <code>null</code>.
0N/A *
0N/A * @param p the point defining the top-left corner of
0N/A * the <code>Accessible</code>, given in the
0N/A * coordinate space of the object's parent
0N/A * @return the <code>Accessible</code>, if it exists,
0N/A * at the specified location; else <code>null</code>
0N/A */
0N/A public Accessible getAccessibleAt(Point p) {
0N/A return null; // Components don't have children
0N/A }
0N/A
0N/A /**
0N/A * Returns whether this object can accept focus or not.
0N/A *
0N/A * @return true if object can accept focus; otherwise false
0N/A */
0N/A public boolean isFocusTraversable() {
0N/A return Component.this.isFocusTraversable();
0N/A }
0N/A
0N/A /**
0N/A * Requests focus for this object.
0N/A */
0N/A public void requestFocus() {
0N/A Component.this.requestFocus();
0N/A }
0N/A
0N/A /**
0N/A * Adds the specified focus listener to receive focus events from this
0N/A * component.
0N/A *
0N/A * @param l the focus listener
0N/A */
0N/A public void addFocusListener(FocusListener l) {
0N/A Component.this.addFocusListener(l);
0N/A }
0N/A
0N/A /**
0N/A * Removes the specified focus listener so it no longer receives focus
0N/A * events from this component.
0N/A *
0N/A * @param l the focus listener
0N/A */
0N/A public void removeFocusListener(FocusListener l) {
0N/A Component.this.removeFocusListener(l);
0N/A }
0N/A
0N/A } // inner class AccessibleAWTComponent
0N/A
0N/A
0N/A /**
0N/A * Gets the index of this object in its accessible parent.
0N/A * If this object does not have an accessible parent, returns
0N/A * -1.
0N/A *
0N/A * @return the index of this object in its accessible parent
0N/A */
0N/A int getAccessibleIndexInParent() {
0N/A synchronized (getTreeLock()) {
0N/A int index = -1;
0N/A Container parent = this.getParent();
0N/A if (parent != null && parent instanceof Accessible) {
0N/A Component ca[] = parent.getComponents();
0N/A for (int i = 0; i < ca.length; i++) {
0N/A if (ca[i] instanceof Accessible) {
0N/A index++;
0N/A }
0N/A if (this.equals(ca[i])) {
0N/A return index;
0N/A }
0N/A }
0N/A }
0N/A return -1;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Gets the current state set of this object.
0N/A *
0N/A * @return an instance of <code>AccessibleStateSet</code>
0N/A * containing the current state set of the object
0N/A * @see AccessibleState
0N/A */
0N/A AccessibleStateSet getAccessibleStateSet() {
0N/A synchronized (getTreeLock()) {
0N/A AccessibleStateSet states = new AccessibleStateSet();
0N/A if (this.isEnabled()) {
0N/A states.add(AccessibleState.ENABLED);
0N/A }
0N/A if (this.isFocusTraversable()) {
0N/A states.add(AccessibleState.FOCUSABLE);
0N/A }
0N/A if (this.isVisible()) {
0N/A states.add(AccessibleState.VISIBLE);
0N/A }
0N/A if (this.isShowing()) {
0N/A states.add(AccessibleState.SHOWING);
0N/A }
0N/A if (this.isFocusOwner()) {
0N/A states.add(AccessibleState.FOCUSED);
0N/A }
0N/A if (this instanceof Accessible) {
0N/A AccessibleContext ac = ((Accessible) this).getAccessibleContext();
0N/A if (ac != null) {
0N/A Accessible ap = ac.getAccessibleParent();
0N/A if (ap != null) {
0N/A AccessibleContext pac = ap.getAccessibleContext();
0N/A if (pac != null) {
0N/A AccessibleSelection as = pac.getAccessibleSelection();
0N/A if (as != null) {
0N/A states.add(AccessibleState.SELECTABLE);
0N/A int i = ac.getAccessibleIndexInParent();
0N/A if (i >= 0) {
0N/A if (as.isAccessibleChildSelected(i)) {
0N/A states.add(AccessibleState.SELECTED);
0N/A }
0N/A }
0N/A }
0N/A }
0N/A }
0N/A }
0N/A }
0N/A if (Component.isInstanceOf(this, "javax.swing.JComponent")) {
0N/A if (((javax.swing.JComponent) this).isOpaque()) {
0N/A states.add(AccessibleState.OPAQUE);
0N/A }
0N/A }
0N/A return states;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Checks that the given object is instance of the given class.
0N/A * @param obj Object to be checked
0N/A * @param className The name of the class. Must be fully-qualified class name.
0N/A * @return true, if this object is instanceof given class,
0N/A * false, otherwise, or if obj or className is null
0N/A */
0N/A static boolean isInstanceOf(Object obj, String className) {
0N/A if (obj == null) return false;
0N/A if (className == null) return false;
0N/A
0N/A Class cls = obj.getClass();
0N/A while (cls != null) {
0N/A if (cls.getName().equals(className)) {
0N/A return true;
0N/A }
0N/A cls = cls.getSuperclass();
0N/A }
0N/A return false;
0N/A }
0N/A
0N/A
0N/A // ************************** MIXING CODE *******************************
0N/A
0N/A /**
103N/A * Check whether we can trust the current bounds of the component.
103N/A * The return value of false indicates that the container of the
103N/A * component is invalid, and therefore needs to be layed out, which would
103N/A * probably mean changing the bounds of its children.
103N/A * Null-layout of the container or absence of the container mean
103N/A * the bounds of the component are final and can be trusted.
103N/A */
103N/A private boolean areBoundsValid() {
103N/A Container cont = getContainer();
103N/A return cont == null || cont.isValid() || cont.getLayout() == null;
103N/A }
103N/A
103N/A /**
0N/A * Applies the shape to the component
0N/A * @param shape Shape to be applied to the component
0N/A */
0N/A void applyCompoundShape(Region shape) {
0N/A checkTreeLock();
0N/A if (!isLightweight()) {
0N/A ComponentPeer peer = getPeer();
0N/A if (peer != null) {
0N/A // The Region class has some optimizations. That's why
0N/A // we should manually check whether it's empty and
0N/A // substitute the object ourselves. Otherwise we end up
0N/A // with some incorrect Region object with loX being
0N/A // greater than the hiX for instance.
0N/A if (shape.isEmpty()) {
0N/A shape = Region.getInstanceXYWH(0, 0, 0, 0);
0N/A }
0N/A
0N/A // Note: the shape is not really copied/cloned. We create
0N/A // the Region object ourselves, so there's no any possibility
0N/A // to modify the object outside of the mixing code.
0N/A this.compoundShape = shape;
0N/A
103N/A if (areBoundsValid()) {
0N/A Point compAbsolute = getLocationOnWindow();
0N/A
0N/A if (mixingLog.isLoggable(Level.FINER)) {
0N/A mixingLog.fine("this = " + this +
0N/A "; compAbsolute=" + compAbsolute + "; shape=" + shape);
0N/A }
0N/A
0N/A peer.applyShape(shape.getTranslatedRegion(-compAbsolute.x, -compAbsolute.y));
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the shape previously set with applyCompoundShape().
0N/A * If the component is LW or no shape was applied yet,
0N/A * the method returns the normal shape.
0N/A */
0N/A private Region getAppliedShape() {
0N/A checkTreeLock();
0N/A //XXX: if we allow LW components to have a shape, this must be changed
0N/A return (this.compoundShape == null || isLightweight()) ? getNormalShape() : this.compoundShape;
0N/A }
0N/A
0N/A Point getLocationOnWindow() {
0N/A checkTreeLock();
0N/A Point curLocation = getLocation();
0N/A
0N/A for (Container parent = getContainer();
0N/A parent != null;
0N/A parent = parent.getContainer())
0N/A {
0N/A curLocation.x += parent.getX();
0N/A curLocation.y += parent.getY();
0N/A }
0N/A
0N/A return curLocation;
0N/A }
0N/A
0N/A /**
0N/A * Returns the full shape of the component located in window coordinates
0N/A */
0N/A final Region getNormalShape() {
0N/A checkTreeLock();
0N/A //XXX: we may take into account a user-specified shape for this component
0N/A Point compAbsolute = getLocationOnWindow();
0N/A return
0N/A Region.getInstanceXYWH(
0N/A compAbsolute.x,
0N/A compAbsolute.y,
0N/A getWidth(),
0N/A getHeight()
0N/A );
0N/A }
0N/A
0N/A private int getSiblingIndexAbove() {
0N/A checkTreeLock();
0N/A Container parent = getContainer();
0N/A if (parent == null) {
0N/A return -1;
0N/A }
0N/A
0N/A int nextAbove = parent.getComponentZOrder(this) - 1;
0N/A
0N/A return nextAbove < 0 ? -1 : nextAbove;
0N/A }
0N/A
0N/A private int getSiblingIndexBelow() {
0N/A checkTreeLock();
0N/A Container parent = getContainer();
0N/A if (parent == null) {
0N/A return -1;
0N/A }
0N/A
0N/A int nextBelow = parent.getComponentZOrder(this) + 1;
0N/A
0N/A return nextBelow >= parent.getComponentCount() ? -1 : nextBelow;
0N/A }
0N/A
0N/A private Region calculateCurrentShape() {
0N/A checkTreeLock();
0N/A Region s = getNormalShape();
0N/A
0N/A if (mixingLog.isLoggable(Level.FINE)) {
0N/A mixingLog.fine("this = " + this + "; normalShape=" + s);
0N/A }
0N/A
0N/A if (getContainer() != null) {
0N/A Component comp = this;
0N/A Container cont = comp.getContainer();
0N/A
0N/A while (cont != null) {
0N/A for (int index = comp.getSiblingIndexAbove(); index != -1; --index) {
0N/A /* It is assumed that:
0N/A *
0N/A * getComponent(getContainer().getComponentZOrder(comp)) == comp
0N/A *
0N/A * The assumption has been made according to the current
0N/A * implementation of the Container class.
0N/A */
0N/A Component c = cont.getComponent(index);
0N/A if (c.isLightweight() && c.isShowing() && c.isOpaque()) {
0N/A s = s.getDifference(c.getNormalShape());
0N/A }
0N/A }
0N/A
0N/A if (cont.isLightweight()) {
0N/A s = s.getIntersection(cont.getNormalShape());
0N/A } else {
0N/A break;
0N/A }
0N/A
0N/A comp = cont;
0N/A cont = cont.getContainer();
0N/A }
0N/A }
0N/A
0N/A if (mixingLog.isLoggable(Level.FINE)) {
0N/A mixingLog.fine("currentShape=" + s);
0N/A }
0N/A
0N/A return s;
0N/A }
0N/A
0N/A void applyCurrentShape() {
0N/A checkTreeLock();
103N/A if (!areBoundsValid()) {
0N/A return; // Because applyCompoundShape() ignores such components anyway
0N/A }
0N/A if (mixingLog.isLoggable(Level.FINE)) {
0N/A mixingLog.fine("this = " + this);
0N/A }
0N/A applyCompoundShape(calculateCurrentShape());
0N/A }
0N/A
0N/A final void subtractAndApplyShape(Region s) {
0N/A checkTreeLock();
0N/A
0N/A if (mixingLog.isLoggable(Level.FINE)) {
0N/A mixingLog.fine("this = " + this + "; s=" + s);
0N/A }
0N/A
0N/A applyCompoundShape(getAppliedShape().getDifference(s));
0N/A }
0N/A
0N/A void mixOnShowing() {
0N/A synchronized (getTreeLock()) {
0N/A if (mixingLog.isLoggable(Level.FINE)) {
0N/A mixingLog.fine("this = " + this);
0N/A }
0N/A if (isLightweight()) {
0N/A Container parent = getContainer();
0N/A if (parent != null && isShowing() && isOpaque()) {
0N/A parent.recursiveSubtractAndApplyShape(getNormalShape(), getSiblingIndexBelow());
0N/A }
0N/A } else {
0N/A applyCurrentShape();
0N/A }
0N/A }
0N/A }
0N/A
0N/A void mixOnHiding(boolean isLightweight) {
0N/A // We cannot be sure that the peer exists at this point, so we need the argument
0N/A // to find out whether the hiding component is (well, actually was) a LW or a HW.
0N/A synchronized (getTreeLock()) {
0N/A if (mixingLog.isLoggable(Level.FINE)) {
0N/A mixingLog.fine("this = " + this + "; isLightweight = " + isLightweight);
0N/A }
0N/A if (isLightweight) {
0N/A Container parent = getContainer();
0N/A if (parent != null) {
0N/A parent.recursiveApplyCurrentShape(getSiblingIndexBelow());
0N/A }
0N/A } //XXX: else applyNormalShape() ???
0N/A }
0N/A }
0N/A
0N/A void mixOnReshaping() {
0N/A synchronized (getTreeLock()) {
0N/A if (mixingLog.isLoggable(Level.FINE)) {
0N/A mixingLog.fine("this = " + this);
0N/A }
0N/A if (isLightweight()) {
0N/A Container parent = getContainer();
0N/A if (parent != null) {
0N/A parent.recursiveApplyCurrentShape(parent.getComponentZOrder(this));
0N/A }
0N/A } else {
0N/A applyCurrentShape();
0N/A }
0N/A }
0N/A }
0N/A
0N/A void mixOnZOrderChanging(int oldZorder, int newZorder) {
0N/A synchronized (getTreeLock()) {
0N/A boolean becameHigher = newZorder < oldZorder;
0N/A Container parent = getContainer();
0N/A
0N/A if (mixingLog.isLoggable(Level.FINE)) {
0N/A mixingLog.fine("this = " + this +
0N/A "; oldZorder=" + oldZorder + "; newZorder=" + newZorder + "; parent=" + parent);
0N/A }
0N/A
0N/A if (isLightweight()) {
0N/A if (becameHigher) {
0N/A if (parent != null && isShowing() && isOpaque()) {
0N/A parent.recursiveSubtractAndApplyShape(getNormalShape(), getSiblingIndexBelow(), oldZorder);
0N/A }
0N/A } else {
0N/A if (parent != null) {
0N/A parent.recursiveApplyCurrentShape(oldZorder, newZorder);
0N/A }
0N/A }
0N/A } else {
0N/A if (becameHigher) {
0N/A applyCurrentShape();
0N/A } else {
0N/A if (parent != null) {
0N/A Region shape = getAppliedShape();
0N/A
0N/A for (int index = oldZorder; index < newZorder; index++) {
0N/A Component c = parent.getComponent(index);
0N/A if (c.isLightweight() && c.isShowing() && c.isOpaque()) {
0N/A shape = shape.getDifference(c.getNormalShape());
0N/A }
0N/A }
0N/A applyCompoundShape(shape);
0N/A }
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A void mixOnOpaqueChanging() {
0N/A if (mixingLog.isLoggable(Level.FINE)) {
0N/A mixingLog.fine("this = " + this);
0N/A }
0N/A if (isOpaque()) {
0N/A mixOnShowing();
0N/A } else {
0N/A mixOnHiding(isLightweight());
0N/A }
0N/A }
0N/A
0N/A // ****************** END OF MIXING CODE ********************************
0N/A}