01: /*
02: * soapUI, copyright (C) 2004-2007 eviware.com
03: *
04: * soapUI is free software; you can redistribute it and/or modify it under the
05: * terms of version 2.1 of the GNU Lesser General Public License as published by
06: * the Free Software Foundation.
07: *
08: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
09: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10: * See the GNU Lesser General Public License for more details at gnu.org.
11: */
12:
13: package com.eviware.soapui.support.swing;
14:
15: import java.util.HashMap;
16: import java.util.Iterator;
17: import java.util.Map;
18:
19: import javax.swing.JComponent;
20:
21: /**
22: * Utility for working with collections of components
23: *
24: * @author Ole.Matzura
25: */
26:
27: public class ComponentBag {
28: private Map<String, JComponent> components = new HashMap<String, JComponent>();
29:
30: public ComponentBag() {
31: }
32:
33: public void add(JComponent component) {
34: components.put(String.valueOf(component.hashCode()), component);
35: }
36:
37: public void add(String name, JComponent component) {
38: components.put(name, component);
39: }
40:
41: public JComponent get(String name) {
42: return components.get(name);
43: }
44:
45: public void setEnabled(boolean enabled) {
46: Iterator<JComponent> iterator = components.values().iterator();
47: while (iterator.hasNext()) {
48: iterator.next().setEnabled(enabled);
49: }
50: }
51:
52: public void setEnabled(boolean enabled, String name) {
53: if (components.containsKey(name))
54: components.get(name).setEnabled(enabled);
55: }
56:
57: public void setEnabled(boolean enabled, String[] names) {
58: for (int c = 0; c < names.length; c++)
59: setEnabled(enabled, names[c]);
60: }
61: }
|