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:
@@ -273,17 +273,27 @@ public class SwingUtil
|
|||||||
* and then all its descendants.
|
* and then all its descendants.
|
||||||
*/
|
*/
|
||||||
public static void applyToHierarchy (Component comp, ComponentOp op)
|
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) {
|
if (comp == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
op.apply(comp);
|
op.apply(comp);
|
||||||
if (comp instanceof Container) {
|
if (comp instanceof Container && --depth >= 0) {
|
||||||
Container c = (Container) comp;
|
Container c = (Container) comp;
|
||||||
int ccount = c.getComponentCount();
|
int ccount = c.getComponentCount();
|
||||||
for (int ii = 0; ii < ccount; ii++) {
|
for (int ii = 0; ii < ccount; ii++) {
|
||||||
applyToHierarchy(c.getComponent(ii), op);
|
applyToHierarchy(c.getComponent(ii), depth, op);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user