1 19 20 package org.netbeans.modules.masterfs; 21 22 import java.util.prefs.PreferenceChangeEvent ; 23 import java.util.prefs.PreferenceChangeListener ; 24 import org.netbeans.spi.queries.VisibilityQueryImplementation; 25 import org.openide.filesystems.FileObject; 26 import javax.swing.event.ChangeEvent ; 27 import javax.swing.event.ChangeListener ; 28 import java.lang.reflect.Method ; 29 import java.util.ArrayList ; 30 import java.util.List ; 31 import java.util.prefs.Preferences ; 32 import java.util.regex.Pattern ; 33 import org.openide.util.NbPreferences; 34 35 38 46 public class GlobalVisibilityQueryImpl implements VisibilityQueryImplementation { 47 static GlobalVisibilityQueryImpl INSTANCE; 48 private final List listeners = new ArrayList (); 49 50 53 private static final String PROP_IGNORED_FILES = "IgnoredFiles"; private static Method mIgnoredFiles; 55 private Pattern ignoreFilesPattern = null; 56 57 58 public GlobalVisibilityQueryImpl() { 59 INSTANCE = this; 60 } 61 62 private static Preferences getPreferences() { 63 return NbPreferences.root().node("/org/netbeans/core"); 64 } 65 66 public boolean isVisible(FileObject file) { 67 return isVisible(file.getNameExt()); 68 } 69 70 boolean isVisible(final String fileName) { 71 Pattern ignoreFilesPattern = getIgnoreFilesPattern(); 72 return (ignoreFilesPattern != null) ? !(ignoreFilesPattern.matcher(fileName).find()) : true; 73 } 74 75 79 public synchronized void addChangeListener(ChangeListener l) { 80 listeners.add(l); 81 } 82 83 87 public synchronized void removeChangeListener(ChangeListener l) { 88 listeners.remove(l); 89 } 90 91 private void fireChange() { 92 ChangeListener [] _listeners; 93 synchronized (this) { 94 if (listeners.isEmpty()) { 95 return; 96 } 97 _listeners = (ChangeListener []) listeners.toArray(new ChangeListener [listeners.size()]); 98 } 99 ChangeEvent ev = new ChangeEvent (this); 100 for (int i = 0; i < _listeners.length; i++) { 101 _listeners[i].stateChanged(ev); 102 } 103 } 104 105 private Pattern getIgnoreFilesPattern() { 106 if (ignoreFilesPattern == null) { 107 String ignoredFiles = getIgnoredFiles(); 108 ignoreFilesPattern = (ignoredFiles != null && ignoredFiles.length() > 0) ? Pattern.compile(ignoredFiles) : null; 109 } 110 return ignoreFilesPattern; 111 } 112 113 protected String getIgnoredFiles() { 114 String retval = getPreferences().get(PROP_IGNORED_FILES, "^(CVS|SCCS|vssver\\.scc|#.*#|%.*%|\\.(cvsignore|svn|DS_Store)|_svn)$|~$|^\\..*$"); getPreferences().addPreferenceChangeListener(new PreferenceChangeListener () { 117 public void preferenceChange(PreferenceChangeEvent evt) { 118 if (PROP_IGNORED_FILES.equals(evt.getKey())) { 119 ignoreFilesPattern = null; 120 fireChange(); 121 } 122 123 } 124 }); 125 return retval; 126 } 127 } 128 | Popular Tags |