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