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