1 package net.sf.openrocket.gui.util;
5 import javax.swing.filechooser.FileFilter;
8 * A FileFilter similar to FileNameExtensionFilter except that
9 * it allows multipart extensions (.ork.gz), and also implements
10 * the java.io.FileFilter interface.
12 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
14 public class SimpleFileFilter extends FileFilter implements java.io.FileFilter {
16 private final String description;
17 private final boolean acceptDir;
18 private final String[] extensions;
22 * Create filter that accepts files with the provided extensions that
23 * accepts directories as well.
25 * @param description the description of this file filter.
26 * @param extensions an array of extensions that match this filter.
28 public SimpleFileFilter(String description, String ... extensions) {
29 this(description, true, extensions);
34 * Create filter that accepts files with the provided extensions.
36 * @param description the description of this file filter.
37 * @param acceptDir whether to accept directories
38 * @param extensions an array of extensions that match this filter.
40 public SimpleFileFilter(String description, boolean acceptDir, String ... extensions) {
41 this.description = description;
42 this.acceptDir = acceptDir;
43 this.extensions = new String[extensions.length];
44 for (int i=0; i<extensions.length; i++) {
45 String ext = extensions[i].toLowerCase();
46 if (ext.charAt(0) == '.') {
47 this.extensions[i] = ext;
49 this.extensions[i] = '.' + ext;
56 public boolean accept(File file) {
59 if (file.isDirectory())
62 String filename = file.getName();
63 filename = filename.toLowerCase();
64 for (String ext: extensions) {
65 if (filename.endsWith(ext))
73 public String getDescription() {