1
6 import javax.swing.filechooser.*;
7
8 public class FileTypes extends FileFilter {
9
10 public static int CARTO = 1;
11 public static int SURVEY = 2;
12 public static int IMAGE = 4;
13 public static int PRINT = 4;
14 public static int ANY = 16;
15 public static int JAR = 32;
16
17
18
19 int types = 0;
20
21 public FileTypes(int types) {
22 this.types = types;
23 }
24
25 public boolean accept(java.io.File f) {
26 if (f.isDirectory()) return(true);
27 String name = f.getName().toLowerCase();
28 if (0!=(types&ANY)) return(true);
29 int dot = name.lastIndexOf('.');
30 if (dot==-1) return(false);
31 String ext = name.substring(dot+1);
32 if ((ext.equals("cto")) &&
33 (0!=(types&CARTO))) return(true);
34 if (ext.equals("jar")&&(0!=(types&JAR))) return(true);
35 if (ext.equals("xyz")&&(0!=(types&SURVEY))) return(true);
36 if (ext.equals("plt")&&(0!=(types&SURVEY))) return(true);
37 if ((0!=(types&IMAGE))||(0!=(types&PRINT))) {
38 if (ext.equals("gif")) return(true);
39 else if (ext.equals("png")) return(true);
40 else if (ext.equals("jpg")) return(true);
41 }
42 if ((0!=(types&PRINT))) {
43 if (ext.equals("ps")) return(true);
44 }
45 return(false);
46 }
47
48 public String getDescription() {
49 String string = "";
50 if (0!=(types&ANY)) string += ".* ";
51 if (0!=(types&CARTO)) string += ".cto";
52 else if (0!=(types&SURVEY)) string += ".xyz .plt";
53 else if (0!=(types&IMAGE)) string += ".gif .png .jpg";
54 else if (0!=(types&PRINT)) string += ".ps";
55
56
57 else if (0!=(types&JAR)) string += ".jar";
58 return(string);
59 }
60 }
61