From 1bbaf04fa950d5a12d5bff609dca43588472531c Mon Sep 17 00:00:00 2001 From: ray Date: Wed, 10 Jul 2002 01:53:59 +0000 Subject: [PATCH] added SwingUtil.applyToHierarchy(Component c, SwingUtil.ComponentOp op) git-svn-id: https://samskivert.googlecode.com/svn/trunk@795 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../com/samskivert/swing/util/DialogUtil.java | 24 +++------- .../com/samskivert/swing/util/SwingUtil.java | 44 ++++++++++++++----- 2 files changed, 39 insertions(+), 29 deletions(-) diff --git a/projects/samskivert/src/java/com/samskivert/swing/util/DialogUtil.java b/projects/samskivert/src/java/com/samskivert/swing/util/DialogUtil.java index f1e6fde6..d2f1bed9 100644 --- a/projects/samskivert/src/java/com/samskivert/swing/util/DialogUtil.java +++ b/projects/samskivert/src/java/com/samskivert/swing/util/DialogUtil.java @@ -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(); - } - } } diff --git a/projects/samskivert/src/java/com/samskivert/swing/util/SwingUtil.java b/projects/samskivert/src/java/com/samskivert/swing/util/SwingUtil.java index 834de2ef..6e71c7c8 100644 --- a/projects/samskivert/src/java/com/samskivert/swing/util/SwingUtil.java +++ b/projects/samskivert/src/java/com/samskivert/swing/util/SwingUtil.java @@ -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); } /**