/[classpath]/classpath/javax/swing/JLayeredPane.java
ViewVC logotype

Diff of /classpath/javax/swing/JLayeredPane.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.6 by graydon, Mon Dec 1 22:20:50 2003 UTC revision 1.7 by mkoch, Tue Dec 2 16:50:20 2003 UTC
# Line 1  Line 1 
1  /* JLayeredPane.java --  /* JLayeredPane.java --
2     Copyright (C) 2002 Free Software Foundation, Inc.     Copyright (C) 2002 Free Software Foundation, Inc.
3    
4     This file is part of GNU Classpath.  This file is part of GNU Classpath.
5    
6     GNU Classpath is free software; you can redistribute it and/or modify  GNU Classpath is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by  it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2, or (at your option)  the Free Software Foundation; either version 2, or (at your option)
9     any later version.  any later version.
10    
11     GNU Classpath is distributed in the hope that it will be useful, but  GNU Classpath is distributed in the hope that it will be useful, but
12     WITHOUT ANY WARRANTY; without even the implied warranty of  WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14     General Public License for more details.  General Public License for more details.
15    
16     You should have received a copy of the GNU General Public License  You should have received a copy of the GNU General Public License
17     along with GNU Classpath; see the file COPYING.  If not, write to the  along with GNU Classpath; see the file COPYING.  If not, write to the
18     Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19     02111-1307 USA.  02111-1307 USA.
20    
21     Linking this library statically or dynamically with other modules is  Linking this library statically or dynamically with other modules is
22     making a combined work based on this library.  Thus, the terms and  making a combined work based on this library.  Thus, the terms and
23     conditions of the GNU General Public License cover the whole  conditions of the GNU General Public License cover the whole
24     combination.  combination.
25    
26     As a special exception, the copyright holders of this library give you  As a special exception, the copyright holders of this library give you
27     permission to link this library with independent modules to produce an  permission to link this library with independent modules to produce an
28     executable, regardless of the license terms of these independent  executable, regardless of the license terms of these independent
29     modules, and to copy and distribute the resulting executable under  modules, and to copy and distribute the resulting executable under
30     terms of your choice, provided that you also meet, for each linked  terms of your choice, provided that you also meet, for each linked
31     independent module, the terms and conditions of the license of that  independent module, the terms and conditions of the license of that
32     module.  An independent module is a module which is not derived from  module.  An independent module is a module which is not derived from
33     or based on this library.  If you modify this library, you may extend  or based on this library.  If you modify this library, you may extend
34     this exception to your version of the library, but you are not  this exception to your version of the library, but you are not
35     obligated to do so.  If you do not wish to do so, delete this  obligated to do so.  If you do not wish to do so, delete this
36     exception statement from your version.  exception statement from your version. */
 */  
37    
38    
39  package javax.swing;  package javax.swing;
# Line 46  import javax.accessibility.Accessible; Line 45  import javax.accessibility.Accessible;
45    
46    
47  /**  /**
48   * <p>The "Layered Pane" is a container which divides its children into 6 (or   * The "Layered Pane" is a container which divides its children into 6 (or
49   * more) disjoint sets. the pre-defined sets are:</p>   * more) disjoint sets. the pre-defined sets are:
50   *   *
51   *  <ul>   *  "Frame Content", "Default", "Palette", "Modal", "Popup", and "Drag".
  *    <li>"Frame Content"</li>  
  *    <li>"Default"</li>  
  *    <li>"Palette"</li>  
  *    <li>"Modal"</li>  
  *    <li>"Popup"</li>  
  *    <li>"Drag"</li>  
  *  </ul>  
52   *   *
53   * <p>A child is in exactly one of these layers at any time, though there may   * A child is in exactly one of these layers at any time, though there may
54   * be other layers if someone creates them.</p>   * be other layers if someone creates them.
55   *   *
56   * <p>The purpose of this class is to translate this view of "layers" into a   * The purpose of this class is to translate this view of "layers" into a
57   * contiguous array of components: the one held in our ancestor,   * contiguous array of components: the one held in our ancestor,
58   * {@link java.awt.Container}.</p>   * java.awt.Container.
59   *   *
60   * <p>There is a precise set of words we will use to refer to numbers within   * There is a precise set of words we will use to refer to numbers within
61   * this class:</p>   * this class:
62   *   *
63   * <dl>   * Internal Component Index: an offset into the "component" array held in
64   * <dt>Internal Component Index:</dt>   * our ancestor, java.awt.Container, from [0 .. component.length). The
65   * <dd>An offset into the <code>component</code> array held in our ancestor,   * drawing rule with internal indices is that 0 is drawn first.
  * {@link java.awt.Container}, from <code>[0 .. component.length)</code>. The drawing  
  * rule with internal indices is that 0 is drawn first.</dd>  
66   *   *
67   * <dt>External Component Index:</dt>   * External Component Index: an offset into the "logical drawing order" of
68   * <dd>An offset into the "logical drawing order" of this container. If <code>I</code>   * this container. If I is the internal index of a component, the external
69   * is the internal index of a component, the external index <tt>E =   * index E = component.length - I. The rule with external indices is that 0
70   * component.length - I</tt>. The rule with external indices is that 0 is   * is drawn last.
  * drawn last.</dd>  
71   *   *
72   * <dt>Layer Number:</dt>   * Layer Number: a general int specifying a layer within this component.
73   * <dd>A general <code>int</code> specifying a layer within this component.  Negative   * Negative numbers are drawn first, then layer 0, then positive numbered
74   * numbers are drawn first, then layer 0, then positive numbered layers, in   * layers, in ascending order.
  * ascending order.</dd>  
75   *   *
76   * <dt>Position:</dt>   * Position: an offset into a layer's "logical drawing order". Layer
77   * <dd>An offset into a layer's "logical drawing order". Layer position 0   * position 0 is drawn last. Layer position -1 is a synonym for the first
78   * is drawn last. Layer position -1 is a synonym for the first layer   * layer position (the logical "bottom").
  * position (the logical "bottom").</dd>  
  *  
  * @author Graydon Hoare <graydon@redhat.com>  
79   */   */
80    
81  public class JLayeredPane extends JComponent implements Accessible  public class JLayeredPane extends JComponent implements Accessible
82  {  {
83    
84    public static String LAYER_PROPERTY = "LAYER_PROPERTY";      public static String LAYER_PROPERTY = "LAYER_PROPERTY";
85    
86    public static Integer FRAME_CONTENT_LAYER = new Integer (-30000);      public static Integer FRAME_CONTENT_LAYER = new Integer (-30000);
87    
88    public static Integer DEFAULT_LAYER = new Integer (0);      public static Integer DEFAULT_LAYER = new Integer (0);
89    public static Integer PALETTE_LAYER = new Integer (100);      public static Integer PALETTE_LAYER = new Integer (100);
90    public static Integer MODAL_LAYER   = new Integer (200);      public static Integer MODAL_LAYER   = new Integer (200);
91    public static Integer POPUP_LAYER   = new Integer (300);      public static Integer POPUP_LAYER   = new Integer (300);
92    public static Integer DRAG_LAYER    = new Integer (400);      public static Integer DRAG_LAYER    = new Integer (400);
93    
94    TreeMap layers;               // Layer Number (Integer) -> Layer Size (Integer)      TreeMap layers;               // Layer Number (Integer) -> Layer Size (Integer)
95    Hashtable componentToLayer;   // Component -> Layer Number (Integer)      Hashtable componentToLayer;   // Component -> Layer Number (Integer)
96    
97    JLayeredPane()      protected Integer getLayer (Component c)
98    {      {
99      layers = new TreeMap ();          if (! componentToLayer.containsKey (c))
     componentToLayer = new Hashtable ();  
   }  
   
   
   /**  
    * 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.  
    */  
   
   protected Integer getLayer (Component c)  
   {  
     if (! componentToLayer.containsKey (c))  
100              throw new IllegalArgumentException ();              throw new IllegalArgumentException ();
101      return (Integer) componentToLayer.get (c);          return (Integer) componentToLayer.get (c);
102    }      }
103    
104    /**      // this returns a half-open range [bottom, top), which is the range of
105     * Returns a pair of ints representing a half-open interval      // internal component indices this layer number corresponds to.  note
106     * <code>[bottom, top)</code>, which is the range of internal component      // that top is *not* included in the range of component indices in this
107     * indices the provided layer number corresponds to.      // layer: a layer with 0 elements in it has ret[0] == ret[1].
108     *  
109     * Note that "top" is <em>not</em> included in the interval of      protected int[] layerToRange (Integer layer)
110     * component indices in this layer: a layer with 0 elements in it has      {
111     * <code>ret[0] == ret[1]</code>.          int[] ret = new int[2];
112     *          Iterator i = layers.entrySet ().iterator ();
113     * @param layer the layer to look up.          while (i.hasNext())
    * @return the half-open range of internal indices this layer spans.  
    * @throws IllegalArgumentException if layer does not refer to an active layer  
    * in this container.  
    */  
   
   protected int[] layerToRange (Integer layer)  
   {  
     int[] ret = new int[2];      
     Iterator i = layers.entrySet ().iterator ();  
     while (i.hasNext())  
114              {              {
115          Map.Entry pair = (Map.Entry) i.next();                  Map.Entry pair = (Map.Entry) i.next();
116          Integer layerNum = (Integer) pair.getKey ();                  Integer layerNum = (Integer) pair.getKey ();
117          Integer layerSz = (Integer) pair.getValue ();                  Integer layerSz = (Integer) pair.getValue ();
118          if (layerNum == layer)                  if (layerNum == layer)
119            {                      {
120              ret[1] = ret[0] + layerSz.intValue ();                          ret[1] = ret[0] + layerSz.intValue ();
121              return ret;                          return ret;
122            }                      }
123          else                  else
124            {                      {
125              ret[0] += layerSz.intValue ();                          ret[0] += layerSz.intValue ();
126            }                      }
127              }              }
128      // should have found the layer during iteration          // should have found the layer during iteration
129      throw new IllegalArgumentException ();          throw new IllegalArgumentException ();
130    }      }
131    
132    /**      protected void incrLayer(Integer layer)
133     * Increments the recorded size of a given layer.      {
134     *          int sz = 1;
135     * @param layer the layer number to increment.          if (layers.containsKey (layer))
    * @see #incrLayer()  
    */  
   
   protected void incrLayer(Integer layer)  
   {  
     int sz = 1;  
     if (layers.containsKey (layer))  
136              sz += ((Integer)(layers.get (layer))).intValue ();              sz += ((Integer)(layers.get (layer))).intValue ();
137      layers.put (layer, new Integer(sz));          layers.put (layer, new Integer(sz));
138    }      }
139    
140    /**      protected void decrLayer(Integer layer)
141     * Decrements the recorded size of a given layer.      {
142     *          int sz = 0;
143     * @param layer the layer number to decrement.          if (layers.containsKey (layer))
    * @see #decrLayer()  
    */  
   
   protected void decrLayer(Integer layer)  
   {  
     int sz = 0;  
     if (layers.containsKey (layer))  
144              sz = ((Integer)(layers.get (layer))).intValue () - 1;              sz = ((Integer)(layers.get (layer))).intValue () - 1;
145      layers.put (layer, new Integer(sz));          layers.put (layer, new Integer(sz));
146    }      }
147    
148    /**      JLayeredPane()
149     * Return the greatest layer number currently in use, in this container.      {
150     * This number may legally be positive <em>or</em> negative.          layers = new TreeMap ();
151     *          layers.put (FRAME_CONTENT_LAYER, new Integer (0));
152     * @return the least layer number.          layers.put (DEFAULT_LAYER, new Integer (0));
153     * @see #lowestLayer()          layers.put (PALETTE_LAYER, new Integer (0));
154     */          layers.put (MODAL_LAYER, new Integer (0));
155            layers.put (POPUP_LAYER, new Integer (0));
156    public int highestLayer()          layers.put (DRAG_LAYER, new Integer (0));      
157    {  
158      if (layers.size() == 0)          componentToLayer = new Hashtable ();
159        }
160    
161        public int highestLayer()
162        {
163            if (layers.size() == 0)
164              return 0;              return 0;
165      return ((Integer)(layers.lastKey ())).intValue ();          return ((Integer)(layers.lastKey ())).intValue ();
166    }      }
   
   /**  
    * 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()  
    */  
167            
168    public int lowestLayer()      public int lowestLayer()
169    {      {
170      if (layers.size() == 0)          if (layers.size() == 0)
171              return 0;              return 0;
172      return ((Integer)(layers.firstKey ())).intValue ();          return ((Integer)(layers.firstKey ())).intValue ();
173    }      }
174    
175    /**      public void moveToFront(Component c)
176     * Moves a component to the "front" of its layer. The "front" is a      {
177     * synonym for position 0, which is also the last position drawn in each          setPosition (c, 0);
178     * layer, so is usually the component which occludes the most other      }
179     * components in its layer.  
180     *      public void moveToBack(Component c)
181     * @param c the component to move to the front of its layer.      {
182     * @throws IllegalArgumentException if the component is not a child of          setPosition (c, -1);
183     * 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>  
    *  
    * <p>The "back" of a layer is the first position drawn, so the component at  
    * the "back" is usually the component which is occluded by the most  
    * other components in its layer.</p>  
    *  
    * @param c the component to move to the back of its layer.  
    * @throws IllegalArgumentException if the component is not a child of  
    * this container.  
    * @see #moveToFront()  
    */  
   
   public void moveToBack(Component c)  
   {  
     setPosition (c, -1);  
   }  
   
   /**  
    * Return the position of a component within its layer. Positions are assigned  
    * from the "front" (position 0) to the "back" (position N-1), and drawn from  
    * the back towards the front.  
    *  
    * @param c the component to get the position of.  
    * @throws IllegalArgumentException if the component is not a child of  
    * this container.  
    * @see #setPosition()  
    */  
184            
185    public int getPosition(Component c)      public int getPosition(Component c)
186    {      {
187      Integer layer = getLayer (c);          Integer layer = getLayer (c);
188      int[] range = layerToRange (layer);          int[] range = layerToRange (layer);
189      int top = (range[1] - 1);          int top = (range[1] - 1);
190      Component[] comps = getComponents ();          Component[] comps = getComponents ();
191      for (int i = range[0]; i < range[1]; ++i)          for (int i = range[0]; i < range[1]; ++i)
192              {              {
193          if (comps[i] == c)                  if (comps[i] == c)
194            return top - i;                      return top - i;
195              }              }
196      // should have found it          // should have found it
197      throw new IllegalArgumentException ();          throw new IllegalArgumentException ();
198    }      }
199    
200    /**      public void setPosition(Component c, int position)
201     * Change the position of a component within its layer. Positions are assigned      {
202     * from the "front" (position 0) to the "back" (position N-1), and drawn from          Integer layer = getLayer (c);
203     * the back towards the front.          int[] range = layerToRange (layer);
204     *          if (range[0] == range[1])
    * @param c the component to change the position of.  
    * @param position the position to assign the component to.  
    * @throws IllegalArgumentException if the component is not a child of  
    * this container.  
    * @see #getPosition()  
    */  
   
   public void setPosition(Component c, int position)  
   {  
     Integer layer = getLayer (c);  
     int[] range = layerToRange (layer);  
     if (range[0] == range[1])  
205              throw new IllegalArgumentException ();              throw new IllegalArgumentException ();
206    
207      int top = (range[1] - 1);          int top = (range[1] - 1);
208      if (position == -1)          if (position == -1)
209              position = top - range[0];              position = top - range[0];
210      int targ = top - position;          int targ = top - position;
211      int curr = -1;          int curr = -1;
212    
213      Component[] comps = getComponents();          Component[] comps = getComponents();
214      for (int i = range[0]; i < range[1]; ++i)          for (int i = range[0]; i < range[1]; ++i)
215              {              {
216          if (comps[i] == c)                  if (comps[i] == c)
217            {                      {
218              curr = i;                          curr = i;
219              break;                          break;
220            }                      }
221              }              }
222      if (curr == -1)          if (curr == -1)
223              // should have found it              // should have found it
224              throw new IllegalArgumentException ();              throw new IllegalArgumentException ();
225    
226      super.swapComponents (curr, targ);          // System.err.println("set component position to " + position + " in layer " + layer);
227      validate();  
228      repaint();          Component tmp = comps[curr];
229    }          super.remove (curr);
230            super.add (tmp, targ);
231            super.validate ();
232        }
233            
234    /**  
235     * Return an array of all components within a layer of this  
236     * container. Components are ordered back-to-front, with the "back"      public Component[] getComponentsInLayer(int layer)
237     * element (which draws first) at position 0 of the returned array.      {
238     *          int[] range = layerToRange (getObjectForLayer (layer));
239     * @param layer the layer to return components from.          if (range[0] == range[1])
    * @return the components in the layer.  
    */  
   
   public Component[] getComponentsInLayer(int layer)  
   {  
     int[] range = layerToRange (getObjectForLayer (layer));  
     if (range[0] == range[1])  
240              return new Component[0];              return new Component[0];
241      else          else
242              {              {
243          Component[] comps = getComponents ();                  Component[] comps = getComponents ();
244          int sz = (range[1] - 1) - range[0];                  int sz = (range[1] - 1) - range[0];
245          Component[] nc = new Component[sz];                  Component[] nc = new Component[sz];
246          for (int i = 0; i < sz; ++i)                  for (int i = 0; i < sz; ++i)
247            nc[i] = comps[range[0] + i];                      nc[i] = comps[range[0] + i];
248          return nc;                  return nc;
249              }              }
250    }      }
251    
252    /**      public int getComponentCountInLayer(int layer)
253     * Return the number of components within a layer of this      {
254     * container.          int[] range = layerToRange (getObjectForLayer (layer));
255     *          if (range[0] == range[1])
    * @param layer the layer count components in.  
    * @return the number of components in the layer.  
    */  
   
   public int getComponentCountInLayer(int layer)  
   {  
     int[] range = layerToRange (getObjectForLayer (layer));  
     if (range[0] == range[1])  
256              return 0;              return 0;
257      else          else
258              return (range[1] - range[0]);              return ((range[1] - 1) - range[0]);
259    }      }
260    
261    /**      protected Hashtable getComponentToLayer()
262     * Return a hashtable mapping child components of this container to      {
263     * Integer objects representing the component's layer assignments.          return componentToLayer;
264     */      }
265    
266    protected Hashtable getComponentToLayer()      protected int getInternalIndexOf(Component c)
267    {      {
268      return componentToLayer;          Integer layer = getLayer (c);
269    }          int[] range = layerToRange (layer);
270            Component[] comps = getComponents();
271            for (int i = range[0]; i < range[1]; ++i)
   /**  
    * Return the index of a component within the underlying (contiguous)  
    * array of children. This is a "raw" number which does not represent the  
    * child's position in a layer, but rather its position in the  
    * concatenation of <em>all</em> layers within the container.  
    *  
    * @param c the component to look up.  
    * @return the internal index of the component.  
    * @throws IllegalArgumentException if the component is not a child of  
    * this container.  
    */  
   
   protected int getInternalIndexOf(Component c)  
   {  
     Integer layer = getLayer (c);  
     int[] range = layerToRange (layer);  
     Component[] comps = getComponents();  
     for (int i = range[0]; i < range[1]; ++i)  
272              {              {
273          if (comps[i] == c)                  if (comps[i] == c)
274            return i;                      return i;
275              }              }
276      // should have found the component during iteration          // should have found the component during iteration
277      throw new IllegalArgumentException ();          throw new IllegalArgumentException ();
278    }      }
279    
280    
281    /**      public int getIndexOf(Component c)
282     * Return the external index of a component within the underlying      {
283     * (contiguous) array of children. This is a "raw" number which does not          // returns the *external* index of the component.
284     * represent the child's position in a layer, but rather its position in          int top = getComponentCount() - 1;
285     * the logical drawing order of all children of the container.          return top - getIndexOf (c);
286     *      }    
287     * @param c the component to look up.  
288     * @return the external index of the component.  
289     * @throws IllegalArgumentException if the component is not a child of      protected Integer getObjectForLayer(int layer)
290     * this container.      {
291     */          switch (layer)
   
   public int getIndexOf(Component c)  
   {  
     // returns the *external* index of the component.  
     int top = getComponentCount() - 1;  
     return top - getIndexOf (c);  
   }      
   
   /**  
    * Return an Integer object which holds the same int value as the  
    * parameter. This is strictly an optimization to minimize the number of  
    * identical Integer objects which we allocate.  
    *  
    * @param layer the layer number as an int.  
    * @return the layer number as an Integer, possibly shared.  
    */  
   
   protected Integer getObjectForLayer(int layer)  
   {  
     switch (layer)  
292              {              {
293              case -30000:              case -30000:
294          return FRAME_CONTENT_LAYER;                  return FRAME_CONTENT_LAYER;
295    
296              case 0:              case 0:
297          return DEFAULT_LAYER;                  return DEFAULT_LAYER;
298    
299              case 100:              case 100:
300          return PALETTE_LAYER;                  return PALETTE_LAYER;
301    
302              case 200:              case 200:
303          return MODAL_LAYER;                  return MODAL_LAYER;
304    
305              case 300:              case 300:
306          return POPUP_LAYER;                  return POPUP_LAYER;
307    
308              case 400:              case 400:
309          return DRAG_LAYER;                  return DRAG_LAYER;
310    
311              default:              default:
312          break;                  break;
313              }              }
314    
315      return new Integer(layer);          return new Integer(layer);
316    }      }
   
   /**  
    * Computes an internal index at which to request the superclass {@link  
    * java.awt.Container} inserts a component, given an abstract layer and  
    * position number.  
    *  
    * @param layer the layer in which to insert a component.  
    * @param position the position in the layer at which to insert a component.  
    * @return the internal index at which to insert the component.  
    */  
317            
318    protected int insertIndexForLayer(int layer, int position)      protected int insertIndexForLayer(int layer, int position)
319    {      {
320            int[] range = layerToRange (getObjectForLayer (layer));
321      Integer lobj = getObjectForLayer (layer);          if (range[0] == range[1])
     if (! layers.containsKey(lobj))  
       layers.put (lobj, new Integer (0));  
     int[] range = layerToRange (lobj);  
     if (range[0] == range[1])  
322              return range[0];              return range[0];
323                    
324      int bottom = range[0];          int bottom = range[0];
325      int top = range[1] - 1;          int top = range[1] - 1;
326                    
327      if (position == -1 || position > (top - bottom))          if (position == -1 || position > (top - bottom))
328              return bottom;              return bottom;
329      else          else
330              return top - position;              return top - position;
331    }      }
   
   /**  
    * Removes a child from this container. The child is specified by  
    * internal index. After removal, the child no longer occupies a layer.  
    *  
    * @param index the internal index of the child component to remove.  
    */  
332            
333    public void remove (int index)      public void remove (int index)
334    {      {
335      Component c = getComponent (index);          Component c = getComponent (index);
336      Integer layer = getLayer (c);          Integer layer = getLayer (c);
337      decrLayer (layer);          decrLayer (layer);
338      componentToLayer.remove (c);          componentToLayer.remove (c);
339      super.remove (index);          super.remove (index);
340    }      }
   
   /**  
    * Removes a child from this container. The child is specified directly.  
    * After removal, the child no longer occupies a layer.  
    *  
    * @param comp the child to remove.  
    */  
341                    
342    public void remove (Component comp)      public void remove (Component comp)
343    {      {
344      remove (getInternalIndexOf (comp));          Integer layer = getLayer (comp);
345    }          decrLayer (layer);
346            componentToLayer.remove (comp);
347    /**          super.remove (comp);
348     * <p>Set the layer property for a component, within this container. The      }
349     * component will be implicitly mapped to the bottom-most position in the  
350     * layer, but only if added <em>after</em> calling this method.</p>      public void removeAll ()
351     *      {
352     * <p>Read that carefully: this method should be called <em>before</em> the          componentToLayer.clear ();
353     * component is added to the container.</p>          layers.clear ();
354     *          super.removeAll ();
355     * @param c the component to set the layer property for.      }
356     * @param layer the layer number to assign to the component.  
357     */      public void setLayer(Component c, int layer)
358        {
359    public void setLayer(Component c, int layer)          componentToLayer.put (c, getObjectForLayer (layer));
360    {      }
361      componentToLayer.put (c, getObjectForLayer (layer));  
362    }      public void setLayer(Component c,
363                             int layer,
364    /**                           int position)
365     * Set the layer and position of a component, within this container.      {
366     *          componentToLayer.put (c, getObjectForLayer (layer));
367     * @param c the child component to set the layer property for.          setPosition(c, position);
368     * @param layer the layer number to assign to the component.          repaint();
369     * @param position the position number to assign to the component.      }
370     */  
371        protected void addImpl(Component comp, Object layerConstraint, int index)
372    public void setLayer(Component c,      {          
373                         int layer,          Integer layer;
374                         int position)          if (layerConstraint != null && layerConstraint instanceof Integer)
375    {                  layer = (Integer) layerConstraint;
376      componentToLayer.put (c, getObjectForLayer (layer));          else if (componentToLayer.containsKey (comp))
     setPosition(c, position);  
     validate();  
     repaint();  
   }  
   
   /**  
    * Overrides the default implementation from {@link java.awt.Container}  
    * such that <code>layerConstraint</code> is interpreted as an {@link  
    * Integer}, specifying the layer to which the component will be added  
    * (at the bottom position).  
    *  
    * @param comp the component to add.  
    * @param layerConstraint an integer specifying the layer to add the component to.  
    * @param index an ignored parameter, for compatibility.  
    */  
   
   protected void addImpl(Component comp, Object layerConstraint, int index)  
   {              
     Integer layer;  
     if (layerConstraint != null && layerConstraint instanceof Integer)  
       layer = (Integer) layerConstraint;  
     else if (componentToLayer.containsKey (comp))  
377              layer = (Integer) componentToLayer.remove (comp);              layer = (Integer) componentToLayer.remove (comp);
378      else          else
379              layer = DEFAULT_LAYER;              layer = DEFAULT_LAYER;
380    
381      int newIdx = insertIndexForLayer(layer.intValue (), -1);          int newIdx = insertIndexForLayer(layer.intValue (), -1);
382      componentToLayer.put (comp, layer);          componentToLayer.put (comp, layer);
383      incrLayer (layer);          incrLayer (layer);
384    
385            // System.err.println("adding component to layer " + layer);
386                    
387      super.addImpl(comp, null, newIdx);            super.addImpl(comp, null, newIdx);      
388      validate();          validate();
389      repaint();          repaint();
390    }          }    
391  }  }

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26