KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > launch4j > FileChooserFilter


1 /*
2     Launch4j (http://launch4j.sourceforge.net/)
3     Cross-platform Java application wrapper for creating Windows native executables.
4
5     Copyright (C) 2004, 2006 Grzegorz Kowal
6
7     This program is free software; you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation; either version 2 of the License, or
10     (at your option) any later version.
11
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     GNU General Public License for more details.
16
17     You should have received a copy of the GNU General Public License
18     along with this program; if not, write to the Free Software
19     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */

21
22 /*
23  * Created on 2004-01-15
24  */

25 package net.sf.launch4j;
26
27 import java.io.File JavaDoc;
28
29 import javax.swing.filechooser.FileFilter JavaDoc;
30
31 /**
32  * @author Copyright (C) 2004 Grzegorz Kowal
33  */

34 public class FileChooserFilter extends FileFilter JavaDoc {
35     String JavaDoc _description;
36     String JavaDoc[] _extensions;
37
38     public FileChooserFilter(String JavaDoc description, String JavaDoc extension) {
39         _description = description;
40         _extensions = new String JavaDoc[] {extension};
41     }
42     
43     public FileChooserFilter(String JavaDoc description, String JavaDoc[] extensions) {
44         _description = description;
45         _extensions = extensions;
46     }
47
48     public boolean accept(File JavaDoc f) {
49         if (f.isDirectory()) {
50             return true;
51         }
52         String JavaDoc ext = Util.getExtension(f);
53         for (int i = 0; i < _extensions.length; i++) {
54             if (ext.toLowerCase().equals(_extensions[i].toLowerCase())) {
55                 return true;
56             }
57         }
58         return false;
59     }
60
61     public String JavaDoc getDescription() {
62         return _description;
63     }
64 }
65
Popular Tags