89 |
* <p><b>Note:</b> the layer numbering order is the <em>reverse</em> of the |
* <p><b>Note:</b> the layer numbering order is the <em>reverse</em> of the |
90 |
* component indexing and position order</p> |
* component indexing and position order</p> |
91 |
* |
* |
92 |
* @author Graydon Hoare <graydon@redhat.com> |
* @author Graydon Hoare (graydon@redhat.com) |
93 |
*/ |
*/ |
94 |
public class JLayeredPane extends JComponent implements Accessible |
public class JLayeredPane extends JComponent implements Accessible |
95 |
{ |
{ |
122 |
* @return the layer the component is currently assigned to, in this container. |
* @return the layer the component is currently assigned to, in this container. |
123 |
* @throws IllegalArgumentException if the component is not a child of this container. |
* @throws IllegalArgumentException if the component is not a child of this container. |
124 |
*/ |
*/ |
|
|
|
125 |
protected Integer getLayer (Component c) |
protected Integer getLayer (Component c) |
126 |
{ |
{ |
127 |
if (! componentToLayer.containsKey (c)) |
if (! componentToLayer.containsKey (c)) |
143 |
* @throws IllegalArgumentException if layer does not refer to an active layer |
* @throws IllegalArgumentException if layer does not refer to an active layer |
144 |
* in this container. |
* in this container. |
145 |
*/ |
*/ |
|
|
|
146 |
protected int[] layerToRange (Integer layer) |
protected int[] layerToRange (Integer layer) |
147 |
{ |
{ |
148 |
int[] ret = new int[2]; |
int[] ret = new int[2]; |
173 |
* @param layer the layer number to increment. |
* @param layer the layer number to increment. |
174 |
* @see #incrLayer() |
* @see #incrLayer() |
175 |
*/ |
*/ |
|
|
|
176 |
protected void incrLayer(Integer layer) |
protected void incrLayer(Integer layer) |
177 |
{ |
{ |
178 |
int sz = 1; |
int sz = 1; |
187 |
* @param layer the layer number to decrement. |
* @param layer the layer number to decrement. |
188 |
* @see #decrLayer() |
* @see #decrLayer() |
189 |
*/ |
*/ |
|
|
|
190 |
protected void decrLayer(Integer layer) |
protected void decrLayer(Integer layer) |
191 |
{ |
{ |
192 |
int sz = 0; |
int sz = 0; |
202 |
* @return the least layer number. |
* @return the least layer number. |
203 |
* @see #lowestLayer() |
* @see #lowestLayer() |
204 |
*/ |
*/ |
|
|
|
205 |
public int highestLayer() |
public int highestLayer() |
206 |
{ |
{ |
207 |
if (layers.size() == 0) |
if (layers.size() == 0) |
216 |
* @return the least layer number. |
* @return the least layer number. |
217 |
* @see #highestLayer() |
* @see #highestLayer() |
218 |
*/ |
*/ |
|
|
|
219 |
public int lowestLayer() |
public int lowestLayer() |
220 |
{ |
{ |
221 |
if (layers.size() == 0) |
if (layers.size() == 0) |
234 |
* this container. |
* this container. |
235 |
* @see #moveToBack() |
* @see #moveToBack() |
236 |
*/ |
*/ |
|
|
|
237 |
public void moveToFront(Component c) |
public void moveToFront(Component c) |
238 |
{ |
{ |
239 |
setPosition (c, 0); |
setPosition (c, 0); |
253 |
* this container. |
* this container. |
254 |
* @see #moveToFront() |
* @see #moveToFront() |
255 |
*/ |
*/ |
|
|
|
256 |
public void moveToBack(Component c) |
public void moveToBack(Component c) |
257 |
{ |
{ |
258 |
setPosition (c, -1); |
setPosition (c, -1); |
268 |
* this container. |
* this container. |
269 |
* @see #setPosition() |
* @see #setPosition() |
270 |
*/ |
*/ |
|
|
|
271 |
public int getPosition(Component c) |
public int getPosition(Component c) |
272 |
{ |
{ |
273 |
Integer layer = getLayer (c); |
Integer layer = getLayer (c); |
295 |
* this container. |
* this container. |
296 |
* @see #getPosition() |
* @see #getPosition() |
297 |
*/ |
*/ |
|
|
|
298 |
public void setPosition(Component c, int position) |
public void setPosition(Component c, int position) |
299 |
{ |
{ |
300 |
Integer layer = getLayer (c); |
Integer layer = getLayer (c); |
301 |
int[] range = layerToRange (layer); |
int[] range = layerToRange (layer); |
302 |
if (range[0] == range[1]) |
if (range[0] == range[1]) |
303 |
throw new IllegalArgumentException (); |
throw new IllegalArgumentException (); |
304 |
|
|
305 |
int top = range[0]; |
int top = range[0]; |
306 |
int bot = range[1]; |
int bot = range[1]; |
307 |
if (position == -1) |
if (position == -1) |
308 |
position = (bot - top) - 1; |
position = (bot - top) - 1; |
309 |
int targ = Math.min(top + position, bot-1); |
int targ = Math.min(top + position, bot-1); |
310 |
int curr = -1; |
int curr = -1; |
311 |
|
|
312 |
Component[] comps = getComponents(); |
Component[] comps = getComponents(); |
313 |
for (int i = top; i < bot; ++i) |
for (int i = top; i < bot; ++i) |
314 |
{ |
{ |
315 |
if (comps[i] == c) |
if (comps[i] == c) |
316 |
{ |
{ |
317 |
curr = i; |
curr = i; |
318 |
break; |
break; |
319 |
} |
} |
320 |
} |
} |
321 |
if (curr == -1) |
if (curr == -1) |
322 |
// should have found it |
// should have found it |
323 |
throw new IllegalArgumentException (); |
throw new IllegalArgumentException(); |
324 |
|
|
325 |
super.swapComponents (curr, targ); |
super.swapComponents (curr, targ); |
326 |
revalidate(); |
revalidate(); |
335 |
* @param layer the layer to return components from. |
* @param layer the layer to return components from. |
336 |
* @return the components in the layer. |
* @return the components in the layer. |
337 |
*/ |
*/ |
|
|
|
338 |
public Component[] getComponentsInLayer(int layer) |
public Component[] getComponentsInLayer(int layer) |
339 |
{ |
{ |
340 |
int[] range = layerToRange (getObjectForLayer (layer)); |
int[] range = layerToRange (getObjectForLayer (layer)); |
358 |
* @param layer the layer count components in. |
* @param layer the layer count components in. |
359 |
* @return the number of components in the layer. |
* @return the number of components in the layer. |
360 |
*/ |
*/ |
|
|
|
361 |
public int getComponentCountInLayer(int layer) |
public int getComponentCountInLayer(int layer) |
362 |
{ |
{ |
363 |
int[] range = layerToRange (getObjectForLayer (layer)); |
int[] range = layerToRange (getObjectForLayer (layer)); |
371 |
* Return a hashtable mapping child components of this container to |
* Return a hashtable mapping child components of this container to |
372 |
* Integer objects representing the component's layer assignments. |
* Integer objects representing the component's layer assignments. |
373 |
*/ |
*/ |
|
|
|
374 |
protected Hashtable getComponentToLayer() |
protected Hashtable getComponentToLayer() |
375 |
{ |
{ |
376 |
return componentToLayer; |
return componentToLayer; |
387 |
* @throws IllegalArgumentException if the component is not a child of |
* @throws IllegalArgumentException if the component is not a child of |
388 |
* this container. |
* this container. |
389 |
*/ |
*/ |
|
|
|
390 |
public int getIndexOf(Component c) |
public int getIndexOf(Component c) |
391 |
{ |
{ |
392 |
Integer layer = getLayer (c); |
Integer layer = getLayer (c); |
409 |
* @param layer the layer number as an int. |
* @param layer the layer number as an int. |
410 |
* @return the layer number as an Integer, possibly shared. |
* @return the layer number as an Integer, possibly shared. |
411 |
*/ |
*/ |
|
|
|
412 |
protected Integer getObjectForLayer(int layer) |
protected Integer getObjectForLayer(int layer) |
413 |
{ |
{ |
414 |
switch (layer) |
switch (layer) |
447 |
* @param position the position in the layer at which to insert a component. |
* @param position the position in the layer at which to insert a component. |
448 |
* @return the index at which to insert the component. |
* @return the index at which to insert the component. |
449 |
*/ |
*/ |
|
|
|
450 |
protected int insertIndexForLayer(int layer, int position) |
protected int insertIndexForLayer(int layer, int position) |
451 |
{ |
{ |
452 |
|
|
472 |
* |
* |
473 |
* @param index the index of the child component to remove. |
* @param index the index of the child component to remove. |
474 |
*/ |
*/ |
|
|
|
475 |
public void remove (int index) |
public void remove (int index) |
476 |
{ |
{ |
477 |
Component c = getComponent (index); |
Component c = getComponent (index); |
489 |
* |
* |
490 |
* @param comp the child to remove. |
* @param comp the child to remove. |
491 |
*/ |
*/ |
|
|
|
492 |
public void remove (Component comp) |
public void remove (Component comp) |
493 |
{ |
{ |
494 |
remove (getIndexOf (comp)); |
remove (getIndexOf (comp)); |
505 |
* @param c the component to set the layer property for. |
* @param c the component to set the layer property for. |
506 |
* @param layer the layer number to assign to the component. |
* @param layer the layer number to assign to the component. |
507 |
*/ |
*/ |
|
|
|
508 |
public void setLayer(Component c, int layer) |
public void setLayer(Component c, int layer) |
509 |
{ |
{ |
510 |
componentToLayer.put (c, getObjectForLayer (layer)); |
componentToLayer.put (c, getObjectForLayer (layer)); |
517 |
* @param layer the layer number to assign to the component. |
* @param layer the layer number to assign to the component. |
518 |
* @param position the position number to assign to the component. |
* @param position the position number to assign to the component. |
519 |
*/ |
*/ |
|
|
|
520 |
public void setLayer(Component c, |
public void setLayer(Component c, |
521 |
int layer, |
int layer, |
522 |
int position) |
int position) |
538 |
* @param layerConstraint an integer specifying the layer to add the component to. |
* @param layerConstraint an integer specifying the layer to add the component to. |
539 |
* @param index an ignored parameter, for compatibility. |
* @param index an ignored parameter, for compatibility. |
540 |
*/ |
*/ |
|
|
|
541 |
protected void addImpl(Component comp, Object layerConstraint, int index) |
protected void addImpl(Component comp, Object layerConstraint, int index) |
542 |
{ |
{ |
543 |
Integer layer; |
Integer layer; |