Allow applyToHierarchy() to be depth limited.

git-svn-id: https://samskivert.googlecode.com/svn/trunk@1635 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
mdb
2005-04-18 02:57:56 +00:00
parent 8c1111ddc4
commit 422f80bac1
@@ -273,17 +273,27 @@ public class SwingUtil
* and then all its descendants.
*/
public static void applyToHierarchy (Component comp, ComponentOp op)
{
applyToHierarchy(comp, Integer.MAX_VALUE, op);
}
/**
* Apply the specified ComponentOp to the supplied component
* and then all its descendants, up to the specified maximum depth.
*/
public static void applyToHierarchy (
Component comp, int depth, ComponentOp op)
{
if (comp == null) {
return;
}
op.apply(comp);
if (comp instanceof Container) {
if (comp instanceof Container && --depth >= 0) {
Container c = (Container) comp;
int ccount = c.getComponentCount();
for (int ii = 0; ii < ccount; ii++) {
applyToHierarchy(c.getComponent(ii), op);
applyToHierarchy(c.getComponent(ii), depth, op);
}
}
}