-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMonFiltre.java
36 lines (30 loc) · 872 Bytes
/
MonFiltre.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
import java.io.File;
import javax.swing.filechooser.FileFilter;
public class MonFiltre extends FileFilter {
String[] lesSuffixes;
String laDescription;
public MonFiltre(String[] lesSuffixes, String laDescription) {
this.lesSuffixes = lesSuffixes;
this.laDescription = laDescription;
}
boolean appartient(String suffixe) {
for (int i = 0; i < lesSuffixes.length; ++i)
if (suffixe.equals(lesSuffixes[i]))
return true;
return false;
}
public boolean accept(File f) {
if (f.isDirectory())
return true;
String suffixe = null;
String s = f.getName();
int i = s.lastIndexOf('.');
if (i > 0 && i < s.length() - 1)
suffixe = s.substring(i + 1).toLowerCase();
return suffixe != null && appartient(suffixe);
}
// la description du filtre
public String getDescription() {
return laDescription;
}
}