KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > suggestions > SuggestionTypes


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
20 package org.netbeans.modules.tasklist.suggestions;
21
22 import java.util.Map JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.Collection JavaDoc;
25
26 /**
27  * Registry of all suggestion types. This is singleton and it also keeps
28  * the settings whether the suggestion types which are not active are
29  * drawn on the background, whther the combining of suggestions is
30  * turned on or off etc. These settings are shared by all views.
31  *
32  * Based on AnnotationTypes.java in the editor package.
33  * <p>
34  *
35  * @author Tor Norbye, David Konecny
36  */

37
38 final public class SuggestionTypes {
39     /** Static map containing all suggestion types:
40         suggestion_name <-> suggestion_type */

41     private Map JavaDoc allTypes = null;
42     
43     /** Flag whether the suggestion types were initialized or not */
44     private boolean initializedTypes = false;
45
46     /** Single instance of this class */
47     private static SuggestionTypes suggestionTypes = null;
48     
49     private SuggestionTypes() {
50     }
51
52     /** Returns instance of SuggestionTypes singleton. */
53     public static SuggestionTypes getDefault() {
54         if (suggestionTypes == null) {
55             suggestionTypes = new SuggestionTypes();
56         }
57         return suggestionTypes;
58     }
59     
60     /** Initialize the map of all suggestion types
61      * @param map map containing all suggestion types */

62     final void setTypes(Map JavaDoc map) {
63         allTypes = map;
64         initializedTypes = map != null;
65     }
66
67     public final int getCount() {
68         loadTypes();
69         if (allTypes == null) {
70             return 0;
71         } else {
72             return allTypes.size();
73         }
74     }
75     
76     /** Returns SuggestionType instance for the given name of the type
77      * @param name suggestion type name
78      * @return instance describing suggestion type */

79     public final SuggestionType getType(String JavaDoc name) {
80         loadTypes();
81         
82         if (allTypes == null)
83             return null;
84         
85         return (SuggestionType)allTypes.get(name);
86     }
87
88     /** Returns a collection containing all the registered SuggestionTypes.
89      * @return collection containing all registered types */

90     public final Collection JavaDoc getAllTypes() {
91         loadTypes();
92         
93         if (allTypes == null)
94             return null;
95         
96         return allTypes.values();
97     }
98
99     /** Check if the types were loaded and load them if not */
100     private void loadTypes() {
101         if (initializedTypes)
102             return;
103
104         SuggestionTypesFolder.getSuggestionTypesFolder();
105
106         initializedTypes = true;
107     }
108 }
109
Popular Tags