Initial revision
[old-projects.git] / ekit / com / hexidec / util / MutableFilter.java
diff --git a/ekit/com/hexidec/util/MutableFilter.java b/ekit/com/hexidec/util/MutableFilter.java
new file mode 100644 (file)
index 0000000..bbeb3fc
--- /dev/null
@@ -0,0 +1,77 @@
+/*\r
+GNU Lesser General Public License\r
+\r
+MutableFilter\r
+Copyright (C) 2000-2002  Howard A Kistler\r
+\r
+This library is free software; you can redistribute it and/or\r
+modify it under the terms of the GNU Lesser General Public\r
+License as published by the Free Software Foundation; either\r
+version 2.1 of the License, or (at your option) any later version.\r
+\r
+This library is distributed in the hope that it will be useful,\r
+but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
+Lesser General Public License for more details.\r
+\r
+You should have received a copy of the GNU Lesser General Public\r
+License along with this library; if not, write to the Free Software\r
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
+*/\r
+\r
+package com.hexidec.util;\r
+\r
+import java.io.File;\r
+import javax.swing.filechooser.FileFilter;\r
+\r
+/** Class for providing JFileChooser with a FileFilter\r
+  */\r
+public class MutableFilter extends FileFilter\r
+{\r
+       private String[] acceptableExtensions;\r
+       private String descriptor;\r
+\r
+       public MutableFilter(String[] exts, String desc)\r
+       {\r
+               acceptableExtensions = exts;\r
+               StringBuffer strbDesc = new StringBuffer(desc + " (");\r
+               for(int i = 0; i < acceptableExtensions.length; i++)\r
+               {\r
+                       if(i > 0) { strbDesc.append(", "); }\r
+                       strbDesc.append("*." + acceptableExtensions[i]);\r
+               }\r
+               strbDesc.append(")");\r
+               descriptor = strbDesc.toString();\r
+       }\r
+\r
+       public boolean accept(File file)\r
+       {\r
+               if(file.isDirectory())\r
+               {\r
+                       return true;\r
+               }\r
+               String fileName = file.getName();\r
+               String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length()).toLowerCase();\r
+               if(fileExt != null)\r
+               {\r
+                       for(int i = 0; i < acceptableExtensions.length; i++)\r
+                       {\r
+                               if(fileExt.equals(acceptableExtensions[i]))\r
+                               {\r
+                                       return true;\r
+                               }\r
+                       }\r
+                       return false;\r
+               }\r
+               else\r
+               {\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       public String getDescription()\r
+       {\r
+               return descriptor;\r
+       }\r
+}\r
+\r