01: /*
02: * Author: Chris Seguin
03: *
04: * This software has been developed under the copyleft
05: * rules of the GNU General Public License. Please
06: * consult the GNU General Public License for more
07: * details about use and distribution of this software.
08: */
09: package org.acm.seguin.io;
10:
11: import java.io.File;
12: import javax.swing.filechooser.FileFilter;
13: import java.util.Enumeration;
14: import java.util.Vector;
15:
16: /**
17: * Accepts all files
18: *
19: *@author Chris Seguin
20: *@created May 30, 1999
21: */
22: public class ExtensionFileFilter extends FileFilter {
23: // Local Variables
24: private String description;
25: private Vector extensions;
26:
27: /**
28: * Constructor for the ExtensionFileFilter
29: */
30: public ExtensionFileFilter() {
31: description = "Unknown set of files";
32: extensions = new Vector();
33: }
34:
35: /**
36: * Sets the description of the files accepted
37: *
38: *@param descr the new description
39: */
40: public void setDescription(String descr) {
41: if (descr != null) {
42: description = descr;
43: }
44: }
45:
46: /**
47: * Return the description of the files accepted
48: *
49: *@return the description to be displayed in the file box
50: */
51: public String getDescription() {
52: return description;
53: }
54:
55: /**
56: * Add an extension
57: *
58: *@param ext the extension to add
59: */
60: public void addExtension(String ext) {
61: if (ext != null) {
62: extensions.addElement(ext);
63: }
64: }
65:
66: /**
67: * Should this file be accepted
68: *
69: *@param file the file under consideration
70: *@return true - all files are accepted
71: */
72: public boolean accept(File file) {
73: if (file.isDirectory()) {
74: return true;
75: }
76:
77: Enumeration enumx = extensions.elements();
78: while (enumx.hasMoreElements()) {
79: String ext = ((String) enumx.nextElement()).toLowerCase();
80:
81: String filename = file.getName().toLowerCase();
82: if (filename.endsWith(ext)) {
83: return true;
84: }
85: }
86:
87: return false;
88: }
89: }
|