001: /*
002: * Project: Gulden Utilies
003: * Class: de.gulden.util.swing.SuffixFileFilter
004: * Version: snapshot-beautyj-1.1
005: *
006: * Date: 2004-09-29
007: *
008: * This is a snapshot version of the Gulden Utilities,
009: * it is not released as a seperate version.
010: *
011: * Note: Contains auto-generated Javadoc comments created by BeautyJ.
012: *
013: * This is licensed under the GNU Lesser General Public License (LGPL)
014: * and comes with NO WARRANTY.
015: *
016: * Author: Jens Gulden
017: * Email: amoda@jensgulden.de
018: */
019:
020: package de.gulden.util.swing;
021:
022: import java.io.File;
023: import java.util.*;
024: import javax.swing.filechooser.FileFilter;
025:
026: /**
027: * Class SuffixFileFilter.
028: *
029: * @author Jens Gulden
030: * @version snapshot-beautyj-1.1
031: */
032: public class SuffixFileFilter extends FileFilter {
033:
034: // ------------------------------------------------------------------------
035: // --- fields ---
036: // ------------------------------------------------------------------------
037:
038: /**
039: * The suffix.
040: */
041: protected String suffix;
042:
043: /**
044: * The description.
045: */
046: protected String description;
047:
048: // ------------------------------------------------------------------------
049: // --- constructors ---
050: // ------------------------------------------------------------------------
051:
052: /**
053: * Creates a new instance of SuffixFileFilter.
054: */
055: public SuffixFileFilter() {
056: super ();
057: }
058:
059: /**
060: * Creates a new instance of SuffixFileFilter.
061: */
062: public SuffixFileFilter(String suffix, String description) {
063: this ();
064: this .suffix = suffix;
065: this .description = description;
066: }
067:
068: // ------------------------------------------------------------------------
069: // --- methods ---
070: // ------------------------------------------------------------------------
071:
072: /**
073: * Returns the suffix.
074: */
075: public String getSuffix() {
076: return suffix;
077: }
078:
079: /**
080: * Sets the suffix.
081: */
082: public void setSuffix(String _suffix) {
083: suffix = _suffix;
084: }
085:
086: /**
087: * Returns the description.
088: */
089: public String getDescription() {
090: return "*." + getSuffix() + " - " + description;
091: }
092:
093: /**
094: * Sets the description.
095: */
096: public void setDescription(String _description) {
097: description = _description;
098: }
099:
100: public boolean accept(File file) {
101: if (file.isDirectory()) { // must accept to allow user choosing and navigating in directories
102: return true;
103: }
104: String suffix = getSuffix();
105: if ((suffix == null) || suffix.equals("") || suffix.equals("*")) {
106: return true;
107: } else {
108: String f = file.getName();
109: return f.endsWith("." + suffix);
110: }
111: }
112:
113: } // end SuffixFileFilter
|