1 19 20 package org.netbeans.core; 21 22 import java.net.MalformedURLException ; 23 import java.net.URL ; 24 import java.util.logging.Level ; 25 import java.util.logging.Logger ; 26 import java.util.prefs.Preferences ; 27 import java.util.regex.Pattern ; 28 import java.util.regex.PatternSyntaxException ; 29 import org.openide.awt.HtmlBrowser; 30 import org.openide.cookies.InstanceCookie; 31 import org.openide.filesystems.FileObject; 32 import org.openide.filesystems.Repository; 33 import org.openide.loaders.DataFolder; 34 import org.openide.loaders.DataNode; 35 import org.openide.loaders.DataObject; 36 import org.openide.nodes.BeanNode; 37 import org.openide.util.Exceptions; 38 import org.openide.util.HelpCtx; 39 import org.openide.util.Lookup; 40 import org.openide.util.NbBundle; 41 import org.openide.util.NbPreferences; 42 43 47 public class IDESettings { 48 private static final IDESettings INSTANCE = new IDESettings(); 49 50 51 public static final String PROP_SHOW_TOOLTIPS_IN_IDE = "showToolTipsInIDE"; 53 public static final String PROP_CONFIRM_DELETE = "confirmDelete"; 55 public static final String PROP_HOME_PAGE = "homePage"; 57 public static final String PROP_SHOW_FILE_EXTENSIONS = "showFileExtensions"; 59 public static final String PROP_WWWBROWSER = "WWWBrowser"; 61 68 public static final String PROP_IGNORED_FILES = "IgnoredFiles"; 70 71 74 public static IDESettings getInstance() { 75 return INSTANCE; 76 } 77 78 static Preferences getPreferences() { 79 return NbPreferences.forModule(IDESettings.class); 80 } 81 82 85 87 public boolean getShowToolTipsInIDE () { 88 return getPreferences().getBoolean(PROP_SHOW_TOOLTIPS_IN_IDE, true); 89 } 90 91 94 public void setShowToolTipsInIDE (boolean value) { 95 getPreferences().putBoolean(PROP_SHOW_TOOLTIPS_IN_IDE, value); 96 } 97 98 100 public boolean getConfirmDelete () { 101 return getPreferences().getBoolean(PROP_CONFIRM_DELETE, true); 102 } 103 104 106 public void setConfirmDelete (boolean value) { 107 getPreferences().putBoolean(PROP_CONFIRM_DELETE, value); 108 } 109 110 112 public String displayName () { 113 return NbBundle.getBundle (IDESettings.class).getString ("CTL_IDESettings"); 114 } 115 116 public HelpCtx getHelpCtx () { 117 return new HelpCtx (IDESettings.class); 118 } 119 120 122 public String getHomePage () { 123 return HtmlBrowser.getHomePage (); 124 } 125 126 128 public void setHomePage (String homePage) { 129 HtmlBrowser.setHomePage (homePage); 130 } 131 132 135 public boolean getShowFileExtensions () { 136 return DataNode.getShowFileExtensions (); 137 } 138 139 142 public void setShowFileExtensions (boolean s) { 143 DataNode.setShowFileExtensions (s); 144 } 145 146 154 public static HtmlBrowser.Factory getWWWBrowser () { 155 try { 156 Object obj = getPreferences().get(PROP_WWWBROWSER, null); 157 158 if (obj instanceof String && !"".equals (obj)) { 159 Lookup.Item<HtmlBrowser.Factory> item = Lookup.getDefault ().lookupItem (new Lookup.Template<HtmlBrowser.Factory> (HtmlBrowser.Factory.class, (String )obj, null)); 161 return item == null ? null : item.getInstance (); 162 } 163 164 if (obj == null || "".equals (obj)) { 166 Lookup.Result<HtmlBrowser.Factory> res = Lookup.getDefault ().lookupResult (HtmlBrowser.Factory.class); 167 java.util.Iterator <? extends HtmlBrowser.Factory> it = res.allInstances ().iterator (); 168 while (it.hasNext ()) { 169 HtmlBrowser.Factory brow = it.next (); 170 171 FileObject fo = Repository.getDefault () 173 .getDefaultFileSystem ().findResource ("Services/Browsers"); 175 DataFolder folder = DataFolder.findFolder (fo); 176 DataObject [] dobjs = folder.getChildren (); 177 for (int i = 0; i < dobjs.length; i++) { 178 Object o = null; 179 180 try { 181 if (Boolean.TRUE.equals (dobjs[i].getPrimaryFile ().getAttribute ("hidden"))) 182 continue; 183 InstanceCookie cookie = (InstanceCookie) dobjs[i].getCookie (InstanceCookie.class); 184 185 if (cookie == null) 186 continue; 187 o = cookie.instanceCreate (); 188 if (o != null && o.equals (brow)) { 189 return brow; 190 } 191 } 192 catch (java.io.IOException ex) { 194 Logger.getLogger (IDESettings.class.getName ()).log (Level.WARNING, null, ex); 195 } catch (ClassNotFoundException ex) { 196 Logger.getLogger (IDESettings.class.getName ()).log (Level.WARNING, null, ex); 197 } 198 } 199 200 } 201 return null; 202 } 203 } catch (Exception ex) { 204 Exceptions.printStackTrace (ex); 205 } 206 return null; 207 } 208 209 215 public static void setWWWBrowser (HtmlBrowser.Factory brow) { 216 try { 217 if (brow == null) { 218 getPreferences().put(PROP_WWWBROWSER, ""); return; 220 } 221 222 Lookup.Item<HtmlBrowser.Factory> item = 223 Lookup.getDefault ().lookupItem (new Lookup.Template<HtmlBrowser.Factory> (HtmlBrowser.Factory.class, null, brow)); 224 if (item != null) { 225 getPreferences().put(PROP_WWWBROWSER, item.getId ()); 226 } else { 227 Logger.getLogger (IDESettings.class.getName ()).warning ("IDESettings: Cannot find browser in lookup"); getPreferences().put(PROP_WWWBROWSER, ""); } 231 } catch (Exception ex) { 232 Exceptions.printStackTrace (ex); 233 } 234 } 235 236 238 public String getIgnoredFiles () { 239 return getPreferences().get(PROP_IGNORED_FILES, "^(CVS|SCCS|vssver\\.scc|#.*#|%.*%|\\.(cvsignore|svn|DS_Store)|_svn)$|~$|^\\..*$"); } 241 242 public void setIgnoredFiles(String ignoredFiles) throws IllegalArgumentException { 243 try { 244 Pattern.compile(ignoredFiles); 245 getPreferences().put(PROP_IGNORED_FILES, ignoredFiles); } catch (PatternSyntaxException e) { 247 IllegalArgumentException iae = new IllegalArgumentException (); 248 iae.initCause( e ); 249 UIExceptions.annotateUser(iae, e.getMessage(), 250 e.getLocalizedMessage(), null, null); 251 throw iae; 252 } 253 } 254 255 private static BeanNode createViewNode() throws java.beans.IntrospectionException { 256 return new BeanNode(IDESettings.getInstance()); 257 } 258 259 private static org.netbeans.beaninfo.editors.HtmlBrowser.FactoryEditor createHtmlBrowserFactoryEditor() { 260 return new org.netbeans.beaninfo.editors.HtmlBrowser.FactoryEditor(){ 261 public void setValue(Object value) { 262 setWWWBrowser((HtmlBrowser.Factory)value); 263 } 264 265 public Object getValue() { 266 return getWWWBrowser(); 267 } 268 }; 269 } 270 } 271 | Popular Tags |