added SwingUtil.applyToHierarchy(Component c, SwingUtil.ComponentOp op)

git-svn-id: https://samskivert.googlecode.com/svn/trunk@795 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
ray
2002-07-10 01:53:59 +00:00
parent 0dcefaa993
commit 1bbaf04fa9
2 changed files with 39 additions and 29 deletions
@@ -1,5 +1,5 @@
//
// $Id: DialogUtil.java,v 1.1 2002/07/09 17:48:13 ray Exp $
// $Id: DialogUtil.java,v 1.2 2002/07/10 01:53:59 ray Exp $
package com.samskivert.swing.util;
@@ -60,23 +60,13 @@ public class DialogUtil
public static void invalidateDialog (Component any)
{
JInternalDialog dialog = getInternalDialog(any);
invalidateChildren(dialog);
SwingUtil.applyToHierarchy(dialog, new SwingUtil.ComponentOp() {
public void apply (Component comp)
{
comp.invalidate();
}
});
dialog.resize(dialog.getPreferredSize());
}
/**
* Invalidate all the children of the specified container.
*/
protected static void invalidateChildren (Container c)
{
int numkids = c.getComponentCount();
for (int ii=0; ii < numkids; ii++) {
Component child = c.getComponent(ii);
if (child instanceof Container) {
invalidateChildren((Container) child);
}
child.invalidate();
}
}
}
@@ -1,5 +1,5 @@
//
// $Id: SwingUtil.java,v 1.10 2002/06/14 07:55:11 shaper Exp $
// $Id: SwingUtil.java,v 1.11 2002/07/10 01:53:59 ray Exp $
//
// samskivert library - useful routines for java programs
// Copyright (C) 2001 Michael Bayne
@@ -142,21 +142,41 @@ public class SwingUtil
* component, which is senseless in our opinion, but was surely done
* for some arguably good reason.
*/
public static void setEnabled (Container comp, boolean enabled)
public static void setEnabled (Container comp, final boolean enabled)
{
// set the state of our children
int ccount = comp.getComponentCount();
for (int i = 0; i < ccount; i++) {
Component child = comp.getComponent(i);
if (child instanceof Container) {
setEnabled((Container)child, enabled);
} else {
child.setEnabled(enabled);
applyToHierarchy(comp, new ComponentOp() {
public void apply (Component comp)
{
comp.setEnabled(enabled);
}
});
}
/**
* Apply the specified ComponentOp to the supplied component
* and then all its descendants.
*/
public static void applyToHierarchy (Component comp, ComponentOp op)
{
op.apply(comp);
if (comp instanceof Container) {
Container c = (Container) comp;
int ccount = c.getComponentCount();
for (int ii=0; ii < ccount; ii++) {
applyToHierarchy(c.getComponent(ii), op);
}
}
}
// set our state
comp.setEnabled(enabled);
/**
* An operation that may be applied to a component.
*/
public static interface ComponentOp
{
/**
* Apply an operation to the given component.
*/
public void apply (Component comp);
}
/**