⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jlayeredpane.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* JLayeredPane.java --    Copyright (C) 2002, 2004 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. */package javax.swing;import java.awt.Color;import java.awt.Component;import java.awt.Container;import java.awt.Graphics;import java.awt.Rectangle;import java.awt.Shape;import java.util.Hashtable;import java.util.Iterator;import java.util.Map;import java.util.TreeMap;import javax.accessibility.Accessible;import javax.accessibility.AccessibleContext;import javax.accessibility.AccessibleRole;/** * A container that adds depth to the usual <code>Container</code> semantics. * Each child component of a <code>Layered Pane</code> is placed within one * of several layers. <code>JLayeredPane</code> defines a set of standard * layers. The pre-defined sets are (in the order from button to top): * *  <dl> *    <dt>{@link #DEFAULT_LAYER}</dt> *    <dd>The layer where most of the normal components are placed. This *      is the bottommost layer.</dd> * *    <dt>{@link #PALETTE_LAYER}</dt> *    <dd>Palette windows are placed in this layer.</dd> * *    <dt>{@link #MODAL_LAYER}</dt> *    <dd>The layer where internal modal dialog windows are placed.</dd> * *    <dt>{@link #POPUP_LAYER}</dt> *    <dd>The layer for popup menus</dd> * *    <dt>{@link #DRAG_LAYER}</dt> *    <dd>Components that are beeing dragged are temporarily placed in *       this layer.</dd> *  </dl> * * <p>A child is in exactly one of these layers at any time, though there may * be other layers if someone creates them.</p> * * <p>You can add a component to a specific layer using the * {@link Container#add(Component, Object)} method. I.e. * <code>layeredPane.add(comp, JLayeredPane.MODAL_LAYER)</code> will add the * component <code>comp</code> to the modal layer of <code>layeredPane</code>. * </p> * * <p>To change the layer of a component that is already a child of * a <code>JLayeredPane</code>, use the {@link #setLayer(Component, int)}  * method.</p> * * <p>The purpose of this class is to translate this view of "layers" into a * contiguous array of components: the one held in our ancestor, * {@link java.awt.Container}.</p> * * <p>There is a precise set of words we will use to refer to numbers within * this class:</p> *  * <dl> * <dt>Component Index:</dt>  * <dd>An offset into the <code>component</code> array held in our ancestor, * {@link java.awt.Container}, from <code>[0 .. component.length)</code>. The drawing * rule with indices is that 0 is drawn last.</dd> * * <dt>Layer Number:</dt> * <dd>A general <code>int</code> specifying a layer within this component.  Negative * numbers are drawn first, then layer 0, then positive numbered layers, in * ascending order.</dd> * * <dt>Position:</dt>  * <dd>An offset into a layer's "logical drawing order". Layer position 0 * is drawn last. Layer position -1 is a synonym for the first layer * position (the logical "bottom").</dd> * </dl> * * <p><b>Note:</b> the layer numbering order is the <em>reverse</em> of the * component indexing and position order</p> * * @author Graydon Hoare (graydon@redhat.com) */public class JLayeredPane extends JComponent implements Accessible{    /**   * Provides accessibility support for <code>JLayeredPane</code>.   */  protected class AccessibleJLayeredPane extends AccessibleJComponent  {    /**     * Creates a new instance of <code>AccessibleJLayeredPane</code>.     */    public AccessibleJLayeredPane()    {      // Nothing to do here.    }    /**     * Returns the accessble role of <code>JLayeredPane</code>,     * {@link AccessibleRole#LAYERED_PANE}.      */    public AccessibleRole getAccessibleRole()    {      return AccessibleRole.LAYERED_PANE;    }  }  private static final long serialVersionUID = 5534920399324590459L;    public static final String LAYER_PROPERTY = "layeredContainerLayer";  public static Integer FRAME_CONTENT_LAYER = new Integer (-30000);  public static Integer DEFAULT_LAYER = new Integer (0);  public static Integer PALETTE_LAYER = new Integer (100);  public static Integer MODAL_LAYER   = new Integer (200);  public static Integer POPUP_LAYER   = new Integer (300);  public static Integer DRAG_LAYER    = new Integer (400);  TreeMap layers;               // Layer Number (Integer) -> Layer Size (Integer)  Hashtable componentToLayer;   // Component -> Layer Number (Integer)  private transient Rectangle rectCache;    public JLayeredPane()  {    layers = new TreeMap ();    componentToLayer = new Hashtable ();    setLayout(null);  }  /**    * Looks up the layer a child component is currently assigned to.   *   * @param c the component to look up.   * @return the layer the component is currently assigned to, in this container.   * @throws IllegalArgumentException if the component is not a child of this container.   */  public int getLayer(Component c)  {    Component myComp = c;    while(! componentToLayer.containsKey(myComp))      {	myComp = myComp.getParent();	if (myComp == null)	  break;      }    if (myComp == null)      throw new IllegalArgumentException	("component is not in this JLayeredPane");    Integer layerObj = (Integer) componentToLayer.get(myComp);    return layerObj.intValue();  }  /**   * Looks up the layer of <code>comp</code> in the component's nearest   * JLayeredPane ancestor. If <code>comp</code> is not contained   * in a JLayeredPane, the value 0 (default layer) is returned.   *   * @param comp the component for which the layer is looked up   *   * @return the layer of <code>comp</code> in its nearest JLayeredPane   *     ancestor   */  public static int getLayer(JComponent comp)  {    JLayeredPane lp = (JLayeredPane) SwingUtilities.getAncestorOfClass      (JLayeredPane.class, comp);    if (lp == null)      return 0;    else      // The cast here forces the call to the instance method getLayer()      // instead of the static method (this would lead to infinite      // recursion).      return lp.getLayer((Component) comp);  }  /**   * Returns the first JLayeredPane that contains the Component   * <code>comp</code> or <code>null</code> if <code>comp</code> is   * not contained in a JLayeredPane.   *   * @param comp the component for which we are searching the JLayeredPane   *     ancestor   *   * @return the first JLayeredPane that contains the Component   *     <code>comp</code> or <code>null</code> if <code>comp</code> is   *     not contained in a JLayeredPane   */  public static JLayeredPane getLayeredPaneAbove(Component comp)  {    JLayeredPane lp = (JLayeredPane) SwingUtilities.getAncestorOfClass      (JLayeredPane.class, comp);    return lp;  }  /**   * <p>Returns a pair of ints representing a half-open interval    * <code>[top, bottom)</code>, which is the range of component indices    * the provided layer number corresponds to.</p>   *   * <p>Note that "bottom" is <em>not</em> included in the interval of   * component indices in this layer: a layer with 0 elements in it has   * <code>ret[0] == ret[1]</code>.</p>   *   * @param layer the layer to look up.   * @return the half-open range of indices this layer spans.   * @throws IllegalArgumentException if layer does not refer to an active layer   * in this container.   */  private int[] layerToRange (Integer layer)  {    int[] ret = new int[2];    ret[1] = getComponents ().length;    Iterator i = layers.entrySet ().iterator ();    while (i.hasNext())      {        Map.Entry pair = (Map.Entry) i.next();        Integer layerNum = (Integer) pair.getKey ();        Integer layerSz = (Integer) pair.getValue ();        int layerInt = layerNum.intValue();        if (layerInt == layer.intValue())          {            ret[0] = ret[1] - layerSz.intValue ();            break;          }        // In the following case there exists no layer with the specified        // number, so we return an empty interval here with the index at which        // such a layer would be inserted        else if (layerInt > layer.intValue())          {            ret[1] = ret[0];            break;          }        else          {            ret[1] -= layerSz.intValue ();          }      }    return ret;  }  /**   * Increments the recorded size of a given layer.   *   * @param layer the layer number to increment.   * @see #incrLayer   */  private void incrLayer(Integer layer)  {    int sz = 1;    if (layers.containsKey (layer))	    sz += ((Integer)(layers.get (layer))).intValue ();    layers.put (layer, new Integer(sz));  }  /**   * Decrements the recorded size of a given layer.   *   * @param layer the layer number to decrement.   * @see #incrLayer   */  private void decrLayer(Integer layer)  {    int sz = 0;    if (layers.containsKey (layer))	    sz = ((Integer)(layers.get (layer))).intValue () - 1;    layers.put (layer, new Integer(sz));  }  /**   * Return the greatest layer number currently in use, in this container.   * This number may legally be positive <em>or</em> negative.   *   * @return the least layer number.   * @see #lowestLayer()   */  public int highestLayer()  {    if (layers.size() == 0)	    return 0;    return ((Integer)(layers.lastKey ())).intValue ();  }  /**   * Return the least layer number currently in use, in this container.   * This number may legally be positive <em>or</em> negative.   *   * @return the least layer number.   * @see #highestLayer()   */  public int lowestLayer()  {    if (layers.size() == 0)	    return 0;    return ((Integer)(layers.firstKey ())).intValue ();  }  /**   * Moves a component to the "front" of its layer. The "front" is a   * synonym for position 0, which is also the last position drawn in each   * layer, so is usually the component which occludes the most other   * components in its layer.   *   * @param c the component to move to the front of its layer.   * @throws IllegalArgumentException if the component is not a child of   * this container.   * @see #moveToBack   */  public void moveToFront(Component c)  {    setPosition (c, 0);  }  /**   * <p>Moves a component to the "back" of its layer. The "back" is a   * synonym for position N-1 (also known as position -1), where N is the   * size of the layer.</p>   *

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -