summaryrefslogtreecommitdiffstats
path: root/libjava/classpath/javax/swing/JLayeredPane.java
diff options
context:
space:
mode:
authormark <mark@138bc75d-0d04-0410-961f-82ee72b054a4>2006-08-14 23:12:35 +0000
committermark <mark@138bc75d-0d04-0410-961f-82ee72b054a4>2006-08-14 23:12:35 +0000
commitffde862e033a0825e1e9972a89c0f1f80b261a8e (patch)
tree97037d2c09c8384d80531f67ec36a01205df6bdb /libjava/classpath/javax/swing/JLayeredPane.java
parentb415ff10527e977c3758234fd930e2c027bfa17d (diff)
downloadppe42-gcc-ffde862e033a0825e1e9972a89c0f1f80b261a8e.tar.gz
ppe42-gcc-ffde862e033a0825e1e9972a89c0f1f80b261a8e.zip
2006-08-14 Mark Wielaard <mark@klomp.org>
Imported GNU Classpath 0.92 * HACKING: Add more importing hints. Update automake version requirement. * configure.ac (gconf-peer): New enable AC argument. Add --disable-gconf-peer and --enable-default-preferences-peer to classpath configure when gconf is disabled. * scripts/makemake.tcl: Set gnu/java/util/prefs/gconf and gnu/java/awt/dnd/peer/gtk to bc. Classify gnu/java/security/Configuration.java as generated source file. * gnu/java/lang/management/VMGarbageCollectorMXBeanImpl.java, gnu/java/lang/management/VMMemoryPoolMXBeanImpl.java, gnu/java/lang/management/VMClassLoadingMXBeanImpl.java, gnu/java/lang/management/VMRuntimeMXBeanImpl.java, gnu/java/lang/management/VMMemoryManagerMXBeanImpl.java, gnu/java/lang/management/VMThreadMXBeanImpl.java, gnu/java/lang/management/VMMemoryMXBeanImpl.java, gnu/java/lang/management/VMCompilationMXBeanImpl.java: New VM stub classes. * java/lang/management/VMManagementFactory.java: Likewise. * java/net/VMURLConnection.java: Likewise. * gnu/java/nio/VMChannel.java: Likewise. * java/lang/Thread.java (getState): Add stub implementation. * java/lang/Class.java (isEnum): Likewise. * java/lang/Class.h (isEnum): Likewise. * gnu/awt/xlib/XToolkit.java (getClasspathTextLayoutPeer): Removed. * javax/naming/spi/NamingManager.java: New override for StackWalker functionality. * configure, sources.am, Makefile.in, gcj/Makefile.in, include/Makefile.in, testsuite/Makefile.in: Regenerated. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@116139 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/classpath/javax/swing/JLayeredPane.java')
-rw-r--r--libjava/classpath/javax/swing/JLayeredPane.java145
1 files changed, 105 insertions, 40 deletions
diff --git a/libjava/classpath/javax/swing/JLayeredPane.java b/libjava/classpath/javax/swing/JLayeredPane.java
index 11650e721d0..ca913e97fed 100644
--- a/libjava/classpath/javax/swing/JLayeredPane.java
+++ b/libjava/classpath/javax/swing/JLayeredPane.java
@@ -43,6 +43,7 @@ import java.awt.Component;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Rectangle;
+import java.util.ArrayList;
import java.util.Hashtable;
import javax.accessibility.Accessible;
@@ -326,13 +327,13 @@ public class JLayeredPane extends JComponent implements Accessible
{
int pos = -1;
int index = getIndexOf(c);
- Component[] components = getComponents();
- int layer = getLayer(c);
if (index >= 0)
{
- for (int i = index; i >= 0; --i)
+ pos = 0;
+ int layer = getLayer(c);
+ for (int i = index - 1; i >= 0; --i)
{
- if (layer == getLayer(components[i]))
+ if (layer == getLayer(getComponent(i)))
pos++;
else
break;
@@ -353,9 +354,7 @@ public class JLayeredPane extends JComponent implements Accessible
*/
public void setPosition(Component c, int position)
{
- int layer = getLayer(c);
- int index = insertIndexForLayer(layer, position);
- setComponentZOrder(c, index);
+ setLayer(c, getLayer(c), position);
}
/**
@@ -478,34 +477,85 @@ public class JLayeredPane extends JComponent implements Accessible
*/
protected int insertIndexForLayer(int layer, int position)
{
- // position < 0 means insert at greatest position within layer.
- if (position < 0)
- position = Integer.MAX_VALUE;
+ return insertIndexForLayer(null, layer, position);
+ }
- Component[] components = getComponents();
- int index = 0;
+ /**
+ * Similar to {@link #insertIndexForLayer(int, int)}, only that it takes a
+ * component parameter, which should be ignored in the search. This is
+ * necessary to support {@link #setLayer(Component, int, int)} which uses
+ * Container.setComponentZOrder(), which doesn't remove the component.
+ *
+ * @param comp the component to ignore
+ * @param layer the layer
+ * @param position the position
+ *
+ * @return the insertion index
+ */
+ private int insertIndexForLayer(Component comp, int layer, int position)
+ {
+ // Create the component list to search through.
+ ArrayList l = new ArrayList();
+ int count = getComponentCount();
+ for (int i = 0; i < count; i++)
+ {
+ Component c = getComponent(i);
+ if (c != comp)
+ l.add(c);
+ }
- // Try to find the start index of the specified layer.
- int p = -1;
- for (int i = 0; i < components.length; i++)
+ count = l.size();
+ int layerStart = -1;
+ int layerEnd = -1;
+ for (int i = 0; i < count; i++)
{
- int l = getLayer(components[i]);
- if (l > layer)
- index++;
- // If we are in the layer we look for, try to find the position.
- else if (l == layer)
+ int layerOfComponent = getLayer((Component) l.get(i));
+ if (layerStart == -1 && layerOfComponent == layer)
+ layerStart = i;
+ if (layerOfComponent < layer)
{
- p++;
- if (p < position)
- index++;
+ // We are beyond the layer that we are looking for. Update the
+ // layerStart and layerEnd and exit the loop.
+ if (i == 0)
+ {
+ layerStart = 0;
+ layerEnd = 0;
+ }
else
- break;
+ layerEnd = i;
+ break;
}
- // No need to look further if the layer at i is smaller than layer.
+ }
+
+ // No layer found. The requested layer is lower than any existing layer,
+ // put the component at the end.
+ int insertIndex;
+ if (layerStart == -1 && layerEnd == -1)
+ {
+ insertIndex = count;
+ }
+ else
+ {
+ // Corner cases.
+ if (layerStart != -1 && layerEnd == -1)
+ layerEnd = count;
+ if (layerStart == -1 && layerEnd != -1)
+ layerStart = layerEnd;
+
+ // Adding to the bottom of a layer returns the end index
+ // in the layer.
+ if (position == -1)
+ insertIndex = layerEnd;
else
- break;
+ {
+ // Insert into a layer.
+ if (position > -1 && layerStart + position <= layerEnd)
+ insertIndex = layerStart + position;
+ else
+ insertIndex = layerEnd;
+ }
}
- return index;
+ return insertIndex;
}
/**
@@ -559,17 +609,29 @@ public class JLayeredPane extends JComponent implements Accessible
public void setLayer(Component c, int layer, int position)
{
Integer layerObj = getObjectForLayer(layer);
- if (c instanceof JComponent)
+
+ // Nothing to do if neither the layer nor the position is
+ // changed.
+ if (layer != getLayer(c) || position != getPosition(c))
{
- JComponent jc = (JComponent) c;
- jc.putClientProperty(LAYER_PROPERTY, layerObj);
- }
- else
- componentToLayer.put (c, layerObj);
+ // Store the layer either in the JComponent or in the hashtable
+ if (c instanceof JComponent)
+ {
+ JComponent jc = (JComponent) c;
+ jc.putClientProperty(LAYER_PROPERTY, layerObj);
+ }
+ else
+ componentToLayer.put (c, layerObj);
- // Set position only of component is already added to this layered pane.
- if (getIndexOf(c) != -1)
- setPosition(c, position);
+ // Update the component in the Z order of the Container.
+ Container parent = c.getParent();
+ if (parent == this)
+ {
+ int index = insertIndexForLayer(c, layer, position);
+ setComponentZOrder(c, index);
+ }
+ }
+ repaint(c.getX(), c.getY(), c.getWidth(), c.getHeight());
}
/**
@@ -592,14 +654,17 @@ public class JLayeredPane extends JComponent implements Accessible
{
int layer;
if (layerConstraint != null && layerConstraint instanceof Integer)
- layer = ((Integer) layerConstraint).intValue();
+ {
+ layer = ((Integer) layerConstraint).intValue();
+ setLayer(comp, layer);
+ }
else
- layer = getLayer(comp);
+ layer = getLayer(comp);
int newIdx = insertIndexForLayer(layer, index);
- setLayer(comp, layer);
super.addImpl(comp, layerConstraint, newIdx);
- repaint(comp.getX(), comp.getY(), comp.getWidth(), comp.getHeight());
+ comp.validate();
+ comp.repaint();
}
/**
OpenPOWER on IntegriCloud