1/*
2 * Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25
26package com.sun.java.swing.action;
27
28import java.util.HashMap;
29import javax.swing.Action;
30import javax.swing.ImageIcon;
31
32// Referenced classes of package com.sun.java.swing.action:
33//            DelegateAction, StateChangeAction, ActionUtilities
34
35public abstract class ActionManager
36{
37
38    protected ActionManager()
39    {
40        actions = new HashMap();
41        addActions();
42    }
43
44    public static ActionManager getInstance()
45    {
46        return manager;
47    }
48
49    protected static void setInstance(ActionManager m)
50    {
51        manager = m;
52    }
53
54    protected abstract void addActions();
55
56    protected void addAction(String cmdname, Action action)
57    {
58        actions.put(cmdname, action);
59    }
60
61    public Action getAction(String key)
62    {
63        return (Action)actions.get(key);
64    }
65
66    public DelegateAction getDelegateAction(String name)
67    {
68        Action a = getAction(name);
69        if(a instanceof DelegateAction)
70            return (DelegateAction)a;
71        else
72            return null;
73    }
74
75    public StateChangeAction getStateChangeAction(String name)
76    {
77        Action a = getAction(name);
78        if(a instanceof StateChangeAction)
79            return (StateChangeAction)a;
80        else
81            return null;
82    }
83
84    public static ImageIcon getIcon(String name)
85    {
86        return utilities.getIcon(name);
87    }
88
89    public void setActionEnabled(String name, boolean enabled)
90    {
91        Action action = getAction(name);
92        if(action != null)
93            action.setEnabled(enabled);
94    }
95
96    private HashMap actions;
97    private static ActionUtilities utilities = new ActionUtilities();
98    private static ActionManager manager;
99
100}
101