import java.awt.Component;
import java.util.HashMap;
import java.util.Map.Entry;
import javax.swing.JComboBox;
import javax.swing.JComponent;
public class GuiFreezer {
private JComponent component = null;
private HashMap<JComponent, Boolean> stateHolder = null;
public GuiFreezer(JComponent component) {
this.component = component;
this.stateHolder = new HashMap<JComponent, Boolean>();
}
public void freeze() {
_freezeRec(component);
}
public void unFreeze() {
for (Entry<JComponent, Boolean> e : stateHolder.entrySet()) {
JComponent c = e.getKey();
c.setEnabled(e.getValue());
}
}
private void _freezeRec(JComponent c) {
if (c instanceof JComboBox || c.getComponentCount() == 0) {
boolean state = c.isEnabled();
c.setEnabled(false);
stateHolder.put(c, state);
} else {
Component[] children = c.getComponents();
for (Component child : children) {
_freezeRec((JComponent) child);
}
}
}
}