jdk/src/share/classes/java/awt/Container.java
author anthony
Fri, 26 Nov 2010 15:41:16 +0300
changeset 7241 ed85b6040a98
parent 7154 4e8371f358ac
child 7668 d4a77089c587
permissions -rw-r--r--
7002856: Provide an accessor for Container.validateUnconditionally() Summary: Introduce sun.awt.AWTAccessor.getContainerAccessor().validateUnconditionally() Reviewed-by: art
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5277
diff changeset
     2
 * Copyright (c) 1995, 2009, 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.awt.dnd.DropTarget;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.peer.ContainerPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.peer.ComponentPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.peer.LightweightPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.beans.PropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.io.ObjectStreamField;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.io.PrintStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.io.PrintWriter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.util.Arrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.util.EventListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.util.HashSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
    51
import sun.util.logging.PlatformLogger;
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
    52
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import sun.awt.AppContext;
7241
ed85b6040a98 7002856: Provide an accessor for Container.validateUnconditionally()
anthony
parents: 7154
diff changeset
    54
import sun.awt.AWTAccessor;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import sun.awt.CausedFocusEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import sun.awt.PeerEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import sun.awt.SunToolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
import sun.awt.dnd.SunDropTargetEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
import sun.java2d.pipe.Region;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * A generic Abstract Window Toolkit(AWT) container object is a component
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * that can contain other AWT components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * Components added to a container are tracked in a list.  The order
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * of the list will define the components' front-to-back stacking order
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * within the container.  If no index is specified when adding a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * component to a container, it will be added to the end of the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * (and hence to the bottom of the stacking order).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * <b>Note</b>: For details on the focus subsystem, see
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * How to Use the Focus Subsystem</a>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * a section in <em>The Java Tutorial</em>, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * <a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * for more information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * @author      Arthur van Hoff
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * @author      Sami Shaio
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * @see       #add(java.awt.Component, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * @see       #getComponent(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * @see       LayoutManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * @since     JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
public class Container extends Component {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
    89
    private static final PlatformLogger log = PlatformLogger.getLogger("java.awt.Container");
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
    90
    private static final PlatformLogger eventLog = PlatformLogger.getLogger("java.awt.event.Container");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
    92
    private static final Component[] EMPTY_ARRAY = new Component[0];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * The components in this container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * @see #add
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @see #getComponents
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     */
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
    99
    private java.util.List<Component> component = new java.util.ArrayList<Component>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * Layout manager for this container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * @see #doLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * @see #setLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @see #getLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    LayoutManager layoutMgr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * Event router for lightweight components.  If this container
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * is native, this dispatcher takes care of forwarding and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * retargeting the events to lightweight components contained
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * (if any).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    private LightweightDispatcher dispatcher;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * The focus traversal policy that will manage keyboard traversal of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * Container's children, if this Container is a focus cycle root. If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * value is null, this Container inherits its policy from its focus-cycle-
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * root ancestor. If all such ancestors of this Container have null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * policies, then the current KeyboardFocusManager's default policy is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * used. If the value is non-null, this policy will be inherited by all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * focus-cycle-root children that have no keyboard-traversal policy of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * their own (as will, recursively, their focus-cycle-root children).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * If this Container is not a focus cycle root, the value will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * remembered, but will not be used or inherited by this or any other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * Containers until this Container is made a focus cycle root.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * @see #setFocusTraversalPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * @see #getFocusTraversalPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    private transient FocusTraversalPolicy focusTraversalPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * Indicates whether this Component is the root of a focus traversal cycle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * Once focus enters a traversal cycle, typically it cannot leave it via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * focus traversal unless one of the up- or down-cycle keys is pressed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * Normal traversal is limited to this Container, and all of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * Container's descendants that are not descendants of inferior focus cycle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * roots.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @see #setFocusCycleRoot
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * @see #isFocusCycleRoot
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    private boolean focusCycleRoot = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * Stores the value of focusTraversalPolicyProvider property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * @see #setFocusTraversalPolicyProvider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    private boolean focusTraversalPolicyProvider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    // keeps track of the threads that are printing this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    private transient Set printingThreads;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    // True if there is at least one thread that's printing this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    private transient boolean printing = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    transient ContainerListener containerListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    /* HierarchyListener and HierarchyBoundsListener support */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    transient int listeningChildren;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    transient int listeningBoundsChildren;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    transient int descendantsCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   171
    /* Non-opaque window support -- see Window.setLayersOpaque */
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   172
    transient Color preserveBackgroundColor = null;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   173
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * JDK 1.1 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    private static final long serialVersionUID = 4613797578919906343L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * A constant which toggles one of the controllable behaviors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * of <code>getMouseEventTarget</code>. It is used to specify whether
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * the method can return the Container on which it is originally called
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * in case if none of its children are the current mouse event targets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * @see #getMouseEventTarget(int, int, boolean, boolean, boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    static final boolean INCLUDE_SELF = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * A constant which toggles one of the controllable behaviors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * of <code>getMouseEventTarget</code>. It is used to specify whether
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * the method should search only lightweight components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * @see #getMouseEventTarget(int, int, boolean, boolean, boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    static final boolean SEARCH_HEAVYWEIGHTS = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * Number of HW or LW components in this container (including
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * all descendant containers).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    private transient int numOfHWComponents = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    private transient int numOfLWComponents = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
   205
    private static final PlatformLogger mixingLog = PlatformLogger.getLogger("java.awt.mixing.Container");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * @serialField ncomponents                     int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     *       The number of components in this container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     *       This value can be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * @serialField component                       Component[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     *       The components in this container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * @serialField layoutMgr                       LayoutManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *       Layout manager for this container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @serialField dispatcher                      LightweightDispatcher
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     *       Event router for lightweight components.  If this container
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *       is native, this dispatcher takes care of forwarding and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *       retargeting the events to lightweight components contained
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *       (if any).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @serialField maxSize                         Dimension
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *       Maximum size of this Container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * @serialField focusCycleRoot                  boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *       Indicates whether this Component is the root of a focus traversal cycle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *       Once focus enters a traversal cycle, typically it cannot leave it via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     *       focus traversal unless one of the up- or down-cycle keys is pressed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *       Normal traversal is limited to this Container, and all of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *       Container's descendants that are not descendants of inferior focus cycle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *       roots.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @serialField containerSerializedDataVersion  int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     *       Container Serial Data Version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * @serialField focusTraversalPolicyProvider    boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     *       Stores the value of focusTraversalPolicyProvider property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    private static final ObjectStreamField[] serialPersistentFields = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        new ObjectStreamField("ncomponents", Integer.TYPE),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        new ObjectStreamField("component", Component[].class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        new ObjectStreamField("layoutMgr", LayoutManager.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        new ObjectStreamField("dispatcher", LightweightDispatcher.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        new ObjectStreamField("maxSize", Dimension.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        new ObjectStreamField("focusCycleRoot", Boolean.TYPE),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        new ObjectStreamField("containerSerializedDataVersion", Integer.TYPE),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        new ObjectStreamField("focusTraversalPolicyProvider", Boolean.TYPE),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        /* ensure that the necessary native libraries are loaded */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        Toolkit.loadLibraries();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        if (!GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        }
7241
ed85b6040a98 7002856: Provide an accessor for Container.validateUnconditionally()
anthony
parents: 7154
diff changeset
   251
ed85b6040a98 7002856: Provide an accessor for Container.validateUnconditionally()
anthony
parents: 7154
diff changeset
   252
        AWTAccessor.setContainerAccessor(new AWTAccessor.ContainerAccessor() {
ed85b6040a98 7002856: Provide an accessor for Container.validateUnconditionally()
anthony
parents: 7154
diff changeset
   253
            @Override
ed85b6040a98 7002856: Provide an accessor for Container.validateUnconditionally()
anthony
parents: 7154
diff changeset
   254
            public void validateUnconditionally(Container cont) {
ed85b6040a98 7002856: Provide an accessor for Container.validateUnconditionally()
anthony
parents: 7154
diff changeset
   255
                cont.validateUnconditionally();
ed85b6040a98 7002856: Provide an accessor for Container.validateUnconditionally()
anthony
parents: 7154
diff changeset
   256
            }
ed85b6040a98 7002856: Provide an accessor for Container.validateUnconditionally()
anthony
parents: 7154
diff changeset
   257
        });
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * Initialize JNI field and method IDs for fields that may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
       called from C.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    private static native void initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * Constructs a new Container. Containers can be extended directly,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * but are lightweight in this case and must be contained by a parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * somewhere higher up in the component tree that is native.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * (such as Frame for example).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    public Container() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    void initializeFocusTraversalKeys() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        focusTraversalKeys = new Set[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * Gets the number of components in this panel.
2463
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
   281
     * <p>
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
   282
     * Note: This method should be called under AWT tree lock.
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
   283
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * @return    the number of components in this panel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * @see       #getComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * @since     JDK1.1
2463
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
   287
     * @see Component#getTreeLock()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    public int getComponentCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        return countComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * replaced by getComponentCount().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    public int countComponents() {
2463
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
   299
        // This method is not synchronized under AWT tree lock.
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
   300
        // Instead, the calling code is responsible for the
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
   301
        // synchronization. See 6784816 for details.
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
   302
        return component.size();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * Gets the nth component in this container.
2463
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
   307
     * <p>
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
   308
     * Note: This method should be called under AWT tree lock.
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
   309
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * @param      n   the index of the component to get.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * @return     the n<sup>th</sup> component in this container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * @exception  ArrayIndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     *                 if the n<sup>th</sup> value does not exist.
2463
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
   314
     * @see Component#getTreeLock()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    public Component getComponent(int n) {
2463
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
   317
        // This method is not synchronized under AWT tree lock.
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
   318
        // Instead, the calling code is responsible for the
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
   319
        // synchronization. See 6784816 for details.
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
   320
        try {
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
   321
            return component.get(n);
2463
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
   322
        } catch (IndexOutOfBoundsException z) {
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
   323
            throw new ArrayIndexOutOfBoundsException("No such child: " + n);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * Gets all the components in this container.
2463
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
   329
     * <p>
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
   330
     * Note: This method should be called under AWT tree lock.
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
   331
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * @return    an array of all the components in this container.
2463
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
   333
     * @see Component#getTreeLock()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    public Component[] getComponents() {
2463
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
   336
        // This method is not synchronized under AWT tree lock.
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
   337
        // Instead, the calling code is responsible for the
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
   338
        // synchronization. See 6784816 for details.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        return getComponents_NoClientCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    }
2463
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
   341
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    // NOTE: This method may be called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    //       This functionality is implemented in a package-private method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    //       to insure that it cannot be overridden by client subclasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    final Component[] getComponents_NoClientCode() {
2463
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
   347
        return component.toArray(EMPTY_ARRAY);
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
   348
    }
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
   349
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
   350
    /*
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
   351
     * Wrapper for getComponents() method with a proper synchronization.
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
   352
     */
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
   353
    Component[] getComponentsSync() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        synchronized (getTreeLock()) {
2463
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
   355
            return getComponents();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        }
2463
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
   357
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * Determines the insets of this container, which indicate the size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * of the container's border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * A <code>Frame</code> object, for example, has a top inset that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * corresponds to the height of the frame's title bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * @return    the insets of this container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * @see       Insets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * @see       LayoutManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * @since     JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    public Insets getInsets() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        return insets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * replaced by <code>getInsets()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    public Insets insets() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        ComponentPeer peer = this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        if (peer instanceof ContainerPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            ContainerPeer cpeer = (ContainerPeer)peer;
1964
934568dfe859 6749920: Cleanup AWT peer interfaces
rkennke
parents: 1188
diff changeset
   383
            return (Insets)cpeer.getInsets().clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        return new Insets(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * Appends the specified component to the end of this container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * This is a convenience method for {@link #addImpl}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * <p>
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
   392
     * 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: 2805
diff changeset
   393
     * invalidates the component hierarchy. If the container has already been
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
   394
     * displayed, the hierarchy must be validated thereafter in order to
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
   395
     * display the added component.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * @param     comp   the component to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * @exception NullPointerException if {@code comp} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * @see #addImpl
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
   400
     * @see #invalidate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * @see #validate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * @see javax.swing.JComponent#revalidate()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * @return    the component argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    public Component add(Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        addImpl(comp, null, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        return comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * Adds the specified component to this container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * This is a convenience method for {@link #addImpl}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * This method is obsolete as of 1.1.  Please use the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * method <code>add(Component, Object)</code> instead.
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
   416
     * <p>
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
   417
     * 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: 2805
diff changeset
   418
     * invalidates the component hierarchy. If the container has already been
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
   419
     * displayed, the hierarchy must be validated thereafter in order to
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
   420
     * display the added component.
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
   421
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * @exception NullPointerException if {@code comp} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * @see #add(Component, Object)
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
   424
     * @see #invalidate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    public Component add(String name, Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        addImpl(comp, name, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        return comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * Adds the specified component to this container at the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * This is a convenience method for {@link #addImpl}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * <p>
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
   436
     * 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: 2805
diff changeset
   437
     * invalidates the component hierarchy. If the container has already been
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
   438
     * displayed, the hierarchy must be validated thereafter in order to
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
   439
     * display the added component.
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
   440
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * @param     comp   the component to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * @param     index    the position at which to insert the component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     *                   or <code>-1</code> to append the component to the end
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * @exception NullPointerException if {@code comp} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * @exception IllegalArgumentException if {@code index} is invalid (see
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     *            {@link #addImpl} for details)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * @return    the component <code>comp</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * @see #addImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * @see #remove
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
   451
     * @see #invalidate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * @see #validate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * @see javax.swing.JComponent#revalidate()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    public Component add(Component comp, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        addImpl(comp, null, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        return comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    /**
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
   461
     * Checks that the component
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
   462
     * isn't supposed to be added into itself.
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
   463
     */
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
   464
    private void checkAddToSelf(Component comp){
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
   465
        if (comp instanceof Container) {
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
   466
            for (Container cn = this; cn != null; cn=cn.parent) {
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
   467
                if (cn == comp) {
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
   468
                    throw new IllegalArgumentException("adding container's parent to itself");
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
   469
                }
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
   470
            }
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
   471
        }
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
   472
    }
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
   473
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
   474
    /**
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
   475
     * Checks that the component is not a Window instance.
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
   476
     */
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
   477
    private void checkNotAWindow(Component comp){
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
   478
        if (comp instanceof Window) {
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
   479
            throw new IllegalArgumentException("adding a window to a container");
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
   480
        }
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
   481
    }
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
   482
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
   483
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * Checks that the component comp can be added to this container
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * Checks :  index in bounds of container's size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * comp is not one of this container's parents,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * and comp is not a window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * Comp and container must be on the same GraphicsDevice.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * if comp is container, all sub-components must be on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * same GraphicsDevice.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    private void checkAdding(Component comp, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        checkTreeLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        GraphicsConfiguration thisGC = getGraphicsConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
   499
        if (index > component.size() || index < 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            throw new IllegalArgumentException("illegal component position");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        if (comp.parent == this) {
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
   503
            if (index == component.size()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                throw new IllegalArgumentException("illegal component position " +
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
   505
                                                   index + " should be less then " + component.size());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        }
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
   508
        checkAddToSelf(comp);
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
   509
        checkNotAWindow(comp);
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
   510
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        Window thisTopLevel = getContainingWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        Window compTopLevel = comp.getContainingWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        if (thisTopLevel != compTopLevel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            throw new IllegalArgumentException("component and container should be in the same top-level window");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        if (thisGC != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            comp.checkGD(thisGC.getDevice().getIDstring());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * Removes component comp from this container without making unneccessary changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * and generating unneccessary events. This function intended to perform optimized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * remove, for example, if newParent and current parent are the same it just changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * index without calling removeNotify.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * Note: Should be called while holding treeLock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * Returns whether removeNotify was invoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * @since: 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    private boolean removeDelicately(Component comp, Container newParent, int newIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        checkTreeLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        int index = getComponentZOrder(comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        boolean needRemoveNotify = isRemoveNotifyNeeded(comp, this, newParent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        if (needRemoveNotify) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            comp.removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        if (newParent != this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            if (layoutMgr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                layoutMgr.removeLayoutComponent(comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            adjustListeningChildren(AWTEvent.HIERARCHY_EVENT_MASK,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                                    -comp.numListening(AWTEvent.HIERARCHY_EVENT_MASK));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            adjustListeningChildren(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                                    -comp.numListening(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            adjustDescendants(-(comp.countHierarchyMembers()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            comp.parent = null;
2461
5a213483d221 6811674: Container.setComponentZOrder throws NPE
anthony
parents: 2459
diff changeset
   549
            if (needRemoveNotify) {
5a213483d221 6811674: Container.setComponentZOrder throws NPE
anthony
parents: 2459
diff changeset
   550
                comp.setGraphicsConfiguration(null);
5a213483d221 6811674: Container.setComponentZOrder throws NPE
anthony
parents: 2459
diff changeset
   551
            }
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
   552
            component.remove(index);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
1183
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1172
diff changeset
   554
            invalidateIfValid();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        } else {
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
   556
            // We should remove component and then
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
   557
            // add it by the newIndex without newIndex decrement if even we shift components to the left
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
   558
            // after remove. Consult the rules below:
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
   559
            // 2->4: 012345 -> 013425, 2->5: 012345 -> 013452
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
   560
            // 4->2: 012345 -> 014235
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
   561
            component.remove(index);
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
   562
            component.add(newIndex, comp);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        if (comp.parent == null) { // was actually removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
            if (containerListener != null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                (eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                Toolkit.enabledOnToolkit(AWTEvent.CONTAINER_EVENT_MASK)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                ContainerEvent e = new ContainerEvent(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                                                      ContainerEvent.COMPONENT_REMOVED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                                                      comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                dispatchEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            comp.createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED, comp,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                                       this, HierarchyEvent.PARENT_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                                       Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            if (peer != null && layoutMgr == null && isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                updateCursorImmediately();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        return needRemoveNotify;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * Checks whether this container can contain component which is focus owner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * Verifies that container is enable and showing, and if it is focus cycle root
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     * its FTP allows component to be focus owner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    boolean canContainFocusOwner(Component focusOwnerCandidate) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        if (!(isEnabled() && isDisplayable()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
              && isVisible() && isFocusable()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        if (isFocusCycleRoot()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            FocusTraversalPolicy policy = getFocusTraversalPolicy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            if (policy instanceof DefaultFocusTraversalPolicy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                if (!((DefaultFocusTraversalPolicy)policy).accept(focusOwnerCandidate)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        synchronized(getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                return parent.canContainFocusOwner(focusOwnerCandidate);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * Checks whether or not this container has heavyweight children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * Note: Should be called while holding tree lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * @return true if there is at least one heavyweight children in a container, false otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     */
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   618
    final boolean hasHeavyweightDescendants() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        checkTreeLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        return numOfHWComponents > 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * Checks whether or not this container has lightweight children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * Note: Should be called while holding tree lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * @return true if there is at least one lightweight children in a container, false otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     */
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   629
    final boolean hasLightweightDescendants() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        checkTreeLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        return numOfLWComponents > 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * Returns closest heavyweight component to this container. If this container is heavyweight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * returns this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    Container getHeavyweightContainer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        checkTreeLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        if (peer != null && !(peer instanceof LightweightPeer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
            return getNativeContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * Detects whether or not remove from current parent and adding to new parent requires call of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     * removeNotify on the component. Since removeNotify destroys native window this might (not)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * be required. For example, if new container and old containers are the same we don't need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     * destroy native window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     * @since: 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
    private static boolean isRemoveNotifyNeeded(Component comp, Container oldContainer, Container newContainer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        if (oldContainer == null) { // Component didn't have parent - no removeNotify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        if (comp.peer == null) { // Component didn't have peer - no removeNotify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        if (newContainer.peer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
            // Component has peer but new Container doesn't - call removeNotify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        // If component is lightweight non-Container or lightweight Container with all but heavyweight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        // children there is no need to call remove notify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        if (comp.isLightweight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
            boolean isContainer = comp instanceof Container;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
            if (!isContainer || (isContainer && !((Container)comp).hasHeavyweightDescendants())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        // If this point is reached, then the comp is either a HW or a LW container with HW descendants.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        // All three components have peers, check for peer change
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        Container newNativeContainer = oldContainer.getHeavyweightContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        Container oldNativeContainer = newContainer.getHeavyweightContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        if (newNativeContainer != oldNativeContainer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
            // Native containers change - check whether or not current platform supports
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
            // changing of widget hierarchy on native level without recreation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
            // The current implementation forbids reparenting of LW containers with HW descendants
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
            // into another native container w/o destroying the peers. Actually such an operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            // is quite rare. If we ever need to save the peers, we'll have to slightly change the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            // addDelicately() method in order to handle such LW containers recursively, reparenting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            // each HW descendant independently.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
            return !comp.peer.isReparentSupported();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        } else {
2462
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2461
diff changeset
   692
            return false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     * Moves the specified component to the specified z-order index in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     * the container. The z-order determines the order that components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * are painted; the component with the highest z-order paints first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     * and the component with the lowest z-order paints last.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     * Where components overlap, the component with the lower
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     * z-order paints over the component with the higher z-order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     * If the component is a child of some other container, it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * removed from that container before being added to this container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * The important difference between this method and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     * <code>java.awt.Container.add(Component, int)</code> is that this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     * doesn't call <code>removeNotify</code> on the component while
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * removing it from its previous container unless necessary and when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * allowed by the underlying native windowing system. This way, if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * component has the keyboard focus, it maintains the focus when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     * moved to the new position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     * This property is guaranteed to apply only to lightweight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     * non-<code>Container</code> components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * <p>
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
   717
     * 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: 2805
diff changeset
   718
     * invalidates the component hierarchy.
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
   719
     * <p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     * <b>Note</b>: Not all platforms support changing the z-order of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     * heavyweight components from one container into another without
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     * the call to <code>removeNotify</code>. There is no way to detect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     * whether a platform supports this, so developers shouldn't make
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     * any assumptions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     * @param     comp the component to be moved
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * @param     index the position in the container's list to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     *            insert the component, where <code>getComponentCount()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     *            appends to the end
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     * @exception NullPointerException if <code>comp</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     *            <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     * @exception IllegalArgumentException if <code>comp</code> is one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     *            container's parents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     * @exception IllegalArgumentException if <code>index</code> is not in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     *            the range <code>[0, getComponentCount()]</code> for moving
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     *            between containers, or not in the range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     *            <code>[0, getComponentCount()-1]</code> for moving inside
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     *            a container
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     * @exception IllegalArgumentException if adding a container to itself
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     * @exception IllegalArgumentException if adding a <code>Window</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     *            to a container
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     * @see #getComponentZOrder(java.awt.Component)
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
   743
     * @see #invalidate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
    public void setComponentZOrder(Component comp, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
         synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
             // Store parent because remove will clear it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
             Container curParent = comp.parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
             int oldZindex = getComponentZOrder(comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
             if (curParent == this && index == oldZindex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                 return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
             checkAdding(comp, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
             boolean peerRecreated = (curParent != null) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
                 curParent.removeDelicately(comp, this, index) : false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
             addDelicately(comp, curParent, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
             // If the oldZindex == -1, the component gets inserted,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
             // rather than it changes its z-order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
             if (!peerRecreated && oldZindex != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                 // The new 'index' cannot be == -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                 // It gets checked at the checkAdding() method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                 // Therefore both oldZIndex and index denote
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                 // some existing positions at this point and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                 // this is actually a Z-order changing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                 comp.mixOnZOrderChanging(oldZindex, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     * Traverses the tree of components and reparents children heavyweight component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     * to new heavyweight parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
    private void reparentTraverse(ContainerPeer parentPeer, Container child) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        checkTreeLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        for (int i = 0; i < child.getComponentCount(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
            Component comp = child.getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
            if (comp.isLightweight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                // If components is lightweight check if it is container
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                // If it is container it might contain heavyweight children we need to reparent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                if (comp instanceof Container) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
                    reparentTraverse(parentPeer, (Container)comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                // Q: Need to update NativeInLightFixer?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
                comp.getPeer().reparent(parentPeer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     * Reparents child component peer to this container peer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     * Container must be heavyweight.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
    private void reparentChild(Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        checkTreeLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        if (comp == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        if (comp.isLightweight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
            // If component is lightweight container we need to reparent all its explicit  heavyweight children
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
            if (comp instanceof Container) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                // Traverse component's tree till depth-first until encountering heavyweight component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                reparentTraverse((ContainerPeer)getPeer(), (Container)comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
            comp.getPeer().reparent((ContainerPeer)getPeer());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     * Adds component to this container. Tries to minimize side effects of this adding -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
     * doesn't call remove notify if it is not required.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
    private void addDelicately(Component comp, Container curParent, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        checkTreeLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        // Check if moving between containers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        if (curParent != this) {
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
   829
            //index == -1 means add to the end.
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
   830
            if (index == -1) {
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
   831
                component.add(comp);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
            } else {
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
   833
                component.add(index, comp);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
            comp.parent = this;
2459
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
   836
            comp.setGraphicsConfiguration(getGraphicsConfiguration());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
            adjustListeningChildren(AWTEvent.HIERARCHY_EVENT_MASK,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
                                    comp.numListening(AWTEvent.HIERARCHY_EVENT_MASK));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
            adjustListeningChildren(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
                                    comp.numListening(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
            adjustDescendants(comp.countHierarchyMembers());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
        } else {
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
   844
            if (index < component.size()) {
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
   845
                component.set(index, comp);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
1183
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1172
diff changeset
   849
        invalidateIfValid();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
            if (comp.peer == null) { // Remove notify was called or it didn't have peer - create new one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
                comp.addNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
            } else { // Both container and child have peers, it means child peer should be reparented.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
                // In both cases we need to reparent native widgets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
                Container newNativeContainer = getHeavyweightContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
                Container oldNativeContainer = curParent.getHeavyweightContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
                if (oldNativeContainer != newNativeContainer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
                    // Native container changed - need to reparent native widgets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
                    newNativeContainer.reparentChild(comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
                }
2647
ea80a312972e 6825362: Avoid calling peer.setZOrder on Window instances
dcherepanov
parents: 2644
diff changeset
   861
                comp.updateZOrder();
2462
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2461
diff changeset
   862
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
                if (!comp.isLightweight() && isLightweight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
                    // If component is heavyweight and one of the containers is lightweight
130
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
   865
                    // the location of the component should be fixed.
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
   866
                    comp.relocateComponent();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        if (curParent != this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
            /* Notify the layout manager of the added component. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            if (layoutMgr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
                if (layoutMgr instanceof LayoutManager2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
                    ((LayoutManager2)layoutMgr).addLayoutComponent(comp, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
                    layoutMgr.addLayoutComponent(null, comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
            if (containerListener != null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
                (eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
                Toolkit.enabledOnToolkit(AWTEvent.CONTAINER_EVENT_MASK)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
                ContainerEvent e = new ContainerEvent(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
                                                      ContainerEvent.COMPONENT_ADDED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
                                                      comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
                dispatchEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
            comp.createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED, comp,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
                                       this, HierarchyEvent.PARENT_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
                                       Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
            // If component is focus owner or parent container of focus owner check that after reparenting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
            // focus owner moved out if new container prohibit this kind of focus owner.
1171
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 441
diff changeset
   893
            if (comp.isFocusOwner() && !comp.canBeFocusOwnerRecursively()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
                comp.transferFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
            } else if (comp instanceof Container) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
                Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
1171
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 441
diff changeset
   897
                if (focusOwner != null && isParentOf(focusOwner) && !focusOwner.canBeFocusOwnerRecursively()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
                    focusOwner.transferFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
            comp.createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED, comp,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
                                       this, HierarchyEvent.HIERARCHY_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
                                       Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        if (peer != null && layoutMgr == null && isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
            updateCursorImmediately();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
     * Returns the z-order index of the component inside the container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     * The higher a component is in the z-order hierarchy, the lower
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
     * its index.  The component with the lowest z-order index is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
     * painted last, above all other child components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
     * @param comp the component being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
     * @return  the z-order index of the component; otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     *          returns -1 if the component is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     *          or doesn't belong to the container
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     * @see #setComponentZOrder(java.awt.Component, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
    public int getComponentZOrder(Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        if (comp == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
        synchronized(getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
            // Quick check - container should be immediate parent of the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
            if (comp.parent != this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
                return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
            }
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
   934
            return component.indexOf(comp);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
     * Adds the specified component to the end of this container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
     * Also notifies the layout manager to add the component to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
     * this container's layout using the specified constraints object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
     * This is a convenience method for {@link #addImpl}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
     * <p>
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
   944
     * 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: 2805
diff changeset
   945
     * invalidates the component hierarchy. If the container has already been
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
   946
     * displayed, the hierarchy must be validated thereafter in order to
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
   947
     * display the added component.
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
   948
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
     * @param     comp the component to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
     * @param     constraints an object expressing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
     *                  layout contraints for this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
     * @exception NullPointerException if {@code comp} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
     * @see #addImpl
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
   955
     * @see #invalidate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
     * @see #validate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
     * @see javax.swing.JComponent#revalidate()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
     * @see       LayoutManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
     * @since     JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
    public void add(Component comp, Object constraints) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
        addImpl(comp, constraints, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
     * Adds the specified component to this container with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
     * constraints at the specified index.  Also notifies the layout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
     * manager to add the component to the this container's layout using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
     * the specified constraints object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
     * This is a convenience method for {@link #addImpl}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
     * <p>
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
   972
     * 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: 2805
diff changeset
   973
     * invalidates the component hierarchy. If the container has already been
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
   974
     * displayed, the hierarchy must be validated thereafter in order to
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
   975
     * display the added component.
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
   976
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
     * @param comp the component to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
     * @param constraints an object expressing layout contraints for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
     * @param index the position in the container's list at which to insert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
     * the component; <code>-1</code> means insert at the end
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
     * component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
     * @exception NullPointerException if {@code comp} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
     * @exception IllegalArgumentException if {@code index} is invalid (see
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
     *            {@link #addImpl} for details)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
     * @see #addImpl
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
   987
     * @see #invalidate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
     * @see #validate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
     * @see javax.swing.JComponent#revalidate()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
     * @see #remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
     * @see LayoutManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
    public void add(Component comp, Object constraints, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
       addImpl(comp, constraints, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
     * Adds the specified component to this container at the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
     * index. This method also notifies the layout manager to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
     * the component to this container's layout using the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
     * constraints object via the <code>addLayoutComponent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
     * method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
     * The constraints are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
     * defined by the particular layout manager being used.  For
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
     * example, the <code>BorderLayout</code> class defines five
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
     * constraints: <code>BorderLayout.NORTH</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
     * <code>BorderLayout.SOUTH</code>, <code>BorderLayout.EAST</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
     * <code>BorderLayout.WEST</code>, and <code>BorderLayout.CENTER</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
     * The <code>GridBagLayout</code> class requires a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
     * <code>GridBagConstraints</code> object.  Failure to pass
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
     * the correct type of constraints object results in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
     * <code>IllegalArgumentException</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
     * If the current layout manager implements {@code LayoutManager2}, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
     * {@link LayoutManager2#addLayoutComponent(Component,Object)} is invoked on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
     * it. If the current layout manager does not implement
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
     * {@code LayoutManager2}, and constraints is a {@code String}, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
     * {@link LayoutManager#addLayoutComponent(String,Component)} is invoked on it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
     * If the component is not an ancestor of this container and has a non-null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
     * parent, it is removed from its current parent before it is added to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
     * container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
     * This is the method to override if a program needs to track
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
     * every add request to a container as all other add methods defer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
     * to this one. An overriding method should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
     * usually include a call to the superclass's version of the method:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
     * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
     * <code>super.addImpl(comp, constraints, index)</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
     * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
     * <p>
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
  1035
     * 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: 2805
diff changeset
  1036
     * invalidates the component hierarchy. If the container has already been
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
  1037
     * displayed, the hierarchy must be validated thereafter in order to
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
  1038
     * display the added component.
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
  1039
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
     * @param     comp       the component to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
     * @param     constraints an object expressing layout constraints
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
     *                 for this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
     * @param     index the position in the container's list at which to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
     *                 insert the component, where <code>-1</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
     *                 means append to the end
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
     * @exception IllegalArgumentException if {@code index} is invalid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
     *            if {@code comp} is a child of this container, the valid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
     *            range is {@code [-1, getComponentCount()-1]}; if component is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
     *            not a child of this container, the valid range is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
     *            {@code [-1, getComponentCount()]}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
     * @exception IllegalArgumentException if {@code comp} is an ancestor of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
     *                                     this container
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
     * @exception IllegalArgumentException if adding a window to a container
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
     * @exception NullPointerException if {@code comp} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
     * @see       #add(Component)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
     * @see       #add(Component, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
     * @see       #add(Component, java.lang.Object)
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
  1059
     * @see #invalidate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
     * @see       LayoutManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
     * @see       LayoutManager2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
     * @since     JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
    protected void addImpl(Component comp, Object constraints, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
            /* Check for correct arguments:  index in bounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
             * comp cannot be one of this container's parents,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
             * and comp cannot be a window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
             * comp and container must be on the same GraphicsDevice.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
             * if comp is container, all sub-components must be on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
             * same GraphicsDevice.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
            GraphicsConfiguration thisGC = this.getGraphicsConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  1075
            if (index > component.size() || (index < 0 && index != -1)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
                throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
                          "illegal component position");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
            }
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  1079
            checkAddToSelf(comp);
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  1080
            checkNotAWindow(comp);
2463
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  1081
            if (thisGC != null) {
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  1082
                comp.checkGD(thisGC.getDevice().getIDstring());
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  1083
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
            /* Reparent the component and tidy up the tree's state. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
            if (comp.parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
                comp.parent.remove(comp);
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  1088
                    if (index > component.size()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
                        throw new IllegalArgumentException("illegal component position");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  1093
            //index == -1 means add to the end.
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  1094
            if (index == -1) {
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  1095
                component.add(comp);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
            } else {
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  1097
                component.add(index, comp);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
            comp.parent = this;
2459
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
  1100
            comp.setGraphicsConfiguration(thisGC);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
            adjustListeningChildren(AWTEvent.HIERARCHY_EVENT_MASK,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
                comp.numListening(AWTEvent.HIERARCHY_EVENT_MASK));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
            adjustListeningChildren(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
                comp.numListening(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
            adjustDescendants(comp.countHierarchyMembers());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
1183
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1172
diff changeset
  1108
            invalidateIfValid();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
                comp.addNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
            /* Notify the layout manager of the added component. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
            if (layoutMgr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
                if (layoutMgr instanceof LayoutManager2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
                    ((LayoutManager2)layoutMgr).addLayoutComponent(comp, constraints);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
                } else if (constraints instanceof String) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
                    layoutMgr.addLayoutComponent((String)constraints, comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
            if (containerListener != null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
                (eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
                Toolkit.enabledOnToolkit(AWTEvent.CONTAINER_EVENT_MASK)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
                ContainerEvent e = new ContainerEvent(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
                                     ContainerEvent.COMPONENT_ADDED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
                                     comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
                dispatchEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
            comp.createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED, comp,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
                                       this, HierarchyEvent.PARENT_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
                                       Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
            if (peer != null && layoutMgr == null && isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
                updateCursorImmediately();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
2459
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
  1139
    @Override
2805
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2647
diff changeset
  1140
    boolean updateGraphicsData(GraphicsConfiguration gc) {
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2647
diff changeset
  1141
        checkTreeLock();
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2647
diff changeset
  1142
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2647
diff changeset
  1143
        boolean ret = super.updateGraphicsData(gc);
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2647
diff changeset
  1144
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2647
diff changeset
  1145
        for (Component comp : component) {
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2647
diff changeset
  1146
            if (comp != null) {
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2647
diff changeset
  1147
                ret |= comp.updateGraphicsData(gc);
2459
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
  1148
            }
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
  1149
        }
2805
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2647
diff changeset
  1150
        return ret;
2459
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
  1151
    }
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
  1152
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
     * Checks that all Components that this Container contains are on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
     * the same GraphicsDevice as this Container.  If not, throws an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
     * IllegalArgumentException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
    void checkGD(String stringID) {
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  1159
        for (Component comp : component) {
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  1160
            if (comp != null) {
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  1161
                comp.checkGD(stringID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
     * Removes the component, specified by <code>index</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
     * from this container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
     * This method also notifies the layout manager to remove the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
     * component from this container's layout via the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
     * <code>removeLayoutComponent</code> method.
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
  1172
     * <p>
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
  1173
     * 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: 2805
diff changeset
  1174
     * invalidates the component hierarchy. If the container has already been
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
  1175
     * displayed, the hierarchy must be validated thereafter in order to
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
  1176
     * reflect the changes.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
     * @param     index   the index of the component to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
     * @throws ArrayIndexOutOfBoundsException if {@code index} is not in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
     *         range {@code [0, getComponentCount()-1]}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
     * @see #add
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
  1183
     * @see #invalidate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
     * @see #validate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
     * @see #getComponentCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
     * @since JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
    public void remove(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
        synchronized (getTreeLock()) {
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  1190
            if (index < 0  || index >= component.size()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
                throw new ArrayIndexOutOfBoundsException(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
            }
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  1193
            Component comp = component.get(index);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
                comp.removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
            if (layoutMgr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
                layoutMgr.removeLayoutComponent(comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
            adjustListeningChildren(AWTEvent.HIERARCHY_EVENT_MASK,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
                -comp.numListening(AWTEvent.HIERARCHY_EVENT_MASK));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
            adjustListeningChildren(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
                -comp.numListening(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
            adjustDescendants(-(comp.countHierarchyMembers()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
            comp.parent = null;
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  1208
            component.remove(index);
2459
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
  1209
            comp.setGraphicsConfiguration(null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
1183
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1172
diff changeset
  1211
            invalidateIfValid();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
            if (containerListener != null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
                (eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
                Toolkit.enabledOnToolkit(AWTEvent.CONTAINER_EVENT_MASK)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
                ContainerEvent e = new ContainerEvent(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
                                     ContainerEvent.COMPONENT_REMOVED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
                                     comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
                dispatchEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
            comp.createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED, comp,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
                                       this, HierarchyEvent.PARENT_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
                                       Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
            if (peer != null && layoutMgr == null && isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
                updateCursorImmediately();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
     * Removes the specified component from this container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
     * This method also notifies the layout manager to remove the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
     * component from this container's layout via the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
     * <code>removeLayoutComponent</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
     * <p>
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
  1236
     * 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: 2805
diff changeset
  1237
     * invalidates the component hierarchy. If the container has already been
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
  1238
     * displayed, the hierarchy must be validated thereafter in order to
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
  1239
     * reflect the changes.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
     * @param comp the component to be removed
7154
4e8371f358ac 6877895: Some AWT's methods should specify throwing NPE for null arg value
dcherepanov
parents: 6827
diff changeset
  1242
     * @throws NullPointerException if {@code comp} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
     * @see #add
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
  1244
     * @see #invalidate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
     * @see #validate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
     * @see #remove(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
    public void remove(Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
            if (comp.parent == this)  {
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  1251
                int index = component.indexOf(comp);
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  1252
                if (index >= 0) {
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  1253
                    remove(index);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
     * Removes all the components from this container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
     * This method also notifies the layout manager to remove the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
     * components from this container's layout via the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
     * <code>removeLayoutComponent</code> method.
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
  1264
     * <p>
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
  1265
     * 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: 2805
diff changeset
  1266
     * invalidates the component hierarchy. If the container has already been
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
  1267
     * displayed, the hierarchy must be validated thereafter in order to
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
  1268
     * reflect the changes.
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
  1269
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
     * @see #add
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
     * @see #remove
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
  1272
     * @see #invalidate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
    public void removeAll() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
            adjustListeningChildren(AWTEvent.HIERARCHY_EVENT_MASK,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
                                    -listeningChildren);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
            adjustListeningChildren(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
                                    -listeningBoundsChildren);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
            adjustDescendants(-descendantsCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  1282
            while (!component.isEmpty()) {
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  1283
                Component comp = component.remove(component.size()-1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
                if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
                    comp.removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
                if (layoutMgr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
                    layoutMgr.removeLayoutComponent(comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
                comp.parent = null;
2459
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
  1292
                comp.setGraphicsConfiguration(null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
                if (containerListener != null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
                   (eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
                    Toolkit.enabledOnToolkit(AWTEvent.CONTAINER_EVENT_MASK)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
                    ContainerEvent e = new ContainerEvent(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
                                     ContainerEvent.COMPONENT_REMOVED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
                                     comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
                    dispatchEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
                comp.createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
                                           comp, this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
                                           HierarchyEvent.PARENT_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
                                           Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
            if (peer != null && layoutMgr == null && isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
                updateCursorImmediately();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
            }
1183
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1172
diff changeset
  1310
            invalidateIfValid();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
    // Should only be called while holding tree lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
    int numListening(long mask) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
        int superListening = super.numListening(mask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
        if (mask == AWTEvent.HIERARCHY_EVENT_MASK) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
  1319
            if (eventLog.isLoggable(PlatformLogger.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
                // Verify listeningChildren is correct
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
                int sum = 0;
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  1322
                for (Component comp : component) {
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  1323
                    sum += comp.numListening(mask);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
                if (listeningChildren != sum) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
  1326
                    eventLog.fine("Assertion (listeningChildren == sum) failed");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
            return listeningChildren + superListening;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
        } else if (mask == AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
  1331
            if (eventLog.isLoggable(PlatformLogger.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
                // Verify listeningBoundsChildren is correct
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
                int sum = 0;
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  1334
                for (Component comp : component) {
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  1335
                    sum += comp.numListening(mask);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
                if (listeningBoundsChildren != sum) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
  1338
                    eventLog.fine("Assertion (listeningBoundsChildren == sum) failed");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
            return listeningBoundsChildren + superListening;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
            // assert false;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
  1344
            if (eventLog.isLoggable(PlatformLogger.FINE)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
  1345
                eventLog.fine("This code must never be reached");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
            return superListening;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
    // Should only be called while holding tree lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
    void adjustListeningChildren(long mask, int num) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
  1353
        if (eventLog.isLoggable(PlatformLogger.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
            boolean toAssert = (mask == AWTEvent.HIERARCHY_EVENT_MASK ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
                                mask == AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
                                mask == (AWTEvent.HIERARCHY_EVENT_MASK |
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
                                         AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
            if (!toAssert) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
  1359
                eventLog.fine("Assertion failed");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
        if (num == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
        if ((mask & AWTEvent.HIERARCHY_EVENT_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
            listeningChildren += num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
        if ((mask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
            listeningBoundsChildren += num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
        adjustListeningChildrenOnParent(mask, num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
    // Should only be called while holding tree lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
    void adjustDescendants(int num) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
        if (num == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
        descendantsCount += num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
        adjustDecendantsOnParent(num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
    // Should only be called while holding tree lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
    void adjustDecendantsOnParent(int num) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
        if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
            parent.adjustDescendants(num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
    // Should only be called while holding tree lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
    int countHierarchyMembers() {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
  1394
        if (log.isLoggable(PlatformLogger.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
            // Verify descendantsCount is correct
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
            int sum = 0;
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  1397
            for (Component comp : component) {
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  1398
                sum += comp.countHierarchyMembers();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
            if (descendantsCount != sum) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
  1401
                log.fine("Assertion (descendantsCount == sum) failed");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
        return descendantsCount + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
    private int getListenersCount(int id, boolean enabledOnToolkit) {
2463
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  1408
        checkTreeLock();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
        if (enabledOnToolkit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
            return descendantsCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
        switch (id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
          case HierarchyEvent.HIERARCHY_CHANGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
            return listeningChildren;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
          case HierarchyEvent.ANCESTOR_MOVED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
          case HierarchyEvent.ANCESTOR_RESIZED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
            return listeningBoundsChildren;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
    final int createHierarchyEvents(int id, Component changed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
        Container changedParent, long changeFlags, boolean enabledOnToolkit)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
    {
2463
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  1426
        checkTreeLock();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
        int listeners = getListenersCount(id, enabledOnToolkit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
        for (int count = listeners, i = 0; count > 0; i++) {
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  1430
            count -= component.get(i).createHierarchyEvents(id, changed,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
                changedParent, changeFlags, enabledOnToolkit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
        return listeners +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
            super.createHierarchyEvents(id, changed, changedParent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
                                        changeFlags, enabledOnToolkit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
    final void createChildHierarchyEvents(int id, long changeFlags,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
        boolean enabledOnToolkit)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
    {
2463
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  1441
        checkTreeLock();
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  1442
        if (component.isEmpty()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
        int listeners = getListenersCount(id, enabledOnToolkit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
        for (int count = listeners, i = 0; count > 0; i++) {
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  1448
            count -= component.get(i).createHierarchyEvents(id, this, parent,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
                changeFlags, enabledOnToolkit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
     * Gets the layout manager for this container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
     * @see #doLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
     * @see #setLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
    public LayoutManager getLayout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
        return layoutMgr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
     * Sets the layout manager for this container.
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
  1464
     * <p>
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
  1465
     * 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: 2805
diff changeset
  1466
     * invalidates the component hierarchy.
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
  1467
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
     * @param mgr the specified layout manager
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
     * @see #doLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
     * @see #getLayout
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
  1471
     * @see #invalidate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
    public void setLayout(LayoutManager mgr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
        layoutMgr = mgr;
1183
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1172
diff changeset
  1475
        invalidateIfValid();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
     * Causes this container to lay out its components.  Most programs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
     * should not call this method directly, but should invoke
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
     * the <code>validate</code> method instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
     * @see LayoutManager#layoutContainer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
     * @see #setLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
     * @see #validate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
     * @since JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
    public void doLayout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
        layout();
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>doLayout()</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 layout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
        LayoutManager layoutMgr = this.layoutMgr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
        if (layoutMgr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
            layoutMgr.layoutContainer(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
    /**
4261
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1504
     * Indicates if this container is a <i>validate root</i>.
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1505
     * <p>
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1506
     * Layout-related changes, such as bounds of the validate root descendants,
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1507
     * do not affect the layout of the validate root parent. This peculiarity
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1508
     * enables the {@code invalidate()} method to stop invalidating the
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1509
     * component hierarchy when the method encounters a validate root.
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1510
     * <p>
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1511
     * If a component hierarchy contains validate roots, the {@code validate()}
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1512
     * method must be invoked on the validate root of a previously invalidated
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1513
     * component, rather than on the top-level container (such as a {@code
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1514
     * Frame} object) to restore the validity of the hierarchy later.
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1515
     * <p>
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1516
     * The {@code Window} class and the {@code Applet} class are the validate
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1517
     * roots in AWT.  Swing introduces more validate roots.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
     *
4261
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1519
     * @return whether this container is a validate root
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1520
     * @see #invalidate
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1521
     * @see java.awt.Component#invalidate
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1522
     * @see javax.swing.JComponent#isValidateRoot
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1523
     * @see javax.swing.JComponent#revalidate
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1524
     * @since 1.7
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1525
     */
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1526
    public boolean isValidateRoot() {
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1527
        return false;
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1528
    }
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1529
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1530
    /**
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1531
     * Invalidates the parent of the container unless the container
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1532
     * is a validate root.
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1533
     */
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1534
    @Override
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1535
    void invalidateParent() {
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1536
        if (!isValidateRoot()) {
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1537
            super.invalidateParent();
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1538
        }
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1539
    }
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1540
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1541
    /**
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1542
     * Invalidates the container.
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1543
     * <p>
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1544
     * If the {@code LayoutManager} installed on this container is an instance
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1545
     * of the {@code LayoutManager2} interface, then
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1546
     * the {@link LayoutManager2#invalidateLayout(Container)} method is invoked
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1547
     * on it supplying this {@code Container} as the argument.
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1548
     * <p>
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1549
     * Afterwards this method marks this container invalid, and invalidates its
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1550
     * ancestors. See the {@link Component#invalidate} method for more details.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
     * @see #validate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
     * @see #layout
4261
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1554
     * @see LayoutManager2
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
     */
4261
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1556
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
    public void invalidate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
        LayoutManager layoutMgr = this.layoutMgr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
        if (layoutMgr instanceof LayoutManager2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
            LayoutManager2 lm = (LayoutManager2) layoutMgr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
            lm.invalidateLayout(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
        super.invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
     * Validates this container and all of its subcomponents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
     * <p>
4261
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1569
     * Validating a container means laying out its subcomponents.
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1570
     * Layout-related changes, such as setting the bounds of a component, or
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1571
     * adding a component to the container, invalidate the container
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1572
     * automatically.  Note that the ancestors of the container may be
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1573
     * invalidated also (see {@link Component#invalidate} for details.)
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1574
     * Therefore, to restore the validity of the hierarchy, the {@code
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1575
     * validate()} method should be invoked on a validate root of an
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1576
     * invalidated component, or on the top-most container if the hierarchy
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1577
     * does not contain validate roots.
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1578
     * <p>
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1579
     * Validating the container may be a quite time-consuming operation. For
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1580
     * performance reasons a developer may postpone the validation of the
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1581
     * hierarchy till a set of layout-related operations completes, e.g. after
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1582
     * adding all the children to the container.
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1583
     * <p>
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1584
     * If this {@code Container} is not valid, this method invokes
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
     * the {@code validateTree} method and marks this {@code Container}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
     * as valid. Otherwise, no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
     * @see #add(java.awt.Component)
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
  1589
     * @see #invalidate
4261
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1590
     * @see Container#isValidateRoot
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
     * @see javax.swing.JComponent#revalidate()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
     * @see #validateTree
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
    public void validate() {
4263
db2d1f69a60e 6887249: Get rid of double-check for isValid() idiom in validate() methods
anthony
parents: 4261
diff changeset
  1595
        boolean updateCur = false;
db2d1f69a60e 6887249: Get rid of double-check for isValid() idiom in validate() methods
anthony
parents: 4261
diff changeset
  1596
        synchronized (getTreeLock()) {
db2d1f69a60e 6887249: Get rid of double-check for isValid() idiom in validate() methods
anthony
parents: 4261
diff changeset
  1597
            if ((!isValid() || descendUnconditionallyWhenValidating)
db2d1f69a60e 6887249: Get rid of double-check for isValid() idiom in validate() methods
anthony
parents: 4261
diff changeset
  1598
                    && peer != null)
db2d1f69a60e 6887249: Get rid of double-check for isValid() idiom in validate() methods
anthony
parents: 4261
diff changeset
  1599
            {
db2d1f69a60e 6887249: Get rid of double-check for isValid() idiom in validate() methods
anthony
parents: 4261
diff changeset
  1600
                ContainerPeer p = null;
db2d1f69a60e 6887249: Get rid of double-check for isValid() idiom in validate() methods
anthony
parents: 4261
diff changeset
  1601
                if (peer instanceof ContainerPeer) {
db2d1f69a60e 6887249: Get rid of double-check for isValid() idiom in validate() methods
anthony
parents: 4261
diff changeset
  1602
                    p = (ContainerPeer) peer;
db2d1f69a60e 6887249: Get rid of double-check for isValid() idiom in validate() methods
anthony
parents: 4261
diff changeset
  1603
                }
db2d1f69a60e 6887249: Get rid of double-check for isValid() idiom in validate() methods
anthony
parents: 4261
diff changeset
  1604
                if (p != null) {
db2d1f69a60e 6887249: Get rid of double-check for isValid() idiom in validate() methods
anthony
parents: 4261
diff changeset
  1605
                    p.beginValidate();
db2d1f69a60e 6887249: Get rid of double-check for isValid() idiom in validate() methods
anthony
parents: 4261
diff changeset
  1606
                }
db2d1f69a60e 6887249: Get rid of double-check for isValid() idiom in validate() methods
anthony
parents: 4261
diff changeset
  1607
                validateTree();
db2d1f69a60e 6887249: Get rid of double-check for isValid() idiom in validate() methods
anthony
parents: 4261
diff changeset
  1608
                if (p != null) {
db2d1f69a60e 6887249: Get rid of double-check for isValid() idiom in validate() methods
anthony
parents: 4261
diff changeset
  1609
                    p.endValidate();
db2d1f69a60e 6887249: Get rid of double-check for isValid() idiom in validate() methods
anthony
parents: 4261
diff changeset
  1610
                    // Avoid updating cursor if this is an internal call.
db2d1f69a60e 6887249: Get rid of double-check for isValid() idiom in validate() methods
anthony
parents: 4261
diff changeset
  1611
                    // See validateUnconditionally() for details.
db2d1f69a60e 6887249: Get rid of double-check for isValid() idiom in validate() methods
anthony
parents: 4261
diff changeset
  1612
                    if (!descendUnconditionallyWhenValidating) {
db2d1f69a60e 6887249: Get rid of double-check for isValid() idiom in validate() methods
anthony
parents: 4261
diff changeset
  1613
                        updateCur = isVisible();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
            }
4263
db2d1f69a60e 6887249: Get rid of double-check for isValid() idiom in validate() methods
anthony
parents: 4261
diff changeset
  1617
        }
db2d1f69a60e 6887249: Get rid of double-check for isValid() idiom in validate() methods
anthony
parents: 4261
diff changeset
  1618
        if (updateCur) {
db2d1f69a60e 6887249: Get rid of double-check for isValid() idiom in validate() methods
anthony
parents: 4261
diff changeset
  1619
            updateCursorImmediately();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
    /**
4261
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1624
     * Indicates whether valid containers should also traverse their
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1625
     * children and call the validateTree() method on them.
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1626
     *
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1627
     * Synchronization: TreeLock.
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1628
     *
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1629
     * The field is allowed to be static as long as the TreeLock itself is
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1630
     * static.
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1631
     *
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1632
     * @see #validateUnconditionally()
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1633
     */
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1634
    private static boolean descendUnconditionallyWhenValidating = false;
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1635
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1636
    /**
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1637
     * Unconditionally validate the component hierarchy.
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1638
     */
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1639
    final void validateUnconditionally() {
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1640
        boolean updateCur = false;
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1641
        synchronized (getTreeLock()) {
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1642
            descendUnconditionallyWhenValidating = true;
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1643
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1644
            validate();
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1645
            if (peer instanceof ContainerPeer) {
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1646
                updateCur = isVisible();
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1647
            }
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1648
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1649
            descendUnconditionallyWhenValidating = false;
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1650
        }
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1651
        if (updateCur) {
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1652
            updateCursorImmediately();
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1653
        }
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1654
    }
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1655
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1656
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
     * Recursively descends the container tree and recomputes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
     * layout for any subtrees marked as needing it (those marked as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
     * invalid).  Synchronization should be provided by the method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
     * that calls this one:  <code>validate</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
     * @see #doLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
     * @see #validate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
    protected void validateTree() {
2463
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  1666
        checkTreeLock();
4261
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1667
        if (!isValid() || descendUnconditionallyWhenValidating) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
            if (peer instanceof ContainerPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
                ((ContainerPeer)peer).beginLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
            }
4261
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1671
            if (!isValid()) {
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1672
                doLayout();
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1673
            }
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  1674
            for (int i = 0; i < component.size(); i++) {
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  1675
                Component comp = component.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
                if (   (comp instanceof Container)
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  1677
                       && !(comp instanceof Window)
4261
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1678
                       && (!comp.isValid() ||
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1679
                           descendUnconditionallyWhenValidating))
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  1680
                {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
                    ((Container)comp).validateTree();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
                    comp.validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
            if (peer instanceof ContainerPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
                ((ContainerPeer)peer).endLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
        }
1183
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1172
diff changeset
  1690
        super.validate();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
     * Recursively descends the container tree and invalidates all
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
     * contained components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
    void invalidateTree() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
        synchronized (getTreeLock()) {
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  1699
            for (int i = 0; i < component.size(); i++) {
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  1700
                Component comp = component.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
                if (comp instanceof Container) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
                    ((Container)comp).invalidateTree();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
                else {
1183
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1172
diff changeset
  1705
                    comp.invalidateIfValid();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
            }
1183
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1172
diff changeset
  1708
            invalidateIfValid();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
     * Sets the font of this container.
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
  1714
     * <p>
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
  1715
     * 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: 2805
diff changeset
  1716
     * invalidates the component hierarchy.
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
  1717
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
     * @param f The font to become this container's font.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
     * @see Component#getFont
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
  1720
     * @see #invalidate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
     * @since JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
    public void setFont(Font f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
        boolean shouldinvalidate = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
        Font oldfont = getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
        super.setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
        Font newfont = getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
        if (newfont != oldfont && (oldfont == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
                                   !oldfont.equals(newfont))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
            invalidateTree();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
     * Returns the preferred size of this container.  If the preferred size has
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
     * not been set explicitly by {@link Component#setPreferredSize(Dimension)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
     * and this {@code Container} has a {@code non-null} {@link LayoutManager},
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
     * then {@link LayoutManager#preferredLayoutSize(Container)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
     * is used to calculate the preferred size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
     * <p>Note: some implementations may cache the value returned from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
     * {@code LayoutManager}.  Implementations that cache need not invoke
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
     * {@code preferredLayoutSize} on the {@code LayoutManager} every time
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
     * this method is invoked, rather the {@code LayoutManager} will only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
     * be queried after the {@code Container} becomes invalid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
     * @return    an instance of <code>Dimension</code> that represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
     *                the preferred size of this container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
     * @see       #getMinimumSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
     * @see       #getMaximumSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
     * @see       #getLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
     * @see       LayoutManager#preferredLayoutSize(Container)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
     * @see       Component#getPreferredSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
    public Dimension getPreferredSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
        return preferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
     * replaced by <code>getPreferredSize()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
    public Dimension preferredSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
        /* Avoid grabbing the lock if a reasonable cached size value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
         * is available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
        Dimension dim = prefSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
        if (dim == null || !(isPreferredSizeSet() || isValid())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
            synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
                prefSize = (layoutMgr != null) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
                    layoutMgr.preferredLayoutSize(this) :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
                    super.preferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
                dim = prefSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
        if (dim != null){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
            return new Dimension(dim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
        else{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
            return dim;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
     * Returns the minimum size of this container.  If the minimum size has
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
     * not been set explicitly by {@link Component#setMinimumSize(Dimension)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
     * and this {@code Container} has a {@code non-null} {@link LayoutManager},
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
     * then {@link LayoutManager#minimumLayoutSize(Container)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
     * is used to calculate the minimum size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
     * <p>Note: some implementations may cache the value returned from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
     * {@code LayoutManager}.  Implementations that cache need not invoke
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
     * {@code minimumLayoutSize} on the {@code LayoutManager} every time
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
     * this method is invoked, rather the {@code LayoutManager} will only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
     * be queried after the {@code Container} becomes invalid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
     * @return    an instance of <code>Dimension</code> that represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
     *                the minimum size of this container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
     * @see       #getPreferredSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
     * @see       #getMaximumSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
     * @see       #getLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
     * @see       LayoutManager#minimumLayoutSize(Container)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
     * @see       Component#getMinimumSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
     * @since     JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
    public Dimension getMinimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
        return minimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
     * replaced by <code>getMinimumSize()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
    public Dimension minimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
        /* Avoid grabbing the lock if a reasonable cached size value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
         * is available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
        Dimension dim = minSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
        if (dim == null || !(isMinimumSizeSet() || isValid())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
            synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
                minSize = (layoutMgr != null) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
                    layoutMgr.minimumLayoutSize(this) :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
                    super.minimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
                dim = minSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
        if (dim != null){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
            return new Dimension(dim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
        else{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
            return dim;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
     * Returns the maximum size of this container.  If the maximum size has
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
     * not been set explicitly by {@link Component#setMaximumSize(Dimension)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
     * and the {@link LayoutManager} installed on this {@code Container}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
     * is an instance of {@link LayoutManager2}, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
     * {@link LayoutManager2#maximumLayoutSize(Container)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
     * is used to calculate the maximum size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
     * <p>Note: some implementations may cache the value returned from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
     * {@code LayoutManager2}.  Implementations that cache need not invoke
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
     * {@code maximumLayoutSize} on the {@code LayoutManager2} every time
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
     * this method is invoked, rather the {@code LayoutManager2} will only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
     * be queried after the {@code Container} becomes invalid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
     * @return    an instance of <code>Dimension</code> that represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
     *                the maximum size of this container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
     * @see       #getPreferredSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
     * @see       #getMinimumSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
     * @see       #getLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
     * @see       LayoutManager2#maximumLayoutSize(Container)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
     * @see       Component#getMaximumSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
    public Dimension getMaximumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
        /* Avoid grabbing the lock if a reasonable cached size value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
         * is available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
        Dimension dim = maxSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
        if (dim == null || !(isMaximumSizeSet() || isValid())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
            synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
               if (layoutMgr instanceof LayoutManager2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
                    LayoutManager2 lm = (LayoutManager2) layoutMgr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
                    maxSize = lm.maximumLayoutSize(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
               } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
                    maxSize = super.getMaximumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
               dim = maxSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
        if (dim != null){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
            return new Dimension(dim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
        else{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
            return dim;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
     * Returns the alignment along the x axis.  This specifies how
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
     * the component would like to be aligned relative to other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
     * components.  The value should be a number between 0 and 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
     * where 0 represents alignment along the origin, 1 is aligned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
     * the furthest away from the origin, 0.5 is centered, etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
    public float getAlignmentX() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
        float xAlign;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
        if (layoutMgr instanceof LayoutManager2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
            synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
                LayoutManager2 lm = (LayoutManager2) layoutMgr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
                xAlign = lm.getLayoutAlignmentX(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
            xAlign = super.getAlignmentX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
        return xAlign;
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
     * Returns the alignment along the y axis.  This specifies how
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
     * the component would like to be aligned relative to other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
     * components.  The value should be a number between 0 and 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
     * where 0 represents alignment along the origin, 1 is aligned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
     * the furthest away from the origin, 0.5 is centered, etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
    public float getAlignmentY() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
        float yAlign;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
        if (layoutMgr instanceof LayoutManager2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
            synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
                LayoutManager2 lm = (LayoutManager2) layoutMgr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
                yAlign = lm.getLayoutAlignmentY(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
            yAlign = super.getAlignmentY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
        return yAlign;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
     * Paints the container. This forwards the paint to any lightweight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
     * components that are children of this container. If this method is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
     * reimplemented, super.paint(g) should be called so that lightweight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
     * components are properly rendered. If a child component is entirely
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
     * clipped by the current clipping setting in g, paint() will not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
     * forwarded to that child.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
     * @param g the specified Graphics window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
     * @see   Component#update(Graphics)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
    public void paint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
        if (isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
            synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
                if (printing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
                    if (printingThreads.contains(Thread.currentThread())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
                        return;
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
            // The container is showing on screen and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
            // this paint() is not called from print().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
            // Paint self and forward the paint to lightweight subcomponents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
            // super.paint(); -- Don't bother, since it's a NOP.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
            GraphicsCallback.PaintCallback.getInstance().
2463
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  1952
                runComponents(getComponentsSync(), g, GraphicsCallback.LIGHTWEIGHTS);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
     * Updates the container.  This forwards the update to any lightweight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
     * components that are children of this container.  If this method is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
     * reimplemented, super.update(g) should be called so that lightweight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
     * components are properly rendered.  If a child component is entirely
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
     * clipped by the current clipping setting in g, update() will not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
     * forwarded to that child.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
     * @param g the specified Graphics window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
     * @see   Component#update(Graphics)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
    public void update(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
        if (isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
            if (! (peer instanceof LightweightPeer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
                g.clearRect(0, 0, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
            paint(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
     * Prints the container. This forwards the print to any lightweight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
     * components that are children of this container. If this method is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
     * reimplemented, super.print(g) should be called so that lightweight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
     * components are properly rendered. If a child component is entirely
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
     * clipped by the current clipping setting in g, print() will not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
     * forwarded to that child.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
     * @param g the specified Graphics window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
     * @see   Component#update(Graphics)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
    public void print(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
        if (isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
            Thread t = Thread.currentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
                synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
                    if (printingThreads == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
                        printingThreads = new HashSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
                    printingThreads.add(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
                    printing = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
                super.print(g);  // By default, Component.print() calls paint()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
                synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
                    printingThreads.remove(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
                    printing = !printingThreads.isEmpty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
            GraphicsCallback.PrintCallback.getInstance().
2463
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2007
                runComponents(getComponentsSync(), g, GraphicsCallback.LIGHTWEIGHTS);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
     * Paints each of the components in this container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
     * @param     g   the graphics context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
     * @see       Component#paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
     * @see       Component#paintAll
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
    public void paintComponents(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
        if (isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
            GraphicsCallback.PaintAllCallback.getInstance().
2463
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2020
                runComponents(getComponentsSync(), g, GraphicsCallback.TWO_PASSES);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
     * Simulates the peer callbacks into java.awt for printing of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
     * lightweight Containers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
     * @param     g   the graphics context to use for printing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
     * @see       Component#printAll
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
     * @see       #printComponents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
    void lightweightPaint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
        super.lightweightPaint(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
        paintHeavyweightComponents(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
     * Prints all the heavyweight subcomponents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
    void paintHeavyweightComponents(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
        if (isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
            GraphicsCallback.PaintHeavyweightComponentsCallback.getInstance().
2463
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2042
                runComponents(getComponentsSync(), g,
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2043
                              GraphicsCallback.LIGHTWEIGHTS | GraphicsCallback.HEAVYWEIGHTS);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
     * Prints each of the components in this container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
     * @param     g   the graphics context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
     * @see       Component#print
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
     * @see       Component#printAll
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
    public void printComponents(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
        if (isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
            GraphicsCallback.PrintAllCallback.getInstance().
2463
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2056
                runComponents(getComponentsSync(), g, GraphicsCallback.TWO_PASSES);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
     * Simulates the peer callbacks into java.awt for printing of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
     * lightweight Containers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
     * @param     g   the graphics context to use for printing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
     * @see       Component#printAll
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
     * @see       #printComponents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
    void lightweightPrint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
        super.lightweightPrint(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
        printHeavyweightComponents(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
     * Prints all the heavyweight subcomponents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
    void printHeavyweightComponents(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
        if (isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
            GraphicsCallback.PrintHeavyweightComponentsCallback.getInstance().
2463
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2078
                runComponents(getComponentsSync(), g,
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2079
                              GraphicsCallback.LIGHTWEIGHTS | GraphicsCallback.HEAVYWEIGHTS);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
     * Adds the specified container listener to receive container events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
     * from this container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
     * If l is null, no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
     * @param    l the container listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
     * @see #removeContainerListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
     * @see #getContainerListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
    public synchronized void addContainerListener(ContainerListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
        containerListener = AWTEventMulticaster.add(containerListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
        newEventsOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
     * Removes the specified container listener so it no longer receives
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
     * container events from this container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
     * If l is null, no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
     * @param   l the container listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
     * @see #addContainerListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
     * @see #getContainerListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
    public synchronized void removeContainerListener(ContainerListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
        containerListener = AWTEventMulticaster.remove(containerListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
     * Returns an array of all the container listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
     * registered on this container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
     * @return all of this container's <code>ContainerListener</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
     *         or an empty array if no container
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
     *         listeners are currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
     * @see #addContainerListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
     * @see #removeContainerListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
    public synchronized ContainerListener[] getContainerListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2135
        return (ContainerListener[]) (getListeners(ContainerListener.class));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
     * Returns an array of all the objects currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
     * as <code><em>Foo</em>Listener</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
     * upon this <code>Container</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
     * <code><em>Foo</em>Listener</code>s are registered using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
     * <code>add<em>Foo</em>Listener</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
     * You can specify the <code>listenerType</code> argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
     * with a class literal, such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
     * <code><em>Foo</em>Listener.class</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
     * For example, you can query a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
     * <code>Container</code> <code>c</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
     * for its container listeners with the following code:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
     * <pre>ContainerListener[] cls = (ContainerListener[])(c.getListeners(ContainerListener.class));</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
     * If no such listeners exist, this method returns an empty array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
     * @param listenerType the type of listeners requested; this parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
     *          should specify an interface that descends from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
     *          <code>java.util.EventListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
     * @return an array of all objects registered as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
     *          <code><em>Foo</em>Listener</code>s on this container,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
     *          or an empty array if no such listeners have been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
     * @exception ClassCastException if <code>listenerType</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
     *          doesn't specify a class or interface that implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
     *          <code>java.util.EventListener</code>
7154
4e8371f358ac 6877895: Some AWT's methods should specify throwing NPE for null arg value
dcherepanov
parents: 6827
diff changeset
  2166
     * @exception NullPointerException if {@code listenerType} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
     * @see #getContainerListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
    public <T extends EventListener> T[] getListeners(Class<T> listenerType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
        EventListener l = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
        if  (listenerType == ContainerListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
            l = containerListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
            return super.getListeners(listenerType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
        return AWTEventMulticaster.getListeners(l, listenerType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
    // REMIND: remove when filtering is done at lower level
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
    boolean eventEnabled(AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
        int id = e.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
        if (id == ContainerEvent.COMPONENT_ADDED ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
            id == ContainerEvent.COMPONENT_REMOVED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
            if ((eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
                containerListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
        return super.eventEnabled(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
     * Processes events on this container. If the event is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
     * <code>ContainerEvent</code>, it invokes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
     * <code>processContainerEvent</code> method, else it invokes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
     * its superclass's <code>processEvent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
     * <p>Note that if the event parameter is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
     * the behavior is unspecified and may result in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
     * @param e the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
    protected void processEvent(AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
        if (e instanceof ContainerEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
            processContainerEvent((ContainerEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
        super.processEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2217
     * Processes container events occurring on this container by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2218
     * dispatching them to any registered ContainerListener objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
     * NOTE: This method will not be called unless container events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
     * are enabled for this component; this happens when one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
     * following occurs:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
     * <li>A ContainerListener object is registered via
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
     *     <code>addContainerListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
     * <li>Container events are enabled via <code>enableEvents</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
     * <p>Note that if the event parameter is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
     * the behavior is unspecified and may result in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
     * @param e the container event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2232
     * @see Component#enableEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
    protected void processContainerEvent(ContainerEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
        ContainerListener listener = containerListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
        if (listener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
            switch(e.getID()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
              case ContainerEvent.COMPONENT_ADDED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
                listener.componentAdded(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
              case ContainerEvent.COMPONENT_REMOVED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
                listener.componentRemoved(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2247
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2248
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2249
     * Dispatches an event to this component or one of its sub components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2250
     * Create ANCESTOR_RESIZED and ANCESTOR_MOVED events in response to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2251
     * COMPONENT_RESIZED and COMPONENT_MOVED events. We have to do this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2252
     * here instead of in processComponentEvent because ComponentEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2253
     * may not be enabled for this Container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2254
     * @param e the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2255
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
    void dispatchEventImpl(AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2257
        if ((dispatcher != null) && dispatcher.dispatchEvent(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2258
            // event was sent to a lightweight component.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
            // native-produced event sent to the native container
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2260
            // must be properly disposed of by the peer, so it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2261
            // gets forwarded.  If the native host has been removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2262
            // as a result of the sending the lightweight event,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2263
            // the peer reference will be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2264
            e.consume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2265
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
                peer.handleEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2267
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2268
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2269
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2270
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2271
        super.dispatchEventImpl(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2272
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
            switch (e.getID()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
              case ComponentEvent.COMPONENT_RESIZED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
                createChildHierarchyEvents(HierarchyEvent.ANCESTOR_RESIZED, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2277
                                           Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2278
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2279
              case ComponentEvent.COMPONENT_MOVED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
                createChildHierarchyEvents(HierarchyEvent.ANCESTOR_MOVED, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2281
                                       Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2282
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2283
              default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2285
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2286
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
     * Dispatches an event to this component, without trying to forward
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2291
     * it to any subcomponents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
     * @param e the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2294
    void dispatchEventToSelf(AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
        super.dispatchEventImpl(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2296
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2298
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2299
     * Fetchs the top-most (deepest) lightweight component that is interested
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2300
     * in receiving mouse events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2301
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2302
    Component getMouseEventTarget(int x, int y, boolean includeSelf) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2303
        return getMouseEventTarget(x, y, includeSelf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2304
                                   MouseEventTargetFilter.FILTER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2305
                                   !SEARCH_HEAVYWEIGHTS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2306
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2307
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2308
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2309
     * Fetches the top-most (deepest) component to receive SunDropTargetEvents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2310
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2311
    Component getDropTargetEventTarget(int x, int y, boolean includeSelf) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2312
        return getMouseEventTarget(x, y, includeSelf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2313
                                   DropTargetEventTargetFilter.FILTER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
                                   SEARCH_HEAVYWEIGHTS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2316
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
     * A private version of getMouseEventTarget which has two additional
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2319
     * controllable behaviors. This method searches for the top-most
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
     * descendant of this container that contains the given coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
     * and is accepted by the given filter. The search will be constrained to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2322
     * lightweight descendants if the last argument is <code>false</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2323
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2324
     * @param filter EventTargetFilter instance to determine whether the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2325
     *        given component is a valid target for this event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2326
     * @param searchHeavyweights if <code>false</code>, the method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2327
     *        will bypass heavyweight components during the search.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2329
    private Component getMouseEventTarget(int x, int y, boolean includeSelf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2330
                                          EventTargetFilter filter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2331
                                          boolean searchHeavyweights) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2332
        Component comp = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2333
        if (searchHeavyweights) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2334
            comp = getMouseEventTargetImpl(x, y, includeSelf, filter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2335
                                           SEARCH_HEAVYWEIGHTS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2336
                                           searchHeavyweights);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2337
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2338
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2339
        if (comp == null || comp == this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2340
            comp = getMouseEventTargetImpl(x, y, includeSelf, filter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2341
                                           !SEARCH_HEAVYWEIGHTS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2342
                                           searchHeavyweights);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2343
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2344
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2345
        return comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2346
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2347
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2348
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2349
     * A private version of getMouseEventTarget which has three additional
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2350
     * controllable behaviors. This method searches for the top-most
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2351
     * descendant of this container that contains the given coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2352
     * and is accepted by the given filter. The search will be constrained to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2353
     * descendants of only lightweight children or only heavyweight children
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2354
     * of this container depending on searchHeavyweightChildren. The search will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2355
     * be constrained to only lightweight descendants of the searched children
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2356
     * of this container if searchHeavyweightDescendants is <code>false</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2357
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2358
     * @param filter EventTargetFilter instance to determine whether the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2359
     *        selected component is a valid target for this event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2360
     * @param searchHeavyweightChildren if <code>true</code>, the method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2361
     *        will bypass immediate lightweight children during the search.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2362
     *        If <code>false</code>, the methods will bypass immediate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2363
     *        heavyweight children during the search.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2364
     * @param searchHeavyweightDescendants if <code>false</code>, the method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2365
     *        will bypass heavyweight descendants which are not immediate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2366
     *        children during the search. If <code>true</code>, the method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2367
     *        will traverse both lightweight and heavyweight descendants during
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2368
     *        the search.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2369
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2370
    private Component getMouseEventTargetImpl(int x, int y, boolean includeSelf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
                                         EventTargetFilter filter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2372
                                         boolean searchHeavyweightChildren,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2373
                                         boolean searchHeavyweightDescendants) {
125
079ae88eaea9 6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents: 121
diff changeset
  2374
        synchronized (getTreeLock()) {
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  2375
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  2376
            for (int i = 0; i < component.size(); i++) {
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  2377
                Component comp = component.get(i);
125
079ae88eaea9 6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents: 121
diff changeset
  2378
                if (comp != null && comp.visible &&
079ae88eaea9 6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents: 121
diff changeset
  2379
                    ((!searchHeavyweightChildren &&
079ae88eaea9 6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents: 121
diff changeset
  2380
                      comp.peer instanceof LightweightPeer) ||
079ae88eaea9 6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents: 121
diff changeset
  2381
                     (searchHeavyweightChildren &&
079ae88eaea9 6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents: 121
diff changeset
  2382
                      !(comp.peer instanceof LightweightPeer))) &&
079ae88eaea9 6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents: 121
diff changeset
  2383
                    comp.contains(x - comp.x, y - comp.y)) {
079ae88eaea9 6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents: 121
diff changeset
  2384
079ae88eaea9 6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents: 121
diff changeset
  2385
                    // found a component that intersects the point, see if there
079ae88eaea9 6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents: 121
diff changeset
  2386
                    // is a deeper possibility.
079ae88eaea9 6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents: 121
diff changeset
  2387
                    if (comp instanceof Container) {
079ae88eaea9 6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents: 121
diff changeset
  2388
                        Container child = (Container) comp;
079ae88eaea9 6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents: 121
diff changeset
  2389
                        Component deeper = child.getMouseEventTarget(
079ae88eaea9 6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents: 121
diff changeset
  2390
                                x - child.x,
079ae88eaea9 6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents: 121
diff changeset
  2391
                                y - child.y,
079ae88eaea9 6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents: 121
diff changeset
  2392
                                includeSelf,
079ae88eaea9 6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents: 121
diff changeset
  2393
                                filter,
079ae88eaea9 6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents: 121
diff changeset
  2394
                                searchHeavyweightDescendants);
079ae88eaea9 6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents: 121
diff changeset
  2395
                        if (deeper != null) {
079ae88eaea9 6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents: 121
diff changeset
  2396
                            return deeper;
079ae88eaea9 6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents: 121
diff changeset
  2397
                        }
079ae88eaea9 6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents: 121
diff changeset
  2398
                    } else {
079ae88eaea9 6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents: 121
diff changeset
  2399
                        if (filter.accept(comp)) {
079ae88eaea9 6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents: 121
diff changeset
  2400
                            // there isn't a deeper target, but this component
079ae88eaea9 6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents: 121
diff changeset
  2401
                            // is a target
079ae88eaea9 6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents: 121
diff changeset
  2402
                            return comp;
079ae88eaea9 6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents: 121
diff changeset
  2403
                        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2404
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2405
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2406
            }
125
079ae88eaea9 6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents: 121
diff changeset
  2407
079ae88eaea9 6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents: 121
diff changeset
  2408
            boolean isPeerOK;
079ae88eaea9 6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents: 121
diff changeset
  2409
            boolean isMouseOverMe;
079ae88eaea9 6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents: 121
diff changeset
  2410
079ae88eaea9 6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents: 121
diff changeset
  2411
            isPeerOK = (peer instanceof LightweightPeer) || includeSelf;
079ae88eaea9 6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents: 121
diff changeset
  2412
            isMouseOverMe = contains(x,y);
079ae88eaea9 6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents: 121
diff changeset
  2413
079ae88eaea9 6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents: 121
diff changeset
  2414
            // didn't find a child target, return this component if it's
079ae88eaea9 6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents: 121
diff changeset
  2415
            // a possible target
079ae88eaea9 6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents: 121
diff changeset
  2416
            if (isMouseOverMe && isPeerOK && filter.accept(this)) {
079ae88eaea9 6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents: 121
diff changeset
  2417
                return this;
079ae88eaea9 6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents: 121
diff changeset
  2418
            }
079ae88eaea9 6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents: 121
diff changeset
  2419
            // no possible target
079ae88eaea9 6607660: java.awt.Container.getMouseEventTargetImpl should be invoked while holding the TreeLock
anthony
parents: 121
diff changeset
  2420
            return null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2421
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2422
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2423
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2424
    static interface EventTargetFilter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2425
        boolean accept(final Component comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2426
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2427
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2428
    static class MouseEventTargetFilter implements EventTargetFilter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2429
        static final EventTargetFilter FILTER = new MouseEventTargetFilter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2430
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2431
        private MouseEventTargetFilter() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2432
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2433
        public boolean accept(final Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2434
            return (comp.eventMask & AWTEvent.MOUSE_MOTION_EVENT_MASK) != 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2435
                || (comp.eventMask & AWTEvent.MOUSE_EVENT_MASK) != 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2436
                || (comp.eventMask & AWTEvent.MOUSE_WHEEL_EVENT_MASK) != 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2437
                || comp.mouseListener != null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2438
                || comp.mouseMotionListener != null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2439
                || comp.mouseWheelListener != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2440
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2441
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2442
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2443
    static class DropTargetEventTargetFilter implements EventTargetFilter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2444
        static final EventTargetFilter FILTER = new DropTargetEventTargetFilter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2445
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2446
        private DropTargetEventTargetFilter() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2447
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2448
        public boolean accept(final Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2449
            DropTarget dt = comp.getDropTarget();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2450
            return dt != null && dt.isActive();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2451
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2452
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2453
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2454
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2455
     * This is called by lightweight components that want the containing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2456
     * windowed parent to enable some kind of events on their behalf.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2457
     * This is needed for events that are normally only dispatched to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2458
     * windows to be accepted so that they can be forwarded downward to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2459
     * the lightweight component that has enabled them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2460
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2461
    void proxyEnableEvents(long events) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2462
        if (peer instanceof LightweightPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2463
            // this container is lightweight.... continue sending it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2464
            // upward.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2465
            if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2466
                parent.proxyEnableEvents(events);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2467
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2468
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2469
            // This is a native container, so it needs to host
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2470
            // one of it's children.  If this function is called before
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2471
            // a peer has been created we don't yet have a dispatcher
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2472
            // because it has not yet been determined if this instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2473
            // is lightweight.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2474
            if (dispatcher != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2475
                dispatcher.enableEvents(events);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2476
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2477
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2478
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2479
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2480
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2481
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2482
     * replaced by <code>dispatchEvent(AWTEvent e)</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2483
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2484
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2485
    public void deliverEvent(Event e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2486
        Component comp = getComponentAt(e.x, e.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2487
        if ((comp != null) && (comp != this)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2488
            e.translate(-comp.x, -comp.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2489
            comp.deliverEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2490
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2491
            postEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2492
        }
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
     * Locates the component that contains the x,y position.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2497
     * top-most child component is returned in the case where there
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2498
     * is overlap in the components.  This is determined by finding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2499
     * the component closest to the index 0 that claims to contain
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2500
     * the given point via Component.contains(), except that Components
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2501
     * which have native peers take precedence over those which do not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2502
     * (i.e., lightweight Components).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2503
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2504
     * @param x the <i>x</i> coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2505
     * @param y the <i>y</i> coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2506
     * @return null if the component does not contain the position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2507
     * If there is no child component at the requested point and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2508
     * point is within the bounds of the container the container itself
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2509
     * is returned; otherwise the top-most child is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2510
     * @see Component#contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2511
     * @since JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2512
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2513
    public Component getComponentAt(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2514
        return locate(x, y);
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
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2519
     * replaced by <code>getComponentAt(int, int)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2520
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2521
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2522
    public Component locate(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2523
        if (!contains(x, y)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2524
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2525
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2526
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2527
            // Two passes: see comment in sun.awt.SunGraphicsCallback
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  2528
            for (int i = 0; i < component.size(); i++) {
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  2529
                Component comp = component.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2530
                if (comp != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2531
                    !(comp.peer instanceof LightweightPeer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2532
                    if (comp.contains(x - comp.x, y - comp.y)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2533
                        return comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2534
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2535
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2536
            }
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  2537
            for (int i = 0; i < component.size(); i++) {
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  2538
                Component comp = component.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2539
                if (comp != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2540
                    comp.peer instanceof LightweightPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2541
                    if (comp.contains(x - comp.x, y - comp.y)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2542
                        return comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2543
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2544
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2545
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2546
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2547
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2548
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2549
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2550
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2551
     * Gets the component that contains the specified point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2552
     * @param      p   the point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2553
     * @return     returns the component that contains the point,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2554
     *                 or <code>null</code> if the component does
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2555
     *                 not contain the point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2556
     * @see        Component#contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2557
     * @since      JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2558
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2559
    public Component getComponentAt(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2560
        return getComponentAt(p.x, p.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2561
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2562
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2563
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2564
     * Returns the position of the mouse pointer in this <code>Container</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2565
     * coordinate space if the <code>Container</code> is under the mouse pointer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2566
     * otherwise returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2567
     * This method is similar to {@link Component#getMousePosition()} with the exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2568
     * that it can take the <code>Container</code>'s children into account.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2569
     * If <code>allowChildren</code> is <code>false</code>, this method will return
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2570
     * a non-null value only if the mouse pointer is above the <code>Container</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2571
     * directly, not above the part obscured by children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2572
     * If <code>allowChildren</code> is <code>true</code>, this method returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2573
     * a non-null value if the mouse pointer is above <code>Container</code> or any
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2574
     * of its descendants.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2575
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2576
     * @exception HeadlessException if GraphicsEnvironment.isHeadless() returns true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2577
     * @param     allowChildren true if children should be taken into account
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2578
     * @see       Component#getMousePosition
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2579
     * @return    mouse coordinates relative to this <code>Component</code>, or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2580
     * @since     1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2581
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2582
    public Point getMousePosition(boolean allowChildren) throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2583
        if (GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2584
            throw new HeadlessException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2585
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2586
        PointerInfo pi = (PointerInfo)java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2587
            new java.security.PrivilegedAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2588
                public Object run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2589
                    return MouseInfo.getPointerInfo();
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
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2594
            Component inTheSameWindow = findUnderMouseInWindow(pi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2595
            if (isSameOrAncestorOf(inTheSameWindow, allowChildren)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2596
                return  pointRelativeToComponent(pi.getLocation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2597
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2598
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2599
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2600
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2601
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2602
    boolean isSameOrAncestorOf(Component comp, boolean allowChildren) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2603
        return this == comp || (allowChildren && isParentOf(comp));
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
     * Locates the visible child component that contains the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2608
     * position.  The top-most child component is returned in the case
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2609
     * where there is overlap in the components.  If the containing child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2610
     * component is a Container, this method will continue searching for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2611
     * the deepest nested child component.  Components which are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2612
     * visible are ignored during the search.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2613
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2614
     * The findComponentAt method is different from getComponentAt in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2615
     * that getComponentAt only searches the Container's immediate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2616
     * children; if the containing component is a Container,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2617
     * findComponentAt will search that child to find a nested component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2618
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2619
     * @param x the <i>x</i> coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2620
     * @param y the <i>y</i> coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2621
     * @return null if the component does not contain the position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2622
     * If there is no child component at the requested point and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2623
     * point is within the bounds of the container the container itself
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2624
     * is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2625
     * @see Component#contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2626
     * @see #getComponentAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2627
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2628
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2629
    public Component findComponentAt(int x, int y) {
2463
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2630
        return findComponentAt(x, y, true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2631
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2632
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2633
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2634
     * Private version of findComponentAt which has a controllable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2635
     * behavior. Setting 'ignoreEnabled' to 'false' bypasses disabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2636
     * Components during the search. This behavior is used by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2637
     * lightweight cursor support in sun.awt.GlobalCursorManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2638
     * The cursor code calls this function directly via native code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2639
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2640
     * The addition of this feature is temporary, pending the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2641
     * adoption of new, public API which exports this feature.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2642
     */
2463
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2643
    final Component findComponentAt(int x, int y, boolean ignoreEnabled) {
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2644
        synchronized (getTreeLock()) {
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2645
            if (isRecursivelyVisible()){
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2646
                return findComponentAtImpl(x, y, ignoreEnabled);
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2647
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2648
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2649
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2650
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2651
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2652
    final Component findComponentAtImpl(int x, int y, boolean ignoreEnabled){
2463
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2653
        checkTreeLock();
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2654
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2655
        if (!(contains(x, y) && visible && (ignoreEnabled || enabled))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2656
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2657
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2658
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2659
        // Two passes: see comment in sun.awt.SunGraphicsCallback
2463
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2660
        for (int i = 0; i < component.size(); i++) {
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2661
            Component comp = component.get(i);
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2662
            if (comp != null &&
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2663
                !(comp.peer instanceof LightweightPeer)) {
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2664
                if (comp instanceof Container) {
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2665
                    comp = ((Container)comp).findComponentAtImpl(x - comp.x,
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2666
                                                                 y - comp.y,
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2667
                                                                 ignoreEnabled);
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2668
                } else {
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2669
                    comp = comp.locate(x - comp.x, y - comp.y);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2670
                }
2463
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2671
                if (comp != null && comp.visible &&
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2672
                    (ignoreEnabled || comp.enabled))
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2673
                {
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2674
                    return comp;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2675
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2676
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2677
        }
2463
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2678
        for (int i = 0; i < component.size(); i++) {
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2679
            Component comp = component.get(i);
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2680
            if (comp != null &&
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2681
                comp.peer instanceof LightweightPeer) {
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2682
                if (comp instanceof Container) {
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2683
                    comp = ((Container)comp).findComponentAtImpl(x - comp.x,
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2684
                                                                 y - comp.y,
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2685
                                                                 ignoreEnabled);
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2686
                } else {
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2687
                    comp = comp.locate(x - comp.x, y - comp.y);
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2688
                }
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2689
                if (comp != null && comp.visible &&
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2690
                    (ignoreEnabled || comp.enabled))
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2691
                {
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2692
                    return comp;
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2693
                }
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2694
            }
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2695
        }
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  2696
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2697
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2698
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2699
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2700
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2701
     * Locates the visible child component that contains the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2702
     * point.  The top-most child component is returned in the case
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2703
     * where there is overlap in the components.  If the containing child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2704
     * component is a Container, this method will continue searching for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2705
     * the deepest nested child component.  Components which are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2706
     * visible are ignored during the search.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2707
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2708
     * The findComponentAt method is different from getComponentAt in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2709
     * that getComponentAt only searches the Container's immediate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2710
     * children; if the containing component is a Container,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2711
     * findComponentAt will search that child to find a nested component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2712
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2713
     * @param      p   the point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2714
     * @return null if the component does not contain the position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2715
     * If there is no child component at the requested point and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2716
     * point is within the bounds of the container the container itself
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2717
     * is returned.
7154
4e8371f358ac 6877895: Some AWT's methods should specify throwing NPE for null arg value
dcherepanov
parents: 6827
diff changeset
  2718
     * @throws NullPointerException if {@code p} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2719
     * @see Component#contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2720
     * @see #getComponentAt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2721
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2722
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2723
    public Component findComponentAt(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2724
        return findComponentAt(p.x, p.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2725
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2726
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2727
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2728
     * Makes this Container displayable by connecting it to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2729
     * a native screen resource.  Making a container displayable will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2730
     * cause all of its children to be made displayable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2731
     * This method is called internally by the toolkit and should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2732
     * not be called directly by programs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2733
     * @see Component#isDisplayable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2734
     * @see #removeNotify
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2735
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2736
    public void addNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2737
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2738
            // addNotify() on the children may cause proxy event enabling
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2739
            // on this instance, so we first call super.addNotify() and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2740
            // possibly create an lightweight event dispatcher before calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2741
            // addNotify() on the children which may be lightweight.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2742
            super.addNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2743
            if (! (peer instanceof LightweightPeer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2744
                dispatcher = new LightweightDispatcher(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2745
            }
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  2746
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  2747
            // We shouldn't use iterator because of the Swing menu
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  2748
            // implementation specifics:
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  2749
            // the menu is being assigned as a child to JLayeredPane
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  2750
            // instead of particular component so always affect
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  2751
            // collection of component if menu is becoming shown or hidden.
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  2752
            for (int i = 0; i < component.size(); i++) {
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  2753
                component.get(i).addNotify();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2754
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2755
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2756
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2757
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2758
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2759
     * Makes this Container undisplayable by removing its connection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2760
     * to its native screen resource.  Making a container undisplayable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2761
     * will cause all of its children to be made undisplayable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2762
     * This method is called by the toolkit internally and should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2763
     * not be called directly by programs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2764
     * @see Component#isDisplayable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2765
     * @see #addNotify
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2766
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2767
    public void removeNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2768
        synchronized (getTreeLock()) {
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  2769
            // We shouldn't use iterator because of the Swing menu
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  2770
            // implementation specifics:
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  2771
            // the menu is being assigned as a child to JLayeredPane
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  2772
            // instead of particular component so always affect
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  2773
            // collection of component if menu is becoming shown or hidden.
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  2774
            for (int i = component.size()-1 ; i >= 0 ; i--) {
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  2775
                Component comp = component.get(i);
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  2776
                if (comp != null) {
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 130
diff changeset
  2777
                    // Fix for 6607170.
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 130
diff changeset
  2778
                    // We want to suppress focus change on disposal
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 130
diff changeset
  2779
                    // of the focused component. But because of focus
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 130
diff changeset
  2780
                    // is asynchronous, we should suppress focus change
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 130
diff changeset
  2781
                    // on every component in case it receives native focus
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 130
diff changeset
  2782
                    // in the process of disposal.
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  2783
                    comp.setAutoFocusTransferOnDisposal(false);
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  2784
                    comp.removeNotify();
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  2785
                    comp.setAutoFocusTransferOnDisposal(true);
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  2786
                 }
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  2787
             }
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 130
diff changeset
  2788
            // If some of the children had focus before disposal then it still has.
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 130
diff changeset
  2789
            // Auto-transfer focus to the next (or previous) component if auto-transfer
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 130
diff changeset
  2790
            // is enabled.
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 130
diff changeset
  2791
            if (containsFocus() && KeyboardFocusManager.isAutoFocusTransferEnabledFor(this)) {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 130
diff changeset
  2792
                if (!transferFocus(false)) {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 130
diff changeset
  2793
                    transferFocusBackward(true);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 130
diff changeset
  2794
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2795
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2796
            if ( dispatcher != null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2797
                dispatcher.dispose();
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  2798
                dispatcher = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2799
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2800
            super.removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2801
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2802
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2803
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2804
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2805
     * Checks if the component is contained in the component hierarchy of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2806
     * this container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2807
     * @param c the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2808
     * @return     <code>true</code> if it is an ancestor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2809
     *             <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2810
     * @since      JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2811
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2812
    public boolean isAncestorOf(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2813
        Container p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2814
        if (c == null || ((p = c.getParent()) == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2815
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2816
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2817
        while (p != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2818
            if (p == this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2819
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2820
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2821
            p = p.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2822
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2823
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2824
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2825
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2826
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2827
     * The following code was added to support modal JInternalFrames
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2828
     * Unfortunately this code has to be added here so that we can get access to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2829
     * some private AWT classes like SequencedEvent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2830
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2831
     * The native container of the LW component has this field set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2832
     * to tell it that it should block Mouse events for all LW
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2833
     * children except for the modal component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2834
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2835
     * In the case of nested Modal components, we store the previous
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2836
     * modal component in the new modal components value of modalComp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2837
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2838
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2839
    transient Component modalComp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2840
    transient AppContext modalAppContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2841
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2842
    private void startLWModal() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2843
        // Store the app context on which this component is being shown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2844
        // Event dispatch thread of this app context will be sleeping until
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2845
        // we wake it by any event from hideAndDisposeHandler().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2846
        modalAppContext = AppContext.getAppContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2847
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2848
        // keep the KeyEvents from being dispatched
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2849
        // until the focus has been transfered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2850
        long time = Toolkit.getEventQueue().getMostRecentEventTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2851
        Component predictedFocusOwner = (Component.isInstanceOf(this, "javax.swing.JInternalFrame")) ? ((javax.swing.JInternalFrame)(this)).getMostRecentFocusOwner() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2852
        if (predictedFocusOwner != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2853
            KeyboardFocusManager.getCurrentKeyboardFocusManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2854
                enqueueKeyEvents(time, predictedFocusOwner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2855
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2856
        // We have two mechanisms for blocking: 1. If we're on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2857
        // EventDispatchThread, start a new event pump. 2. If we're
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2858
        // on any other thread, call wait() on the treelock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2859
        final Container nativeContainer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2860
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2861
            nativeContainer = getHeavyweightContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2862
            if (nativeContainer.modalComp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2863
                this.modalComp =  nativeContainer.modalComp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2864
                nativeContainer.modalComp = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2865
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2866
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2867
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2868
                nativeContainer.modalComp = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2869
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2870
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2871
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2872
        Runnable pumpEventsForHierarchy = new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2873
            public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2874
                EventDispatchThread dispatchThread =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2875
                    (EventDispatchThread)Thread.currentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2876
                dispatchThread.pumpEventsForHierarchy(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2877
                        new Conditional() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2878
                        public boolean evaluate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2879
                        return ((windowClosingException == null) && (nativeContainer.modalComp != null)) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2880
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2881
                        }, Container.this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2882
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2883
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2884
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2885
        if (EventQueue.isDispatchThread()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2886
            SequencedEvent currentSequencedEvent =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2887
                KeyboardFocusManager.getCurrentKeyboardFocusManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2888
                getCurrentSequencedEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2889
            if (currentSequencedEvent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2890
                currentSequencedEvent.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2891
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2892
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2893
            pumpEventsForHierarchy.run();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2894
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2895
            synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2896
                Toolkit.getEventQueue().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2897
                    postEvent(new PeerEvent(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2898
                                pumpEventsForHierarchy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2899
                                PeerEvent.PRIORITY_EVENT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2900
                while ((windowClosingException == null) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2901
                       (nativeContainer.modalComp != null))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2902
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2903
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2904
                        getTreeLock().wait();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2905
                    } catch (InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2906
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2907
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2908
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2909
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2910
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2911
        if (windowClosingException != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2912
            windowClosingException.fillInStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2913
            throw windowClosingException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2914
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2915
        if (predictedFocusOwner != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2916
            KeyboardFocusManager.getCurrentKeyboardFocusManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2917
                dequeueKeyEvents(time, predictedFocusOwner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2918
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2919
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2920
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2921
    private void stopLWModal() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2922
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2923
            if (modalAppContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2924
                Container nativeContainer = getHeavyweightContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2925
                if(nativeContainer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2926
                    if (this.modalComp !=  null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2927
                        nativeContainer.modalComp = this.modalComp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2928
                        this.modalComp = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2929
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2930
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2931
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2932
                        nativeContainer.modalComp = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2933
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2934
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2935
                // Wake up event dispatch thread on which the dialog was
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2936
                // initially shown
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2937
                SunToolkit.postEvent(modalAppContext,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2938
                        new PeerEvent(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2939
                                new WakingRunnable(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2940
                                PeerEvent.PRIORITY_EVENT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2941
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2942
            EventQueue.invokeLater(new WakingRunnable());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2943
            getTreeLock().notifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2944
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2945
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2946
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2947
    final static class WakingRunnable implements Runnable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2948
        public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2949
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2950
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2951
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2952
    /* End of JOptionPane support code */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2953
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2954
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2955
     * Returns a string representing the state of this <code>Container</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2956
     * This method is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2957
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2958
     * implementations. The returned string may be empty but may not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2959
     * <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2960
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2961
     * @return    the parameter string of this container
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2962
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2963
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2964
        String str = super.paramString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2965
        LayoutManager layoutMgr = this.layoutMgr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2966
        if (layoutMgr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2967
            str += ",layout=" + layoutMgr.getClass().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2968
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2969
        return str;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2970
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2971
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2972
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2973
     * Prints a listing of this container to the specified output
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2974
     * stream. The listing starts at the specified indentation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2975
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2976
     * The immediate children of the container are printed with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2977
     * an indentation of <code>indent+1</code>.  The children
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2978
     * of those children are printed at <code>indent+2</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2979
     * and so on.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2980
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2981
     * @param    out      a print stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2982
     * @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: 6827
diff changeset
  2983
     * @throws   NullPointerException if {@code out} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2984
     * @see      Component#list(java.io.PrintStream, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2985
     * @since    JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2986
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2987
    public void list(PrintStream out, int indent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2988
        super.list(out, indent);
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  2989
        synchronized(getTreeLock()) {
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  2990
            for (int i = 0; i < component.size(); i++) {
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  2991
                Component comp = component.get(i);
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  2992
                if (comp != null) {
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  2993
                    comp.list(out, indent+1);
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  2994
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2995
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2996
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2997
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2998
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2999
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3000
     * Prints out a list, starting at the specified indentation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3001
     * to the specified print writer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3002
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3003
     * The immediate children of the container are printed with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3004
     * an indentation of <code>indent+1</code>.  The children
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3005
     * of those children are printed at <code>indent+2</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3006
     * and so on.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3007
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3008
     * @param    out      a print writer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3009
     * @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: 6827
diff changeset
  3010
     * @throws   NullPointerException if {@code out} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3011
     * @see      Component#list(java.io.PrintWriter, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3012
     * @since    JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3013
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3014
    public void list(PrintWriter out, int indent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3015
        super.list(out, indent);
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  3016
        synchronized(getTreeLock()) {
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  3017
            for (int i = 0; i < component.size(); i++) {
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  3018
                Component comp = component.get(i);
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  3019
                if (comp != null) {
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  3020
                    comp.list(out, indent+1);
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  3021
                }
2
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3026
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3027
     * Sets the focus traversal keys for a given traversal operation for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3028
     * Container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3029
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3030
     * The default values for a Container's focus traversal keys are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3031
     * implementation-dependent. Sun recommends that all implementations for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3032
     * particular native platform use the same default values. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3033
     * recommendations for Windows and Unix are listed below. These
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3034
     * recommendations are used in the Sun AWT implementations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3035
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3036
     * <table border=1 summary="Recommended default values for a Container's focus traversal keys">
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3037
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3038
     *    <th>Identifier</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3039
     *    <th>Meaning</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3040
     *    <th>Default</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3041
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3042
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3043
     *    <td>KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3044
     *    <td>Normal forward keyboard traversal</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3045
     *    <td>TAB on KEY_PRESSED, CTRL-TAB on KEY_PRESSED</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3046
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3047
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3048
     *    <td>KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3049
     *    <td>Normal reverse keyboard traversal</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3050
     *    <td>SHIFT-TAB on KEY_PRESSED, CTRL-SHIFT-TAB on KEY_PRESSED</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3051
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3052
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3053
     *    <td>KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3054
     *    <td>Go up one focus traversal cycle</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3055
     *    <td>none</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3056
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3057
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3058
     *    <td>KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS<td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3059
     *    <td>Go down one focus traversal cycle</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3060
     *    <td>none</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3061
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3062
     * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3063
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3064
     * To disable a traversal key, use an empty Set; Collections.EMPTY_SET is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3065
     * recommended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3066
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3067
     * Using the AWTKeyStroke API, client code can specify on which of two
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3068
     * specific KeyEvents, KEY_PRESSED or KEY_RELEASED, the focus traversal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3069
     * operation will occur. Regardless of which KeyEvent is specified,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3070
     * however, all KeyEvents related to the focus traversal key, including the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3071
     * associated KEY_TYPED event, will be consumed, and will not be dispatched
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3072
     * to any Container. It is a runtime error to specify a KEY_TYPED event as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3073
     * mapping to a focus traversal operation, or to map the same event to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3074
     * multiple default focus traversal operations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3075
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3076
     * If a value of null is specified for the Set, this Container inherits the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3077
     * Set from its parent. If all ancestors of this Container have null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3078
     * specified for the Set, then the current KeyboardFocusManager's default
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3079
     * Set is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3080
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3081
     * @param id one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3082
     *        KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3083
     *        KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3084
     *        KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3085
     * @param keystrokes the Set of AWTKeyStroke for the specified operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3086
     * @see #getFocusTraversalKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3087
     * @see KeyboardFocusManager#FORWARD_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3088
     * @see KeyboardFocusManager#BACKWARD_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3089
     * @see KeyboardFocusManager#UP_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3090
     * @see KeyboardFocusManager#DOWN_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3091
     * @throws IllegalArgumentException if id is not one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3092
     *         KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3093
     *         KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3094
     *         KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3095
     *         KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS, or if keystrokes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3096
     *         contains null, or if any Object in keystrokes is not an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3097
     *         AWTKeyStroke, or if any keystroke represents a KEY_TYPED event,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3098
     *         or if any keystroke already maps to another focus traversal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3099
     *         operation for this Container
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3100
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3101
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3102
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3103
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3104
    public void setFocusTraversalKeys(int id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3105
                                      Set<? extends AWTKeyStroke> keystrokes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3106
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3107
        if (id < 0 || id >= KeyboardFocusManager.TRAVERSAL_KEY_LENGTH) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3108
            throw new IllegalArgumentException("invalid focus traversal key identifier");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3109
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3110
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3111
        // Don't call super.setFocusTraversalKey. The Component parameter check
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3112
        // does not allow DOWN_CYCLE_TRAVERSAL_KEYS, but we do.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3113
        setFocusTraversalKeys_NoIDCheck(id, keystrokes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3115
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3116
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3117
     * Returns the Set of focus traversal keys for a given traversal operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3118
     * for this Container. (See
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3119
     * <code>setFocusTraversalKeys</code> for a full description of each key.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3120
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3121
     * If a Set of traversal keys has not been explicitly defined for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3122
     * Container, then this Container's parent's Set is returned. If no Set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3123
     * has been explicitly defined for any of this Container's ancestors, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3124
     * the current KeyboardFocusManager's default Set is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3125
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3126
     * @param id one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3127
     *        KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3128
     *        KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3129
     *        KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3130
     * @return the Set of AWTKeyStrokes for the specified operation. The Set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3131
     *         will be unmodifiable, and may be empty. null will never be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3132
     *         returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3133
     * @see #setFocusTraversalKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3134
     * @see KeyboardFocusManager#FORWARD_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3135
     * @see KeyboardFocusManager#BACKWARD_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3136
     * @see KeyboardFocusManager#UP_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3137
     * @see KeyboardFocusManager#DOWN_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3138
     * @throws IllegalArgumentException if id is not one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3139
     *         KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3140
     *         KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3141
     *         KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3142
     *         KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3143
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3144
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3145
    public Set<AWTKeyStroke> getFocusTraversalKeys(int id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3146
        if (id < 0 || id >= KeyboardFocusManager.TRAVERSAL_KEY_LENGTH) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3147
            throw new IllegalArgumentException("invalid focus traversal key identifier");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3148
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3149
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3150
        // Don't call super.getFocusTraversalKey. The Component parameter check
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3151
        // does not allow DOWN_CYCLE_TRAVERSAL_KEY, but we do.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3152
        return getFocusTraversalKeys_NoIDCheck(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3154
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3155
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3156
     * Returns whether the Set of focus traversal keys for the given focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3157
     * traversal operation has been explicitly defined for this Container. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3158
     * this method returns <code>false</code>, this Container is inheriting the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3159
     * Set from an ancestor, or from the current KeyboardFocusManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3160
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3161
     * @param id one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3162
     *        KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3163
     *        KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3164
     *        KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3165
     * @return <code>true</code> if the the Set of focus traversal keys for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3166
     *         given focus traversal operation has been explicitly defined for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3167
     *         this Component; <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3168
     * @throws IllegalArgumentException if id is not one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3169
     *         KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3170
     *        KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3171
     *        KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3172
     *        KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3173
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3174
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3175
    public boolean areFocusTraversalKeysSet(int id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3176
        if (id < 0 || id >= KeyboardFocusManager.TRAVERSAL_KEY_LENGTH) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3177
            throw new IllegalArgumentException("invalid focus traversal key identifier");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3179
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3180
        return (focusTraversalKeys != null && focusTraversalKeys[id] != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3182
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3183
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3184
     * Returns whether the specified Container is the focus cycle root of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3185
     * Container's focus traversal cycle. Each focus traversal cycle has only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3186
     * a single focus cycle root and each Container which is not a focus cycle
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3187
     * root belongs to only a single focus traversal cycle. Containers which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3188
     * are focus cycle roots belong to two cycles: one rooted at the Container
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3189
     * itself, and one rooted at the Container's nearest focus-cycle-root
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3190
     * ancestor. This method will return <code>true</code> for both such
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3191
     * Containers in this case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3192
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3193
     * @param container the Container to be tested
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3194
     * @return <code>true</code> if the specified Container is a focus-cycle-
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3195
     *         root of this Container; <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3196
     * @see #isFocusCycleRoot()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3197
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3198
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3199
    public boolean isFocusCycleRoot(Container container) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3200
        if (isFocusCycleRoot() && container == this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3201
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3202
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3203
            return super.isFocusCycleRoot(container);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3206
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3207
    private Container findTraversalRoot() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3208
        // I potentially have two roots, myself and my root parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3209
        // If I am the current root, then use me
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3210
        // If none of my parents are roots, then use me
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3211
        // If my root parent is the current root, then use my root parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3212
        // If neither I nor my root parent is the current root, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3213
        // use my root parent (a guess)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3214
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3215
        Container currentFocusCycleRoot = KeyboardFocusManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3216
            getCurrentKeyboardFocusManager().getCurrentFocusCycleRoot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3217
        Container root;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3218
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3219
        if (currentFocusCycleRoot == this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3220
            root = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3221
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3222
            root = getFocusCycleRootAncestor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3223
            if (root == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3224
                root = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3225
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3226
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3227
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3228
        if (root != currentFocusCycleRoot) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3229
            KeyboardFocusManager.getCurrentKeyboardFocusManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3230
                setGlobalCurrentFocusCycleRoot(root);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3231
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3232
        return root;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3234
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3235
    final boolean containsFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3236
        final Component focusOwner = KeyboardFocusManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3237
            getCurrentKeyboardFocusManager().getFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3238
        return isParentOf(focusOwner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3240
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3241
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3242
     * Check if this component is the child of this container or its children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3243
     * Note: this function acquires treeLock
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3244
     * Note: this function traverses children tree only in one Window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3245
     * @param comp a component in test, must not be null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3246
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3247
    private boolean isParentOf(Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3248
        synchronized(getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3249
            while (comp != null && comp != this && !(comp instanceof Window)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3250
                comp = comp.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3251
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3252
            return (comp == this);
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
    void clearMostRecentFocusOwnerOnHide() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3257
        boolean reset = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3258
        Window window = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3259
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3260
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3261
            window = getContainingWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3262
            if (window != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3263
                Component comp = KeyboardFocusManager.getMostRecentFocusOwner(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3264
                reset = ((comp == this) || isParentOf(comp));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3265
                // This synchronized should always be the second in a pair
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3266
                // (tree lock, KeyboardFocusManager.class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3267
                synchronized(KeyboardFocusManager.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3268
                    Component storedComp = window.getTemporaryLostComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3269
                    if (isParentOf(storedComp) || storedComp == this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3270
                        window.setTemporaryLostComponent(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3271
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3272
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3273
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3274
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3275
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3276
        if (reset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3277
            KeyboardFocusManager.setMostRecentFocusOwner(window, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3278
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3279
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3280
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3281
    void clearCurrentFocusCycleRootOnHide() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3282
        KeyboardFocusManager kfm =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3283
            KeyboardFocusManager.getCurrentKeyboardFocusManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3284
        Container cont = kfm.getCurrentFocusCycleRoot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3285
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3286
        if (cont == this || isParentOf(cont)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3287
            kfm.setGlobalCurrentFocusCycleRoot(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3289
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3290
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3291
    final Container getTraversalRoot() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3292
        if (isFocusCycleRoot()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3293
            return findTraversalRoot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3294
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3295
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3296
        return super.getTraversalRoot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3298
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3299
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3300
     * Sets the focus traversal policy that will manage keyboard traversal of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3301
     * this Container's children, if this Container is a focus cycle root. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3302
     * the argument is null, this Container inherits its policy from its focus-
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3303
     * cycle-root ancestor. If the argument is non-null, this policy will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3304
     * inherited by all focus-cycle-root children that have no keyboard-
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3305
     * traversal policy of their own (as will, recursively, their focus-cycle-
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3306
     * root children).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3307
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3308
     * If this Container is not a focus cycle root, the policy will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3309
     * remembered, but will not be used or inherited by this or any other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3310
     * Containers until this Container is made a focus cycle root.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3311
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3312
     * @param policy the new focus traversal policy for this Container
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3313
     * @see #getFocusTraversalPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3314
     * @see #setFocusCycleRoot
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3315
     * @see #isFocusCycleRoot
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3316
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3317
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3318
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3319
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3320
    public void setFocusTraversalPolicy(FocusTraversalPolicy policy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3321
        FocusTraversalPolicy oldPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3322
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3323
            oldPolicy = this.focusTraversalPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3324
            this.focusTraversalPolicy = policy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3325
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3326
        firePropertyChange("focusTraversalPolicy", oldPolicy, policy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3328
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3329
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3330
     * Returns the focus traversal policy that will manage keyboard traversal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3331
     * of this Container's children, or null if this Container is not a focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3332
     * cycle root. If no traversal policy has been explicitly set for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3333
     * Container, then this Container's focus-cycle-root ancestor's policy is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3334
     * returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3335
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3336
     * @return this Container's focus traversal policy, or null if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3337
     *         Container is not a focus cycle root.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3338
     * @see #setFocusTraversalPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3339
     * @see #setFocusCycleRoot
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3340
     * @see #isFocusCycleRoot
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3341
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3342
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3343
    public FocusTraversalPolicy getFocusTraversalPolicy() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3344
        if (!isFocusTraversalPolicyProvider() && !isFocusCycleRoot()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3345
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3346
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3347
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3348
        FocusTraversalPolicy policy = this.focusTraversalPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3349
        if (policy != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3350
            return policy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3351
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3352
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3353
        Container rootAncestor = getFocusCycleRootAncestor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3354
        if (rootAncestor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3355
            return rootAncestor.getFocusTraversalPolicy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3356
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3357
            return KeyboardFocusManager.getCurrentKeyboardFocusManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3358
                getDefaultFocusTraversalPolicy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3359
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3360
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3361
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3362
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3363
     * Returns whether the focus traversal policy has been explicitly set for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3364
     * this Container. If this method returns <code>false</code>, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3365
     * Container will inherit its focus traversal policy from an ancestor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3366
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3367
     * @return <code>true</code> if the focus traversal policy has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3368
     *         explicitly set for this Container; <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3369
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3370
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3371
    public boolean isFocusTraversalPolicySet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3372
        return (focusTraversalPolicy != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3373
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3374
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3375
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3376
     * Sets whether this Container is the root of a focus traversal cycle. Once
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3377
     * focus enters a traversal cycle, typically it cannot leave it via focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3378
     * traversal unless one of the up- or down-cycle keys is pressed. Normal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3379
     * traversal is limited to this Container, and all of this Container's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3380
     * descendants that are not descendants of inferior focus cycle roots. Note
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3381
     * that a FocusTraversalPolicy may bend these restrictions, however. For
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3382
     * example, ContainerOrderFocusTraversalPolicy supports implicit down-cycle
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3383
     * traversal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3384
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3385
     * The alternative way to specify the traversal order of this Container's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3386
     * children is to make this Container a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3387
     * <a href="doc-files/FocusSpec.html#FocusTraversalPolicyProviders">focus traversal policy provider</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3388
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3389
     * @param focusCycleRoot indicates whether this Container is the root of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3390
     *        focus traversal cycle
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3391
     * @see #isFocusCycleRoot()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3392
     * @see #setFocusTraversalPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3393
     * @see #getFocusTraversalPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3394
     * @see ContainerOrderFocusTraversalPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3395
     * @see #setFocusTraversalPolicyProvider
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3396
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3397
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3398
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3399
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3400
    public void setFocusCycleRoot(boolean focusCycleRoot) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3401
        boolean oldFocusCycleRoot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3402
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3403
            oldFocusCycleRoot = this.focusCycleRoot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3404
            this.focusCycleRoot = focusCycleRoot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3405
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3406
        firePropertyChange("focusCycleRoot", oldFocusCycleRoot,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3407
                           focusCycleRoot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3408
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3409
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3410
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3411
     * Returns whether this Container is the root of a focus traversal cycle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3412
     * Once focus enters a traversal cycle, typically it cannot leave it via
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3413
     * focus traversal unless one of the up- or down-cycle keys is pressed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3414
     * Normal traversal is limited to this Container, and all of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3415
     * Container's descendants that are not descendants of inferior focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3416
     * cycle roots. Note that a FocusTraversalPolicy may bend these
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3417
     * restrictions, however. For example, ContainerOrderFocusTraversalPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3418
     * supports implicit down-cycle traversal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3419
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3420
     * @return whether this Container is the root of a focus traversal cycle
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3421
     * @see #setFocusCycleRoot
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3422
     * @see #setFocusTraversalPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3423
     * @see #getFocusTraversalPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3424
     * @see ContainerOrderFocusTraversalPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3425
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3426
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3427
    public boolean isFocusCycleRoot() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3428
        return focusCycleRoot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3429
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3430
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3431
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3432
     * Sets whether this container will be used to provide focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3433
     * traversal policy. Container with this property as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3434
     * <code>true</code> will be used to acquire focus traversal policy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3435
     * instead of closest focus cycle root ancestor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3436
     * @param provider indicates whether this container will be used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3437
     *                provide focus traversal policy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3438
     * @see #setFocusTraversalPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3439
     * @see #getFocusTraversalPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3440
     * @see #isFocusTraversalPolicyProvider
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3441
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3442
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3443
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3444
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3445
    public final void setFocusTraversalPolicyProvider(boolean provider) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3446
        boolean oldProvider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3447
        synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3448
            oldProvider = focusTraversalPolicyProvider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3449
            focusTraversalPolicyProvider = provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3450
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3451
        firePropertyChange("focusTraversalPolicyProvider", oldProvider, provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3452
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3453
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3454
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3455
     * Returns whether this container provides focus traversal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3456
     * policy. If this property is set to <code>true</code> then when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3457
     * keyboard focus manager searches container hierarchy for focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3458
     * traversal policy and encounters this container before any other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3459
     * container with this property as true or focus cycle roots then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3460
     * its focus traversal policy will be used instead of focus cycle
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3461
     * root's policy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3462
     * @see #setFocusTraversalPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3463
     * @see #getFocusTraversalPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3464
     * @see #setFocusCycleRoot
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3465
     * @see #setFocusTraversalPolicyProvider
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3466
     * @return <code>true</code> if this container provides focus traversal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3467
     *         policy, <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3468
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3469
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3470
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3471
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3472
    public final boolean isFocusTraversalPolicyProvider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3473
        return focusTraversalPolicyProvider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3474
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3475
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3476
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3477
     * Transfers the focus down one focus traversal cycle. If this Container is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3478
     * a focus cycle root, then the focus owner is set to this Container's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3479
     * default Component to focus, and the current focus cycle root is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3480
     * this Container. If this Container is not a focus cycle root, then no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3481
     * focus traversal operation occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3482
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3483
     * @see       Component#requestFocus()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3484
     * @see       #isFocusCycleRoot
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3485
     * @see       #setFocusCycleRoot
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3486
     * @since     1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3487
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3488
    public void transferFocusDownCycle() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3489
        if (isFocusCycleRoot()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3490
            KeyboardFocusManager.getCurrentKeyboardFocusManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3491
                setGlobalCurrentFocusCycleRoot(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3492
            Component toFocus = getFocusTraversalPolicy().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3493
                getDefaultComponent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3494
            if (toFocus != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3495
                toFocus.requestFocus(CausedFocusEvent.Cause.TRAVERSAL_DOWN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3496
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3497
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3498
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3499
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3500
    void preProcessKeyEvent(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3501
        Container parent = this.parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3502
        if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3503
            parent.preProcessKeyEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3504
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3505
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3506
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3507
    void postProcessKeyEvent(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3508
        Container parent = this.parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3509
        if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3510
            parent.postProcessKeyEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3511
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3512
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3513
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3514
    boolean postsOldMouseEvents() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3515
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3516
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3517
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3518
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3519
     * Sets the <code>ComponentOrientation</code> property of this container
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3520
     * 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: 2805
diff changeset
  3521
     * <p>
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
  3522
     * 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: 2805
diff changeset
  3523
     * invalidates the component hierarchy.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3524
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3525
     * @param o the new component orientation of this container and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3526
     *        the components contained within it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3527
     * @exception NullPointerException if <code>orientation</code> is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3528
     * @see Component#setComponentOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3529
     * @see Component#getComponentOrientation
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 2805
diff changeset
  3530
     * @see #invalidate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3531
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3532
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3533
    public void applyComponentOrientation(ComponentOrientation o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3534
        super.applyComponentOrientation(o);
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  3535
        synchronized (getTreeLock()) {
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  3536
            for (int i = 0; i < component.size(); i++) {
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  3537
                Component comp = component.get(i);
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  3538
                comp.applyComponentOrientation(o);
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  3539
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3540
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3541
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3542
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3543
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3544
     * Adds a PropertyChangeListener to the listener list. The listener is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3545
     * registered for all bound properties of this class, including the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3546
     * following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3547
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3548
     *    <li>this Container's font ("font")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3549
     *    <li>this Container's background color ("background")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3550
     *    <li>this Container's foreground color ("foreground")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3551
     *    <li>this Container's focusability ("focusable")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3552
     *    <li>this Container's focus traversal keys enabled state
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3553
     *        ("focusTraversalKeysEnabled")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3554
     *    <li>this Container's Set of FORWARD_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3555
     *        ("forwardFocusTraversalKeys")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3556
     *    <li>this Container's Set of BACKWARD_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3557
     *        ("backwardFocusTraversalKeys")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3558
     *    <li>this Container's Set of UP_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3559
     *        ("upCycleFocusTraversalKeys")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3560
     *    <li>this Container's Set of DOWN_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3561
     *        ("downCycleFocusTraversalKeys")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3562
     *    <li>this Container's focus traversal policy ("focusTraversalPolicy")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3563
     *        </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3564
     *    <li>this Container's focus-cycle-root state ("focusCycleRoot")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3565
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3566
     * Note that if this Container is inheriting a bound property, then no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3567
     * event will be fired in response to a change in the inherited property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3568
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3569
     * If listener is null, no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3570
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3571
     * @param    listener  the PropertyChangeListener to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3572
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3573
     * @see Component#removePropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3574
     * @see #addPropertyChangeListener(java.lang.String,java.beans.PropertyChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3575
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3576
    public void addPropertyChangeListener(PropertyChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3577
        super.addPropertyChangeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3578
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3579
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3580
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3581
     * Adds a PropertyChangeListener to the listener list for a specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3582
     * property. The specified property may be user-defined, or one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3583
     * following defaults:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3584
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3585
     *    <li>this Container's font ("font")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3586
     *    <li>this Container's background color ("background")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3587
     *    <li>this Container's foreground color ("foreground")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3588
     *    <li>this Container's focusability ("focusable")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3589
     *    <li>this Container's focus traversal keys enabled state
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3590
     *        ("focusTraversalKeysEnabled")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3591
     *    <li>this Container's Set of FORWARD_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3592
     *        ("forwardFocusTraversalKeys")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3593
     *    <li>this Container's Set of BACKWARD_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3594
     *        ("backwardFocusTraversalKeys")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3595
     *    <li>this Container's Set of UP_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3596
     *        ("upCycleFocusTraversalKeys")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3597
     *    <li>this Container's Set of DOWN_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3598
     *        ("downCycleFocusTraversalKeys")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3599
     *    <li>this Container's focus traversal policy ("focusTraversalPolicy")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3600
     *        </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3601
     *    <li>this Container's focus-cycle-root state ("focusCycleRoot")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3602
     *    <li>this Container's focus-traversal-policy-provider state("focusTraversalPolicyProvider")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3603
     *    <li>this Container's focus-traversal-policy-provider state("focusTraversalPolicyProvider")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3604
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3605
     * Note that if this Container is inheriting a bound property, then no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3606
     * event will be fired in response to a change in the inherited property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3607
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3608
     * If listener is null, no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3609
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3610
     * @param propertyName one of the property names listed above
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3611
     * @param listener the PropertyChangeListener to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3612
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3613
     * @see #addPropertyChangeListener(java.beans.PropertyChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3614
     * @see Component#removePropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3615
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3616
    public void addPropertyChangeListener(String propertyName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3617
                                          PropertyChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3618
        super.addPropertyChangeListener(propertyName, listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3619
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3620
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3621
    // Serialization support. A Container is responsible for restoring the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3622
    // parent fields of its component children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3623
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3624
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3625
     * Container Serial Data Version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3626
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3627
    private int containerSerializedDataVersion = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3628
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3629
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3630
     * Serializes this <code>Container</code> to the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3631
     * <code>ObjectOutputStream</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3632
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3633
     *    <li>Writes default serializable fields to the stream.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3634
     *    <li>Writes a list of serializable ContainerListener(s) as optional
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3635
     *        data. The non-serializable ContainerListner(s) are detected and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3636
     *        no attempt is made to serialize them.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3637
     *    <li>Write this Container's FocusTraversalPolicy if and only if it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3638
     *        is Serializable; otherwise, <code>null</code> is written.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3639
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3640
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3641
     * @param s the <code>ObjectOutputStream</code> to write
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3642
     * @serialData <code>null</code> terminated sequence of 0 or more pairs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3643
     *   the pair consists of a <code>String</code> and <code>Object</code>;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3644
     *   the <code>String</code> indicates the type of object and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3645
     *   is one of the following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3646
     *   <code>containerListenerK</code> indicating an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3647
     *     <code>ContainerListener</code> object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3648
     *   the <code>Container</code>'s <code>FocusTraversalPolicy</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3649
     *     or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3650
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3651
     * @see AWTEventMulticaster#save(java.io.ObjectOutputStream, java.lang.String, java.util.EventListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3652
     * @see Container#containerListenerK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3653
     * @see #readObject(ObjectInputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3654
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3655
    private void writeObject(ObjectOutputStream s) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3656
        ObjectOutputStream.PutField f = s.putFields();
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  3657
        f.put("ncomponents", component.size());
2463
c90a9d542c79 6784816: Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
art
parents: 2462
diff changeset
  3658
        f.put("component", getComponentsSync());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3659
        f.put("layoutMgr", layoutMgr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3660
        f.put("dispatcher", dispatcher);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3661
        f.put("maxSize", maxSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3662
        f.put("focusCycleRoot", focusCycleRoot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3663
        f.put("containerSerializedDataVersion", containerSerializedDataVersion);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3664
        f.put("focusTraversalPolicyProvider", focusTraversalPolicyProvider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3665
        s.writeFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3666
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3667
        AWTEventMulticaster.save(s, containerListenerK, containerListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3668
        s.writeObject(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3669
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3670
        if (focusTraversalPolicy instanceof java.io.Serializable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3671
            s.writeObject(focusTraversalPolicy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3672
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3673
            s.writeObject(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3674
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3675
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3676
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3677
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3678
     * Deserializes this <code>Container</code> from the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3679
     * <code>ObjectInputStream</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3680
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3681
     *    <li>Reads default serializable fields from the stream.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3682
     *    <li>Reads a list of serializable ContainerListener(s) as optional
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3683
     *        data. If the list is null, no Listeners are installed.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3684
     *    <li>Reads this Container's FocusTraversalPolicy, which may be null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3685
     *        as optional data.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3686
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3687
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3688
     * @param s the <code>ObjectInputStream</code> to read
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3689
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3690
     * @see #addContainerListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3691
     * @see #writeObject(ObjectOutputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3692
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3693
    private void readObject(ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3694
        throws ClassNotFoundException, IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3695
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3696
        ObjectInputStream.GetField f = s.readFields();
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  3697
        Component [] tmpComponent = (Component[])f.get("component", EMPTY_ARRAY);
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  3698
        int ncomponents = (Integer) f.get("ncomponents", 0);
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  3699
        component = new java.util.ArrayList<Component>(ncomponents);
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  3700
        for (int i = 0; i < ncomponents; ++i) {
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  3701
            component.add(tmpComponent[i]);
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  3702
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3703
        layoutMgr = (LayoutManager)f.get("layoutMgr", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3704
        dispatcher = (LightweightDispatcher)f.get("dispatcher", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3705
        // Old stream. Doesn't contain maxSize among Component's fields.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3706
        if (maxSize == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3707
            maxSize = (Dimension)f.get("maxSize", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3708
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3709
        focusCycleRoot = f.get("focusCycleRoot", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3710
        containerSerializedDataVersion = f.get("containerSerializedDataVersion", 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3711
        focusTraversalPolicyProvider = f.get("focusTraversalPolicyProvider", false);
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  3712
        java.util.List<Component> component = this.component;
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  3713
        for(Component comp : component) {
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  3714
            comp.parent = this;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3715
            adjustListeningChildren(AWTEvent.HIERARCHY_EVENT_MASK,
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  3716
                                    comp.numListening(AWTEvent.HIERARCHY_EVENT_MASK));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3717
            adjustListeningChildren(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK,
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  3718
                                    comp.numListening(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK));
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  3719
            adjustDescendants(comp.countHierarchyMembers());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3720
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3721
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3722
        Object keyOrNull;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3723
        while(null != (keyOrNull = s.readObject())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3724
            String key = ((String)keyOrNull).intern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3725
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3726
            if (containerListenerK == key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3727
                addContainerListener((ContainerListener)(s.readObject()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3728
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3729
                // skip value for unrecognized key
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3730
                s.readObject();
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
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3735
            Object policy = s.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3736
            if (policy instanceof FocusTraversalPolicy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3737
                focusTraversalPolicy = (FocusTraversalPolicy)policy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3738
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3739
        } catch (java.io.OptionalDataException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3740
            // JDK 1.1/1.2/1.3 instances will not have this optional data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3741
            // e.eof will be true to indicate that there is no more data
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3742
            // available for this object. If e.eof is not true, throw the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3743
            // exception as it might have been caused by reasons unrelated to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3744
            // focusTraversalPolicy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3745
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3746
            if (!e.eof) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3747
                throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3748
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3749
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3750
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3751
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3752
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3753
     * --- Accessibility Support ---
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3754
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3755
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3756
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3757
     * Inner class of Container used to provide default support for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3758
     * accessibility.  This class is not meant to be used directly by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3759
     * application developers, but is instead meant only to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3760
     * subclassed by container developers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3761
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3762
     * The class used to obtain the accessible role for this object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3763
     * as well as implementing many of the methods in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3764
     * AccessibleContainer interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3765
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3766
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3767
    protected class AccessibleAWTContainer extends AccessibleAWTComponent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3768
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3769
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3770
         * JDK1.3 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3771
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3772
        private static final long serialVersionUID = 5081320404842566097L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3773
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3774
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3775
         * Returns the number of accessible children in the object.  If all
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3776
         * of the children of this object implement <code>Accessible</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3777
         * then this method should return the number of children of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3778
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3779
         * @return the number of accessible children in the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3780
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3781
        public int getAccessibleChildrenCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3782
            return Container.this.getAccessibleChildrenCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3783
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3784
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3785
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3786
         * Returns the nth <code>Accessible</code> child of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3787
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3788
         * @param i zero-based index of child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3789
         * @return the nth <code>Accessible</code> child of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3790
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3791
        public Accessible getAccessibleChild(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3792
            return Container.this.getAccessibleChild(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3793
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3794
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3795
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3796
         * Returns the <code>Accessible</code> child, if one exists,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3797
         * contained at the local coordinate <code>Point</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3798
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3799
         * @param p the point defining the top-left corner of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3800
         *    <code>Accessible</code>, given in the coordinate space
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3801
         *    of the object's parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3802
         * @return the <code>Accessible</code>, if it exists,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3803
         *    at the specified location; else <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3804
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3805
        public Accessible getAccessibleAt(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3806
            return Container.this.getAccessibleAt(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3807
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3808
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3809
        protected ContainerListener accessibleContainerHandler = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3810
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3811
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3812
         * Fire <code>PropertyChange</code> listener, if one is registered,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3813
         * when children are added or removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3814
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3815
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3816
        protected class AccessibleContainerHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3817
            implements ContainerListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3818
            public void componentAdded(ContainerEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3819
                Component c = e.getChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3820
                if (c != null && c instanceof Accessible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3821
                    AccessibleAWTContainer.this.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3822
                        AccessibleContext.ACCESSIBLE_CHILD_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3823
                        null, ((Accessible) c).getAccessibleContext());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3824
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3825
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3826
            public void componentRemoved(ContainerEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3827
                Component c = e.getChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3828
                if (c != null && c instanceof Accessible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3829
                    AccessibleAWTContainer.this.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3830
                        AccessibleContext.ACCESSIBLE_CHILD_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3831
                        ((Accessible) c).getAccessibleContext(), null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3832
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3833
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3834
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3835
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3836
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3837
         * Adds a PropertyChangeListener to the listener list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3838
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3839
         * @param listener  the PropertyChangeListener to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3840
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3841
        public void addPropertyChangeListener(PropertyChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3842
            if (accessibleContainerHandler == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3843
                accessibleContainerHandler = new AccessibleContainerHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3844
                Container.this.addContainerListener(accessibleContainerHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3845
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3846
            super.addPropertyChangeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3847
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3848
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3849
    } // inner class AccessibleAWTContainer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3850
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3851
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3852
     * Returns the <code>Accessible</code> child contained at the local
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3853
     * coordinate <code>Point</code>, if one exists.  Otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3854
     * returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3855
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3856
     * @param p the point defining the top-left corner of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3857
     *    <code>Accessible</code>, given in the coordinate space
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3858
     *    of the object's parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3859
     * @return the <code>Accessible</code> at the specified location,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3860
     *    if it exists; otherwise <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3861
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3862
    Accessible getAccessibleAt(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3863
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3864
            if (this instanceof Accessible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3865
                Accessible a = (Accessible)this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3866
                AccessibleContext ac = a.getAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3867
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3868
                    AccessibleComponent acmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3869
                    Point location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3870
                    int nchildren = ac.getAccessibleChildrenCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3871
                    for (int i=0; i < nchildren; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3872
                        a = ac.getAccessibleChild(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3873
                        if ((a != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3874
                            ac = a.getAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3875
                            if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3876
                                acmp = ac.getAccessibleComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3877
                                if ((acmp != null) && (acmp.isShowing())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3878
                                    location = acmp.getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3879
                                    Point np = new Point(p.x-location.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3880
                                                         p.y-location.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3881
                                    if (acmp.contains(np)){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3882
                                        return a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3883
                                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3884
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3885
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3886
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3887
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3888
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3889
                return (Accessible)this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3890
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3891
                Component ret = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3892
                if (!this.contains(p.x,p.y)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3893
                    ret = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3894
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3895
                    int ncomponents = this.getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3896
                    for (int i=0; i < ncomponents; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3897
                        Component comp = this.getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3898
                        if ((comp != null) && comp.isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3899
                            Point location = comp.getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3900
                            if (comp.contains(p.x-location.x,p.y-location.y)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3901
                                ret = comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3902
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3903
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3904
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3905
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3906
                if (ret instanceof Accessible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3907
                    return (Accessible) ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3908
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3909
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3910
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3911
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3912
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3913
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3914
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3915
     * Returns the number of accessible children in the object.  If all
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3916
     * of the children of this object implement <code>Accessible</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3917
     * then this method should return the number of children of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3918
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3919
     * @return the number of accessible children in the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3920
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3921
    int getAccessibleChildrenCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3922
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3923
            int count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3924
            Component[] children = this.getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3925
            for (int i = 0; i < children.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3926
                if (children[i] instanceof Accessible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3927
                    count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3928
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3929
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3930
            return count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3931
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3932
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3933
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3934
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3935
     * Returns the nth <code>Accessible</code> child of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3936
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3937
     * @param i zero-based index of child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3938
     * @return the nth <code>Accessible</code> child of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3939
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3940
    Accessible getAccessibleChild(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3941
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3942
            Component[] children = this.getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3943
            int count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3944
            for (int j = 0; j < children.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3945
                if (children[j] instanceof Accessible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3946
                    if (count == i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3947
                        return (Accessible) children[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3948
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3949
                        count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3950
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3951
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3952
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3953
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3954
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3955
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3956
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3957
    // ************************** MIXING CODE *******************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3958
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3959
    final void increaseComponentCount(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3960
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3961
            if (!c.isDisplayable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3962
                throw new IllegalStateException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3963
                    "Peer does not exist while invoking the increaseComponentCount() method"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3964
                );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3965
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3966
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3967
            int addHW = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3968
            int addLW = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3969
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3970
            if (c instanceof Container) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3971
                addLW = ((Container)c).numOfLWComponents;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3972
                addHW = ((Container)c).numOfHWComponents;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3973
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3974
            if (c.isLightweight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3975
                addLW++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3976
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3977
                addHW++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3978
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3979
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3980
            for (Container cont = this; cont != null; cont = cont.getContainer()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3981
                cont.numOfLWComponents += addLW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3982
                cont.numOfHWComponents += addHW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3983
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3984
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3985
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3986
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3987
    final void decreaseComponentCount(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3988
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3989
            if (!c.isDisplayable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3990
                throw new IllegalStateException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3991
                    "Peer does not exist while invoking the decreaseComponentCount() method"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3992
                );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3993
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3994
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3995
            int subHW = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3996
            int subLW = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3997
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3998
            if (c instanceof Container) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3999
                subLW = ((Container)c).numOfLWComponents;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4000
                subHW = ((Container)c).numOfHWComponents;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4001
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4002
            if (c.isLightweight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4003
                subLW++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4004
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4005
                subHW++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4006
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4007
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4008
            for (Container cont = this; cont != null; cont = cont.getContainer()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4009
                cont.numOfLWComponents -= subLW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4010
                cont.numOfHWComponents -= subHW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4011
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4012
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4013
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4014
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4015
    private int getTopmostComponentIndex() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4016
        checkTreeLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4017
        if (getComponentCount() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4018
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4019
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4020
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4021
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4022
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4023
    private int getBottommostComponentIndex() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4024
        checkTreeLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4025
        if (getComponentCount() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4026
            return getComponentCount() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4027
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4028
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4029
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4030
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4031
    /*
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4032
     * This method is overriden to handle opaque children in non-opaque
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4033
     * containers.
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4034
     */
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4035
    @Override
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4036
    final Region getOpaqueShape() {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4037
        checkTreeLock();
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4038
        if (isLightweight() && isNonOpaqueForMixing()
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4039
                && hasLightweightDescendants())
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4040
        {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4041
            Region s = Region.EMPTY_REGION;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4042
            for (int index = 0; index < getComponentCount(); index++) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4043
                Component c = getComponent(index);
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4044
                if (c.isLightweight() && c.isShowing()) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4045
                    s = s.getUnion(c.getOpaqueShape());
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4046
                }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4047
            }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4048
            return s.getIntersection(getNormalShape());
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4049
        }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4050
        return super.getOpaqueShape();
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4051
    }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4052
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4053
    final void recursiveSubtractAndApplyShape(Region shape) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4054
        recursiveSubtractAndApplyShape(shape, getTopmostComponentIndex(), getBottommostComponentIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4055
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4056
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4057
    final void recursiveSubtractAndApplyShape(Region shape, int fromZorder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4058
        recursiveSubtractAndApplyShape(shape, fromZorder, getBottommostComponentIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4059
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4060
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4061
    final void recursiveSubtractAndApplyShape(Region shape, int fromZorder, int toZorder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4062
        checkTreeLock();
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
  4063
        if (mixingLog.isLoggable(PlatformLogger.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4064
            mixingLog.fine("this = " + this +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4065
                "; shape=" + shape + "; fromZ=" + fromZorder + "; toZ=" + toZorder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4066
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4067
        if (fromZorder == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4068
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4069
        }
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4070
        if (shape.isEmpty()) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4071
            return;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4072
        }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4073
        // An invalid container with not-null layout should be ignored
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4074
        // by the mixing code, the container will be validated later
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4075
        // and the mixing code will be executed later.
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4076
        if (getLayout() != null && !isValid()) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4077
            return;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4078
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4079
        for (int index = fromZorder; index <= toZorder; index++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4080
            Component comp = getComponent(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4081
            if (!comp.isLightweight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4082
                comp.subtractAndApplyShape(shape);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4083
            } else if (comp instanceof Container &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4084
                    ((Container)comp).hasHeavyweightDescendants() && comp.isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4085
                ((Container)comp).recursiveSubtractAndApplyShape(shape);
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4090
    final void recursiveApplyCurrentShape() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4091
        recursiveApplyCurrentShape(getTopmostComponentIndex(), getBottommostComponentIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4092
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4093
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4094
    final void recursiveApplyCurrentShape(int fromZorder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4095
        recursiveApplyCurrentShape(fromZorder, getBottommostComponentIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4096
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4097
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4098
    final void recursiveApplyCurrentShape(int fromZorder, int toZorder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4099
        checkTreeLock();
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
  4100
        if (mixingLog.isLoggable(PlatformLogger.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4101
            mixingLog.fine("this = " + this +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4102
                "; fromZ=" + fromZorder + "; toZ=" + toZorder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4103
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4104
        if (fromZorder == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4105
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4106
        }
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4107
        // An invalid container with not-null layout should be ignored
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4108
        // by the mixing code, the container will be validated later
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4109
        // and the mixing code will be executed later.
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4110
        if (getLayout() != null && !isValid()) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4111
            return;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4112
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4113
        for (int index = fromZorder; index <= toZorder; index++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4114
            Component comp = getComponent(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4115
            if (!comp.isLightweight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4116
                comp.applyCurrentShape();
2644
63360b4ca6c4 6829858: JInternalFrame is not redrawing heavyweight children properly
anthony
parents: 2463
diff changeset
  4117
            }
63360b4ca6c4 6829858: JInternalFrame is not redrawing heavyweight children properly
anthony
parents: 2463
diff changeset
  4118
            if (comp instanceof Container &&
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4119
                    ((Container)comp).hasHeavyweightDescendants()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4120
                ((Container)comp).recursiveApplyCurrentShape();
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
130
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4125
    private void recursiveShowHeavyweightChildren() {
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4126
        if (!hasHeavyweightDescendants() || !isVisible()) {
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4127
            return;
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4128
        }
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4129
        for (int index = 0; index < getComponentCount(); index++) {
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4130
            Component comp = getComponent(index);
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4131
            if (comp.isLightweight()) {
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4132
                if  (comp instanceof Container) {
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4133
                    ((Container)comp).recursiveShowHeavyweightChildren();
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4134
                }
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4135
            } else {
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4136
                if (comp.isVisible()) {
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4137
                    ComponentPeer peer = comp.getPeer();
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4138
                    if (peer != null) {
1964
934568dfe859 6749920: Cleanup AWT peer interfaces
rkennke
parents: 1188
diff changeset
  4139
                        peer.setVisible(true);
130
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4140
                    }
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4141
                }
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4142
            }
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4143
        }
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4144
    }
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4145
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4146
    private void recursiveHideHeavyweightChildren() {
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4147
        if (!hasHeavyweightDescendants()) {
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4148
            return;
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4149
        }
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4150
        for (int index = 0; index < getComponentCount(); index++) {
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4151
            Component comp = getComponent(index);
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4152
            if (comp.isLightweight()) {
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4153
                if  (comp instanceof Container) {
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4154
                    ((Container)comp).recursiveHideHeavyweightChildren();
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4155
                }
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4156
            } else {
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4157
                if (comp.isVisible()) {
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4158
                    ComponentPeer peer = comp.getPeer();
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4159
                    if (peer != null) {
1964
934568dfe859 6749920: Cleanup AWT peer interfaces
rkennke
parents: 1188
diff changeset
  4160
                        peer.setVisible(false);
130
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4161
                    }
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4162
                }
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4163
            }
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4164
        }
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4165
    }
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4166
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4167
    private void recursiveRelocateHeavyweightChildren(Point origin) {
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4168
        for (int index = 0; index < getComponentCount(); index++) {
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4169
            Component comp = getComponent(index);
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4170
            if (comp.isLightweight()) {
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4171
                if  (comp instanceof Container &&
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4172
                        ((Container)comp).hasHeavyweightDescendants())
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4173
                {
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4174
                    final Point newOrigin = new Point(origin);
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4175
                    newOrigin.translate(comp.getX(), comp.getY());
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4176
                    ((Container)comp).recursiveRelocateHeavyweightChildren(newOrigin);
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4177
                }
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4178
            } else {
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4179
                ComponentPeer peer = comp.getPeer();
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4180
                if (peer != null) {
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4181
                    peer.setBounds(origin.x + comp.getX(), origin.y + comp.getY(),
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4182
                            comp.getWidth(), comp.getHeight(),
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4183
                            ComponentPeer.SET_LOCATION);
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4184
                }
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4185
            }
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4186
        }
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4187
    }
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4188
4257
c447aed67cec 6885735: closed/java/awt/Component/DisablingLWDisabledHW/DisablingLWDisabledHW.html fails
anthony
parents: 3971
diff changeset
  4189
    /**
c447aed67cec 6885735: closed/java/awt/Component/DisablingLWDisabledHW/DisablingLWDisabledHW.html fails
anthony
parents: 3971
diff changeset
  4190
     * Checks if the container and its direct lightweight containers are
c447aed67cec 6885735: closed/java/awt/Component/DisablingLWDisabledHW/DisablingLWDisabledHW.html fails
anthony
parents: 3971
diff changeset
  4191
     * visible.
c447aed67cec 6885735: closed/java/awt/Component/DisablingLWDisabledHW/DisablingLWDisabledHW.html fails
anthony
parents: 3971
diff changeset
  4192
     *
130
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4193
     * Consider the heavyweight container hides or shows the HW descendants
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4194
     * automatically. Therefore we care of LW containers' visibility only.
4257
c447aed67cec 6885735: closed/java/awt/Component/DisablingLWDisabledHW/DisablingLWDisabledHW.html fails
anthony
parents: 3971
diff changeset
  4195
     *
c447aed67cec 6885735: closed/java/awt/Component/DisablingLWDisabledHW/DisablingLWDisabledHW.html fails
anthony
parents: 3971
diff changeset
  4196
     * This method MUST be invoked under the TreeLock.
130
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4197
     */
4257
c447aed67cec 6885735: closed/java/awt/Component/DisablingLWDisabledHW/DisablingLWDisabledHW.html fails
anthony
parents: 3971
diff changeset
  4198
    final boolean isRecursivelyVisibleUpToHeavyweightContainer() {
130
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4199
        if (!isLightweight()) {
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4200
            return true;
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4201
        }
4257
c447aed67cec 6885735: closed/java/awt/Component/DisablingLWDisabledHW/DisablingLWDisabledHW.html fails
anthony
parents: 3971
diff changeset
  4202
6827
ee4403d28487 6979568: Test failure: test\closed\java\awt\Component\VisibleHwInLwContTest\VisibleHwInLwContTest.html
anthony
parents: 5506
diff changeset
  4203
        for (Container cont = this;
4257
c447aed67cec 6885735: closed/java/awt/Component/DisablingLWDisabledHW/DisablingLWDisabledHW.html fails
anthony
parents: 3971
diff changeset
  4204
                cont != null && cont.isLightweight();
c447aed67cec 6885735: closed/java/awt/Component/DisablingLWDisabledHW/DisablingLWDisabledHW.html fails
anthony
parents: 3971
diff changeset
  4205
                cont = cont.getContainer())
c447aed67cec 6885735: closed/java/awt/Component/DisablingLWDisabledHW/DisablingLWDisabledHW.html fails
anthony
parents: 3971
diff changeset
  4206
        {
c447aed67cec 6885735: closed/java/awt/Component/DisablingLWDisabledHW/DisablingLWDisabledHW.html fails
anthony
parents: 3971
diff changeset
  4207
            if (!cont.isVisible()) {
c447aed67cec 6885735: closed/java/awt/Component/DisablingLWDisabledHW/DisablingLWDisabledHW.html fails
anthony
parents: 3971
diff changeset
  4208
                return false;
c447aed67cec 6885735: closed/java/awt/Component/DisablingLWDisabledHW/DisablingLWDisabledHW.html fails
anthony
parents: 3971
diff changeset
  4209
            }
c447aed67cec 6885735: closed/java/awt/Component/DisablingLWDisabledHW/DisablingLWDisabledHW.html fails
anthony
parents: 3971
diff changeset
  4210
        }
c447aed67cec 6885735: closed/java/awt/Component/DisablingLWDisabledHW/DisablingLWDisabledHW.html fails
anthony
parents: 3971
diff changeset
  4211
        return true;
130
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4212
    }
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4213
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4214
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4215
    void mixOnShowing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4216
        synchronized (getTreeLock()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
  4217
            if (mixingLog.isLoggable(PlatformLogger.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4218
                mixingLog.fine("this = " + this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4219
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4220
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4221
            boolean isLightweight = isLightweight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4222
130
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4223
            if (isLightweight && isRecursivelyVisibleUpToHeavyweightContainer()) {
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4224
                recursiveShowHeavyweightChildren();
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4225
            }
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4226
3971
067e6580a577 6862611: Reg testcase closed/java/awt/Component/NativeInLightShow/NativeInLightShow.html fails
anthony
parents: 3966
diff changeset
  4227
            if (!isMixingNeeded()) {
067e6580a577 6862611: Reg testcase closed/java/awt/Component/NativeInLightShow/NativeInLightShow.html fails
anthony
parents: 3966
diff changeset
  4228
                return;
067e6580a577 6862611: Reg testcase closed/java/awt/Component/NativeInLightShow/NativeInLightShow.html fails
anthony
parents: 3966
diff changeset
  4229
            }
067e6580a577 6862611: Reg testcase closed/java/awt/Component/NativeInLightShow/NativeInLightShow.html fails
anthony
parents: 3966
diff changeset
  4230
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4231
            if (!isLightweight || (isLightweight && hasHeavyweightDescendants())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4232
                recursiveApplyCurrentShape();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4233
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4234
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4235
            super.mixOnShowing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4236
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4238
130
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4239
    @Override
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4240
    void mixOnHiding(boolean isLightweight) {
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4241
        synchronized (getTreeLock()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
  4242
            if (mixingLog.isLoggable(PlatformLogger.FINE)) {
130
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4243
                mixingLog.fine("this = " + this +
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4244
                        "; isLightweight=" + isLightweight);
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4245
            }
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4246
            if (isLightweight) {
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4247
                recursiveHideHeavyweightChildren();
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4248
            }
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4249
            super.mixOnHiding(isLightweight);
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4250
        }
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4251
    }
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4252
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4253
    @Override
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4254
    void mixOnReshaping() {
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4255
        synchronized (getTreeLock()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
  4256
            if (mixingLog.isLoggable(PlatformLogger.FINE)) {
130
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4257
                mixingLog.fine("this = " + this);
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4258
            }
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4259
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4260
            boolean isMixingNeeded = isMixingNeeded();
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4261
130
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4262
            if (isLightweight() && hasHeavyweightDescendants()) {
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4263
                final Point origin = new Point(getX(), getY());
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4264
                for (Container cont = getContainer();
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4265
                        cont != null && cont.isLightweight();
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4266
                        cont = cont.getContainer())
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4267
                {
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4268
                    origin.translate(cont.getX(), cont.getY());
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4269
                }
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4270
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4271
                recursiveRelocateHeavyweightChildren(origin);
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4272
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4273
                if (!isMixingNeeded) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4274
                    return;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4275
                }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4276
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4277
                recursiveApplyCurrentShape();
130
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4278
            }
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4279
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4280
            if (!isMixingNeeded) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4281
                return;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4282
            }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4283
130
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4284
            super.mixOnReshaping();
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4285
        }
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4286
    }
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4287
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 125
diff changeset
  4288
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4289
    void mixOnZOrderChanging(int oldZorder, int newZorder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4290
        synchronized (getTreeLock()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
  4291
            if (mixingLog.isLoggable(PlatformLogger.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4292
                mixingLog.fine("this = " + this +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4293
                    "; oldZ=" + oldZorder + "; newZ=" + newZorder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4294
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4295
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4296
            if (!isMixingNeeded()) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4297
                return;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4298
            }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4299
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4300
            boolean becameHigher = newZorder < oldZorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4301
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4302
            if (becameHigher && isLightweight() && hasHeavyweightDescendants()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4303
                recursiveApplyCurrentShape();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4304
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4305
            super.mixOnZOrderChanging(oldZorder, newZorder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4306
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4307
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4308
1183
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1172
diff changeset
  4309
    @Override
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1172
diff changeset
  4310
    void mixOnValidating() {
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1172
diff changeset
  4311
        synchronized (getTreeLock()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
  4312
            if (mixingLog.isLoggable(PlatformLogger.FINE)) {
1183
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1172
diff changeset
  4313
                mixingLog.fine("this = " + this);
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1172
diff changeset
  4314
            }
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1172
diff changeset
  4315
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4316
            if (!isMixingNeeded()) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4317
                return;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4318
            }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4319
1183
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1172
diff changeset
  4320
            if (hasHeavyweightDescendants()) {
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1172
diff changeset
  4321
                recursiveApplyCurrentShape();
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1172
diff changeset
  4322
            }
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1172
diff changeset
  4323
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4324
            if (isLightweight() && isNonOpaqueForMixing()) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4325
                subtractAndApplyShapeBelowMe();
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4326
            }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  4327
1183
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1172
diff changeset
  4328
            super.mixOnValidating();
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1172
diff changeset
  4329
        }
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1172
diff changeset
  4330
    }
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1172
diff changeset
  4331
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4332
    // ****************** END OF MIXING CODE ********************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4333
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4334
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4335
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4336
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4337
 * Class to manage the dispatching of MouseEvents to the lightweight descendants
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4338
 * and SunDropTargetEvents to both lightweight and heavyweight descendants
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4339
 * contained by a native container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4340
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4341
 * NOTE: the class name is not appropriate anymore, but we cannot change it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4342
 * because we must keep serialization compatibility.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4343
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4344
 * @author Timothy Prinzing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4345
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4346
class LightweightDispatcher implements java.io.Serializable, AWTEventListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4347
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4348
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4349
     * JDK 1.1 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4350
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4351
    private static final long serialVersionUID = 5184291520170872969L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4352
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4353
     * Our own mouse event for when we're dragged over from another hw
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4354
     * container
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4355
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4356
    private static final int  LWD_MOUSE_DRAGGED_OVER = 1500;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4357
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
  4358
    private static final PlatformLogger eventLog = PlatformLogger.getLogger("java.awt.event.LightweightDispatcher");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4359
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4360
    LightweightDispatcher(Container nativeContainer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4361
        this.nativeContainer = nativeContainer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4362
        mouseEventTarget = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4363
        eventMask = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4364
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4365
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4366
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4367
     * Clean up any resources allocated when dispatcher was created;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4368
     * should be called from Container.removeNotify
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4369
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4370
    void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4371
        //System.out.println("Disposing lw dispatcher");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4372
        stopListeningForOtherDrags();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4373
        mouseEventTarget = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4374
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4375
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4376
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4377
     * Enables events to subcomponents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4378
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4379
    void enableEvents(long events) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4380
        eventMask |= events;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4381
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4382
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4383
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4384
     * Dispatches an event to a sub-component if necessary, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4385
     * returns whether or not the event was forwarded to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4386
     * sub-component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4387
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4388
     * @param e the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4389
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4390
    boolean dispatchEvent(AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4391
        boolean ret = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4392
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4393
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4394
         * Fix for BugTraq Id 4389284.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4395
         * Dispatch SunDropTargetEvents regardless of eventMask value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4396
         * Do not update cursor on dispatching SunDropTargetEvents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4397
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4398
        if (e instanceof SunDropTargetEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4399
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4400
            SunDropTargetEvent sdde = (SunDropTargetEvent) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4401
            ret = processDropTargetEvent(sdde);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4402
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4403
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4404
            if (e instanceof MouseEvent && (eventMask & MOUSE_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4405
                MouseEvent me = (MouseEvent) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4406
                ret = processMouseEvent(me);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4407
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4408
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4409
            if (e.getID() == MouseEvent.MOUSE_MOVED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4410
                nativeContainer.updateCursorImmediately();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4411
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4412
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4413
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4414
        return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4415
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4416
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4417
    /* This method effectively returns whether or not a mouse button was down
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4418
     * just BEFORE the event happened.  A better method name might be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4419
     * wasAMouseButtonDownBeforeThisEvent().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4420
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4421
    private boolean isMouseGrab(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4422
        int modifiers = e.getModifiersEx();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4423
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4424
        if(e.getID() == MouseEvent.MOUSE_PRESSED
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4425
            || e.getID() == MouseEvent.MOUSE_RELEASED)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4426
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4427
            switch (e.getButton()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4428
            case MouseEvent.BUTTON1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4429
                modifiers ^= InputEvent.BUTTON1_DOWN_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4430
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4431
            case MouseEvent.BUTTON2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4432
                modifiers ^= InputEvent.BUTTON2_DOWN_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4433
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4434
            case MouseEvent.BUTTON3:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4435
                modifiers ^= InputEvent.BUTTON3_DOWN_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4436
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4437
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4438
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4439
        /* modifiers now as just before event */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4440
        return ((modifiers & (InputEvent.BUTTON1_DOWN_MASK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4441
                              | InputEvent.BUTTON2_DOWN_MASK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4442
                              | InputEvent.BUTTON3_DOWN_MASK)) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4443
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4444
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4445
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4446
     * This method attempts to distribute a mouse event to a lightweight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4447
     * component.  It tries to avoid doing any unnecessary probes down
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4448
     * into the component tree to minimize the overhead of determining
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4449
     * where to route the event, since mouse movement events tend to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4450
     * come in large and frequent amounts.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4451
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4452
    private boolean processMouseEvent(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4453
        int id = e.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4454
        Component mouseOver =   // sensitive to mouse events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4455
            nativeContainer.getMouseEventTarget(e.getX(), e.getY(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4456
                                                Container.INCLUDE_SELF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4457
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4458
        trackMouseEnterExit(mouseOver, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4459
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4460
    // 4508327 : MOUSE_CLICKED should only go to the recipient of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4461
    // the accompanying MOUSE_PRESSED, so don't reset mouseEventTarget on a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4462
    // MOUSE_CLICKED.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4463
    if (!isMouseGrab(e) && id != MouseEvent.MOUSE_CLICKED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4464
            mouseEventTarget = (mouseOver != nativeContainer) ? mouseOver: null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4465
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4466
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4467
        if (mouseEventTarget != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4468
            switch (id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4469
            case MouseEvent.MOUSE_ENTERED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4470
            case MouseEvent.MOUSE_EXITED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4471
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4472
            case MouseEvent.MOUSE_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4473
                retargetMouseEvent(mouseEventTarget, id, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4474
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4475
        case MouseEvent.MOUSE_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4476
            retargetMouseEvent(mouseEventTarget, id, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4477
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4478
        case MouseEvent.MOUSE_CLICKED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4479
        // 4508327: MOUSE_CLICKED should never be dispatched to a Component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4480
        // other than that which received the MOUSE_PRESSED event.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4481
        // mouse is now over a different Component, don't dispatch the event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4482
        // The previous fix for a similar problem was associated with bug
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4483
        // 4155217.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4484
        if (mouseOver == mouseEventTarget) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4485
            retargetMouseEvent(mouseOver, id, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4486
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4487
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4488
            case MouseEvent.MOUSE_MOVED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4489
                retargetMouseEvent(mouseEventTarget, id, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4490
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4491
        case MouseEvent.MOUSE_DRAGGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4492
            if (isMouseGrab(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4493
                retargetMouseEvent(mouseEventTarget, id, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4494
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4495
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4496
        case MouseEvent.MOUSE_WHEEL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4497
            // This may send it somewhere that doesn't have MouseWheelEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4498
            // enabled.  In this case, Component.dispatchEventImpl() will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4499
            // retarget the event to a parent that DOES have the events enabled.
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
  4500
            if (eventLog.isLoggable(PlatformLogger.FINEST) && (mouseOver != null)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
  4501
                eventLog.finest("retargeting mouse wheel to " +
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
  4502
                                mouseOver.getName() + ", " +
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
  4503
                                mouseOver.getClass());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4504
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4505
            retargetMouseEvent(mouseOver, id, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4506
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4507
            }
5277
03170721df2e 6920842: Wheel events do not bubbling to the browser if they was not treated in applet.
uta
parents: 4263
diff changeset
  4508
            //Consuming of wheel events is implemented in "retargetMouseEvent".
03170721df2e 6920842: Wheel events do not bubbling to the browser if they was not treated in applet.
uta
parents: 4263
diff changeset
  4509
            if (id != MouseEvent.MOUSE_WHEEL) {
03170721df2e 6920842: Wheel events do not bubbling to the browser if they was not treated in applet.
uta
parents: 4263
diff changeset
  4510
                e.consume();
03170721df2e 6920842: Wheel events do not bubbling to the browser if they was not treated in applet.
uta
parents: 4263
diff changeset
  4511
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4512
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4513
    return e.isConsumed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4514
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4515
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4516
    private boolean processDropTargetEvent(SunDropTargetEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4517
        int id = e.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4518
        int x = e.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4519
        int y = e.getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4520
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4521
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4522
         * Fix for BugTraq ID 4395290.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4523
         * It is possible that SunDropTargetEvent's Point is outside of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4524
         * native container bounds. In this case we truncate coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4525
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4526
        if (!nativeContainer.contains(x, y)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4527
            final Dimension d = nativeContainer.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4528
            if (d.width <= x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4529
                x = d.width - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4530
            } else if (x < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4531
                x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4532
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4533
            if (d.height <= y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4534
                y = d.height - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4535
            } else if (y < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4536
                y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4537
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4538
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4539
        Component mouseOver =   // not necessarily sensitive to mouse events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4540
            nativeContainer.getDropTargetEventTarget(x, y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4541
                                                     Container.INCLUDE_SELF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4542
        trackMouseEnterExit(mouseOver, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4543
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4544
        if (mouseOver != nativeContainer && mouseOver != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4545
            switch (id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4546
            case SunDropTargetEvent.MOUSE_ENTERED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4547
            case SunDropTargetEvent.MOUSE_EXITED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4548
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4549
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4550
                retargetMouseEvent(mouseOver, id, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4551
                e.consume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4552
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4553
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4554
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4555
        return e.isConsumed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4556
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4557
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4558
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4559
     * Generates enter/exit events as mouse moves over lw components
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4560
     * @param targetOver        Target mouse is over (including native container)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4561
     * @param e                 Mouse event in native container
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4562
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4563
    private void trackMouseEnterExit(Component targetOver, MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4564
        Component       targetEnter = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4565
        int             id = e.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4566
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4567
        if (e instanceof SunDropTargetEvent &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4568
            id == MouseEvent.MOUSE_ENTERED &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4569
            isMouseInNativeContainer == true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4570
            // This can happen if a lightweight component which initiated the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4571
            // drag has an associated drop target. MOUSE_ENTERED comes when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4572
            // mouse is in the native container already. To propagate this event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4573
            // properly we should null out targetLastEntered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4574
            targetLastEntered = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4575
        } else if ( id != MouseEvent.MOUSE_EXITED &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4576
             id != MouseEvent.MOUSE_DRAGGED &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4577
             id != LWD_MOUSE_DRAGGED_OVER &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4578
             isMouseInNativeContainer == false ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4579
            // any event but an exit or drag means we're in the native container
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4580
            isMouseInNativeContainer = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4581
            startListeningForOtherDrags();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4582
        } else if ( id == MouseEvent.MOUSE_EXITED ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4583
            isMouseInNativeContainer = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4584
            stopListeningForOtherDrags();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4585
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4586
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4587
        if (isMouseInNativeContainer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4588
            targetEnter = targetOver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4589
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4590
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4591
        if (targetLastEntered == targetEnter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4592
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4593
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4594
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4595
        if (targetLastEntered != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4596
            retargetMouseEvent(targetLastEntered, MouseEvent.MOUSE_EXITED, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4597
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4598
        if (id == MouseEvent.MOUSE_EXITED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4599
            // consume native exit event if we generate one
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4600
            e.consume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4601
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4602
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4603
        if (targetEnter != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4604
            retargetMouseEvent(targetEnter, MouseEvent.MOUSE_ENTERED, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4605
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4606
        if (id == MouseEvent.MOUSE_ENTERED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4607
            // consume native enter event if we generate one
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4608
            e.consume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4609
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4610
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4611
        targetLastEntered = targetEnter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4612
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4613
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4614
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4615
     * Listens to global mouse drag events so even drags originating
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4616
     * from other heavyweight containers will generate enter/exit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4617
     * events in this container
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4618
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4619
    private void startListeningForOtherDrags() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4620
        //System.out.println("Adding AWTEventListener");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4621
        java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4622
            new java.security.PrivilegedAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4623
                public Object run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4624
                    nativeContainer.getToolkit().addAWTEventListener(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4625
                        LightweightDispatcher.this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4626
                        AWTEvent.MOUSE_EVENT_MASK |
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4627
                        AWTEvent.MOUSE_MOTION_EVENT_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4628
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4629
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4630
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4631
        );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4632
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4633
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4634
    private void stopListeningForOtherDrags() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4635
        //System.out.println("Removing AWTEventListener");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4636
        java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4637
            new java.security.PrivilegedAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4638
                public Object run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4639
                    nativeContainer.getToolkit().removeAWTEventListener(LightweightDispatcher.this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4640
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4641
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4642
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4643
        );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4644
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4645
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4646
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4647
     * (Implementation of AWTEventListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4648
     * Listen for drag events posted in other hw components so we can
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4649
     * track enter/exit regardless of where a drag originated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4650
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4651
    public void eventDispatched(AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4652
        boolean isForeignDrag = (e instanceof MouseEvent) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4653
                                !(e instanceof SunDropTargetEvent) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4654
                                (e.id == MouseEvent.MOUSE_DRAGGED) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4655
                                (e.getSource() != nativeContainer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4656
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4657
        if (!isForeignDrag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4658
            // only interested in drags from other hw components
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4659
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4660
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4661
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4662
        MouseEvent      srcEvent = (MouseEvent)e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4663
        MouseEvent      me;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4664
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4665
        synchronized (nativeContainer.getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4666
            Component srcComponent = srcEvent.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4667
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4668
            // component may have disappeared since drag event posted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4669
            // (i.e. Swing hierarchical menus)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4670
            if ( !srcComponent.isShowing() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4671
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4672
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4673
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4674
            // see 5083555
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4675
            // check if srcComponent is in any modal blocked window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4676
            Component c = nativeContainer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4677
            while ((c != null) && !(c instanceof Window)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4678
                c = c.getParent_NoClientCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4679
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4680
            if ((c == null) || ((Window)c).isModalBlocked()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4681
                return;
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
            // create an internal 'dragged-over' event indicating
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4686
            // we are being dragged over from another hw component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4687
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4688
            me = new MouseEvent(nativeContainer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4689
                               LWD_MOUSE_DRAGGED_OVER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4690
                               srcEvent.getWhen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4691
                               srcEvent.getModifiersEx() | srcEvent.getModifiers(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4692
                               srcEvent.getX(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4693
                               srcEvent.getY(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4694
                               srcEvent.getXOnScreen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4695
                               srcEvent.getYOnScreen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4696
                               srcEvent.getClickCount(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4697
                               srcEvent.isPopupTrigger(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4698
                               srcEvent.getButton());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4699
            ((AWTEvent)srcEvent).copyPrivateDataInto(me);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4700
            // translate coordinates to this native container
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4701
            final Point ptSrcOrigin = srcComponent.getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4702
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4703
            if (AppContext.getAppContext() != nativeContainer.appContext) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4704
                final MouseEvent mouseEvent = me;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4705
                Runnable r = new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4706
                        public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4707
                            if (!nativeContainer.isShowing() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4708
                                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4709
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4710
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4711
                            Point       ptDstOrigin = nativeContainer.getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4712
                            mouseEvent.translatePoint(ptSrcOrigin.x - ptDstOrigin.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4713
                                              ptSrcOrigin.y - ptDstOrigin.y );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4714
                            Component targetOver =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4715
                                nativeContainer.getMouseEventTarget(mouseEvent.getX(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4716
                                                                    mouseEvent.getY(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4717
                                                                    Container.INCLUDE_SELF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4718
                            trackMouseEnterExit(targetOver, mouseEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4719
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4720
                    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4721
                SunToolkit.executeOnEventHandlerThread(nativeContainer, r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4722
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4723
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4724
                if (!nativeContainer.isShowing() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4725
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4726
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4727
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4728
                Point   ptDstOrigin = nativeContainer.getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4729
                me.translatePoint( ptSrcOrigin.x - ptDstOrigin.x, ptSrcOrigin.y - ptDstOrigin.y );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4730
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4731
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4732
        //System.out.println("Track event: " + me);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4733
        // feed the 'dragged-over' event directly to the enter/exit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4734
        // code (not a real event so don't pass it to dispatchEvent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4735
        Component targetOver =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4736
            nativeContainer.getMouseEventTarget(me.getX(), me.getY(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4737
                                                Container.INCLUDE_SELF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4738
        trackMouseEnterExit(targetOver, me);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4739
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4740
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4741
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4742
     * Sends a mouse event to the current mouse event recipient using
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4743
     * the given event (sent to the windowed host) as a srcEvent.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4744
     * the mouse event target is still in the component tree, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4745
     * coordinates of the event are translated to those of the target.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4746
     * If the target has been removed, we don't bother to send the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4747
     * message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4748
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4749
    void retargetMouseEvent(Component target, int id, MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4750
        if (target == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4751
            return; // mouse is over another hw component or target is disabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4752
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4753
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4754
        int x = e.getX(), y = e.getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4755
        Component component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4756
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4757
        for(component = target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4758
            component != null && component != nativeContainer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4759
            component = component.getParent()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4760
            x -= component.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4761
            y -= component.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4762
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4763
        MouseEvent retargeted;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4764
        if (component != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4765
            if (e instanceof SunDropTargetEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4766
                retargeted = new SunDropTargetEvent(target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4767
                                                    id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4768
                                                    x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4769
                                                    y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4770
                                                    ((SunDropTargetEvent)e).getDispatcher());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4771
            } else if (id == MouseEvent.MOUSE_WHEEL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4772
                retargeted = new MouseWheelEvent(target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4773
                                      id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4774
                                       e.getWhen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4775
                                       e.getModifiersEx() | e.getModifiers(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4776
                                       x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4777
                                       y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4778
                                       e.getXOnScreen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4779
                                       e.getYOnScreen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4780
                                       e.getClickCount(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4781
                                       e.isPopupTrigger(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4782
                                       ((MouseWheelEvent)e).getScrollType(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4783
                                       ((MouseWheelEvent)e).getScrollAmount(),
121
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
  4784
                                       ((MouseWheelEvent)e).getWheelRotation(),
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
  4785
                                       ((MouseWheelEvent)e).getPreciseWheelRotation());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4786
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4787
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4788
                retargeted = new MouseEvent(target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4789
                                            id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4790
                                            e.getWhen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4791
                                            e.getModifiersEx() | e.getModifiers(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4792
                                            x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4793
                                            y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4794
                                            e.getXOnScreen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4795
                                            e.getYOnScreen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4796
                                            e.getClickCount(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4797
                                            e.isPopupTrigger(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4798
                                            e.getButton());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4799
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4800
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4801
            ((AWTEvent)e).copyPrivateDataInto(retargeted);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4802
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4803
            if (target == nativeContainer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4804
                // avoid recursively calling LightweightDispatcher...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4805
                ((Container)target).dispatchEventToSelf(retargeted);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4806
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4807
                assert AppContext.getAppContext() == target.appContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4808
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4809
                if (nativeContainer.modalComp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4810
                    if (((Container)nativeContainer.modalComp).isAncestorOf(target)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4811
                        target.dispatchEvent(retargeted);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4812
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4813
                        e.consume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4814
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4815
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4816
                    target.dispatchEvent(retargeted);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4817
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4818
            }
5277
03170721df2e 6920842: Wheel events do not bubbling to the browser if they was not treated in applet.
uta
parents: 4263
diff changeset
  4819
            if (id == MouseEvent.MOUSE_WHEEL && retargeted.isConsumed()) {
03170721df2e 6920842: Wheel events do not bubbling to the browser if they was not treated in applet.
uta
parents: 4263
diff changeset
  4820
                //An exception for wheel bubbling to the native system.
03170721df2e 6920842: Wheel events do not bubbling to the browser if they was not treated in applet.
uta
parents: 4263
diff changeset
  4821
                //In "processMouseEvent" total event consuming for wheel events is skipped.
03170721df2e 6920842: Wheel events do not bubbling to the browser if they was not treated in applet.
uta
parents: 4263
diff changeset
  4822
                //Protection from bubbling of Java-accepted wheel events.
03170721df2e 6920842: Wheel events do not bubbling to the browser if they was not treated in applet.
uta
parents: 4263
diff changeset
  4823
                e.consume();
03170721df2e 6920842: Wheel events do not bubbling to the browser if they was not treated in applet.
uta
parents: 4263
diff changeset
  4824
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4825
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4826
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4827
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4828
    // --- member variables -------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4829
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4830
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4831
     * The windowed container that might be hosting events for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4832
     * subcomponents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4833
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4834
    private Container nativeContainer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4835
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4836
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4837
     * This variable is not used, but kept for serialization compatibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4838
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4839
    private Component focus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4840
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4841
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4842
     * The current subcomponent being hosted by this windowed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4843
     * component that has events being forwarded to it.  If this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4844
     * is null, there are currently no events being forwarded to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4845
     * a subcomponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4846
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4847
    private transient Component mouseEventTarget;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4848
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4849
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4850
     * The last component entered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4851
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4852
    private transient Component targetLastEntered;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4853
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4854
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4855
     * Is the mouse over the native container
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4856
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4857
    private transient boolean isMouseInNativeContainer = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4858
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4859
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4860
     * This variable is not used, but kept for serialization compatibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4861
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4862
    private Cursor nativeCursor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4863
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4864
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4865
     * The event mask for contained lightweight components.  Lightweight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4866
     * components need a windowed container to host window-related
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4867
     * events.  This separate mask indicates events that have been
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4868
     * requested by contained lightweight components without effecting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4869
     * the mask of the windowed component itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4870
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4871
    private long eventMask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4872
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4873
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4874
     * The kind of events routed to lightweight components from windowed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4875
     * hosts.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4876
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4877
    private static final long PROXY_EVENT_MASK =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4878
        AWTEvent.FOCUS_EVENT_MASK |
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4879
        AWTEvent.KEY_EVENT_MASK |
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4880
        AWTEvent.MOUSE_EVENT_MASK |
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4881
        AWTEvent.MOUSE_MOTION_EVENT_MASK |
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4882
        AWTEvent.MOUSE_WHEEL_EVENT_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4883
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4884
    private static final long MOUSE_MASK =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4885
        AWTEvent.MOUSE_EVENT_MASK |
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4886
        AWTEvent.MOUSE_MOTION_EVENT_MASK |
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4887
        AWTEvent.MOUSE_WHEEL_EVENT_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4888
}