Commit | Line | Data |
---|---|---|
c2da4d40 JL |
1 | /*\r |
2 | GNU Lesser General Public License\r | |
3 | \r | |
4 | MutableFilter\r | |
5 | Copyright (C) 2000-2002 Howard A Kistler\r | |
6 | \r | |
7 | This library is free software; you can redistribute it and/or\r | |
8 | modify it under the terms of the GNU Lesser General Public\r | |
9 | License as published by the Free Software Foundation; either\r | |
10 | version 2.1 of the License, or (at your option) any later version.\r | |
11 | \r | |
12 | This library is distributed in the hope that it will be useful,\r | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of\r | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r | |
15 | Lesser General Public License for more details.\r | |
16 | \r | |
17 | You should have received a copy of the GNU Lesser General Public\r | |
18 | License along with this library; if not, write to the Free Software\r | |
19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r | |
20 | */\r | |
21 | \r | |
22 | package com.hexidec.util;\r | |
23 | \r | |
24 | import java.io.File;\r | |
25 | import javax.swing.filechooser.FileFilter;\r | |
26 | \r | |
27 | /** Class for providing JFileChooser with a FileFilter\r | |
28 | */\r | |
29 | public class MutableFilter extends FileFilter\r | |
30 | {\r | |
31 | private String[] acceptableExtensions;\r | |
32 | private String descriptor;\r | |
33 | \r | |
34 | public MutableFilter(String[] exts, String desc)\r | |
35 | {\r | |
36 | acceptableExtensions = exts;\r | |
37 | StringBuffer strbDesc = new StringBuffer(desc + " (");\r | |
38 | for(int i = 0; i < acceptableExtensions.length; i++)\r | |
39 | {\r | |
40 | if(i > 0) { strbDesc.append(", "); }\r | |
41 | strbDesc.append("*." + acceptableExtensions[i]);\r | |
42 | }\r | |
43 | strbDesc.append(")");\r | |
44 | descriptor = strbDesc.toString();\r | |
45 | }\r | |
46 | \r | |
47 | public boolean accept(File file)\r | |
48 | {\r | |
49 | if(file.isDirectory())\r | |
50 | {\r | |
51 | return true;\r | |
52 | }\r | |
53 | String fileName = file.getName();\r | |
54 | String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length()).toLowerCase();\r | |
55 | if(fileExt != null)\r | |
56 | {\r | |
57 | for(int i = 0; i < acceptableExtensions.length; i++)\r | |
58 | {\r | |
59 | if(fileExt.equals(acceptableExtensions[i]))\r | |
60 | {\r | |
61 | return true;\r | |
62 | }\r | |
63 | }\r | |
64 | return false;\r | |
65 | }\r | |
66 | else\r | |
67 | {\r | |
68 | return false;\r | |
69 | }\r | |
70 | }\r | |
71 | \r | |
72 | public String getDescription()\r | |
73 | {\r | |
74 | return descriptor;\r | |
75 | }\r | |
76 | }\r | |
77 | \r |