01: /*
02: * SQLeonardo :: java database frontend
03: * Copyright (C) 2004 nickyb@users.sourceforge.net
04: *
05: * This program is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU General Public License
07: * as published by the Free Software Foundation; either version 2
08: * of the License, or (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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18: *
19: */
20:
21: package nickyb.sqleonardo.common.gui;
22:
23: import java.io.File;
24:
25: import javax.swing.JFileChooser;
26: import javax.swing.filechooser.FileFilter;
27: import javax.swing.plaf.basic.BasicFileChooserUI;
28:
29: public abstract class AbstractMaskChooser extends JFileChooser {
30: public AbstractMaskChooser(int type, int mode, boolean showAllFiles) {
31: setBorder(null);
32: setDialogType(type);
33: setFileSelectionMode(mode);
34: setControlButtonsAreShown(false);
35: setAcceptAllFileFilterUsed(showAllFiles);
36: }
37:
38: protected void fireApproveSelection() {
39: if (this .getUI() instanceof BasicFileChooserUI) {
40: ((BasicFileChooserUI) this .getUI())
41: .getApproveSelectionAction().actionPerformed(null);
42: }
43: }
44:
45: public File getSelectedFile() {
46: fireApproveSelection();
47: return super .getSelectedFile();
48: }
49:
50: public short getPerformType() {
51: return ((AbstractFileFilter) getFileFilter()).getPerformType();
52: }
53:
54: public static abstract class AbstractFileFilter extends FileFilter {
55: String description;
56: String[] extensions;
57:
58: public AbstractFileFilter(String description,
59: String[] extensions) {
60: this .description = description;
61: this .extensions = extensions;
62: }
63:
64: public boolean accept(File file) {
65: if (file.isDirectory())
66: return true;
67:
68: for (int i = 0; i < extensions.length; i++)
69: if (file.getName().toLowerCase().endsWith(
70: extensions[i].toLowerCase()))
71: return true;
72:
73: return false;
74: }
75:
76: public String getDescription() {
77: return description;
78: }
79:
80: public abstract short getPerformType();
81: }
82: }
|