1
/* ========================================================================
2
* JCommon : a free general purpose class library for the Java(tm) platform
3
* ========================================================================
5
* (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
7
* Project Info: http://www.jfree.org/jcommon/index.html
9
* This library is free software; you can redistribute it and/or modify it
10
* under the terms of the GNU Lesser General Public License as published by
11
* the Free Software Foundation; either version 2.1 of the License, or
12
* (at your option) any later version.
14
* This library is distributed in the hope that it will be useful, but
15
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17
* License for more details.
19
* You should have received a copy of the GNU Lesser General Public
20
* License along with this library; if not, write to the Free Software
21
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
24
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
25
* in the United States and other countries.]
27
* ------------------------
28
* ExtensionFileFilter.java
29
* ------------------------
30
* (C) Copyright 2000-2004, by Object Refinery Limited.
32
* Original Author: David Gilbert (for Object Refinery Limited);
35
* $Id: FilesystemFilter.java,v 1.5 2005/10/18 13:18:34 mungady Exp $
37
* Changes (from 26-Oct-2001)
38
* --------------------------
39
* 01-Jun-2005 : Updated javadoc.
44
import java.io.FilenameFilter;
45
import javax.swing.filechooser.FileFilter;
48
* A filesystem filter.
50
* @author David Gilbert
52
public class FilesystemFilter extends FileFilter implements FilenameFilter {
54
/** The file extension, which should be accepted. */
55
private String[] fileext;
56
/** The filter description. */
58
/** A flag indicating whether to accept directories. */
59
private boolean accDirs;
62
* Creates a new filter.
64
* @param fileext the file extension.
65
* @param descr the description.
67
public FilesystemFilter(final String fileext, final String descr) {
68
this(fileext, descr, true);
72
* Creates a new filter.
74
* @param fileext the file extension.
75
* @param descr the description.
76
* @param accDirs accept directories?
78
public FilesystemFilter(final String fileext, final String descr,
79
final boolean accDirs) {
80
this(new String[]{fileext}, descr, accDirs);
84
* Creates a new filter.
86
* @param fileext the file extension.
87
* @param descr the description.
88
* @param accDirs accept directories?
89
* @throws NullPointerException if the file extensions are null.
91
public FilesystemFilter(final String[] fileext, final String descr,
92
final boolean accDirs) {
93
this.fileext = (String[]) fileext.clone();
95
this.accDirs = accDirs;
100
* Returns <code>true</code> if the file is accepted, and <code>false</code> otherwise.
102
* @param dir the directory.
103
* @param name the file name.
106
public boolean accept(final File dir, final String name) {
107
final File f = new File(dir, name);
108
if (f.isDirectory() && acceptsDirectories()) {
112
for (int i = 0; i < fileext.length; i++) {
113
if (name.endsWith(this.fileext[i])) {
121
* Returns <code>true</code> if the specified file matches the requirements of this
122
* filter, and <code>false</code> otherwise.
124
* @param dir the file or directory.
127
public boolean accept(final File dir) {
128
if (dir.isDirectory() && acceptsDirectories()) {
132
for (int i = 0; i < fileext.length; i++) {
133
if (dir.getName().endsWith(this.fileext[i])) {
141
* Returns the filter description.
143
* @return The filter description.
145
public String getDescription() {
150
* Sets the flag that controls whether or not the filter accepts directories.
152
* @param b a boolean.
154
public void acceptDirectories(final boolean b) {
159
* Returns the flag that indicates whether or not the filter accepts directories.
163
public boolean acceptsDirectories() {