src/java.desktop/share/classes/javax/swing/JLayeredPane.java
author serb
Mon, 09 Sep 2019 12:23:22 -0700
changeset 58325 d32a3b1ca84a
parent 52752 5e7dba63836d
permissions -rw-r--r--
8225372: accessibility errors in tables in java.desktop files Reviewed-by: aivanov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
58325
d32a3b1ca84a 8225372: accessibility errors in tables in java.desktop files
serb
parents: 52752
diff changeset
     2
 * Copyright (c) 1997, 2019, 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: 3084
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: 3084
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: 3084
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3084
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3084
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package javax.swing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.Color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.Graphics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.Rectangle;
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 32865
diff changeset
    33
import java.beans.JavaBean;
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 32865
diff changeset
    34
import java.beans.BeanProperty;
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 32865
diff changeset
    35
3084
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 1639
diff changeset
    36
import sun.awt.SunToolkit;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <code>JLayeredPane</code> adds depth to a JFC/Swing container,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * allowing components to overlap each other when needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * An <code>Integer</code> object specifies each component's depth in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * container, where higher-numbered components sit &quot;on top&quot; of other
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * For task-oriented documentation and examples of using layered panes see
52752
5e7dba63836d 8212882: links to tutorial should be updated to use https:
kaddepalli
parents: 47216
diff changeset
    47
 * <a href="https://docs.oracle.com/javase/tutorial/uiswing/components/layeredpane.html">How to Use a Layered Pane</a>,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * a section in <em>The Java Tutorial</em>.
21982
fd6e5fe509df 8029264: [doclint] more doclint and tidy cleanup
yan
parents: 21278
diff changeset
    49
 *
58325
d32a3b1ca84a 8225372: accessibility errors in tables in java.desktop files
serb
parents: 52752
diff changeset
    50
 * <div style="float:right;text-align:center">
d32a3b1ca84a 8225372: accessibility errors in tables in java.desktop files
serb
parents: 52752
diff changeset
    51
 *   <p><b>Example:</b>
d32a3b1ca84a 8225372: accessibility errors in tables in java.desktop files
serb
parents: 52752
diff changeset
    52
 *   <p><img src="doc-files/JLayeredPane-1.gif"
d32a3b1ca84a 8225372: accessibility errors in tables in java.desktop files
serb
parents: 52752
diff changeset
    53
 *       alt="The following text describes this image."
d32a3b1ca84a 8225372: accessibility errors in tables in java.desktop files
serb
parents: 52752
diff changeset
    54
 *       width="269" height="264">
d32a3b1ca84a 8225372: accessibility errors in tables in java.desktop files
serb
parents: 52752
diff changeset
    55
 * </div>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * For convenience, <code>JLayeredPane</code> divides the depth-range
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * into several different layers. Putting a component into one of those
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * layers makes it easy to ensure that components overlap properly,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * without having to worry about specifying numbers for specific depths:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <DL>
22260
c9185e010e03 8031082: Fix non-missing doclint problems in client libraries
darcy
parents: 21982
diff changeset
    61
 *    <DT>DEFAULT_LAYER</DT>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *         <DD>The standard layer, where most components go. This the bottommost
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *         layer.
22260
c9185e010e03 8031082: Fix non-missing doclint problems in client libraries
darcy
parents: 21982
diff changeset
    64
 *    <DT>PALETTE_LAYER</DT>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *         <DD>The palette layer sits over the default layer. Useful for floating
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *         toolbars and palettes, so they can be positioned above other components.
22260
c9185e010e03 8031082: Fix non-missing doclint problems in client libraries
darcy
parents: 21982
diff changeset
    67
 *    <DT>MODAL_LAYER</DT>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *         <DD>The layer used for modal dialogs. They will appear on top of any
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *         toolbars, palettes, or standard components in the container.
22260
c9185e010e03 8031082: Fix non-missing doclint problems in client libraries
darcy
parents: 21982
diff changeset
    70
 *    <DT>POPUP_LAYER</DT>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *         <DD>The popup layer displays above dialogs. That way, the popup windows
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *         associated with combo boxes, tooltips, and other help text will appear
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *         above the component, palette, or dialog that generated them.
22260
c9185e010e03 8031082: Fix non-missing doclint problems in client libraries
darcy
parents: 21982
diff changeset
    74
 *    <DT>DRAG_LAYER</DT>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *         <DD>When dragging a component, reassigning it to the drag layer ensures
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *         that it is positioned over every other component in the container. When
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *         finished dragging, it can be reassigned to its normal layer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * </DL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * The <code>JLayeredPane</code> methods <code>moveToFront(Component)</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * <code>moveToBack(Component)</code> and <code>setPosition</code> can be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * to reposition a component within its layer. The <code>setLayer</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * can also be used to change the component's current layer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * <h2>Details</h2>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * <code>JLayeredPane</code> manages its list of children like
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * <code>Container</code>, but allows for the definition of a several
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * layers within itself. Children in the same layer are managed exactly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * like the normal <code>Container</code> object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * with the added feature that when children components overlap, children
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * in higher layers display above the children in lower layers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * Each layer is a distinct integer number. The layer attribute can be set
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * on a <code>Component</code> by passing an <code>Integer</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * object during the add call.<br> For example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * <PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 *     layeredPane.add(child, JLayeredPane.DEFAULT_LAYER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * or
37714
7a0b1c7e7054 8154213: clean up uses of boxed primitive constructors in the java.desktop module
prr
parents: 33253
diff changeset
    98
 *     layeredPane.add(child, Integer.valueOf.valueOf(10));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * </PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * The layer attribute can also be set on a Component by calling<PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 *     layeredPaneParent.setLayer(child, 10)</PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * on the <code>JLayeredPane</code> that is the parent of component. The layer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * should be set <i>before</i> adding the child to the parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * Higher number layers display above lower number layers. So, using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * numbers for the layers and letters for individual components, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * representative list order would look like this:<PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 *       5a, 5b, 5c, 2a, 2b, 2c, 1a </PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * where the leftmost components are closest to the top of the display.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * A component can be moved to the top or bottom position within its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * layer by calling <code>moveToFront</code> or <code>moveToBack</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * The position of a component within a layer can also be specified directly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * Valid positions range from 0 up to one less than the number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * components in that layer. A value of -1 indicates the bottommost
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * position. A value of 0 indicates the topmost position. Unlike layer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * numbers, higher position values are <i>lower</i> in the display.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * <b>Note:</b> This sequence (defined by java.awt.Container) is the reverse
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * of the layer numbering sequence. Usually though, you will use <code>moveToFront</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * <code>moveToBack</code>, and <code>setLayer</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * Here are some examples using the method add(Component, layer, position):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * Calling add(5x, 5, -1) results in:<PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 *       5a, 5b, 5c, 5x, 2a, 2b, 2c, 1a </PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * Calling add(5z, 5, 2) results in:<PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 *       5a, 5b, 5z, 5c, 5x, 2a, 2b, 2c, 1a </PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * Calling add(3a, 3, 7) results in:<PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 *       5a, 5b, 5z, 5c, 5x, 3a, 2a, 2b, 2c, 1a </PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * Using normal paint/event mechanics results in 1a appearing at the bottom
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * and 5a being above all other components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 * <b>Note:</b> that these layers are simply a logical construct and LayoutManagers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 * will affect all child components of this container without regard for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 * layer settings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * <strong>Warning:</strong> Swing is not thread safe. For more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * information see <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * href="package-summary.html#threading">Swing's Threading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * Policy</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 * the same version of Swing.  As of 1.4, support for long term storage
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 20455
diff changeset
   151
 * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 * @author David Kloba
25201
4adc75e0c4e5 8046485: Add missing @since tag under javax.swing.*
henryjen
parents: 22260
diff changeset
   156
 * @since 1.2
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 32865
diff changeset
   158
@JavaBean(defaultProperty = "accessibleContext")
11268
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 5506
diff changeset
   159
@SuppressWarnings("serial")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
public class JLayeredPane extends JComponent implements Accessible {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    /// Watch the values in getObjectForLayer()
37714
7a0b1c7e7054 8154213: clean up uses of boxed primitive constructors in the java.desktop module
prr
parents: 33253
diff changeset
   162
    /** Convenience object defining the Default layer. Equivalent to Integer.valueOf(0).*/
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 25859
diff changeset
   163
    public static final Integer DEFAULT_LAYER = 0;
37714
7a0b1c7e7054 8154213: clean up uses of boxed primitive constructors in the java.desktop module
prr
parents: 33253
diff changeset
   164
    /** Convenience object defining the Palette layer. Equivalent to Integer.valueOf(100).*/
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 25859
diff changeset
   165
    public static final Integer PALETTE_LAYER = 100;
37714
7a0b1c7e7054 8154213: clean up uses of boxed primitive constructors in the java.desktop module
prr
parents: 33253
diff changeset
   166
    /** Convenience object defining the Modal layer. Equivalent to Integer.valueOf(200).*/
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 25859
diff changeset
   167
    public static final Integer MODAL_LAYER = 200;
37714
7a0b1c7e7054 8154213: clean up uses of boxed primitive constructors in the java.desktop module
prr
parents: 33253
diff changeset
   168
    /** Convenience object defining the Popup layer. Equivalent to Integer.valueOf(300).*/
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 25859
diff changeset
   169
    public static final Integer POPUP_LAYER = 300;
37714
7a0b1c7e7054 8154213: clean up uses of boxed primitive constructors in the java.desktop module
prr
parents: 33253
diff changeset
   170
    /** Convenience object defining the Drag layer. Equivalent to Integer.valueOf(400).*/
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 25859
diff changeset
   171
    public static final Integer DRAG_LAYER = 400;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    /** Convenience object defining the Frame Content layer.
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20458
diff changeset
   173
      * This layer is normally only use to position the contentPane and menuBar
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
      * components of JFrame.
37714
7a0b1c7e7054 8154213: clean up uses of boxed primitive constructors in the java.desktop module
prr
parents: 33253
diff changeset
   175
      * Equivalent to Integer.valueOf(-30000).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
      * @see JFrame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
      */
37714
7a0b1c7e7054 8154213: clean up uses of boxed primitive constructors in the java.desktop module
prr
parents: 33253
diff changeset
   178
    public static final Integer FRAME_CONTENT_LAYER = -30000;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    /** Bound property */
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 25859
diff changeset
   181
    public static final String LAYER_PROPERTY = "layeredContainerLayer";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    // Hashtable to store layer values for non-JComponent components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    private Hashtable<Component,Integer> componentToLayer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    private boolean optimizedDrawingPossible = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
//////////////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
//// Container Override methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
//////////////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    /** Create a new JLayeredPane */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    public JLayeredPane() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        setLayout(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    private void validateOptimizedDrawing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        boolean layeredComponentFound = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        synchronized(getTreeLock()) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   198
            Integer layer;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            for (Component c : getComponents()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                layer = null;
3084
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 1639
diff changeset
   202
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 1639
diff changeset
   203
                if(SunToolkit.isInstanceOf(c, "javax.swing.JInternalFrame") ||
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 1639
diff changeset
   204
                       (c instanceof JComponent &&
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 1639
diff changeset
   205
                        (layer = (Integer)((JComponent)c).
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 1639
diff changeset
   206
                                     getClientProperty(LAYER_PROPERTY)) != null))
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 1639
diff changeset
   207
                {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                    if(layer != null && layer.equals(FRAME_CONTENT_LAYER))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                    layeredComponentFound = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        if(layeredComponentFound)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            optimizedDrawingPossible = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            optimizedDrawingPossible = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    protected void addImpl(Component comp, Object constraints, int index) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   223
        int layer;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        int pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        if(constraints instanceof Integer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            layer = ((Integer)constraints).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            setLayer(comp, layer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            layer = getLayer(comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        pos = insertIndexForLayer(layer, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        super.addImpl(comp, constraints, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        comp.validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        comp.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        validateOptimizedDrawing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * Remove the indexed component from this pane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * This is the absolute index, ignoring layers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @param index  an int specifying the component to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * @see #getIndexOf
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    public void remove(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        Component c = getComponent(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        super.remove(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        if (c != null && !(c instanceof JComponent)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            getComponentToLayer().remove(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        validateOptimizedDrawing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * Removes all the components from this container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    public void removeAll() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        Component[] children = getComponents();
11268
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 5506
diff changeset
   262
        Hashtable<Component, Integer> cToL = getComponentToLayer();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        for (int counter = children.length - 1; counter >= 0; counter--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            Component c = children[counter];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            if (c != null && !(c instanceof JComponent)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                cToL.remove(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        super.removeAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * Returns false if components in the pane can overlap, which makes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * optimized drawing impossible. Otherwise, returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * @return false if components can overlap, else true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * @see JComponent#isOptimizedDrawingEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 32865
diff changeset
   279
    @BeanProperty(bound = false)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    public boolean isOptimizedDrawingEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        return optimizedDrawingPossible;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
//////////////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
//// New methods for managing layers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
//////////////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    /** Sets the layer property on a JComponent. This method does not cause
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
      * any side effects like setLayer() (painting, add/remove, etc).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
      * Normally you should use the instance method setLayer(), in order to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
      * get the desired side-effects (like repainting).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
      * @param c      the JComponent to move
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
      * @param layer  an int specifying the layer to move it to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
      * @see #setLayer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    public static void putLayer(JComponent c, int layer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        /// MAKE SURE THIS AND setLayer(Component c, int layer, int position)  are SYNCED
25777
bb88947b6766 8049893: Replace uses of 'new Integer()' with appropriate alternative across client classes
prr
parents: 25201
diff changeset
   299
        c.putClientProperty(LAYER_PROPERTY, layer);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    /** Gets the layer property for a JComponent, it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
      * does not cause any side effects like setLayer(). (painting, add/remove, etc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
      * Normally you should use the instance method getLayer().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
      * @param c  the JComponent to check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
      * @return   an int specifying the component's layer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    public static int getLayer(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        Integer i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        if((i = (Integer)c.getClientProperty(LAYER_PROPERTY)) != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            return i.intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        return DEFAULT_LAYER.intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    /** Convenience method that returns the first JLayeredPane which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
      * contains the specified component. Note that all JFrames have a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
      * JLayeredPane at their root, so any component in a JFrame will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
      * have a JLayeredPane parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
      * @param c the Component to check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
      * @return the JLayeredPane that contains the component, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
      *         null if no JLayeredPane is found in the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
      *         hierarchy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
      * @see JFrame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
      * @see JRootPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    public static JLayeredPane getLayeredPaneAbove(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        if(c == null) return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        Component parent = c.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        while(parent != null && !(parent instanceof JLayeredPane))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            parent = parent.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        return (JLayeredPane)parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    /** Sets the layer attribute on the specified component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
      * making it the bottommost component in that layer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
      * Should be called before adding to parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
      * @param c     the Component to set the layer for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
      * @param layer an int specifying the layer to set, where
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
      *              lower numbers are closer to the bottom
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    public void setLayer(Component c, int layer)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        setLayer(c, layer, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    /** Sets the layer attribute for the specified component and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
      * also sets its position within that layer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
      * @param c         the Component to set the layer for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
      * @param layer     an int specifying the layer to set, where
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
      *                  lower numbers are closer to the bottom
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
      * @param position  an int specifying the position within the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
      *                  layer, where 0 is the topmost position and -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
      *                  is the bottommost position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    public void setLayer(Component c, int layer, int position)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        Integer layerObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        layerObj = getObjectForLayer(layer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        if(layer == getLayer(c) && position == getPosition(c)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                repaint(c.getBounds());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        /// MAKE SURE THIS AND putLayer(JComponent c, int layer) are SYNCED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        if(c instanceof JComponent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            ((JComponent)c).putClientProperty(LAYER_PROPERTY, layerObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        else
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   372
            getComponentToLayer().put(c, layerObj);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        if(c.getParent() == null || c.getParent() != this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            repaint(c.getBounds());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        int index = insertIndexForLayer(c, layer, position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        setComponentZOrder(c, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        repaint(c.getBounds());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * Returns the layer attribute for the specified Component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * @param c  the Component to check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * @return an int specifying the component's current layer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    public int getLayer(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        Integer i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        if(c instanceof JComponent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            i = (Integer)((JComponent)c).getClientProperty(LAYER_PROPERTY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        else
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   396
            i = getComponentToLayer().get(c);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        if(i == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            return DEFAULT_LAYER.intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        return i.intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * Returns the index of the specified Component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * This is the absolute index, ignoring layers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * Index numbers, like position numbers, have the topmost component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * at index zero. Larger numbers are closer to the bottom.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * @param c  the Component to check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * @return an int specifying the component's index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    public int getIndexOf(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        int i, count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        count = getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        for(i = 0; i < count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            if(c == getComponent(i))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * Moves the component to the top of the components in its current layer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * (position 0).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * @param c the Component to move
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * @see #setPosition(Component, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    public void moveToFront(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        setPosition(c, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * Moves the component to the bottom of the components in its current layer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * (position -1).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * @param c the Component to move
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * @see #setPosition(Component, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    public void moveToBack(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        setPosition(c, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * Moves the component to <code>position</code> within its current layer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * where 0 is the topmost position within the layer and -1 is the bottommost
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * <b>Note:</b> Position numbering is defined by java.awt.Container, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * is the opposite of layer numbering. Lower position numbers are closer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * to the top (0 is topmost), and higher position numbers are closer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * the bottom.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * @param c         the Component to move
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * @param position  an int in the range -1..N-1, where N is the number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     *                  components in the component's current layer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    public void setPosition(Component c, int position) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        setLayer(c, getLayer(c), position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * Get the relative position of the component within its layer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * @param c  the Component to check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * @return an int giving the component's position, where 0 is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     *         topmost position and the highest index value = the count
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     *         count of components at that layer, minus 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * @see #getComponentCountInLayer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    public int getPosition(Component c) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   473
        int i, startLayer, curLayer, startLocation, pos = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   475
        getComponentCount();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        startLocation = getIndexOf(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        if(startLocation == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        startLayer = getLayer(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        for(i = startLocation - 1; i >= 0; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            curLayer = getLayer(getComponent(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            if(curLayer == startLayer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                pos++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                return pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        return pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    /** Returns the highest layer value from all current children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
      * Returns 0 if there are no children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
      * @return an int indicating the layer of the topmost component in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
      *         pane, or zero if there are no children
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    public int highestLayer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        if(getComponentCount() > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            return getLayer(getComponent(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    /** Returns the lowest layer value from all current children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
      * Returns 0 if there are no children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
      * @return an int indicating the layer of the bottommost component in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
      *         pane, or zero if there are no children
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    public int lowestLayer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        int count = getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        if(count > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            return getLayer(getComponent(count-1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * Returns the number of children currently in the specified layer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * @param layer  an int specifying the layer to check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * @return an int specifying the number of components in that layer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    public int getComponentCountInLayer(int layer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        int i, count, curLayer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        int layerCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        count = getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        for(i = 0; i < count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            curLayer = getLayer(getComponent(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            if(curLayer == layer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                layerCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            /// Short circut the counting when we have them all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            } else if(layerCount > 0 || curLayer < layer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        return layerCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * Returns an array of the components in the specified layer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * @param layer  an int specifying the layer to check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * @return an array of Components contained in that layer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    public Component[] getComponentsInLayer(int layer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        int i, count, curLayer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        int layerCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        Component[] results;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        results = new Component[getComponentCountInLayer(layer)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        count = getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        for(i = 0; i < count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            curLayer = getLayer(getComponent(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            if(curLayer == layer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                results[layerCount++] = getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            /// Short circut the counting when we have them all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            } else if(layerCount > 0 || curLayer < layer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        return results;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * Paints this JLayeredPane within the specified graphics context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * @param g  the Graphics context within which to paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    public void paint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        if(isOpaque()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            Rectangle r = g.getClipBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            Color c = getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
            if(c == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                c = Color.lightGray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            g.setColor(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            if (r != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                g.fillRect(r.x, r.y, r.width, r.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                g.fillRect(0, 0, getWidth(), getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        super.paint(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
//////////////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
//// Implementation Details
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
//////////////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * Returns the hashtable that maps components to layers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * @return the Hashtable used to map components to their layers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    protected Hashtable<Component,Integer> getComponentToLayer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        if(componentToLayer == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            componentToLayer = new Hashtable<Component,Integer>(4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        return componentToLayer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * Returns the Integer object associated with a specified layer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * @param layer an int specifying the layer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * @return an Integer object for that layer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    protected Integer getObjectForLayer(int layer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        switch(layer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        case 0:
25777
bb88947b6766 8049893: Replace uses of 'new Integer()' with appropriate alternative across client classes
prr
parents: 25201
diff changeset
   613
            return DEFAULT_LAYER;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        case 100:
25777
bb88947b6766 8049893: Replace uses of 'new Integer()' with appropriate alternative across client classes
prr
parents: 25201
diff changeset
   615
            return PALETTE_LAYER;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        case 200:
25777
bb88947b6766 8049893: Replace uses of 'new Integer()' with appropriate alternative across client classes
prr
parents: 25201
diff changeset
   617
            return MODAL_LAYER;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        case 300:
25777
bb88947b6766 8049893: Replace uses of 'new Integer()' with appropriate alternative across client classes
prr
parents: 25201
diff changeset
   619
            return POPUP_LAYER;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        case 400:
25777
bb88947b6766 8049893: Replace uses of 'new Integer()' with appropriate alternative across client classes
prr
parents: 25201
diff changeset
   621
            return DRAG_LAYER;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        default:
25777
bb88947b6766 8049893: Replace uses of 'new Integer()' with appropriate alternative across client classes
prr
parents: 25201
diff changeset
   623
            return layer;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * Primitive method that determines the proper location to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * insert a new child based on layer and position requests.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * @param layer     an int specifying the layer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * @param position  an int specifying the position within the layer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * @return an int giving the (absolute) insertion-index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * @see #getIndexOf
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    protected int insertIndexForLayer(int layer, int position) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        return insertIndexForLayer(null, layer, position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * This method is an extended version of insertIndexForLayer()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * to support setLayer which uses Container.setZOrder which does
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20458
diff changeset
   644
     * not remove the component from the containment hierarchy though
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * we need to ignore it when calculating the insertion index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * @param comp      component to ignore when determining index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * @param layer     an int specifying the layer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * @param position  an int specifying the position within the layer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     * @return an int giving the (absolute) insertion-index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     * @see #getIndexOf
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    private int insertIndexForLayer(Component comp, int layer, int position) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        int i, count, curLayer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        int layerStart = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        int layerEnd = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        int componentCount = getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        ArrayList<Component> compList =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
            new ArrayList<Component>(componentCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        for (int index = 0; index < componentCount; index++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
            if (getComponent(index) != comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                compList.add(getComponent(index));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        count = compList.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        for (i = 0; i < count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
            curLayer = getLayer(compList.get(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
            if (layerStart == -1 && curLayer == layer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                layerStart = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
            if (curLayer < layer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                if (i == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                    // layer is greater than any current layer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                    // [ ASSERT(layer > highestLayer()) ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                    layerStart = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                    layerEnd = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                    layerEnd = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        // layer requested is lower than any current layer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        // [ ASSERT(layer < lowestLayer()) ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        // put it on the bottom of the stack
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        if (layerStart == -1 && layerEnd == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
            return count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        // In the case of a single layer entry handle the degenerative cases
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        if (layerStart != -1 && layerEnd == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
            layerEnd = count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        if (layerEnd != -1 && layerStart == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
            layerStart = layerEnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        // If we are adding to the bottom, return the last element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        if (position == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            return layerEnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        // Otherwise make sure the requested position falls in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        // proper range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        if (position > -1 && layerStart + position <= layerEnd)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            return layerStart + position;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        // Otherwise return the end of the layer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        return layerEnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     * Returns a string representation of this JLayeredPane. This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     * is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * implementations. The returned string may be empty but may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     * be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     * @return  a string representation of this JLayeredPane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        String optimizedDrawingPossibleString = (optimizedDrawingPossible ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                                                 "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        return super.paramString() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        ",optimizedDrawingPossible=" + optimizedDrawingPossibleString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
// Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     * Gets the AccessibleContext associated with this JLayeredPane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     * For layered panes, the AccessibleContext takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     * AccessibleJLayeredPane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     * A new AccessibleJLayeredPane instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     * @return an AccessibleJLayeredPane that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     *         AccessibleContext of this JLayeredPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 32865
diff changeset
   743
    @BeanProperty(bound = false)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
            accessibleContext = new AccessibleJLayeredPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     * <code>JLayeredPane</code> class.  It provides an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     * Java Accessibility API appropriate to layered pane user-interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     * elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     * the same version of Swing.  As of 1.4, support for long term storage
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 20455
diff changeset
   762
     * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     */
11268
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 5506
diff changeset
   766
    @SuppressWarnings("serial")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
    protected class AccessibleJLayeredPane extends AccessibleJComponent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
         * Get the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
         * @return an instance of AccessibleRole describing the role of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
         * object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
         * @see AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
            return AccessibleRole.LAYERED_PANE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
}