-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExtensionFileFilter.java
53 lines (45 loc) · 1.35 KB
/
ExtensionFileFilter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package rjavautils;
import java.io.File;
import javax.swing.filechooser.FileFilter;
class ExtensionFileFilter extends FileFilter
{
String description;
String[] extensions;
public ExtensionFileFilter(String description, String extension)
{
this(description, new String[] { extension });
}
public ExtensionFileFilter(String description, String[] extensions)
{
if (description == null)
this.description = (extensions[0] + "{ " + extensions.length + "} ");
else {
this.description = description;
}
this.extensions = ((String[])(String[])extensions.clone());
toLower(this.extensions);
}
private void toLower(String[] array) {
int i = 0; for (int n = array.length; i < n; i++)
array[i] = array[i].toLowerCase();
}
public String getDescription()
{
return this.description;
}
public boolean accept(File file) {
if (file.isDirectory()) {
return true;
}
String path = file.getAbsolutePath().toLowerCase();
int i = 0; for (int n = this.extensions.length; i < n; i++) {
String extension = this.extensions[i];
if (extension.equals("*"))
return true;
if ((path.endsWith(extension)) && (path.charAt(path.length() - extension.length() - 1) == '.')) {
return true;
}
}
return false;
}
}