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