01: /*
02: * VFSFileFilter.java - VFSFileFilter that uses Unix-style globs.
03: * :tabSize=4:indentSize=4:noTabs=false:
04: * :folding=explicit:collapseFolds=1:
05: *
06: * Copyright (C) 2006 Marcelo Vanzin
07: *
08: * This program is free software; you can redistribute it and/or
09: * modify it under the terms of the GNU General Public License
10: * as published by the Free Software Foundation; either version 2
11: * of the License, or any later version.
12: *
13: * This program is distributed in the hope that it will be useful,
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16: * GNU General Public License for more details.
17: *
18: * You should have received a copy of the GNU General Public License
19: * along with this program; if not, write to the Free Software
20: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21: */
22:
23: package org.gjt.sp.jedit.io;
24:
25: import java.util.regex.Pattern;
26: import org.gjt.sp.jedit.jEdit;
27: import org.gjt.sp.util.StandardUtilities;
28:
29: /**
30: * Implementation of {@link VFSFileFilter} that uses Unix-style globs
31: * to filter files. This doesn't filter directories - just files.
32: *
33: * @author Marcelo Vanzin
34: * @version $Id$
35: * @since jEdit 4.3pre7
36: */
37: public class GlobVFSFileFilter implements VFSFileFilter {
38:
39: public GlobVFSFileFilter(String glob) {
40: this .glob = glob;
41: }
42:
43: public boolean accept(VFSFile file) {
44: if (file.getType() == VFSFile.DIRECTORY
45: || file.getType() == VFSFile.FILESYSTEM) {
46: return true;
47: } else {
48: return accept(file.getName());
49: }
50: }
51:
52: public boolean accept(String url) {
53: if (pattern == null) {
54: pattern = Pattern.compile(StandardUtilities.globToRE(glob),
55: Pattern.CASE_INSENSITIVE);
56: }
57: return pattern.matcher(url).matches();
58: }
59:
60: public String getDescription() {
61: return jEdit.getProperty("vfs.browser.file_filter.glob");
62: }
63:
64: public String toString() {
65: return glob;
66: }
67:
68: public void setGlob(String glob) {
69: this .glob = glob;
70: pattern = null;
71: }
72:
73: public String getGlob() {
74: return glob;
75: }
76:
77: private String glob;
78: private Pattern pattern;
79:
80: }
|