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 * 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 * 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 * 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. 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 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 "on top" of other 0N/A * For task-oriented documentation and examples of using layered panes see 0N/A * a section in <em>The Java Tutorial</em>. 0N/A * <TABLE ALIGN="RIGHT" BORDER="0" SUMMARY="layout"> 0N/A * <TD ALIGN="CENTER"> 0N/A * alt="The following text describes this image." 0N/A * WIDTH="269" HEIGHT="264" ALIGN="BOTTOM" BORDER="0"> 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 * <DT><FONT SIZE="2">DEFAULT_LAYER</FONT></DT> 0N/A * <DD>The standard layer, where most components go. This the bottommost 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 * 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 * <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 * 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 * layeredPane.add(child, JLayeredPane.DEFAULT_LAYER); 0N/A * layeredPane.add(child, new Integer(10)); 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 * 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 * 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 * 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 * <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 * 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 * Calling add(5z, 5, 2) results in:<PRE> 0N/A * 5a, 5b, 5z, 5c, 5x, 2a, 2b, 2c, 1a </PRE> 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 * Using normal paint/event mechanics results in 1a appearing at the bottom 0N/A * and 5a being above all other components. 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 * <strong>Warning:</strong> Swing is not thread safe. For more 0N/A * information see <a 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 * @author David Kloba 0N/A /// Watch the values in getObjectForLayer() 0N/A /** Convenience object defining the Default layer. Equivalent to new Integer(0).*/ 0N/A /** Convenience object defining the Palette layer. Equivalent to new Integer(100).*/ 0N/A /** Convenience object defining the Modal layer. Equivalent to new Integer(200).*/ 0N/A /** Convenience object defining the Popup layer. Equivalent to new Integer(300).*/ 0N/A /** Convenience object defining the Drag layer. Equivalent to 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 /** Bound property */ 0N/A // Hashtable to store layer values for non-JComponent components 0N/A////////////////////////////////////////////////////////////////////////////// 0N/A//// Container Override methods 0N/A////////////////////////////////////////////////////////////////////////////// 0N/A /** Create a new JLayeredPane */ 0N/A * Remove the indexed component from this pane. 0N/A * This is the absolute index, ignoring layers. 0N/A * @param index an int specifying the component to remove 0N/A * Removes all the components from this container. 0N/A * Returns false if components in the pane can overlap, which makes 0N/A * optimized drawing impossible. Otherwise, returns true. 0N/A * @return false if components can overlap, else true 0N/A * @see JComponent#isOptimizedDrawingEnabled 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 * @param c the JComponent to move 0N/A * @param layer an int specifying the layer to move it to 0N/A /// MAKE SURE THIS AND setLayer(Component c, int layer, int position) are SYNCED 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 * @param c the JComponent to check 0N/A * @return an int specifying the component's layer 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 * @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 /** 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 * @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 /** Sets the layer attribute for the specified component and 0N/A * also sets its position within that layer. 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 /// MAKE SURE THIS AND putLayer(JComponent c, int layer) are SYNCED 0N/A * Returns the layer attribute for the specified Component. 0N/A * @param c the Component to check 0N/A * @return an int specifying the component's current layer 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 * @param c the Component to check 0N/A * @return an int specifying the component's index 0N/A * Moves the component to the top of the components in its current layer 0N/A * @param c the Component to move 0N/A * @see #setPosition(Component, int) 0N/A * Moves the component to the bottom of the components in its current layer 0N/A * @param c the Component to move 0N/A * @see #setPosition(Component, int) 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 * <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 * @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 * Get the relative position of the component within its layer. 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 * @see #getComponentCountInLayer 0N/A /** Returns the highest layer value from all current children. 0N/A * Returns 0 if there are no children. 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 /** Returns the lowest layer value from all current children. 0N/A * Returns 0 if there are no children. 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 * Returns the number of children currently in the specified layer. 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 /// Short circut the counting when we have them all 0N/A * Returns an array of the components in the specified layer. 0N/A * @param layer an int specifying the layer to check 0N/A * @return an array of Components contained in that layer 0N/A /// Short circut the counting when we have them all 0N/A * Paints this JLayeredPane within the specified graphics context. 0N/A * @param g the Graphics context within which to paint 0N/A////////////////////////////////////////////////////////////////////////////// 0N/A//// Implementation Details 0N/A////////////////////////////////////////////////////////////////////////////// 0N/A * Returns the hashtable that maps components to layers. 0N/A * @return the Hashtable used to map components to their layers 0N/A * Returns the Integer object associated with a specified layer. 0N/A * @param layer an int specifying the layer 0N/A * @return an Integer object for that layer 0N/A * Primitive method that determines the proper location to 0N/A * insert a new child based on layer and position requests. 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 * 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 * @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 // layer is greater than any current layer 0N/A // [ ASSERT(layer > highestLayer()) ] 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 // In the case of a single layer entry handle the degenerative cases 0N/A // If we are adding to the bottom, return the last element 0N/A // Otherwise make sure the requested position falls in the 0N/A // Otherwise return the end of the layer 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 * @return a string representation of this JLayeredPane. 0N/A// Accessibility support 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 * @return an AccessibleJLayeredPane that serves as the 0N/A * AccessibleContext of this JLayeredPane 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 * <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 * Get the role of this object. 0N/A * @return an instance of AccessibleRole describing the role of the 0N/A * @see AccessibleRole