View Javadoc
1 /***
2 * MyFileFilter.java
3 *
4 * Project: Dependency Tool
5 *
6 * WHEN WHO WHAT
7 * 06.06.2003 pko initial public release
8 * 20.01.2003 pko modification
9 * 10.12.2002 pko creation
10 *
11 * Copyright 2003 ELCA Informatique SA
12 * Av. de la Harpe 22-24, 1000 Lausanne 13, Switzerland
13 * www.elca.ch
14 *
15 * This library is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU Lesser General Public License
17 * as published by the Free Software Foundation; either version 2.1 of
18 * the License, or (at your option) any later version.
19 *
20 * This library is distributed in the hope that it will be useful, but
21 * WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
24 *
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
28 * USA
29 */
30
31 package ch.elca.dependency.gui;
32
33 import java.io.File;
34 import java.util.Hashtable;
35 import javax.swing.filechooser.FileFilter;
36
37 /***
38 * A FileFilter used for JFileOpenDialogs within the DependencyTool.
39 *
40 * @author Pawel Kowalski
41 * @version 1.0-beta
42 */
43 public class MyFileFilter extends FileFilter {
44
45 //*********************************************************************************/
46 // public static part
47 //*********************************************************************************/
48
49 private static Hashtable s_fileFilters = new Hashtable();
50
51 /***
52 * Get a FileFilter accepting files with the specified extension.
53 *
54 * @param extension a <code>String</code> value
55 * @return a <code>FileFilter</code> value
56 */
57 public static synchronized FileFilter getFileFilter(String extension) {
58 if (s_fileFilters.containsKey(extension)) {
59 return (FileFilter)s_fileFilters.get(extension);
60 }
61 FileFilter fileFilter = new MyFileFilter(extension);
62 s_fileFilters.put(extension, fileFilter);
63 return fileFilter;
64 }
65
66 //*********************************************************************************/
67 // dynamic FileFilter part
68 //*********************************************************************************/
69
70 private String m_extension = null;
71
72 /***
73 * Creates a new <code>MyFileFilter</code> instance.
74 *
75 * @param extension a <code>String</code> value
76 */
77 private MyFileFilter(String extension) {
78 m_extension = extension;
79 }
80
81 /***
82 * Accept a file and return whether it's to be displayed.
83 *
84 * @param file a <code>File</code> value
85 * @return a <code>boolean</code> value
86 */
87 public boolean accept(File file) {
88 return file.getName().endsWith("." + m_extension) || file.isDirectory();
89 }
90
91 /***
92 * Get description for this FileFilter.
93 *
94 * @return a <code>String</code> value
95 */
96 public String getDescription() {
97 return m_extension.toUpperCase() + " files (*." + m_extension + ")";
98 }
99 }
This page was automatically generated by Maven