1 /*
2 * XNap - A P2P framework and client.
3 *
4 * See the file AUTHORS for copyright information.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation.
9 *
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 package org.xnap.io;
21
22 import java.io.File;
23 import java.io.FileFilter;
24
25 import org.xnap.XNap;
26
27 /***
28 * Provides a <code>FileFilter</code> that accepts a certain file
29 * extension only.
30 */
31 public class FileExtensionFilter extends javax.swing.filechooser.FileFilter
32 implements FileFilter
33 {
34
35 //--- Constant(s) ---
36
37 //--- Data field(s) ---
38
39 private String ext;
40 private String description;
41
42 //--- Constructor(s) ---
43
44 public FileExtensionFilter(String ext, String description)
45 {
46 this.ext = ext;
47 this.description = XNap.tr("{0} Files (*.{1})", description, ext);
48 }
49
50 public FileExtensionFilter(String ext)
51 {
52 this(ext, ext.toUpperCase());
53 }
54
55 //--- Method(s) ---
56
57 public boolean accept(File file)
58 {
59 return file.isDirectory() || file.getName().endsWith(ext);
60 }
61
62 public String getDescription()
63 {
64 return description;
65 }
66
67 }
68