2
* @(#)AbstractHelpAction.java 1.2 06/10/30
4
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
5
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7
* This code is free software; you can redistribute it and/or modify it
8
* under the terms of the GNU General Public License version 2 only, as
9
* published by the Free Software Foundation. Sun designates this
10
* particular file as subject to the "Classpath" exception as provided
11
* by Sun in the LICENSE file that accompanied this code.
13
* This code is distributed in the hope that it will be useful, but WITHOUT
14
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16
* version 2 for more details (a copy is included in the LICENSE file that
17
* accompanied this code).
19
* You should have received a copy of the GNU General Public License version
20
* 2 along with this work; if not, write to the Free Software Foundation,
21
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
23
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
24
* CA 95054 USA or visit www.sun.com if you need additional information or
30
import java.beans.PropertyChangeListener;
31
import java.beans.PropertyChangeSupport;
32
import java.util.Hashtable;
36
* @author Stepan Marek
37
* @version 1.2 10/30/06
39
public abstract class AbstractHelpAction implements HelpAction {
41
AbstractHelpAction(Object control, String name) {
42
this.control = control;
43
putValue("name", name);
46
/** Holds value of property enabled. */
47
private boolean enabled = true;
49
/** Holds value of property control. */
50
private Object control;
52
private Hashtable table;
54
/** Utility field used by bound properties. */
55
private PropertyChangeSupport propertyChangeSupport;;
57
/** Add a PropertyChangeListener to the listener list.
58
* @param l The listener to add.
60
public synchronized void addPropertyChangeListener(PropertyChangeListener l) {
61
if (propertyChangeSupport == null) {
62
propertyChangeSupport = new PropertyChangeSupport(this);
64
propertyChangeSupport.addPropertyChangeListener(l);
67
/** Removes a PropertyChangeListener from the listener list.
68
* @param l The listener to remove.
70
public synchronized void removePropertyChangeListener(PropertyChangeListener l) {
71
if (propertyChangeSupport == null) {
72
propertyChangeSupport = new PropertyChangeSupport(this);
74
propertyChangeSupport.removePropertyChangeListener(l);
78
* Supports reporting bound property changes. This method can be called
79
* when a bound property has changed and it will send the appropriate
80
* <code>PropertyChangeEvent</code> to any registered
81
* <code>PropertyChangeListeners</code>.
83
protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
84
if (propertyChangeSupport == null) {
87
propertyChangeSupport.firePropertyChange(propertyName, oldValue, newValue);
90
/** Getter for property enabled.
91
* @return Value of property enabled.
93
public boolean isEnabled() {
97
/** Setter for property enabled.
98
* @param enabled New value of property enabled.
100
public void setEnabled(boolean enabled) {
101
boolean oldEnabled = this.enabled;
102
this.enabled = enabled;
103
firePropertyChange("enabled", new Boolean(oldEnabled), new Boolean(enabled));
106
/** Getter for property control.
107
* @return Value of property control.
109
public Object getControl() {
114
* Gets the <code>Object</code> associated with the specified key.
116
* @param key a string containing the specified <code>key</code>
117
* @return the binding <code>Object</code> stored with this key; if there
118
* are no keys, it will return <code>null</code>
119
* @see Action#getValue
121
public Object getValue(String key) {
125
return table.get(key);
129
* Sets the <code>Value</code> associated with the specified key.
131
* @param key the <code>String</code> that identifies the stored object
132
* @param newValue the <code>Object</code> to store using this key
133
* @see Action#putValue
135
public void putValue(String key, Object newValue) {
137
table = new Hashtable();
140
if (newValue == null) {
141
oldValue = table.remove(key);
143
oldValue = table.put(key, newValue);
145
firePropertyChange(key, oldValue, newValue);