View Javadoc
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  
26  package com.sun.java.swing.action;
27  
28  import java.util.HashMap;
29  import javax.swing.Action;
30  import javax.swing.ImageIcon;
31  
32  // Referenced classes of package com.sun.java.swing.action:
33  //            DelegateAction, StateChangeAction, ActionUtilities
34  
35  public 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 abstract void addActions();
50  
51      protected void addAction(String cmdname, Action action)
52      {
53          actions.put(cmdname, action);
54      }
55  
56      public Action getAction(String key)
57      {
58          return (Action)actions.get(key);
59      }
60  
61      public DelegateAction getDelegateAction(String name)
62      {
63          Action a = getAction(name);
64          if(a instanceof DelegateAction)
65              return (DelegateAction)a;
66          else
67              return null;
68      }
69  
70      public StateChangeAction getStateChangeAction(String name)
71      {
72          Action a = getAction(name);
73          if(a instanceof StateChangeAction)
74              return (StateChangeAction)a;
75          else
76              return null;
77      }
78  
79      public static ImageIcon getIcon(String name)
80      {
81          return utilities.getIcon(name);
82      }
83  
84      public void setActionEnabled(String name, boolean enabled)
85      {
86          Action action = getAction(name);
87          if(action != null)
88              action.setEnabled(enabled);
89      }
90  
91      private HashMap actions;
92      private static ActionUtilities utilities = new ActionUtilities();
93      protected static ActionManager manager;
94  
95  }