KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > sp > jedit > io > GlobVFSFileFilter


1 /*
2  * VFSFileFilter.java - VFSFileFilter that uses Unix-style globs.
3  * :tabSize=4:indentSize=4:noTabs=false:
4  * :folding=explicit:collapseFolds=1:
5  *
6  * Copyright (C) 2006 Marcelo Vanzin
7  *
8  * This program is free software; you can redistribute it and/or
9  * 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 JavaDoc;
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
40     public GlobVFSFileFilter(String JavaDoc glob)
41     {
42         this.glob = glob;
43     }
44
45     public boolean accept(VFSFile file)
46     {
47         if (file.getType() == VFSFile.DIRECTORY
48                 || file.getType() == VFSFile.FILESYSTEM)
49         {
50             return true;
51         }
52         else
53         {
54             return accept(file.getName());
55         }
56     }
57
58     public boolean accept(String JavaDoc url)
59     {
60         if (pattern == null)
61         {
62             pattern = Pattern.compile(StandardUtilities.globToRE(glob),
63                           Pattern.CASE_INSENSITIVE);
64         }
65         return pattern.matcher(url).matches();
66     }
67
68     public String JavaDoc getDescription()
69     {
70         return jEdit.getProperty("vfs.browser.file_filter.glob");
71     }
72
73     public String JavaDoc toString()
74     {
75         return glob;
76     }
77
78     public void setGlob(String JavaDoc glob)
79     {
80         this.glob = glob;
81         pattern = null;
82     }
83
84     public String JavaDoc getGlob()
85     {
86         return glob;
87     }
88
89     private String JavaDoc glob;
90     private Pattern JavaDoc pattern;
91
92 }
93
94
Popular Tags