View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2009 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.components;
14  
15  import java.beans.PropertyChangeListener;
16  import java.beans.PropertyChangeSupport;
17  
18  import javax.swing.ImageIcon;
19  import javax.swing.JComponent;
20  
21  public class JComponentInspector<T extends JComponent> implements Inspector
22  {
23  	private final T component;
24  	private String title;
25  	private String description;
26  	private boolean enabled;
27  	private PropertyChangeSupport propertyChangeSupport;
28  	private ImageIcon imageIcon;
29  	private String id;
30  
31  	public JComponentInspector( T component, String title, String description, boolean enabled )
32  	{
33  		this.component = component;
34  		this.title = title;
35  		this.id = title;
36  		this.description = description;
37  		this.enabled = enabled;
38  	}
39  
40  	public void activate()
41  	{
42  	}
43  
44  	public void addPropertyChangeListener( PropertyChangeListener listener )
45  	{
46  		if( propertyChangeSupport == null )
47  			propertyChangeSupport = new PropertyChangeSupport( this );
48  
49  		propertyChangeSupport.addPropertyChangeListener( listener );
50  	}
51  
52  	public T getComponent()
53  	{
54  		return component;
55  	}
56  
57  	public String getDescription()
58  	{
59  		return description;
60  	}
61  
62  	public String getInspectorId()
63  	{
64  		return id;
65  	}
66  
67  	public String getTitle()
68  	{
69  		return title;
70  	}
71  
72  	public boolean isEnabled()
73  	{
74  		return enabled;
75  	}
76  
77  	public void release()
78  	{
79  	}
80  
81  	public void setDescription( String description )
82  	{
83  		String old = this.description;
84  		this.description = description;
85  
86  		if( propertyChangeSupport != null )
87  			propertyChangeSupport.firePropertyChange( Inspector.DESCRIPTION_PROPERTY, old, description );
88  	}
89  
90  	public void setEnabled( boolean enabled )
91  	{
92  		if( enabled == this.enabled )
93  			return;
94  
95  		this.enabled = enabled;
96  		if( propertyChangeSupport != null )
97  			propertyChangeSupport.firePropertyChange( Inspector.ENABLED_PROPERTY, !enabled, enabled );
98  	}
99  
100 	public void setTitle( String title )
101 	{
102 		String old = this.title;
103 		this.title = title;
104 
105 		if( propertyChangeSupport != null )
106 			propertyChangeSupport.firePropertyChange( Inspector.TITLE_PROPERTY, old, title );
107 	}
108 
109 	public void removePropertyChangeListener( PropertyChangeListener listener )
110 	{
111 		if( propertyChangeSupport != null )
112 			propertyChangeSupport.removePropertyChangeListener( listener );
113 	}
114 
115 	public ImageIcon getIcon()
116 	{
117 		return imageIcon;
118 	}
119 
120 	public void setIcon( ImageIcon imageIcon )
121 	{
122 		ImageIcon old = this.imageIcon;
123 
124 		this.imageIcon = imageIcon;
125 		if( propertyChangeSupport != null )
126 			propertyChangeSupport.firePropertyChange( Inspector.ICON_PROPERTY, old, imageIcon );
127 	}
128 
129 	public void deactivate()
130 	{
131 	}
132 }