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