2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
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]"
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.
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.
42
package org.netbeans.spi.debugger;
44
import java.util.HashSet;
45
import java.util.Vector;
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.
55
public abstract class ActionsProviderSupport extends ActionsProvider {
57
private HashSet enabled = new HashSet ();
58
private Vector listeners = new Vector ();
62
* Called when the action is called (action button is pressed).
64
* @param action an action which has been called
66
public abstract void doAction (Object action);
69
* Returns a state of given action defined by {@link #setEnabled}
72
* Do not override. Should be final - the enabled state is cached,
73
* therefore this method is not consulted unless the state change
76
* @param action action
78
public boolean isEnabled (Object action) {
79
return enabled.contains (action);
83
* Sets state of enabled property.
85
* @param action action whose state should be changed
86
* @param enabled the new state
88
protected final void setEnabled (Object action, boolean enabled) {
91
fire = this.enabled.add (action);
93
fire = this.enabled.remove (action);
95
fireActionStateChanged (action, enabled);
99
* Fires a change of action state.
101
* @param action action whose state has been changed
102
* @param enabled the new state
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 (
114
* Adds property change listener.
116
* @param l new listener.
118
public final void addActionsProviderListener (ActionsProviderListener l) {
119
listeners.addElement (l);
123
* Removes property change listener.
125
* @param l removed listener.
127
public final void removeActionsProviderListener (ActionsProviderListener l) {
128
listeners.removeElement (l);