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 JFocusableComponentInspector<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  	private final JComponent target;
31  
32  	public JFocusableComponentInspector( T component, JComponent target, String title, String description,
33  			boolean enabled )
34  	{
35  		this.component = component;
36  		this.target = target;
37  		this.title = title;
38  		this.id = title;
39  		this.description = description;
40  		this.enabled = enabled;
41  	}
42  
43  	public void activate()
44  	{
45  		target.requestFocusInWindow();
46  	}
47  
48  	public void addPropertyChangeListener( PropertyChangeListener listener )
49  	{
50  		if( propertyChangeSupport == null )
51  			propertyChangeSupport = new PropertyChangeSupport( this );
52  
53  		propertyChangeSupport.addPropertyChangeListener( listener );
54  	}
55  
56  	public T getComponent()
57  	{
58  		return component;
59  	}
60  
61  	public String getDescription()
62  	{
63  		return description;
64  	}
65  
66  	public String getInspectorId()
67  	{
68  		return id;
69  	}
70  
71  	public String getTitle()
72  	{
73  		return title;
74  	}
75  
76  	public boolean isEnabled()
77  	{
78  		return enabled;
79  	}
80  
81  	public void release()
82  	{
83  	}
84  
85  	public void setDescription( String description )
86  	{
87  		String old = this.description;
88  		this.description = description;
89  
90  		if( propertyChangeSupport != null )
91  			propertyChangeSupport.firePropertyChange( Inspector.DESCRIPTION_PROPERTY, old, description );
92  	}
93  
94  	public void setEnabled( boolean enabled )
95  	{
96  		if( enabled == this.enabled )
97  			return;
98  
99  		this.enabled = enabled;
100 		if( propertyChangeSupport != null )
101 			propertyChangeSupport.firePropertyChange( Inspector.ENABLED_PROPERTY, !enabled, enabled );
102 	}
103 
104 	public void setTitle( String title )
105 	{
106 		String old = this.title;
107 		this.title = title;
108 
109 		if( propertyChangeSupport != null )
110 			propertyChangeSupport.firePropertyChange( Inspector.TITLE_PROPERTY, old, title );
111 	}
112 
113 	public void removePropertyChangeListener( PropertyChangeListener listener )
114 	{
115 		if( propertyChangeSupport != null )
116 			propertyChangeSupport.removePropertyChangeListener( listener );
117 	}
118 
119 	public ImageIcon getIcon()
120 	{
121 		return imageIcon;
122 	}
123 
124 	public void setIcon( ImageIcon imageIcon )
125 	{
126 		ImageIcon old = this.imageIcon;
127 
128 		this.imageIcon = imageIcon;
129 		if( propertyChangeSupport != null )
130 			propertyChangeSupport.firePropertyChange( Inspector.ICON_PROPERTY, old, imageIcon );
131 	}
132 
133 	public void deactivate()
134 	{
135 	}
136 }