File tree 1 file changed +48
-0
lines changed
app/src/processing/app/javax/swing/filechooser
1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change
1
+ package processing .app .javax .swing .filechooser ;
2
+
3
+ import javax .swing .filechooser .FileFilter ;
4
+ import java .io .File ;
5
+ import java .util .Locale ;
6
+
7
+ public class FileNameExtensionFilter extends FileFilter {
8
+
9
+ private final String description ;
10
+ private final String [] extensions ;
11
+
12
+ public FileNameExtensionFilter (String description , String ... exts ) {
13
+ this .description = description ;
14
+ this .extensions = new String [exts .length ];
15
+ for (int i = 0 ; i < exts .length ; i ++) {
16
+ this .extensions [i ] = exts [i ].toLowerCase (Locale .ENGLISH );
17
+ }
18
+ }
19
+
20
+ @ Override
21
+ public boolean accept (File f ) {
22
+ if (f == null ) {
23
+ return false ;
24
+ }
25
+
26
+ if (f .isDirectory ()) {
27
+ return true ;
28
+ }
29
+
30
+ String fileName = f .getName ();
31
+ int i = fileName .lastIndexOf ('.' );
32
+ if (i > 0 && i < fileName .length () - 1 ) {
33
+ String fileExtension = fileName .substring (i + 1 ).toLowerCase (Locale .ENGLISH );
34
+ for (String extension : extensions ) {
35
+ if (extension .equals (fileExtension )) {
36
+ return true ;
37
+ }
38
+ }
39
+ }
40
+
41
+ return false ;
42
+ }
43
+
44
+ @ Override
45
+ public String getDescription () {
46
+ return description ;
47
+ }
48
+ }
You can’t perform that action at this time.
0 commit comments