View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2008 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by 
6    *  the Free Software Foundation.
7    *
8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  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  {
29  	private Map<String,JComponent> components = new HashMap<String,JComponent>();
30  	
31  	public ComponentBag()
32  	{
33  	}
34  	
35  	public void add( JComponent component )
36  	{
37  		components.put( String.valueOf( component.hashCode() ), component );
38  	}
39  
40  	public void add( String name, JComponent component )
41  	{
42  		components.put( name, component );
43  	}
44  	
45  	public JComponent get( String name )
46  	{
47  		return components.get( name );
48  	}
49  	
50  	public void setEnabled( boolean enabled )
51  	{
52  		Iterator<JComponent> iterator = components.values().iterator();
53  		while( iterator.hasNext() )
54  		{
55  			iterator.next().setEnabled( enabled );
56  		}
57  	}
58  	
59  	public void setEnabled( boolean enabled, String name )
60  	{
61  		if( components.containsKey( name ))
62  			components.get( name ).setEnabled( enabled );
63  	}
64  	
65  	public void setEnabled( boolean enabled, String [] names )
66  	{
67  		for( int c = 0; c < names.length; c++ )
68  			setEnabled( enabled, names[c] );
69  	}
70  }