// $Header$
/*
 * Copyright 2001-2004 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */

package org.apache.jmeter.gui;

import java.io.File;
import java.util.Arrays;

/**
 * A file filter which allows files to be filtered based on a list of allowed
 * extensions.
 * 
 * @author unknown
 * @version $Revision$
 */
public class JMeterFileFilter extends javax.swing.filechooser.FileFilter implements java.io.FileFilter {
	/** The list of extensions allowed by this filter. */
	private String[] exts;

	/**
	 * Create a new JMeter file filter which allows the specified extensions. If
	 * the array of extensions contains no elements, any file will be allowed.
	 * 
	 * @param extensions
	 *            non-null array of allowed file extensions
	 */
	public JMeterFileFilter(String[] extensions) {
		exts = extensions;
	}

	/**
	 * Determine if the specified file is allowed by this filter. The file will
	 * be allowed if it is a directory, or if the end of the filename matches
	 * one of the extensions allowed by this filter. The filename is converted
	 * to lower-case before making the comparison.
	 * 
	 * @param f
	 *            the File being tested
	 * 
	 * @return true if the file should be allowed, false otherwise
	 */
	public boolean accept(File f) {
		return f.isDirectory() || accept(f.getName().toLowerCase());
	}

	/**
	 * Determine if the specified filename is allowed by this filter. The file
	 * will be allowed if the end of the filename matches one of the extensions
	 * allowed by this filter. The comparison is case-sensitive. If no
	 * extensions were provided for this filter, the file will always be
	 * allowed.
	 * 
	 * @param filename
	 *            the filename to test
	 * @return true if the file should be allowed, false otherwise
	 */
	public boolean accept(String filename) {
		if (exts.length == 0) {
			return true;
		}

		for (int i = 0; i < exts.length; i++) {
			if (filename.endsWith(exts[i])) {
				return true;
			}
		}

		return false;
	}

	/**
	 * Get a description for this filter.
	 * 
	 * @return a description for this filter
	 */
	public String getDescription() {
		return "JMeter " + Arrays.asList(exts).toString();
	}
}

@@ -1,16 +1,4 @@
-// $Header$%0A
 /*%0A 
@@ -803,46 +803,43 @@
 %0A * 
-@author unknown%0A * @version $Revision$
+Optionally returns directories.%0A * 
 %0A */
@@ -1008,16 +1008,22 @@
 private 
+final 
 String%5B%5D
@@ -1028,16 +1028,90 @@
 %5B%5D exts;
+%0A    %0A    private final boolean allowDirs; // Should we allow directories?
 %0A%0A%09/**%0A%09
@@ -1255,35 +1255,101 @@
 ill be allowed.%0A
-%09 *
+     * %0A%09 * This constructor will also return all directories%0A     * 
  %0A%09 * @param ext
@@ -1470,30 +1470,471 @@
 ) %7B%0A
-%09%09exts = extensions;%0A%09
+        this(extensions,true);%0A%09%7D%0A%0A    /**%0A     * Create a new JMeter file filter which allows the specified extensions. If%0A     * the array of extensions contains no elements, any file will be allowed.%0A     * %0A     * @param extensions non-null array of allowed file extensions%0A     * @param allow should directories be returned ?%0A     */%0A    public JMeterFileFilter(String%5B%5D extensions, boolean allow) %7B%0A        exts = extensions;%0A        allowDirs = allow;%0A    
 %7D%0A%0A%09
@@ -2383,16 +2383,30 @@
 %09%09return
+ (allowDirs &&
  f.isDir
@@ -2413,16 +2413,17 @@
 ectory()
+)
  %7C%7C acce

Add option to exclude directories from the filter