|
What this is
Other links
The source code// $Header: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/gui/JMeterFileFilter.java,v 1.4 2004/02/13 02:21:37 sebb Exp $ /* * 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: 1.4 $ */ 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(); } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.