01: /*
02: JSmooth: a VM wrapper toolkit for Windows
03: Copyright (C) 2003 Rodrigo Reyes <reyes@charabia.net>
04:
05: This program is free software; you can redistribute it and/or modify
06: it under the terms of the GNU General Public License as published by
07: the Free Software Foundation; either version 2 of the License, or
08: (at your option) any later version.
09:
10: This program is distributed in the hope that it will be useful,
11: but WITHOUT ANY WARRANTY; without even the implied warranty of
12: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13: GNU General Public License for more details.
14:
15: You should have received a copy of the GNU General Public License
16: along with this program; if not, write to the Free Software
17: Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18:
19: */
20:
21: package net.charabia.jsmoothgen.application.gui.util;
22:
23: import java.util.*;
24:
25: public class GenericFileFilter extends
26: javax.swing.filechooser.FileFilter {
27: private Vector m_suffix = new Vector();;
28: private String m_description;
29:
30: public GenericFileFilter() {
31: m_description = "?";
32: }
33:
34: public GenericFileFilter(String desc) {
35: m_description = desc;
36: }
37:
38: public GenericFileFilter(String suffix, String desc) {
39: m_suffix.add(suffix.toUpperCase());
40: m_description = desc;
41: }
42:
43: public void addSuffix(String suffix) {
44: m_suffix.add(suffix.toUpperCase());
45: }
46:
47: public boolean accept(java.io.File f) {
48: if (f.isDirectory())
49: return true;
50:
51: String suffix = getSuffix(f).toUpperCase();
52: return m_suffix.contains(suffix);
53: }
54:
55: public String getDescription() {
56: return m_description;
57: }
58:
59: private String getSuffix(java.io.File f) {
60: String fstr = f.getAbsolutePath();
61: int lastDot = fstr.lastIndexOf('.');
62: if ((lastDot >= 0) && ((lastDot + 1) < fstr.length())) {
63: return fstr.substring(lastDot + 1);
64: }
65: return "";
66: }
67:
68: }
|