View Javadoc

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