0N/A/*
2362N/A * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/Apackage javax.swing;
0N/A
0N/Aimport java.awt.Component;
0N/Aimport java.util.ArrayList;
0N/Aimport java.util.Hashtable;
0N/Aimport java.awt.Color;
0N/Aimport java.awt.Graphics;
0N/Aimport java.awt.Rectangle;
1338N/Aimport sun.awt.SunToolkit;
0N/A
0N/Aimport javax.accessibility.*;
0N/A
0N/A/**
0N/A * <code>JLayeredPane</code> adds depth to a JFC/Swing container,
0N/A * allowing components to overlap each other when needed.
0N/A * An <code>Integer</code> object specifies each component's depth in the
0N/A * container, where higher-numbered components sit &quot;on top&quot; of other
0N/A * components.
0N/A * For task-oriented documentation and examples of using layered panes see
0N/A * <a href="http://java.sun.com/docs/books/tutorial/uiswing/components/layeredpane.html">How to Use a Layered Pane</a>,
0N/A * a section in <em>The Java Tutorial</em>.
0N/A * <P>
0N/A * <TABLE ALIGN="RIGHT" BORDER="0" SUMMARY="layout">
0N/A * <TR>
0N/A * <TD ALIGN="CENTER">
0N/A * <P ALIGN="CENTER"><IMG SRC="doc-files/JLayeredPane-1.gif"
0N/A * alt="The following text describes this image."
0N/A * WIDTH="269" HEIGHT="264" ALIGN="BOTTOM" BORDER="0">
0N/A * </TD>
0N/A * </TR>
0N/A * </TABLE>
0N/A * For convenience, <code>JLayeredPane</code> divides the depth-range
0N/A * into several different layers. Putting a component into one of those
0N/A * layers makes it easy to ensure that components overlap properly,
0N/A * without having to worry about specifying numbers for specific depths:
0N/A * <DL>
0N/A * <DT><FONT SIZE="2">DEFAULT_LAYER</FONT></DT>
0N/A * <DD>The standard layer, where most components go. This the bottommost
0N/A * layer.
0N/A * <DT><FONT SIZE="2">PALETTE_LAYER</FONT></DT>
0N/A * <DD>The palette layer sits over the default layer. Useful for floating
0N/A * toolbars and palettes, so they can be positioned above other components.
0N/A * <DT><FONT SIZE="2">MODAL_LAYER</FONT></DT>
0N/A * <DD>The layer used for modal dialogs. They will appear on top of any
0N/A * toolbars, palettes, or standard components in the container.
0N/A * <DT><FONT SIZE="2">POPUP_LAYER</FONT></DT>
0N/A * <DD>The popup layer displays above dialogs. That way, the popup windows
0N/A * associated with combo boxes, tooltips, and other help text will appear
0N/A * above the component, palette, or dialog that generated them.
0N/A * <DT><FONT SIZE="2">DRAG_LAYER</FONT></DT>
0N/A * <DD>When dragging a component, reassigning it to the drag layer ensures
0N/A * that it is positioned over every other component in the container. When
0N/A * finished dragging, it can be reassigned to its normal layer.
0N/A * </DL>
0N/A * The <code>JLayeredPane</code> methods <code>moveToFront(Component)</code>,
0N/A * <code>moveToBack(Component)</code> and <code>setPosition</code> can be used
0N/A * to reposition a component within its layer. The <code>setLayer</code> method
0N/A * can also be used to change the component's current layer.
0N/A *
0N/A * <h2>Details</h2>
0N/A * <code>JLayeredPane</code> manages its list of children like
0N/A * <code>Container</code>, but allows for the definition of a several
0N/A * layers within itself. Children in the same layer are managed exactly
0N/A * like the normal <code>Container</code> object,
0N/A * with the added feature that when children components overlap, children
0N/A * in higher layers display above the children in lower layers.
0N/A * <p>
0N/A * Each layer is a distinct integer number. The layer attribute can be set
0N/A * on a <code>Component</code> by passing an <code>Integer</code>
0N/A * object during the add call.<br> For example:
0N/A * <PRE>
0N/A * layeredPane.add(child, JLayeredPane.DEFAULT_LAYER);
0N/A * or
0N/A * layeredPane.add(child, new Integer(10));
0N/A * </PRE>
0N/A * The layer attribute can also be set on a Component by calling<PRE>
0N/A * layeredPaneParent.setLayer(child, 10)</PRE>
0N/A * on the <code>JLayeredPane</code> that is the parent of component. The layer
0N/A * should be set <i>before</i> adding the child to the parent.
0N/A * <p>
0N/A * Higher number layers display above lower number layers. So, using
0N/A * numbers for the layers and letters for individual components, a
0N/A * representative list order would look like this:<PRE>
0N/A * 5a, 5b, 5c, 2a, 2b, 2c, 1a </PRE>
0N/A * where the leftmost components are closest to the top of the display.
0N/A * <p>
0N/A * A component can be moved to the top or bottom position within its
0N/A * layer by calling <code>moveToFront</code> or <code>moveToBack</code>.
0N/A * <p>
0N/A * The position of a component within a layer can also be specified directly.
0N/A * Valid positions range from 0 up to one less than the number of
0N/A * components in that layer. A value of -1 indicates the bottommost
0N/A * position. A value of 0 indicates the topmost position. Unlike layer
0N/A * numbers, higher position values are <i>lower</i> in the display.
0N/A * <blockquote>
0N/A * <b>Note:</b> This sequence (defined by java.awt.Container) is the reverse
0N/A * of the layer numbering sequence. Usually though, you will use <code>moveToFront</code>,
0N/A * <code>moveToBack</code>, and <code>setLayer</code>.
0N/A * </blockquote>
0N/A * Here are some examples using the method add(Component, layer, position):
0N/A * Calling add(5x, 5, -1) results in:<PRE>
0N/A * 5a, 5b, 5c, 5x, 2a, 2b, 2c, 1a </PRE>
0N/A *
0N/A * Calling add(5z, 5, 2) results in:<PRE>
0N/A * 5a, 5b, 5z, 5c, 5x, 2a, 2b, 2c, 1a </PRE>
0N/A *
0N/A * Calling add(3a, 3, 7) results in:<PRE>
0N/A * 5a, 5b, 5z, 5c, 5x, 3a, 2a, 2b, 2c, 1a </PRE>
0N/A *
0N/A * Using normal paint/event mechanics results in 1a appearing at the bottom
0N/A * and 5a being above all other components.
0N/A * <p>
0N/A * <b>Note:</b> that these layers are simply a logical construct and LayoutManagers
0N/A * will affect all child components of this container without regard for
0N/A * layer settings.
0N/A * <p>
0N/A * <strong>Warning:</strong> Swing is not thread safe. For more
0N/A * information see <a
0N/A * href="package-summary.html#threading">Swing's Threading
0N/A * Policy</a>.
0N/A * <p>
0N/A * <strong>Warning:</strong>
0N/A * Serialized objects of this class will not be compatible with
0N/A * future Swing releases. The current serialization support is
0N/A * appropriate for short term storage or RMI between applications running
0N/A * the same version of Swing. As of 1.4, support for long term storage
0N/A * of all JavaBeans<sup><font size="-2">TM</font></sup>
0N/A * has been added to the <code>java.beans</code> package.
0N/A * Please see {@link java.beans.XMLEncoder}.
0N/A *
0N/A * @author David Kloba
0N/A */
0N/Apublic class JLayeredPane extends JComponent implements Accessible {
0N/A /// Watch the values in getObjectForLayer()
0N/A /** Convenience object defining the Default layer. Equivalent to new Integer(0).*/
0N/A public final static Integer DEFAULT_LAYER = new Integer(0);
0N/A /** Convenience object defining the Palette layer. Equivalent to new Integer(100).*/
0N/A public final static Integer PALETTE_LAYER = new Integer(100);
0N/A /** Convenience object defining the Modal layer. Equivalent to new Integer(200).*/
0N/A public final static Integer MODAL_LAYER = new Integer(200);
0N/A /** Convenience object defining the Popup layer. Equivalent to new Integer(300).*/
0N/A public final static Integer POPUP_LAYER = new Integer(300);
0N/A /** Convenience object defining the Drag layer. Equivalent to new Integer(400).*/
0N/A public final static Integer DRAG_LAYER = new Integer(400);
0N/A /** Convenience object defining the Frame Content layer.
0N/A * This layer is normally only use to positon the contentPane and menuBar
0N/A * components of JFrame.
0N/A * Equivalent to new Integer(-30000).
0N/A * @see JFrame
0N/A */
0N/A public final static Integer FRAME_CONTENT_LAYER = new Integer(-30000);
0N/A
0N/A /** Bound property */
0N/A public final static String LAYER_PROPERTY = "layeredContainerLayer";
0N/A // Hashtable to store layer values for non-JComponent components
0N/A private Hashtable<Component,Integer> componentToLayer;
0N/A private boolean optimizedDrawingPossible = true;
0N/A
0N/A
0N/A//////////////////////////////////////////////////////////////////////////////
0N/A//// Container Override methods
0N/A//////////////////////////////////////////////////////////////////////////////
0N/A /** Create a new JLayeredPane */
0N/A public JLayeredPane() {
0N/A setLayout(null);
0N/A }
0N/A
0N/A private void validateOptimizedDrawing() {
0N/A boolean layeredComponentFound = false;
0N/A synchronized(getTreeLock()) {
625N/A Integer layer;
0N/A
0N/A for (Component c : getComponents()) {
0N/A layer = null;
1338N/A
1338N/A if(SunToolkit.isInstanceOf(c, "javax.swing.JInternalFrame") ||
1338N/A (c instanceof JComponent &&
1338N/A (layer = (Integer)((JComponent)c).
1338N/A getClientProperty(LAYER_PROPERTY)) != null))
1338N/A {
0N/A if(layer != null && layer.equals(FRAME_CONTENT_LAYER))
0N/A continue;
0N/A layeredComponentFound = true;
0N/A break;
0N/A }
0N/A }
0N/A }
0N/A
0N/A if(layeredComponentFound)
0N/A optimizedDrawingPossible = false;
0N/A else
0N/A optimizedDrawingPossible = true;
0N/A }
0N/A
0N/A protected void addImpl(Component comp, Object constraints, int index) {
625N/A int layer;
0N/A int pos;
0N/A
0N/A if(constraints instanceof Integer) {
0N/A layer = ((Integer)constraints).intValue();
0N/A setLayer(comp, layer);
0N/A } else
0N/A layer = getLayer(comp);
0N/A
0N/A pos = insertIndexForLayer(layer, index);
0N/A super.addImpl(comp, constraints, pos);
0N/A comp.validate();
0N/A comp.repaint();
0N/A validateOptimizedDrawing();
0N/A }
0N/A
0N/A /**
0N/A * Remove the indexed component from this pane.
0N/A * This is the absolute index, ignoring layers.
0N/A *
0N/A * @param index an int specifying the component to remove
0N/A * @see #getIndexOf
0N/A */
0N/A public void remove(int index) {
0N/A Component c = getComponent(index);
0N/A super.remove(index);
0N/A if (c != null && !(c instanceof JComponent)) {
0N/A getComponentToLayer().remove(c);
0N/A }
0N/A validateOptimizedDrawing();
0N/A }
0N/A
0N/A /**
0N/A * Removes all the components from this container.
0N/A *
0N/A * @since 1.5
0N/A */
0N/A public void removeAll() {
0N/A Component[] children = getComponents();
0N/A Hashtable cToL = getComponentToLayer();
0N/A for (int counter = children.length - 1; counter >= 0; counter--) {
0N/A Component c = children[counter];
0N/A if (c != null && !(c instanceof JComponent)) {
0N/A cToL.remove(c);
0N/A }
0N/A }
0N/A super.removeAll();
0N/A }
0N/A
0N/A /**
0N/A * Returns false if components in the pane can overlap, which makes
0N/A * optimized drawing impossible. Otherwise, returns true.
0N/A *
0N/A * @return false if components can overlap, else true
0N/A * @see JComponent#isOptimizedDrawingEnabled
0N/A */
0N/A public boolean isOptimizedDrawingEnabled() {
0N/A return optimizedDrawingPossible;
0N/A }
0N/A
0N/A
0N/A//////////////////////////////////////////////////////////////////////////////
0N/A//// New methods for managing layers
0N/A//////////////////////////////////////////////////////////////////////////////
0N/A /** Sets the layer property on a JComponent. This method does not cause
0N/A * any side effects like setLayer() (painting, add/remove, etc).
0N/A * Normally you should use the instance method setLayer(), in order to
0N/A * get the desired side-effects (like repainting).
0N/A *
0N/A * @param c the JComponent to move
0N/A * @param layer an int specifying the layer to move it to
0N/A * @see #setLayer
0N/A */
0N/A public static void putLayer(JComponent c, int layer) {
0N/A /// MAKE SURE THIS AND setLayer(Component c, int layer, int position) are SYNCED
0N/A Integer layerObj;
0N/A
0N/A layerObj = new Integer(layer);
0N/A c.putClientProperty(LAYER_PROPERTY, layerObj);
0N/A }
0N/A
0N/A /** Gets the layer property for a JComponent, it
0N/A * does not cause any side effects like setLayer(). (painting, add/remove, etc)
0N/A * Normally you should use the instance method getLayer().
0N/A *
0N/A * @param c the JComponent to check
0N/A * @return an int specifying the component's layer
0N/A */
0N/A public static int getLayer(JComponent c) {
0N/A Integer i;
0N/A if((i = (Integer)c.getClientProperty(LAYER_PROPERTY)) != null)
0N/A return i.intValue();
0N/A return DEFAULT_LAYER.intValue();
0N/A }
0N/A
0N/A /** Convenience method that returns the first JLayeredPane which
0N/A * contains the specified component. Note that all JFrames have a
0N/A * JLayeredPane at their root, so any component in a JFrame will
0N/A * have a JLayeredPane parent.
0N/A *
0N/A * @param c the Component to check
0N/A * @return the JLayeredPane that contains the component, or
0N/A * null if no JLayeredPane is found in the component
0N/A * hierarchy
0N/A * @see JFrame
0N/A * @see JRootPane
0N/A */
0N/A public static JLayeredPane getLayeredPaneAbove(Component c) {
0N/A if(c == null) return null;
0N/A
0N/A Component parent = c.getParent();
0N/A while(parent != null && !(parent instanceof JLayeredPane))
0N/A parent = parent.getParent();
0N/A return (JLayeredPane)parent;
0N/A }
0N/A
0N/A /** Sets the layer attribute on the specified component,
0N/A * making it the bottommost component in that layer.
0N/A * Should be called before adding to parent.
0N/A *
0N/A * @param c the Component to set the layer for
0N/A * @param layer an int specifying the layer to set, where
0N/A * lower numbers are closer to the bottom
0N/A */
0N/A public void setLayer(Component c, int layer) {
0N/A setLayer(c, layer, -1);
0N/A }
0N/A
0N/A /** Sets the layer attribute for the specified component and
0N/A * also sets its position within that layer.
0N/A *
0N/A * @param c the Component to set the layer for
0N/A * @param layer an int specifying the layer to set, where
0N/A * lower numbers are closer to the bottom
0N/A * @param position an int specifying the position within the
0N/A * layer, where 0 is the topmost position and -1
0N/A * is the bottommost position
0N/A */
0N/A public void setLayer(Component c, int layer, int position) {
0N/A Integer layerObj;
0N/A layerObj = getObjectForLayer(layer);
0N/A
0N/A if(layer == getLayer(c) && position == getPosition(c)) {
0N/A repaint(c.getBounds());
0N/A return;
0N/A }
0N/A
0N/A /// MAKE SURE THIS AND putLayer(JComponent c, int layer) are SYNCED
0N/A if(c instanceof JComponent)
0N/A ((JComponent)c).putClientProperty(LAYER_PROPERTY, layerObj);
0N/A else
625N/A getComponentToLayer().put(c, layerObj);
0N/A
0N/A if(c.getParent() == null || c.getParent() != this) {
0N/A repaint(c.getBounds());
0N/A return;
0N/A }
0N/A
0N/A int index = insertIndexForLayer(c, layer, position);
0N/A
0N/A setComponentZOrder(c, index);
0N/A repaint(c.getBounds());
0N/A }
0N/A
0N/A /**
0N/A * Returns the layer attribute for the specified Component.
0N/A *
0N/A * @param c the Component to check
0N/A * @return an int specifying the component's current layer
0N/A */
0N/A public int getLayer(Component c) {
0N/A Integer i;
0N/A if(c instanceof JComponent)
0N/A i = (Integer)((JComponent)c).getClientProperty(LAYER_PROPERTY);
0N/A else
625N/A i = getComponentToLayer().get(c);
0N/A
0N/A if(i == null)
0N/A return DEFAULT_LAYER.intValue();
0N/A return i.intValue();
0N/A }
0N/A
0N/A /**
0N/A * Returns the index of the specified Component.
0N/A * This is the absolute index, ignoring layers.
0N/A * Index numbers, like position numbers, have the topmost component
0N/A * at index zero. Larger numbers are closer to the bottom.
0N/A *
0N/A * @param c the Component to check
0N/A * @return an int specifying the component's index
0N/A */
0N/A public int getIndexOf(Component c) {
0N/A int i, count;
0N/A
0N/A count = getComponentCount();
0N/A for(i = 0; i < count; i++) {
0N/A if(c == getComponent(i))
0N/A return i;
0N/A }
0N/A return -1;
0N/A }
0N/A /**
0N/A * Moves the component to the top of the components in its current layer
0N/A * (position 0).
0N/A *
0N/A * @param c the Component to move
0N/A * @see #setPosition(Component, int)
0N/A */
0N/A public void moveToFront(Component c) {
0N/A setPosition(c, 0);
0N/A }
0N/A
0N/A /**
0N/A * Moves the component to the bottom of the components in its current layer
0N/A * (position -1).
0N/A *
0N/A * @param c the Component to move
0N/A * @see #setPosition(Component, int)
0N/A */
0N/A public void moveToBack(Component c) {
0N/A setPosition(c, -1);
0N/A }
0N/A
0N/A /**
0N/A * Moves the component to <code>position</code> within its current layer,
0N/A * where 0 is the topmost position within the layer and -1 is the bottommost
0N/A * position.
0N/A * <p>
0N/A * <b>Note:</b> Position numbering is defined by java.awt.Container, and
0N/A * is the opposite of layer numbering. Lower position numbers are closer
0N/A * to the top (0 is topmost), and higher position numbers are closer to
0N/A * the bottom.
0N/A *
0N/A * @param c the Component to move
0N/A * @param position an int in the range -1..N-1, where N is the number of
0N/A * components in the component's current layer
0N/A */
0N/A public void setPosition(Component c, int position) {
0N/A setLayer(c, getLayer(c), position);
0N/A }
0N/A
0N/A /**
0N/A * Get the relative position of the component within its layer.
0N/A *
0N/A * @param c the Component to check
0N/A * @return an int giving the component's position, where 0 is the
0N/A * topmost position and the highest index value = the count
0N/A * count of components at that layer, minus 1
0N/A *
0N/A * @see #getComponentCountInLayer
0N/A */
0N/A public int getPosition(Component c) {
625N/A int i, startLayer, curLayer, startLocation, pos = 0;
0N/A
625N/A getComponentCount();
0N/A startLocation = getIndexOf(c);
0N/A
0N/A if(startLocation == -1)
0N/A return -1;
0N/A
0N/A startLayer = getLayer(c);
0N/A for(i = startLocation - 1; i >= 0; i--) {
0N/A curLayer = getLayer(getComponent(i));
0N/A if(curLayer == startLayer)
0N/A pos++;
0N/A else
0N/A return pos;
0N/A }
0N/A return pos;
0N/A }
0N/A
0N/A /** Returns the highest layer value from all current children.
0N/A * Returns 0 if there are no children.
0N/A *
0N/A * @return an int indicating the layer of the topmost component in the
0N/A * pane, or zero if there are no children
0N/A */
0N/A public int highestLayer() {
0N/A if(getComponentCount() > 0)
0N/A return getLayer(getComponent(0));
0N/A return 0;
0N/A }
0N/A
0N/A /** Returns the lowest layer value from all current children.
0N/A * Returns 0 if there are no children.
0N/A *
0N/A * @return an int indicating the layer of the bottommost component in the
0N/A * pane, or zero if there are no children
0N/A */
0N/A public int lowestLayer() {
0N/A int count = getComponentCount();
0N/A if(count > 0)
0N/A return getLayer(getComponent(count-1));
0N/A return 0;
0N/A }
0N/A
0N/A /**
0N/A * Returns the number of children currently in the specified layer.
0N/A *
0N/A * @param layer an int specifying the layer to check
0N/A * @return an int specifying the number of components in that layer
0N/A */
0N/A public int getComponentCountInLayer(int layer) {
0N/A int i, count, curLayer;
0N/A int layerCount = 0;
0N/A
0N/A count = getComponentCount();
0N/A for(i = 0; i < count; i++) {
0N/A curLayer = getLayer(getComponent(i));
0N/A if(curLayer == layer) {
0N/A layerCount++;
0N/A /// Short circut the counting when we have them all
0N/A } else if(layerCount > 0 || curLayer < layer) {
0N/A break;
0N/A }
0N/A }
0N/A
0N/A return layerCount;
0N/A }
0N/A
0N/A /**
0N/A * Returns an array of the components in the specified layer.
0N/A *
0N/A * @param layer an int specifying the layer to check
0N/A * @return an array of Components contained in that layer
0N/A */
0N/A public Component[] getComponentsInLayer(int layer) {
0N/A int i, count, curLayer;
0N/A int layerCount = 0;
0N/A Component[] results;
0N/A
0N/A results = new Component[getComponentCountInLayer(layer)];
0N/A count = getComponentCount();
0N/A for(i = 0; i < count; i++) {
0N/A curLayer = getLayer(getComponent(i));
0N/A if(curLayer == layer) {
0N/A results[layerCount++] = getComponent(i);
0N/A /// Short circut the counting when we have them all
0N/A } else if(layerCount > 0 || curLayer < layer) {
0N/A break;
0N/A }
0N/A }
0N/A
0N/A return results;
0N/A }
0N/A
0N/A /**
0N/A * Paints this JLayeredPane within the specified graphics context.
0N/A *
0N/A * @param g the Graphics context within which to paint
0N/A */
0N/A public void paint(Graphics g) {
0N/A if(isOpaque()) {
0N/A Rectangle r = g.getClipBounds();
0N/A Color c = getBackground();
0N/A if(c == null)
0N/A c = Color.lightGray;
0N/A g.setColor(c);
0N/A if (r != null) {
0N/A g.fillRect(r.x, r.y, r.width, r.height);
0N/A }
0N/A else {
0N/A g.fillRect(0, 0, getWidth(), getHeight());
0N/A }
0N/A }
0N/A super.paint(g);
0N/A }
0N/A
0N/A//////////////////////////////////////////////////////////////////////////////
0N/A//// Implementation Details
0N/A//////////////////////////////////////////////////////////////////////////////
0N/A
0N/A /**
0N/A * Returns the hashtable that maps components to layers.
0N/A *
0N/A * @return the Hashtable used to map components to their layers
0N/A */
0N/A protected Hashtable<Component,Integer> getComponentToLayer() {
0N/A if(componentToLayer == null)
0N/A componentToLayer = new Hashtable<Component,Integer>(4);
0N/A return componentToLayer;
0N/A }
0N/A
0N/A /**
0N/A * Returns the Integer object associated with a specified layer.
0N/A *
0N/A * @param layer an int specifying the layer
0N/A * @return an Integer object for that layer
0N/A */
0N/A protected Integer getObjectForLayer(int layer) {
0N/A Integer layerObj;
0N/A switch(layer) {
0N/A case 0:
0N/A layerObj = DEFAULT_LAYER;
0N/A break;
0N/A case 100:
0N/A layerObj = PALETTE_LAYER;
0N/A break;
0N/A case 200:
0N/A layerObj = MODAL_LAYER;
0N/A break;
0N/A case 300:
0N/A layerObj = POPUP_LAYER;
0N/A break;
0N/A case 400:
0N/A layerObj = DRAG_LAYER;
0N/A break;
0N/A default:
0N/A layerObj = new Integer(layer);
0N/A }
0N/A return layerObj;
0N/A }
0N/A
0N/A /**
0N/A * Primitive method that determines the proper location to
0N/A * insert a new child based on layer and position requests.
0N/A *
0N/A * @param layer an int specifying the layer
0N/A * @param position an int specifying the position within the layer
0N/A * @return an int giving the (absolute) insertion-index
0N/A *
0N/A * @see #getIndexOf
0N/A */
0N/A protected int insertIndexForLayer(int layer, int position) {
0N/A return insertIndexForLayer(null, layer, position);
0N/A }
0N/A
0N/A /**
0N/A * This method is an extended version of insertIndexForLayer()
0N/A * to support setLayer which uses Container.setZOrder which does
0N/A * not remove the component from the containment heirarchy though
0N/A * we need to ignore it when calculating the insertion index.
0N/A *
0N/A * @param comp component to ignore when determining index
0N/A * @param layer an int specifying the layer
0N/A * @param position an int specifying the position within the layer
0N/A * @return an int giving the (absolute) insertion-index
0N/A *
0N/A * @see #getIndexOf
0N/A */
0N/A private int insertIndexForLayer(Component comp, int layer, int position) {
0N/A int i, count, curLayer;
0N/A int layerStart = -1;
0N/A int layerEnd = -1;
0N/A int componentCount = getComponentCount();
0N/A
0N/A ArrayList<Component> compList =
0N/A new ArrayList<Component>(componentCount);
0N/A for (int index = 0; index < componentCount; index++) {
0N/A if (getComponent(index) != comp) {
0N/A compList.add(getComponent(index));
0N/A }
0N/A }
0N/A
0N/A count = compList.size();
0N/A for (i = 0; i < count; i++) {
0N/A curLayer = getLayer(compList.get(i));
0N/A if (layerStart == -1 && curLayer == layer) {
0N/A layerStart = i;
0N/A }
0N/A if (curLayer < layer) {
0N/A if (i == 0) {
0N/A // layer is greater than any current layer
0N/A // [ ASSERT(layer > highestLayer()) ]
0N/A layerStart = 0;
0N/A layerEnd = 0;
0N/A } else {
0N/A layerEnd = i;
0N/A }
0N/A break;
0N/A }
0N/A }
0N/A
0N/A // layer requested is lower than any current layer
0N/A // [ ASSERT(layer < lowestLayer()) ]
0N/A // put it on the bottom of the stack
0N/A if (layerStart == -1 && layerEnd == -1)
0N/A return count;
0N/A
0N/A // In the case of a single layer entry handle the degenerative cases
0N/A if (layerStart != -1 && layerEnd == -1)
0N/A layerEnd = count;
0N/A
0N/A if (layerEnd != -1 && layerStart == -1)
0N/A layerStart = layerEnd;
0N/A
0N/A // If we are adding to the bottom, return the last element
0N/A if (position == -1)
0N/A return layerEnd;
0N/A
0N/A // Otherwise make sure the requested position falls in the
0N/A // proper range
0N/A if (position > -1 && layerStart + position <= layerEnd)
0N/A return layerStart + position;
0N/A
0N/A // Otherwise return the end of the layer
0N/A return layerEnd;
0N/A }
0N/A
0N/A /**
0N/A * Returns a string representation of this JLayeredPane. This method
0N/A * is intended to be used only for debugging purposes, and the
0N/A * content and format of the returned string may vary between
0N/A * implementations. The returned string may be empty but may not
0N/A * be <code>null</code>.
0N/A *
0N/A * @return a string representation of this JLayeredPane.
0N/A */
0N/A protected String paramString() {
0N/A String optimizedDrawingPossibleString = (optimizedDrawingPossible ?
0N/A "true" : "false");
0N/A
0N/A return super.paramString() +
0N/A ",optimizedDrawingPossible=" + optimizedDrawingPossibleString;
0N/A }
0N/A
0N/A/////////////////
0N/A// Accessibility support
0N/A////////////////
0N/A
0N/A /**
0N/A * Gets the AccessibleContext associated with this JLayeredPane.
0N/A * For layered panes, the AccessibleContext takes the form of an
0N/A * AccessibleJLayeredPane.
0N/A * A new AccessibleJLayeredPane instance is created if necessary.
0N/A *
0N/A * @return an AccessibleJLayeredPane that serves as the
0N/A * AccessibleContext of this JLayeredPane
0N/A */
0N/A public AccessibleContext getAccessibleContext() {
0N/A if (accessibleContext == null) {
0N/A accessibleContext = new AccessibleJLayeredPane();
0N/A }
0N/A return accessibleContext;
0N/A }
0N/A
0N/A /**
0N/A * This class implements accessibility support for the
0N/A * <code>JLayeredPane</code> class. It provides an implementation of the
0N/A * Java Accessibility API appropriate to layered pane user-interface
0N/A * elements.
0N/A * <p>
0N/A * <strong>Warning:</strong>
0N/A * Serialized objects of this class will not be compatible with
0N/A * future Swing releases. The current serialization support is
0N/A * appropriate for short term storage or RMI between applications running
0N/A * the same version of Swing. As of 1.4, support for long term storage
0N/A * of all JavaBeans<sup><font size="-2">TM</font></sup>
0N/A * has been added to the <code>java.beans</code> package.
0N/A * Please see {@link java.beans.XMLEncoder}.
0N/A */
0N/A protected class AccessibleJLayeredPane extends AccessibleJComponent {
0N/A
0N/A /**
0N/A * Get the role of this object.
0N/A *
0N/A * @return an instance of AccessibleRole describing the role of the
0N/A * object
0N/A * @see AccessibleRole
0N/A */
0N/A public AccessibleRole getAccessibleRole() {
0N/A return AccessibleRole.LAYERED_PANE;
0N/A }
0N/A }
0N/A}