1 package net.sf.openrocket.gui.util;
4 import java.util.Locale;
6 import javax.swing.filechooser.FileFilter;
9 * A FileFilter similar to FileNameExtensionFilter except that
10 * it allows multipart extensions (.ork.gz), and also implements
11 * the java.io.FileFilter interface.
13 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
15 public class SimpleFileFilter extends FileFilter implements java.io.FileFilter {
17 private final String description;
18 private final boolean acceptDir;
19 private final String[] extensions;
23 * Create filter that accepts files with the provided extensions that
24 * accepts directories as well.
26 * @param description the description of this file filter.
27 * @param extensions an array of extensions that match this filter.
29 public SimpleFileFilter(String description, String... extensions) {
30 this(description, true, extensions);
35 * Create filter that accepts files with the provided extensions.
37 * @param description the description of this file filter.
38 * @param acceptDir whether to accept directories
39 * @param extensions an array of extensions that match this filter.
41 public SimpleFileFilter(String description, boolean acceptDir, String... extensions) {
42 this.description = description;
43 this.acceptDir = acceptDir;
44 this.extensions = new String[extensions.length];
45 for (int i = 0; i < extensions.length; i++) {
46 String ext = extensions[i].toLowerCase(Locale.ENGLISH);
47 if (ext.charAt(0) == '.') {
48 this.extensions[i] = ext;
50 this.extensions[i] = '.' + ext;
57 public boolean accept(File file) {
60 if (file.isDirectory())
63 String filename = file.getName();
64 filename = filename.toLowerCase(Locale.ENGLISH);
65 for (String ext : extensions) {
66 if (filename.endsWith(ext))
74 public String getDescription() {