KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > editor > app > core > actions > ActionRegistry


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.netbeans.test.editor.app.core.actions;
20
21 import java.util.HashMap JavaDoc;
22 import java.util.Map JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.Collection JavaDoc;
26 import java.util.Vector JavaDoc;
27 import org.netbeans.test.editor.app.gui.actions.TreeNewType;
28 import org.netbeans.test.editor.app.gui.actions.TreeNodeAction;
29
30 /**
31  *
32  * @author jlahoda
33  * @version
34  */

35 public class ActionRegistry extends Object JavaDoc {
36
37     HashMap JavaDoc actions;
38     HashMap JavaDoc newTypes;
39     HashMap JavaDoc newClasses;
40     private static ActionRegistry actionRegistry = null;
41     private static Object JavaDoc synchronizeTo = new Object JavaDoc();
42     
43     /** Creates new ActionRegistry */
44     private ActionRegistry() {
45         actions = new HashMap JavaDoc();
46         newTypes=new HashMap JavaDoc();
47         newClasses=new HashMap JavaDoc();
48     }
49     
50     public static ActionRegistry getDefault() {
51         if (actionRegistry == null) {
52             synchronized (synchronizeTo) {
53                 if (actionRegistry == null) {
54                     actionRegistry = new ActionRegistry();
55                 }
56             }
57         }
58         return actionRegistry;
59     }
60     
61     public static void clear() {
62         actionRegistry = null;
63     }
64     
65     public void addAction(Class JavaDoc cookie, TreeNodeAction action) {
66         Vector JavaDoc v;
67         v=(Vector JavaDoc)(actions.get(cookie));
68         if (v == null) {
69             v=new Vector JavaDoc();
70             v.add(action);
71             actions.put(cookie, v);
72         } else {
73             v.add(action);
74         }
75     }
76     
77     public Vector JavaDoc getActions(Class JavaDoc cookie) {
78         return (Vector JavaDoc)actions.get(cookie);
79     }
80     
81     public Vector JavaDoc getActions(Collection JavaDoc cookieSet) {
82         Vector JavaDoc result = new Vector JavaDoc();
83         Iterator JavaDoc keys = actions.keySet().iterator();
84         
85         while (keys.hasNext()) {
86             Class JavaDoc key = (Class JavaDoc) keys.next();
87             Object JavaDoc o;
88             for (Iterator JavaDoc it=cookieSet.iterator();it.hasNext();) {
89                 o=it.next();
90                 if (o.equals(key)) {
91                     result.addAll(getActions(key));
92                     break;
93                 }
94             }
95         }
96         return result;
97     }
98     
99     //new types
100
public void registerNewType(Class JavaDoc newClass,TreeNewType type) {
101         newClasses.put(newClass,type);
102     }
103     
104     public TreeNewType getRegisteredNewType(Class JavaDoc newClass) {
105         return (TreeNewType)(newClasses.get(newClass));
106     }
107     
108     public void addRegisteredNewType(Class JavaDoc node,Class JavaDoc newClass) {
109         addNewType(node,getRegisteredNewType(newClass));
110     }
111     
112     public void addNewTypes(Class JavaDoc node,Vector JavaDoc types) {
113         newTypes.put(node, types);
114     }
115     
116     public void addNewType(Class JavaDoc node,TreeNewType type) {
117         if (newTypes.get(node) != null) {
118             ((Vector JavaDoc)(newTypes.get(node))).add(type);
119         } else {
120             Vector JavaDoc v=new Vector JavaDoc();
121             addNewTypes(node,v);
122             v.add(type);
123         }
124     }
125     
126     public Vector JavaDoc getNewTypes(Class JavaDoc node) {
127         return (Vector JavaDoc)(newTypes.get(node));
128     }
129 }
130
Popular Tags