jdk/src/share/classes/java/awt/Component.java
author bagiras
Fri, 24 Feb 2012 13:50:37 +0400
changeset 11982 9e19ca1ff707
parent 11270 d7b0b63bd082
child 12643 5d709010bb1d
permissions -rw-r--r--
7145980: Dispose method of window.java takes long Reviewed-by: anthony
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 8818
diff changeset
     2
 * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5277
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5277
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5277
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5277
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5277
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package java.awt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.io.PrintStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.PrintWriter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.EventListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.HashSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.Collections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.peer.ComponentPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.awt.peer.ContainerPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.awt.peer.LightweightPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.awt.image.BufferStrategy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.awt.image.ImageObserver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.awt.image.ImageProducer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.awt.image.ColorModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.awt.image.VolatileImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.beans.PropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import java.beans.PropertyChangeSupport;
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 130
diff changeset
    52
import java.beans.Transient;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import java.awt.event.InputMethodListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import java.awt.event.InputMethodEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import java.awt.im.InputContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import java.awt.im.InputMethodRequests;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import java.awt.dnd.DropTarget;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import java.lang.reflect.InvocationTargetException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
import java.lang.reflect.Method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
import java.security.PrivilegedAction;
8816
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
    62
import java.security.AccessControlContext;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
import java.applet.Applet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
import sun.security.action.GetPropertyAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
import sun.awt.AppContext;
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
    68
import sun.awt.AWTAccessor;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
import sun.awt.ConstrainableGraphics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
import sun.awt.SubRegionShowable;
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
    71
import sun.awt.SunToolkit;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
import sun.awt.WindowClosingListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
import sun.awt.CausedFocusEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
import sun.awt.EmbeddedFrame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
import sun.awt.dnd.SunDropTargetEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
import sun.awt.im.CompositionArea;
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3237
diff changeset
    77
import sun.font.FontManager;
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3237
diff changeset
    78
import sun.font.FontManagerFactory;
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3237
diff changeset
    79
import sun.font.SunFontManager;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
import sun.java2d.SunGraphics2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
import sun.java2d.pipe.Region;
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
    82
import sun.awt.image.VSyncedBSManager;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
    83
import sun.java2d.pipe.hw.ExtendedBufferCapabilities;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
    84
import static sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.*;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
import sun.awt.RequestFocusController;
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
    86
import sun.java2d.SunGraphicsEnvironment;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
    87
import sun.util.logging.PlatformLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * A <em>component</em> is an object having a graphical representation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * that can be displayed on the screen and that can interact with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * user. Examples of components are the buttons, checkboxes, and scrollbars
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * of a typical graphical user interface. <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * The <code>Component</code> class is the abstract superclass of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * the nonmenu-related Abstract Window Toolkit components. Class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * <code>Component</code> can also be extended directly to create a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * lightweight component. A lightweight component is a component that is
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
    98
 * not associated with a native window. On the contrary, a heavyweight
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
    99
 * component is associated with a native window. The {@link #isLightweight()}
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
   100
 * method may be used to distinguish between the two kinds of the components.
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
   101
 * <p>
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
   102
 * Lightweight and heavyweight components may be mixed in a single component
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
   103
 * hierarchy. However, for correct operating of such a mixed hierarchy of
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
   104
 * components, the whole hierarchy must be valid. When the hierarchy gets
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
   105
 * invalidated, like after changing the bounds of components, or
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
   106
 * adding/removing components to/from containers, the whole hierarchy must be
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
   107
 * validated afterwards by means of the {@link Container#validate()} method
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
   108
 * invoked on the top-most invalid container of the hierarchy.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * <h3>Serialization</h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * It is important to note that only AWT listeners which conform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * to the <code>Serializable</code> protocol will be saved when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * the object is stored.  If an AWT object has listeners that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * aren't marked serializable, they will be dropped at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * <code>writeObject</code> time.  Developers will need, as always,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * to consider the implications of making an object serializable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * One situation to watch out for is this:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 *    import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 *    import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 *    import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 *    class MyApp implements ActionListener, Serializable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 *    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 *        BigObjectThatShouldNotBeSerializedWithAButton bigOne;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 *        Button aButton = new Button();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 *        MyApp()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 *        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 *            // Oops, now aButton has a listener with a reference
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 *            // to bigOne!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 *            aButton.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 *        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 *        public void actionPerformed(ActionEvent e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 *        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 *            System.out.println("Hello There");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 *        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 *    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * In this example, serializing <code>aButton</code> by itself
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * will cause <code>MyApp</code> and everything it refers to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * to be serialized as well.  The problem is that the listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * is serializable by coincidence, not by design.  To separate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * the decisions about <code>MyApp</code> and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * <code>ActionListener</code> being serializable one can use a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 * nested class, as in the following example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 *    import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 *    import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 *    import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 *    class MyApp java.io.Serializable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 *    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 *         BigObjectThatShouldNotBeSerializedWithAButton bigOne;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 *         Button aButton = new Button();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 *         static class MyActionListener implements ActionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 *         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 *             public void actionPerformed(ActionEvent e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 *             {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
 *                 System.out.println("Hello There");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 *             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 *         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
 *         MyApp()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
 *         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 *             aButton.addActionListener(new MyActionListener());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
 *         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
 *    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
 * <b>Note</b>: For more information on the paint mechanisms utilitized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
 * by AWT and Swing, including information on how to write the most
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
 * efficient painting code, see
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
 * <a href="http://java.sun.com/products/jfc/tsc/articles/painting/index.html">Painting in AWT and Swing</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
 * For details on the focus subsystem, see
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
 * <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
 * How to Use the Focus Subsystem</a>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
 * a section in <em>The Java Tutorial</em>, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
 * <a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
 * for more information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
 * @author      Arthur van Hoff
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
 * @author      Sami Shaio
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
public abstract class Component implements ImageObserver, MenuContainer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                                           Serializable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
   192
    private static final PlatformLogger log = PlatformLogger.getLogger("java.awt.Component");
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
   193
    private static final PlatformLogger eventLog = PlatformLogger.getLogger("java.awt.event.Component");
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
   194
    private static final PlatformLogger focusLog = PlatformLogger.getLogger("java.awt.focus.Component");
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
   195
    private static final PlatformLogger mixingLog = PlatformLogger.getLogger("java.awt.mixing.Component");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * The peer of the component. The peer implements the component's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * behavior. The peer is set when the <code>Component</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * added to a container that also is a peer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @see #addNotify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * @see #removeNotify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    transient ComponentPeer peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * The parent of the object. It may be <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * for top-level components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * @see #getParent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    transient Container parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * The <code>AppContext</code> of the component. Applets/Plugin may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * change the AppContext.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    transient AppContext appContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * The x position of the component in the parent's coordinate system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * @see #getLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    int x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * The y position of the component in the parent's coordinate system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * @see #getLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    int y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * The width of the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * @see #getSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    int width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * The height of the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @see #getSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    int height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * The foreground color for this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * <code>foreground</code> can be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @see #getForeground
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * @see #setForeground
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    Color       foreground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * The background color for this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * <code>background</code> can be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @see #getBackground
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * @see #setBackground
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    Color       background;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * The font used by this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * The <code>font</code> can be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * @see #getFont
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * @see #setFont
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    Font        font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * The font which the peer is currently using.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * (<code>null</code> if no peer exists.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    Font        peerFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * The cursor displayed when pointer is over this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * This value can be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * @see #getCursor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * @see #setCursor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    Cursor      cursor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * The locale for the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * @see #getLocale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * @see #setLocale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    Locale      locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * A reference to a <code>GraphicsConfiguration</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * used to describe the characteristics of a graphics
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * destination.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * This value can be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * @see GraphicsConfiguration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * @see #getGraphicsConfiguration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     */
2459
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
   317
    private transient GraphicsConfiguration graphicsConfig = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * A reference to a <code>BufferStrategy</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * used to manipulate the buffers on this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * @see java.awt.image.BufferStrategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * @see #getBufferStrategy()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    transient BufferStrategy bufferStrategy = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * True when the object should ignore all repaint events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * @see #setIgnoreRepaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * @see #getIgnoreRepaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    boolean ignoreRepaint = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * True when the object is visible. An object that is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * visible is not drawn on the screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * @see #isVisible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * @see #setVisible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    boolean visible = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * True when the object is enabled. An object that is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * enabled does not interact with the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * @see #isEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * @see #setEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    boolean enabled = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * True when the object is valid. An invalid object needs to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * be layed out. This flag is set to false when the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * size is changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * @see #isValid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * @see #validate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * @see #invalidate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     */
1183
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
   369
    private volatile boolean valid = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * The <code>DropTarget</code> associated with this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * @see #setDropTarget
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * @see #getDropTarget
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    DropTarget dropTarget;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * @see #add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     */
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
   385
    Vector<PopupMenu> popups;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * A component's name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * This field can be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * @see #getName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * @see #setName(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    private String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * A bool to determine whether the name has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * been set explicitly. <code>nameExplicitlySet</code> will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * be false if the name has not been set and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * true if it has.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * @see #getName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * @see #setName(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    private boolean nameExplicitlySet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * Indicates whether this Component can be focused.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * @see #setFocusable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * @see #isFocusable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    private boolean focusable = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    private static final int FOCUS_TRAVERSABLE_UNKNOWN = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    private static final int FOCUS_TRAVERSABLE_DEFAULT = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    private static final int FOCUS_TRAVERSABLE_SET = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * Tracks whether this Component is relying on default focus travesability.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    private int isFocusTraversableOverridden = FOCUS_TRAVERSABLE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * The focus traversal keys. These keys will generate focus traversal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * behavior for Components for which focus traversal keys are enabled. If a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * value of null is specified for a traversal key, this Component inherits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * that traversal key from its parent. If all ancestors of this Component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * have null specified for that traversal key, then the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * KeyboardFocusManager's default traversal key is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * @see #setFocusTraversalKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * @see #getFocusTraversalKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     */
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
   444
    Set<AWTKeyStroke>[] focusTraversalKeys;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    private static final String[] focusTraversalKeyPropertyNames = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        "forwardFocusTraversalKeys",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        "backwardFocusTraversalKeys",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        "upCycleFocusTraversalKeys",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        "downCycleFocusTraversalKeys"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * Indicates whether focus traversal keys are enabled for this Component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * Components for which focus traversal keys are disabled receive key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * events for focus traversal keys. Components for which focus traversal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * keys are enabled do not see these events; instead, the events are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * automatically converted to traversal operations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * @see #setFocusTraversalKeysEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * @see #getFocusTraversalKeysEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    private boolean focusTraversalKeysEnabled = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * The locking object for AWT component-tree and layout operations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * @see #getTreeLock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    static final Object LOCK = new AWTTreeLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    static class AWTTreeLock {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
8816
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   475
    /*
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   476
     * The component's AccessControlContext.
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   477
     */
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   478
    private transient volatile AccessControlContext acc =
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   479
        AccessController.getContext();
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   480
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * Minimum size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * (This field perhaps should have been transient).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    Dimension minSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * Whether or not setMinimumSize has been invoked with a non-null value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    boolean minSizeSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * Preferred size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * (This field perhaps should have been transient).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    Dimension prefSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * Whether or not setPreferredSize has been invoked with a non-null value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    boolean prefSizeSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * Maximum size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    Dimension maxSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * Whether or not setMaximumSize has been invoked with a non-null value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    boolean maxSizeSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * The orientation for this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * @see #getComponentOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * @see #setComponentOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    transient ComponentOrientation componentOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    = ComponentOrientation.UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * <code>newEventsOnly</code> will be true if the event is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * one of the event types enabled for the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * It will then allow for normal processing to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * continue.  If it is false the event is passed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * to the component's parent and up the ancestor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * tree until the event has been consumed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * @see #dispatchEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    boolean newEventsOnly = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    transient ComponentListener componentListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    transient FocusListener focusListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    transient HierarchyListener hierarchyListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    transient HierarchyBoundsListener hierarchyBoundsListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    transient KeyListener keyListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    transient MouseListener mouseListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    transient MouseMotionListener mouseMotionListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    transient MouseWheelListener mouseWheelListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    transient InputMethodListener inputMethodListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    transient RuntimeException windowClosingException = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    /** Internal, constants for serialization */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    final static String actionListenerK = "actionL";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    final static String adjustmentListenerK = "adjustmentL";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    final static String componentListenerK = "componentL";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    final static String containerListenerK = "containerL";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    final static String focusListenerK = "focusL";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    final static String itemListenerK = "itemL";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    final static String keyListenerK = "keyL";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    final static String mouseListenerK = "mouseL";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    final static String mouseMotionListenerK = "mouseMotionL";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    final static String mouseWheelListenerK = "mouseWheelL";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    final static String textListenerK = "textL";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    final static String ownedWindowK = "ownedL";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    final static String windowListenerK = "windowL";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    final static String inputMethodListenerK = "inputMethodL";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    final static String hierarchyListenerK = "hierarchyL";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    final static String hierarchyBoundsListenerK = "hierarchyBoundsL";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    final static String windowStateListenerK = "windowStateL";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    final static String windowFocusListenerK = "windowFocusL";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * The <code>eventMask</code> is ONLY set by subclasses via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * <code>enableEvents</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * The mask should NOT be set when listeners are registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * so that we can distinguish the difference between when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * listeners request events and subclasses request them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * One bit is used to indicate whether input methods are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * enabled; this bit is set by <code>enableInputMethods</code> and is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * on by default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * @see #enableInputMethods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * @see AWTEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    long eventMask = AWTEvent.INPUT_METHODS_ENABLED_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * Static properties for incremental drawing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     * @see #imageUpdate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    static boolean isInc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    static int incRate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        /* ensure that the necessary native libraries are loaded */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        Toolkit.loadLibraries();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        /* initialize JNI field and method ids */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        if (!GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
   601
        String s = java.security.AccessController.doPrivileged(
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
   602
                                                               new GetPropertyAction("awt.image.incrementaldraw"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        isInc = (s == null || s.equals("true"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
   605
        s = java.security.AccessController.doPrivileged(
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
   606
                                                        new GetPropertyAction("awt.image.redrawrate"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        incRate = (s != null) ? Integer.parseInt(s) : 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * Ease-of-use constant for <code>getAlignmentY()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * Specifies an alignment to the top of the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * @see     #getAlignmentY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    public static final float TOP_ALIGNMENT = 0.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * Ease-of-use constant for <code>getAlignmentY</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * <code>getAlignmentX</code>. Specifies an alignment to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     * the center of the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     * @see     #getAlignmentX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * @see     #getAlignmentY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    public static final float CENTER_ALIGNMENT = 0.5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * Ease-of-use constant for <code>getAlignmentY</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * Specifies an alignment to the bottom of the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * @see     #getAlignmentY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    public static final float BOTTOM_ALIGNMENT = 1.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * Ease-of-use constant for <code>getAlignmentX</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * Specifies an alignment to the left side of the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * @see     #getAlignmentX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    public static final float LEFT_ALIGNMENT = 0.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * Ease-of-use constant for <code>getAlignmentX</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * Specifies an alignment to the right side of the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * @see     #getAlignmentX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    public static final float RIGHT_ALIGNMENT = 1.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * JDK 1.1 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    private static final long serialVersionUID = -7644114512714619750L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     * If any <code>PropertyChangeListeners</code> have been registered,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * the <code>changeSupport</code> field describes them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     * @see #addPropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * @see #removePropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * @see #firePropertyChange
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    private PropertyChangeSupport changeSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
1169
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
   664
    /*
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
   665
     * In some cases using "this" as an object to synchronize by
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
   666
     * can lead to a deadlock if client code also uses synchronization
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
   667
     * by a component object. For every such situation revealed we should
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
   668
     * consider possibility of replacing "this" with the package private
11094
1f244f2719d3 7108598: Pogo Table Games freeze with JDK 7
bagiras
parents: 11083
diff changeset
   669
     * objectLock object introduced below. So far there're 3 issues known:
1169
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
   670
     * - CR 6708322 (the getName/setName methods);
11094
1f244f2719d3 7108598: Pogo Table Games freeze with JDK 7
bagiras
parents: 11083
diff changeset
   671
     * - CR 6608764 (the PropertyChangeListener machinery);
1f244f2719d3 7108598: Pogo Table Games freeze with JDK 7
bagiras
parents: 11083
diff changeset
   672
     * - CR 7108598 (the Container.paint/KeyboardFocusManager.clearMostRecentFocusOwner methods).
1169
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
   673
     *
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
   674
     * Note: this field is considered final, though readObject() prohibits
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
   675
     * initializing final fields.
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
   676
     */
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
   677
    private transient Object objectLock = new Object();
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
   678
    Object getObjectLock() {
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
   679
        return objectLock;
123
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
   680
    }
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
   681
8816
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   682
    /*
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   683
     * Returns the acc this component was constructed with.
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   684
     */
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   685
    final AccessControlContext getAccessControlContext() {
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   686
        if (acc == null) {
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   687
            throw new SecurityException("Component is missing AccessControlContext");
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   688
        }
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   689
        return acc;
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   690
    }
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   691
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
    boolean isPacked = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     * Pseudoparameter for direct Geometry API (setLocation, setBounds setSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     * to signal setBounds what's changing. Should be used under TreeLock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     * This is only needed due to the inability to change the cross-calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     * order of public and deprecated methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
    private int boundsOp = ComponentPeer.DEFAULT_OPERATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * Enumeration of the common ways the baseline of a component can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     * change as the size changes.  The baseline resize behavior is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * primarily for layout managers that need to know how the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * position of the baseline changes as the component size changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     * In general the baseline resize behavior will be valid for sizes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     * greater than or equal to the minimum size (the actual minimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * size; not a developer specified minimum size).  For sizes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * smaller than the minimum size the baseline may change in a way
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * other than the baseline resize behavior indicates.  Similarly,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     * as the size approaches <code>Integer.MAX_VALUE</code> and/or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     * <code>Short.MAX_VALUE</code> the baseline may change in a way
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     * other than the baseline resize behavior indicates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * @see #getBaselineResizeBehavior
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * @see #getBaseline(int,int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    public enum BaselineResizeBehavior {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
         * Indicates the baseline remains fixed relative to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
         * y-origin.  That is, <code>getBaseline</code> returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
         * the same value regardless of the height or width.  For example, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
         * <code>JLabel</code> containing non-empty text with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
         * vertical alignment of <code>TOP</code> should have a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
         * baseline type of <code>CONSTANT_ASCENT</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        CONSTANT_ASCENT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
         * Indicates the baseline remains fixed relative to the height
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
         * and does not change as the width is varied.  That is, for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
         * any height H the difference between H and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
         * <code>getBaseline(w, H)</code> is the same.  For example, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
         * <code>JLabel</code> containing non-empty text with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
         * vertical alignment of <code>BOTTOM</code> should have a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
         * baseline type of <code>CONSTANT_DESCENT</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        CONSTANT_DESCENT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
         * Indicates the baseline remains a fixed distance from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
         * the center of the component.  That is, for any height H the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
         * difference between <code>getBaseline(w, H)</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
         * <code>H / 2</code> is the same (plus or minus one depending upon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
         * rounding error).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
         * Because of possible rounding errors it is recommended
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
         * you ask for the baseline with two consecutive heights and use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
         * the return value to determine if you need to pad calculations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
         * by 1.  The following shows how to calculate the baseline for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
         * any height:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
         * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
         *   Dimension preferredSize = component.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
         *   int baseline = getBaseline(preferredSize.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
         *                              preferredSize.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
         *   int nextBaseline = getBaseline(preferredSize.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
         *                                  preferredSize.height + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
         *   // Amount to add to height when calculating where baseline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
         *   // lands for a particular height:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
         *   int padding = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
         *   // Where the baseline is relative to the mid point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
         *   int baselineOffset = baseline - height / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
         *   if (preferredSize.height % 2 == 0 &amp;&amp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
         *       baseline != nextBaseline) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
         *       padding = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
         *   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
         *   else if (preferredSize.height % 2 == 1 &amp;&amp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
         *            baseline == nextBaseline) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
         *       baselineOffset--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
         *       padding = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
         *   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
         *   // The following calculates where the baseline lands for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
         *   // the height z:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
         *   int calculatedBaseline = (z + padding) / 2 + baselineOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
         * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        CENTER_OFFSET,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
         * Indicates the baseline resize behavior can not be expressed using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
         * any of the other constants.  This may also indicate the baseline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
         * varies with the width of the component.  This is also returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
         * by components that do not have a baseline.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        OTHER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     * The shape set with the applyCompoundShape() method. It uncludes the result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     * of the HW/LW mixing related shape computation. It may also include
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     * the user-specified shape of the component.
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   794
     * The 'null' value means the component has normal shape (or has no shape at all)
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   795
     * and applyCompoundShape() will skip the following shape identical to normal.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
    private transient Region compoundShape = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
    /*
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   800
     * Represents the shape of this lightweight component to be cut out from
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   801
     * heavyweight components should they intersect. Possible values:
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   802
     *    1. null - consider the shape rectangular
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   803
     *    2. EMPTY_REGION - nothing gets cut out (children still get cut out)
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   804
     *    3. non-empty - this shape gets cut out.
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   805
     */
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   806
    private transient Region mixingCutoutRegion = null;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   807
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   808
    /*
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     * Indicates whether addNotify() is complete
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     * (i.e. the peer is created).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
    private transient boolean isAddNotifyComplete = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     * Should only be used in subclass getBounds to check that part of bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     * is actualy changing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
    int getBoundsOp() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
        assert Thread.holdsLock(getTreeLock());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        return boundsOp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
    void setBoundsOp(int op) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        assert Thread.holdsLock(getTreeLock());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        if (op == ComponentPeer.RESET_OPERATION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
            boundsOp = ComponentPeer.DEFAULT_OPERATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
            if (boundsOp == ComponentPeer.DEFAULT_OPERATION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
                boundsOp = op;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   833
    // Whether this Component has had the background erase flag
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   834
    // specified via SunToolkit.disableBackgroundErase(). This is
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   835
    // needed in order to make this function work on X11 platforms,
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   836
    // where currently there is no chance to interpose on the creation
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   837
    // of the peer and therefore the call to XSetBackground.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   838
    transient boolean backgroundEraseDisabled;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   839
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   840
    static {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   841
        AWTAccessor.setComponentAccessor(new AWTAccessor.ComponentAccessor() {
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   842
            public void setBackgroundEraseDisabled(Component comp, boolean disabled) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   843
                comp.backgroundEraseDisabled = disabled;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   844
            }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   845
            public boolean getBackgroundEraseDisabled(Component comp) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   846
                return comp.backgroundEraseDisabled;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   847
            }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   848
            public Rectangle getBounds(Component comp) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   849
                return new Rectangle(comp.x, comp.y, comp.width, comp.height);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   850
            }
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   851
            public void setMixingCutoutShape(Component comp, Shape shape) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   852
                Region region = shape == null ?  null :
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   853
                    Region.getInstance(shape, null);
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   854
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   855
                synchronized (comp.getTreeLock()) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   856
                    boolean needShowing = false;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   857
                    boolean needHiding = false;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   858
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   859
                    if (!comp.isNonOpaqueForMixing()) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   860
                        needHiding = true;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   861
                    }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   862
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   863
                    comp.mixingCutoutRegion = region;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   864
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   865
                    if (!comp.isNonOpaqueForMixing()) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   866
                        needShowing = true;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   867
                    }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   868
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   869
                    if (comp.isMixingNeeded()) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   870
                        if (needHiding) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   871
                            comp.mixOnHiding(comp.isLightweight());
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   872
                        }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   873
                        if (needShowing) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   874
                            comp.mixOnShowing();
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   875
                        }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   876
                    }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   877
                }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   878
            }
2459
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
   879
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
   880
            public void setGraphicsConfiguration(Component comp,
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
   881
                    GraphicsConfiguration gc)
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
   882
            {
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
   883
                comp.setGraphicsConfiguration(gc);
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
   884
            }
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2462
diff changeset
   885
            public boolean requestFocus(Component comp, CausedFocusEvent.Cause cause) {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2462
diff changeset
   886
                return comp.requestFocus(cause);
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2462
diff changeset
   887
            }
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2462
diff changeset
   888
            public boolean canBeFocusOwner(Component comp) {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2462
diff changeset
   889
                return comp.canBeFocusOwner();
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2462
diff changeset
   890
            }
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
   891
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   892
            public boolean isVisible(Component comp) {
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
   893
                return comp.isVisible_NoClientCode();
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
   894
            }
3084
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 2805
diff changeset
   895
            public void setRequestFocusController
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 2805
diff changeset
   896
                (RequestFocusController requestController)
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 2805
diff changeset
   897
            {
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 2805
diff changeset
   898
                 Component.setRequestFocusController(requestController);
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 2805
diff changeset
   899
            }
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 2805
diff changeset
   900
            public AppContext getAppContext(Component comp) {
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 2805
diff changeset
   901
                 return comp.appContext;
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 2805
diff changeset
   902
            }
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 2805
diff changeset
   903
            public void setAppContext(Component comp, AppContext appContext) {
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 2805
diff changeset
   904
                 comp.appContext = appContext;
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 2805
diff changeset
   905
            }
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   906
            public Container getParent(Component comp) {
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   907
                return comp.getParent_NoClientCode();
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   908
            }
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   909
            public void setParent(Component comp, Container parent) {
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   910
                comp.parent = parent;
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   911
            }
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   912
            public void setSize(Component comp, int width, int height) {
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   913
                comp.width = width;
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   914
                comp.height = height;
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   915
            }
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   916
            public Point getLocation(Component comp) {
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   917
                return comp.location_NoClientCode();
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   918
            }
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   919
            public void setLocation(Component comp, int x, int y) {
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   920
                comp.x = x;
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   921
                comp.y = y;
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   922
            }
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   923
            public boolean isEnabled(Component comp) {
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   924
                return comp.isEnabledImpl();
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   925
            }
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   926
            public boolean isDisplayable(Component comp) {
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   927
                return comp.peer != null;
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   928
            }
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   929
            public Cursor getCursor(Component comp) {
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   930
                return comp.getCursor_NoClientCode();
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   931
            }
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   932
            public ComponentPeer getPeer(Component comp) {
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   933
                return comp.peer;
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   934
            }
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   935
            public void setPeer(Component comp, ComponentPeer peer) {
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   936
                comp.peer = peer;
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   937
            }
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   938
            public boolean isLightweight(Component comp) {
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   939
                return (comp.peer instanceof LightweightPeer);
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   940
            }
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   941
            public boolean getIgnoreRepaint(Component comp) {
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   942
                return comp.ignoreRepaint;
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   943
            }
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   944
            public int getWidth(Component comp) {
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   945
                return comp.width;
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   946
            }
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   947
            public int getHeight(Component comp) {
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   948
                return comp.height;
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   949
            }
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   950
            public int getX(Component comp) {
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   951
                return comp.x;
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   952
            }
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   953
            public int getY(Component comp) {
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   954
                return comp.y;
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   955
            }
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   956
            public Color getForeground(Component comp) {
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   957
                return comp.foreground;
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   958
            }
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   959
            public Color getBackground(Component comp) {
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   960
                return comp.background;
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   961
            }
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   962
            public void setBackground(Component comp, Color background) {
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   963
                comp.background = background;
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   964
            }
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   965
            public Font getFont(Component comp) {
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   966
                return comp.getFont_NoClientCode();
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   967
            }
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   968
            public void processEvent(Component comp, AWTEvent e) {
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   969
                comp.processEvent(e);
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   970
            }
8816
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   971
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   972
            public AccessControlContext getAccessControlContext(Component comp) {
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   973
                return comp.getAccessControlContext();
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   974
            }
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   975
        });
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   976
    }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   977
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
     * Constructs a new component. Class <code>Component</code> can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
     * extended directly to create a lightweight component that does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
     * utilize an opaque native window. A lightweight component must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
     * hosted by a native container somewhere higher up in the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
     * tree (for example, by a <code>Frame</code> object).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
    protected Component() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        appContext = AppContext.getAppContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
   989
    @SuppressWarnings({"rawtypes", "unchecked"})
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
    void initializeFocusTraversalKeys() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
        focusTraversalKeys = new Set[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
     * Constructs a name for this component.  Called by <code>getName</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
     * when the name is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
    String constructComponentName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
        return null; // For strict compliance with prior platform versions, a Component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
                     // that doesn't set its name should return null from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
                     // getName()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
     * Gets the name of the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
     * @return this component's name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
     * @see    #setName
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
     * @since JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
    public String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
        if (name == null && !nameExplicitlySet) {
1169
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
  1012
            synchronized(getObjectLock()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
                if (name == null && !nameExplicitlySet)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
                    name = constructComponentName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
     * Sets the name of the component to the specified string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
     * @param name  the string that is to be this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
     *           component's name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
     * @see #getName
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
     * @since JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
    public void setName(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
        String oldName;
1169
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
  1029
        synchronized(getObjectLock()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
            oldName = this.name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
            this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
            nameExplicitlySet = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
        firePropertyChange("name", oldName, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
     * Gets the parent of this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
     * @return the parent container of this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
     * @since JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
    public Container getParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
        return getParent_NoClientCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
    // NOTE: This method may be called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
    //       This functionality is implemented in a package-private method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
    //       to insure that it cannot be overridden by client subclasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
    final Container getParent_NoClientCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
        return parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
    // This method is overriden in the Window class to return null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
    //    because the parent field of the Window object contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
    //    the owner of the window, not its parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
    Container getContainer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
        return getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
     * programs should not directly manipulate peers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
     * replaced by <code>boolean isDisplayable()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
    public ComponentPeer getPeer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
     * Associate a <code>DropTarget</code> with this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
     * The <code>Component</code> will receive drops only if it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
     * is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
     * @see #isEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
     * @param dt The DropTarget
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
    public synchronized void setDropTarget(DropTarget dt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
        if (dt == dropTarget || (dropTarget != null && dropTarget.equals(dt)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
        DropTarget old;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
        if ((old = dropTarget) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
            if (peer != null) dropTarget.removeNotify(peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
            DropTarget t = dropTarget;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
            dropTarget = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
                t.setComponent(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
            } catch (IllegalArgumentException iae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
                // ignore it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
        // if we have a new one, and we have a peer, add it!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
        if ((dropTarget = dt) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
                dropTarget.setComponent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
                if (peer != null) dropTarget.addNotify(peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
            } catch (IllegalArgumentException iae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
                if (old != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
                        old.setComponent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
                        if (peer != null) dropTarget.addNotify(peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
                    } catch (IllegalArgumentException iae1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
                        // ignore it!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
     * Gets the <code>DropTarget</code> associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
     * <code>Component</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
    public synchronized DropTarget getDropTarget() { return dropTarget; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
     * Gets the <code>GraphicsConfiguration</code> associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
     * <code>Component</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
     * If the <code>Component</code> has not been assigned a specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
     * <code>GraphicsConfiguration</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
     * the <code>GraphicsConfiguration</code> of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
     * <code>Component</code> object's top-level container is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
     * returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
     * If the <code>Component</code> has been created, but not yet added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
     * to a <code>Container</code>, this method returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
     * @return the <code>GraphicsConfiguration</code> used by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
     *          <code>Component</code> or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
    public GraphicsConfiguration getGraphicsConfiguration() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
        synchronized(getTreeLock()) {
2459
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
  1143
            return getGraphicsConfiguration_NoClientCode();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
    final GraphicsConfiguration getGraphicsConfiguration_NoClientCode() {
2459
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
  1148
        return graphicsConfig;
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
  1149
    }
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
  1150
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
  1151
    void setGraphicsConfiguration(GraphicsConfiguration gc) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
        synchronized(getTreeLock()) {
2805
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2647
diff changeset
  1153
            if (updateGraphicsData(gc)) {
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2647
diff changeset
  1154
                removeNotify();
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2647
diff changeset
  1155
                addNotify();
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2647
diff changeset
  1156
            }
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2647
diff changeset
  1157
        }
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2647
diff changeset
  1158
    }
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2647
diff changeset
  1159
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2647
diff changeset
  1160
    boolean updateGraphicsData(GraphicsConfiguration gc) {
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2647
diff changeset
  1161
        checkTreeLock();
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2647
diff changeset
  1162
11083
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10442
diff changeset
  1163
        if (graphicsConfig == gc) {
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10442
diff changeset
  1164
            return false;
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10442
diff changeset
  1165
        }
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10442
diff changeset
  1166
2805
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2647
diff changeset
  1167
        graphicsConfig = gc;
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2647
diff changeset
  1168
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2647
diff changeset
  1169
        ComponentPeer peer = getPeer();
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2647
diff changeset
  1170
        if (peer != null) {
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2647
diff changeset
  1171
            return peer.updateGraphicsData(gc);
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2647
diff changeset
  1172
        }
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2647
diff changeset
  1173
        return false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
     * Checks that this component's <code>GraphicsDevice</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
     * <code>idString</code> matches the string argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
    void checkGD(String stringID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
        if (graphicsConfig != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
            if (!graphicsConfig.getDevice().getIDstring().equals(stringID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
                throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
                                                   "adding a container to a container on a different GraphicsDevice");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
     * Gets this component's locking object (the object that owns the thread
435
30ae000d9354 6615015: Typo in javadoc for Component.getTreeLock()
dcherepanov
parents: 432
diff changeset
  1191
     * synchronization monitor) for AWT component-tree and layout
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
     * operations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
     * @return this component's locking object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
    public final Object getTreeLock() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
        return LOCK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
    final void checkTreeLock() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
        if (!Thread.holdsLock(getTreeLock())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
            throw new IllegalStateException("This function should be called while holding treeLock");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
     * Gets the toolkit of this component. Note that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
     * the frame that contains a component controls which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
     * toolkit is used by that component. Therefore if the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
     * is moved from one frame to another, the toolkit it uses may change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
     * @return  the toolkit of this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
     * @since JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
    public Toolkit getToolkit() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
        return getToolkitImpl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
     * This is called by the native code, so client code can't
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
     * be called on the toolkit thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
    final Toolkit getToolkitImpl() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
        ComponentPeer peer = this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
        if ((peer != null) && ! (peer instanceof LightweightPeer)){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
            return peer.getToolkit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
        Container parent = this.parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
        if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
            return parent.getToolkitImpl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
        return Toolkit.getDefaultToolkit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
     * Determines whether this component is valid. A component is valid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
     * when it is correctly sized and positioned within its parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
     * container and all its children are also valid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
     * In order to account for peers' size requirements, components are invalidated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
     * before they are first shown on the screen. By the time the parent container
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
     * is fully realized, all its components will be valid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
     * @return <code>true</code> if the component is valid, <code>false</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
     * otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
     * @see #validate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
     * @see #invalidate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
     * @since JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
    public boolean isValid() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
        return (peer != null) && valid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
     * Determines whether this component is displayable. A component is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
     * displayable when it is connected to a native screen resource.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
     * A component is made displayable either when it is added to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
     * a displayable containment hierarchy or when its containment
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
     * hierarchy is made displayable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
     * A containment hierarchy is made displayable when its ancestor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
     * window is either packed or made visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
     * A component is made undisplayable either when it is removed from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
     * a displayable containment hierarchy or when its containment hierarchy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
     * is made undisplayable.  A containment hierarchy is made
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
     * undisplayable when its ancestor window is disposed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
     * @return <code>true</code> if the component is displayable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
     * <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
     * @see Container#add(Component)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
     * @see Window#pack
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
     * @see Window#show
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
     * @see Container#remove(Component)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
     * @see Window#dispose
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
    public boolean isDisplayable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
        return getPeer() != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
     * Determines whether this component should be visible when its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
     * parent is visible. Components are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
     * initially visible, with the exception of top level components such
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
     * as <code>Frame</code> objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
     * @return <code>true</code> if the component is visible,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
     * <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
     * @see #setVisible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
     * @since JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
     */
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 130
diff changeset
  1288
    @Transient
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
    public boolean isVisible() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
        return isVisible_NoClientCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
    final boolean isVisible_NoClientCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
        return visible;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
     * Determines whether this component will be displayed on the screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
     * @return <code>true</code> if the component and all of its ancestors
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
     *          until a toplevel window or null parent are visible,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
     *          <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
    boolean isRecursivelyVisible() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
        return visible && (parent == null || parent.isRecursivelyVisible());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
     * Translates absolute coordinates into coordinates in the coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
     * space of this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
    Point pointRelativeToComponent(Point absolute) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
        Point compCoords = getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
        return new Point(absolute.x - compCoords.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
                         absolute.y - compCoords.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
     * Assuming that mouse location is stored in PointerInfo passed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
     * to this method, it finds a Component that is in the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
     * Window as this Component and is located under the mouse pointer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
     * If no such Component exists, null is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
     * NOTE: this method should be called under the protection of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
     * tree lock, as it is done in Component.getMousePosition() and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
     * Container.getMousePosition(boolean).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
    Component findUnderMouseInWindow(PointerInfo pi) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
        if (!isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
        Window win = getContainingWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
        if (!Toolkit.getDefaultToolkit().getMouseInfoPeer().isWindowUnderMouse(win)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
        final boolean INCLUDE_DISABLED = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
        Point relativeToWindow = win.pointRelativeToComponent(pi.getLocation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
        Component inTheSameWindow = win.findComponentAt(relativeToWindow.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
                                                        relativeToWindow.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
                                                        INCLUDE_DISABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
        return inTheSameWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
     * Returns the position of the mouse pointer in this <code>Component</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
     * coordinate space if the <code>Component</code> is directly under the mouse
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
     * pointer, otherwise returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
     * If the <code>Component</code> is not showing on the screen, this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
     * returns <code>null</code> even if the mouse pointer is above the area
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
     * where the <code>Component</code> would be displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
     * If the <code>Component</code> is partially or fully obscured by other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
     * <code>Component</code>s or native windows, this method returns a non-null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
     * value only if the mouse pointer is located above the unobscured part of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
     * <code>Component</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
     * For <code>Container</code>s it returns a non-null value if the mouse is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
     * above the <code>Container</code> itself or above any of its descendants.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
     * Use {@link Container#getMousePosition(boolean)} if you need to exclude children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
     * Sometimes the exact mouse coordinates are not important, and the only thing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
     * that matters is whether a specific <code>Component</code> is under the mouse
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
     * pointer. If the return value of this method is <code>null</code>, mouse
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
     * pointer is not directly above the <code>Component</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
     * @exception HeadlessException if GraphicsEnvironment.isHeadless() returns true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
     * @see       #isShowing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
     * @see       Container#getMousePosition
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
     * @return    mouse coordinates relative to this <code>Component</code>, or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
     * @since     1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
    public Point getMousePosition() throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
        if (GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
            throw new HeadlessException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  1373
        PointerInfo pi = java.security.AccessController.doPrivileged(
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  1374
                                                                     new java.security.PrivilegedAction<PointerInfo>() {
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  1375
                                                                         public PointerInfo run() {
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  1376
                                                                             return MouseInfo.getPointerInfo();
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  1377
                                                                         }
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  1378
                                                                     }
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  1379
                                                                     );
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
            Component inTheSameWindow = findUnderMouseInWindow(pi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
            if (!isSameOrAncestorOf(inTheSameWindow, true)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
            return pointRelativeToComponent(pi.getLocation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
     * Overridden in Container. Must be called under TreeLock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
    boolean isSameOrAncestorOf(Component comp, boolean allowChildren) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
        return comp == this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
     * Determines whether this component is showing on screen. This means
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
     * that the component must be visible, and it must be in a container
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
     * that is visible and showing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
     * <strong>Note:</strong> sometimes there is no way to detect whether the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
     * {@code Component} is actually visible to the user.  This can happen when:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
     * <li>the component has been added to a visible {@code ScrollPane} but
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
     * the {@code Component} is not currently in the scroll pane's view port.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
     * <li>the {@code Component} is obscured by another {@code Component} or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
     * {@code Container}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
     * @return <code>true</code> if the component is showing,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
     *          <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
     * @see #setVisible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
     * @since JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
    public boolean isShowing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
        if (visible && (peer != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
            Container parent = this.parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
            return (parent == null) || parent.isShowing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
     * Determines whether this component is enabled. An enabled component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
     * can respond to user input and generate events. Components are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
     * enabled initially by default. A component may be enabled or disabled by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
     * calling its <code>setEnabled</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
     * @return <code>true</code> if the component is enabled,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
     *          <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
     * @see #setEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
     * @since JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
    public boolean isEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
        return isEnabledImpl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
     * This is called by the native code, so client code can't
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
     * be called on the toolkit thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
    final boolean isEnabledImpl() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
        return enabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
     * Enables or disables this component, depending on the value of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
     * parameter <code>b</code>. An enabled component can respond to user
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
     * input and generate events. Components are enabled initially by default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
     * <p>Note: Disabling a lightweight component does not prevent it from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
     * receiving MouseEvents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
     * <p>Note: Disabling a heavyweight container prevents all components
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
     * in this container from receiving any input events.  But disabling a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
     * lightweight container affects only this container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
     * @param     b   If <code>true</code>, this component is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
     *            enabled; otherwise this component is disabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
     * @see #isEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
     * @see #isLightweight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
     * @since JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
    public void setEnabled(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
        enable(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
     * replaced by <code>setEnabled(boolean)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
    public void enable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
        if (!enabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
            synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
                enabled = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
                ComponentPeer peer = this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
                if (peer != null) {
1964
934568dfe859 6749920: Cleanup AWT peer interfaces
rkennke
parents: 1188
diff changeset
  1477
                    peer.setEnabled(true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
                    if (visible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
                        updateCursorImmediately();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
            if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
                accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
                                                     AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
                                                     null, AccessibleState.ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
     * replaced by <code>setEnabled(boolean)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
    public void enable(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
        if (b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
            enable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
            disable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
     * replaced by <code>setEnabled(boolean)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
    public void disable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
        if (enabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
            KeyboardFocusManager.clearMostRecentFocusOwner(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
            synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
                enabled = false;
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  1514
                // A disabled lw container is allowed to contain a focus owner.
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  1515
                if ((isFocusOwner() || (containsFocus() && !isLightweight())) &&
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  1516
                    KeyboardFocusManager.isAutoFocusTransferEnabled())
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  1517
                {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
                    // Don't clear the global focus owner. If transferFocus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
                    // fails, we want the focus to stay on the disabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
                    // Component so that keyboard traversal, et. al. still
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
                    // makes sense to the user.
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  1522
                    transferFocus(false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
                ComponentPeer peer = this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
                if (peer != null) {
1964
934568dfe859 6749920: Cleanup AWT peer interfaces
rkennke
parents: 1188
diff changeset
  1526
                    peer.setEnabled(false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
                    if (visible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
                        updateCursorImmediately();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
            if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
                accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
                                                     AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
                                                     null, AccessibleState.ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
     * Returns true if this component is painted to an offscreen image
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
     * ("buffer") that's copied to the screen later.  Component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
     * subclasses that support double buffering should override this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
     * method to return true if double buffering is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
     * @return false by default
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
    public boolean isDoubleBuffered() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
     * Enables or disables input method support for this component. If input
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
     * method support is enabled and the component also processes key events,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
     * incoming events are offered to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
     * the current input method and will only be processed by the component or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
     * dispatched to its listeners if the input method does not consume them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
     * By default, input method support is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
     * @param enable true to enable, false to disable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
     * @see #processKeyEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
    public void enableInputMethods(boolean enable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
        if (enable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
            if ((eventMask & AWTEvent.INPUT_METHODS_ENABLED_MASK) != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
            // If this component already has focus, then activate the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
            // input method by dispatching a synthesized focus gained
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
            // event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
            if (isFocusOwner()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
                InputContext inputContext = getInputContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
                if (inputContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
                    FocusEvent focusGainedEvent =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
                        new FocusEvent(this, FocusEvent.FOCUS_GAINED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
                    inputContext.dispatchEvent(focusGainedEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
            eventMask |= AWTEvent.INPUT_METHODS_ENABLED_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
            if ((eventMask & AWTEvent.INPUT_METHODS_ENABLED_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
                InputContext inputContext = getInputContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
                if (inputContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
                    inputContext.endComposition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
                    inputContext.removeNotify(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
            eventMask &= ~AWTEvent.INPUT_METHODS_ENABLED_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
     * Shows or hides this component depending on the value of parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
     * <code>b</code>.
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  1597
     * <p>
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  1598
     * This method changes layout-related information, and therefore,
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  1599
     * invalidates the component hierarchy.
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  1600
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
     * @param b  if <code>true</code>, shows this component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
     * otherwise, hides this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
     * @see #isVisible
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  1604
     * @see #invalidate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
     * @since JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
    public void setVisible(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
        show(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
     * replaced by <code>setVisible(boolean)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
    public void show() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
        if (!visible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
            synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
                visible = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
                mixOnShowing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
                ComponentPeer peer = this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
                if (peer != null) {
1964
934568dfe859 6749920: Cleanup AWT peer interfaces
rkennke
parents: 1188
diff changeset
  1623
                    peer.setVisible(true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
                    createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
                                          this, parent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
                                          HierarchyEvent.SHOWING_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
                                          Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
                    if (peer instanceof LightweightPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
                        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
                    updateCursorImmediately();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
                if (componentListener != null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
                    (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
                    Toolkit.enabledOnToolkit(AWTEvent.COMPONENT_EVENT_MASK)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
                    ComponentEvent e = new ComponentEvent(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
                                                          ComponentEvent.COMPONENT_SHOWN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
                    Toolkit.getEventQueue().postEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
            Container parent = this.parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
            if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
                parent.invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
     * replaced by <code>setVisible(boolean)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
    public void show(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
        if (b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
            show();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
            hide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
    boolean containsFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
        return isFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
    void clearMostRecentFocusOwnerOnHide() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
        KeyboardFocusManager.clearMostRecentFocusOwner(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
    void clearCurrentFocusCycleRootOnHide() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
        /* do nothing */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
     * replaced by <code>setVisible(boolean)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
    public void hide() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
        isPacked = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
        if (visible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
            clearCurrentFocusCycleRootOnHide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
            clearMostRecentFocusOwnerOnHide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
            synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
                visible = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
                mixOnHiding(isLightweight());
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  1688
                if (containsFocus() && KeyboardFocusManager.isAutoFocusTransferEnabled()) {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  1689
                    transferFocus(true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
                ComponentPeer peer = this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
                if (peer != null) {
1964
934568dfe859 6749920: Cleanup AWT peer interfaces
rkennke
parents: 1188
diff changeset
  1693
                    peer.setVisible(false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
                    createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
                                          this, parent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
                                          HierarchyEvent.SHOWING_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
                                          Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
                    if (peer instanceof LightweightPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
                        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
                    updateCursorImmediately();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
                if (componentListener != null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
                    (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
                    Toolkit.enabledOnToolkit(AWTEvent.COMPONENT_EVENT_MASK)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
                    ComponentEvent e = new ComponentEvent(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
                                                          ComponentEvent.COMPONENT_HIDDEN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
                    Toolkit.getEventQueue().postEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
            Container parent = this.parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
            if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
                parent.invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
     * Gets the foreground color of this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
     * @return this component's foreground color; if this component does
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
     * not have a foreground color, the foreground color of its parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
     * is returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
     * @see #setForeground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
     * @since JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
     */
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 130
diff changeset
  1728
    @Transient
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
    public Color getForeground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
        Color foreground = this.foreground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
        if (foreground != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
            return foreground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
        Container parent = this.parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
        return (parent != null) ? parent.getForeground() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
     * Sets the foreground color of this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
     * @param c the color to become this component's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
     *          foreground color; if this parameter is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
     *          then this component will inherit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
     *          the foreground color of its parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
     * @see #getForeground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
     * @since JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
    public void setForeground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
        Color oldColor = foreground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
        ComponentPeer peer = this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
        foreground = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
        if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
            c = getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
            if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
                peer.setForeground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
        // This is a bound property, so report the change to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
        // any registered listeners.  (Cheap if there are none.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
        firePropertyChange("foreground", oldColor, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
     * Returns whether the foreground color has been explicitly set for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
     * Component. If this method returns <code>false</code>, this Component is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
     * inheriting its foreground color from an ancestor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
     * @return <code>true</code> if the foreground color has been explicitly
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
     *         set for this Component; <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
    public boolean isForegroundSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
        return (foreground != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
     * Gets the background color of this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
     * @return this component's background color; if this component does
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
     *          not have a background color,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
     *          the background color of its parent is returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
     * @see #setBackground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
     * @since JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
     */
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 130
diff changeset
  1783
    @Transient
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
    public Color getBackground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
        Color background = this.background;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
        if (background != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
            return background;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
        Container parent = this.parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
        return (parent != null) ? parent.getBackground() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
     * Sets the background color of this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
     * The background color affects each component differently and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
     * parts of the component that are affected by the background color
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
     * may differ between operating systems.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
     * @param c the color to become this component's color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
     *          if this parameter is <code>null</code>, then this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
     *          component will inherit the background color of its parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
     * @see #getBackground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
     * @since JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
    public void setBackground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
        Color oldColor = background;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
        ComponentPeer peer = this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
        background = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
        if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
            c = getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
            if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
                peer.setBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
        // This is a bound property, so report the change to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
        // any registered listeners.  (Cheap if there are none.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
        firePropertyChange("background", oldColor, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
     * Returns whether the background color has been explicitly set for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
     * Component. If this method returns <code>false</code>, this Component is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
     * inheriting its background color from an ancestor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
     * @return <code>true</code> if the background color has been explicitly
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
     *         set for this Component; <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
    public boolean isBackgroundSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
        return (background != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
     * Gets the font of this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
     * @return this component's font; if a font has not been set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
     * for this component, the font of its parent is returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
     * @see #setFont
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
     * @since JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
     */
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 130
diff changeset
  1843
    @Transient
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
    public Font getFont() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
        return getFont_NoClientCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
    // NOTE: This method may be called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
    //       This functionality is implemented in a package-private method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
    //       to insure that it cannot be overridden by client subclasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
    final Font getFont_NoClientCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
        Font font = this.font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
        if (font != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
            return font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
        Container parent = this.parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
        return (parent != null) ? parent.getFont_NoClientCode() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
     * Sets the font of this component.
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  1863
     * <p>
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  1864
     * This method changes layout-related information, and therefore,
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  1865
     * invalidates the component hierarchy.
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  1866
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
     * @param f the font to become this component's font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
     *          if this parameter is <code>null</code> then this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
     *          component will inherit the font of its parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
     * @see #getFont
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  1871
     * @see #invalidate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
     * @since JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
    public void setFont(Font f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
        Font oldFont, newFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
        synchronized(getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
            synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
                oldFont = font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
                newFont = font = f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
            ComponentPeer peer = this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
                f = getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
                if (f != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
                    peer.setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
                    peerFont = f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
        // This is a bound property, so report the change to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
        // any registered listeners.  (Cheap if there are none.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
        firePropertyChange("font", oldFont, newFont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
        // This could change the preferred size of the Component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
        // Fix for 6213660. Should compare old and new fonts and do not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
        // call invalidate() if they are equal.
1183
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
  1899
        if (f != oldFont && (oldFont == null ||
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
                                      !oldFont.equals(f))) {
1183
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
  1901
            invalidateIfValid();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
     * Returns whether the font has been explicitly set for this Component. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
     * this method returns <code>false</code>, this Component is inheriting its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
     * font from an ancestor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
     * @return <code>true</code> if the font has been explicitly set for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
     *         Component; <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
    public boolean isFontSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
        return (font != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
     * Gets the locale of this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
     * @return this component's locale; if this component does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
     *          have a locale, the locale of its parent is returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
     * @see #setLocale
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
     * @exception IllegalComponentStateException if the <code>Component</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
     *          does not have its own locale and has not yet been added to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
     *          a containment hierarchy such that the locale can be determined
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
     *          from the containing parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
     * @since  JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
    public Locale getLocale() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
        Locale locale = this.locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
        if (locale != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
            return locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
        Container parent = this.parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
        if (parent == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
            throw new IllegalComponentStateException("This component must have a parent in order to determine its locale");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
            return parent.getLocale();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
     * Sets the locale of this component.  This is a bound property.
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  1945
     * <p>
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  1946
     * This method changes layout-related information, and therefore,
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  1947
     * invalidates the component hierarchy.
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  1948
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
     * @param l the locale to become this component's locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
     * @see #getLocale
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  1951
     * @see #invalidate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
     * @since JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
    public void setLocale(Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
        Locale oldValue = locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
        locale = l;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
        // This is a bound property, so report the change to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
        // any registered listeners.  (Cheap if there are none.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
        firePropertyChange("locale", oldValue, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
        // This could change the preferred size of the Component.
1183
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
  1963
        invalidateIfValid();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
     * Gets the instance of <code>ColorModel</code> used to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
     * the component on the output device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
     * @return the color model used by this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
     * @see java.awt.image.ColorModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
     * @see java.awt.peer.ComponentPeer#getColorModel()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
     * @see Toolkit#getColorModel()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
     * @since JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
    public ColorModel getColorModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
        ComponentPeer peer = this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
        if ((peer != null) && ! (peer instanceof LightweightPeer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
            return peer.getColorModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
        } else if (GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
            return ColorModel.getRGBdefault();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
        } // else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
        return getToolkit().getColorModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
     * Gets the location of this component in the form of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
     * point specifying the component's top-left corner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
     * The location will be relative to the parent's coordinate space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
     * Due to the asynchronous nature of native event handling, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
     * method can return outdated values (for instance, after several calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
     * of <code>setLocation()</code> in rapid succession).  For this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
     * reason, the recommended method of obtaining a component's position is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
     * within <code>java.awt.event.ComponentListener.componentMoved()</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
     * which is called after the operating system has finished moving the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
     * component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
     * </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
     * @return an instance of <code>Point</code> representing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
     *          the top-left corner of the component's bounds in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
     *          the coordinate space of the component's parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
     * @see #setLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
     * @see #getLocationOnScreen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
     * @since JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
    public Point getLocation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
        return location();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
     * Gets the location of this component in the form of a point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
     * specifying the component's top-left corner in the screen's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
     * coordinate space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
     * @return an instance of <code>Point</code> representing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
     *          the top-left corner of the component's bounds in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
     *          coordinate space of the screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
     * @throws <code>IllegalComponentStateException</code> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
     *          component is not showing on the screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
     * @see #setLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
     * @see #getLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
    public Point getLocationOnScreen() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
            return getLocationOnScreen_NoTreeLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
     * a package private version of getLocationOnScreen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
     * used by GlobalCursormanager to update cursor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
    final Point getLocationOnScreen_NoTreeLock() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
        if (peer != null && isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
            if (peer instanceof LightweightPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
                // lightweight component location needs to be translated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
                // relative to a native component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
                Container host = getNativeContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
                Point pt = host.peer.getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
                for(Component c = this; c != host; c = c.getParent()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
                    pt.x += c.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
                    pt.y += c.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
                return pt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
                Point pt = peer.getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
                return pt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
            throw new IllegalComponentStateException("component must be showing on the screen to determine its location");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
     * replaced by <code>getLocation()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
    public Point location() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
        return location_NoClientCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
    private Point location_NoClientCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
        return new Point(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
     * Moves this component to a new location. The top-left corner of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
     * the new location is specified by the <code>x</code> and <code>y</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
     * parameters in the coordinate space of this component's parent.
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2071
     * <p>
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2072
     * This method changes layout-related information, and therefore,
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2073
     * invalidates the component hierarchy.
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2074
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
     * @param x the <i>x</i>-coordinate of the new location's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
     *          top-left corner in the parent's coordinate space
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
     * @param y the <i>y</i>-coordinate of the new location's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
     *          top-left corner in the parent's coordinate space
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
     * @see #getLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
     * @see #setBounds
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2081
     * @see #invalidate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
     * @since JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
    public void setLocation(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
        move(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
     * replaced by <code>setLocation(int, int)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
    public void move(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
        synchronized(getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
            setBoundsOp(ComponentPeer.SET_LOCATION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
            setBounds(x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
     * Moves this component to a new location. The top-left corner of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
     * the new location is specified by point <code>p</code>. Point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
     * <code>p</code> is given in the parent's coordinate space.
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2104
     * <p>
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2105
     * This method changes layout-related information, and therefore,
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2106
     * invalidates the component hierarchy.
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2107
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
     * @param p the point defining the top-left corner
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
     *          of the new location, given in the coordinate space of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
     *          component's parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
     * @see #getLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
     * @see #setBounds
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2113
     * @see #invalidate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
     * @since JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
    public void setLocation(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
        setLocation(p.x, p.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
     * Returns the size of this component in the form of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
     * <code>Dimension</code> object. The <code>height</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
     * field of the <code>Dimension</code> object contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
     * this component's height, and the <code>width</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
     * field of the <code>Dimension</code> object contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
     * this component's width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
     * @return a <code>Dimension</code> object that indicates the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
     *          size of this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
     * @see #setSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
     * @since JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
    public Dimension getSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
        return size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2135
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
     * replaced by <code>getSize()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
    public Dimension size() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
        return new Dimension(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
     * Resizes this component so that it has width <code>width</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
     * and height <code>height</code>.
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2148
     * <p>
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2149
     * This method changes layout-related information, and therefore,
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2150
     * invalidates the component hierarchy.
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2151
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
     * @param width the new width of this component in pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
     * @param height the new height of this component in pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
     * @see #getSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
     * @see #setBounds
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2156
     * @see #invalidate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
     * @since JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
    public void setSize(int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
        resize(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
     * replaced by <code>setSize(int, int)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
    public void resize(int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
        synchronized(getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
            setBoundsOp(ComponentPeer.SET_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
            setBounds(x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
     * Resizes this component so that it has width <code>d.width</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
     * and height <code>d.height</code>.
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2178
     * <p>
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2179
     * This method changes layout-related information, and therefore,
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2180
     * invalidates the component hierarchy.
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2181
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
     * @param d the dimension specifying the new size
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
     *          of this component
7154
4e8371f358ac 6877895: Some AWT's methods should specify throwing NPE for null arg value
dcherepanov
parents: 5506
diff changeset
  2184
     * @throws NullPointerException if {@code d} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
     * @see #setSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
     * @see #setBounds
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2187
     * @see #invalidate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
     * @since JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
    public void setSize(Dimension d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
        resize(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
     * replaced by <code>setSize(Dimension)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
    public void resize(Dimension d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
        setSize(d.width, d.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
     * Gets the bounds of this component in the form of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
     * <code>Rectangle</code> object. The bounds specify this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
     * component's width, height, and location relative to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
     * its parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
     * @return a rectangle indicating this component's bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
     * @see #setBounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
     * @see #getLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
     * @see #getSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
    public Rectangle getBounds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
        return bounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2217
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2218
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
     * replaced by <code>getBounds()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
    public Rectangle bounds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
        return new Rectangle(x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
     * Moves and resizes this component. The new location of the top-left
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
     * corner is specified by <code>x</code> and <code>y</code>, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
     * new size is specified by <code>width</code> and <code>height</code>.
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2230
     * <p>
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2231
     * This method changes layout-related information, and therefore,
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2232
     * invalidates the component hierarchy.
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2233
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
     * @param x the new <i>x</i>-coordinate of this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
     * @param y the new <i>y</i>-coordinate of this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
     * @param width the new <code>width</code> of this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
     * @param height the new <code>height</code> of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
     *          component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
     * @see #getBounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
     * @see #setLocation(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
     * @see #setLocation(Point)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
     * @see #setSize(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
     * @see #setSize(Dimension)
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2244
     * @see #invalidate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
     * @since JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2247
    public void setBounds(int x, int y, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2248
        reshape(x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2250
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2251
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2252
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2253
     * replaced by <code>setBounds(int, int, int, int)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2254
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2255
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
    public void reshape(int x, int y, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2257
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2258
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
                setBoundsOp(ComponentPeer.SET_BOUNDS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2260
                boolean resized = (this.width != width) || (this.height != height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2261
                boolean moved = (this.x != x) || (this.y != y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2262
                if (!resized && !moved) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2263
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2264
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2265
                int oldX = this.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
                int oldY = this.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2267
                int oldWidth = this.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2268
                int oldHeight = this.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2269
                this.x = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2270
                this.y = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2271
                this.width = width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2272
                this.height = height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
                if (resized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
                    isPacked = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2277
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2278
                boolean needNotify = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2279
                mixOnReshaping();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
                if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2281
                    // LightwightPeer is an empty stub so can skip peer.reshape
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2282
                    if (!(peer instanceof LightweightPeer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2283
                        reshapeNativePeer(x, y, width, height, getBoundsOp());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
                        // Check peer actualy changed coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2285
                        resized = (oldWidth != this.width) || (oldHeight != this.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2286
                        moved = (oldX != this.x) || (oldY != this.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
                        // fix for 5025858: do not send ComponentEvents for toplevel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
                        // windows here as it is done from peer or native code when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
                        // the window is really resized or moved, otherwise some
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
                        // events may be sent twice
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2291
                        if (this instanceof Window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
                            needNotify = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2294
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
                    if (resized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2296
                        invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
                    }
1183
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
  2298
                    if (parent != null) {
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
  2299
                        parent.invalidateIfValid();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2300
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2301
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2302
                if (needNotify) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2303
                    notifyNewBounds(resized, moved);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2304
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2305
                repaintParentIfNeeded(oldX, oldY, oldWidth, oldHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2306
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2307
                setBoundsOp(ComponentPeer.RESET_OPERATION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2308
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2309
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2311
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2312
    private void repaintParentIfNeeded(int oldX, int oldY, int oldWidth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2313
                                       int oldHeight)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
        if (parent != null && peer instanceof LightweightPeer && isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2316
            // Have the parent redraw the area this component occupied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
            parent.repaint(oldX, oldY, oldWidth, oldHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
            // Have the parent redraw the area this component *now* occupies.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2319
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2322
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2323
    private void reshapeNativePeer(int x, int y, int width, int height, int op) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2324
        // native peer might be offset by more than direct
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2325
        // parent since parent might be lightweight.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2326
        int nativeX = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2327
        int nativeY = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
        for (Component c = parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2329
             (c != null) && (c.peer instanceof LightweightPeer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2330
             c = c.parent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2331
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2332
            nativeX += c.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2333
            nativeY += c.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2334
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2335
        peer.setBounds(nativeX, nativeY, width, height, op);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2337
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  2338
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2339
    private void notifyNewBounds(boolean resized, boolean moved) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2340
        if (componentListener != null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2341
            || (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2342
            || Toolkit.enabledOnToolkit(AWTEvent.COMPONENT_EVENT_MASK))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2343
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2344
                if (resized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2345
                    ComponentEvent e = new ComponentEvent(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2346
                                                          ComponentEvent.COMPONENT_RESIZED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2347
                    Toolkit.getEventQueue().postEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2348
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2349
                if (moved) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2350
                    ComponentEvent e = new ComponentEvent(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2351
                                                          ComponentEvent.COMPONENT_MOVED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2352
                    Toolkit.getEventQueue().postEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2353
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2354
            } else {
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  2355
                if (this instanceof Container && ((Container)this).countComponents() > 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2356
                    boolean enabledOnToolkit =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2357
                        Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2358
                    if (resized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2359
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2360
                        ((Container)this).createChildHierarchyEvents(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2361
                                                                     HierarchyEvent.ANCESTOR_RESIZED, 0, enabledOnToolkit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2362
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2363
                    if (moved) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2364
                        ((Container)this).createChildHierarchyEvents(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2365
                                                                     HierarchyEvent.ANCESTOR_MOVED, 0, enabledOnToolkit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2366
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2367
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2368
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2369
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2370
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2372
     * Moves and resizes this component to conform to the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2373
     * bounding rectangle <code>r</code>. This component's new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2374
     * position is specified by <code>r.x</code> and <code>r.y</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2375
     * and its new size is specified by <code>r.width</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2376
     * <code>r.height</code>
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2377
     * <p>
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2378
     * This method changes layout-related information, and therefore,
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2379
     * invalidates the component hierarchy.
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2380
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2381
     * @param r the new bounding rectangle for this component
7154
4e8371f358ac 6877895: Some AWT's methods should specify throwing NPE for null arg value
dcherepanov
parents: 5506
diff changeset
  2382
     * @throws NullPointerException if {@code r} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2383
     * @see       #getBounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2384
     * @see       #setLocation(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2385
     * @see       #setLocation(Point)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2386
     * @see       #setSize(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2387
     * @see       #setSize(Dimension)
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2388
     * @see #invalidate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2389
     * @since     JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2390
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2391
    public void setBounds(Rectangle r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2392
        setBounds(r.x, r.y, r.width, r.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2393
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2394
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2395
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2396
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2397
     * Returns the current x coordinate of the components origin.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2398
     * This method is preferable to writing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2399
     * <code>component.getBounds().x</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2400
     * or <code>component.getLocation().x</code> because it doesn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2401
     * cause any heap allocations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2402
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2403
     * @return the current x coordinate of the components origin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2404
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2405
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2406
    public int getX() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2407
        return x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2408
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2409
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2410
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2411
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2412
     * Returns the current y coordinate of the components origin.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2413
     * This method is preferable to writing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2414
     * <code>component.getBounds().y</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2415
     * or <code>component.getLocation().y</code> because it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2416
     * doesn't cause any heap allocations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2417
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2418
     * @return the current y coordinate of the components origin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2419
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2420
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2421
    public int getY() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2422
        return y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2423
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2424
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2425
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2426
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2427
     * Returns the current width of this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2428
     * This method is preferable to writing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2429
     * <code>component.getBounds().width</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2430
     * or <code>component.getSize().width</code> because it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2431
     * doesn't cause any heap allocations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2432
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2433
     * @return the current width of this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2434
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2435
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2436
    public int getWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2437
        return width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2438
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2439
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2440
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2441
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2442
     * Returns the current height of this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2443
     * This method is preferable to writing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2444
     * <code>component.getBounds().height</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2445
     * or <code>component.getSize().height</code> because it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2446
     * doesn't cause any heap allocations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2447
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2448
     * @return the current height of this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2449
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2450
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2451
    public int getHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2452
        return height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2453
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2454
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2455
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2456
     * Stores the bounds of this component into "return value" <b>rv</b> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2457
     * return <b>rv</b>.  If rv is <code>null</code> a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2458
     * <code>Rectangle</code> is allocated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2459
     * This version of <code>getBounds</code> is useful if the caller
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2460
     * wants to avoid allocating a new <code>Rectangle</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2461
     * on the heap.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2462
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2463
     * @param rv the return value, modified to the components bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2464
     * @return rv
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2465
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2466
    public Rectangle getBounds(Rectangle rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2467
        if (rv == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2468
            return new Rectangle(getX(), getY(), getWidth(), getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2469
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2470
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2471
            rv.setBounds(getX(), getY(), getWidth(), getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2472
            return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2473
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2474
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2475
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2476
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2477
     * Stores the width/height of this component into "return value" <b>rv</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2478
     * and return <b>rv</b>.   If rv is <code>null</code> a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2479
     * <code>Dimension</code> object is allocated.  This version of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2480
     * <code>getSize</code> is useful if the caller wants to avoid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2481
     * allocating a new <code>Dimension</code> object on the heap.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2482
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2483
     * @param rv the return value, modified to the components size
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2484
     * @return rv
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2485
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2486
    public Dimension getSize(Dimension rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2487
        if (rv == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2488
            return new Dimension(getWidth(), getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2489
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2490
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2491
            rv.setSize(getWidth(), getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2492
            return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2493
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2494
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2495
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2496
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2497
     * Stores the x,y origin of this component into "return value" <b>rv</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2498
     * and return <b>rv</b>.   If rv is <code>null</code> a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2499
     * <code>Point</code> is allocated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2500
     * This version of <code>getLocation</code> is useful if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2501
     * caller wants to avoid allocating a new <code>Point</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2502
     * object on the heap.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2503
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2504
     * @param rv the return value, modified to the components location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2505
     * @return rv
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2506
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2507
    public Point getLocation(Point rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2508
        if (rv == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2509
            return new Point(getX(), getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2510
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2511
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2512
            rv.setLocation(getX(), getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2513
            return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2514
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2515
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2516
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2517
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2518
     * Returns true if this component is completely opaque, returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2519
     * false by default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2520
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2521
     * An opaque component paints every pixel within its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2522
     * rectangular region. A non-opaque component paints only some of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2523
     * its pixels, allowing the pixels underneath it to "show through".
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2524
     * A component that does not fully paint its pixels therefore
3237
7c6c2d9361d9 6837446: Introduce Window.isOpaque() method
anthony
parents: 3084
diff changeset
  2525
     * provides a degree of transparency.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2526
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2527
     * Subclasses that guarantee to always completely paint their
3237
7c6c2d9361d9 6837446: Introduce Window.isOpaque() method
anthony
parents: 3084
diff changeset
  2528
     * contents should override this method and return true.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2529
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2530
     * @return true if this component is completely opaque
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2531
     * @see #isLightweight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2532
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2533
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2534
    public boolean isOpaque() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2535
        if (getPeer() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2536
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2537
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2538
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2539
            return !isLightweight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2540
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2541
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2542
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2543
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2544
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2545
     * A lightweight component doesn't have a native toolkit peer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2546
     * Subclasses of <code>Component</code> and <code>Container</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2547
     * other than the ones defined in this package like <code>Button</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2548
     * or <code>Scrollbar</code>, are lightweight.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2549
     * All of the Swing components are lightweights.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2550
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2551
     * This method will always return <code>false</code> if this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2552
     * is not displayable because it is impossible to determine the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2553
     * weight of an undisplayable component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2554
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2555
     * @return true if this component has a lightweight peer; false if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2556
     *         it has a native peer or no peer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2557
     * @see #isDisplayable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2558
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2559
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2560
    public boolean isLightweight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2561
        return getPeer() instanceof LightweightPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2562
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2563
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2564
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2565
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2566
     * Sets the preferred size of this component to a constant
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2567
     * value.  Subsequent calls to <code>getPreferredSize</code> will always
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2568
     * return this value.  Setting the preferred size to <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2569
     * restores the default behavior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2570
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2571
     * @param preferredSize The new preferred size, or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2572
     * @see #getPreferredSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2573
     * @see #isPreferredSizeSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2574
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2575
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2576
    public void setPreferredSize(Dimension preferredSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2577
        Dimension old;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2578
        // If the preferred size was set, use it as the old value, otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2579
        // use null to indicate we didn't previously have a set preferred
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2580
        // size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2581
        if (prefSizeSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2582
            old = this.prefSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2583
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2584
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2585
            old = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2586
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2587
        this.prefSize = preferredSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2588
        prefSizeSet = (preferredSize != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2589
        firePropertyChange("preferredSize", old, preferredSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2590
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2591
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2592
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2593
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2594
     * Returns true if the preferred size has been set to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2595
     * non-<code>null</code> value otherwise returns false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2596
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2597
     * @return true if <code>setPreferredSize</code> has been invoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2598
     *         with a non-null value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2599
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2600
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2601
    public boolean isPreferredSizeSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2602
        return prefSizeSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2603
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2604
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2605
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2606
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2607
     * Gets the preferred size of this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2608
     * @return a dimension object indicating this component's preferred size
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2609
     * @see #getMinimumSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2610
     * @see LayoutManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2611
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2612
    public Dimension getPreferredSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2613
        return preferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2614
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2615
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2616
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2617
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2618
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2619
     * replaced by <code>getPreferredSize()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2620
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2621
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2622
    public Dimension preferredSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2623
        /* Avoid grabbing the lock if a reasonable cached size value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2624
         * is available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2625
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2626
        Dimension dim = prefSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2627
        if (dim == null || !(isPreferredSizeSet() || isValid())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2628
            synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2629
                prefSize = (peer != null) ?
1964
934568dfe859 6749920: Cleanup AWT peer interfaces
rkennke
parents: 1188
diff changeset
  2630
                    peer.getPreferredSize() :
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2631
                    getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2632
                dim = prefSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2633
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2634
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2635
        return new Dimension(dim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2636
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2637
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2638
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2639
     * Sets the minimum size of this component to a constant
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2640
     * value.  Subsequent calls to <code>getMinimumSize</code> will always
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2641
     * return this value.  Setting the minimum size to <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2642
     * restores the default behavior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2643
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2644
     * @param minimumSize the new minimum size of this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2645
     * @see #getMinimumSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2646
     * @see #isMinimumSizeSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2647
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2648
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2649
    public void setMinimumSize(Dimension minimumSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2650
        Dimension old;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2651
        // If the minimum size was set, use it as the old value, otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2652
        // use null to indicate we didn't previously have a set minimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2653
        // size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2654
        if (minSizeSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2655
            old = this.minSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2656
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2657
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2658
            old = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2659
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2660
        this.minSize = minimumSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2661
        minSizeSet = (minimumSize != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2662
        firePropertyChange("minimumSize", old, minimumSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2663
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2664
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2665
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2666
     * Returns whether or not <code>setMinimumSize</code> has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2667
     * invoked with a non-null value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2668
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2669
     * @return true if <code>setMinimumSize</code> has been invoked with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2670
     *              non-null value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2671
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2672
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2673
    public boolean isMinimumSizeSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2674
        return minSizeSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2675
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2676
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2677
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2678
     * Gets the mininimum size of this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2679
     * @return a dimension object indicating this component's minimum size
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2680
     * @see #getPreferredSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2681
     * @see LayoutManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2682
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2683
    public Dimension getMinimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2684
        return minimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2685
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2686
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2687
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2688
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2689
     * replaced by <code>getMinimumSize()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2690
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2691
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2692
    public Dimension minimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2693
        /* Avoid grabbing the lock if a reasonable cached size value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2694
         * is available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2695
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2696
        Dimension dim = minSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2697
        if (dim == null || !(isMinimumSizeSet() || isValid())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2698
            synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2699
                minSize = (peer != null) ?
1964
934568dfe859 6749920: Cleanup AWT peer interfaces
rkennke
parents: 1188
diff changeset
  2700
                    peer.getMinimumSize() :
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2701
                    size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2702
                dim = minSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2703
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2704
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2705
        return new Dimension(dim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2706
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2707
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2708
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2709
     * Sets the maximum size of this component to a constant
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2710
     * value.  Subsequent calls to <code>getMaximumSize</code> will always
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2711
     * return this value.  Setting the maximum size to <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2712
     * restores the default behavior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2713
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2714
     * @param maximumSize a <code>Dimension</code> containing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2715
     *          desired maximum allowable size
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2716
     * @see #getMaximumSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2717
     * @see #isMaximumSizeSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2718
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2719
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2720
    public void setMaximumSize(Dimension maximumSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2721
        // If the maximum size was set, use it as the old value, otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2722
        // use null to indicate we didn't previously have a set maximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2723
        // size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2724
        Dimension old;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2725
        if (maxSizeSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2726
            old = this.maxSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2727
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2728
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2729
            old = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2730
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2731
        this.maxSize = maximumSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2732
        maxSizeSet = (maximumSize != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2733
        firePropertyChange("maximumSize", old, maximumSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2734
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2735
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2736
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2737
     * Returns true if the maximum size has been set to a non-<code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2738
     * value otherwise returns false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2739
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2740
     * @return true if <code>maximumSize</code> is non-<code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2741
     *          false otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2742
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2743
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2744
    public boolean isMaximumSizeSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2745
        return maxSizeSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2746
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2747
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2748
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2749
     * Gets the maximum size of this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2750
     * @return a dimension object indicating this component's maximum size
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2751
     * @see #getMinimumSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2752
     * @see #getPreferredSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2753
     * @see LayoutManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2754
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2755
    public Dimension getMaximumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2756
        if (isMaximumSizeSet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2757
            return new Dimension(maxSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2758
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2759
        return new Dimension(Short.MAX_VALUE, Short.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2760
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2761
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2762
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2763
     * Returns the alignment along the x axis.  This specifies how
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2764
     * the component would like to be aligned relative to other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2765
     * components.  The value should be a number between 0 and 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2766
     * where 0 represents alignment along the origin, 1 is aligned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2767
     * the furthest away from the origin, 0.5 is centered, etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2768
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2769
    public float getAlignmentX() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2770
        return CENTER_ALIGNMENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2771
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2772
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2773
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2774
     * Returns the alignment along the y axis.  This specifies how
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2775
     * the component would like to be aligned relative to other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2776
     * components.  The value should be a number between 0 and 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2777
     * where 0 represents alignment along the origin, 1 is aligned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2778
     * the furthest away from the origin, 0.5 is centered, etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2779
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2780
    public float getAlignmentY() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2781
        return CENTER_ALIGNMENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2782
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2783
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2784
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2785
     * Returns the baseline.  The baseline is measured from the top of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2786
     * the component.  This method is primarily meant for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2787
     * <code>LayoutManager</code>s to align components along their
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2788
     * baseline.  A return value less than 0 indicates this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2789
     * does not have a reasonable baseline and that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2790
     * <code>LayoutManager</code>s should not align this component on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2791
     * its baseline.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2792
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2793
     * The default implementation returns -1.  Subclasses that support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2794
     * baseline should override appropriately.  If a value &gt;= 0 is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2795
     * returned, then the component has a valid baseline for any
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2796
     * size &gt;= the minimum size and <code>getBaselineResizeBehavior</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2797
     * can be used to determine how the baseline changes with size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2798
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2799
     * @param width the width to get the baseline for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2800
     * @param height the height to get the baseline for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2801
     * @return the baseline or &lt; 0 indicating there is no reasonable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2802
     *         baseline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2803
     * @throws IllegalArgumentException if width or height is &lt; 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2804
     * @see #getBaselineResizeBehavior
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2805
     * @see java.awt.FontMetrics
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2806
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2807
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2808
    public int getBaseline(int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2809
        if (width < 0 || height < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2810
            throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2811
                    "Width and height must be >= 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2812
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2813
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2814
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2815
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2816
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2817
     * Returns an enum indicating how the baseline of the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2818
     * changes as the size changes.  This method is primarily meant for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2819
     * layout managers and GUI builders.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2820
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2821
     * The default implementation returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2822
     * <code>BaselineResizeBehavior.OTHER</code>.  Subclasses that have a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2823
     * baseline should override appropriately.  Subclasses should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2824
     * never return <code>null</code>; if the baseline can not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2825
     * calculated return <code>BaselineResizeBehavior.OTHER</code>.  Callers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2826
     * should first ask for the baseline using
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2827
     * <code>getBaseline</code> and if a value &gt;= 0 is returned use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2828
     * this method.  It is acceptable for this method to return a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2829
     * value other than <code>BaselineResizeBehavior.OTHER</code> even if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2830
     * <code>getBaseline</code> returns a value less than 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2831
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2832
     * @return an enum indicating how the baseline changes as the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2833
     *         size changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2834
     * @see #getBaseline(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2835
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2836
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2837
    public BaselineResizeBehavior getBaselineResizeBehavior() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2838
        return BaselineResizeBehavior.OTHER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2839
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2840
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2841
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2842
     * Prompts the layout manager to lay out this component. This is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2843
     * usually called when the component (more specifically, container)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2844
     * is validated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2845
     * @see #validate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2846
     * @see LayoutManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2847
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2848
    public void doLayout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2849
        layout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2850
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2851
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2852
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2853
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2854
     * replaced by <code>doLayout()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2855
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2856
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2857
    public void layout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2858
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2859
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2860
    /**
4261
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  2861
     * Validates this component.
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  2862
     * <p>
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  2863
     * The meaning of the term <i>validating</i> is defined by the ancestors of
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  2864
     * this class. See {@link Container#validate} for more details.
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  2865
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2866
     * @see       #invalidate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2867
     * @see       #doLayout()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2868
     * @see       LayoutManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2869
     * @see       Container#validate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2870
     * @since     JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2871
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2872
    public void validate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2873
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2874
            ComponentPeer peer = this.peer;
1183
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
  2875
            boolean wasValid = isValid();
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
  2876
            if (!wasValid && peer != null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2877
                Font newfont = getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2878
                Font oldfont = peerFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2879
                if (newfont != oldfont && (oldfont == null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2880
                                           || !oldfont.equals(newfont))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2881
                    peer.setFont(newfont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2882
                    peerFont = newfont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2883
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2884
                peer.layout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2885
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2886
            valid = true;
1183
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
  2887
            if (!wasValid) {
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
  2888
                mixOnValidating();
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
  2889
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2890
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2891
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2892
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2893
    /**
4261
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  2894
     * Invalidates this component and its ancestors.
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  2895
     * <p>
9658
5484189eeabb 7041387: Introduce new boolean system property java.awt.smartInvalidate
anthony
parents: 9471
diff changeset
  2896
     * By default, all the ancestors of the component up to the top-most
5484189eeabb 7041387: Introduce new boolean system property java.awt.smartInvalidate
anthony
parents: 9471
diff changeset
  2897
     * container of the hierarchy are marked invalid. If the {@code
5484189eeabb 7041387: Introduce new boolean system property java.awt.smartInvalidate
anthony
parents: 9471
diff changeset
  2898
     * java.awt.smartInvalidate} system property is set to {@code true},
5484189eeabb 7041387: Introduce new boolean system property java.awt.smartInvalidate
anthony
parents: 9471
diff changeset
  2899
     * invalidation stops on the nearest validate root of this component.
5484189eeabb 7041387: Introduce new boolean system property java.awt.smartInvalidate
anthony
parents: 9471
diff changeset
  2900
     * Marking a container <i>invalid</i> indicates that the container needs to
5484189eeabb 7041387: Introduce new boolean system property java.awt.smartInvalidate
anthony
parents: 9471
diff changeset
  2901
     * be laid out.
4261
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  2902
     * <p>
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  2903
     * This method is called automatically when any layout-related information
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  2904
     * changes (e.g. setting the bounds of the component, or adding the
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  2905
     * component to a container).
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  2906
     * <p>
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  2907
     * This method might be called often, so it should work fast.
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  2908
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2909
     * @see       #validate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2910
     * @see       #doLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2911
     * @see       LayoutManager
4261
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  2912
     * @see       java.awt.Container#isValidateRoot
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2913
     * @since     JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2914
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2915
    public void invalidate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2916
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2917
            /* Nullify cached layout and size information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2918
             * For efficiency, propagate invalidate() upwards only if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2919
             * some other component hasn't already done so first.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2920
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2921
            valid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2922
            if (!isPreferredSizeSet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2923
                prefSize = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2924
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2925
            if (!isMinimumSizeSet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2926
                minSize = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2927
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2928
            if (!isMaximumSizeSet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2929
                maxSize = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2930
            }
4261
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  2931
            invalidateParent();
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  2932
        }
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  2933
    }
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  2934
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  2935
    /**
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  2936
     * Invalidates the parent of this component if any.
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  2937
     *
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  2938
     * This method MUST BE invoked under the TreeLock.
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  2939
     */
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  2940
    void invalidateParent() {
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  2941
        if (parent != null) {
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  2942
            parent.invalidateIfValid();
1183
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
  2943
        }
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
  2944
    }
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
  2945
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
  2946
    /** Invalidates the component unless it is already invalid.
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
  2947
     */
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
  2948
    final void invalidateIfValid() {
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
  2949
        if (isValid()) {
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
  2950
            invalidate();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2951
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2952
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2953
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2954
    /**
9471
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  2955
     * Revalidates the component hierarchy up to the nearest validate root.
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  2956
     * <p>
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  2957
     * This method first invalidates the component hierarchy starting from this
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  2958
     * component up to the nearest validate root. Afterwards, the component
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  2959
     * hierarchy is validated starting from the nearest validate root.
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  2960
     * <p>
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  2961
     * This is a convenience method supposed to help application developers
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  2962
     * avoid looking for validate roots manually. Basically, it's equivalent to
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  2963
     * first calling the {@link #invalidate()} method on this component, and
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  2964
     * then calling the {@link #validate()} method on the nearest validate
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  2965
     * root.
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  2966
     *
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  2967
     * @see Container#isValidateRoot
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  2968
     * @since 1.7
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  2969
     */
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  2970
    public void revalidate() {
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  2971
        synchronized (getTreeLock()) {
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  2972
            invalidate();
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  2973
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  2974
            Container root = getContainer();
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  2975
            if (root == null) {
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  2976
                // There's no parents. Just validate itself.
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  2977
                validate();
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  2978
            } else {
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  2979
                while (!root.isValidateRoot()) {
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  2980
                    if (root.getContainer() == null) {
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  2981
                        // If there's no validate roots, we'll validate the
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  2982
                        // topmost container
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  2983
                        break;
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  2984
                    }
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  2985
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  2986
                    root = root.getContainer();
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  2987
                }
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  2988
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  2989
                root.validate();
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  2990
            }
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  2991
        }
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  2992
    }
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  2993
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  2994
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2995
     * Creates a graphics context for this component. This method will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2996
     * return <code>null</code> if this component is currently not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2997
     * displayable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2998
     * @return a graphics context for this component, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2999
     *             if it has none
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3000
     * @see       #paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3001
     * @since     JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3002
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3003
    public Graphics getGraphics() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3004
        if (peer instanceof LightweightPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3005
            // This is for a lightweight component, need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3006
            // translate coordinate spaces and clip relative
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3007
            // to the parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3008
            if (parent == null) return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3009
            Graphics g = parent.getGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3010
            if (g == null) return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3011
            if (g instanceof ConstrainableGraphics) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3012
                ((ConstrainableGraphics) g).constrain(x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3013
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3014
                g.translate(x,y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3015
                g.setClip(0, 0, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3016
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3017
            g.setFont(getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3018
            return g;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3019
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3020
            ComponentPeer peer = this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3021
            return (peer != null) ? peer.getGraphics() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3022
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3023
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3024
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3025
    final Graphics getGraphics_NoClientCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3026
        ComponentPeer peer = this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3027
        if (peer instanceof LightweightPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3028
            // This is for a lightweight component, need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3029
            // translate coordinate spaces and clip relative
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3030
            // to the parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3031
            Container parent = this.parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3032
            if (parent == null) return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3033
            Graphics g = parent.getGraphics_NoClientCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3034
            if (g == null) return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3035
            if (g instanceof ConstrainableGraphics) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3036
                ((ConstrainableGraphics) g).constrain(x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3037
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3038
                g.translate(x,y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3039
                g.setClip(0, 0, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3040
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3041
            g.setFont(getFont_NoClientCode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3042
            return g;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3043
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3044
            return (peer != null) ? peer.getGraphics() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3045
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3046
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3047
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3048
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3049
     * Gets the font metrics for the specified font.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3050
     * Warning: Since Font metrics are affected by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3051
     * {@link java.awt.font.FontRenderContext FontRenderContext} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3052
     * this method does not provide one, it can return only metrics for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3053
     * the default render context which may not match that used when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3054
     * rendering on the Component if {@link Graphics2D} functionality is being
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3055
     * used. Instead metrics can be obtained at rendering time by calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3056
     * {@link Graphics#getFontMetrics()} or text measurement APIs on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3057
     * {@link Font Font} class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3058
     * @param font the font for which font metrics is to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3059
     *          obtained
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3060
     * @return the font metrics for <code>font</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3061
     * @see       #getFont
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3062
     * @see       #getPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3063
     * @see       java.awt.peer.ComponentPeer#getFontMetrics(Font)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3064
     * @see       Toolkit#getFontMetrics(Font)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3065
     * @since     JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3066
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3067
    public FontMetrics getFontMetrics(Font font) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3237
diff changeset
  3068
        // This is an unsupported hack, but left in for a customer.
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3237
diff changeset
  3069
        // Do not remove.
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3237
diff changeset
  3070
        FontManager fm = FontManagerFactory.getInstance();
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3237
diff changeset
  3071
        if (fm instanceof SunFontManager
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3237
diff changeset
  3072
            && ((SunFontManager) fm).usePlatformFontMetrics()) {
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3237
diff changeset
  3073
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3074
            if (peer != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3075
                !(peer instanceof LightweightPeer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3076
                return peer.getFontMetrics(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3077
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3078
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3079
        return sun.font.FontDesignMetrics.getMetrics(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3080
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3081
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3082
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3083
     * Sets the cursor image to the specified cursor.  This cursor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3084
     * image is displayed when the <code>contains</code> method for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3085
     * this component returns true for the current cursor location, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3086
     * this Component is visible, displayable, and enabled. Setting the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3087
     * cursor of a <code>Container</code> causes that cursor to be displayed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3088
     * within all of the container's subcomponents, except for those
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3089
     * that have a non-<code>null</code> cursor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3090
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3091
     * The method may have no visual effect if the Java platform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3092
     * implementation and/or the native system do not support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3093
     * changing the mouse cursor shape.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3094
     * @param cursor One of the constants defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3095
     *          by the <code>Cursor</code> class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3096
     *          if this parameter is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3097
     *          then this component will inherit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3098
     *          the cursor of its parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3099
     * @see       #isEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3100
     * @see       #isShowing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3101
     * @see       #getCursor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3102
     * @see       #contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3103
     * @see       Toolkit#createCustomCursor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3104
     * @see       Cursor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3105
     * @since     JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3107
    public void setCursor(Cursor cursor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3108
        this.cursor = cursor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3109
        updateCursorImmediately();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3111
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3112
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3113
     * Updates the cursor.  May not be invoked from the native
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3114
     * message pump.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3115
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3116
    final void updateCursorImmediately() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3117
        if (peer instanceof LightweightPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3118
            Container nativeContainer = getNativeContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3119
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3120
            if (nativeContainer == null) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3121
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3122
            ComponentPeer cPeer = nativeContainer.getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3123
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3124
            if (cPeer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3125
                cPeer.updateCursorImmediately();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3126
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3127
        } else if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3128
            peer.updateCursorImmediately();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3129
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3131
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3132
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3133
     * Gets the cursor set in the component. If the component does
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3134
     * not have a cursor set, the cursor of its parent is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3135
     * If no cursor is set in the entire hierarchy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3136
     * <code>Cursor.DEFAULT_CURSOR</code> is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3137
     * @see #setCursor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3138
     * @since      JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3139
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3140
    public Cursor getCursor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3141
        return getCursor_NoClientCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3143
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3144
    final Cursor getCursor_NoClientCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3145
        Cursor cursor = this.cursor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3146
        if (cursor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3147
            return cursor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3148
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3149
        Container parent = this.parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3150
        if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3151
            return parent.getCursor_NoClientCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3152
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3153
            return Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3156
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3157
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3158
     * Returns whether the cursor has been explicitly set for this Component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3159
     * If this method returns <code>false</code>, this Component is inheriting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3160
     * its cursor from an ancestor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3161
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3162
     * @return <code>true</code> if the cursor has been explicitly set for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3163
     *         Component; <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3164
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3165
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3166
    public boolean isCursorSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3167
        return (cursor != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3169
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3170
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3171
     * Paints this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3172
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3173
     * This method is called when the contents of the component should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3174
     * be painted; such as when the component is first being shown or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3175
     * is damaged and in need of repair.  The clip rectangle in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3176
     * <code>Graphics</code> parameter is set to the area
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3177
     * which needs to be painted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3178
     * Subclasses of <code>Component</code> that override this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3179
     * method need not call <code>super.paint(g)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3180
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3181
     * For performance reasons, <code>Component</code>s with zero width
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3182
     * or height aren't considered to need painting when they are first shown,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3183
     * and also aren't considered to need repair.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3184
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3185
     * <b>Note</b>: For more information on the paint mechanisms utilitized
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3186
     * by AWT and Swing, including information on how to write the most
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3187
     * efficient painting code, see
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3188
     * <a href="http://java.sun.com/products/jfc/tsc/articles/painting/index.html">Painting in AWT and Swing</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3189
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3190
     * @param g the graphics context to use for painting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3191
     * @see       #update
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3192
     * @since     JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3193
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3194
    public void paint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3196
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3197
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3198
     * Updates this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3199
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3200
     * If this component is not a lightweight component, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3201
     * AWT calls the <code>update</code> method in response to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3202
     * a call to <code>repaint</code>.  You can assume that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3203
     * the background is not cleared.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3204
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3205
     * The <code>update</code> method of <code>Component</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3206
     * calls this component's <code>paint</code> method to redraw
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3207
     * this component.  This method is commonly overridden by subclasses
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3208
     * which need to do additional work in response to a call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3209
     * <code>repaint</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3210
     * Subclasses of Component that override this method should either
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3211
     * call <code>super.update(g)</code>, or call <code>paint(g)</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3212
     * directly from their <code>update</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3213
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3214
     * The origin of the graphics context, its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3215
     * (<code>0</code>,&nbsp;<code>0</code>) coordinate point, is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3216
     * top-left corner of this component. The clipping region of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3217
     * graphics context is the bounding rectangle of this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3218
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3219
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3220
     * <b>Note</b>: For more information on the paint mechanisms utilitized
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3221
     * by AWT and Swing, including information on how to write the most
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3222
     * efficient painting code, see
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3223
     * <a href="http://java.sun.com/products/jfc/tsc/articles/painting/index.html">Painting in AWT and Swing</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3224
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3225
     * @param g the specified context to use for updating
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3226
     * @see       #paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3227
     * @see       #repaint()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3228
     * @since     JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3229
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3230
    public void update(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3231
        paint(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3233
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3234
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3235
     * Paints this component and all of its subcomponents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3236
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3237
     * The origin of the graphics context, its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3238
     * (<code>0</code>,&nbsp;<code>0</code>) coordinate point, is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3239
     * top-left corner of this component. The clipping region of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3240
     * graphics context is the bounding rectangle of this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3241
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3242
     * @param     g   the graphics context to use for painting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3243
     * @see       #paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3244
     * @since     JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3245
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3246
    public void paintAll(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3247
        if (isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3248
            GraphicsCallback.PeerPaintCallback.getInstance().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3249
                runOneComponent(this, new Rectangle(0, 0, width, height),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3250
                                g, g.getClip(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3251
                                GraphicsCallback.LIGHTWEIGHTS |
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3252
                                GraphicsCallback.HEAVYWEIGHTS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3253
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3255
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3256
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3257
     * Simulates the peer callbacks into java.awt for painting of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3258
     * lightweight Components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3259
     * @param     g   the graphics context to use for painting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3260
     * @see       #paintAll
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3261
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3262
    void lightweightPaint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3263
        paint(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3265
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3266
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3267
     * Paints all the heavyweight subcomponents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3268
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3269
    void paintHeavyweightComponents(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3271
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3272
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3273
     * Repaints this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3274
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3275
     * If this component is a lightweight component, this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3276
     * causes a call to this component's <code>paint</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3277
     * method as soon as possible.  Otherwise, this method causes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3278
     * a call to this component's <code>update</code> method as soon
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3279
     * as possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3280
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3281
     * <b>Note</b>: For more information on the paint mechanisms utilitized
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3282
     * by AWT and Swing, including information on how to write the most
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3283
     * efficient painting code, see
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3284
     * <a href="http://java.sun.com/products/jfc/tsc/articles/painting/index.html">Painting in AWT and Swing</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3285
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3286
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3287
     * @see       #update(Graphics)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3288
     * @since     JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3289
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3290
    public void repaint() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3291
        repaint(0, 0, 0, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3292
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3293
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3294
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3295
     * Repaints the component.  If this component is a lightweight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3296
     * component, this results in a call to <code>paint</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3297
     * within <code>tm</code> milliseconds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3298
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3299
     * <b>Note</b>: For more information on the paint mechanisms utilitized
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3300
     * by AWT and Swing, including information on how to write the most
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3301
     * efficient painting code, see
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3302
     * <a href="http://java.sun.com/products/jfc/tsc/articles/painting/index.html">Painting in AWT and Swing</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3303
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3304
     * @param tm maximum time in milliseconds before update
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3305
     * @see #paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3306
     * @see #update(Graphics)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3307
     * @since JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3308
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3309
    public void repaint(long tm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3310
        repaint(tm, 0, 0, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3311
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3312
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3313
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3314
     * Repaints the specified rectangle of this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3315
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3316
     * If this component is a lightweight component, this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3317
     * causes a call to this component's <code>paint</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3318
     * as soon as possible.  Otherwise, this method causes a call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3319
     * this component's <code>update</code> method as soon as possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3320
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3321
     * <b>Note</b>: For more information on the paint mechanisms utilitized
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3322
     * by AWT and Swing, including information on how to write the most
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3323
     * efficient painting code, see
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3324
     * <a href="http://java.sun.com/products/jfc/tsc/articles/painting/index.html">Painting in AWT and Swing</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3325
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3326
     * @param     x   the <i>x</i> coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3327
     * @param     y   the <i>y</i> coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3328
     * @param     width   the width
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3329
     * @param     height  the height
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3330
     * @see       #update(Graphics)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3331
     * @since     JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3332
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3333
    public void repaint(int x, int y, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3334
        repaint(0, x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3335
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3336
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3337
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3338
     * Repaints the specified rectangle of this component within
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3339
     * <code>tm</code> milliseconds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3340
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3341
     * If this component is a lightweight component, this method causes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3342
     * a call to this component's <code>paint</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3343
     * Otherwise, this method causes a call to this component's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3344
     * <code>update</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3345
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3346
     * <b>Note</b>: For more information on the paint mechanisms utilitized
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3347
     * by AWT and Swing, including information on how to write the most
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3348
     * efficient painting code, see
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3349
     * <a href="http://java.sun.com/products/jfc/tsc/articles/painting/index.html">Painting in AWT and Swing</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3350
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3351
     * @param     tm   maximum time in milliseconds before update
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3352
     * @param     x    the <i>x</i> coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3353
     * @param     y    the <i>y</i> coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3354
     * @param     width    the width
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3355
     * @param     height   the height
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3356
     * @see       #update(Graphics)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3357
     * @since     JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3358
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3359
    public void repaint(long tm, int x, int y, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3360
        if (this.peer instanceof LightweightPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3361
            // Needs to be translated to parent coordinates since
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3362
            // a parent native container provides the actual repaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3363
            // services.  Additionally, the request is restricted to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3364
            // the bounds of the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3365
            if (parent != null) {
634
34d4a2d5b8cb 6644301: lightweight components can repaint outside request bounds
son
parents: 441
diff changeset
  3366
                if (x < 0) {
34d4a2d5b8cb 6644301: lightweight components can repaint outside request bounds
son
parents: 441
diff changeset
  3367
                    width += x;
34d4a2d5b8cb 6644301: lightweight components can repaint outside request bounds
son
parents: 441
diff changeset
  3368
                    x = 0;
34d4a2d5b8cb 6644301: lightweight components can repaint outside request bounds
son
parents: 441
diff changeset
  3369
                }
34d4a2d5b8cb 6644301: lightweight components can repaint outside request bounds
son
parents: 441
diff changeset
  3370
                if (y < 0) {
34d4a2d5b8cb 6644301: lightweight components can repaint outside request bounds
son
parents: 441
diff changeset
  3371
                    height += y;
34d4a2d5b8cb 6644301: lightweight components can repaint outside request bounds
son
parents: 441
diff changeset
  3372
                    y = 0;
34d4a2d5b8cb 6644301: lightweight components can repaint outside request bounds
son
parents: 441
diff changeset
  3373
                }
34d4a2d5b8cb 6644301: lightweight components can repaint outside request bounds
son
parents: 441
diff changeset
  3374
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3375
                int pwidth = (width > this.width) ? this.width : width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3376
                int pheight = (height > this.height) ? this.height : height;
634
34d4a2d5b8cb 6644301: lightweight components can repaint outside request bounds
son
parents: 441
diff changeset
  3377
34d4a2d5b8cb 6644301: lightweight components can repaint outside request bounds
son
parents: 441
diff changeset
  3378
                if (pwidth <= 0 || pheight <= 0) {
34d4a2d5b8cb 6644301: lightweight components can repaint outside request bounds
son
parents: 441
diff changeset
  3379
                    return;
34d4a2d5b8cb 6644301: lightweight components can repaint outside request bounds
son
parents: 441
diff changeset
  3380
                }
34d4a2d5b8cb 6644301: lightweight components can repaint outside request bounds
son
parents: 441
diff changeset
  3381
34d4a2d5b8cb 6644301: lightweight components can repaint outside request bounds
son
parents: 441
diff changeset
  3382
                int px = this.x + x;
34d4a2d5b8cb 6644301: lightweight components can repaint outside request bounds
son
parents: 441
diff changeset
  3383
                int py = this.y + y;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3384
                parent.repaint(tm, px, py, pwidth, pheight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3385
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3386
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3387
            if (isVisible() && (this.peer != null) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3388
                (width > 0) && (height > 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3389
                PaintEvent e = new PaintEvent(this, PaintEvent.UPDATE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3390
                                              new Rectangle(x, y, width, height));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3391
                Toolkit.getEventQueue().postEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3392
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3393
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3394
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3395
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3396
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3397
     * Prints this component. Applications should override this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3398
     * for components that must do special processing before being
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3399
     * printed or should be printed differently than they are painted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3400
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3401
     * The default implementation of this method calls the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3402
     * <code>paint</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3403
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3404
     * The origin of the graphics context, its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3405
     * (<code>0</code>,&nbsp;<code>0</code>) coordinate point, is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3406
     * top-left corner of this component. The clipping region of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3407
     * graphics context is the bounding rectangle of this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3408
     * @param     g   the graphics context to use for printing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3409
     * @see       #paint(Graphics)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3410
     * @since     JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3411
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3412
    public void print(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3413
        paint(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3414
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3415
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3416
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3417
     * Prints this component and all of its subcomponents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3418
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3419
     * The origin of the graphics context, its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3420
     * (<code>0</code>,&nbsp;<code>0</code>) coordinate point, is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3421
     * top-left corner of this component. The clipping region of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3422
     * graphics context is the bounding rectangle of this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3423
     * @param     g   the graphics context to use for printing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3424
     * @see       #print(Graphics)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3425
     * @since     JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3426
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3427
    public void printAll(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3428
        if (isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3429
            GraphicsCallback.PeerPrintCallback.getInstance().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3430
                runOneComponent(this, new Rectangle(0, 0, width, height),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3431
                                g, g.getClip(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3432
                                GraphicsCallback.LIGHTWEIGHTS |
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3433
                                GraphicsCallback.HEAVYWEIGHTS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3434
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3435
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3436
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3437
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3438
     * Simulates the peer callbacks into java.awt for printing of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3439
     * lightweight Components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3440
     * @param     g   the graphics context to use for printing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3441
     * @see       #printAll
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3442
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3443
    void lightweightPrint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3444
        print(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3445
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3446
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3447
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3448
     * Prints all the heavyweight subcomponents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3449
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3450
    void printHeavyweightComponents(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3451
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3452
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3453
    private Insets getInsets_NoClientCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3454
        ComponentPeer peer = this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3455
        if (peer instanceof ContainerPeer) {
1964
934568dfe859 6749920: Cleanup AWT peer interfaces
rkennke
parents: 1188
diff changeset
  3456
            return (Insets)((ContainerPeer)peer).getInsets().clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3457
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3458
        return new Insets(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3459
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3460
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3461
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3462
     * Repaints the component when the image has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3463
     * This <code>imageUpdate</code> method of an <code>ImageObserver</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3464
     * is called when more information about an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3465
     * image which had been previously requested using an asynchronous
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3466
     * routine such as the <code>drawImage</code> method of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3467
     * <code>Graphics</code> becomes available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3468
     * See the definition of <code>imageUpdate</code> for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3469
     * more information on this method and its arguments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3470
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3471
     * The <code>imageUpdate</code> method of <code>Component</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3472
     * incrementally draws an image on the component as more of the bits
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3473
     * of the image are available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3474
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3475
     * If the system property <code>awt.image.incrementaldraw</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3476
     * is missing or has the value <code>true</code>, the image is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3477
     * incrementally drawn. If the system property has any other value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3478
     * then the image is not drawn until it has been completely loaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3479
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3480
     * Also, if incremental drawing is in effect, the value of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3481
     * system property <code>awt.image.redrawrate</code> is interpreted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3482
     * as an integer to give the maximum redraw rate, in milliseconds. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3483
     * the system property is missing or cannot be interpreted as an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3484
     * integer, the redraw rate is once every 100ms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3485
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3486
     * The interpretation of the <code>x</code>, <code>y</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3487
     * <code>width</code>, and <code>height</code> arguments depends on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3488
     * the value of the <code>infoflags</code> argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3489
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3490
     * @param     img   the image being observed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3491
     * @param     infoflags   see <code>imageUpdate</code> for more information
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3492
     * @param     x   the <i>x</i> coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3493
     * @param     y   the <i>y</i> coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3494
     * @param     w   the width
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3495
     * @param     h   the height
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3496
     * @return    <code>false</code> if the infoflags indicate that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3497
     *            image is completely loaded; <code>true</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3498
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3499
     * @see     java.awt.image.ImageObserver
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3500
     * @see     Graphics#drawImage(Image, int, int, Color, java.awt.image.ImageObserver)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3501
     * @see     Graphics#drawImage(Image, int, int, java.awt.image.ImageObserver)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3502
     * @see     Graphics#drawImage(Image, int, int, int, int, Color, java.awt.image.ImageObserver)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3503
     * @see     Graphics#drawImage(Image, int, int, int, int, java.awt.image.ImageObserver)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3504
     * @see     java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3505
     * @since   JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3506
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3507
    public boolean imageUpdate(Image img, int infoflags,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3508
                               int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3509
        int rate = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3510
        if ((infoflags & (FRAMEBITS|ALLBITS)) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3511
            rate = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3512
        } else if ((infoflags & SOMEBITS) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3513
            if (isInc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3514
                rate = incRate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3515
                if (rate < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3516
                    rate = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3517
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3518
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3519
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3520
        if (rate >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3521
            repaint(rate, 0, 0, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3522
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3523
        return (infoflags & (ALLBITS|ABORT)) == 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3524
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3525
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3526
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3527
     * Creates an image from the specified image producer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3528
     * @param     producer  the image producer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3529
     * @return    the image produced
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3530
     * @since     JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3531
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3532
    public Image createImage(ImageProducer producer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3533
        ComponentPeer peer = this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3534
        if ((peer != null) && ! (peer instanceof LightweightPeer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3535
            return peer.createImage(producer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3536
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3537
        return getToolkit().createImage(producer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3538
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3539
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3540
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3541
     * Creates an off-screen drawable image
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3542
     *     to be used for double buffering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3543
     * @param     width the specified width
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3544
     * @param     height the specified height
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3545
     * @return    an off-screen drawable image, which can be used for double
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3546
     *    buffering.  The return value may be <code>null</code> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3547
     *    component is not displayable.  This will always happen if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3548
     *    <code>GraphicsEnvironment.isHeadless()</code> returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3549
     *    <code>true</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3550
     * @see #isDisplayable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3551
     * @see GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3552
     * @since     JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3553
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3554
    public Image createImage(int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3555
        ComponentPeer peer = this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3556
        if (peer instanceof LightweightPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3557
            if (parent != null) { return parent.createImage(width, height); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3558
            else { return null;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3559
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3560
            return (peer != null) ? peer.createImage(width, height) : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3561
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3562
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3563
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3564
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3565
     * Creates a volatile off-screen drawable image
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3566
     *     to be used for double buffering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3567
     * @param     width the specified width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3568
     * @param     height the specified height.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3569
     * @return    an off-screen drawable image, which can be used for double
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3570
     *    buffering.  The return value may be <code>null</code> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3571
     *    component is not displayable.  This will always happen if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3572
     *    <code>GraphicsEnvironment.isHeadless()</code> returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3573
     *    <code>true</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3574
     * @see java.awt.image.VolatileImage
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3575
     * @see #isDisplayable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3576
     * @see GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3577
     * @since     1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3578
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3579
    public VolatileImage createVolatileImage(int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3580
        ComponentPeer peer = this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3581
        if (peer instanceof LightweightPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3582
            if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3583
                return parent.createVolatileImage(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3584
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3585
            else { return null;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3586
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3587
            return (peer != null) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3588
                peer.createVolatileImage(width, height) : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3589
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3590
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3591
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3592
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3593
     * Creates a volatile off-screen drawable image, with the given capabilities.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3594
     * The contents of this image may be lost at any time due
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3595
     * to operating system issues, so the image must be managed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3596
     * via the <code>VolatileImage</code> interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3597
     * @param width the specified width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3598
     * @param height the specified height.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3599
     * @param caps the image capabilities
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3600
     * @exception AWTException if an image with the specified capabilities cannot
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3601
     * be created
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3602
     * @return a VolatileImage object, which can be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3603
     * to manage surface contents loss and capabilities.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3604
     * @see java.awt.image.VolatileImage
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3605
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3606
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3607
    public VolatileImage createVolatileImage(int width, int height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3608
                                             ImageCapabilities caps) throws AWTException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3609
        // REMIND : check caps
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3610
        return createVolatileImage(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3611
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3612
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3613
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3614
     * Prepares an image for rendering on this component.  The image
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3615
     * data is downloaded asynchronously in another thread and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3616
     * appropriate screen representation of the image is generated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3617
     * @param     image   the <code>Image</code> for which to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3618
     *                    prepare a screen representation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3619
     * @param     observer   the <code>ImageObserver</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3620
     *                       to be notified as the image is being prepared
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3621
     * @return    <code>true</code> if the image has already been fully
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3622
     *           prepared; <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3623
     * @since     JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3624
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3625
    public boolean prepareImage(Image image, ImageObserver observer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3626
        return prepareImage(image, -1, -1, observer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3627
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3628
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3629
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3630
     * Prepares an image for rendering on this component at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3631
     * specified width and height.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3632
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3633
     * The image data is downloaded asynchronously in another thread,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3634
     * and an appropriately scaled screen representation of the image is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3635
     * generated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3636
     * @param     image    the instance of <code>Image</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3637
     *            for which to prepare a screen representation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3638
     * @param     width    the width of the desired screen representation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3639
     * @param     height   the height of the desired screen representation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3640
     * @param     observer   the <code>ImageObserver</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3641
     *            to be notified as the image is being prepared
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3642
     * @return    <code>true</code> if the image has already been fully
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3643
     *          prepared; <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3644
     * @see       java.awt.image.ImageObserver
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3645
     * @since     JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3646
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3647
    public boolean prepareImage(Image image, int width, int height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3648
                                ImageObserver observer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3649
        ComponentPeer peer = this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3650
        if (peer instanceof LightweightPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3651
            return (parent != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3652
                ? parent.prepareImage(image, width, height, observer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3653
                : getToolkit().prepareImage(image, width, height, observer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3654
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3655
            return (peer != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3656
                ? peer.prepareImage(image, width, height, observer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3657
                : getToolkit().prepareImage(image, width, height, observer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3658
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3659
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3660
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3661
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3662
     * Returns the status of the construction of a screen representation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3663
     * of the specified image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3664
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3665
     * This method does not cause the image to begin loading. An
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3666
     * application must use the <code>prepareImage</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3667
     * to force the loading of an image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3668
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3669
     * Information on the flags returned by this method can be found
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3670
     * with the discussion of the <code>ImageObserver</code> interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3671
     * @param     image   the <code>Image</code> object whose status
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3672
     *            is being checked
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3673
     * @param     observer   the <code>ImageObserver</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3674
     *            object to be notified as the image is being prepared
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3675
     * @return  the bitwise inclusive <b>OR</b> of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3676
     *            <code>ImageObserver</code> flags indicating what
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3677
     *            information about the image is currently available
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3678
     * @see      #prepareImage(Image, int, int, java.awt.image.ImageObserver)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3679
     * @see      Toolkit#checkImage(Image, int, int, java.awt.image.ImageObserver)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3680
     * @see      java.awt.image.ImageObserver
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3681
     * @since    JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3682
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3683
    public int checkImage(Image image, ImageObserver observer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3684
        return checkImage(image, -1, -1, observer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3685
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3686
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3687
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3688
     * Returns the status of the construction of a screen representation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3689
     * of the specified image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3690
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3691
     * This method does not cause the image to begin loading. An
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3692
     * application must use the <code>prepareImage</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3693
     * to force the loading of an image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3694
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3695
     * The <code>checkImage</code> method of <code>Component</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3696
     * calls its peer's <code>checkImage</code> method to calculate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3697
     * the flags. If this component does not yet have a peer, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3698
     * component's toolkit's <code>checkImage</code> method is called
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3699
     * instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3700
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3701
     * Information on the flags returned by this method can be found
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3702
     * with the discussion of the <code>ImageObserver</code> interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3703
     * @param     image   the <code>Image</code> object whose status
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3704
     *                    is being checked
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3705
     * @param     width   the width of the scaled version
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3706
     *                    whose status is to be checked
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3707
     * @param     height  the height of the scaled version
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3708
     *                    whose status is to be checked
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3709
     * @param     observer   the <code>ImageObserver</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3710
     *                    to be notified as the image is being prepared
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3711
     * @return    the bitwise inclusive <b>OR</b> of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3712
     *            <code>ImageObserver</code> flags indicating what
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3713
     *            information about the image is currently available
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3714
     * @see      #prepareImage(Image, int, int, java.awt.image.ImageObserver)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3715
     * @see      Toolkit#checkImage(Image, int, int, java.awt.image.ImageObserver)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3716
     * @see      java.awt.image.ImageObserver
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3717
     * @since    JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3718
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3719
    public int checkImage(Image image, int width, int height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3720
                          ImageObserver observer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3721
        ComponentPeer peer = this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3722
        if (peer instanceof LightweightPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3723
            return (parent != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3724
                ? parent.checkImage(image, width, height, observer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3725
                : getToolkit().checkImage(image, width, height, observer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3726
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3727
            return (peer != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3728
                ? peer.checkImage(image, width, height, observer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3729
                : getToolkit().checkImage(image, width, height, observer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3730
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3731
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3732
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3733
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3734
     * Creates a new strategy for multi-buffering on this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3735
     * Multi-buffering is useful for rendering performance.  This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3736
     * attempts to create the best strategy available with the number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3737
     * buffers supplied.  It will always create a <code>BufferStrategy</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3738
     * with that number of buffers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3739
     * A page-flipping strategy is attempted first, then a blitting strategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3740
     * using accelerated buffers.  Finally, an unaccelerated blitting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3741
     * strategy is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3742
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3743
     * Each time this method is called,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3744
     * the existing buffer strategy for this component is discarded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3745
     * @param numBuffers number of buffers to create, including the front buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3746
     * @exception IllegalArgumentException if numBuffers is less than 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3747
     * @exception IllegalStateException if the component is not displayable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3748
     * @see #isDisplayable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3749
     * @see Window#getBufferStrategy()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3750
     * @see Canvas#getBufferStrategy()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3751
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3752
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3753
    void createBufferStrategy(int numBuffers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3754
        BufferCapabilities bufferCaps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3755
        if (numBuffers > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3756
            // Try to create a page-flipping strategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3757
            bufferCaps = new BufferCapabilities(new ImageCapabilities(true),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3758
                                                new ImageCapabilities(true),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3759
                                                BufferCapabilities.FlipContents.UNDEFINED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3760
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3761
                createBufferStrategy(numBuffers, bufferCaps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3762
                return; // Success
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3763
            } catch (AWTException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3764
                // Failed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3765
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3766
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3767
        // Try a blitting (but still accelerated) strategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3768
        bufferCaps = new BufferCapabilities(new ImageCapabilities(true),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3769
                                            new ImageCapabilities(true),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3770
                                            null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3771
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3772
            createBufferStrategy(numBuffers, bufferCaps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3773
            return; // Success
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3774
        } catch (AWTException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3775
            // Failed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3776
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3777
        // Try an unaccelerated blitting strategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3778
        bufferCaps = new BufferCapabilities(new ImageCapabilities(false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3779
                                            new ImageCapabilities(false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3780
                                            null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3781
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3782
            createBufferStrategy(numBuffers, bufferCaps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3783
            return; // Success
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3784
        } catch (AWTException e) {
10419
12c063b39232 7084245: Update usages of InternalError to use exception chaining
sherman
parents: 9658
diff changeset
  3785
            // Code should never reach here (an unaccelerated blitting
12c063b39232 7084245: Update usages of InternalError to use exception chaining
sherman
parents: 9658
diff changeset
  3786
            // strategy should always work)
12c063b39232 7084245: Update usages of InternalError to use exception chaining
sherman
parents: 9658
diff changeset
  3787
            throw new InternalError("Could not create a buffer strategy", e);
12c063b39232 7084245: Update usages of InternalError to use exception chaining
sherman
parents: 9658
diff changeset
  3788
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3789
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3790
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3791
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3792
     * Creates a new strategy for multi-buffering on this component with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3793
     * required buffer capabilities.  This is useful, for example, if only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3794
     * accelerated memory or page flipping is desired (as specified by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3795
     * buffer capabilities).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3796
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3797
     * Each time this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3798
     * is called, <code>dispose</code> will be invoked on the existing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3799
     * <code>BufferStrategy</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3800
     * @param numBuffers number of buffers to create
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3801
     * @param caps the required capabilities for creating the buffer strategy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3802
     * cannot be <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3803
     * @exception AWTException if the capabilities supplied could not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3804
     * supported or met; this may happen, for example, if there is not enough
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3805
     * accelerated memory currently available, or if page flipping is specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3806
     * but not possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3807
     * @exception IllegalArgumentException if numBuffers is less than 1, or if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3808
     * caps is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3809
     * @see Window#getBufferStrategy()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3810
     * @see Canvas#getBufferStrategy()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3811
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3812
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3813
    void createBufferStrategy(int numBuffers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3814
                              BufferCapabilities caps) throws AWTException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3815
        // Check arguments
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3816
        if (numBuffers < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3817
            throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3818
                "Number of buffers must be at least 1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3819
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3820
        if (caps == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3821
            throw new IllegalArgumentException("No capabilities specified");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3822
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3823
        // Destroy old buffers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3824
        if (bufferStrategy != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3825
            bufferStrategy.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3826
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3827
        if (numBuffers == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3828
            bufferStrategy = new SingleBufferStrategy(caps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3829
        } else {
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3830
            SunGraphicsEnvironment sge = (SunGraphicsEnvironment)
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3831
                GraphicsEnvironment.getLocalGraphicsEnvironment();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3832
            if (!caps.isPageFlipping() && sge.isFlipStrategyPreferred(peer)) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3833
                caps = new ProxyCapabilities(caps);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3834
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3835
            // assert numBuffers > 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3836
            if (caps.isPageFlipping()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3837
                bufferStrategy = new FlipSubRegionBufferStrategy(numBuffers, caps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3838
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3839
                bufferStrategy = new BltSubRegionBufferStrategy(numBuffers, caps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3840
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3841
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3842
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3843
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3844
    /**
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3845
     * This is a proxy capabilities class used when a FlipBufferStrategy
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3846
     * is created instead of the requested Blit strategy.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3847
     *
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3848
     * @see sun.awt.SunGraphicsEnvironment#isFlipStrategyPreferred(ComponentPeer)
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3849
     */
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3850
    private class ProxyCapabilities extends ExtendedBufferCapabilities {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3851
        private BufferCapabilities orig;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3852
        private ProxyCapabilities(BufferCapabilities orig) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3853
            super(orig.getFrontBufferCapabilities(),
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3854
                  orig.getBackBufferCapabilities(),
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3855
                  orig.getFlipContents() ==
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3856
                      BufferCapabilities.FlipContents.BACKGROUND ?
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3857
                      BufferCapabilities.FlipContents.BACKGROUND :
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3858
                      BufferCapabilities.FlipContents.COPIED);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3859
            this.orig = orig;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3860
        }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3861
    }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3862
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3863
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3864
     * @return the buffer strategy used by this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3865
     * @see Window#createBufferStrategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3866
     * @see Canvas#createBufferStrategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3867
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3868
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3869
    BufferStrategy getBufferStrategy() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3870
        return bufferStrategy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3871
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3872
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3873
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3874
     * @return the back buffer currently used by this component's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3875
     * BufferStrategy.  If there is no BufferStrategy or no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3876
     * back buffer, this method returns null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3877
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3878
    Image getBackBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3879
        if (bufferStrategy != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3880
            if (bufferStrategy instanceof BltBufferStrategy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3881
                BltBufferStrategy bltBS = (BltBufferStrategy)bufferStrategy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3882
                return bltBS.getBackBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3883
            } else if (bufferStrategy instanceof FlipBufferStrategy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3884
                FlipBufferStrategy flipBS = (FlipBufferStrategy)bufferStrategy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3885
                return flipBS.getBackBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3886
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3887
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3888
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3889
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3890
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3891
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3892
     * Inner class for flipping buffers on a component.  That component must
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3893
     * be a <code>Canvas</code> or <code>Window</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3894
     * @see Canvas
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3895
     * @see Window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3896
     * @see java.awt.image.BufferStrategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3897
     * @author Michael Martak
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3898
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3899
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3900
    protected class FlipBufferStrategy extends BufferStrategy {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3901
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3902
         * The number of buffers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3903
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3904
        protected int numBuffers; // = 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3905
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3906
         * The buffering capabilities
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3907
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3908
        protected BufferCapabilities caps; // = null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3909
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3910
         * The drawing buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3911
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3912
        protected Image drawBuffer; // = null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3913
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3914
         * The drawing buffer as a volatile image
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3915
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3916
        protected VolatileImage drawVBuffer; // = null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3917
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3918
         * Whether or not the drawing buffer has been recently restored from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3919
         * a lost state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3920
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3921
        protected boolean validatedContents; // = false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3922
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3923
         * Size of the back buffers.  (Note: these fields were added in 6.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3924
         * but kept package-private to avoid exposing them in the spec.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3925
         * None of these fields/methods really should have been marked
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3926
         * protected when they were introduced in 1.4, but now we just have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3927
         * to live with that decision.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3928
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3929
        int width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3930
        int height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3931
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3932
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3933
         * Creates a new flipping buffer strategy for this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3934
         * The component must be a <code>Canvas</code> or <code>Window</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3935
         * @see Canvas
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3936
         * @see Window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3937
         * @param numBuffers the number of buffers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3938
         * @param caps the capabilities of the buffers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3939
         * @exception AWTException if the capabilities supplied could not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3940
         * supported or met
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3941
         * @exception ClassCastException if the component is not a canvas or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3942
         * window.
8752
b8b7c54b0c7a 7023019: Constructor of class java.awt.Component.FlipBufferStrategy throws unspecified IAE
dav
parents: 7668
diff changeset
  3943
         * @exception IllegalStateException if the component has no peer
b8b7c54b0c7a 7023019: Constructor of class java.awt.Component.FlipBufferStrategy throws unspecified IAE
dav
parents: 7668
diff changeset
  3944
         * @exception IllegalArgumentException if {@code numBuffers} is less than two,
b8b7c54b0c7a 7023019: Constructor of class java.awt.Component.FlipBufferStrategy throws unspecified IAE
dav
parents: 7668
diff changeset
  3945
         * or if {@code BufferCapabilities.isPageFlipping} is not
b8b7c54b0c7a 7023019: Constructor of class java.awt.Component.FlipBufferStrategy throws unspecified IAE
dav
parents: 7668
diff changeset
  3946
         * {@code true}.
b8b7c54b0c7a 7023019: Constructor of class java.awt.Component.FlipBufferStrategy throws unspecified IAE
dav
parents: 7668
diff changeset
  3947
         * @see #createBuffers(int, BufferCapabilities)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3948
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3949
        protected FlipBufferStrategy(int numBuffers, BufferCapabilities caps)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3950
            throws AWTException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3951
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3952
            if (!(Component.this instanceof Window) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3953
                !(Component.this instanceof Canvas))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3954
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3955
                throw new ClassCastException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3956
                    "Component must be a Canvas or Window");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3957
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3958
            this.numBuffers = numBuffers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3959
            this.caps = caps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3960
            createBuffers(numBuffers, caps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3961
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3962
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3963
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3964
         * Creates one or more complex, flipping buffers with the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3965
         * capabilities.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3966
         * @param numBuffers number of buffers to create; must be greater than
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3967
         * one
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3968
         * @param caps the capabilities of the buffers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3969
         * <code>BufferCapabilities.isPageFlipping</code> must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3970
         * <code>true</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3971
         * @exception AWTException if the capabilities supplied could not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3972
         * supported or met
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3973
         * @exception IllegalStateException if the component has no peer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3974
         * @exception IllegalArgumentException if numBuffers is less than two,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3975
         * or if <code>BufferCapabilities.isPageFlipping</code> is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3976
         * <code>true</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3977
         * @see java.awt.BufferCapabilities#isPageFlipping()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3978
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3979
        protected void createBuffers(int numBuffers, BufferCapabilities caps)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3980
            throws AWTException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3981
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3982
            if (numBuffers < 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3983
                throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3984
                    "Number of buffers cannot be less than two");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3985
            } else if (peer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3986
                throw new IllegalStateException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3987
                    "Component must have a valid peer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3988
            } else if (caps == null || !caps.isPageFlipping()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3989
                throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3990
                    "Page flipping capabilities must be specified");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3991
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3992
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3993
            // save the current bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3994
            width = getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3995
            height = getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3996
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3997
            if (drawBuffer != null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3998
                // dispose the existing backbuffers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3999
                drawBuffer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4000
                drawVBuffer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4001
                destroyBuffers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4002
                // ... then recreate the backbuffers
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4003
            }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4004
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4005
            if (caps instanceof ExtendedBufferCapabilities) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4006
                ExtendedBufferCapabilities ebc =
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4007
                    (ExtendedBufferCapabilities)caps;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4008
                if (ebc.getVSync() == VSYNC_ON) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4009
                    // if this buffer strategy is not allowed to be v-synced,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4010
                    // change the caps that we pass to the peer but keep on
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4011
                    // trying to create v-synced buffers;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4012
                    // do not throw IAE here in case it is disallowed, see
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4013
                    // ExtendedBufferCapabilities for more info
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4014
                    if (!VSyncedBSManager.vsyncAllowed(this)) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4015
                        caps = ebc.derive(VSYNC_DEFAULT);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4016
                    }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4017
                }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4018
            }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4019
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4020
            peer.createBuffers(numBuffers, caps);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4021
            updateInternalBuffers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4022
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4023
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4024
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4025
         * Updates internal buffers (both volatile and non-volatile)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4026
         * by requesting the back-buffer from the peer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4027
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4028
        private void updateInternalBuffers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4029
            // get the images associated with the draw buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4030
            drawBuffer = getBackBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4031
            if (drawBuffer instanceof VolatileImage) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4032
                drawVBuffer = (VolatileImage)drawBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4033
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4034
                drawVBuffer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4035
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4036
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4037
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4038
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4039
         * @return direct access to the back buffer, as an image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4040
         * @exception IllegalStateException if the buffers have not yet
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4041
         * been created
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4042
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4043
        protected Image getBackBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4044
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4045
                return peer.getBackBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4046
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4047
                throw new IllegalStateException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4048
                    "Component must have a valid peer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4049
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4050
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4051
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4052
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4053
         * Flipping moves the contents of the back buffer to the front buffer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4054
         * either by copying or by moving the video pointer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4055
         * @param flipAction an integer value describing the flipping action
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4056
         * for the contents of the back buffer.  This should be one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4057
         * values of the <code>BufferCapabilities.FlipContents</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4058
         * property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4059
         * @exception IllegalStateException if the buffers have not yet
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4060
         * been created
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4061
         * @see java.awt.BufferCapabilities#getFlipContents()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4062
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4063
        protected void flip(BufferCapabilities.FlipContents flipAction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4064
            if (peer != null) {
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4065
                Image backBuffer = getBackBuffer();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4066
                if (backBuffer != null) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4067
                    peer.flip(0, 0,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4068
                              backBuffer.getWidth(null),
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4069
                              backBuffer.getHeight(null), flipAction);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4070
                }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4071
            } else {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4072
                throw new IllegalStateException(
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4073
                    "Component must have a valid peer");
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4074
            }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4075
        }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4076
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4077
        void flipSubRegion(int x1, int y1, int x2, int y2,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4078
                      BufferCapabilities.FlipContents flipAction)
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4079
        {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4080
            if (peer != null) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4081
                peer.flip(x1, y1, x2, y2, flipAction);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4082
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4083
                throw new IllegalStateException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4084
                    "Component must have a valid peer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4085
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4086
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4087
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4088
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4089
         * Destroys the buffers created through this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4090
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4091
        protected void destroyBuffers() {
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4092
            VSyncedBSManager.releaseVsync(this);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4093
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4094
                peer.destroyBuffers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4095
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4096
                throw new IllegalStateException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4097
                    "Component must have a valid peer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4098
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4099
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4100
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4101
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4102
         * @return the buffering capabilities of this strategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4103
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4104
        public BufferCapabilities getCapabilities() {
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4105
            if (caps instanceof ProxyCapabilities) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4106
                return ((ProxyCapabilities)caps).orig;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4107
            } else {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4108
                return caps;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4109
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4110
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4111
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4112
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4113
         * @return the graphics on the drawing buffer.  This method may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4114
         * be synchronized for performance reasons; use of this method by multiple
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4115
         * threads should be handled at the application level.  Disposal of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4116
         * graphics object must be handled by the application.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4117
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4118
        public Graphics getDrawGraphics() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4119
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4120
            return drawBuffer.getGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4122
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4123
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4124
         * Restore the drawing buffer if it has been lost
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4125
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4126
        protected void revalidate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4127
            revalidate(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4128
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4129
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4130
        void revalidate(boolean checkSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4131
            validatedContents = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4132
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4133
            if (checkSize && (getWidth() != width || getHeight() != height)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4134
                // component has been resized; recreate the backbuffers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4135
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4136
                    createBuffers(numBuffers, caps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4137
                } catch (AWTException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4138
                    // shouldn't be possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4139
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4140
                validatedContents = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4141
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4142
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4143
            // get the buffers from the peer every time since they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4144
            // might have been replaced in response to a display change event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4145
            updateInternalBuffers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4146
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4147
            // now validate the backbuffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4148
            if (drawVBuffer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4149
                GraphicsConfiguration gc =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4150
                        getGraphicsConfiguration_NoClientCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4151
                int returnCode = drawVBuffer.validate(gc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4152
                if (returnCode == VolatileImage.IMAGE_INCOMPATIBLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4153
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4154
                        createBuffers(numBuffers, caps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4155
                    } catch (AWTException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4156
                        // shouldn't be possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4157
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4158
                    if (drawVBuffer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4159
                        // backbuffers were recreated, so validate again
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4160
                        drawVBuffer.validate(gc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4161
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4162
                    validatedContents = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4163
                } else if (returnCode == VolatileImage.IMAGE_RESTORED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4164
                    validatedContents = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4165
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4166
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4167
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4168
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4169
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4170
         * @return whether the drawing buffer was lost since the last call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4171
         * <code>getDrawGraphics</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4172
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4173
        public boolean contentsLost() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4174
            if (drawVBuffer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4175
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4176
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4177
            return drawVBuffer.contentsLost();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4179
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4180
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4181
         * @return whether the drawing buffer was recently restored from a lost
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4182
         * state and reinitialized to the default background color (white)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4183
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4184
        public boolean contentsRestored() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4185
            return validatedContents;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4187
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4188
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4189
         * Makes the next available buffer visible by either blitting or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4190
         * flipping.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4191
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4192
        public void show() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4193
            flip(caps.getFlipContents());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4195
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4196
        /**
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4197
         * Makes specified region of the the next available buffer visible
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4198
         * by either blitting or flipping.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4199
         */
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4200
        void showSubRegion(int x1, int y1, int x2, int y2) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4201
            flipSubRegion(x1, y1, x2, y2, caps.getFlipContents());
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4202
        }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4203
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4204
        /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4205
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4206
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4207
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4208
        public void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4209
            if (Component.this.bufferStrategy == this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4210
                Component.this.bufferStrategy = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4211
                if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4212
                    destroyBuffers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4213
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4214
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4215
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4216
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4217
    } // Inner class FlipBufferStrategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4218
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4219
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4220
     * Inner class for blitting offscreen surfaces to a component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4221
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4222
     * @author Michael Martak
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4223
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4224
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4225
    protected class BltBufferStrategy extends BufferStrategy {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4226
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4227
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4228
         * The buffering capabilities
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4229
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4230
        protected BufferCapabilities caps; // = null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4231
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4232
         * The back buffers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4233
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4234
        protected VolatileImage[] backBuffers; // = null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4235
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4236
         * Whether or not the drawing buffer has been recently restored from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4237
         * a lost state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4238
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4239
        protected boolean validatedContents; // = false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4240
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4241
         * Size of the back buffers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4242
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4243
        protected int width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4244
        protected int height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4245
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4246
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4247
         * Insets for the hosting Component.  The size of the back buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4248
         * is constrained by these.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4249
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4250
        private Insets insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4251
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4252
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4253
         * Creates a new blt buffer strategy around a component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4254
         * @param numBuffers number of buffers to create, including the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4255
         * front buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4256
         * @param caps the capabilities of the buffers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4257
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4258
        protected BltBufferStrategy(int numBuffers, BufferCapabilities caps) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4259
            this.caps = caps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4260
            createBackBuffers(numBuffers - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4261
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4262
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4263
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4264
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4265
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4266
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4267
        public void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4268
            if (backBuffers != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4269
                for (int counter = backBuffers.length - 1; counter >= 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4270
                     counter--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4271
                    if (backBuffers[counter] != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4272
                        backBuffers[counter].flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4273
                        backBuffers[counter] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4274
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4275
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4276
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4277
            if (Component.this.bufferStrategy == this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4278
                Component.this.bufferStrategy = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4279
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4280
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4281
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4282
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4283
         * Creates the back buffers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4284
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4285
        protected void createBackBuffers(int numBuffers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4286
            if (numBuffers == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4287
                backBuffers = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4288
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4289
                // save the current bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4290
                width = getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4291
                height = getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4292
                insets = getInsets_NoClientCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4293
                int iWidth = width - insets.left - insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4294
                int iHeight = height - insets.top - insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4295
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4296
                // It is possible for the component's width and/or height
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4297
                // to be 0 here.  Force the size of the backbuffers to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4298
                // be > 0 so that creating the image won't fail.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4299
                iWidth = Math.max(1, iWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4300
                iHeight = Math.max(1, iHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4301
                if (backBuffers == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4302
                    backBuffers = new VolatileImage[numBuffers];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4303
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4304
                    // flush any existing backbuffers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4305
                    for (int i = 0; i < numBuffers; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4306
                        if (backBuffers[i] != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4307
                            backBuffers[i].flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4308
                            backBuffers[i] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4309
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4310
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4311
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4312
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4313
                // create the backbuffers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4314
                for (int i = 0; i < numBuffers; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4315
                    backBuffers[i] = createVolatileImage(iWidth, iHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4316
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4317
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4318
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4319
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4320
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4321
         * @return the buffering capabilities of this strategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4322
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4323
        public BufferCapabilities getCapabilities() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4324
            return caps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4325
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4326
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4327
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4328
         * @return the draw graphics
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4329
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4330
        public Graphics getDrawGraphics() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4331
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4332
            Image backBuffer = getBackBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4333
            if (backBuffer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4334
                return getGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4335
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4336
            SunGraphics2D g = (SunGraphics2D)backBuffer.getGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4337
            g.constrain(-insets.left, -insets.top,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4338
                        backBuffer.getWidth(null) + insets.left,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4339
                        backBuffer.getHeight(null) + insets.top);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4340
            return g;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4341
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4342
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4343
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4344
         * @return direct access to the back buffer, as an image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4345
         * If there is no back buffer, returns null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4346
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4347
        Image getBackBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4348
            if (backBuffers != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4349
                return backBuffers[backBuffers.length - 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4350
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4351
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4352
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4353
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4354
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4355
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4356
         * Makes the next available buffer visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4357
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4358
        public void show() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4359
            showSubRegion(insets.left, insets.top,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4360
                          width - insets.right,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4361
                          height - insets.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4362
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4363
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4364
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4365
         * Package-private method to present a specific rectangular area
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4366
         * of this buffer.  This class currently shows only the entire
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4367
         * buffer, by calling showSubRegion() with the full dimensions of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4368
         * the buffer.  Subclasses (e.g., BltSubRegionBufferStrategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4369
         * and FlipSubRegionBufferStrategy) may have region-specific show
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4370
         * methods that call this method with actual sub regions of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4371
         * buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4372
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4373
        void showSubRegion(int x1, int y1, int x2, int y2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4374
            if (backBuffers == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4375
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4376
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4377
            // Adjust location to be relative to client area.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4378
            x1 -= insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4379
            x2 -= insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4380
            y1 -= insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4381
            y2 -= insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4382
            Graphics g = getGraphics_NoClientCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4383
            if (g == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4384
                // Not showing, bail
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4385
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4386
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4387
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4388
                // First image copy is in terms of Frame's coordinates, need
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4389
                // to translate to client area.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4390
                g.translate(insets.left, insets.top);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4391
                for (int i = 0; i < backBuffers.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4392
                    g.drawImage(backBuffers[i],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4393
                                x1, y1, x2, y2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4394
                                x1, y1, x2, y2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4395
                                null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4396
                    g.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4397
                    g = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4398
                    g = backBuffers[i].getGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4399
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4400
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4401
                if (g != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4402
                    g.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4403
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4404
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4405
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4406
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4407
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4408
         * Restore the drawing buffer if it has been lost
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4409
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4410
        protected void revalidate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4411
            revalidate(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4412
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4413
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4414
        void revalidate(boolean checkSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4415
            validatedContents = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4416
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4417
            if (backBuffers == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4418
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4419
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4420
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4421
            if (checkSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4422
                Insets insets = getInsets_NoClientCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4423
                if (getWidth() != width || getHeight() != height ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4424
                    !insets.equals(this.insets)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4425
                    // component has been resized; recreate the backbuffers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4426
                    createBackBuffers(backBuffers.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4427
                    validatedContents = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4428
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4429
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4430
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4431
            // now validate the backbuffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4432
            GraphicsConfiguration gc = getGraphicsConfiguration_NoClientCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4433
            int returnCode =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4434
                backBuffers[backBuffers.length - 1].validate(gc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4435
            if (returnCode == VolatileImage.IMAGE_INCOMPATIBLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4436
                if (checkSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4437
                    createBackBuffers(backBuffers.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4438
                    // backbuffers were recreated, so validate again
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4439
                    backBuffers[backBuffers.length - 1].validate(gc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4440
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4441
                // else case means we're called from Swing on the toolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4442
                // thread, don't recreate buffers as that'll deadlock
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4443
                // (creating VolatileImages invokes getting GraphicsConfig
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4444
                // which grabs treelock).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4445
                validatedContents = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4446
            } else if (returnCode == VolatileImage.IMAGE_RESTORED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4447
                validatedContents = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4448
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4449
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4450
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4451
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4452
         * @return whether the drawing buffer was lost since the last call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4453
         * <code>getDrawGraphics</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4454
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4455
        public boolean contentsLost() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4456
            if (backBuffers == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4457
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4458
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4459
                return backBuffers[backBuffers.length - 1].contentsLost();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4460
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4461
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4462
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4463
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4464
         * @return whether the drawing buffer was recently restored from a lost
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4465
         * state and reinitialized to the default background color (white)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4466
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4467
        public boolean contentsRestored() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4468
            return validatedContents;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4469
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4470
    } // Inner class BltBufferStrategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4471
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4472
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4473
     * Private class to perform sub-region flipping.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4474
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4475
    private class FlipSubRegionBufferStrategy extends FlipBufferStrategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4476
        implements SubRegionShowable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4477
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4478
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4479
        protected FlipSubRegionBufferStrategy(int numBuffers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4480
                                              BufferCapabilities caps)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4481
            throws AWTException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4482
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4483
            super(numBuffers, caps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4484
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4485
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4486
        public void show(int x1, int y1, int x2, int y2) {
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4487
            showSubRegion(x1, y1, x2, y2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4488
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4489
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4490
        // This is invoked by Swing on the toolkit thread.
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4491
        public boolean showIfNotLost(int x1, int y1, int x2, int y2) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4492
            if (!contentsLost()) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4493
                showSubRegion(x1, y1, x2, y2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4494
                return !contentsLost();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4495
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4496
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4497
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4498
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4499
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4500
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4501
     * Private class to perform sub-region blitting.  Swing will use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4502
     * this subclass via the SubRegionShowable interface in order to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4503
     * copy only the area changed during a repaint.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4504
     * @see javax.swing.BufferStrategyPaintManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4505
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4506
    private class BltSubRegionBufferStrategy extends BltBufferStrategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4507
        implements SubRegionShowable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4508
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4509
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4510
        protected BltSubRegionBufferStrategy(int numBuffers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4511
                                             BufferCapabilities caps)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4512
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4513
            super(numBuffers, caps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4514
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4515
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4516
        public void show(int x1, int y1, int x2, int y2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4517
            showSubRegion(x1, y1, x2, y2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4518
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4519
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4520
        // This method is called by Swing on the toolkit thread.
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4521
        public boolean showIfNotLost(int x1, int y1, int x2, int y2) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4522
            if (!contentsLost()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4523
                showSubRegion(x1, y1, x2, y2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4524
                return !contentsLost();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4525
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4526
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4527
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4528
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4529
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4530
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4531
     * Inner class for flipping buffers on a component.  That component must
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4532
     * be a <code>Canvas</code> or <code>Window</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4533
     * @see Canvas
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4534
     * @see Window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4535
     * @see java.awt.image.BufferStrategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4536
     * @author Michael Martak
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4537
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4538
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4539
    private class SingleBufferStrategy extends BufferStrategy {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4540
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4541
        private BufferCapabilities caps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4542
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4543
        public SingleBufferStrategy(BufferCapabilities caps) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4544
            this.caps = caps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4545
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4546
        public BufferCapabilities getCapabilities() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4547
            return caps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4548
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4549
        public Graphics getDrawGraphics() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4550
            return getGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4551
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4552
        public boolean contentsLost() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4553
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4554
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4555
        public boolean contentsRestored() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4556
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4557
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4558
        public void show() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4559
            // Do nothing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4560
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4561
    } // Inner class SingleBufferStrategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4562
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4563
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4564
     * Sets whether or not paint messages received from the operating system
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4565
     * should be ignored.  This does not affect paint events generated in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4566
     * software by the AWT, unless they are an immediate response to an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4567
     * OS-level paint message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4568
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4569
     * This is useful, for example, if running under full-screen mode and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4570
     * better performance is desired, or if page-flipping is used as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4571
     * buffer strategy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4572
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4573
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4574
     * @see #getIgnoreRepaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4575
     * @see Canvas#createBufferStrategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4576
     * @see Window#createBufferStrategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4577
     * @see java.awt.image.BufferStrategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4578
     * @see GraphicsDevice#setFullScreenWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4579
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4580
    public void setIgnoreRepaint(boolean ignoreRepaint) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4581
        this.ignoreRepaint = ignoreRepaint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4582
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4583
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4584
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4585
     * @return whether or not paint messages received from the operating system
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4586
     * should be ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4587
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4588
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4589
     * @see #setIgnoreRepaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4590
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4591
    public boolean getIgnoreRepaint() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4592
        return ignoreRepaint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4593
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4594
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4595
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4596
     * Checks whether this component "contains" the specified point,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4597
     * where <code>x</code> and <code>y</code> are defined to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4598
     * relative to the coordinate system of this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4599
     * @param     x   the <i>x</i> coordinate of the point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4600
     * @param     y   the <i>y</i> coordinate of the point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4601
     * @see       #getComponentAt(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4602
     * @since     JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4603
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4604
    public boolean contains(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4605
        return inside(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4606
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4607
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4608
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4609
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4610
     * replaced by contains(int, int).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4611
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4612
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4613
    public boolean inside(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4614
        return (x >= 0) && (x < width) && (y >= 0) && (y < height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4615
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4616
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4617
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4618
     * Checks whether this component "contains" the specified point,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4619
     * where the point's <i>x</i> and <i>y</i> coordinates are defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4620
     * to be relative to the coordinate system of this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4621
     * @param     p     the point
7154
4e8371f358ac 6877895: Some AWT's methods should specify throwing NPE for null arg value
dcherepanov
parents: 5506
diff changeset
  4622
     * @throws    NullPointerException if {@code p} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4623
     * @see       #getComponentAt(Point)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4624
     * @since     JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4625
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4626
    public boolean contains(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4627
        return contains(p.x, p.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4628
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4629
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4630
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4631
     * Determines if this component or one of its immediate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4632
     * subcomponents contains the (<i>x</i>,&nbsp;<i>y</i>) location,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4633
     * and if so, returns the containing component. This method only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4634
     * looks one level deep. If the point (<i>x</i>,&nbsp;<i>y</i>) is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4635
     * inside a subcomponent that itself has subcomponents, it does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4636
     * go looking down the subcomponent tree.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4637
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4638
     * The <code>locate</code> method of <code>Component</code> simply
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4639
     * returns the component itself if the (<i>x</i>,&nbsp;<i>y</i>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4640
     * coordinate location is inside its bounding box, and <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4641
     * otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4642
     * @param     x   the <i>x</i> coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4643
     * @param     y   the <i>y</i> coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4644
     * @return    the component or subcomponent that contains the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4645
     *                (<i>x</i>,&nbsp;<i>y</i>) location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4646
     *                <code>null</code> if the location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4647
     *                is outside this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4648
     * @see       #contains(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4649
     * @since     JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4650
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4651
    public Component getComponentAt(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4652
        return locate(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4653
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4654
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4655
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4656
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4657
     * replaced by getComponentAt(int, int).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4658
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4659
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4660
    public Component locate(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4661
        return contains(x, y) ? this : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4662
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4663
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4664
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4665
     * Returns the component or subcomponent that contains the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4666
     * specified point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4667
     * @param     p   the point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4668
     * @see       java.awt.Component#contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4669
     * @since     JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4670
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4671
    public Component getComponentAt(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4672
        return getComponentAt(p.x, p.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4673
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4674
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4675
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4676
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4677
     * replaced by <code>dispatchEvent(AWTEvent e)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4678
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4679
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4680
    public void deliverEvent(Event e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4681
        postEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4682
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4683
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4684
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4685
     * Dispatches an event to this component or one of its sub components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4686
     * Calls <code>processEvent</code> before returning for 1.1-style
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4687
     * events which have been enabled for the <code>Component</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4688
     * @param e the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4689
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4690
    public final void dispatchEvent(AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4691
        dispatchEventImpl(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4692
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4693
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  4694
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4695
    void dispatchEventImpl(AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4696
        int id = e.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4697
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4698
        // Check that this component belongs to this app-context
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4699
        AppContext compContext = appContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4700
        if (compContext != null && !compContext.equals(AppContext.getAppContext())) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  4701
            if (eventLog.isLoggable(PlatformLogger.FINE)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  4702
                eventLog.fine("Event " + e + " is being dispatched on the wrong AppContext");
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  4703
            }
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  4704
        }
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  4705
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  4706
        if (eventLog.isLoggable(PlatformLogger.FINEST)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  4707
            eventLog.finest("{0}", e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4708
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4709
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4710
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4711
         * 0. Set timestamp and modifiers of current event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4712
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4713
        EventQueue.setCurrentEventAndMostRecentTime(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4714
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4715
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4716
         * 1. Pre-dispatchers. Do any necessary retargeting/reordering here
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4717
         *    before we notify AWTEventListeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4718
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4719
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4720
        if (e instanceof SunDropTargetEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4721
            ((SunDropTargetEvent)e).dispatch();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4722
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4723
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4724
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4725
        if (!e.focusManagerIsDispatching) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4726
            // Invoke the private focus retargeting method which provides
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4727
            // lightweight Component support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4728
            if (e.isPosted) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4729
                e = KeyboardFocusManager.retargetFocusEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4730
                e.isPosted = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4731
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4732
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4733
            // Now, with the event properly targeted to a lightweight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4734
            // descendant if necessary, invoke the public focus retargeting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4735
            // and dispatching function
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4736
            if (KeyboardFocusManager.getCurrentKeyboardFocusManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4737
                dispatchEvent(e))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4738
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4739
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4740
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4741
        }
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  4742
        if ((e instanceof FocusEvent) && focusLog.isLoggable(PlatformLogger.FINEST)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  4743
            focusLog.finest("" + e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4744
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4745
        // MouseWheel may need to be retargeted here so that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4746
        // AWTEventListener sees the event go to the correct
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4747
        // Component.  If the MouseWheelEvent needs to go to an ancestor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4748
        // the event is dispatched to the ancestor, and dispatching here
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4749
        // stops.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4750
        if (id == MouseEvent.MOUSE_WHEEL &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4751
            (!eventTypeEnabled(id)) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4752
            (peer != null && !peer.handlesWheelScrolling()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4753
            (dispatchMouseWheelToAncestor((MouseWheelEvent)e)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4754
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4755
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4756
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4757
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4758
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4759
         * 2. Allow the Toolkit to pass this to AWTEventListeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4760
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4761
        Toolkit toolkit = Toolkit.getDefaultToolkit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4762
        toolkit.notifyAWTEventListeners(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4763
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4764
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4765
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4766
         * 3. If no one has consumed a key event, allow the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4767
         *    KeyboardFocusManager to process it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4768
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4769
        if (!e.isConsumed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4770
            if (e instanceof java.awt.event.KeyEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4771
                KeyboardFocusManager.getCurrentKeyboardFocusManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4772
                    processKeyEvent(this, (KeyEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4773
                if (e.isConsumed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4774
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4775
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4776
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4777
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4778
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4779
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4780
         * 4. Allow input methods to process the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4781
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4782
        if (areInputMethodsEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4783
            // We need to pass on InputMethodEvents since some host
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4784
            // input method adapters send them through the Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4785
            // event queue instead of directly to the component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4786
            // and the input context also handles the Java composition window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4787
            if(((e instanceof InputMethodEvent) && !(this instanceof CompositionArea))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4788
               ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4789
               // Otherwise, we only pass on input and focus events, because
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4790
               // a) input methods shouldn't know about semantic or component-level events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4791
               // b) passing on the events takes time
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4792
               // c) isConsumed() is always true for semantic events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4793
               (e instanceof InputEvent) || (e instanceof FocusEvent)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4794
                InputContext inputContext = getInputContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4795
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4796
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4797
                if (inputContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4798
                    inputContext.dispatchEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4799
                    if (e.isConsumed()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  4800
                        if ((e instanceof FocusEvent) && focusLog.isLoggable(PlatformLogger.FINEST)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  4801
                            focusLog.finest("3579: Skipping " + e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4802
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4803
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4804
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4805
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4806
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4807
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4808
            // When non-clients get focus, we need to explicitly disable the native
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4809
            // input method. The native input method is actually not disabled when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4810
            // the active/passive/peered clients loose focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4811
            if (id == FocusEvent.FOCUS_GAINED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4812
                InputContext inputContext = getInputContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4813
                if (inputContext != null && inputContext instanceof sun.awt.im.InputContext) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4814
                    ((sun.awt.im.InputContext)inputContext).disableNativeIM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4815
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4816
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4817
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4818
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4819
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4820
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4821
         * 5. Pre-process any special events before delivery
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4822
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4823
        switch(id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4824
            // Handling of the PAINT and UPDATE events is now done in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4825
            // peer's handleEvent() method so the background can be cleared
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4826
            // selectively for non-native components on Windows only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4827
            // - Fred.Ecks@Eng.sun.com, 5-8-98
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4828
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4829
          case KeyEvent.KEY_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4830
          case KeyEvent.KEY_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4831
              Container p = (Container)((this instanceof Container) ? this : parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4832
              if (p != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4833
                  p.preProcessKeyEvent((KeyEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4834
                  if (e.isConsumed()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  4835
                        if (focusLog.isLoggable(PlatformLogger.FINEST)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  4836
                            focusLog.finest("Pre-process consumed event");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4837
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4838
                      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4839
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4840
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4841
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4842
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4843
          case WindowEvent.WINDOW_CLOSING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4844
              if (toolkit instanceof WindowClosingListener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4845
                  windowClosingException = ((WindowClosingListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4846
                                            toolkit).windowClosingNotify((WindowEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4847
                  if (checkWindowClosingException()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4848
                      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4849
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4850
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4851
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4852
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4853
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4854
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4855
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4856
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4857
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4858
         * 6. Deliver event for normal processing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4859
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4860
        if (newEventsOnly) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4861
            // Filtering needs to really be moved to happen at a lower
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4862
            // level in order to get maximum performance gain;  it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4863
            // here temporarily to ensure the API spec is honored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4864
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4865
            if (eventEnabled(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4866
                processEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4867
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4868
        } else if (id == MouseEvent.MOUSE_WHEEL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4869
            // newEventsOnly will be false for a listenerless ScrollPane, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4870
            // MouseWheelEvents still need to be dispatched to it so scrolling
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4871
            // can be done.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4872
            autoProcessMouseWheel((MouseWheelEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4873
        } else if (!(e instanceof MouseEvent && !postsOldMouseEvents())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4874
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4875
            // backward compatibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4876
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4877
            Event olde = e.convertToOld();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4878
            if (olde != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4879
                int key = olde.key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4880
                int modifiers = olde.modifiers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4881
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4882
                postEvent(olde);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4883
                if (olde.isConsumed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4884
                    e.consume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4885
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4886
                // if target changed key or modifier values, copy them
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4887
                // back to original event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4888
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4889
                switch(olde.id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4890
                  case Event.KEY_PRESS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4891
                  case Event.KEY_RELEASE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4892
                  case Event.KEY_ACTION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4893
                  case Event.KEY_ACTION_RELEASE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4894
                      if (olde.key != key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4895
                          ((KeyEvent)e).setKeyChar(olde.getKeyEventChar());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4896
                      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4897
                      if (olde.modifiers != modifiers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4898
                          ((KeyEvent)e).setModifiers(olde.modifiers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4899
                      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4900
                      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4901
                  default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4902
                      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4903
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4904
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4905
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4906
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4907
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4908
         * 8. Special handling for 4061116 : Hook for browser to close modal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4909
         *    dialogs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4910
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4911
        if (id == WindowEvent.WINDOW_CLOSING && !e.isConsumed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4912
            if (toolkit instanceof WindowClosingListener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4913
                windowClosingException =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4914
                    ((WindowClosingListener)toolkit).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4915
                    windowClosingDelivered((WindowEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4916
                if (checkWindowClosingException()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4917
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4918
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4919
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4920
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4921
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4922
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4923
         * 9. Allow the peer to process the event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4924
         * Except KeyEvents, they will be processed by peer after
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4925
         * all KeyEventPostProcessors
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4926
         * (see DefaultKeyboardFocusManager.dispatchKeyEvent())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4927
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4928
        if (!(e instanceof KeyEvent)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4929
            ComponentPeer tpeer = peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4930
            if (e instanceof FocusEvent && (tpeer == null || tpeer instanceof LightweightPeer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4931
                // if focus owner is lightweight then its native container
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4932
                // processes event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4933
                Component source = (Component)e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4934
                if (source != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4935
                    Container target = source.getNativeContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4936
                    if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4937
                        tpeer = target.getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4938
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4939
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4940
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4941
            if (tpeer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4942
                tpeer.handleEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4943
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4944
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4945
    } // dispatchEventImpl()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4946
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4947
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4948
     * If newEventsOnly is false, method is called so that ScrollPane can
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4949
     * override it and handle common-case mouse wheel scrolling.  NOP
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4950
     * for Component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4951
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4952
    void autoProcessMouseWheel(MouseWheelEvent e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4953
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4954
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4955
     * Dispatch given MouseWheelEvent to the first ancestor for which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4956
     * MouseWheelEvents are enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4957
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4958
     * Returns whether or not event was dispatched to an ancestor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4959
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4960
    boolean dispatchMouseWheelToAncestor(MouseWheelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4961
        int newX, newY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4962
        newX = e.getX() + getX(); // Coordinates take into account at least
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4963
        newY = e.getY() + getY(); // the cursor's position relative to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4964
                                  // Component (e.getX()), and this Component's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4965
                                  // position relative to its parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4966
        MouseWheelEvent newMWE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4967
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  4968
        if (eventLog.isLoggable(PlatformLogger.FINEST)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  4969
            eventLog.finest("dispatchMouseWheelToAncestor");
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  4970
            eventLog.finest("orig event src is of " + e.getSource().getClass());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4971
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4972
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4973
        /* parent field for Window refers to the owning Window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4974
         * MouseWheelEvents should NOT be propagated into owning Windows
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4975
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4976
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4977
            Container anc = getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4978
            while (anc != null && !anc.eventEnabled(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4979
                // fix coordinates to be relative to new event source
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4980
                newX += anc.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4981
                newY += anc.getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4982
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4983
                if (!(anc instanceof Window)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4984
                    anc = anc.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4985
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4986
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4987
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4988
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4989
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4990
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  4991
            if (eventLog.isLoggable(PlatformLogger.FINEST)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  4992
                eventLog.finest("new event src is " + anc.getClass());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4993
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4994
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4995
            if (anc != null && anc.eventEnabled(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4996
                // Change event to be from new source, with new x,y
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4997
                // For now, just create a new event - yucky
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4998
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4999
                newMWE = new MouseWheelEvent(anc, // new source
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5000
                                             e.getID(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5001
                                             e.getWhen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5002
                                             e.getModifiers(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5003
                                             newX, // x relative to new source
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5004
                                             newY, // y relative to new source
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5005
                                             e.getXOnScreen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5006
                                             e.getYOnScreen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5007
                                             e.getClickCount(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5008
                                             e.isPopupTrigger(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5009
                                             e.getScrollType(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5010
                                             e.getScrollAmount(),
121
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 119
diff changeset
  5011
                                             e.getWheelRotation(),
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 119
diff changeset
  5012
                                             e.getPreciseWheelRotation());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5013
                ((AWTEvent)e).copyPrivateDataInto(newMWE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5014
                // When dispatching a wheel event to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5015
                // ancestor, there is no need trying to find descendant
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5016
                // lightweights to dispatch event to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5017
                // If we dispatch the event to toplevel ancestor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5018
                // this could encolse the loop: 6480024.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5019
                anc.dispatchEventToSelf(newMWE);
5277
03170721df2e 6920842: Wheel events do not bubbling to the browser if they was not treated in applet.
uta
parents: 4371
diff changeset
  5020
                if (newMWE.isConsumed()) {
03170721df2e 6920842: Wheel events do not bubbling to the browser if they was not treated in applet.
uta
parents: 4371
diff changeset
  5021
                    e.consume();
03170721df2e 6920842: Wheel events do not bubbling to the browser if they was not treated in applet.
uta
parents: 4371
diff changeset
  5022
                }
03170721df2e 6920842: Wheel events do not bubbling to the browser if they was not treated in applet.
uta
parents: 4371
diff changeset
  5023
                return true;
03170721df2e 6920842: Wheel events do not bubbling to the browser if they was not treated in applet.
uta
parents: 4371
diff changeset
  5024
            }
03170721df2e 6920842: Wheel events do not bubbling to the browser if they was not treated in applet.
uta
parents: 4371
diff changeset
  5025
        }
03170721df2e 6920842: Wheel events do not bubbling to the browser if they was not treated in applet.
uta
parents: 4371
diff changeset
  5026
        return false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5027
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5028
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5029
    boolean checkWindowClosingException() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5030
        if (windowClosingException != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5031
            if (this instanceof Dialog) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5032
                ((Dialog)this).interruptBlocking();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5033
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5034
                windowClosingException.fillInStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5035
                windowClosingException.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5036
                windowClosingException = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5037
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5038
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5039
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5040
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5041
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5042
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5043
    boolean areInputMethodsEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5044
        // in 1.2, we assume input method support is required for all
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5045
        // components that handle key events, but components can turn off
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5046
        // input methods by calling enableInputMethods(false).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5047
        return ((eventMask & AWTEvent.INPUT_METHODS_ENABLED_MASK) != 0) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5048
            ((eventMask & AWTEvent.KEY_EVENT_MASK) != 0 || keyListener != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5049
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5050
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5051
    // REMIND: remove when filtering is handled at lower level
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5052
    boolean eventEnabled(AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5053
        return eventTypeEnabled(e.id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5054
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5055
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5056
    boolean eventTypeEnabled(int type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5057
        switch(type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5058
          case ComponentEvent.COMPONENT_MOVED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5059
          case ComponentEvent.COMPONENT_RESIZED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5060
          case ComponentEvent.COMPONENT_SHOWN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5061
          case ComponentEvent.COMPONENT_HIDDEN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5062
              if ((eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5063
                  componentListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5064
                  return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5065
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5066
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5067
          case FocusEvent.FOCUS_GAINED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5068
          case FocusEvent.FOCUS_LOST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5069
              if ((eventMask & AWTEvent.FOCUS_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5070
                  focusListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5071
                  return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5072
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5073
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5074
          case KeyEvent.KEY_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5075
          case KeyEvent.KEY_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5076
          case KeyEvent.KEY_TYPED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5077
              if ((eventMask & AWTEvent.KEY_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5078
                  keyListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5079
                  return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5080
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5081
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5082
          case MouseEvent.MOUSE_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5083
          case MouseEvent.MOUSE_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5084
          case MouseEvent.MOUSE_ENTERED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5085
          case MouseEvent.MOUSE_EXITED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5086
          case MouseEvent.MOUSE_CLICKED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5087
              if ((eventMask & AWTEvent.MOUSE_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5088
                  mouseListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5089
                  return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5090
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5091
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5092
          case MouseEvent.MOUSE_MOVED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5093
          case MouseEvent.MOUSE_DRAGGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5094
              if ((eventMask & AWTEvent.MOUSE_MOTION_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5095
                  mouseMotionListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5096
                  return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5097
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5098
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5099
          case MouseEvent.MOUSE_WHEEL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5100
              if ((eventMask & AWTEvent.MOUSE_WHEEL_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5101
                  mouseWheelListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5102
                  return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5103
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5104
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5105
          case InputMethodEvent.INPUT_METHOD_TEXT_CHANGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5106
          case InputMethodEvent.CARET_POSITION_CHANGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5107
              if ((eventMask & AWTEvent.INPUT_METHOD_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5108
                  inputMethodListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5109
                  return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5110
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5111
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5112
          case HierarchyEvent.HIERARCHY_CHANGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5113
              if ((eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5114
                  hierarchyListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5115
                  return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5116
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5117
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5118
          case HierarchyEvent.ANCESTOR_MOVED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5119
          case HierarchyEvent.ANCESTOR_RESIZED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5120
              if ((eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5121
                  hierarchyBoundsListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5122
                  return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5123
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5124
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5125
          case ActionEvent.ACTION_PERFORMED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5126
              if ((eventMask & AWTEvent.ACTION_EVENT_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5127
                  return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5128
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5129
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5130
          case TextEvent.TEXT_VALUE_CHANGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5131
              if ((eventMask & AWTEvent.TEXT_EVENT_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5132
                  return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5133
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5134
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5135
          case ItemEvent.ITEM_STATE_CHANGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5136
              if ((eventMask & AWTEvent.ITEM_EVENT_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5137
                  return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5138
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5139
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5140
          case AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5141
              if ((eventMask & AWTEvent.ADJUSTMENT_EVENT_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5142
                  return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5143
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5144
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5145
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5146
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5148
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5149
        // Always pass on events defined by external programs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5150
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5151
        if (type > AWTEvent.RESERVED_ID_MAX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5152
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5154
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5156
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5157
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5158
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5159
     * replaced by dispatchEvent(AWTEvent).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5160
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5161
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5162
    public boolean postEvent(Event e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5163
        ComponentPeer peer = this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5164
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5165
        if (handleEvent(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5166
            e.consume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5167
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5168
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5169
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5170
        Component parent = this.parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5171
        int eventx = e.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5172
        int eventy = e.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5173
        if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5174
            e.translate(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5175
            if (parent.postEvent(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5176
                e.consume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5177
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5178
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5179
            // restore coords
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5180
            e.x = eventx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5181
            e.y = eventy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5183
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5185
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5186
    // Event source interfaces
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5187
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5188
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5189
     * Adds the specified component listener to receive component events from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5190
     * this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5191
     * If listener <code>l</code> is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5192
     * no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5193
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5194
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5195
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5196
     * @param    l   the component listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5197
     * @see      java.awt.event.ComponentEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5198
     * @see      java.awt.event.ComponentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5199
     * @see      #removeComponentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5200
     * @see      #getComponentListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5201
     * @since    JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5202
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5203
    public synchronized void addComponentListener(ComponentListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5204
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5205
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5206
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5207
        componentListener = AWTEventMulticaster.add(componentListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5208
        newEventsOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5210
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5211
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5212
     * Removes the specified component listener so that it no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5213
     * receives component events from this component. This method performs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5214
     * no function, nor does it throw an exception, if the listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5215
     * specified by the argument was not previously added to this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5216
     * If listener <code>l</code> is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5217
     * no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5218
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5219
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5220
     * @param    l   the component listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5221
     * @see      java.awt.event.ComponentEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5222
     * @see      java.awt.event.ComponentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5223
     * @see      #addComponentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5224
     * @see      #getComponentListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5225
     * @since    JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5226
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5227
    public synchronized void removeComponentListener(ComponentListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5228
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5229
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5230
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5231
        componentListener = AWTEventMulticaster.remove(componentListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5233
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5234
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5235
     * Returns an array of all the component listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5236
     * registered on this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5237
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5238
     * @return all of this comonent's <code>ComponentListener</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5239
     *         or an empty array if no component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5240
     *         listeners are currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5241
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5242
     * @see #addComponentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5243
     * @see #removeComponentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5244
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5245
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5246
    public synchronized ComponentListener[] getComponentListeners() {
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  5247
        return getListeners(ComponentListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5249
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5250
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5251
     * Adds the specified focus listener to receive focus events from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5252
     * this component when this component gains input focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5253
     * If listener <code>l</code> is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5254
     * no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5255
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5256
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5257
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5258
     * @param    l   the focus listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5259
     * @see      java.awt.event.FocusEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5260
     * @see      java.awt.event.FocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5261
     * @see      #removeFocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5262
     * @see      #getFocusListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5263
     * @since    JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5264
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5265
    public synchronized void addFocusListener(FocusListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5266
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5267
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5268
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5269
        focusListener = AWTEventMulticaster.add(focusListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5270
        newEventsOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5271
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5272
        // if this is a lightweight component, enable focus events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5273
        // in the native container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5274
        if (peer instanceof LightweightPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5275
            parent.proxyEnableEvents(AWTEvent.FOCUS_EVENT_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5276
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5278
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5279
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5280
     * Removes the specified focus listener so that it no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5281
     * receives focus events from this component. This method performs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5282
     * no function, nor does it throw an exception, if the listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5283
     * specified by the argument was not previously added to this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5284
     * If listener <code>l</code> is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5285
     * no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5286
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5287
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5288
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5289
     * @param    l   the focus listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5290
     * @see      java.awt.event.FocusEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5291
     * @see      java.awt.event.FocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5292
     * @see      #addFocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5293
     * @see      #getFocusListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5294
     * @since    JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5295
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5296
    public synchronized void removeFocusListener(FocusListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5297
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5298
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5299
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5300
        focusListener = AWTEventMulticaster.remove(focusListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5302
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5303
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5304
     * Returns an array of all the focus listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5305
     * registered on this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5306
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5307
     * @return all of this component's <code>FocusListener</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5308
     *         or an empty array if no component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5309
     *         listeners are currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5310
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5311
     * @see #addFocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5312
     * @see #removeFocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5313
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5314
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5315
    public synchronized FocusListener[] getFocusListeners() {
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  5316
        return getListeners(FocusListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5317
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5318
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5319
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5320
     * Adds the specified hierarchy listener to receive hierarchy changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5321
     * events from this component when the hierarchy to which this container
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5322
     * belongs changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5323
     * If listener <code>l</code> is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5324
     * no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5325
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5326
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5327
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5328
     * @param    l   the hierarchy listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5329
     * @see      java.awt.event.HierarchyEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5330
     * @see      java.awt.event.HierarchyListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5331
     * @see      #removeHierarchyListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5332
     * @see      #getHierarchyListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5333
     * @since    1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5334
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5335
    public void addHierarchyListener(HierarchyListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5336
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5337
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5338
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5339
        boolean notifyAncestors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5340
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5341
            notifyAncestors =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5342
                (hierarchyListener == null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5343
                 (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5344
            hierarchyListener = AWTEventMulticaster.add(hierarchyListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5345
            notifyAncestors = (notifyAncestors && hierarchyListener != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5346
            newEventsOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5347
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5348
        if (notifyAncestors) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5349
            synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5350
                adjustListeningChildrenOnParent(AWTEvent.HIERARCHY_EVENT_MASK,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5351
                                                1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5352
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5353
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5354
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5355
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5356
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5357
     * Removes the specified hierarchy listener so that it no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5358
     * receives hierarchy changed events from this component. This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5359
     * performs no function, nor does it throw an exception, if the listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5360
     * specified by the argument was not previously added to this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5361
     * If listener <code>l</code> is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5362
     * no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5363
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5364
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5365
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5366
     * @param    l   the hierarchy listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5367
     * @see      java.awt.event.HierarchyEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5368
     * @see      java.awt.event.HierarchyListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5369
     * @see      #addHierarchyListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5370
     * @see      #getHierarchyListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5371
     * @since    1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5372
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5373
    public void removeHierarchyListener(HierarchyListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5374
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5375
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5376
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5377
        boolean notifyAncestors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5378
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5379
            notifyAncestors =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5380
                (hierarchyListener != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5381
                 (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5382
            hierarchyListener =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5383
                AWTEventMulticaster.remove(hierarchyListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5384
            notifyAncestors = (notifyAncestors && hierarchyListener == null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5385
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5386
        if (notifyAncestors) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5387
            synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5388
                adjustListeningChildrenOnParent(AWTEvent.HIERARCHY_EVENT_MASK,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5389
                                                -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5390
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5391
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5392
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5393
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5394
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5395
     * Returns an array of all the hierarchy listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5396
     * registered on this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5397
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5398
     * @return all of this component's <code>HierarchyListener</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5399
     *         or an empty array if no hierarchy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5400
     *         listeners are currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5401
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5402
     * @see      #addHierarchyListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5403
     * @see      #removeHierarchyListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5404
     * @since    1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5405
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5406
    public synchronized HierarchyListener[] getHierarchyListeners() {
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  5407
        return getListeners(HierarchyListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5408
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5409
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5410
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5411
     * Adds the specified hierarchy bounds listener to receive hierarchy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5412
     * bounds events from this component when the hierarchy to which this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5413
     * container belongs changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5414
     * If listener <code>l</code> is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5415
     * no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5416
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5417
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5418
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5419
     * @param    l   the hierarchy bounds listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5420
     * @see      java.awt.event.HierarchyEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5421
     * @see      java.awt.event.HierarchyBoundsListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5422
     * @see      #removeHierarchyBoundsListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5423
     * @see      #getHierarchyBoundsListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5424
     * @since    1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5425
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5426
    public void addHierarchyBoundsListener(HierarchyBoundsListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5427
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5428
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5429
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5430
        boolean notifyAncestors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5431
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5432
            notifyAncestors =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5433
                (hierarchyBoundsListener == null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5434
                 (eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5435
            hierarchyBoundsListener =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5436
                AWTEventMulticaster.add(hierarchyBoundsListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5437
            notifyAncestors = (notifyAncestors &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5438
                               hierarchyBoundsListener != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5439
            newEventsOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5440
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5441
        if (notifyAncestors) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5442
            synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5443
                adjustListeningChildrenOnParent(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5444
                                                AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5445
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5446
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5447
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5448
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5449
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5450
     * Removes the specified hierarchy bounds listener so that it no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5451
     * receives hierarchy bounds events from this component. This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5452
     * performs no function, nor does it throw an exception, if the listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5453
     * specified by the argument was not previously added to this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5454
     * If listener <code>l</code> is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5455
     * no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5456
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5457
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5458
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5459
     * @param    l   the hierarchy bounds listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5460
     * @see      java.awt.event.HierarchyEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5461
     * @see      java.awt.event.HierarchyBoundsListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5462
     * @see      #addHierarchyBoundsListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5463
     * @see      #getHierarchyBoundsListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5464
     * @since    1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5465
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5466
    public void removeHierarchyBoundsListener(HierarchyBoundsListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5467
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5468
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5469
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5470
        boolean notifyAncestors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5471
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5472
            notifyAncestors =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5473
                (hierarchyBoundsListener != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5474
                 (eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5475
            hierarchyBoundsListener =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5476
                AWTEventMulticaster.remove(hierarchyBoundsListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5477
            notifyAncestors = (notifyAncestors &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5478
                               hierarchyBoundsListener == null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5479
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5480
        if (notifyAncestors) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5481
            synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5482
                adjustListeningChildrenOnParent(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5483
                                                AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5484
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5485
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5486
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5487
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5488
    // Should only be called while holding the tree lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5489
    int numListening(long mask) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5490
        // One mask or the other, but not neither or both.
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  5491
        if (eventLog.isLoggable(PlatformLogger.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5492
            if ((mask != AWTEvent.HIERARCHY_EVENT_MASK) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5493
                (mask != AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5494
            {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  5495
                eventLog.fine("Assertion failed");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5496
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5497
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5498
        if ((mask == AWTEvent.HIERARCHY_EVENT_MASK &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5499
             (hierarchyListener != null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5500
              (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0)) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5501
            (mask == AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5502
             (hierarchyBoundsListener != null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5503
              (eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5504
            return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5505
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5506
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5507
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5508
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5509
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5510
    // Should only be called while holding tree lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5511
    int countHierarchyMembers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5512
        return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5513
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5514
    // Should only be called while holding the tree lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5515
    int createHierarchyEvents(int id, Component changed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5516
                              Container changedParent, long changeFlags,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5517
                              boolean enabledOnToolkit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5518
        switch (id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5519
          case HierarchyEvent.HIERARCHY_CHANGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5520
              if (hierarchyListener != null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5521
                  (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5522
                  enabledOnToolkit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5523
                  HierarchyEvent e = new HierarchyEvent(this, id, changed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5524
                                                        changedParent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5525
                                                        changeFlags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5526
                  dispatchEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5527
                  return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5528
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5529
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5530
          case HierarchyEvent.ANCESTOR_MOVED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5531
          case HierarchyEvent.ANCESTOR_RESIZED:
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  5532
              if (eventLog.isLoggable(PlatformLogger.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5533
                  if (changeFlags != 0) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  5534
                      eventLog.fine("Assertion (changeFlags == 0) failed");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5535
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5536
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5537
              if (hierarchyBoundsListener != null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5538
                  (eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5539
                  enabledOnToolkit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5540
                  HierarchyEvent e = new HierarchyEvent(this, id, changed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5541
                                                        changedParent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5542
                  dispatchEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5543
                  return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5544
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5545
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5546
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5547
              // assert false
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  5548
              if (eventLog.isLoggable(PlatformLogger.FINE)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  5549
                  eventLog.fine("This code must never be reached");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5550
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5551
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5552
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5553
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5554
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5555
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5556
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5557
     * Returns an array of all the hierarchy bounds listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5558
     * registered on this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5559
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5560
     * @return all of this component's <code>HierarchyBoundsListener</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5561
     *         or an empty array if no hierarchy bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5562
     *         listeners are currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5563
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5564
     * @see      #addHierarchyBoundsListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5565
     * @see      #removeHierarchyBoundsListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5566
     * @since    1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5567
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5568
    public synchronized HierarchyBoundsListener[] getHierarchyBoundsListeners() {
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  5569
        return getListeners(HierarchyBoundsListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5570
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5571
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5572
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5573
     * Should only be called while holding the tree lock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5574
     * It's added only for overriding in java.awt.Window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5575
     * because parent in Window is owner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5576
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5577
    void adjustListeningChildrenOnParent(long mask, int num) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5578
        if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5579
            parent.adjustListeningChildren(mask, num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5580
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5581
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5582
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5583
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5584
     * Adds the specified key listener to receive key events from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5585
     * this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5586
     * If l is null, no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5587
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5588
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5589
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5590
     * @param    l   the key listener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5591
     * @see      java.awt.event.KeyEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5592
     * @see      java.awt.event.KeyListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5593
     * @see      #removeKeyListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5594
     * @see      #getKeyListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5595
     * @since    JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5596
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5597
    public synchronized void addKeyListener(KeyListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5598
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5599
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5600
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5601
        keyListener = AWTEventMulticaster.add(keyListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5602
        newEventsOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5603
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5604
        // if this is a lightweight component, enable key events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5605
        // in the native container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5606
        if (peer instanceof LightweightPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5607
            parent.proxyEnableEvents(AWTEvent.KEY_EVENT_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5608
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5609
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5610
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5611
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5612
     * Removes the specified key listener so that it no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5613
     * receives key events from this component. This method performs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5614
     * no function, nor does it throw an exception, if the listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5615
     * specified by the argument was not previously added to this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5616
     * If listener <code>l</code> is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5617
     * no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5618
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5619
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5620
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5621
     * @param    l   the key listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5622
     * @see      java.awt.event.KeyEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5623
     * @see      java.awt.event.KeyListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5624
     * @see      #addKeyListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5625
     * @see      #getKeyListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5626
     * @since    JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5627
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5628
    public synchronized void removeKeyListener(KeyListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5629
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5630
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5631
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5632
        keyListener = AWTEventMulticaster.remove(keyListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5633
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5634
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5635
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5636
     * Returns an array of all the key listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5637
     * registered on this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5638
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5639
     * @return all of this component's <code>KeyListener</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5640
     *         or an empty array if no key
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5641
     *         listeners are currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5642
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5643
     * @see      #addKeyListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5644
     * @see      #removeKeyListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5645
     * @since    1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5646
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5647
    public synchronized KeyListener[] getKeyListeners() {
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  5648
        return getListeners(KeyListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5649
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5650
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5651
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5652
     * Adds the specified mouse listener to receive mouse events from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5653
     * this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5654
     * If listener <code>l</code> is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5655
     * no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5656
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5657
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5658
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5659
     * @param    l   the mouse listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5660
     * @see      java.awt.event.MouseEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5661
     * @see      java.awt.event.MouseListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5662
     * @see      #removeMouseListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5663
     * @see      #getMouseListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5664
     * @since    JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5665
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5666
    public synchronized void addMouseListener(MouseListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5667
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5668
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5669
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5670
        mouseListener = AWTEventMulticaster.add(mouseListener,l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5671
        newEventsOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5672
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5673
        // if this is a lightweight component, enable mouse events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5674
        // in the native container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5675
        if (peer instanceof LightweightPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5676
            parent.proxyEnableEvents(AWTEvent.MOUSE_EVENT_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5677
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5678
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5679
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5680
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5681
     * Removes the specified mouse listener so that it no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5682
     * receives mouse events from this component. This method performs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5683
     * no function, nor does it throw an exception, if the listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5684
     * specified by the argument was not previously added to this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5685
     * If listener <code>l</code> is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5686
     * no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5687
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5688
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5689
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5690
     * @param    l   the mouse listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5691
     * @see      java.awt.event.MouseEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5692
     * @see      java.awt.event.MouseListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5693
     * @see      #addMouseListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5694
     * @see      #getMouseListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5695
     * @since    JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5696
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5697
    public synchronized void removeMouseListener(MouseListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5698
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5699
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5700
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5701
        mouseListener = AWTEventMulticaster.remove(mouseListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5702
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5703
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5704
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5705
     * Returns an array of all the mouse listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5706
     * registered on this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5707
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5708
     * @return all of this component's <code>MouseListener</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5709
     *         or an empty array if no mouse
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5710
     *         listeners are currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5711
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5712
     * @see      #addMouseListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5713
     * @see      #removeMouseListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5714
     * @since    1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5715
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5716
    public synchronized MouseListener[] getMouseListeners() {
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  5717
        return getListeners(MouseListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5718
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5719
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5720
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5721
     * Adds the specified mouse motion listener to receive mouse motion
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5722
     * events from this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5723
     * If listener <code>l</code> is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5724
     * no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5725
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5726
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5727
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5728
     * @param    l   the mouse motion listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5729
     * @see      java.awt.event.MouseEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5730
     * @see      java.awt.event.MouseMotionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5731
     * @see      #removeMouseMotionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5732
     * @see      #getMouseMotionListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5733
     * @since    JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5734
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5735
    public synchronized void addMouseMotionListener(MouseMotionListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5736
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5737
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5738
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5739
        mouseMotionListener = AWTEventMulticaster.add(mouseMotionListener,l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5740
        newEventsOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5741
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5742
        // if this is a lightweight component, enable mouse events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5743
        // in the native container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5744
        if (peer instanceof LightweightPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5745
            parent.proxyEnableEvents(AWTEvent.MOUSE_MOTION_EVENT_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5746
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5747
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5748
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5749
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5750
     * Removes the specified mouse motion listener so that it no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5751
     * receives mouse motion events from this component. This method performs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5752
     * no function, nor does it throw an exception, if the listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5753
     * specified by the argument was not previously added to this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5754
     * If listener <code>l</code> is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5755
     * no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5756
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5757
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5758
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5759
     * @param    l   the mouse motion listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5760
     * @see      java.awt.event.MouseEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5761
     * @see      java.awt.event.MouseMotionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5762
     * @see      #addMouseMotionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5763
     * @see      #getMouseMotionListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5764
     * @since    JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5765
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5766
    public synchronized void removeMouseMotionListener(MouseMotionListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5767
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5768
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5769
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5770
        mouseMotionListener = AWTEventMulticaster.remove(mouseMotionListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5771
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5772
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5773
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5774
     * Returns an array of all the mouse motion listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5775
     * registered on this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5776
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5777
     * @return all of this component's <code>MouseMotionListener</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5778
     *         or an empty array if no mouse motion
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5779
     *         listeners are currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5780
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5781
     * @see      #addMouseMotionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5782
     * @see      #removeMouseMotionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5783
     * @since    1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5784
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5785
    public synchronized MouseMotionListener[] getMouseMotionListeners() {
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  5786
        return getListeners(MouseMotionListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5787
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5788
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5789
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5790
     * Adds the specified mouse wheel listener to receive mouse wheel events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5791
     * from this component.  Containers also receive mouse wheel events from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5792
     * sub-components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5793
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5794
     * For information on how mouse wheel events are dispatched, see
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5795
     * the class description for {@link MouseWheelEvent}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5796
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5797
     * If l is <code>null</code>, no exception is thrown and no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5798
     * action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5799
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5800
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5801
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5802
     * @param    l   the mouse wheel listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5803
     * @see      java.awt.event.MouseWheelEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5804
     * @see      java.awt.event.MouseWheelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5805
     * @see      #removeMouseWheelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5806
     * @see      #getMouseWheelListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5807
     * @since    1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5808
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5809
    public synchronized void addMouseWheelListener(MouseWheelListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5810
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5811
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5812
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5813
        mouseWheelListener = AWTEventMulticaster.add(mouseWheelListener,l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5814
        newEventsOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5815
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5816
        // if this is a lightweight component, enable mouse events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5817
        // in the native container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5818
        if (peer instanceof LightweightPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5819
            parent.proxyEnableEvents(AWTEvent.MOUSE_WHEEL_EVENT_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5820
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5821
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5822
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5823
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5824
     * Removes the specified mouse wheel listener so that it no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5825
     * receives mouse wheel events from this component. This method performs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5826
     * no function, nor does it throw an exception, if the listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5827
     * specified by the argument was not previously added to this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5828
     * If l is null, no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5829
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5830
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5831
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5832
     * @param    l   the mouse wheel listener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5833
     * @see      java.awt.event.MouseWheelEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5834
     * @see      java.awt.event.MouseWheelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5835
     * @see      #addMouseWheelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5836
     * @see      #getMouseWheelListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5837
     * @since    1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5838
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5839
    public synchronized void removeMouseWheelListener(MouseWheelListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5840
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5841
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5842
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5843
        mouseWheelListener = AWTEventMulticaster.remove(mouseWheelListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5844
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5845
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5846
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5847
     * Returns an array of all the mouse wheel listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5848
     * registered on this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5849
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5850
     * @return all of this component's <code>MouseWheelListener</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5851
     *         or an empty array if no mouse wheel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5852
     *         listeners are currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5853
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5854
     * @see      #addMouseWheelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5855
     * @see      #removeMouseWheelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5856
     * @since    1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5857
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5858
    public synchronized MouseWheelListener[] getMouseWheelListeners() {
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  5859
        return getListeners(MouseWheelListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5860
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5861
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5862
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5863
     * Adds the specified input method listener to receive
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5864
     * input method events from this component. A component will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5865
     * only receive input method events from input methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5866
     * if it also overrides <code>getInputMethodRequests</code> to return an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5867
     * <code>InputMethodRequests</code> instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5868
     * If listener <code>l</code> is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5869
     * no exception is thrown and no action is performed.
8982
19c972e3d3ee 7009422: Two dead links in Swing API documentation
rupashka
parents: 7668
diff changeset
  5870
     * <p>Refer to <a href="{@docRoot}/java/awt/doc-files/AWTThreadIssues.html#ListenersThreads"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5871
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5872
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5873
     * @param    l   the input method listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5874
     * @see      java.awt.event.InputMethodEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5875
     * @see      java.awt.event.InputMethodListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5876
     * @see      #removeInputMethodListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5877
     * @see      #getInputMethodListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5878
     * @see      #getInputMethodRequests
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5879
     * @since    1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5880
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5881
    public synchronized void addInputMethodListener(InputMethodListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5882
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5883
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5884
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5885
        inputMethodListener = AWTEventMulticaster.add(inputMethodListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5886
        newEventsOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5887
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5888
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5889
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5890
     * Removes the specified input method listener so that it no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5891
     * receives input method events from this component. This method performs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5892
     * no function, nor does it throw an exception, if the listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5893
     * specified by the argument was not previously added to this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5894
     * If listener <code>l</code> is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5895
     * no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5896
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5897
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5898
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5899
     * @param    l   the input method listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5900
     * @see      java.awt.event.InputMethodEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5901
     * @see      java.awt.event.InputMethodListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5902
     * @see      #addInputMethodListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5903
     * @see      #getInputMethodListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5904
     * @since    1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5905
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5906
    public synchronized void removeInputMethodListener(InputMethodListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5907
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5908
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5909
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5910
        inputMethodListener = AWTEventMulticaster.remove(inputMethodListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5911
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5912
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5913
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5914
     * Returns an array of all the input method listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5915
     * registered on this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5916
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5917
     * @return all of this component's <code>InputMethodListener</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5918
     *         or an empty array if no input method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5919
     *         listeners are currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5920
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5921
     * @see      #addInputMethodListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5922
     * @see      #removeInputMethodListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5923
     * @since    1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5924
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5925
    public synchronized InputMethodListener[] getInputMethodListeners() {
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  5926
        return getListeners(InputMethodListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5927
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5928
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5929
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5930
     * Returns an array of all the objects currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5931
     * as <code><em>Foo</em>Listener</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5932
     * upon this <code>Component</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5933
     * <code><em>Foo</em>Listener</code>s are registered using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5934
     * <code>add<em>Foo</em>Listener</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5935
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5936
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5937
     * You can specify the <code>listenerType</code> argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5938
     * with a class literal, such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5939
     * <code><em>Foo</em>Listener.class</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5940
     * For example, you can query a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5941
     * <code>Component</code> <code>c</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5942
     * for its mouse listeners with the following code:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5943
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5944
     * <pre>MouseListener[] mls = (MouseListener[])(c.getListeners(MouseListener.class));</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5945
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5946
     * If no such listeners exist, this method returns an empty array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5947
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5948
     * @param listenerType the type of listeners requested; this parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5949
     *          should specify an interface that descends from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5950
     *          <code>java.util.EventListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5951
     * @return an array of all objects registered as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5952
     *          <code><em>Foo</em>Listener</code>s on this component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5953
     *          or an empty array if no such listeners have been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5954
     * @exception ClassCastException if <code>listenerType</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5955
     *          doesn't specify a class or interface that implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5956
     *          <code>java.util.EventListener</code>
7154
4e8371f358ac 6877895: Some AWT's methods should specify throwing NPE for null arg value
dcherepanov
parents: 5506
diff changeset
  5957
     * @throws NullPointerException if {@code listenerType} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5958
     * @see #getComponentListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5959
     * @see #getFocusListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5960
     * @see #getHierarchyListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5961
     * @see #getHierarchyBoundsListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5962
     * @see #getKeyListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5963
     * @see #getMouseListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5964
     * @see #getMouseMotionListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5965
     * @see #getMouseWheelListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5966
     * @see #getInputMethodListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5967
     * @see #getPropertyChangeListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5968
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5969
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5970
     */
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  5971
    @SuppressWarnings("unchecked")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5972
    public <T extends EventListener> T[] getListeners(Class<T> listenerType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5973
        EventListener l = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5974
        if  (listenerType == ComponentListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5975
            l = componentListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5976
        } else if (listenerType == FocusListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5977
            l = focusListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5978
        } else if (listenerType == HierarchyListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5979
            l = hierarchyListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5980
        } else if (listenerType == HierarchyBoundsListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5981
            l = hierarchyBoundsListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5982
        } else if (listenerType == KeyListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5983
            l = keyListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5984
        } else if (listenerType == MouseListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5985
            l = mouseListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5986
        } else if (listenerType == MouseMotionListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5987
            l = mouseMotionListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5988
        } else if (listenerType == MouseWheelListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5989
            l = mouseWheelListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5990
        } else if (listenerType == InputMethodListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5991
            l = inputMethodListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5992
        } else if (listenerType == PropertyChangeListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5993
            return (T[])getPropertyChangeListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5994
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5995
        return AWTEventMulticaster.getListeners(l, listenerType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5996
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5997
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5998
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5999
     * Gets the input method request handler which supports
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6000
     * requests from input methods for this component. A component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6001
     * that supports on-the-spot text input must override this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6002
     * method to return an <code>InputMethodRequests</code> instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6003
     * At the same time, it also has to handle input method events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6004
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6005
     * @return the input method request handler for this component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6006
     *          <code>null</code> by default
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6007
     * @see #addInputMethodListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6008
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6009
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6010
    public InputMethodRequests getInputMethodRequests() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6011
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6012
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6013
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6014
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6015
     * Gets the input context used by this component for handling
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6016
     * the communication with input methods when text is entered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6017
     * in this component. By default, the input context used for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6018
     * the parent component is returned. Components may
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6019
     * override this to return a private input context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6020
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6021
     * @return the input context used by this component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6022
     *          <code>null</code> if no context can be determined
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6023
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6024
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6025
    public InputContext getInputContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6026
        Container parent = this.parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6027
        if (parent == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6028
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6029
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6030
            return parent.getInputContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6031
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6032
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6033
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6034
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6035
     * Enables the events defined by the specified event mask parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6036
     * to be delivered to this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6037
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6038
     * Event types are automatically enabled when a listener for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6039
     * that event type is added to the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6040
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6041
     * This method only needs to be invoked by subclasses of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6042
     * <code>Component</code> which desire to have the specified event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6043
     * types delivered to <code>processEvent</code> regardless of whether
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6044
     * or not a listener is registered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6045
     * @param      eventsToEnable   the event mask defining the event types
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6046
     * @see        #processEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6047
     * @see        #disableEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6048
     * @see        AWTEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6049
     * @since      JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6050
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6051
    protected final void enableEvents(long eventsToEnable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6052
        long notifyAncestors = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6053
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6054
            if ((eventsToEnable & AWTEvent.HIERARCHY_EVENT_MASK) != 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6055
                hierarchyListener == null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6056
                (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6057
                notifyAncestors |= AWTEvent.HIERARCHY_EVENT_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6058
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6059
            if ((eventsToEnable & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6060
                hierarchyBoundsListener == null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6061
                (eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6062
                notifyAncestors |= AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6063
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6064
            eventMask |= eventsToEnable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6065
            newEventsOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6066
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6067
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6068
        // if this is a lightweight component, enable mouse events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6069
        // in the native container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6070
        if (peer instanceof LightweightPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6071
            parent.proxyEnableEvents(eventMask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6072
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6073
        if (notifyAncestors != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6074
            synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6075
                adjustListeningChildrenOnParent(notifyAncestors, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6076
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6077
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6078
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6079
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6080
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6081
     * Disables the events defined by the specified event mask parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6082
     * from being delivered to this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6083
     * @param      eventsToDisable   the event mask defining the event types
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6084
     * @see        #enableEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6085
     * @since      JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6086
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6087
    protected final void disableEvents(long eventsToDisable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6088
        long notifyAncestors = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6089
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6090
            if ((eventsToDisable & AWTEvent.HIERARCHY_EVENT_MASK) != 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6091
                hierarchyListener == null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6092
                (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6093
                notifyAncestors |= AWTEvent.HIERARCHY_EVENT_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6094
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6095
            if ((eventsToDisable & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK)!=0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6096
                hierarchyBoundsListener == null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6097
                (eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6098
                notifyAncestors |= AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6099
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6100
            eventMask &= ~eventsToDisable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6102
        if (notifyAncestors != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6103
            synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6104
                adjustListeningChildrenOnParent(notifyAncestors, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6105
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6106
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6108
1181
c5971dbeaaaa 6693974: Unify EventQueue$EventQueueItem and SunToolkit.$EventQueueItem classes
dav
parents: 1172
diff changeset
  6109
    transient sun.awt.EventQueueItem[] eventCache;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6110
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6111
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6112
     * @see #isCoalescingEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6113
     * @see #checkCoalescing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6115
    transient private boolean coalescingEnabled = checkCoalescing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6116
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6118
     * Weak map of known coalesceEvent overriders.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6119
     * Value indicates whether overriden.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6120
     * Bootstrap classes are not included.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6121
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6122
    private static final Map<Class<?>, Boolean> coalesceMap =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6123
        new java.util.WeakHashMap<Class<?>, Boolean>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6124
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6125
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6126
     * Indicates whether this class overrides coalesceEvents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6127
     * It is assumed that all classes that are loaded from the bootstrap
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6128
     *   do not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6129
     * The boostrap class loader is assumed to be represented by null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6130
     * We do not check that the method really overrides
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6131
     *   (it might be static, private or package private).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6132
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6133
     private boolean checkCoalescing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6134
         if (getClass().getClassLoader()==null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6135
             return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6136
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6137
         final Class<? extends Component> clazz = getClass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6138
         synchronized (coalesceMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6139
             // Check cache.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6140
             Boolean value = coalesceMap.get(clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6141
             if (value != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6142
                 return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6143
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6144
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6145
             // Need to check non-bootstraps.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6146
             Boolean enabled = java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6147
                 new java.security.PrivilegedAction<Boolean>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6148
                     public Boolean run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6149
                         return isCoalesceEventsOverriden(clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6150
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6151
                 }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6152
                 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6153
             coalesceMap.put(clazz, enabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6154
             return enabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6155
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6156
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6157
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6158
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6159
     * Parameter types of coalesceEvents(AWTEvent,AWTEVent).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6160
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6161
    private static final Class[] coalesceEventsParams = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6162
        AWTEvent.class, AWTEvent.class
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6163
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6164
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6165
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6166
     * Indicates whether a class or its superclasses override coalesceEvents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6167
     * Must be called with lock on coalesceMap and privileged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6168
     * @see checkCoalsecing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6169
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6170
    private static boolean isCoalesceEventsOverriden(Class<?> clazz) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6171
        assert Thread.holdsLock(coalesceMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6172
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6173
        // First check superclass - we may not need to bother ourselves.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6174
        Class<?> superclass = clazz.getSuperclass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6175
        if (superclass == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6176
            // Only occurs on implementations that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6177
            //   do not use null to represent the bootsrap class loader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6178
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6180
        if (superclass.getClassLoader() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6181
            Boolean value = coalesceMap.get(superclass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6182
            if (value == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6183
                // Not done already - recurse.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6184
                if (isCoalesceEventsOverriden(superclass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6185
                    coalesceMap.put(superclass, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6186
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6187
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6188
            } else if (value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6189
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6190
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6192
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6193
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6194
            // Throws if not overriden.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6195
            clazz.getDeclaredMethod(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6196
                "coalesceEvents", coalesceEventsParams
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6197
                );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6198
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6199
        } catch (NoSuchMethodException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6200
            // Not present in this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6201
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6202
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6204
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6205
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6206
     * Indicates whether coalesceEvents may do something.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6207
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6208
    final boolean isCoalescingEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6209
        return coalescingEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6210
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6211
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6212
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6213
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6214
     * Potentially coalesce an event being posted with an existing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6215
     * event.  This method is called by <code>EventQueue.postEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6216
     * if an event with the same ID as the event to be posted is found in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6217
     * the queue (both events must have this component as their source).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6218
     * This method either returns a coalesced event which replaces
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6219
     * the existing event (and the new event is then discarded), or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6220
     * <code>null</code> to indicate that no combining should be done
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6221
     * (add the second event to the end of the queue).  Either event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6222
     * parameter may be modified and returned, as the other one is discarded
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6223
     * unless <code>null</code> is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6224
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6225
     * This implementation of <code>coalesceEvents</code> coalesces
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6226
     * two event types: mouse move (and drag) events,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6227
     * and paint (and update) events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6228
     * For mouse move events the last event is always returned, causing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6229
     * intermediate moves to be discarded.  For paint events, the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6230
     * event is coalesced into a complex <code>RepaintArea</code> in the peer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6231
     * The new <code>AWTEvent</code> is always returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6232
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6233
     * @param  existingEvent  the event already on the <code>EventQueue</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6234
     * @param  newEvent       the event being posted to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6235
     *          <code>EventQueue</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6236
     * @return a coalesced event, or <code>null</code> indicating that no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6237
     *          coalescing was done
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6238
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6239
    protected AWTEvent coalesceEvents(AWTEvent existingEvent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6240
                                      AWTEvent newEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6241
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6242
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6243
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6244
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6245
     * Processes events occurring on this component. By default this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6246
     * method calls the appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6247
     * <code>process&lt;event&nbsp;type&gt;Event</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6248
     * method for the given class of event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6249
     * <p>Note that if the event parameter is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6250
     * the behavior is unspecified and may result in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6251
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6252
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6253
     * @param     e the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6254
     * @see       #processComponentEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6255
     * @see       #processFocusEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6256
     * @see       #processKeyEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6257
     * @see       #processMouseEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6258
     * @see       #processMouseMotionEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6259
     * @see       #processInputMethodEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6260
     * @see       #processHierarchyEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6261
     * @see       #processMouseWheelEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6262
     * @since     JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6263
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6264
    protected void processEvent(AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6265
        if (e instanceof FocusEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6266
            processFocusEvent((FocusEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6267
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6268
        } else if (e instanceof MouseEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6269
            switch(e.getID()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6270
              case MouseEvent.MOUSE_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6271
              case MouseEvent.MOUSE_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6272
              case MouseEvent.MOUSE_CLICKED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6273
              case MouseEvent.MOUSE_ENTERED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6274
              case MouseEvent.MOUSE_EXITED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6275
                  processMouseEvent((MouseEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6276
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6277
              case MouseEvent.MOUSE_MOVED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6278
              case MouseEvent.MOUSE_DRAGGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6279
                  processMouseMotionEvent((MouseEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6280
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6281
              case MouseEvent.MOUSE_WHEEL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6282
                  processMouseWheelEvent((MouseWheelEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6283
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6284
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6285
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6286
        } else if (e instanceof KeyEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6287
            processKeyEvent((KeyEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6288
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6289
        } else if (e instanceof ComponentEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6290
            processComponentEvent((ComponentEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6291
        } else if (e instanceof InputMethodEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6292
            processInputMethodEvent((InputMethodEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6293
        } else if (e instanceof HierarchyEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6294
            switch (e.getID()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6295
              case HierarchyEvent.HIERARCHY_CHANGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6296
                  processHierarchyEvent((HierarchyEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6297
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6298
              case HierarchyEvent.ANCESTOR_MOVED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6299
              case HierarchyEvent.ANCESTOR_RESIZED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6300
                  processHierarchyBoundsEvent((HierarchyEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6301
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6302
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6303
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6304
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6305
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6306
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6307
     * Processes component events occurring on this component by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6308
     * dispatching them to any registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6309
     * <code>ComponentListener</code> objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6310
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6311
     * This method is not called unless component events are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6312
     * enabled for this component. Component events are enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6313
     * when one of the following occurs:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6314
     * <p><ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6315
     * <li>A <code>ComponentListener</code> object is registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6316
     * via <code>addComponentListener</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6317
     * <li>Component events are enabled via <code>enableEvents</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6318
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6319
     * <p>Note that if the event parameter is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6320
     * the behavior is unspecified and may result in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6321
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6322
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6323
     * @param       e the component event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6324
     * @see         java.awt.event.ComponentEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6325
     * @see         java.awt.event.ComponentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6326
     * @see         #addComponentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6327
     * @see         #enableEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6328
     * @since       JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6329
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6330
    protected void processComponentEvent(ComponentEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6331
        ComponentListener listener = componentListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6332
        if (listener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6333
            int id = e.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6334
            switch(id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6335
              case ComponentEvent.COMPONENT_RESIZED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6336
                  listener.componentResized(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6337
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6338
              case ComponentEvent.COMPONENT_MOVED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6339
                  listener.componentMoved(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6340
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6341
              case ComponentEvent.COMPONENT_SHOWN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6342
                  listener.componentShown(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6343
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6344
              case ComponentEvent.COMPONENT_HIDDEN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6345
                  listener.componentHidden(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6346
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6347
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6348
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6349
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6350
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6351
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6352
     * Processes focus events occurring on this component by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6353
     * dispatching them to any registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6354
     * <code>FocusListener</code> objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6355
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6356
     * This method is not called unless focus events are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6357
     * enabled for this component. Focus events are enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6358
     * when one of the following occurs:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6359
     * <p><ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6360
     * <li>A <code>FocusListener</code> object is registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6361
     * via <code>addFocusListener</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6362
     * <li>Focus events are enabled via <code>enableEvents</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6363
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6364
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6365
     * If focus events are enabled for a <code>Component</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6366
     * the current <code>KeyboardFocusManager</code> determines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6367
     * whether or not a focus event should be dispatched to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6368
     * registered <code>FocusListener</code> objects.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6369
     * events are to be dispatched, the <code>KeyboardFocusManager</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6370
     * calls the <code>Component</code>'s <code>dispatchEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6371
     * method, which results in a call to the <code>Component</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6372
     * <code>processFocusEvent</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6373
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6374
     * If focus events are enabled for a <code>Component</code>, calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6375
     * the <code>Component</code>'s <code>dispatchEvent</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6376
     * with a <code>FocusEvent</code> as the argument will result in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6377
     * call to the <code>Component</code>'s <code>processFocusEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6378
     * method regardless of the current <code>KeyboardFocusManager</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6379
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6380
     * <p>Note that if the event parameter is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6381
     * the behavior is unspecified and may result in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6382
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6383
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6384
     * @param       e the focus event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6385
     * @see         java.awt.event.FocusEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6386
     * @see         java.awt.event.FocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6387
     * @see         java.awt.KeyboardFocusManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6388
     * @see         #addFocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6389
     * @see         #enableEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6390
     * @see         #dispatchEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6391
     * @since       JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6392
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6393
    protected void processFocusEvent(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6394
        FocusListener listener = focusListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6395
        if (listener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6396
            int id = e.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6397
            switch(id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6398
              case FocusEvent.FOCUS_GAINED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6399
                  listener.focusGained(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6400
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6401
              case FocusEvent.FOCUS_LOST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6402
                  listener.focusLost(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6403
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6404
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6405
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6406
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6407
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6408
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6409
     * Processes key events occurring on this component by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6410
     * dispatching them to any registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6411
     * <code>KeyListener</code> objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6412
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6413
     * This method is not called unless key events are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6414
     * enabled for this component. Key events are enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6415
     * when one of the following occurs:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6416
     * <p><ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6417
     * <li>A <code>KeyListener</code> object is registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6418
     * via <code>addKeyListener</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6419
     * <li>Key events are enabled via <code>enableEvents</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6420
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6421
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6422
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6423
     * If key events are enabled for a <code>Component</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6424
     * the current <code>KeyboardFocusManager</code> determines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6425
     * whether or not a key event should be dispatched to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6426
     * registered <code>KeyListener</code> objects.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6427
     * <code>DefaultKeyboardFocusManager</code> will not dispatch
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6428
     * key events to a <code>Component</code> that is not the focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6429
     * owner or is not showing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6430
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6431
     * As of J2SE 1.4, <code>KeyEvent</code>s are redirected to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6432
     * the focus owner. Please see the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6433
     * <a href="doc-files/FocusSpec.html">Focus Specification</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6434
     * for further information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6435
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6436
     * Calling a <code>Component</code>'s <code>dispatchEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6437
     * method with a <code>KeyEvent</code> as the argument will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6438
     * result in a call to the <code>Component</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6439
     * <code>processKeyEvent</code> method regardless of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6440
     * current <code>KeyboardFocusManager</code> as long as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6441
     * component is showing, focused, and enabled, and key events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6442
     * are enabled on it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6443
     * <p>If the event parameter is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6444
     * the behavior is unspecified and may result in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6445
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6446
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6447
     * @param       e the key event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6448
     * @see         java.awt.event.KeyEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6449
     * @see         java.awt.event.KeyListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6450
     * @see         java.awt.KeyboardFocusManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6451
     * @see         java.awt.DefaultKeyboardFocusManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6452
     * @see         #processEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6453
     * @see         #dispatchEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6454
     * @see         #addKeyListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6455
     * @see         #enableEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6456
     * @see         #isShowing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6457
     * @since       JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6458
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6459
    protected void processKeyEvent(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6460
        KeyListener listener = keyListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6461
        if (listener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6462
            int id = e.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6463
            switch(id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6464
              case KeyEvent.KEY_TYPED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6465
                  listener.keyTyped(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6466
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6467
              case KeyEvent.KEY_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6468
                  listener.keyPressed(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6469
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6470
              case KeyEvent.KEY_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6471
                  listener.keyReleased(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6472
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6473
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6474
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6475
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6476
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6477
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6478
     * Processes mouse events occurring on this component by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6479
     * dispatching them to any registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6480
     * <code>MouseListener</code> objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6481
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6482
     * This method is not called unless mouse events are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6483
     * enabled for this component. Mouse events are enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6484
     * when one of the following occurs:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6485
     * <p><ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6486
     * <li>A <code>MouseListener</code> object is registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6487
     * via <code>addMouseListener</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6488
     * <li>Mouse events are enabled via <code>enableEvents</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6489
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6490
     * <p>Note that if the event parameter is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6491
     * the behavior is unspecified and may result in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6492
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6493
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6494
     * @param       e the mouse event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6495
     * @see         java.awt.event.MouseEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6496
     * @see         java.awt.event.MouseListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6497
     * @see         #addMouseListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6498
     * @see         #enableEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6499
     * @since       JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6500
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6501
    protected void processMouseEvent(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6502
        MouseListener listener = mouseListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6503
        if (listener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6504
            int id = e.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6505
            switch(id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6506
              case MouseEvent.MOUSE_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6507
                  listener.mousePressed(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6508
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6509
              case MouseEvent.MOUSE_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6510
                  listener.mouseReleased(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6511
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6512
              case MouseEvent.MOUSE_CLICKED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6513
                  listener.mouseClicked(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6514
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6515
              case MouseEvent.MOUSE_EXITED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6516
                  listener.mouseExited(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6517
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6518
              case MouseEvent.MOUSE_ENTERED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6519
                  listener.mouseEntered(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6520
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6521
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6522
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6523
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6524
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6525
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6526
     * Processes mouse motion events occurring on this component by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6527
     * dispatching them to any registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6528
     * <code>MouseMotionListener</code> objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6529
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6530
     * This method is not called unless mouse motion events are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6531
     * enabled for this component. Mouse motion events are enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6532
     * when one of the following occurs:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6533
     * <p><ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6534
     * <li>A <code>MouseMotionListener</code> object is registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6535
     * via <code>addMouseMotionListener</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6536
     * <li>Mouse motion events are enabled via <code>enableEvents</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6537
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6538
     * <p>Note that if the event parameter is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6539
     * the behavior is unspecified and may result in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6540
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6541
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6542
     * @param       e the mouse motion event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6543
     * @see         java.awt.event.MouseEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6544
     * @see         java.awt.event.MouseMotionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6545
     * @see         #addMouseMotionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6546
     * @see         #enableEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6547
     * @since       JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6548
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6549
    protected void processMouseMotionEvent(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6550
        MouseMotionListener listener = mouseMotionListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6551
        if (listener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6552
            int id = e.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6553
            switch(id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6554
              case MouseEvent.MOUSE_MOVED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6555
                  listener.mouseMoved(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6556
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6557
              case MouseEvent.MOUSE_DRAGGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6558
                  listener.mouseDragged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6559
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6560
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6561
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6562
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6563
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6564
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6565
     * Processes mouse wheel events occurring on this component by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6566
     * dispatching them to any registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6567
     * <code>MouseWheelListener</code> objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6568
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6569
     * This method is not called unless mouse wheel events are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6570
     * enabled for this component. Mouse wheel events are enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6571
     * when one of the following occurs:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6572
     * <p><ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6573
     * <li>A <code>MouseWheelListener</code> object is registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6574
     * via <code>addMouseWheelListener</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6575
     * <li>Mouse wheel events are enabled via <code>enableEvents</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6576
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6577
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6578
     * For information on how mouse wheel events are dispatched, see
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6579
     * the class description for {@link MouseWheelEvent}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6580
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6581
     * Note that if the event parameter is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6582
     * the behavior is unspecified and may result in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6583
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6584
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6585
     * @param       e the mouse wheel event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6586
     * @see         java.awt.event.MouseWheelEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6587
     * @see         java.awt.event.MouseWheelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6588
     * @see         #addMouseWheelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6589
     * @see         #enableEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6590
     * @since       1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6591
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6592
    protected void processMouseWheelEvent(MouseWheelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6593
        MouseWheelListener listener = mouseWheelListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6594
        if (listener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6595
            int id = e.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6596
            switch(id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6597
              case MouseEvent.MOUSE_WHEEL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6598
                  listener.mouseWheelMoved(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6599
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6600
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6601
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6602
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6603
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6604
    boolean postsOldMouseEvents() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6605
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6606
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6607
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6608
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6609
     * Processes input method events occurring on this component by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6610
     * dispatching them to any registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6611
     * <code>InputMethodListener</code> objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6612
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6613
     * This method is not called unless input method events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6614
     * are enabled for this component. Input method events are enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6615
     * when one of the following occurs:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6616
     * <p><ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6617
     * <li>An <code>InputMethodListener</code> object is registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6618
     * via <code>addInputMethodListener</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6619
     * <li>Input method events are enabled via <code>enableEvents</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6620
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6621
     * <p>Note that if the event parameter is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6622
     * the behavior is unspecified and may result in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6623
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6624
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6625
     * @param       e the input method event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6626
     * @see         java.awt.event.InputMethodEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6627
     * @see         java.awt.event.InputMethodListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6628
     * @see         #addInputMethodListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6629
     * @see         #enableEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6630
     * @since       1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6631
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6632
    protected void processInputMethodEvent(InputMethodEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6633
        InputMethodListener listener = inputMethodListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6634
        if (listener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6635
            int id = e.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6636
            switch (id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6637
              case InputMethodEvent.INPUT_METHOD_TEXT_CHANGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6638
                  listener.inputMethodTextChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6639
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6640
              case InputMethodEvent.CARET_POSITION_CHANGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6641
                  listener.caretPositionChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6642
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6643
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6644
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6645
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6646
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6647
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6648
     * Processes hierarchy events occurring on this component by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6649
     * dispatching them to any registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6650
     * <code>HierarchyListener</code> objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6651
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6652
     * This method is not called unless hierarchy events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6653
     * are enabled for this component. Hierarchy events are enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6654
     * when one of the following occurs:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6655
     * <p><ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6656
     * <li>An <code>HierarchyListener</code> object is registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6657
     * via <code>addHierarchyListener</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6658
     * <li>Hierarchy events are enabled via <code>enableEvents</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6659
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6660
     * <p>Note that if the event parameter is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6661
     * the behavior is unspecified and may result in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6662
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6663
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6664
     * @param       e the hierarchy event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6665
     * @see         java.awt.event.HierarchyEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6666
     * @see         java.awt.event.HierarchyListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6667
     * @see         #addHierarchyListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6668
     * @see         #enableEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6669
     * @since       1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6670
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6671
    protected void processHierarchyEvent(HierarchyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6672
        HierarchyListener listener = hierarchyListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6673
        if (listener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6674
            int id = e.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6675
            switch (id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6676
              case HierarchyEvent.HIERARCHY_CHANGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6677
                  listener.hierarchyChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6678
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6679
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6680
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6681
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6682
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6683
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6684
     * Processes hierarchy bounds events occurring on this component by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6685
     * dispatching them to any registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6686
     * <code>HierarchyBoundsListener</code> objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6687
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6688
     * This method is not called unless hierarchy bounds events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6689
     * are enabled for this component. Hierarchy bounds events are enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6690
     * when one of the following occurs:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6691
     * <p><ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6692
     * <li>An <code>HierarchyBoundsListener</code> object is registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6693
     * via <code>addHierarchyBoundsListener</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6694
     * <li>Hierarchy bounds events are enabled via <code>enableEvents</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6695
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6696
     * <p>Note that if the event parameter is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6697
     * the behavior is unspecified and may result in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6698
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6699
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6700
     * @param       e the hierarchy event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6701
     * @see         java.awt.event.HierarchyEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6702
     * @see         java.awt.event.HierarchyBoundsListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6703
     * @see         #addHierarchyBoundsListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6704
     * @see         #enableEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6705
     * @since       1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6706
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6707
    protected void processHierarchyBoundsEvent(HierarchyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6708
        HierarchyBoundsListener listener = hierarchyBoundsListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6709
        if (listener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6710
            int id = e.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6711
            switch (id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6712
              case HierarchyEvent.ANCESTOR_MOVED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6713
                  listener.ancestorMoved(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6714
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6715
              case HierarchyEvent.ANCESTOR_RESIZED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6716
                  listener.ancestorResized(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6717
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6718
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6719
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6720
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6721
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6722
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6723
     * @deprecated As of JDK version 1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6724
     * replaced by processEvent(AWTEvent).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6725
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6726
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6727
    public boolean handleEvent(Event evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6728
        switch (evt.id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6729
          case Event.MOUSE_ENTER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6730
              return mouseEnter(evt, evt.x, evt.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6731
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6732
          case Event.MOUSE_EXIT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6733
              return mouseExit(evt, evt.x, evt.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6734
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6735
          case Event.MOUSE_MOVE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6736
              return mouseMove(evt, evt.x, evt.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6737
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6738
          case Event.MOUSE_DOWN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6739
              return mouseDown(evt, evt.x, evt.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6740
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6741
          case Event.MOUSE_DRAG:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6742
              return mouseDrag(evt, evt.x, evt.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6743
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6744
          case Event.MOUSE_UP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6745
              return mouseUp(evt, evt.x, evt.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6746
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6747
          case Event.KEY_PRESS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6748
          case Event.KEY_ACTION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6749
              return keyDown(evt, evt.key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6750
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6751
          case Event.KEY_RELEASE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6752
          case Event.KEY_ACTION_RELEASE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6753
              return keyUp(evt, evt.key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6754
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6755
          case Event.ACTION_EVENT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6756
              return action(evt, evt.arg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6757
          case Event.GOT_FOCUS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6758
              return gotFocus(evt, evt.arg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6759
          case Event.LOST_FOCUS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6760
              return lostFocus(evt, evt.arg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6761
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6762
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6763
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6764
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6765
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6766
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6767
     * replaced by processMouseEvent(MouseEvent).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6768
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6769
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6770
    public boolean mouseDown(Event evt, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6771
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6772
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6773
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6774
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6775
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6776
     * replaced by processMouseMotionEvent(MouseEvent).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6777
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6778
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6779
    public boolean mouseDrag(Event evt, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6780
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6781
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6782
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6783
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6784
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6785
     * replaced by processMouseEvent(MouseEvent).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6786
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6787
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6788
    public boolean mouseUp(Event evt, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6789
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6790
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6791
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6792
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6793
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6794
     * replaced by processMouseMotionEvent(MouseEvent).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6795
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6796
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6797
    public boolean mouseMove(Event evt, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6798
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6799
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6800
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6801
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6802
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6803
     * replaced by processMouseEvent(MouseEvent).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6804
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6805
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6806
    public boolean mouseEnter(Event evt, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6807
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6808
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6809
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6810
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6811
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6812
     * replaced by processMouseEvent(MouseEvent).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6813
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6814
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6815
    public boolean mouseExit(Event evt, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6816
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6817
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6818
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6819
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6820
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6821
     * replaced by processKeyEvent(KeyEvent).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6822
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6823
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6824
    public boolean keyDown(Event evt, int key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6825
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6826
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6827
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6828
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6829
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6830
     * replaced by processKeyEvent(KeyEvent).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6831
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6832
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6833
    public boolean keyUp(Event evt, int key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6834
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6835
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6836
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6837
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6838
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6839
     * should register this component as ActionListener on component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6840
     * which fires action events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6841
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6842
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6843
    public boolean action(Event evt, Object what) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6844
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6845
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6846
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6847
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6848
     * Makes this <code>Component</code> displayable by connecting it to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6849
     * native screen resource.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6850
     * This method is called internally by the toolkit and should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6851
     * not be called directly by programs.
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  6852
     * <p>
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  6853
     * This method changes layout-related information, and therefore,
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  6854
     * invalidates the component hierarchy.
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  6855
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6856
     * @see       #isDisplayable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6857
     * @see       #removeNotify
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  6858
     * @see #invalidate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6859
     * @since JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6860
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6861
    public void addNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6862
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6863
            ComponentPeer peer = this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6864
            if (peer == null || peer instanceof LightweightPeer){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6865
                if (peer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6866
                    // Update both the Component's peer variable and the local
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6867
                    // variable we use for thread safety.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6868
                    this.peer = peer = getToolkit().createComponent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6869
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6870
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6871
                // This is a lightweight component which means it won't be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6872
                // able to get window-related events by itself.  If any
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6873
                // have been enabled, then the nearest native container must
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6874
                // be enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6875
                if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6876
                    long mask = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6877
                    if ((mouseListener != null) || ((eventMask & AWTEvent.MOUSE_EVENT_MASK) != 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6878
                        mask |= AWTEvent.MOUSE_EVENT_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6879
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6880
                    if ((mouseMotionListener != null) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6881
                        ((eventMask & AWTEvent.MOUSE_MOTION_EVENT_MASK) != 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6882
                        mask |= AWTEvent.MOUSE_MOTION_EVENT_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6883
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6884
                    if ((mouseWheelListener != null ) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6885
                        ((eventMask & AWTEvent.MOUSE_WHEEL_EVENT_MASK) != 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6886
                        mask |= AWTEvent.MOUSE_WHEEL_EVENT_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6887
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6888
                    if (focusListener != null || (eventMask & AWTEvent.FOCUS_EVENT_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6889
                        mask |= AWTEvent.FOCUS_EVENT_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6890
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6891
                    if (keyListener != null || (eventMask & AWTEvent.KEY_EVENT_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6892
                        mask |= AWTEvent.KEY_EVENT_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6893
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6894
                    if (mask != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6895
                        parent.proxyEnableEvents(mask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6896
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6897
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6898
            } else {
4257
c447aed67cec 6885735: closed/java/awt/Component/DisablingLWDisabledHW/DisablingLWDisabledHW.html fails
anthony
parents: 3966
diff changeset
  6899
                // It's native. If the parent is lightweight it will need some
c447aed67cec 6885735: closed/java/awt/Component/DisablingLWDisabledHW/DisablingLWDisabledHW.html fails
anthony
parents: 3966
diff changeset
  6900
                // help.
c447aed67cec 6885735: closed/java/awt/Component/DisablingLWDisabledHW/DisablingLWDisabledHW.html fails
anthony
parents: 3966
diff changeset
  6901
                Container parent = getContainer();
c447aed67cec 6885735: closed/java/awt/Component/DisablingLWDisabledHW/DisablingLWDisabledHW.html fails
anthony
parents: 3966
diff changeset
  6902
                if (parent != null && parent.isLightweight()) {
130
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 126
diff changeset
  6903
                    relocateComponent();
4257
c447aed67cec 6885735: closed/java/awt/Component/DisablingLWDisabledHW/DisablingLWDisabledHW.html fails
anthony
parents: 3966
diff changeset
  6904
                    if (!parent.isRecursivelyVisibleUpToHeavyweightContainer())
c447aed67cec 6885735: closed/java/awt/Component/DisablingLWDisabledHW/DisablingLWDisabledHW.html fails
anthony
parents: 3966
diff changeset
  6905
                    {
3729
80d0cf73598d 6689468: test/closed/java/awt/Component/VisibleHwInLwContTest/VisibleHwInLwContTest.html fails
anthony
parents: 3727
diff changeset
  6906
                        peer.setVisible(false);
80d0cf73598d 6689468: test/closed/java/awt/Component/VisibleHwInLwContTest/VisibleHwInLwContTest.html fails
anthony
parents: 3727
diff changeset
  6907
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6908
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6909
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6910
            invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6911
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6912
            int npopups = (popups != null? popups.size() : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6913
            for (int i = 0 ; i < npopups ; i++) {
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  6914
                PopupMenu popup = popups.elementAt(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6915
                popup.addNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6916
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6917
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6918
            if (dropTarget != null) dropTarget.addNotify(peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6919
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6920
            peerFont = getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6921
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6922
            if (getContainer() != null && !isAddNotifyComplete) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6923
                getContainer().increaseComponentCount(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6924
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6925
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6926
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6927
            // Update stacking order
2647
ea80a312972e 6825362: Avoid calling peer.setZOrder on Window instances
dcherepanov
parents: 2472
diff changeset
  6928
            updateZOrder();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6929
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6930
            if (!isAddNotifyComplete) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6931
                mixOnShowing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6932
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6933
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6934
            isAddNotifyComplete = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6935
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6936
            if (hierarchyListener != null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6937
                (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6938
                Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6939
                HierarchyEvent e =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6940
                    new HierarchyEvent(this, HierarchyEvent.HIERARCHY_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6941
                                       this, parent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6942
                                       HierarchyEvent.DISPLAYABILITY_CHANGED |
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6943
                                       ((isRecursivelyVisible())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6944
                                        ? HierarchyEvent.SHOWING_CHANGED
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6945
                                        : 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6946
                dispatchEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6947
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6948
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6949
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6950
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6951
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6952
     * Makes this <code>Component</code> undisplayable by destroying it native
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6953
     * screen resource.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6954
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6955
     * This method is called by the toolkit internally and should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6956
     * not be called directly by programs. Code overriding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6957
     * this method should call <code>super.removeNotify</code> as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6958
     * the first line of the overriding method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6959
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6960
     * @see       #isDisplayable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6961
     * @see       #addNotify
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6962
     * @since JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6963
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6964
    public void removeNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6965
        KeyboardFocusManager.clearMostRecentFocusOwner(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6966
        if (KeyboardFocusManager.getCurrentKeyboardFocusManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6967
            getPermanentFocusOwner() == this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6968
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6969
            KeyboardFocusManager.getCurrentKeyboardFocusManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6970
                setGlobalPermanentFocusOwner(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6971
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6972
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6973
        synchronized (getTreeLock()) {
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  6974
            if (isFocusOwner() && KeyboardFocusManager.isAutoFocusTransferEnabledFor(this)) {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  6975
                transferFocus(true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6976
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6977
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6978
            if (getContainer() != null && isAddNotifyComplete) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6979
                getContainer().decreaseComponentCount(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6980
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6981
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6982
            int npopups = (popups != null? popups.size() : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6983
            for (int i = 0 ; i < npopups ; i++) {
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  6984
                PopupMenu popup = popups.elementAt(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6985
                popup.removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6986
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6987
            // If there is any input context for this component, notify
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6988
            // that this component is being removed. (This has to be done
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6989
            // before hiding peer.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6990
            if ((eventMask & AWTEvent.INPUT_METHODS_ENABLED_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6991
                InputContext inputContext = getInputContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6992
                if (inputContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6993
                    inputContext.removeNotify(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6994
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6995
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6996
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6997
            ComponentPeer p = peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6998
            if (p != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6999
                boolean isLightweight = isLightweight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7000
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7001
                if (bufferStrategy instanceof FlipBufferStrategy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7002
                    ((FlipBufferStrategy)bufferStrategy).destroyBuffers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7003
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7004
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7005
                if (dropTarget != null) dropTarget.removeNotify(peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7006
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7007
                // Hide peer first to stop system events such as cursor moves.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7008
                if (visible) {
1964
934568dfe859 6749920: Cleanup AWT peer interfaces
rkennke
parents: 1188
diff changeset
  7009
                    p.setVisible(false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7010
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7011
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7012
                peer = null; // Stop peer updates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7013
                peerFont = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7014
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7015
                Toolkit.getEventQueue().removeSourceEvents(this, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7016
                KeyboardFocusManager.getCurrentKeyboardFocusManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7017
                    discardKeyEvents(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7018
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7019
                p.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7020
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7021
                mixOnHiding(isLightweight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7022
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7023
                isAddNotifyComplete = false;
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  7024
                // Nullifying compoundShape means that the component has normal shape
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  7025
                // (or has no shape at all).
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  7026
                this.compoundShape = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7027
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7028
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7029
            if (hierarchyListener != null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7030
                (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7031
                Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7032
                HierarchyEvent e =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7033
                    new HierarchyEvent(this, HierarchyEvent.HIERARCHY_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7034
                                       this, parent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7035
                                       HierarchyEvent.DISPLAYABILITY_CHANGED |
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7036
                                       ((isRecursivelyVisible())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7037
                                        ? HierarchyEvent.SHOWING_CHANGED
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7038
                                        : 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7039
                dispatchEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7040
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7041
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7042
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7043
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7044
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7045
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7046
     * replaced by processFocusEvent(FocusEvent).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7047
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7048
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7049
    public boolean gotFocus(Event evt, Object what) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7050
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7051
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7052
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7053
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7054
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7055
     * replaced by processFocusEvent(FocusEvent).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7056
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7057
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7058
    public boolean lostFocus(Event evt, Object what) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7059
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7060
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7061
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7062
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7063
     * Returns whether this <code>Component</code> can become the focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7064
     * owner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7065
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7066
     * @return <code>true</code> if this <code>Component</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7067
     * focusable; <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7068
     * @see #setFocusable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7069
     * @since JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7070
     * @deprecated As of 1.4, replaced by <code>isFocusable()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7071
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7072
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7073
    public boolean isFocusTraversable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7074
        if (isFocusTraversableOverridden == FOCUS_TRAVERSABLE_UNKNOWN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7075
            isFocusTraversableOverridden = FOCUS_TRAVERSABLE_DEFAULT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7076
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7077
        return focusable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7078
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7079
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7080
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7081
     * Returns whether this Component can be focused.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7082
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7083
     * @return <code>true</code> if this Component is focusable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7084
     *         <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7085
     * @see #setFocusable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7086
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7087
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7088
    public boolean isFocusable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7089
        return isFocusTraversable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7090
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7091
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7092
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7093
     * Sets the focusable state of this Component to the specified value. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7094
     * value overrides the Component's default focusability.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7095
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7096
     * @param focusable indicates whether this Component is focusable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7097
     * @see #isFocusable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7098
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7099
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7100
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7101
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7102
    public void setFocusable(boolean focusable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7103
        boolean oldFocusable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7104
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7105
            oldFocusable = this.focusable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7106
            this.focusable = focusable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7108
        isFocusTraversableOverridden = FOCUS_TRAVERSABLE_SET;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7109
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7110
        firePropertyChange("focusable", oldFocusable, focusable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7111
        if (oldFocusable && !focusable) {
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7112
            if (isFocusOwner() && KeyboardFocusManager.isAutoFocusTransferEnabled()) {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7113
                transferFocus(true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7114
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7115
            KeyboardFocusManager.clearMostRecentFocusOwner(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7116
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7118
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7119
    final boolean isFocusTraversableOverridden() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7120
        return (isFocusTraversableOverridden != FOCUS_TRAVERSABLE_DEFAULT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7122
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7123
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7124
     * Sets the focus traversal keys for a given traversal operation for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7125
     * Component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7126
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7127
     * The default values for a Component's focus traversal keys are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7128
     * implementation-dependent. Sun recommends that all implementations for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7129
     * particular native platform use the same default values. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7130
     * recommendations for Windows and Unix are listed below. These
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7131
     * recommendations are used in the Sun AWT implementations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7132
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7133
     * <table border=1 summary="Recommended default values for a Component's focus traversal keys">
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7134
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7135
     *    <th>Identifier</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7136
     *    <th>Meaning</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7137
     *    <th>Default</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7138
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7139
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7140
     *    <td>KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7141
     *    <td>Normal forward keyboard traversal</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7142
     *    <td>TAB on KEY_PRESSED, CTRL-TAB on KEY_PRESSED</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7143
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7144
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7145
     *    <td>KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7146
     *    <td>Normal reverse keyboard traversal</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7147
     *    <td>SHIFT-TAB on KEY_PRESSED, CTRL-SHIFT-TAB on KEY_PRESSED</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7148
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7149
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7150
     *    <td>KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7151
     *    <td>Go up one focus traversal cycle</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7152
     *    <td>none</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7153
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7154
     * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7155
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7156
     * To disable a traversal key, use an empty Set; Collections.EMPTY_SET is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7157
     * recommended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7158
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7159
     * Using the AWTKeyStroke API, client code can specify on which of two
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7160
     * specific KeyEvents, KEY_PRESSED or KEY_RELEASED, the focus traversal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7161
     * operation will occur. Regardless of which KeyEvent is specified,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7162
     * however, all KeyEvents related to the focus traversal key, including the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7163
     * associated KEY_TYPED event, will be consumed, and will not be dispatched
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7164
     * to any Component. It is a runtime error to specify a KEY_TYPED event as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7165
     * mapping to a focus traversal operation, or to map the same event to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7166
     * multiple default focus traversal operations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7167
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7168
     * If a value of null is specified for the Set, this Component inherits the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7169
     * Set from its parent. If all ancestors of this Component have null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7170
     * specified for the Set, then the current KeyboardFocusManager's default
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7171
     * Set is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7172
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7173
     * @param id one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7174
     *        KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7175
     *        KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7176
     * @param keystrokes the Set of AWTKeyStroke for the specified operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7177
     * @see #getFocusTraversalKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7178
     * @see KeyboardFocusManager#FORWARD_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7179
     * @see KeyboardFocusManager#BACKWARD_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7180
     * @see KeyboardFocusManager#UP_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7181
     * @throws IllegalArgumentException if id is not one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7182
     *         KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7183
     *         KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7184
     *         KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or if keystrokes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7185
     *         contains null, or if any Object in keystrokes is not an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7186
     *         AWTKeyStroke, or if any keystroke represents a KEY_TYPED event,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7187
     *         or if any keystroke already maps to another focus traversal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7188
     *         operation for this Component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7189
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7190
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7191
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7192
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7193
    public void setFocusTraversalKeys(int id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7194
                                      Set<? extends AWTKeyStroke> keystrokes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7195
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7196
        if (id < 0 || id >= KeyboardFocusManager.TRAVERSAL_KEY_LENGTH - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7197
            throw new IllegalArgumentException("invalid focus traversal key identifier");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7198
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7199
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7200
        setFocusTraversalKeys_NoIDCheck(id, keystrokes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7202
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7203
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7204
     * Returns the Set of focus traversal keys for a given traversal operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7205
     * for this Component. (See
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7206
     * <code>setFocusTraversalKeys</code> for a full description of each key.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7207
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7208
     * If a Set of traversal keys has not been explicitly defined for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7209
     * Component, then this Component's parent's Set is returned. If no Set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7210
     * has been explicitly defined for any of this Component's ancestors, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7211
     * the current KeyboardFocusManager's default Set is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7212
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7213
     * @param id one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7214
     *        KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7215
     *        KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7216
     * @return the Set of AWTKeyStrokes for the specified operation. The Set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7217
     *         will be unmodifiable, and may be empty. null will never be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7218
     *         returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7219
     * @see #setFocusTraversalKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7220
     * @see KeyboardFocusManager#FORWARD_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7221
     * @see KeyboardFocusManager#BACKWARD_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7222
     * @see KeyboardFocusManager#UP_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7223
     * @throws IllegalArgumentException if id is not one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7224
     *         KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7225
     *         KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7226
     *         KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7227
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7228
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7229
    public Set<AWTKeyStroke> getFocusTraversalKeys(int id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7230
        if (id < 0 || id >= KeyboardFocusManager.TRAVERSAL_KEY_LENGTH - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7231
            throw new IllegalArgumentException("invalid focus traversal key identifier");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7232
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7233
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7234
        return getFocusTraversalKeys_NoIDCheck(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7236
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7237
    // We define these methods so that Container does not need to repeat this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7238
    // code. Container cannot call super.<method> because Container allows
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7239
    // DOWN_CYCLE_TRAVERSAL_KEY while Component does not. The Component method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7240
    // would erroneously generate an IllegalArgumentException for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7241
    // DOWN_CYCLE_TRAVERSAL_KEY.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7242
    final void setFocusTraversalKeys_NoIDCheck(int id, Set<? extends AWTKeyStroke> keystrokes) {
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  7243
        Set<AWTKeyStroke> oldKeys;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7244
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7245
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7246
            if (focusTraversalKeys == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7247
                initializeFocusTraversalKeys();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7248
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7249
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7250
            if (keystrokes != null) {
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  7251
                for (AWTKeyStroke keystroke : keystrokes ) {
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  7252
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  7253
                    if (keystroke == null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7254
                        throw new IllegalArgumentException("cannot set null focus traversal key");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7255
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7256
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7257
                    if (keystroke.getKeyChar() != KeyEvent.CHAR_UNDEFINED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7258
                        throw new IllegalArgumentException("focus traversal keys cannot map to KEY_TYPED events");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7259
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7260
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7261
                    for (int i = 0; i < focusTraversalKeys.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7262
                        if (i == id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7263
                            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7264
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7265
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7266
                        if (getFocusTraversalKeys_NoIDCheck(i).contains(keystroke))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7267
                        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7268
                            throw new IllegalArgumentException("focus traversal keys must be unique for a Component");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7269
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7270
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7271
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7272
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7273
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7274
            oldKeys = focusTraversalKeys[id];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7275
            focusTraversalKeys[id] = (keystrokes != null)
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  7276
                ? Collections.unmodifiableSet(new HashSet<AWTKeyStroke>(keystrokes))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7277
                : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7278
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7279
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7280
        firePropertyChange(focusTraversalKeyPropertyNames[id], oldKeys,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7281
                           keystrokes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7282
    }
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  7283
    final Set<AWTKeyStroke> getFocusTraversalKeys_NoIDCheck(int id) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7284
        // Okay to return Set directly because it is an unmodifiable view
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  7285
        Set<AWTKeyStroke> keystrokes = (focusTraversalKeys != null)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7286
            ? focusTraversalKeys[id]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7287
            : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7288
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7289
        if (keystrokes != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7290
            return keystrokes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7291
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7292
            Container parent = this.parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7293
            if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7294
                return parent.getFocusTraversalKeys(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7295
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7296
                return KeyboardFocusManager.getCurrentKeyboardFocusManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7297
                    getDefaultFocusTraversalKeys(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7298
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7299
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7300
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7301
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7302
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7303
     * Returns whether the Set of focus traversal keys for the given focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7304
     * traversal operation has been explicitly defined for this Component. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7305
     * this method returns <code>false</code>, this Component is inheriting the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7306
     * Set from an ancestor, or from the current KeyboardFocusManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7307
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7308
     * @param id one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7309
     *        KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7310
     *        KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7311
     * @return <code>true</code> if the the Set of focus traversal keys for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7312
     *         given focus traversal operation has been explicitly defined for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7313
     *         this Component; <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7314
     * @throws IllegalArgumentException if id is not one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7315
     *         KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7316
     *         KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7317
     *         KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7318
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7319
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7320
    public boolean areFocusTraversalKeysSet(int id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7321
        if (id < 0 || id >= KeyboardFocusManager.TRAVERSAL_KEY_LENGTH - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7322
            throw new IllegalArgumentException("invalid focus traversal key identifier");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7323
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7324
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7325
        return (focusTraversalKeys != null && focusTraversalKeys[id] != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7326
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7327
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7328
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7329
     * Sets whether focus traversal keys are enabled for this Component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7330
     * Components for which focus traversal keys are disabled receive key
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7331
     * events for focus traversal keys. Components for which focus traversal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7332
     * keys are enabled do not see these events; instead, the events are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7333
     * automatically converted to traversal operations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7334
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7335
     * @param focusTraversalKeysEnabled whether focus traversal keys are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7336
     *        enabled for this Component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7337
     * @see #getFocusTraversalKeysEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7338
     * @see #setFocusTraversalKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7339
     * @see #getFocusTraversalKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7340
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7341
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7342
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7343
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7344
    public void setFocusTraversalKeysEnabled(boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7345
                                             focusTraversalKeysEnabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7346
        boolean oldFocusTraversalKeysEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7347
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7348
            oldFocusTraversalKeysEnabled = this.focusTraversalKeysEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7349
            this.focusTraversalKeysEnabled = focusTraversalKeysEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7350
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7351
        firePropertyChange("focusTraversalKeysEnabled",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7352
                           oldFocusTraversalKeysEnabled,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7353
                           focusTraversalKeysEnabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7354
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7355
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7356
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7357
     * Returns whether focus traversal keys are enabled for this Component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7358
     * Components for which focus traversal keys are disabled receive key
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7359
     * events for focus traversal keys. Components for which focus traversal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7360
     * keys are enabled do not see these events; instead, the events are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7361
     * automatically converted to traversal operations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7362
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7363
     * @return whether focus traversal keys are enabled for this Component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7364
     * @see #setFocusTraversalKeysEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7365
     * @see #setFocusTraversalKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7366
     * @see #getFocusTraversalKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7367
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7368
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7369
    public boolean getFocusTraversalKeysEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7370
        return focusTraversalKeysEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7371
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7372
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7373
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7374
     * Requests that this Component get the input focus, and that this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7375
     * Component's top-level ancestor become the focused Window. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7376
     * component must be displayable, focusable, visible and all of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7377
     * its ancestors (with the exception of the top-level Window) must
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7378
     * be visible for the request to be granted. Every effort will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7379
     * made to honor the request; however, in some cases it may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7380
     * impossible to do so. Developers must never assume that this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7381
     * Component is the focus owner until this Component receives a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7382
     * FOCUS_GAINED event. If this request is denied because this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7383
     * Component's top-level Window cannot become the focused Window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7384
     * the request will be remembered and will be granted when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7385
     * Window is later focused by the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7386
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7387
     * This method cannot be used to set the focus owner to no Component at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7388
     * all. Use <code>KeyboardFocusManager.clearGlobalFocusOwner()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7389
     * instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7390
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7391
     * Because the focus behavior of this method is platform-dependent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7392
     * developers are strongly encouraged to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7393
     * <code>requestFocusInWindow</code> when possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7394
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7395
     * <p>Note: Not all focus transfers result from invoking this method. As
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7396
     * such, a component may receive focus without this or any of the other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7397
     * {@code requestFocus} methods of {@code Component} being invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7398
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7399
     * @see #requestFocusInWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7400
     * @see java.awt.event.FocusEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7401
     * @see #addFocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7402
     * @see #isFocusable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7403
     * @see #isDisplayable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7404
     * @see KeyboardFocusManager#clearGlobalFocusOwner
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7405
     * @since JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7406
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7407
    public void requestFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7408
        requestFocusHelper(false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7409
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7410
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2462
diff changeset
  7411
    boolean requestFocus(CausedFocusEvent.Cause cause) {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2462
diff changeset
  7412
        return requestFocusHelper(false, true, cause);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7413
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7414
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7415
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7416
     * Requests that this <code>Component</code> get the input focus,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7417
     * and that this <code>Component</code>'s top-level ancestor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7418
     * become the focused <code>Window</code>. This component must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7419
     * displayable, focusable, visible and all of its ancestors (with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7420
     * the exception of the top-level Window) must be visible for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7421
     * request to be granted. Every effort will be made to honor the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7422
     * request; however, in some cases it may be impossible to do
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7423
     * so. Developers must never assume that this component is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7424
     * focus owner until this component receives a FOCUS_GAINED
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7425
     * event. If this request is denied because this component's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7426
     * top-level window cannot become the focused window, the request
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7427
     * will be remembered and will be granted when the window is later
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7428
     * focused by the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7429
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7430
     * This method returns a boolean value. If <code>false</code> is returned,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7431
     * the request is <b>guaranteed to fail</b>. If <code>true</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7432
     * returned, the request will succeed <b>unless</b> it is vetoed, or an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7433
     * extraordinary event, such as disposal of the component's peer, occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7434
     * before the request can be granted by the native windowing system. Again,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7435
     * while a return value of <code>true</code> indicates that the request is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7436
     * likely to succeed, developers must never assume that this component is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7437
     * the focus owner until this component receives a FOCUS_GAINED event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7438
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7439
     * This method cannot be used to set the focus owner to no component at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7440
     * all. Use <code>KeyboardFocusManager.clearGlobalFocusOwner</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7441
     * instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7442
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7443
     * Because the focus behavior of this method is platform-dependent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7444
     * developers are strongly encouraged to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7445
     * <code>requestFocusInWindow</code> when possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7446
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7447
     * Every effort will be made to ensure that <code>FocusEvent</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7448
     * generated as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7449
     * result of this request will have the specified temporary value. However,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7450
     * because specifying an arbitrary temporary state may not be implementable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7451
     * on all native windowing systems, correct behavior for this method can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7452
     * guaranteed only for lightweight <code>Component</code>s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7453
     * This method is not intended
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7454
     * for general use, but exists instead as a hook for lightweight component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7455
     * libraries, such as Swing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7456
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7457
     * <p>Note: Not all focus transfers result from invoking this method. As
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7458
     * such, a component may receive focus without this or any of the other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7459
     * {@code requestFocus} methods of {@code Component} being invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7460
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7461
     * @param temporary true if the focus change is temporary,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7462
     *        such as when the window loses the focus; for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7463
     *        more information on temporary focus changes see the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7464
     *<a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7465
     * @return <code>false</code> if the focus change request is guaranteed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7466
     *         fail; <code>true</code> if it is likely to succeed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7467
     * @see java.awt.event.FocusEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7468
     * @see #addFocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7469
     * @see #isFocusable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7470
     * @see #isDisplayable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7471
     * @see KeyboardFocusManager#clearGlobalFocusOwner
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7472
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7473
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7474
    protected boolean requestFocus(boolean temporary) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7475
        return requestFocusHelper(temporary, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7476
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7477
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7478
    boolean requestFocus(boolean temporary, CausedFocusEvent.Cause cause) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7479
        return requestFocusHelper(temporary, true, cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7480
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7481
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7482
     * Requests that this Component get the input focus, if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7483
     * Component's top-level ancestor is already the focused
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7484
     * Window. This component must be displayable, focusable, visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7485
     * and all of its ancestors (with the exception of the top-level
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7486
     * Window) must be visible for the request to be granted. Every
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7487
     * effort will be made to honor the request; however, in some
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7488
     * cases it may be impossible to do so. Developers must never
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7489
     * assume that this Component is the focus owner until this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7490
     * Component receives a FOCUS_GAINED event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7491
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7492
     * This method returns a boolean value. If <code>false</code> is returned,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7493
     * the request is <b>guaranteed to fail</b>. If <code>true</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7494
     * returned, the request will succeed <b>unless</b> it is vetoed, or an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7495
     * extraordinary event, such as disposal of the Component's peer, occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7496
     * before the request can be granted by the native windowing system. Again,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7497
     * while a return value of <code>true</code> indicates that the request is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7498
     * likely to succeed, developers must never assume that this Component is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7499
     * the focus owner until this Component receives a FOCUS_GAINED event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7500
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7501
     * This method cannot be used to set the focus owner to no Component at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7502
     * all. Use <code>KeyboardFocusManager.clearGlobalFocusOwner()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7503
     * instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7504
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7505
     * The focus behavior of this method can be implemented uniformly across
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7506
     * platforms, and thus developers are strongly encouraged to use this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7507
     * method over <code>requestFocus</code> when possible. Code which relies
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7508
     * on <code>requestFocus</code> may exhibit different focus behavior on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7509
     * different platforms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7510
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7511
     * <p>Note: Not all focus transfers result from invoking this method. As
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7512
     * such, a component may receive focus without this or any of the other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7513
     * {@code requestFocus} methods of {@code Component} being invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7514
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7515
     * @return <code>false</code> if the focus change request is guaranteed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7516
     *         fail; <code>true</code> if it is likely to succeed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7517
     * @see #requestFocus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7518
     * @see java.awt.event.FocusEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7519
     * @see #addFocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7520
     * @see #isFocusable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7521
     * @see #isDisplayable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7522
     * @see KeyboardFocusManager#clearGlobalFocusOwner
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7523
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7524
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7525
    public boolean requestFocusInWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7526
        return requestFocusHelper(false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7527
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7528
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7529
    boolean requestFocusInWindow(CausedFocusEvent.Cause cause) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7530
        return requestFocusHelper(false, false, cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7531
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7532
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7533
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7534
     * Requests that this <code>Component</code> get the input focus,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7535
     * if this <code>Component</code>'s top-level ancestor is already
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7536
     * the focused <code>Window</code>.  This component must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7537
     * displayable, focusable, visible and all of its ancestors (with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7538
     * the exception of the top-level Window) must be visible for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7539
     * request to be granted. Every effort will be made to honor the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7540
     * request; however, in some cases it may be impossible to do
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7541
     * so. Developers must never assume that this component is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7542
     * focus owner until this component receives a FOCUS_GAINED event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7543
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7544
     * This method returns a boolean value. If <code>false</code> is returned,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7545
     * the request is <b>guaranteed to fail</b>. If <code>true</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7546
     * returned, the request will succeed <b>unless</b> it is vetoed, or an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7547
     * extraordinary event, such as disposal of the component's peer, occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7548
     * before the request can be granted by the native windowing system. Again,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7549
     * while a return value of <code>true</code> indicates that the request is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7550
     * likely to succeed, developers must never assume that this component is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7551
     * the focus owner until this component receives a FOCUS_GAINED event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7552
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7553
     * This method cannot be used to set the focus owner to no component at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7554
     * all. Use <code>KeyboardFocusManager.clearGlobalFocusOwner</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7555
     * instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7556
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7557
     * The focus behavior of this method can be implemented uniformly across
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7558
     * platforms, and thus developers are strongly encouraged to use this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7559
     * method over <code>requestFocus</code> when possible. Code which relies
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7560
     * on <code>requestFocus</code> may exhibit different focus behavior on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7561
     * different platforms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7562
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7563
     * Every effort will be made to ensure that <code>FocusEvent</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7564
     * generated as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7565
     * result of this request will have the specified temporary value. However,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7566
     * because specifying an arbitrary temporary state may not be implementable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7567
     * on all native windowing systems, correct behavior for this method can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7568
     * guaranteed only for lightweight components. This method is not intended
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7569
     * for general use, but exists instead as a hook for lightweight component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7570
     * libraries, such as Swing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7571
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7572
     * <p>Note: Not all focus transfers result from invoking this method. As
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7573
     * such, a component may receive focus without this or any of the other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7574
     * {@code requestFocus} methods of {@code Component} being invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7575
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7576
     * @param temporary true if the focus change is temporary,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7577
     *        such as when the window loses the focus; for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7578
     *        more information on temporary focus changes see the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7579
     *<a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7580
     * @return <code>false</code> if the focus change request is guaranteed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7581
     *         fail; <code>true</code> if it is likely to succeed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7582
     * @see #requestFocus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7583
     * @see java.awt.event.FocusEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7584
     * @see #addFocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7585
     * @see #isFocusable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7586
     * @see #isDisplayable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7587
     * @see KeyboardFocusManager#clearGlobalFocusOwner
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7588
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7589
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7590
    protected boolean requestFocusInWindow(boolean temporary) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7591
        return requestFocusHelper(temporary, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7592
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7593
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7594
    boolean requestFocusInWindow(boolean temporary, CausedFocusEvent.Cause cause) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7595
        return requestFocusHelper(temporary, false, cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7596
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7597
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7598
    final boolean requestFocusHelper(boolean temporary,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7599
                                     boolean focusedWindowChangeAllowed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7600
        return requestFocusHelper(temporary, focusedWindowChangeAllowed, CausedFocusEvent.Cause.UNKNOWN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7601
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7602
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7603
    final boolean requestFocusHelper(boolean temporary,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7604
                                     boolean focusedWindowChangeAllowed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7605
                                     CausedFocusEvent.Cause cause)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7606
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7607
        if (!isRequestFocusAccepted(temporary, focusedWindowChangeAllowed, cause)) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  7608
            if (focusLog.isLoggable(PlatformLogger.FINEST)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  7609
                focusLog.finest("requestFocus is not accepted");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7610
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7611
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7612
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7613
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7614
        // Update most-recent map
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7615
        KeyboardFocusManager.setMostRecentFocusOwner(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7616
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7617
        Component window = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7618
        while ( (window != null) && !(window instanceof Window)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7619
            if (!window.isVisible()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  7620
                if (focusLog.isLoggable(PlatformLogger.FINEST)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  7621
                    focusLog.finest("component is recurively invisible");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7622
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7623
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7624
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7625
            window = window.parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7626
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7627
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7628
        ComponentPeer peer = this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7629
        Component heavyweight = (peer instanceof LightweightPeer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7630
            ? getNativeContainer() : this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7631
        if (heavyweight == null || !heavyweight.isVisible()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  7632
            if (focusLog.isLoggable(PlatformLogger.FINEST)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  7633
                focusLog.finest("Component is not a part of visible hierarchy");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7634
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7635
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7636
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7637
        peer = heavyweight.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7638
        if (peer == null) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  7639
            if (focusLog.isLoggable(PlatformLogger.FINEST)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  7640
                focusLog.finest("Peer is null");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7641
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7642
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7643
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7644
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7645
        // Focus this Component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7646
        long time = EventQueue.getMostRecentEventTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7647
        boolean success = peer.requestFocus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7648
            (this, temporary, focusedWindowChangeAllowed, time, cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7649
        if (!success) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7650
            KeyboardFocusManager.getCurrentKeyboardFocusManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7651
                (appContext).dequeueKeyEvents(time, this);
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  7652
            if (focusLog.isLoggable(PlatformLogger.FINEST)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  7653
                focusLog.finest("Peer request failed");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7654
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7655
        } else {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  7656
            if (focusLog.isLoggable(PlatformLogger.FINEST)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  7657
                focusLog.finest("Pass for " + this);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7658
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7659
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7660
        return success;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7661
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7662
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7663
    private boolean isRequestFocusAccepted(boolean temporary,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7664
                                           boolean focusedWindowChangeAllowed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7665
                                           CausedFocusEvent.Cause cause)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7666
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7667
        if (!isFocusable() || !isVisible()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  7668
            if (focusLog.isLoggable(PlatformLogger.FINEST)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  7669
                focusLog.finest("Not focusable or not visible");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7670
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7671
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7672
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7673
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7674
        ComponentPeer peer = this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7675
        if (peer == null) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  7676
            if (focusLog.isLoggable(PlatformLogger.FINEST)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  7677
                focusLog.finest("peer is null");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7678
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7679
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7680
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7681
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7682
        Window window = getContainingWindow();
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  7683
        if (window == null || !window.isFocusableWindow()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  7684
            if (focusLog.isLoggable(PlatformLogger.FINEST)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  7685
                focusLog.finest("Component doesn't have toplevel");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7686
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7687
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7688
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7689
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7690
        // We have passed all regular checks for focus request,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7691
        // now let's call RequestFocusController and see what it says.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7692
        Component focusOwner = KeyboardFocusManager.getMostRecentFocusOwner(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7693
        if (focusOwner == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7694
            // sometimes most recent focus owner may be null, but focus owner is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7695
            // e.g. we reset most recent focus owner if user removes focus owner
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7696
            focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
  7697
            if (focusOwner != null && focusOwner.getContainingWindow() != window) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7698
                focusOwner = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7699
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7700
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7701
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7702
        if (focusOwner == this || focusOwner == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7703
            // Controller is supposed to verify focus transfers and for this it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7704
            // should know both from and to components.  And it shouldn't verify
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7705
            // transfers from when these components are equal.
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  7706
            if (focusLog.isLoggable(PlatformLogger.FINEST)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  7707
                focusLog.finest("focus owner is null or this");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7708
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7709
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7710
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7711
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7712
        if (CausedFocusEvent.Cause.ACTIVATION == cause) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7713
            // we shouldn't call RequestFocusController in case we are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7714
            // in activation.  We do request focus on component which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7715
            // has got temporary focus lost and then on component which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7716
            // most recent focus owner.  But most recent focus owner can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7717
            // changed by requestFocsuXXX() call only, so this transfer has
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7718
            // been already approved.
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  7719
            if (focusLog.isLoggable(PlatformLogger.FINEST)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  7720
                focusLog.finest("cause is activation");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7721
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7722
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7723
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7724
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7725
        boolean ret = Component.requestFocusController.acceptRequestFocus(focusOwner,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7726
                                                                          this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7727
                                                                          temporary,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7728
                                                                          focusedWindowChangeAllowed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7729
                                                                          cause);
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  7730
        if (focusLog.isLoggable(PlatformLogger.FINEST)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  7731
            focusLog.finest("RequestFocusController returns {0}", ret);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7732
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7733
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7734
        return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7735
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7736
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7737
    private static RequestFocusController requestFocusController = new DummyRequestFocusController();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7738
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7739
    // Swing access this method through reflection to implement InputVerifier's functionality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7740
    // Perhaps, we should make this method public (later ;)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7741
    private static class DummyRequestFocusController implements RequestFocusController {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7742
        public boolean acceptRequestFocus(Component from, Component to,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7743
                                          boolean temporary, boolean focusedWindowChangeAllowed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7744
                                          CausedFocusEvent.Cause cause)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7745
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7746
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7747
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7748
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7749
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7750
    synchronized static void setRequestFocusController(RequestFocusController requestController)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7751
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7752
        if (requestController == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7753
            requestFocusController = new DummyRequestFocusController();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7754
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7755
            requestFocusController = requestController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7756
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7757
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7758
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7759
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7760
     * Returns the Container which is the focus cycle root of this Component's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7761
     * focus traversal cycle. Each focus traversal cycle has only a single
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7762
     * focus cycle root and each Component which is not a Container belongs to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7763
     * only a single focus traversal cycle. Containers which are focus cycle
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7764
     * roots belong to two cycles: one rooted at the Container itself, and one
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7765
     * rooted at the Container's nearest focus-cycle-root ancestor. For such
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7766
     * Containers, this method will return the Container's nearest focus-cycle-
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7767
     * root ancestor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7768
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7769
     * @return this Component's nearest focus-cycle-root ancestor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7770
     * @see Container#isFocusCycleRoot()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7771
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7772
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7773
    public Container getFocusCycleRootAncestor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7774
        Container rootAncestor = this.parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7775
        while (rootAncestor != null && !rootAncestor.isFocusCycleRoot()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7776
            rootAncestor = rootAncestor.parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7777
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7778
        return rootAncestor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7779
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7780
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7781
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7782
     * Returns whether the specified Container is the focus cycle root of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7783
     * Component's focus traversal cycle. Each focus traversal cycle has only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7784
     * a single focus cycle root and each Component which is not a Container
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7785
     * belongs to only a single focus traversal cycle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7786
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7787
     * @param container the Container to be tested
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7788
     * @return <code>true</code> if the specified Container is a focus-cycle-
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7789
     *         root of this Component; <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7790
     * @see Container#isFocusCycleRoot()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7791
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7792
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7793
    public boolean isFocusCycleRoot(Container container) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7794
        Container rootAncestor = getFocusCycleRootAncestor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7795
        return (rootAncestor == container);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7796
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7797
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7798
    Container getTraversalRoot() {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7799
        return getFocusCycleRootAncestor();
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7800
    }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7801
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7802
    /**
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7803
     * Transfers the focus to the next component, as though this Component were
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7804
     * the focus owner.
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7805
     * @see       #requestFocus()
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7806
     * @since     JDK1.1
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7807
     */
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7808
    public void transferFocus() {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7809
        nextFocus();
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7810
    }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7811
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7812
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7813
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7814
     * replaced by transferFocus().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7815
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7816
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7817
    public void nextFocus() {
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7818
        transferFocus(false);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7819
    }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7820
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7821
    boolean transferFocus(boolean clearOnFailure) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  7822
        if (focusLog.isLoggable(PlatformLogger.FINER)) {
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7823
            focusLog.finer("clearOnFailure = " + clearOnFailure);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7824
        }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7825
        Component toFocus = getNextFocusCandidate();
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7826
        boolean res = false;
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7827
        if (toFocus != null && !toFocus.isFocusOwner() && toFocus != this) {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7828
            res = toFocus.requestFocusInWindow(CausedFocusEvent.Cause.TRAVERSAL_FORWARD);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7829
        }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7830
        if (clearOnFailure && !res) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  7831
            if (focusLog.isLoggable(PlatformLogger.FINER)) {
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7832
                focusLog.finer("clear global focus owner");
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7833
            }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7834
            KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner();
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7835
        }
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  7836
        if (focusLog.isLoggable(PlatformLogger.FINER)) {
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7837
            focusLog.finer("returning result: " + res);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7838
        }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7839
        return res;
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7840
    }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7841
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7842
    final Component getNextFocusCandidate() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7843
        Container rootAncestor = getTraversalRoot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7844
        Component comp = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7845
        while (rootAncestor != null &&
1171
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 1169
diff changeset
  7846
               !(rootAncestor.isShowing() && rootAncestor.canBeFocusOwner()))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7847
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7848
            comp = rootAncestor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7849
            rootAncestor = comp.getFocusCycleRootAncestor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7850
        }
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  7851
        if (focusLog.isLoggable(PlatformLogger.FINER)) {
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7852
            focusLog.finer("comp = " + comp + ", root = " + rootAncestor);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7853
        }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7854
        Component candidate = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7855
        if (rootAncestor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7856
            FocusTraversalPolicy policy = rootAncestor.getFocusTraversalPolicy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7857
            Component toFocus = policy.getComponentAfter(rootAncestor, comp);
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  7858
            if (focusLog.isLoggable(PlatformLogger.FINER)) {
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7859
                focusLog.finer("component after is " + toFocus);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7860
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7861
            if (toFocus == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7862
                toFocus = policy.getDefaultComponent(rootAncestor);
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  7863
                if (focusLog.isLoggable(PlatformLogger.FINER)) {
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7864
                    focusLog.finer("default component is " + toFocus);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7865
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7866
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7867
            if (toFocus == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7868
                Applet applet = EmbeddedFrame.getAppletIfAncestorOf(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7869
                if (applet != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7870
                    toFocus = applet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7871
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7872
            }
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7873
            candidate = toFocus;
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7874
        }
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  7875
        if (focusLog.isLoggable(PlatformLogger.FINER)) {
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7876
            focusLog.finer("Focus transfer candidate: " + candidate);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7877
        }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7878
        return candidate;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7879
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7880
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7881
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7882
     * Transfers the focus to the previous component, as though this Component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7883
     * were the focus owner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7884
     * @see       #requestFocus()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7885
     * @since     1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7886
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7887
    public void transferFocusBackward() {
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7888
        transferFocusBackward(false);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7889
    }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7890
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7891
    boolean transferFocusBackward(boolean clearOnFailure) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7892
        Container rootAncestor = getTraversalRoot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7893
        Component comp = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7894
        while (rootAncestor != null &&
1171
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 1169
diff changeset
  7895
               !(rootAncestor.isShowing() && rootAncestor.canBeFocusOwner()))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7896
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7897
            comp = rootAncestor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7898
            rootAncestor = comp.getFocusCycleRootAncestor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7899
        }
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7900
        boolean res = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7901
        if (rootAncestor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7902
            FocusTraversalPolicy policy = rootAncestor.getFocusTraversalPolicy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7903
            Component toFocus = policy.getComponentBefore(rootAncestor, comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7904
            if (toFocus == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7905
                toFocus = policy.getDefaultComponent(rootAncestor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7906
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7907
            if (toFocus != null) {
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7908
                res = toFocus.requestFocusInWindow(CausedFocusEvent.Cause.TRAVERSAL_BACKWARD);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7909
            }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7910
        }
10410
ebae41687d0b 7081012: REGRESSION:Component.transferFocusBackward invokes clearGlobalFocusOwner()
denis
parents: 9658
diff changeset
  7911
        if (clearOnFailure && !res) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  7912
            if (focusLog.isLoggable(PlatformLogger.FINER)) {
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7913
                focusLog.finer("clear global focus owner");
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7914
            }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7915
            KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner();
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7916
        }
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  7917
        if (focusLog.isLoggable(PlatformLogger.FINER)) {
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7918
            focusLog.finer("returning result: " + res);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7919
        }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7920
        return res;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7921
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7922
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7923
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7924
     * Transfers the focus up one focus traversal cycle. Typically, the focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7925
     * owner is set to this Component's focus cycle root, and the current focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7926
     * cycle root is set to the new focus owner's focus cycle root. If,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7927
     * however, this Component's focus cycle root is a Window, then the focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7928
     * owner is set to the focus cycle root's default Component to focus, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7929
     * the current focus cycle root is unchanged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7930
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7931
     * @see       #requestFocus()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7932
     * @see       Container#isFocusCycleRoot()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7933
     * @see       Container#setFocusCycleRoot(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7934
     * @since     1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7935
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7936
    public void transferFocusUpCycle() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7937
        Container rootAncestor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7938
        for (rootAncestor = getFocusCycleRootAncestor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7939
             rootAncestor != null && !(rootAncestor.isShowing() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7940
                                       rootAncestor.isFocusable() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7941
                                       rootAncestor.isEnabled());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7942
             rootAncestor = rootAncestor.getFocusCycleRootAncestor()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7943
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7944
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7945
        if (rootAncestor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7946
            Container rootAncestorRootAncestor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7947
                rootAncestor.getFocusCycleRootAncestor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7948
            KeyboardFocusManager.getCurrentKeyboardFocusManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7949
                setGlobalCurrentFocusCycleRoot(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7950
                                               (rootAncestorRootAncestor != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7951
                                               ? rootAncestorRootAncestor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7952
                                               : rootAncestor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7953
            rootAncestor.requestFocus(CausedFocusEvent.Cause.TRAVERSAL_UP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7954
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7955
            Window window = getContainingWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7956
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7957
            if (window != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7958
                Component toFocus = window.getFocusTraversalPolicy().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7959
                    getDefaultComponent(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7960
                if (toFocus != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7961
                    KeyboardFocusManager.getCurrentKeyboardFocusManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7962
                        setGlobalCurrentFocusCycleRoot(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7963
                    toFocus.requestFocus(CausedFocusEvent.Cause.TRAVERSAL_UP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7964
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7965
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7966
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7967
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7968
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7969
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7970
     * Returns <code>true</code> if this <code>Component</code> is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7971
     * focus owner.  This method is obsolete, and has been replaced by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7972
     * <code>isFocusOwner()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7973
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7974
     * @return <code>true</code> if this <code>Component</code> is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7975
     *         focus owner; <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7976
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7977
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7978
    public boolean hasFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7979
        return (KeyboardFocusManager.getCurrentKeyboardFocusManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7980
                getFocusOwner() == this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7981
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7982
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7983
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7984
     * Returns <code>true</code> if this <code>Component</code> is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7985
     *    focus owner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7986
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7987
     * @return <code>true</code> if this <code>Component</code> is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7988
     *     focus owner; <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7989
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7990
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7991
    public boolean isFocusOwner() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7992
        return hasFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7993
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7994
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7995
    /*
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7996
     * Used to disallow auto-focus-transfer on disposal of the focus owner
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7997
     * in the process of disposing its parent container.
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7998
     */
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7999
    private boolean autoFocusTransferOnDisposal = true;
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8000
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8001
    void setAutoFocusTransferOnDisposal(boolean value) {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8002
        autoFocusTransferOnDisposal = value;
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8003
    }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8004
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8005
    boolean isAutoFocusTransferOnDisposal() {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8006
        return autoFocusTransferOnDisposal;
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8007
    }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8008
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8009
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8010
     * Adds the specified popup menu to the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8011
     * @param     popup the popup menu to be added to the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8012
     * @see       #remove(MenuComponent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8013
     * @exception NullPointerException if {@code popup} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8014
     * @since     JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8015
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8016
    public void add(PopupMenu popup) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8017
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8018
            if (popup.parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8019
                popup.parent.remove(popup);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8020
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8021
            if (popups == null) {
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  8022
                popups = new Vector<PopupMenu>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8023
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8024
            popups.addElement(popup);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8025
            popup.parent = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8026
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8027
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8028
                if (popup.peer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8029
                    popup.addNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8030
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8031
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8032
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8033
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8034
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8035
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8036
     * Removes the specified popup menu from the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8037
     * @param     popup the popup menu to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8038
     * @see       #add(PopupMenu)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8039
     * @since     JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8040
     */
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  8041
    @SuppressWarnings("unchecked")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8042
    public void remove(MenuComponent popup) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8043
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8044
            if (popups == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8045
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8046
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8047
            int index = popups.indexOf(popup);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8048
            if (index >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8049
                PopupMenu pmenu = (PopupMenu)popup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8050
                if (pmenu.peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8051
                    pmenu.removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8052
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8053
                pmenu.parent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8054
                popups.removeElementAt(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8055
                if (popups.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8056
                    popups = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8057
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8058
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8059
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8060
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8061
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8062
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8063
     * Returns a string representing the state of this component. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8064
     * method is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8065
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8066
     * implementations. The returned string may be empty but may not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8067
     * <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8068
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8069
     * @return  a string representation of this component's state
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8070
     * @since     JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8071
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8072
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8073
        String thisName = getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8074
        String str = (thisName != null? thisName : "") + "," + x + "," + y + "," + width + "x" + height;
1183
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
  8075
        if (!isValid()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8076
            str += ",invalid";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8077
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8078
        if (!visible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8079
            str += ",hidden";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8080
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8081
        if (!enabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8082
            str += ",disabled";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8083
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8084
        return str;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8085
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8086
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8087
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8088
     * Returns a string representation of this component and its values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8089
     * @return    a string representation of this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8090
     * @since     JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8091
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8092
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8093
        return getClass().getName() + "[" + paramString() + "]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8094
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8095
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8096
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8097
     * Prints a listing of this component to the standard system output
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8098
     * stream <code>System.out</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8099
     * @see       java.lang.System#out
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8100
     * @since     JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8101
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8102
    public void list() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8103
        list(System.out, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8105
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8106
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8107
     * Prints a listing of this component to the specified output
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8108
     * stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8109
     * @param    out   a print stream
7154
4e8371f358ac 6877895: Some AWT's methods should specify throwing NPE for null arg value
dcherepanov
parents: 5506
diff changeset
  8110
     * @throws   NullPointerException if {@code out} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8111
     * @since    JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8113
    public void list(PrintStream out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8114
        list(out, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8116
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8118
     * Prints out a list, starting at the specified indentation, to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8119
     * specified print stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8120
     * @param     out      a print stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8121
     * @param     indent   number of spaces to indent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8122
     * @see       java.io.PrintStream#println(java.lang.Object)
7154
4e8371f358ac 6877895: Some AWT's methods should specify throwing NPE for null arg value
dcherepanov
parents: 5506
diff changeset
  8123
     * @throws    NullPointerException if {@code out} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8124
     * @since     JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8126
    public void list(PrintStream out, int indent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8127
        for (int i = 0 ; i < indent ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8128
            out.print(" ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8129
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8130
        out.println(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8132
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8133
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8134
     * Prints a listing to the specified print writer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8135
     * @param  out  the print writer to print to
7154
4e8371f358ac 6877895: Some AWT's methods should specify throwing NPE for null arg value
dcherepanov
parents: 5506
diff changeset
  8136
     * @throws NullPointerException if {@code out} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8137
     * @since JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8138
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8139
    public void list(PrintWriter out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8140
        list(out, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8142
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8143
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8144
     * Prints out a list, starting at the specified indentation, to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8145
     * the specified print writer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8146
     * @param out the print writer to print to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8147
     * @param indent the number of spaces to indent
7154
4e8371f358ac 6877895: Some AWT's methods should specify throwing NPE for null arg value
dcherepanov
parents: 5506
diff changeset
  8148
     * @throws NullPointerException if {@code out} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8149
     * @see       java.io.PrintStream#println(java.lang.Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8150
     * @since JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8151
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8152
    public void list(PrintWriter out, int indent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8153
        for (int i = 0 ; i < indent ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8154
            out.print(" ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8156
        out.println(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8158
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8159
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8160
     * Fetches the native container somewhere higher up in the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8161
     * tree that contains this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8162
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8163
    Container getNativeContainer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8164
        Container p = parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8165
        while (p != null && p.peer instanceof LightweightPeer) {
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
  8166
            p = p.getParent_NoClientCode();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8167
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8168
        return p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8170
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8171
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8172
     * Adds a PropertyChangeListener to the listener list. The listener is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8173
     * registered for all bound properties of this class, including the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8174
     * following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8175
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8176
     *    <li>this Component's font ("font")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8177
     *    <li>this Component's background color ("background")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8178
     *    <li>this Component's foreground color ("foreground")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8179
     *    <li>this Component's focusability ("focusable")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8180
     *    <li>this Component's focus traversal keys enabled state
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8181
     *        ("focusTraversalKeysEnabled")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8182
     *    <li>this Component's Set of FORWARD_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8183
     *        ("forwardFocusTraversalKeys")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8184
     *    <li>this Component's Set of BACKWARD_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8185
     *        ("backwardFocusTraversalKeys")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8186
     *    <li>this Component's Set of UP_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8187
     *        ("upCycleFocusTraversalKeys")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8188
     *    <li>this Component's preferred size ("preferredSize")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8189
     *    <li>this Component's minimum size ("minimumSize")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8190
     *    <li>this Component's maximum size ("maximumSize")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8191
     *    <li>this Component's name ("name")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8192
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8193
     * Note that if this <code>Component</code> is inheriting a bound property, then no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8194
     * event will be fired in response to a change in the inherited property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8195
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8196
     * If <code>listener</code> is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8197
     * no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8198
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8199
     * @param    listener  the property change listener to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8200
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8201
     * @see #removePropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8202
     * @see #getPropertyChangeListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8203
     * @see #addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8204
     */
123
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8205
    public void addPropertyChangeListener(
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8206
                                                       PropertyChangeListener listener) {
1169
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
  8207
        synchronized (getObjectLock()) {
123
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8208
            if (listener == null) {
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8209
                return;
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8210
            }
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8211
            if (changeSupport == null) {
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8212
                changeSupport = new PropertyChangeSupport(this);
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8213
            }
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8214
            changeSupport.addPropertyChangeListener(listener);
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8215
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8217
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8218
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8219
     * Removes a PropertyChangeListener from the listener list. This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8220
     * should be used to remove PropertyChangeListeners that were registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8221
     * for all bound properties of this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8222
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8223
     * If listener is null, no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8224
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8225
     * @param listener the PropertyChangeListener to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8226
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8227
     * @see #addPropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8228
     * @see #getPropertyChangeListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8229
     * @see #removePropertyChangeListener(java.lang.String,java.beans.PropertyChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8230
     */
123
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8231
    public void removePropertyChangeListener(
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8232
                                                          PropertyChangeListener listener) {
1169
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
  8233
        synchronized (getObjectLock()) {
123
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8234
            if (listener == null || changeSupport == null) {
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8235
                return;
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8236
            }
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8237
            changeSupport.removePropertyChangeListener(listener);
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8238
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8240
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8241
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8242
     * Returns an array of all the property change listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8243
     * registered on this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8244
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8245
     * @return all of this component's <code>PropertyChangeListener</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8246
     *         or an empty array if no property change
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8247
     *         listeners are currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8248
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8249
     * @see      #addPropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8250
     * @see      #removePropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8251
     * @see      #getPropertyChangeListeners(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8252
     * @see      java.beans.PropertyChangeSupport#getPropertyChangeListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8253
     * @since    1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8254
     */
123
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8255
    public PropertyChangeListener[] getPropertyChangeListeners() {
1169
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
  8256
        synchronized (getObjectLock()) {
123
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8257
            if (changeSupport == null) {
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8258
                return new PropertyChangeListener[0];
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8259
            }
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8260
            return changeSupport.getPropertyChangeListeners();
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8261
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8263
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8264
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8265
     * Adds a PropertyChangeListener to the listener list for a specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8266
     * property. The specified property may be user-defined, or one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8267
     * following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8268
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8269
     *    <li>this Component's font ("font")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8270
     *    <li>this Component's background color ("background")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8271
     *    <li>this Component's foreground color ("foreground")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8272
     *    <li>this Component's focusability ("focusable")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8273
     *    <li>this Component's focus traversal keys enabled state
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8274
     *        ("focusTraversalKeysEnabled")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8275
     *    <li>this Component's Set of FORWARD_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8276
     *        ("forwardFocusTraversalKeys")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8277
     *    <li>this Component's Set of BACKWARD_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8278
     *        ("backwardFocusTraversalKeys")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8279
     *    <li>this Component's Set of UP_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8280
     *        ("upCycleFocusTraversalKeys")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8281
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8282
     * Note that if this <code>Component</code> is inheriting a bound property, then no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8283
     * event will be fired in response to a change in the inherited property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8284
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8285
     * If <code>propertyName</code> or <code>listener</code> is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8286
     * no exception is thrown and no action is taken.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8287
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8288
     * @param propertyName one of the property names listed above
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8289
     * @param listener the property change listener to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8290
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8291
     * @see #removePropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8292
     * @see #getPropertyChangeListeners(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8293
     * @see #addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8294
     */
123
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8295
    public void addPropertyChangeListener(
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8296
                                                       String propertyName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8297
                                                       PropertyChangeListener listener) {
1169
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
  8298
        synchronized (getObjectLock()) {
123
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8299
            if (listener == null) {
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8300
                return;
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8301
            }
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8302
            if (changeSupport == null) {
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8303
                changeSupport = new PropertyChangeSupport(this);
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8304
            }
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8305
            changeSupport.addPropertyChangeListener(propertyName, listener);
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8306
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8307
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8308
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8309
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8310
     * Removes a <code>PropertyChangeListener</code> from the listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8311
     * list for a specific property. This method should be used to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8312
     * <code>PropertyChangeListener</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8313
     * that were registered for a specific bound property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8314
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8315
     * If <code>propertyName</code> or <code>listener</code> is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8316
     * no exception is thrown and no action is taken.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8317
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8318
     * @param propertyName a valid property name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8319
     * @param listener the PropertyChangeListener to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8320
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8321
     * @see #addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8322
     * @see #getPropertyChangeListeners(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8323
     * @see #removePropertyChangeListener(java.beans.PropertyChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8324
     */
123
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8325
    public void removePropertyChangeListener(
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8326
                                                          String propertyName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8327
                                                          PropertyChangeListener listener) {
1169
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
  8328
        synchronized (getObjectLock()) {
123
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8329
            if (listener == null || changeSupport == null) {
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8330
                return;
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8331
            }
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8332
            changeSupport.removePropertyChangeListener(propertyName, listener);
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8333
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8334
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8335
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8336
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8337
     * Returns an array of all the listeners which have been associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8338
     * with the named property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8339
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8340
     * @return all of the <code>PropertyChangeListener</code>s associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8341
     *         the named property; if no such listeners have been added or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8342
     *         if <code>propertyName</code> is <code>null</code>, an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8343
     *         array is returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8344
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8345
     * @see #addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8346
     * @see #removePropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8347
     * @see #getPropertyChangeListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8348
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8349
     */
123
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8350
    public PropertyChangeListener[] getPropertyChangeListeners(
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8351
                                                                            String propertyName) {
1169
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
  8352
        synchronized (getObjectLock()) {
123
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8353
            if (changeSupport == null) {
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8354
                return new PropertyChangeListener[0];
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8355
            }
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8356
            return changeSupport.getPropertyChangeListeners(propertyName);
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8357
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8358
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8359
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8360
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8361
     * Support for reporting bound property changes for Object properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8362
     * This method can be called when a bound property has changed and it will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8363
     * send the appropriate PropertyChangeEvent to any registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8364
     * PropertyChangeListeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8365
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8366
     * @param propertyName the property whose value has changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8367
     * @param oldValue the property's previous value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8368
     * @param newValue the property's new value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8369
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8370
    protected void firePropertyChange(String propertyName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8371
                                      Object oldValue, Object newValue) {
123
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8372
        PropertyChangeSupport changeSupport;
1169
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
  8373
        synchronized (getObjectLock()) {
123
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8374
            changeSupport = this.changeSupport;
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8375
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8376
        if (changeSupport == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8377
            (oldValue != null && newValue != null && oldValue.equals(newValue))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8378
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8379
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8380
        changeSupport.firePropertyChange(propertyName, oldValue, newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8381
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8382
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8383
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8384
     * Support for reporting bound property changes for boolean properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8385
     * This method can be called when a bound property has changed and it will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8386
     * send the appropriate PropertyChangeEvent to any registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8387
     * PropertyChangeListeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8388
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8389
     * @param propertyName the property whose value has changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8390
     * @param oldValue the property's previous value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8391
     * @param newValue the property's new value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8392
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8393
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8394
    protected void firePropertyChange(String propertyName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8395
                                      boolean oldValue, boolean newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8396
        PropertyChangeSupport changeSupport = this.changeSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8397
        if (changeSupport == null || oldValue == newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8398
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8399
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8400
        changeSupport.firePropertyChange(propertyName, oldValue, newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8401
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8402
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8403
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8404
     * Support for reporting bound property changes for integer properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8405
     * This method can be called when a bound property has changed and it will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8406
     * send the appropriate PropertyChangeEvent to any registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8407
     * PropertyChangeListeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8408
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8409
     * @param propertyName the property whose value has changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8410
     * @param oldValue the property's previous value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8411
     * @param newValue the property's new value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8412
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8413
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8414
    protected void firePropertyChange(String propertyName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8415
                                      int oldValue, int newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8416
        PropertyChangeSupport changeSupport = this.changeSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8417
        if (changeSupport == null || oldValue == newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8418
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8419
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8420
        changeSupport.firePropertyChange(propertyName, oldValue, newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8421
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8422
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8423
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8424
     * Reports a bound property change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8425
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8426
     * @param propertyName the programmatic name of the property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8427
     *          that was changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8428
     * @param oldValue the old value of the property (as a byte)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8429
     * @param newValue the new value of the property (as a byte)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8430
     * @see #firePropertyChange(java.lang.String, java.lang.Object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8431
     *          java.lang.Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8432
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8433
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8434
    public void firePropertyChange(String propertyName, byte oldValue, byte newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8435
        if (changeSupport == null || oldValue == newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8436
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8437
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8438
        firePropertyChange(propertyName, Byte.valueOf(oldValue), Byte.valueOf(newValue));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8439
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8440
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8441
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8442
     * Reports a bound property change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8443
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8444
     * @param propertyName the programmatic name of the property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8445
     *          that was changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8446
     * @param oldValue the old value of the property (as a char)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8447
     * @param newValue the new value of the property (as a char)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8448
     * @see #firePropertyChange(java.lang.String, java.lang.Object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8449
     *          java.lang.Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8450
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8451
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8452
    public void firePropertyChange(String propertyName, char oldValue, char newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8453
        if (changeSupport == null || oldValue == newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8454
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8455
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8456
        firePropertyChange(propertyName, new Character(oldValue), new Character(newValue));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8457
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8458
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8459
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8460
     * Reports a bound property change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8461
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8462
     * @param propertyName the programmatic name of the property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8463
     *          that was changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8464
     * @param oldValue the old value of the property (as a short)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8465
     * @param newValue the old value of the property (as a short)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8466
     * @see #firePropertyChange(java.lang.String, java.lang.Object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8467
     *          java.lang.Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8468
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8469
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8470
    public void firePropertyChange(String propertyName, short oldValue, short newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8471
        if (changeSupport == null || oldValue == newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8472
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8473
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8474
        firePropertyChange(propertyName, Short.valueOf(oldValue), Short.valueOf(newValue));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8475
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8476
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8477
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8478
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8479
     * Reports a bound property change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8480
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8481
     * @param propertyName the programmatic name of the property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8482
     *          that was changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8483
     * @param oldValue the old value of the property (as a long)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8484
     * @param newValue the new value of the property (as a long)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8485
     * @see #firePropertyChange(java.lang.String, java.lang.Object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8486
     *          java.lang.Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8487
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8488
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8489
    public void firePropertyChange(String propertyName, long oldValue, long newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8490
        if (changeSupport == null || oldValue == newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8491
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8492
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8493
        firePropertyChange(propertyName, Long.valueOf(oldValue), Long.valueOf(newValue));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8494
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8495
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8496
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8497
     * Reports a bound property change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8498
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8499
     * @param propertyName the programmatic name of the property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8500
     *          that was changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8501
     * @param oldValue the old value of the property (as a float)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8502
     * @param newValue the new value of the property (as a float)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8503
     * @see #firePropertyChange(java.lang.String, java.lang.Object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8504
     *          java.lang.Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8505
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8506
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8507
    public void firePropertyChange(String propertyName, float oldValue, float newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8508
        if (changeSupport == null || oldValue == newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8509
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8510
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8511
        firePropertyChange(propertyName, Float.valueOf(oldValue), Float.valueOf(newValue));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8512
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8513
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8514
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8515
     * Reports a bound property change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8516
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8517
     * @param propertyName the programmatic name of the property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8518
     *          that was changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8519
     * @param oldValue the old value of the property (as a double)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8520
     * @param newValue the new value of the property (as a double)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8521
     * @see #firePropertyChange(java.lang.String, java.lang.Object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8522
     *          java.lang.Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8523
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8524
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8525
    public void firePropertyChange(String propertyName, double oldValue, double newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8526
        if (changeSupport == null || oldValue == newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8527
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8528
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8529
        firePropertyChange(propertyName, Double.valueOf(oldValue), Double.valueOf(newValue));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8530
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8531
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8532
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8533
    // Serialization support.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8534
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8535
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8536
     * Component Serialized Data Version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8537
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8538
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8539
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8540
    private int componentSerializedDataVersion = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8541
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8542
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8543
     * This hack is for Swing serialization. It will invoke
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8544
     * the Swing package private method <code>compWriteObjectNotify</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8545
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8546
    private void doSwingSerialization() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8547
        Package swingPackage = Package.getPackage("javax.swing");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8548
        // For Swing serialization to correctly work Swing needs to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8549
        // be notified before Component does it's serialization.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8550
        // hack accomodates this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8551
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8552
        // Swing classes MUST be loaded by the bootstrap class loader,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8553
        // otherwise we don't consider them.
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  8554
        for (Class<?> klass = Component.this.getClass(); klass != null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8555
                   klass = klass.getSuperclass()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8556
            if (klass.getPackage() == swingPackage &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8557
                      klass.getClassLoader() == null) {
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  8558
                final Class<?> swingClass = klass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8559
                // Find the first override of the compWriteObjectNotify method
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  8560
                Method[] methods = AccessController.doPrivileged(
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  8561
                                                                 new PrivilegedAction<Method[]>() {
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  8562
                                                                     public Method[] run() {
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  8563
                                                                         return swingClass.getDeclaredMethods();
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  8564
                                                                     }
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  8565
                                                                 });
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8566
                for (int counter = methods.length - 1; counter >= 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8567
                     counter--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8568
                    final Method method = methods[counter];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8569
                    if (method.getName().equals("compWriteObjectNotify")){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8570
                        // We found it, use doPrivileged to make it accessible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8571
                        // to use.
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  8572
                        AccessController.doPrivileged(new PrivilegedAction<Void>() {
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  8573
                                public Void run() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8574
                                    method.setAccessible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8575
                                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8576
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8577
                            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8578
                        // Invoke the method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8579
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8580
                            method.invoke(this, (Object[]) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8581
                        } catch (IllegalAccessException iae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8582
                        } catch (InvocationTargetException ite) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8583
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8584
                        // We're done, bail.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8585
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8586
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8587
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8588
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8589
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8590
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8591
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8592
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8593
     * Writes default serializable fields to stream.  Writes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8594
     * a variety of serializable listeners as optional data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8595
     * The non-serializable listeners are detected and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8596
     * no attempt is made to serialize them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8597
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8598
     * @param s the <code>ObjectOutputStream</code> to write
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8599
     * @serialData <code>null</code> terminated sequence of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8600
     *   0 or more pairs; the pair consists of a <code>String</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8601
     *   and an <code>Object</code>; the <code>String</code> indicates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8602
     *   the type of object and is one of the following (as of 1.4):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8603
     *   <code>componentListenerK</code> indicating an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8604
     *     <code>ComponentListener</code> object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8605
     *   <code>focusListenerK</code> indicating an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8606
     *     <code>FocusListener</code> object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8607
     *   <code>keyListenerK</code> indicating an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8608
     *     <code>KeyListener</code> object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8609
     *   <code>mouseListenerK</code> indicating an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8610
     *     <code>MouseListener</code> object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8611
     *   <code>mouseMotionListenerK</code> indicating an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8612
     *     <code>MouseMotionListener</code> object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8613
     *   <code>inputMethodListenerK</code> indicating an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8614
     *     <code>InputMethodListener</code> object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8615
     *   <code>hierarchyListenerK</code> indicating an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8616
     *     <code>HierarchyListener</code> object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8617
     *   <code>hierarchyBoundsListenerK</code> indicating an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8618
     *     <code>HierarchyBoundsListener</code> object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8619
     *   <code>mouseWheelListenerK</code> indicating an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8620
     *     <code>MouseWheelListener</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8621
     * @serialData an optional <code>ComponentOrientation</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8622
     *    (after <code>inputMethodListener</code>, as of 1.2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8623
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8624
     * @see AWTEventMulticaster#save(java.io.ObjectOutputStream, java.lang.String, java.util.EventListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8625
     * @see #componentListenerK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8626
     * @see #focusListenerK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8627
     * @see #keyListenerK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8628
     * @see #mouseListenerK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8629
     * @see #mouseMotionListenerK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8630
     * @see #inputMethodListenerK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8631
     * @see #hierarchyListenerK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8632
     * @see #hierarchyBoundsListenerK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8633
     * @see #mouseWheelListenerK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8634
     * @see #readObject(ObjectInputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8635
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8636
    private void writeObject(ObjectOutputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8637
      throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8638
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8639
        doSwingSerialization();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8640
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8641
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8642
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8643
        AWTEventMulticaster.save(s, componentListenerK, componentListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8644
        AWTEventMulticaster.save(s, focusListenerK, focusListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8645
        AWTEventMulticaster.save(s, keyListenerK, keyListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8646
        AWTEventMulticaster.save(s, mouseListenerK, mouseListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8647
        AWTEventMulticaster.save(s, mouseMotionListenerK, mouseMotionListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8648
        AWTEventMulticaster.save(s, inputMethodListenerK, inputMethodListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8649
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8650
        s.writeObject(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8651
        s.writeObject(componentOrientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8652
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8653
        AWTEventMulticaster.save(s, hierarchyListenerK, hierarchyListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8654
        AWTEventMulticaster.save(s, hierarchyBoundsListenerK,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8655
                                 hierarchyBoundsListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8656
        s.writeObject(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8657
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8658
        AWTEventMulticaster.save(s, mouseWheelListenerK, mouseWheelListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8659
        s.writeObject(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8660
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8661
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8662
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8663
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8664
     * Reads the <code>ObjectInputStream</code> and if it isn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8665
     * <code>null</code> adds a listener to receive a variety
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8666
     * of events fired by the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8667
     * Unrecognized keys or values will be ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8668
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8669
     * @param s the <code>ObjectInputStream</code> to read
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8670
     * @see #writeObject(ObjectOutputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8671
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8672
    private void readObject(ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8673
      throws ClassNotFoundException, IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8674
    {
1169
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
  8675
        objectLock = new Object();
432
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents: 130
diff changeset
  8676
8816
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
  8677
        acc = AccessController.getContext();
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
  8678
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8679
        s.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8680
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8681
        appContext = AppContext.getAppContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8682
        coalescingEnabled = checkCoalescing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8683
        if (componentSerializedDataVersion < 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8684
            // These fields are non-transient and rely on default
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8685
            // serialization. However, the default values are insufficient,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8686
            // so we need to set them explicitly for object data streams prior
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8687
            // to 1.4.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8688
            focusable = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8689
            isFocusTraversableOverridden = FOCUS_TRAVERSABLE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8690
            initializeFocusTraversalKeys();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8691
            focusTraversalKeysEnabled = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8692
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8693
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8694
        Object keyOrNull;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8695
        while(null != (keyOrNull = s.readObject())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8696
            String key = ((String)keyOrNull).intern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8697
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8698
            if (componentListenerK == key)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8699
                addComponentListener((ComponentListener)(s.readObject()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8700
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8701
            else if (focusListenerK == key)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8702
                addFocusListener((FocusListener)(s.readObject()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8703
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8704
            else if (keyListenerK == key)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8705
                addKeyListener((KeyListener)(s.readObject()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8706
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8707
            else if (mouseListenerK == key)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8708
                addMouseListener((MouseListener)(s.readObject()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8709
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8710
            else if (mouseMotionListenerK == key)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8711
                addMouseMotionListener((MouseMotionListener)(s.readObject()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8712
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8713
            else if (inputMethodListenerK == key)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8714
                addInputMethodListener((InputMethodListener)(s.readObject()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8715
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8716
            else // skip value for unrecognized key
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8717
                s.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8718
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8719
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8720
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8721
        // Read the component's orientation if it's present
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8722
        Object orient = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8723
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8724
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8725
            orient = s.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8726
        } catch (java.io.OptionalDataException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8727
            // JDK 1.1 instances will not have this optional data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8728
            // e.eof will be true to indicate that there is no more
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8729
            // data available for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8730
            // If e.eof is not true, throw the exception as it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8731
            // might have been caused by reasons unrelated to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8732
            // componentOrientation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8733
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8734
            if (!e.eof)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8735
                throw (e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8736
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8737
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8738
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8739
        if (orient != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8740
            componentOrientation = (ComponentOrientation)orient;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8741
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8742
            componentOrientation = ComponentOrientation.UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8743
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8744
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8745
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8746
            while(null != (keyOrNull = s.readObject())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8747
                String key = ((String)keyOrNull).intern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8748
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8749
                if (hierarchyListenerK == key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8750
                    addHierarchyListener((HierarchyListener)(s.readObject()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8751
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8752
                else if (hierarchyBoundsListenerK == key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8753
                    addHierarchyBoundsListener((HierarchyBoundsListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8754
                                               (s.readObject()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8755
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8756
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8757
                    // skip value for unrecognized key
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8758
                    s.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8759
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8760
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8761
        } catch (java.io.OptionalDataException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8762
            // JDK 1.1/1.2 instances will not have this optional data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8763
            // e.eof will be true to indicate that there is no more
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8764
            // data available for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8765
            // If e.eof is not true, throw the exception as it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8766
            // might have been caused by reasons unrelated to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8767
            // hierarchy and hierarchyBounds listeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8768
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8769
            if (!e.eof)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8770
                throw (e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8771
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8772
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8773
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8774
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8775
            while (null != (keyOrNull = s.readObject())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8776
                String key = ((String)keyOrNull).intern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8777
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8778
                if (mouseWheelListenerK == key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8779
                    addMouseWheelListener((MouseWheelListener)(s.readObject()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8780
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8781
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8782
                    // skip value for unrecognized key
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8783
                    s.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8784
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8785
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8786
        } catch (java.io.OptionalDataException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8787
            // pre-1.3 instances will not have this optional data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8788
            // e.eof will be true to indicate that there is no more
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8789
            // data available for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8790
            // If e.eof is not true, throw the exception as it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8791
            // might have been caused by reasons unrelated to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8792
            // mouse wheel listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8793
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8794
            if (!e.eof)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8795
                throw (e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8796
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8797
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8798
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8799
        if (popups != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8800
            int npopups = popups.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8801
            for (int i = 0 ; i < npopups ; i++) {
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  8802
                PopupMenu popup = popups.elementAt(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8803
                popup.parent = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8804
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8805
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8806
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8807
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8808
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8809
     * Sets the language-sensitive orientation that is to be used to order
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8810
     * the elements or text within this component.  Language-sensitive
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8811
     * <code>LayoutManager</code> and <code>Component</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8812
     * subclasses will use this property to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8813
     * determine how to lay out and draw components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8814
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8815
     * At construction time, a component's orientation is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8816
     * <code>ComponentOrientation.UNKNOWN</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8817
     * indicating that it has not been specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8818
     * explicitly.  The UNKNOWN orientation behaves the same as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8819
     * <code>ComponentOrientation.LEFT_TO_RIGHT</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8820
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8821
     * To set the orientation of a single component, use this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8822
     * To set the orientation of an entire component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8823
     * hierarchy, use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8824
     * {@link #applyComponentOrientation applyComponentOrientation}.
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  8825
     * <p>
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  8826
     * This method changes layout-related information, and therefore,
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  8827
     * invalidates the component hierarchy.
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  8828
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8829
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8830
     * @see ComponentOrientation
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  8831
     * @see #invalidate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8832
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8833
     * @author Laura Werner, IBM
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8834
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8835
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8836
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8837
    public void setComponentOrientation(ComponentOrientation o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8838
        ComponentOrientation oldValue = componentOrientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8839
        componentOrientation = o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8840
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8841
        // This is a bound property, so report the change to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8842
        // any registered listeners.  (Cheap if there are none.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8843
        firePropertyChange("componentOrientation", oldValue, o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8844
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8845
        // This could change the preferred size of the Component.
1183
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
  8846
        invalidateIfValid();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8847
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8848
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8849
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8850
     * Retrieves the language-sensitive orientation that is to be used to order
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8851
     * the elements or text within this component.  <code>LayoutManager</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8852
     * and <code>Component</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8853
     * subclasses that wish to respect orientation should call this method to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8854
     * get the component's orientation before performing layout or drawing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8855
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8856
     * @see ComponentOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8857
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8858
     * @author Laura Werner, IBM
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8859
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8860
    public ComponentOrientation getComponentOrientation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8861
        return componentOrientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8862
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8863
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8864
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8865
     * Sets the <code>ComponentOrientation</code> property of this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8866
     * and all components contained within it.
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  8867
     * <p>
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  8868
     * This method changes layout-related information, and therefore,
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  8869
     * invalidates the component hierarchy.
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  8870
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8871
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8872
     * @param orientation the new component orientation of this component and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8873
     *        the components contained within it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8874
     * @exception NullPointerException if <code>orientation</code> is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8875
     * @see #setComponentOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8876
     * @see #getComponentOrientation
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  8877
     * @see #invalidate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8878
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8879
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8880
    public void applyComponentOrientation(ComponentOrientation orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8881
        if (orientation == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8882
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8883
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8884
        setComponentOrientation(orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8885
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8886
1171
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 1169
diff changeset
  8887
    final boolean canBeFocusOwner() {
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 1169
diff changeset
  8888
        // It is enabled, visible, focusable.
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 1169
diff changeset
  8889
        if (isEnabled() && isDisplayable() && isVisible() && isFocusable()) {
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 1169
diff changeset
  8890
            return true;
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 1169
diff changeset
  8891
        }
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 1169
diff changeset
  8892
        return false;
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 1169
diff changeset
  8893
    }
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 1169
diff changeset
  8894
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8895
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8896
     * Checks that this component meets the prerequesites to be focus owner:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8897
     * - it is enabled, visible, focusable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8898
     * - it's parents are all enabled and showing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8899
     * - top-level window is focusable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8900
     * - if focus cycle root has DefaultFocusTraversalPolicy then it also checks that this policy accepts
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8901
     * this component as focus owner
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8902
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8903
     */
1171
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 1169
diff changeset
  8904
    final boolean canBeFocusOwnerRecursively() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8905
        // - it is enabled, visible, focusable
1171
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 1169
diff changeset
  8906
        if (!canBeFocusOwner()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8907
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8908
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8909
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8910
        // - it's parents are all enabled and showing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8911
        synchronized(getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8912
            if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8913
                return parent.canContainFocusOwner(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8914
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8915
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8916
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8917
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8918
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8919
    /**
130
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 126
diff changeset
  8920
     * Fix the location of the HW component in a LW container hierarchy.
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 126
diff changeset
  8921
     */
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 126
diff changeset
  8922
    final void relocateComponent() {
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 126
diff changeset
  8923
        synchronized (getTreeLock()) {
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 126
diff changeset
  8924
            if (peer == null) {
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 126
diff changeset
  8925
                return;
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 126
diff changeset
  8926
            }
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 126
diff changeset
  8927
            int nativeX = x;
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 126
diff changeset
  8928
            int nativeY = y;
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 126
diff changeset
  8929
            for (Component cont = getContainer();
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 126
diff changeset
  8930
                    cont != null && cont.isLightweight();
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 126
diff changeset
  8931
                    cont = cont.getContainer())
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8932
            {
130
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 126
diff changeset
  8933
                nativeX += cont.x;
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 126
diff changeset
  8934
                nativeY += cont.y;
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 126
diff changeset
  8935
            }
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 126
diff changeset
  8936
            peer.setBounds(nativeX, nativeY, width, height,
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 126
diff changeset
  8937
                    ComponentPeer.SET_LOCATION);
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 126
diff changeset
  8938
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8939
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8940
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8941
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8942
     * Returns the <code>Window</code> ancestor of the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8943
     * @return Window ancestor of the component or component by itself if it is Window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8944
     *         null, if component is not a part of window hierarchy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8945
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8946
    Window getContainingWindow() {
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
  8947
        return SunToolkit.getContainingWindow(this);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
  8948
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8949
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8950
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8951
     * Initialize JNI field and method IDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8952
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8953
    private static native void initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8954
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8955
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8956
     * --- Accessibility Support ---
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8957
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8958
     *  Component will contain all of the methods in interface Accessible,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8959
     *  though it won't actually implement the interface - that will be up
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8960
     *  to the individual objects which extend Component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8961
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8962
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8963
    AccessibleContext accessibleContext = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8964
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8965
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8966
     * Gets the <code>AccessibleContext</code> associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8967
     * with this <code>Component</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8968
     * The method implemented by this base
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8969
     * class returns null.  Classes that extend <code>Component</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8970
     * should implement this method to return the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8971
     * <code>AccessibleContext</code> associated with the subclass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8972
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8973
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8974
     * @return the <code>AccessibleContext</code> of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8975
     *    <code>Component</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8976
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8977
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8978
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8979
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8980
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8981
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8982
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8983
     * Inner class of Component used to provide default support for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8984
     * accessibility.  This class is not meant to be used directly by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8985
     * application developers, but is instead meant only to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8986
     * subclassed by component developers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8987
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8988
     * The class used to obtain the accessible role for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8989
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8990
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8991
    protected abstract class AccessibleAWTComponent extends AccessibleContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8992
        implements Serializable, AccessibleComponent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8993
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8994
        private static final long serialVersionUID = 642321655757800191L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8995
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8996
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8997
         * Though the class is abstract, this should be called by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8998
         * all sub-classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8999
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9000
        protected AccessibleAWTComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9001
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9002
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9003
        protected ComponentListener accessibleAWTComponentHandler = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9004
        protected FocusListener accessibleAWTFocusHandler = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9005
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9006
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9007
         * Fire PropertyChange listener, if one is registered,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9008
         * when shown/hidden..
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9009
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9010
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9011
        protected class AccessibleAWTComponentHandler implements ComponentListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9012
            public void componentHidden(ComponentEvent e)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9013
                if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9014
                    accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9015
                                                         AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9016
                                                         AccessibleState.VISIBLE, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9017
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9018
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9019
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9020
            public void componentShown(ComponentEvent e)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9021
                if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9022
                    accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9023
                                                         AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9024
                                                         null, AccessibleState.VISIBLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9025
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9026
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9027
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9028
            public void componentMoved(ComponentEvent e)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9029
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9030
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9031
            public void componentResized(ComponentEvent e)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9032
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9033
        } // inner class AccessibleAWTComponentHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9034
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9035
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9036
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9037
         * Fire PropertyChange listener, if one is registered,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9038
         * when focus events happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9039
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9040
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9041
        protected class AccessibleAWTFocusHandler implements FocusListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9042
            public void focusGained(FocusEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9043
                if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9044
                    accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9045
                                                         AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9046
                                                         null, AccessibleState.FOCUSED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9047
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9048
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9049
            public void focusLost(FocusEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9050
                if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9051
                    accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9052
                                                         AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9053
                                                         AccessibleState.FOCUSED, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9054
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9055
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9056
        }  // inner class AccessibleAWTFocusHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9057
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9058
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9059
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9060
         * Adds a <code>PropertyChangeListener</code> to the listener list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9061
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9062
         * @param listener  the property change listener to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9063
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9064
        public void addPropertyChangeListener(PropertyChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9065
            if (accessibleAWTComponentHandler == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9066
                accessibleAWTComponentHandler = new AccessibleAWTComponentHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9067
                Component.this.addComponentListener(accessibleAWTComponentHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9068
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9069
            if (accessibleAWTFocusHandler == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9070
                accessibleAWTFocusHandler = new AccessibleAWTFocusHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9071
                Component.this.addFocusListener(accessibleAWTFocusHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9072
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9073
            super.addPropertyChangeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9074
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9075
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9076
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9077
         * Remove a PropertyChangeListener from the listener list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9078
         * This removes a PropertyChangeListener that was registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9079
         * for all properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9080
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9081
         * @param listener  The PropertyChangeListener to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9082
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9083
        public void removePropertyChangeListener(PropertyChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9084
            if (accessibleAWTComponentHandler != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9085
                Component.this.removeComponentListener(accessibleAWTComponentHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9086
                accessibleAWTComponentHandler = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9087
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9088
            if (accessibleAWTFocusHandler != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9089
                Component.this.removeFocusListener(accessibleAWTFocusHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9090
                accessibleAWTFocusHandler = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9091
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9092
            super.removePropertyChangeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9093
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9094
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9095
        // AccessibleContext methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9096
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9097
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9098
         * Gets the accessible name of this object.  This should almost never
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9099
         * return <code>java.awt.Component.getName()</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9100
         * as that generally isn't a localized name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9101
         * and doesn't have meaning for the user.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9102
         * object is fundamentally a text object (e.g. a menu item), the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9103
         * accessible name should be the text of the object (e.g. "save").
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9104
         * If the object has a tooltip, the tooltip text may also be an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9105
         * appropriate String to return.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9106
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9107
         * @return the localized name of the object -- can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9108
         *         <code>null</code> if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9109
         *         object does not have a name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9110
         * @see javax.accessibility.AccessibleContext#setAccessibleName
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9111
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9112
        public String getAccessibleName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9113
            return accessibleName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9114
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9115
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9116
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9117
         * Gets the accessible description of this object.  This should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9118
         * a concise, localized description of what this object is - what
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9119
         * is its meaning to the user.  If the object has a tooltip, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9120
         * tooltip text may be an appropriate string to return, assuming
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9121
         * it contains a concise description of the object (instead of just
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9122
         * the name of the object - e.g. a "Save" icon on a toolbar that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9123
         * had "save" as the tooltip text shouldn't return the tooltip
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9124
         * text as the description, but something like "Saves the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9125
         * text document" instead).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9126
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9127
         * @return the localized description of the object -- can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9128
         *        <code>null</code> if this object does not have a description
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9129
         * @see javax.accessibility.AccessibleContext#setAccessibleDescription
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9130
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9131
        public String getAccessibleDescription() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9132
            return accessibleDescription;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9133
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9134
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9135
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9136
         * Gets the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9137
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9138
         * @return an instance of <code>AccessibleRole</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9139
         *      describing the role of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9140
         * @see javax.accessibility.AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9141
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9142
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9143
            return AccessibleRole.AWT_COMPONENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9145
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9146
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9147
         * Gets the state of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9148
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9149
         * @return an instance of <code>AccessibleStateSet</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9150
         *       containing the current state set of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9151
         * @see javax.accessibility.AccessibleState
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9152
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9153
        public AccessibleStateSet getAccessibleStateSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9154
            return Component.this.getAccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9156
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9157
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9158
         * Gets the <code>Accessible</code> parent of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9159
         * If the parent of this object implements <code>Accessible</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9160
         * this method should simply return <code>getParent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9161
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9162
         * @return the <code>Accessible</code> parent of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9163
         *      object -- can be <code>null</code> if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9164
         *      object does not have an <code>Accessible</code> parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9165
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9166
        public Accessible getAccessibleParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9167
            if (accessibleParent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9168
                return accessibleParent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9169
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9170
                Container parent = getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9171
                if (parent instanceof Accessible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9172
                    return (Accessible) parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9173
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9174
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9175
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9176
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9177
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9178
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9179
         * Gets the index of this object in its accessible parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9180
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9181
         * @return the index of this object in its parent; or -1 if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9182
         *    object does not have an accessible parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9183
         * @see #getAccessibleParent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9184
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9185
        public int getAccessibleIndexInParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9186
            return Component.this.getAccessibleIndexInParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9188
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9189
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9190
         * Returns the number of accessible children in the object.  If all
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9191
         * of the children of this object implement <code>Accessible</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9192
         * then this method should return the number of children of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9193
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9194
         * @return the number of accessible children in the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9195
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9196
        public int getAccessibleChildrenCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9197
            return 0; // Components don't have children
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9198
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9199
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9200
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9201
         * Returns the nth <code>Accessible</code> child of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9202
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9203
         * @param i zero-based index of child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9204
         * @return the nth <code>Accessible</code> child of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9205
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9206
        public Accessible getAccessibleChild(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9207
            return null; // Components don't have children
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9208
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9209
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9210
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9211
         * Returns the locale of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9212
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9213
         * @return the locale of this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9214
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9215
        public Locale getLocale() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9216
            return Component.this.getLocale();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9217
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9218
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9219
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9220
         * Gets the <code>AccessibleComponent</code> associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9221
         * with this object if one exists.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9222
         * Otherwise return <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9223
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9224
         * @return the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9225
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9226
        public AccessibleComponent getAccessibleComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9227
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9229
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9230
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9231
        // AccessibleComponent methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9232
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9233
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9234
         * Gets the background color of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9235
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9236
         * @return the background color, if supported, of the object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9237
         *      otherwise, <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9238
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9239
        public Color getBackground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9240
            return Component.this.getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9242
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9243
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9244
         * Sets the background color of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9245
         * (For transparency, see <code>isOpaque</code>.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9246
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9247
         * @param c the new <code>Color</code> for the background
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9248
         * @see Component#isOpaque
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9249
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9250
        public void setBackground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9251
            Component.this.setBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9252
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9253
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9254
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9255
         * Gets the foreground color of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9256
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9257
         * @return the foreground color, if supported, of the object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9258
         *     otherwise, <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9259
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9260
        public Color getForeground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9261
            return Component.this.getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9262
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9263
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9264
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9265
         * Sets the foreground color of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9266
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9267
         * @param c the new <code>Color</code> for the foreground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9268
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9269
        public void setForeground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9270
            Component.this.setForeground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9271
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9272
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9273
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9274
         * Gets the <code>Cursor</code> of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9275
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9276
         * @return the <code>Cursor</code>, if supported,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9277
         *     of the object; otherwise, <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9278
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9279
        public Cursor getCursor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9280
            return Component.this.getCursor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9281
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9282
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9283
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9284
         * Sets the <code>Cursor</code> of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9285
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9286
         * The method may have no visual effect if the Java platform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9287
         * implementation and/or the native system do not support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9288
         * changing the mouse cursor shape.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9289
         * @param cursor the new <code>Cursor</code> for the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9290
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9291
        public void setCursor(Cursor cursor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9292
            Component.this.setCursor(cursor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9293
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9294
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9295
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9296
         * Gets the <code>Font</code> of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9297
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9298
         * @return the <code>Font</code>, if supported,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9299
         *    for the object; otherwise, <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9300
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9301
        public Font getFont() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9302
            return Component.this.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9303
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9304
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9305
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9306
         * Sets the <code>Font</code> of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9307
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9308
         * @param f the new <code>Font</code> for the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9309
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9310
        public void setFont(Font f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9311
            Component.this.setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9312
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9313
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9314
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9315
         * Gets the <code>FontMetrics</code> of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9316
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9317
         * @param f the <code>Font</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9318
         * @return the <code>FontMetrics</code>, if supported,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9319
         *     the object; otherwise, <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9320
         * @see #getFont
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9321
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9322
        public FontMetrics getFontMetrics(Font f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9323
            if (f == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9324
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9325
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9326
                return Component.this.getFontMetrics(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9327
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9328
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9329
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9330
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9331
         * Determines if the object is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9332
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9333
         * @return true if object is enabled; otherwise, false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9334
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9335
        public boolean isEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9336
            return Component.this.isEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9337
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9338
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9339
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9340
         * Sets the enabled state of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9341
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9342
         * @param b if true, enables this object; otherwise, disables it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9343
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9344
        public void setEnabled(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9345
            boolean old = Component.this.isEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9346
            Component.this.setEnabled(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9347
            if (b != old) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9348
                if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9349
                    if (b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9350
                        accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9351
                                                             AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9352
                                                             null, AccessibleState.ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9353
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9354
                        accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9355
                                                             AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9356
                                                             AccessibleState.ENABLED, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9357
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9358
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9359
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9360
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9361
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9362
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9363
         * Determines if the object is visible.  Note: this means that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9364
         * object intends to be visible; however, it may not in fact be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9365
         * showing on the screen because one of the objects that this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9366
         * is contained by is not visible.  To determine if an object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9367
         * showing on the screen, use <code>isShowing</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9368
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9369
         * @return true if object is visible; otherwise, false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9370
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9371
        public boolean isVisible() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9372
            return Component.this.isVisible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9373
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9374
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9375
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9376
         * Sets the visible state of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9377
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9378
         * @param b if true, shows this object; otherwise, hides it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9379
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9380
        public void setVisible(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9381
            boolean old = Component.this.isVisible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9382
            Component.this.setVisible(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9383
            if (b != old) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9384
                if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9385
                    if (b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9386
                        accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9387
                                                             AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9388
                                                             null, AccessibleState.VISIBLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9389
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9390
                        accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9391
                                                             AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9392
                                                             AccessibleState.VISIBLE, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9393
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9394
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9395
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9396
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9397
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9398
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9399
         * Determines if the object is showing.  This is determined by checking
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9400
         * the visibility of the object and ancestors of the object.  Note:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9401
         * this will return true even if the object is obscured by another
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9402
         * (for example, it happens to be underneath a menu that was pulled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9403
         * down).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9404
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9405
         * @return true if object is showing; otherwise, false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9406
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9407
        public boolean isShowing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9408
            return Component.this.isShowing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9409
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9410
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9411
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9412
         * Checks whether the specified point is within this object's bounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9413
         * where the point's x and y coordinates are defined to be relative to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9414
         * the coordinate system of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9415
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9416
         * @param p the <code>Point</code> relative to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9417
         *     coordinate system of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9418
         * @return true if object contains <code>Point</code>; otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9419
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9420
        public boolean contains(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9421
            return Component.this.contains(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9422
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9423
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9424
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9425
         * Returns the location of the object on the screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9426
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9427
         * @return location of object on screen -- can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9428
         *    <code>null</code> if this object is not on the screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9429
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9430
        public Point getLocationOnScreen() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9431
            synchronized (Component.this.getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9432
                if (Component.this.isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9433
                    return Component.this.getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9434
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9435
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9436
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9437
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9438
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9439
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9440
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9441
         * Gets the location of the object relative to the parent in the form
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9442
         * of a point specifying the object's top-left corner in the screen's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9443
         * coordinate space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9444
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9445
         * @return an instance of Point representing the top-left corner of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9446
         * the object's bounds in the coordinate space of the screen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9447
         * <code>null</code> if this object or its parent are not on the screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9448
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9449
        public Point getLocation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9450
            return Component.this.getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9451
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9452
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9453
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9454
         * Sets the location of the object relative to the parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9455
         * @param p  the coordinates of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9456
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9457
        public void setLocation(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9458
            Component.this.setLocation(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9459
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9460
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9461
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9462
         * Gets the bounds of this object in the form of a Rectangle object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9463
         * The bounds specify this object's width, height, and location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9464
         * relative to its parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9465
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9466
         * @return a rectangle indicating this component's bounds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9467
         *   <code>null</code> if this object is not on the screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9468
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9469
        public Rectangle getBounds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9470
            return Component.this.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9471
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9472
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9473
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9474
         * Sets the bounds of this object in the form of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9475
         * <code>Rectangle</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9476
         * The bounds specify this object's width, height, and location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9477
         * relative to its parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9478
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9479
         * @param r a rectangle indicating this component's bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9480
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9481
        public void setBounds(Rectangle r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9482
            Component.this.setBounds(r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9483
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9484
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9485
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9486
         * Returns the size of this object in the form of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9487
         * <code>Dimension</code> object. The height field of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9488
         * <code>Dimension</code> object contains this objects's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9489
         * height, and the width field of the <code>Dimension</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9490
         * object contains this object's width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9491
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9492
         * @return a <code>Dimension</code> object that indicates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9493
         *     the size of this component; <code>null</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9494
         *     this object is not on the screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9495
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9496
        public Dimension getSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9497
            return Component.this.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9498
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9499
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9500
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9501
         * Resizes this object so that it has width and height.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9502
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9503
         * @param d - the dimension specifying the new size of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9504
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9505
        public void setSize(Dimension d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9506
            Component.this.setSize(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9507
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9508
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9509
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9510
         * Returns the <code>Accessible</code> child,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9511
         * if one exists, contained at the local
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9512
         * coordinate <code>Point</code>.  Otherwise returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9513
         * <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9514
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9515
         * @param p the point defining the top-left corner of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9516
         *      the <code>Accessible</code>, given in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9517
         *      coordinate space of the object's parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9518
         * @return the <code>Accessible</code>, if it exists,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9519
         *      at the specified location; else <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9520
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9521
        public Accessible getAccessibleAt(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9522
            return null; // Components don't have children
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9523
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9524
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9525
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9526
         * Returns whether this object can accept focus or not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9527
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9528
         * @return true if object can accept focus; otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9529
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9530
        public boolean isFocusTraversable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9531
            return Component.this.isFocusTraversable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9532
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9533
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9534
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9535
         * Requests focus for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9536
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9537
        public void requestFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9538
            Component.this.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9539
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9540
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9541
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9542
         * Adds the specified focus listener to receive focus events from this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9543
         * component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9544
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9545
         * @param l the focus listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9546
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9547
        public void addFocusListener(FocusListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9548
            Component.this.addFocusListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9549
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9550
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9551
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9552
         * Removes the specified focus listener so it no longer receives focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9553
         * events from this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9554
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9555
         * @param l the focus listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9556
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9557
        public void removeFocusListener(FocusListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9558
            Component.this.removeFocusListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9559
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9560
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9561
    } // inner class AccessibleAWTComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9562
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9563
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9564
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9565
     * Gets the index of this object in its accessible parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9566
     * If this object does not have an accessible parent, returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9567
     * -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9568
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9569
     * @return the index of this object in its accessible parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9570
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9571
    int getAccessibleIndexInParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9572
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9573
            int index = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9574
            Container parent = this.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9575
            if (parent != null && parent instanceof Accessible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9576
                Component ca[] = parent.getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9577
                for (int i = 0; i < ca.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9578
                    if (ca[i] instanceof Accessible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9579
                        index++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9580
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9581
                    if (this.equals(ca[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9582
                        return index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9583
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9584
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9585
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9586
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9587
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9588
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9589
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9590
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9591
     * Gets the current state set of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9592
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9593
     * @return an instance of <code>AccessibleStateSet</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9594
     *    containing the current state set of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9595
     * @see AccessibleState
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9596
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9597
    AccessibleStateSet getAccessibleStateSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9598
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9599
            AccessibleStateSet states = new AccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9600
            if (this.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9601
                states.add(AccessibleState.ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9602
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9603
            if (this.isFocusTraversable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9604
                states.add(AccessibleState.FOCUSABLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9605
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9606
            if (this.isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9607
                states.add(AccessibleState.VISIBLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9608
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9609
            if (this.isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9610
                states.add(AccessibleState.SHOWING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9611
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9612
            if (this.isFocusOwner()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9613
                states.add(AccessibleState.FOCUSED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9614
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9615
            if (this instanceof Accessible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9616
                AccessibleContext ac = ((Accessible) this).getAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9617
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9618
                    Accessible ap = ac.getAccessibleParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9619
                    if (ap != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9620
                        AccessibleContext pac = ap.getAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9621
                        if (pac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9622
                            AccessibleSelection as = pac.getAccessibleSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9623
                            if (as != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9624
                                states.add(AccessibleState.SELECTABLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9625
                                int i = ac.getAccessibleIndexInParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9626
                                if (i >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9627
                                    if (as.isAccessibleChildSelected(i)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9628
                                        states.add(AccessibleState.SELECTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9629
                                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9630
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9631
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9632
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9633
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9634
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9635
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9636
            if (Component.isInstanceOf(this, "javax.swing.JComponent")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9637
                if (((javax.swing.JComponent) this).isOpaque()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9638
                    states.add(AccessibleState.OPAQUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9639
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9640
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9641
            return states;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9642
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9643
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9644
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9645
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9646
     * Checks that the given object is instance of the given class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9647
     * @param obj Object to be checked
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9648
     * @param className The name of the class. Must be fully-qualified class name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9649
     * @return true, if this object is instanceof given class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9650
     *         false, otherwise, or if obj or className is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9651
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9652
    static boolean isInstanceOf(Object obj, String className) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9653
        if (obj == null) return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9654
        if (className == null) return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9655
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  9656
        Class<?> cls = obj.getClass();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9657
        while (cls != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9658
            if (cls.getName().equals(className)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9659
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9660
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9661
            cls = cls.getSuperclass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9662
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9663
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9664
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9665
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9666
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9667
    // ************************** MIXING CODE *******************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9668
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9669
    /**
126
b37abdfa7875 6637796: setBounds doesn't enlarge Component
anthony
parents: 123
diff changeset
  9670
     * Check whether we can trust the current bounds of the component.
b37abdfa7875 6637796: setBounds doesn't enlarge Component
anthony
parents: 123
diff changeset
  9671
     * The return value of false indicates that the container of the
b37abdfa7875 6637796: setBounds doesn't enlarge Component
anthony
parents: 123
diff changeset
  9672
     * component is invalid, and therefore needs to be layed out, which would
b37abdfa7875 6637796: setBounds doesn't enlarge Component
anthony
parents: 123
diff changeset
  9673
     * probably mean changing the bounds of its children.
b37abdfa7875 6637796: setBounds doesn't enlarge Component
anthony
parents: 123
diff changeset
  9674
     * Null-layout of the container or absence of the container mean
b37abdfa7875 6637796: setBounds doesn't enlarge Component
anthony
parents: 123
diff changeset
  9675
     * the bounds of the component are final and can be trusted.
b37abdfa7875 6637796: setBounds doesn't enlarge Component
anthony
parents: 123
diff changeset
  9676
     */
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9677
    final boolean areBoundsValid() {
126
b37abdfa7875 6637796: setBounds doesn't enlarge Component
anthony
parents: 123
diff changeset
  9678
        Container cont = getContainer();
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9679
        return cont == null || cont.isValid() || cont.getLayout() == null;
126
b37abdfa7875 6637796: setBounds doesn't enlarge Component
anthony
parents: 123
diff changeset
  9680
    }
b37abdfa7875 6637796: setBounds doesn't enlarge Component
anthony
parents: 123
diff changeset
  9681
b37abdfa7875 6637796: setBounds doesn't enlarge Component
anthony
parents: 123
diff changeset
  9682
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9683
     * Applies the shape to the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9684
     * @param shape Shape to be applied to the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9685
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9686
    void applyCompoundShape(Region shape) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9687
        checkTreeLock();
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9688
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9689
        if (!areBoundsValid()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  9690
            if (mixingLog.isLoggable(PlatformLogger.FINE)) {
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9691
                mixingLog.fine("this = " + this + "; areBoundsValid = " + areBoundsValid());
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9692
            }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9693
            return;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9694
        }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9695
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9696
        if (!isLightweight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9697
            ComponentPeer peer = getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9698
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9699
                // The Region class has some optimizations. That's why
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9700
                // we should manually check whether it's empty and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9701
                // substitute the object ourselves. Otherwise we end up
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9702
                // with some incorrect Region object with loX being
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9703
                // greater than the hiX for instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9704
                if (shape.isEmpty()) {
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9705
                    shape = Region.EMPTY_REGION;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9706
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9707
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9708
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9709
                // Note: the shape is not really copied/cloned. We create
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9710
                // the Region object ourselves, so there's no any possibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9711
                // to modify the object outside of the mixing code.
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9712
                // Nullifying compoundShape means that the component has normal shape
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9713
                // (or has no shape at all).
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9714
                if (shape.equals(getNormalShape())) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9715
                    if (this.compoundShape == null) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9716
                        return;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9717
                    }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9718
                    this.compoundShape = null;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9719
                    peer.applyShape(null);
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9720
                } else {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9721
                    if (shape.equals(getAppliedShape())) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9722
                        return;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9723
                    }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9724
                    this.compoundShape = shape;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9725
                    Point compAbsolute = getLocationOnWindow();
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  9726
                    if (mixingLog.isLoggable(PlatformLogger.FINER)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9727
                        mixingLog.fine("this = " + this +
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9728
                                "; compAbsolute=" + compAbsolute + "; shape=" + shape);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9729
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9730
                    peer.applyShape(shape.getTranslatedRegion(-compAbsolute.x, -compAbsolute.y));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9731
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9732
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9733
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9734
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9735
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9736
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9737
     * Returns the shape previously set with applyCompoundShape().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9738
     * If the component is LW or no shape was applied yet,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9739
     * the method returns the normal shape.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9740
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9741
    private Region getAppliedShape() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9742
        checkTreeLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9743
        //XXX: if we allow LW components to have a shape, this must be changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9744
        return (this.compoundShape == null || isLightweight()) ? getNormalShape() : this.compoundShape;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9745
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9746
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9747
    Point getLocationOnWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9748
        checkTreeLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9749
        Point curLocation = getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9750
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9751
        for (Container parent = getContainer();
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9752
                parent != null && !(parent instanceof Window);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9753
                parent = parent.getContainer())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9754
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9755
            curLocation.x += parent.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9756
            curLocation.y += parent.getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9757
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9758
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9759
        return curLocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9760
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9761
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9762
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9763
     * Returns the full shape of the component located in window coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9764
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9765
    final Region getNormalShape() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9766
        checkTreeLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9767
        //XXX: we may take into account a user-specified shape for this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9768
        Point compAbsolute = getLocationOnWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9769
        return
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9770
            Region.getInstanceXYWH(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9771
                    compAbsolute.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9772
                    compAbsolute.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9773
                    getWidth(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9774
                    getHeight()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9775
            );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9776
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9777
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9778
    /**
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9779
     * Returns the "opaque shape" of the component.
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9780
     *
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9781
     * The opaque shape of a lightweight components is the actual shape that
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9782
     * needs to be cut off of the heavyweight components in order to mix this
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9783
     * lightweight component correctly with them.
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9784
     *
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9785
     * The method is overriden in the java.awt.Container to handle non-opaque
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9786
     * containers containing opaque children.
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9787
     *
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9788
     * See 6637655 for details.
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9789
     */
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9790
    Region getOpaqueShape() {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9791
        checkTreeLock();
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9792
        if (mixingCutoutRegion != null) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9793
            return mixingCutoutRegion;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9794
        } else {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9795
            return getNormalShape();
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9796
        }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9797
    }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9798
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9799
    final int getSiblingIndexAbove() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9800
        checkTreeLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9801
        Container parent = getContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9802
        if (parent == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9803
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9804
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9805
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9806
        int nextAbove = parent.getComponentZOrder(this) - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9807
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9808
        return nextAbove < 0 ? -1 : nextAbove;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9809
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9810
2462
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
  9811
    final ComponentPeer getHWPeerAboveMe() {
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
  9812
        checkTreeLock();
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
  9813
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
  9814
        Container cont = getContainer();
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
  9815
        int indexAbove = getSiblingIndexAbove();
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
  9816
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
  9817
        while (cont != null) {
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
  9818
            for (int i = indexAbove; i > -1; i--) {
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
  9819
                Component comp = cont.getComponent(i);
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
  9820
                if (comp != null && comp.isDisplayable() && !comp.isLightweight()) {
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
  9821
                    return comp.getPeer();
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
  9822
                }
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
  9823
            }
3727
43b25dfd1129 6852051: Getting Null Pointer Exception when displaying message for TrayIcon on Opensolaris
dcherepanov
parents: 3237
diff changeset
  9824
            // traversing the hierarchy up to the closest HW container;
43b25dfd1129 6852051: Getting Null Pointer Exception when displaying message for TrayIcon on Opensolaris
dcherepanov
parents: 3237
diff changeset
  9825
            // further traversing may return a component that is not actually
43b25dfd1129 6852051: Getting Null Pointer Exception when displaying message for TrayIcon on Opensolaris
dcherepanov
parents: 3237
diff changeset
  9826
            // a native sibling of this component and this kind of z-order
43b25dfd1129 6852051: Getting Null Pointer Exception when displaying message for TrayIcon on Opensolaris
dcherepanov
parents: 3237
diff changeset
  9827
            // request may not be allowed by the underlying system (6852051).
43b25dfd1129 6852051: Getting Null Pointer Exception when displaying message for TrayIcon on Opensolaris
dcherepanov
parents: 3237
diff changeset
  9828
            if (!cont.isLightweight()) {
43b25dfd1129 6852051: Getting Null Pointer Exception when displaying message for TrayIcon on Opensolaris
dcherepanov
parents: 3237
diff changeset
  9829
                break;
43b25dfd1129 6852051: Getting Null Pointer Exception when displaying message for TrayIcon on Opensolaris
dcherepanov
parents: 3237
diff changeset
  9830
            }
2462
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
  9831
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
  9832
            indexAbove = cont.getSiblingIndexAbove();
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
  9833
            cont = cont.getContainer();
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
  9834
        }
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
  9835
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
  9836
        return null;
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
  9837
    }
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
  9838
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9839
    final int getSiblingIndexBelow() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9840
        checkTreeLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9841
        Container parent = getContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9842
        if (parent == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9843
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9844
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9845
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9846
        int nextBelow = parent.getComponentZOrder(this) + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9847
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9848
        return nextBelow >= parent.getComponentCount() ? -1 : nextBelow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9849
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9850
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9851
    final boolean isNonOpaqueForMixing() {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9852
        return mixingCutoutRegion != null &&
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9853
            mixingCutoutRegion.isEmpty();
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9854
    }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9855
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9856
    private Region calculateCurrentShape() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9857
        checkTreeLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9858
        Region s = getNormalShape();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9859
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  9860
        if (mixingLog.isLoggable(PlatformLogger.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9861
            mixingLog.fine("this = " + this + "; normalShape=" + s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9862
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9863
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9864
        if (getContainer() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9865
            Component comp = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9866
            Container cont = comp.getContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9867
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9868
            while (cont != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9869
                for (int index = comp.getSiblingIndexAbove(); index != -1; --index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9870
                    /* It is assumed that:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9871
                     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9872
                     *    getComponent(getContainer().getComponentZOrder(comp)) == comp
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9873
                     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9874
                     * The assumption has been made according to the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9875
                     * implementation of the Container class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9876
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9877
                    Component c = cont.getComponent(index);
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9878
                    if (c.isLightweight() && c.isShowing()) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9879
                        s = s.getDifference(c.getOpaqueShape());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9880
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9881
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9882
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9883
                if (cont.isLightweight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9884
                    s = s.getIntersection(cont.getNormalShape());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9885
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9886
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9887
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9888
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9889
                comp = cont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9890
                cont = cont.getContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9891
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9892
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9893
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  9894
        if (mixingLog.isLoggable(PlatformLogger.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9895
            mixingLog.fine("currentShape=" + s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9896
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9897
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9898
        return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9899
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9900
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9901
    void applyCurrentShape() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9902
        checkTreeLock();
126
b37abdfa7875 6637796: setBounds doesn't enlarge Component
anthony
parents: 123
diff changeset
  9903
        if (!areBoundsValid()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  9904
            if (mixingLog.isLoggable(PlatformLogger.FINE)) {
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9905
                mixingLog.fine("this = " + this + "; areBoundsValid = " + areBoundsValid());
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9906
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9907
            return; // Because applyCompoundShape() ignores such components anyway
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9908
        }
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  9909
        if (mixingLog.isLoggable(PlatformLogger.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9910
            mixingLog.fine("this = " + this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9911
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9912
        applyCompoundShape(calculateCurrentShape());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9913
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9914
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9915
    final void subtractAndApplyShape(Region s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9916
        checkTreeLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9917
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  9918
        if (mixingLog.isLoggable(PlatformLogger.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9919
            mixingLog.fine("this = " + this + "; s=" + s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9920
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9921
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9922
        applyCompoundShape(getAppliedShape().getDifference(s));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9923
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9924
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9925
    private final void applyCurrentShapeBelowMe() {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9926
        checkTreeLock();
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9927
        Container parent = getContainer();
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9928
        if (parent != null && parent.isShowing()) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9929
            // First, reapply shapes of my siblings
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9930
            parent.recursiveApplyCurrentShape(getSiblingIndexBelow());
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9931
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9932
            // Second, if my container is non-opaque, reapply shapes of siblings of my container
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9933
            Container parent2 = parent.getContainer();
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9934
            while (!parent.isOpaque() && parent2 != null) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9935
                parent2.recursiveApplyCurrentShape(parent.getSiblingIndexBelow());
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9936
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9937
                parent = parent2;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9938
                parent2 = parent.getContainer();
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9939
            }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9940
        }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9941
    }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9942
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9943
    final void subtractAndApplyShapeBelowMe() {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9944
        checkTreeLock();
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9945
        Container parent = getContainer();
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9946
        if (parent != null && isShowing()) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9947
            Region opaqueShape = getOpaqueShape();
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9948
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9949
            // First, cut my siblings
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9950
            parent.recursiveSubtractAndApplyShape(opaqueShape, getSiblingIndexBelow());
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9951
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9952
            // Second, if my container is non-opaque, cut siblings of my container
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9953
            Container parent2 = parent.getContainer();
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9954
            while (!parent.isOpaque() && parent2 != null) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9955
                parent2.recursiveSubtractAndApplyShape(opaqueShape, parent.getSiblingIndexBelow());
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9956
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9957
                parent = parent2;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9958
                parent2 = parent.getContainer();
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9959
            }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9960
        }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9961
    }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9962
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9963
    void mixOnShowing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9964
        synchronized (getTreeLock()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  9965
            if (mixingLog.isLoggable(PlatformLogger.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9966
                mixingLog.fine("this = " + this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9967
            }
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9968
            if (!isMixingNeeded()) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9969
                return;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9970
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9971
            if (isLightweight()) {
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9972
                subtractAndApplyShapeBelowMe();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9973
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9974
                applyCurrentShape();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9975
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9976
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9977
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9978
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9979
    void mixOnHiding(boolean isLightweight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9980
        // We cannot be sure that the peer exists at this point, so we need the argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9981
        //    to find out whether the hiding component is (well, actually was) a LW or a HW.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9982
        synchronized (getTreeLock()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  9983
            if (mixingLog.isLoggable(PlatformLogger.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9984
                mixingLog.fine("this = " + this + "; isLightweight = " + isLightweight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9985
            }
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9986
            if (!isMixingNeeded()) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9987
                return;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9988
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9989
            if (isLightweight) {
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9990
                applyCurrentShapeBelowMe();
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  9991
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9992
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9993
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9994
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9995
    void mixOnReshaping() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9996
        synchronized (getTreeLock()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  9997
            if (mixingLog.isLoggable(PlatformLogger.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9998
                mixingLog.fine("this = " + this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9999
            }
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10000
            if (!isMixingNeeded()) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10001
                return;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10002
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10003
            if (isLightweight()) {
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10004
                applyCurrentShapeBelowMe();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10005
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10006
                applyCurrentShape();
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10007
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10008
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10009
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10010
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10011
    void mixOnZOrderChanging(int oldZorder, int newZorder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10012
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10013
            boolean becameHigher = newZorder < oldZorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10014
            Container parent = getContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10015
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
 10016
            if (mixingLog.isLoggable(PlatformLogger.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10017
                mixingLog.fine("this = " + this +
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10018
                    "; oldZorder=" + oldZorder + "; newZorder=" + newZorder + "; parent=" + parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10019
            }
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10020
            if (!isMixingNeeded()) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10021
                return;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10022
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10023
            if (isLightweight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10024
                if (becameHigher) {
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10025
                    if (parent != null && isShowing()) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10026
                        parent.recursiveSubtractAndApplyShape(getOpaqueShape(), getSiblingIndexBelow(), oldZorder);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10027
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10028
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10029
                    if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10030
                        parent.recursiveApplyCurrentShape(oldZorder, newZorder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10031
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10032
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10033
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10034
                if (becameHigher) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10035
                    applyCurrentShape();
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10036
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10037
                    if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10038
                        Region shape = getAppliedShape();
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10039
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10040
                        for (int index = oldZorder; index < newZorder; index++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10041
                            Component c = parent.getComponent(index);
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10042
                            if (c.isLightweight() && c.isShowing()) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10043
                                shape = shape.getDifference(c.getOpaqueShape());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10044
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10045
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10046
                        applyCompoundShape(shape);
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10047
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10048
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10049
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10050
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10051
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10052
1183
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
 10053
    void mixOnValidating() {
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
 10054
        // This method gets overriden in the Container. Obviously, a plain
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
 10055
        // non-container components don't need to handle validation.
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
 10056
    }
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
 10057
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10058
    final boolean isMixingNeeded() {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10059
        if (SunToolkit.getSunAwtDisableMixing()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
 10060
            if (mixingLog.isLoggable(PlatformLogger.FINEST)) {
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10061
                mixingLog.finest("this = " + this + "; Mixing disabled via sun.awt.disableMixing");
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10062
            }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10063
            return false;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10064
        }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10065
        if (!areBoundsValid()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
 10066
            if (mixingLog.isLoggable(PlatformLogger.FINE)) {
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10067
                mixingLog.fine("this = " + this + "; areBoundsValid = " + areBoundsValid());
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10068
            }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10069
            return false;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10070
        }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10071
        Window window = getContainingWindow();
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10072
        if (window != null) {
11982
9e19ca1ff707 7145980: Dispose method of window.java takes long
bagiras
parents: 11270
diff changeset
 10073
            if (!window.hasHeavyweightDescendants() || !window.hasLightweightDescendants() || window.isDisposing()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
 10074
                if (mixingLog.isLoggable(PlatformLogger.FINE)) {
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10075
                    mixingLog.fine("containing window = " + window +
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10076
                            "; has h/w descendants = " + window.hasHeavyweightDescendants() +
11982
9e19ca1ff707 7145980: Dispose method of window.java takes long
bagiras
parents: 11270
diff changeset
 10077
                            "; has l/w descendants = " + window.hasLightweightDescendants() +
9e19ca1ff707 7145980: Dispose method of window.java takes long
bagiras
parents: 11270
diff changeset
 10078
                            "; disposing = " + window.isDisposing());
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10079
                }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10080
                return false;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10081
            }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10082
        } else {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
 10083
            if (mixingLog.isLoggable(PlatformLogger.FINE)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
 10084
                mixingLog.fine("this = " + this + "; containing window is null");
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10085
            }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10086
            return false;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10087
        }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10088
        return true;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10089
    }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10090
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10091
    // ****************** END OF MIXING CODE ********************************
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
 10092
2647
ea80a312972e 6825362: Avoid calling peer.setZOrder on Window instances
dcherepanov
parents: 2472
diff changeset
 10093
    // Note that the method is overriden in the Window class,
ea80a312972e 6825362: Avoid calling peer.setZOrder on Window instances
dcherepanov
parents: 2472
diff changeset
 10094
    // a window doesn't need to be updated in the Z-order.
ea80a312972e 6825362: Avoid calling peer.setZOrder on Window instances
dcherepanov
parents: 2472
diff changeset
 10095
    void updateZOrder() {
ea80a312972e 6825362: Avoid calling peer.setZOrder on Window instances
dcherepanov
parents: 2472
diff changeset
 10096
        peer.setZOrder(getHWPeerAboveMe());
ea80a312972e 6825362: Avoid calling peer.setZOrder on Window instances
dcherepanov
parents: 2472
diff changeset
 10097
    }
ea80a312972e 6825362: Avoid calling peer.setZOrder on Window instances
dcherepanov
parents: 2472
diff changeset
 10098
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10099
}