KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > docscan > Settings


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
21 package org.netbeans.modules.tasklist.docscan;
22
23 import java.lang.String JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import java.util.List JavaDoc;
26 import java.util.logging.Level JavaDoc;
27 import java.util.logging.Logger JavaDoc;
28 import java.util.prefs.BackingStoreException JavaDoc;
29 import java.util.prefs.Preferences JavaDoc;
30 import org.netbeans.modules.tasklist.client.SuggestionPriority;
31 import org.netbeans.modules.tasklist.docscan.TaskTag;
32 import org.openide.nodes.BeanNode;
33 import org.openide.util.NbBundle;
34 import org.openide.util.HelpCtx;
35 import org.openide.util.NbPreferences;
36
37
38 /** Settings for the tasklist module.
39  */

40
41 public final class Settings {
42     private static final Settings INSTANCE = new Settings();
43     public static final String JavaDoc PROP_SCAN_SKIP = "skipComments"; //NOI18N
44
public static final String JavaDoc PROP_SCAN_TAGS = "taskTags"; //NOI18N
45
static final String JavaDoc PROP_MODIFICATION_TIME = "modificationTime"; // NOI18N
46
/** Defines how many suggestions make sence. */
47     public static final String JavaDoc PROP_USABILITY_LIMIT = "usabilityLimit"; // NOI18N
48
private final static int DEFAULT_USABILITY_LIMIT = 300;
49
50     private TaskTags tags = null;
51     
52     private Settings() {}
53
54     /** Return the signleton */
55     public static Settings getDefault() {
56         return INSTANCE;
57     }
58
59     private static Preferences JavaDoc getPreferences() {
60         return NbPreferences.forModule(Settings.class);
61     }
62
63     /**
64      * Get the display name.
65      *
66      * @return value of OPTION_TASK_SETTINGS_NAME
67      */

68     public String JavaDoc displayName() {
69         return NbBundle.getMessage(Settings.class,
70                 "OPTION_TASK_SETTINGS_NAME"); //NOI18N
71
}
72
73     public HelpCtx getHelpCtx () {
74     return new HelpCtx (org.netbeans.modules.tasklist.docscan.Settings.class); //NOI18N
75
}
76
77
78     /**
79      * @return true iff the user wants to skip all tasks tokens
80      * appear outside of comment sections. The default value
81      * is true.
82      */

83     public boolean getSkipComments() {
84         // XXX I did a spectacularly poor job naming this method.
85
return getPreferences().getBoolean(PROP_SCAN_SKIP, false);
86     }
87
88     /** Sets the skip-outside-of-comments property
89      * @param doSkip True iff you want to skip tasks outside of comments
90      */

91     public void setSkipComments(boolean doSkip) {
92         getPreferences().putBoolean(PROP_SCAN_SKIP, doSkip);
93         modified();
94     }
95
96
97     public void setUsabilityLimit(int limit) {
98         if (limit > 1000) limit = 1000;
99         if (limit <=0) limit = DEFAULT_USABILITY_LIMIT;
100         getPreferences().putInt(PROP_USABILITY_LIMIT, limit);
101     }
102
103     public int getUsabilityLimit() {
104         return getPreferences().getInt(PROP_USABILITY_LIMIT, DEFAULT_USABILITY_LIMIT);
105     }
106
107     public TaskTags getTaskTags() {
108         if (tags == null) {
109             tags = initTaskTags();
110         }
111         return tags;
112     }
113     
114     /** Sets the skip-outside-of-comments property
115      * @param doSkip True iff you want to skip tasks outside of comments
116      */

117     public void setTaskTags(TaskTags scanTasks) {
118         tags = scanTasks;
119         storeTaskTags(scanTasks);
120         modified();
121     }
122     
123     private static TaskTags initTaskTags() {
124         TaskTags retval = new TaskTags();
125         try {
126             Preferences JavaDoc pNode = getPreferences();
127             String JavaDoc[] keys = pNode.keys();
128             List JavaDoc l = new ArrayList JavaDoc();
129             for (int i = 0; i < keys.length; i++) {
130                 String JavaDoc k = keys[i];
131                 if (k != null && k.startsWith("Tag")) {//NOI18N
132
l.add(new TaskTag(k.substring("Tag".length()),//NOI18N
133
SuggestionPriority.getPriority(pNode.getInt(k, 3))));
134                 }
135             }
136             retval.setTags((TaskTag[])l.toArray(new TaskTag[l.size()]));
137         } catch (BackingStoreException JavaDoc ex) {
138             Logger.getLogger(Settings.class.getName()).log(Level.INFO, null, ex);
139         }
140         if (retval.getTags().length == 0) {
141             retval.setTags(new TaskTag[]{
142                 new TaskTag("@todo", SuggestionPriority.MEDIUM),
143                         new TaskTag("TODO", SuggestionPriority.MEDIUM),
144                         new TaskTag("FIXME", SuggestionPriority.MEDIUM),
145                         new TaskTag("XXX", SuggestionPriority.MEDIUM),
146                         new TaskTag("PENDING", SuggestionPriority.MEDIUM),
147                         // XXX CVS merge conflict: overlaps with skipNonComments settings
148
new TaskTag("<<<<<<<", SuggestionPriority.HIGH),
149                         // Additional candidates: HACK, WORKAROUND, REMOVE, OLD
150
});
151         }
152         return retval;
153     }
154     
155     private static void storeTaskTags(TaskTags tags) {
156         removeTaskTags();
157         Preferences JavaDoc pNode = getPreferences();
158         TaskTag[] tts = tags.getTags();
159         for (int i = 0; i < tts.length; i++) {
160             TaskTag taskTag = tts[i];
161             getPreferences().putInt("Tag"+taskTag.getToken(),taskTag.getPriority().intValue());//NOI18N
162
}
163     }
164     
165     private static void removeTaskTags() {
166         Preferences JavaDoc pNode = getPreferences();
167         try {
168             String JavaDoc[] keys = pNode.keys();
169             for (int i = 0; i < keys.length; i++) {
170                 String JavaDoc k = keys[i];
171                 if (k != null && k.startsWith("Tag")) {//NOI18N
172
getPreferences().remove(k);
173                 }
174             }
175         } catch (BackingStoreException JavaDoc ex) {
176             Logger.getLogger(Settings.class.getName()).log(Level.INFO, null, ex);
177         }
178     }
179     
180     /**
181      * Last modification time is stored as hidden property.
182      */

183     public long getModificationTime() {
184         return getPreferences().getLong(PROP_MODIFICATION_TIME,0);
185     }
186
187     /** for deserialization purposes only */
188     public void setModificationTime(long time) {
189         getPreferences().putLong(PROP_MODIFICATION_TIME,time);
190     }
191
192     // update modification time
193
private void modified() {
194         getPreferences().putLong(PROP_MODIFICATION_TIME, System.currentTimeMillis());
195     }
196     
197     private static BeanNode createViewNode() throws java.beans.IntrospectionException JavaDoc {
198         return new BeanNode(Settings.getDefault());
199     }
200 }
201
Popular Tags