-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileExtensionFilter.java
65 lines (52 loc) · 1.34 KB
/
FileExtensionFilter.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
54
55
56
57
58
59
60
61
62
63
64
65
import javax.swing.filechooser.FileFilter;
import java.io.File;
/**
* Implements a FileFilter based on file extension.
* @author Achim Gosse, [email protected]
* @version 1.00
*/
public class FileExtensionFilter extends FileFilter {
/**
* Description of current FileFilter.
*/
private String description;
/**
* Array of valid file extensions.
*/
private String[] extensions;
/**
* Creates a FileExtensionFileFilter.
* @param d description of the filter
* @param e array of valid file extensions
*/
public FileExtensionFilter(String d, String[] e) {
description = d;
extensions = e;
}
/**
* Implements the test.
* @param f file shown in the file open dialog
* @return <i>true</i> - if the file passes the filter<br />
* <i>false</i> - otherwise
*/
@Override
public boolean accept(File f) {
if (f.isDirectory()) {
return true;
}
for (String e : extensions) {
if (f.getAbsolutePath().endsWith(e)) {
return true;
}
}
return false;
}
/**
* Getter of description.
* @return description
*/
@Override
public String getDescription() {
return description;
}
}