01: /*
02: This library is free software; you can redistribute it and/or
03: modify it under the terms of the GNU General Public
04: License as published by the Free Software Foundation; either
05: version 2 of the license, or (at your option) any later version.
06: */
07:
08: package org.gjt.jclasslib.mdi;
09:
10: import javax.swing.filechooser.FileFilter;
11: import java.io.File;
12:
13: /**
14: Configurable file filter for a <tt>JFileChooser</tt>.
15:
16: @author <a href="mailto:jclasslib@ej-technologies.com">Ingo Kegel</a>
17: @version $Revision: 1.4 $ $Date: 2003/08/18 07:59:50 $
18: */
19: public class BasicFileFilter extends FileFilter {
20:
21: private String[] extensions;
22: private String description;
23:
24: /**
25: Constructor.
26: @param extensions the file extensions.
27: @param description the description.
28: */
29: public BasicFileFilter(String[] extensions, String description) {
30:
31: this .extensions = extensions;
32:
33: StringBuffer buffer = new StringBuffer(description);
34: buffer.append(" (");
35: for (int i = 0; i < extensions.length; i++) {
36: if (i > 0) {
37: buffer.append(", ");
38: }
39: buffer.append("*.");
40: buffer.append(extensions[i]);
41: }
42: buffer.append(")");
43:
44: this .description = buffer.toString();
45: }
46:
47: /**
48: Constructor.
49: @param extension the file extension.
50: @param description the description.
51: */
52: public BasicFileFilter(String extension, String description) {
53:
54: this (new String[] { extension }, description);
55: }
56:
57: public boolean accept(File file) {
58:
59: if (extensions == null)
60: return true;
61:
62: for (int i = 0; i < extensions.length; i++) {
63: if (file.isDirectory()
64: || file.getName().endsWith(extensions[i]))
65: return true;
66: }
67: return false;
68: }
69:
70: public String getDescription() {
71: return description + "";
72: }
73: }
|