From e67588afd890cb74a529a4f69c076456725fead7 Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Fri, 18 Mar 2005 16:08:11 +0000 Subject: [PATCH] new class --- src/jalview/io/JalviewFileFilter.java | 118 +++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100755 src/jalview/io/JalviewFileFilter.java diff --git a/src/jalview/io/JalviewFileFilter.java b/src/jalview/io/JalviewFileFilter.java new file mode 100755 index 0000000..85ac084 --- /dev/null +++ b/src/jalview/io/JalviewFileFilter.java @@ -0,0 +1,118 @@ +package jalview.io; + +import javax.swing.filechooser.*; +import java.io.File; +import java.util.*; + +public class JalviewFileFilter extends FileFilter +{ + private static String TYPE_UNKNOWN = "Type Unknown"; + private static String HIDDEN_FILE = "Hidden File"; + public static Hashtable suffixHash = new Hashtable(); + + private Hashtable filters = null; + private String description = "no description"; + private String fullDescription = "full description"; + private boolean useExtensionsInDescription = true; + + public JalviewFileFilter() { + this.filters = new Hashtable(); + } + + public JalviewFileFilter(String extension) { + this(extension,null); + } + + public JalviewFileFilter(String extension, String description) { + this(); + if(extension!=null) addExtension(extension); + if(description!=null) setDescription(description); + } + + public JalviewFileFilter(String[] filts) { + this(filts, null); + } + + public JalviewFileFilter(String[] filts, String description) { + this(); + for (int i = 0; i < filts.length; i++) { + // add filters one by one + addExtension(filts[i]); + } + if(description!=null) setDescription(description); + } + + // takes account of the fact that database is a directory + public boolean accept(File f) { + if(f != null) { + String extension = getExtension(f); + if(f.isDirectory()) { + if(extension == null || extension.equals("")) { + return true; + } else { + if(filters.get(getExtension(f)) != null) { + return true; + } + } + } + if(extension != null && filters.get(getExtension(f)) != null) { + return true; + } + } + return false; + } + + public String getExtension(File f) { + if(f != null) { + String filename = f.getName(); + int i = filename.lastIndexOf('.'); + if(i>0 && i