~vcs-imports/xena/trunk

« back to all changes in this revision

Viewing changes to ext/src/javahelp/jhMaster/JavaHelp/src/new/javax/help/.svn/text-base/AbstractHelpAction.java.svn-base

  • Committer: matthewoliver
  • Date: 2009-12-10 03:18:07 UTC
  • Revision ID: vcs-imports@canonical.com-20091210031807-l086qguzdlljtkl9
Merged Xena Testing into Xena Stable for the Xena 5 release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * @(#)AbstractHelpAction.java  1.2 06/10/30
 
3
 * 
 
4
 * Copyright (c) 2006 Sun Microsystems, Inc.  All Rights Reserved.
 
5
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 
6
 * 
 
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.
 
12
 * 
 
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).
 
18
 * 
 
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.
 
22
 * 
 
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
 
25
 * have any questions.
 
26
 */
 
27
 
 
28
package javax.help;
 
29
 
 
30
import java.beans.PropertyChangeListener;
 
31
import java.beans.PropertyChangeSupport;
 
32
import java.util.Hashtable;
 
33
 
 
34
/**
 
35
 *
 
36
 * @author Stepan Marek
 
37
 * @version     1.2     10/30/06
 
38
 */
 
39
public abstract class AbstractHelpAction implements HelpAction {
 
40
        
 
41
    AbstractHelpAction(Object control, String name) {
 
42
        this.control = control;
 
43
        putValue("name", name);
 
44
    }
 
45
    
 
46
    /** Holds value of property enabled. */
 
47
    private boolean enabled = true;
 
48
    
 
49
    /** Holds value of property control. */
 
50
    private Object control;
 
51
    
 
52
    private Hashtable table;
 
53
    
 
54
    /** Utility field used by bound properties. */
 
55
    private PropertyChangeSupport propertyChangeSupport;;
 
56
    
 
57
    /** Add a PropertyChangeListener to the listener list.
 
58
     * @param l The listener to add.
 
59
     */
 
60
    public synchronized void addPropertyChangeListener(PropertyChangeListener l) {
 
61
        if (propertyChangeSupport == null) {
 
62
            propertyChangeSupport =  new PropertyChangeSupport(this);
 
63
        }
 
64
        propertyChangeSupport.addPropertyChangeListener(l);
 
65
    }
 
66
    
 
67
    /** Removes a PropertyChangeListener from the listener list.
 
68
     * @param l The listener to remove.
 
69
     */
 
70
    public synchronized void removePropertyChangeListener(PropertyChangeListener l) {
 
71
        if (propertyChangeSupport == null) {
 
72
            propertyChangeSupport =  new PropertyChangeSupport(this);
 
73
        }
 
74
        propertyChangeSupport.removePropertyChangeListener(l);
 
75
    }
 
76
 
 
77
    /**
 
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>.
 
82
     */
 
83
    protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
 
84
        if (propertyChangeSupport == null) {
 
85
            return;
 
86
        }
 
87
        propertyChangeSupport.firePropertyChange(propertyName, oldValue, newValue);
 
88
    }
 
89
    
 
90
    /** Getter for property enabled.
 
91
     * @return Value of property enabled.
 
92
     */
 
93
    public boolean isEnabled() {
 
94
        return enabled;
 
95
    }
 
96
    
 
97
    /** Setter for property enabled.
 
98
     * @param enabled New value of property enabled.
 
99
     */
 
100
    public void setEnabled(boolean enabled) {
 
101
        boolean oldEnabled = this.enabled;
 
102
        this.enabled = enabled;
 
103
        firePropertyChange("enabled", new Boolean(oldEnabled), new Boolean(enabled));
 
104
    }
 
105
    
 
106
    /** Getter for property control.
 
107
     * @return Value of property control.
 
108
     */
 
109
    public Object getControl() {
 
110
        return control;
 
111
    }
 
112
 
 
113
    /** 
 
114
     * Gets the <code>Object</code> associated with the specified key.
 
115
     *
 
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
 
120
     */
 
121
    public Object getValue(String key) {
 
122
        if (table == null) {
 
123
            return null;
 
124
        }
 
125
        return table.get(key);
 
126
    }
 
127
    
 
128
    /** 
 
129
     * Sets the <code>Value</code> associated with the specified key.
 
130
     *
 
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 
 
134
     */
 
135
    public void putValue(String key, Object newValue) {
 
136
        if (table == null) {
 
137
            table = new Hashtable();
 
138
        }
 
139
        Object oldValue;
 
140
        if (newValue == null) {
 
141
            oldValue = table.remove(key);
 
142
        } else {
 
143
            oldValue = table.put(key, newValue);
 
144
        }
 
145
        firePropertyChange(key, oldValue, newValue);
 
146
    }
 
147
 
 
148
}