Debian Codegraph @

src/dr/app/bss/SimpleFileFilter.java

raw symbols SCIP
1 /*
2 * SimpleFileFilter.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package dr.app.bss;
27
28 import java.io.File;
29
30 import javax.swing.filechooser.FileFilter;
31
32 /**
33 * @author Filip Bielejec
34 * @version $Id$
35 */
36 public class SimpleFileFilter extends FileFilter {
37
38 private String[] extensions;
39 private String description;
40
41 public SimpleFileFilter(String ext) {
42 this(new String[] { ext }, null);
43 }
44
45 public SimpleFileFilter(String[] exts, String descr) {
46
47 // clone and lowercase the extensions
48 extensions = new String[exts.length];
49 for (int i = exts.length - 1; i >= 0; i--) {
50 extensions[i] = exts[i].toLowerCase();
51 }
52
53 // make sure we have a valid (if simplistic) description
54 description = (descr == null ? exts[0] + " files" : descr);
55 }
56
57 public boolean accept(File f) {
58
59 // we always allow directories, regardless of their extension
60 if (f.isDirectory()) {
61 return true;
62 }
63
64 // ok, it's a regular file so check the extension
65 String name = f.getName().toLowerCase();
66 for (int i = extensions.length - 1; i >= 0; i--) {
67 if (name.endsWith(extensions[i])) {
68 return true;
69 }
70 }
71 return false;
72 }
73
74 public String getDescription() {
75 return description;
76 }
77
78 }// END: class