KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > editor > app > gui > tree > ActionsCache


1 /*
2  * ActionsCache.java
3  *
4  * Created on November 14, 2002, 3:31 PM
5  */

6
7 package org.netbeans.test.editor.app.gui.tree;
8
9 import java.util.HashMap JavaDoc;
10 import java.util.Iterator JavaDoc;
11 import java.util.Vector JavaDoc;
12 import org.netbeans.test.editor.app.gui.actions.TreeNewType;
13 import org.netbeans.test.editor.app.gui.actions.TreeNodeAction;
14
15 /**
16  *
17  * @author eh103527
18  */

19 public class ActionsCache {
20     
21     HashMap JavaDoc actions;
22     
23     private static ActionsCache instance;
24     
25     /** Creates a new instance of ActionsCache */
26     private ActionsCache() {
27         actions=new HashMap JavaDoc();
28     }
29     
30     public static ActionsCache getDefault() {
31         if (instance == null) {
32             instance=new ActionsCache();
33         }
34         return instance;
35     }
36     
37     public void addNodeActions(Class JavaDoc node,Vector JavaDoc acts) {
38         actions.put(node, acts);
39     }
40     
41     public void addNodeAction(Class JavaDoc node,TreeNodeAction action) {
42         if (actions.get(node) != null) {
43             ((Vector JavaDoc)(actions.get(node))).add(action);
44         } else {
45             Vector JavaDoc v=new Vector JavaDoc();
46             addNodeActions(node,v);
47             v.add(action);
48         }
49     }
50     
51     public Vector JavaDoc getActions(Class JavaDoc node) {
52         return (Vector JavaDoc)(actions.get(node));
53     }
54     
55     public TreeNodeAction getAction(Class JavaDoc node, Class JavaDoc action) {
56         Vector JavaDoc v=(Vector JavaDoc)(actions.get(node));
57         Object JavaDoc o;
58         for (Iterator JavaDoc it=v.iterator();it.hasNext();) {
59             o=it.next();
60             if (o.getClass().equals(action)) {
61                 return (TreeNodeAction)o;
62             }
63         }
64         return null;
65     }
66 }
67
Popular Tags