01: package net.sourceforge.squirrel_sql.fw.util;
02:
03: /*
04: * Copyright (C) 2004 Ryan Walberg <generalpf@yahoo.com>
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2.1 of the License, or (at your option) any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: */
20:
21: import javax.swing.filechooser.FileFilter;
22: import java.util.ArrayList;
23: import java.lang.StringBuffer;
24:
25: public class ExtensionFilter extends FileFilter {
26:
27: /* these arrays are parallel. */
28: private ArrayList<String> _descriptions;
29: private ArrayList<String> _extensions;
30:
31: /** Creates a new instance of ExtensionFilter */
32: public ExtensionFilter() {
33: _descriptions = new ArrayList<String>();
34: _extensions = new ArrayList<String>();
35: }
36:
37: public void addExtension(String description, String extension) {
38: _descriptions.add(description);
39: _extensions.add(extension);
40: }
41:
42: public boolean accept(java.io.File f) {
43: if (f.isDirectory())
44: return true;
45: for (int i = 0; i < _extensions.size(); i++) {
46: String ext = _extensions.get(i);
47: if (f.getName().endsWith("." + ext))
48: return true;
49: }
50: return false;
51: }
52:
53: public String getDescription() {
54: StringBuffer buf = new StringBuffer();
55: for (int i = 0; i < _extensions.size(); i++) {
56: buf.append(_descriptions.get(i));
57: buf.append(" (*.");
58: buf.append(_extensions.get(i));
59: buf.append(")");
60: if (i < _extensions.size() - 1)
61: buf.append("; ");
62: }
63: return buf.toString();
64: }
65:
66: }
|