1 19 20 21 package org.netbeans.modules.tasklist.docscan; 22 23 import java.lang.String ; 24 import java.util.ArrayList ; 25 import java.util.List ; 26 import java.util.logging.Level ; 27 import java.util.logging.Logger ; 28 import java.util.prefs.BackingStoreException ; 29 import java.util.prefs.Preferences ; 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 40 41 public final class Settings { 42 private static final Settings INSTANCE = new Settings(); 43 public static final String PROP_SCAN_SKIP = "skipComments"; public static final String PROP_SCAN_TAGS = "taskTags"; static final String PROP_MODIFICATION_TIME = "modificationTime"; 47 public static final String PROP_USABILITY_LIMIT = "usabilityLimit"; private final static int DEFAULT_USABILITY_LIMIT = 300; 49 50 private TaskTags tags = null; 51 52 private Settings() {} 53 54 55 public static Settings getDefault() { 56 return INSTANCE; 57 } 58 59 private static Preferences getPreferences() { 60 return NbPreferences.forModule(Settings.class); 61 } 62 63 68 public String displayName() { 69 return NbBundle.getMessage(Settings.class, 70 "OPTION_TASK_SETTINGS_NAME"); } 72 73 public HelpCtx getHelpCtx () { 74 return new HelpCtx (org.netbeans.modules.tasklist.docscan.Settings.class); } 76 77 78 83 public boolean getSkipComments() { 84 return getPreferences().getBoolean(PROP_SCAN_SKIP, false); 86 } 87 88 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 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 pNode = getPreferences(); 127 String [] keys = pNode.keys(); 128 List l = new ArrayList (); 129 for (int i = 0; i < keys.length; i++) { 130 String k = keys[i]; 131 if (k != null && k.startsWith("Tag")) { l.add(new TaskTag(k.substring("Tag".length()), SuggestionPriority.getPriority(pNode.getInt(k, 3)))); 134 } 135 } 136 retval.setTags((TaskTag[])l.toArray(new TaskTag[l.size()])); 137 } catch (BackingStoreException 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 new TaskTag("<<<<<<<", SuggestionPriority.HIGH), 149 }); 151 } 152 return retval; 153 } 154 155 private static void storeTaskTags(TaskTags tags) { 156 removeTaskTags(); 157 Preferences 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()); } 163 } 164 165 private static void removeTaskTags() { 166 Preferences pNode = getPreferences(); 167 try { 168 String [] keys = pNode.keys(); 169 for (int i = 0; i < keys.length; i++) { 170 String k = keys[i]; 171 if (k != null && k.startsWith("Tag")) { getPreferences().remove(k); 173 } 174 } 175 } catch (BackingStoreException ex) { 176 Logger.getLogger(Settings.class.getName()).log(Level.INFO, null, ex); 177 } 178 } 179 180 183 public long getModificationTime() { 184 return getPreferences().getLong(PROP_MODIFICATION_TIME,0); 185 } 186 187 188 public void setModificationTime(long time) { 189 getPreferences().putLong(PROP_MODIFICATION_TIME,time); 190 } 191 192 private void modified() { 194 getPreferences().putLong(PROP_MODIFICATION_TIME, System.currentTimeMillis()); 195 } 196 197 private static BeanNode createViewNode() throws java.beans.IntrospectionException { 198 return new BeanNode(Settings.getDefault()); 199 } 200 } 201 | Popular Tags |