KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > actions > ActionManager


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.openide.actions;
20
21 import org.openide.util.Lookup;
22 import org.openide.util.actions.SystemAction;
23
24 import java.awt.event.ActionEvent JavaDoc;
25
26 import java.beans.*;
27
28 import javax.swing.Action JavaDoc;
29
30
31 /** Collects access methods to implementation depended functionality
32 * for actions package.
33 *
34 * @author Jaroslav Tulach, Jesse Glick
35 */

36 public abstract class ActionManager extends Object JavaDoc {
37     /** name of property that is fired when set of context actions
38     * changes.
39     */

40     public static final String JavaDoc PROP_CONTEXT_ACTIONS = "contextActions"; // NOI18N
41

42     /** Utility field used by event firing mechanism. */
43     private PropertyChangeSupport supp = null;
44
45     /**
46      * Get the default action manager from lookup.
47      * @return some default instance
48      * @since 4.2
49      */

50     public static ActionManager getDefault() {
51         ActionManager am = (ActionManager) Lookup.getDefault().lookup(ActionManager.class);
52
53         if (am == null) {
54             am = new Trivial();
55         }
56
57         return am;
58     }
59
60     /** Get all registered actions that should be displayed
61     * by tools action.
62     * Can contain <code>null</code>s that will be replaced by separators.
63     *
64     * @return array of actions
65     */

66     public abstract SystemAction[] getContextActions();
67
68     /** Invokes action in a RequestPrecessor dedicated to performing
69      * actions.
70      * Nonabstract since 4.11.
71      * @deprecated Just use {@link java.awt.event.ActionListener#actionPerformed} directly instead. Since 4.11.
72      */

73     public void invokeAction(Action a, ActionEvent JavaDoc e) {
74         a.actionPerformed(e);
75     }
76
77     /** Registers PropertyChangeListener to receive events.
78      * @param listener The listener to register.
79      */

80     public final void addPropertyChangeListener(PropertyChangeListener listener) {
81         if (supp == null) {
82             supp = new PropertyChangeSupport(this);
83         }
84
85         supp.addPropertyChangeListener(listener);
86     }
87
88     /** Removes PropertyChangeListener from the list of listeners.
89      * @param listener The listener to remove.
90      */

91     public final void removePropertyChangeListener(PropertyChangeListener listener) {
92         if (supp != null) {
93             supp.removePropertyChangeListener(listener);
94         }
95     }
96
97     /** Notifies all registered listeners about the event.
98      * @param name property name
99      * @param o old value
100      * @param n new value
101      */

102     protected final void firePropertyChange(String JavaDoc name, Object JavaDoc o, Object JavaDoc n) {
103         if (supp != null) {
104             supp.firePropertyChange(name, o, n);
105         }
106     }
107
108     /**
109      * Trivial impl.
110      * @see "#32092"
111      */

112     private static final class Trivial extends ActionManager {
113         public SystemAction[] getContextActions() {
114             return new SystemAction[0];
115         }
116     }
117 }
118
Popular Tags