jdk/src/share/classes/javax/swing/JLayeredPane.java
author ant
Thu, 17 May 2012 21:48:57 +0400
changeset 12661 6cf8b7116579
parent 11268 f0e59c4852de
child 20451 4cedf4e1560a
permissions -rw-r--r--
7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application. Summary: forward port from 7u4 Reviewed-by: art
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3084
diff changeset
     2
 * Copyright (c) 1997, 2008, 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;
3084
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 1639
diff changeset
    33
import sun.awt.SunToolkit;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <code>JLayeredPane</code> adds depth to a JFC/Swing container,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * allowing components to overlap each other when needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * An <code>Integer</code> object specifies each component's depth in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * container, where higher-numbered components sit &quot;on top&quot; of other
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * For task-oriented documentation and examples of using layered panes see
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <a href="http://java.sun.com/docs/books/tutorial/uiswing/components/layeredpane.html">How to Use a Layered Pane</a>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * a section in <em>The Java Tutorial</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <TABLE ALIGN="RIGHT" BORDER="0" SUMMARY="layout">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <TR>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *   <TD ALIGN="CENTER">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *     <P ALIGN="CENTER"><IMG SRC="doc-files/JLayeredPane-1.gif"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *     alt="The following text describes this image."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *     WIDTH="269" HEIGHT="264" ALIGN="BOTTOM" BORDER="0">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *   </TD>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * </TR>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * </TABLE>
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>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *    <DT><FONT SIZE="2">DEFAULT_LAYER</FONT></DT>
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.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *    <DT><FONT SIZE="2">PALETTE_LAYER</FONT></DT>
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.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *    <DT><FONT SIZE="2">MODAL_LAYER</FONT></DT>
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.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *    <DT><FONT SIZE="2">POPUP_LAYER</FONT></DT>
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.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *    <DT><FONT SIZE="2">DRAG_LAYER</FONT></DT>
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 *     layeredPane.add(child, new Integer(10));
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 * of all JavaBeans<sup><font size="-2">TM</font></sup>
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 */
11268
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 5506
diff changeset
   157
@SuppressWarnings("serial")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
public class JLayeredPane extends JComponent implements Accessible {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    /// Watch the values in getObjectForLayer()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    /** Convenience object defining the Default layer. Equivalent to new Integer(0).*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    public final static Integer DEFAULT_LAYER = new Integer(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    /** Convenience object defining the Palette layer. Equivalent to new Integer(100).*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    public final static Integer PALETTE_LAYER = new Integer(100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    /** Convenience object defining the Modal layer. Equivalent to new Integer(200).*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    public final static Integer MODAL_LAYER = new Integer(200);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    /** Convenience object defining the Popup layer. Equivalent to new Integer(300).*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    public final static Integer POPUP_LAYER = new Integer(300);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    /** Convenience object defining the Drag layer. Equivalent to new Integer(400).*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    public final static Integer DRAG_LAYER = new Integer(400);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    /** Convenience object defining the Frame Content layer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
      * This layer is normally only use to positon the contentPane and menuBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
      * components of JFrame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
      * Equivalent to new Integer(-30000).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
      * @see JFrame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    public final static Integer FRAME_CONTENT_LAYER = new Integer(-30000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    /** Bound property */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    public final static String LAYER_PROPERTY = "layeredContainerLayer";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    // Hashtable to store layer values for non-JComponent components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    private Hashtable<Component,Integer> componentToLayer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    private boolean optimizedDrawingPossible = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
//////////////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
//// Container Override methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
//////////////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    /** Create a new JLayeredPane */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    public JLayeredPane() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        setLayout(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    private void validateOptimizedDrawing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        boolean layeredComponentFound = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        synchronized(getTreeLock()) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   196
            Integer layer;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            for (Component c : getComponents()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                layer = null;
3084
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 1639
diff changeset
   200
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 1639
diff changeset
   201
                if(SunToolkit.isInstanceOf(c, "javax.swing.JInternalFrame") ||
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 1639
diff changeset
   202
                       (c instanceof JComponent &&
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 1639
diff changeset
   203
                        (layer = (Integer)((JComponent)c).
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 1639
diff changeset
   204
                                     getClientProperty(LAYER_PROPERTY)) != null))
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 1639
diff changeset
   205
                {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                    if(layer != null && layer.equals(FRAME_CONTENT_LAYER))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                    layeredComponentFound = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        if(layeredComponentFound)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            optimizedDrawingPossible = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            optimizedDrawingPossible = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    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
   221
        int layer;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        int pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        if(constraints instanceof Integer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            layer = ((Integer)constraints).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            setLayer(comp, layer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            layer = getLayer(comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        pos = insertIndexForLayer(layer, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        super.addImpl(comp, constraints, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        comp.validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        comp.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        validateOptimizedDrawing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * Remove the indexed component from this pane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * This is the absolute index, ignoring layers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * @param index  an int specifying the component to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @see #getIndexOf
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    public void remove(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        Component c = getComponent(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        super.remove(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        if (c != null && !(c instanceof JComponent)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            getComponentToLayer().remove(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        validateOptimizedDrawing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * Removes all the components from this container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    public void removeAll() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        Component[] children = getComponents();
11268
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 5506
diff changeset
   260
        Hashtable<Component, Integer> cToL = getComponentToLayer();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        for (int counter = children.length - 1; counter >= 0; counter--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            Component c = children[counter];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            if (c != null && !(c instanceof JComponent)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                cToL.remove(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        super.removeAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * Returns false if components in the pane can overlap, which makes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * optimized drawing impossible. Otherwise, returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * @return false if components can overlap, else true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @see JComponent#isOptimizedDrawingEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    public boolean isOptimizedDrawingEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        return optimizedDrawingPossible;
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
//////////////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
//// New methods for managing layers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
//////////////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    /** Sets the layer property on a JComponent. This method does not cause
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
      * any side effects like setLayer() (painting, add/remove, etc).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
      * Normally you should use the instance method setLayer(), in order to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
      * get the desired side-effects (like repainting).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
      * @param c      the JComponent to move
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
      * @param layer  an int specifying the layer to move it to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
      * @see #setLayer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    public static void putLayer(JComponent c, int layer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        /// MAKE SURE THIS AND setLayer(Component c, int layer, int position)  are SYNCED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        Integer layerObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        layerObj = new Integer(layer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        c.putClientProperty(LAYER_PROPERTY, layerObj);
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
        Integer layerObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        switch(layer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        case 0:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            layerObj = DEFAULT_LAYER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        case 100:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            layerObj = PALETTE_LAYER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        case 200:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            layerObj = MODAL_LAYER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        case 300:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            layerObj = POPUP_LAYER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        case 400:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            layerObj = DRAG_LAYER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            layerObj = new Integer(layer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        return layerObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * Primitive method that determines the proper location to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * insert a new child based on layer and position requests.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * @param layer     an int specifying the layer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * @param position  an int specifying the position within the layer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * @return an int giving the (absolute) insertion-index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * @see #getIndexOf
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    protected int insertIndexForLayer(int layer, int position) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        return insertIndexForLayer(null, layer, position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * This method is an extended version of insertIndexForLayer()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     * to support setLayer which uses Container.setZOrder which does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * not remove the component from the containment heirarchy though
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     * we need to ignore it when calculating the insertion index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * @param comp      component to ignore when determining index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * @param layer     an int specifying the layer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     * @param position  an int specifying the position within the layer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * @return an int giving the (absolute) insertion-index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * @see #getIndexOf
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    private int insertIndexForLayer(Component comp, int layer, int position) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        int i, count, curLayer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        int layerStart = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        int layerEnd = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        int componentCount = getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        ArrayList<Component> compList =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
            new ArrayList<Component>(componentCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        for (int index = 0; index < componentCount; index++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
            if (getComponent(index) != comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                compList.add(getComponent(index));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        count = compList.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        for (i = 0; i < count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
            curLayer = getLayer(compList.get(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
            if (layerStart == -1 && curLayer == layer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                layerStart = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
            if (curLayer < layer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                if (i == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                    // layer is greater than any current layer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                    // [ ASSERT(layer > highestLayer()) ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                    layerStart = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                    layerEnd = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                    layerEnd = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        // layer requested is lower than any current layer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        // [ ASSERT(layer < lowestLayer()) ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        // put it on the bottom of the stack
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        if (layerStart == -1 && layerEnd == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
            return count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        // In the case of a single layer entry handle the degenerative cases
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        if (layerStart != -1 && layerEnd == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            layerEnd = count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        if (layerEnd != -1 && layerStart == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            layerStart = layerEnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        // If we are adding to the bottom, return the last element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        if (position == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
            return layerEnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        // Otherwise make sure the requested position falls in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        // proper range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        if (position > -1 && layerStart + position <= layerEnd)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
            return layerStart + position;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        // Otherwise return the end of the layer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        return layerEnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     * Returns a string representation of this JLayeredPane. This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     * is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     * implementations. The returned string may be empty but may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     * be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * @return  a string representation of this JLayeredPane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        String optimizedDrawingPossibleString = (optimizedDrawingPossible ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                                                 "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        return super.paramString() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        ",optimizedDrawingPossible=" + optimizedDrawingPossibleString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
// Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     * Gets the AccessibleContext associated with this JLayeredPane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     * For layered panes, the AccessibleContext takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     * AccessibleJLayeredPane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     * A new AccessibleJLayeredPane instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     * @return an AccessibleJLayeredPane that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     *         AccessibleContext of this JLayeredPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
            accessibleContext = new AccessibleJLayeredPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     * <code>JLayeredPane</code> class.  It provides an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     * Java Accessibility API appropriate to layered pane user-interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     * elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
     * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     */
11268
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 5506
diff changeset
   772
    @SuppressWarnings("serial")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    protected class AccessibleJLayeredPane extends AccessibleJComponent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
         * Get the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
         * @return an instance of AccessibleRole describing the role of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
         * object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
         * @see AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
            return AccessibleRole.LAYERED_PANE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
}