001 package jigcell.compare.impl;
002
003 import java.io.File;
004 import javax.swing.filechooser.FileFilter;
005
006 /**
007 * A file filter that matches against a given suffix string.
008 *
009 * <p>
010 * This code is licensed under the DARPA BioCOMP Open Source License. See LICENSE for more details.
011 * </p>
012 *
013 * @author Nicholas Allen
014 */
015
016 public final class SuffixFileFilter extends FileFilter {
017
018 /**
019 * Description of this filter
020 */
021
022 private String description;
023
024 /**
025 * File suffix to match against
026 */
027
028 private String suffix;
029
030 /**
031 * Creates a new file filter.
032 */
033
034 public SuffixFileFilter () {}
035
036 /**
037 * Creates a new file filter.
038 *
039 * @param suffix Suffix to filter
040 * @param description Description of this filter
041 */
042
043 public SuffixFileFilter (String suffix, String description) {
044 this.suffix = suffix;
045 this.description = description;
046 }
047
048 public synchronized boolean accept (File f) {
049 return f.isDirectory () || f.getName ().endsWith (suffix);
050 }
051
052 public String getDescription () {
053 return description;
054 }
055
056 /**
057 * The file suffix to match against.
058 */
059
060 public String getSuffix () {
061 return suffix;
062 }
063
064 /**
065 * Sets the description of this filter.
066 *
067 * @param description Description
068 */
069
070 public synchronized void setDescription (String description) {
071 this.description = description;
072 }
073
074 /**
075 * Sets the file suffix to match against.
076 *
077 * @param suffix Suffix
078 */
079
080 public synchronized void setSuffix (String suffix) {
081 this.suffix = suffix;
082 }
083 }