01: package org.dbbrowser.ui.helper;
02:
03: import java.io.File;
04: import java.util.StringTokenizer;
05: import javax.swing.filechooser.FileFilter;
06:
07: /**
08: * A file filter used to show only 'ConnectionInfo' xml files
09: * @author amangat
10: */
11: public class ConnectionInfoFileFilter extends FileFilter {
12: /**
13: * Returns true if the File 'f' is not a directory and the filename ends with '.xml'
14: * @param f
15: * @return
16: */
17: public boolean accept(File f) {
18: boolean acceptSelectedFile = false;
19:
20: if (f.isFile()) {
21: String filename = f.getName();
22:
23: //Get the extension
24: StringTokenizer st = new StringTokenizer(filename, ".");
25: String lastToken = null;
26: while (st.hasMoreTokens()) {
27: lastToken = st.nextToken();
28: }
29:
30: if ((lastToken != null) && (lastToken.equals("xml"))) {
31: acceptSelectedFile = true;
32: }
33: } else {
34: acceptSelectedFile = true;
35: }
36:
37: return acceptSelectedFile;
38: }
39:
40: /**
41: * Returns the description for use in the UI
42: * @return
43: */
44: public String getDescription() {
45: return "*.xml";
46: }
47: }
|