~ubuntu-branches/ubuntu/quantal/netbeans/quantal

« back to all changes in this revision

Viewing changes to debuggercore/api/src/org/netbeans/spi/debugger/ActionsProviderSupport.java

  • Committer: Bazaar Package Importer
  • Author(s): Marek Slama
  • Date: 2008-01-29 14:11:22 UTC
  • Revision ID: james.westby@ubuntu.com-20080129141122-fnzjbo11ntghxfu7
Tags: upstream-6.0.1
ImportĀ upstreamĀ versionĀ 6.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
3
 *
 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
 
5
 *
 
6
 * The contents of this file are subject to the terms of either the GNU
 
7
 * General Public License Version 2 only ("GPL") or the Common
 
8
 * Development and Distribution License("CDDL") (collectively, the
 
9
 * "License"). You may not use this file except in compliance with the
 
10
 * License. You can obtain a copy of the License at
 
11
 * http://www.netbeans.org/cddl-gplv2.html
 
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
 
13
 * specific language governing permissions and limitations under the
 
14
 * License.  When distributing the software, include this License Header
 
15
 * Notice in each file and include the License file at
 
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
 
17
 * particular file as subject to the "Classpath" exception as provided
 
18
 * by Sun in the GPL Version 2 section of the License file that
 
19
 * accompanied this code. If applicable, add the following below the
 
20
 * License Header, with the fields enclosed by brackets [] replaced by
 
21
 * your own identifying information:
 
22
 * "Portions Copyrighted [year] [name of copyright owner]"
 
23
 *
 
24
 * Contributor(s):
 
25
 *
 
26
 * The Original Software is NetBeans. The Initial Developer of the Original
 
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
 
28
 * Microsystems, Inc. All Rights Reserved.
 
29
 *
 
30
 * If you wish your version of this file to be governed by only the CDDL
 
31
 * or only the GPL Version 2, indicate your decision by adding
 
32
 * "[Contributor] elects to include this software in this distribution
 
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
 
34
 * single choice of license, a recipient has the option to distribute
 
35
 * your version of this file under either the CDDL, the GPL Version 2 or
 
36
 * to extend the choice of license to its licensees as provided above.
 
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
 
38
 * Version 2 license, then the option applies only if the new code is
 
39
 * made subject to such option by the copyright holder.
 
40
 */
 
41
 
 
42
package org.netbeans.spi.debugger;
 
43
 
 
44
import java.util.HashSet;
 
45
import java.util.Vector;
 
46
 
 
47
 
 
48
/**
 
49
 * Support for {@link ActionsProvider} implementation. You should implement
 
50
 * {@link #doAction} and {@link #getActions} only, and call {@link #setEnabled}
 
51
 * when the action state is changed.
 
52
 *
 
53
 * @author   Jan Jancura
 
54
 */
 
55
public abstract class ActionsProviderSupport extends ActionsProvider {
 
56
 
 
57
    private HashSet enabled = new HashSet ();
 
58
    private Vector listeners = new Vector ();
 
59
 
 
60
 
 
61
    /**
 
62
     * Called when the action is called (action button is pressed).
 
63
     *
 
64
     * @param action an action which has been called
 
65
     */
 
66
    public abstract void doAction (Object action);
 
67
    
 
68
    /**
 
69
     * Returns a state of given action defined by {@link #setEnabled} 
 
70
     * method call.
 
71
     *
 
72
     * Do not override. Should be final - the enabled state is cached,
 
73
     * therefore this method is not consulted unless the state change
 
74
     * is fired.
 
75
     *
 
76
     * @param action action
 
77
     */
 
78
    public boolean isEnabled (Object action) {
 
79
        return enabled.contains (action);
 
80
    }
 
81
    
 
82
    /**
 
83
     * Sets state of enabled property.
 
84
     *
 
85
     * @param action action whose state should be changed
 
86
     * @param enabled the new state
 
87
     */
 
88
    protected final void setEnabled (Object action, boolean enabled) {
 
89
        boolean fire = false;
 
90
        if (enabled)
 
91
            fire = this.enabled.add (action);
 
92
        else
 
93
            fire = this.enabled.remove (action);
 
94
        if (fire)
 
95
            fireActionStateChanged (action, enabled);
 
96
    }
 
97
    
 
98
    /**
 
99
     * Fires a change of action state.
 
100
     *
 
101
     * @param action action whose state has been changed
 
102
     * @param enabled the new state
 
103
     */
 
104
    protected void fireActionStateChanged (Object action, boolean enabled) {
 
105
        Vector v = (Vector) listeners.clone ();
 
106
        int i, k = v.size ();
 
107
        for (i = 0; i < k; i++)
 
108
            ((ActionsProviderListener) v.elementAt (i)).actionStateChange (
 
109
                action, enabled
 
110
            );
 
111
    }
 
112
    
 
113
    /**
 
114
     * Adds property change listener.
 
115
     *
 
116
     * @param l new listener.
 
117
     */
 
118
    public final void addActionsProviderListener (ActionsProviderListener l) {
 
119
        listeners.addElement (l);
 
120
    }
 
121
    
 
122
    /**
 
123
     * Removes property change listener.
 
124
     *
 
125
     * @param l removed listener.
 
126
     */
 
127
    public final void removeActionsProviderListener (ActionsProviderListener l) {
 
128
        listeners.removeElement (l);
 
129
    }
 
130
}
 
131