svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.utils / src / main / java / org / gvsig / utils / SimpleFileFilter.java @ 40561
History | View | Annotate | Download (2.16 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.utils; |
25 |
|
26 |
import java.io.File; |
27 |
|
28 |
import javax.swing.filechooser.FileFilter; |
29 |
|
30 |
|
31 |
/**
|
32 |
* A simple file filter implementation that allow to specify one or more file
|
33 |
* extensions
|
34 |
*
|
35 |
* @author wolf
|
36 |
*/
|
37 |
public class SimpleFileFilter extends FileFilter implements java.io.FileFilter { |
38 |
String[] extensions; |
39 |
String description;
|
40 |
|
41 |
public SimpleFileFilter(String extension, String description) { |
42 |
this.extensions = new String[] { extension }; |
43 |
this.description = description;
|
44 |
} |
45 |
|
46 |
public SimpleFileFilter(String[] extensions, String description) { |
47 |
this.extensions = extensions;
|
48 |
this.description = description;
|
49 |
} |
50 |
|
51 |
/**
|
52 |
* @see javax.swing.filechooser.FileFilter#accept(java.io.File)
|
53 |
*/
|
54 |
public boolean accept(File f) { |
55 |
if (f.isDirectory()) {
|
56 |
return true; |
57 |
} |
58 |
|
59 |
String extension = FileUtils.getFileExtension(f);
|
60 |
|
61 |
for (int i = 0; i < extensions.length; i++) { |
62 |
if (extension.equals(extensions[i])) {
|
63 |
return true; |
64 |
} |
65 |
} |
66 |
|
67 |
return false; |
68 |
} |
69 |
|
70 |
/**
|
71 |
* @see javax.swing.filechooser.FileFilter#getDescription()
|
72 |
*/
|
73 |
public String getDescription() { |
74 |
return description;
|
75 |
} |
76 |
} |