KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > gulden > util > swing > SuffixFileFilter


1 /*
2  * Project: Gulden Utilies
3  * Class: de.gulden.util.swing.SuffixFileFilter
4  * Version: snapshot-beautyj-1.1
5  *
6  * Date: 2004-09-29
7  *
8  * This is a snapshot version of the Gulden Utilities,
9  * it is not released as a seperate version.
10  *
11  * Note: Contains auto-generated Javadoc comments created by BeautyJ.
12  *
13  * This is licensed under the GNU Lesser General Public License (LGPL)
14  * and comes with NO WARRANTY.
15  *
16  * Author: Jens Gulden
17  * Email: amoda@jensgulden.de
18  */

19
20 package de.gulden.util.swing;
21
22 import java.io.File JavaDoc;
23 import java.util.*;
24 import javax.swing.filechooser.FileFilter JavaDoc;
25
26 /**
27  * Class SuffixFileFilter.
28  *
29  * @author Jens Gulden
30  * @version snapshot-beautyj-1.1
31  */

32 public class SuffixFileFilter extends FileFilter JavaDoc {
33
34     // ------------------------------------------------------------------------
35
// --- fields ---
36
// ------------------------------------------------------------------------
37

38     /**
39      * The suffix.
40      */

41     protected String JavaDoc suffix;
42
43     /**
44      * The description.
45      */

46     protected String JavaDoc description;
47
48
49     // ------------------------------------------------------------------------
50
// --- constructors ---
51
// ------------------------------------------------------------------------
52

53     /**
54      * Creates a new instance of SuffixFileFilter.
55      */

56     public SuffixFileFilter() {
57         super();
58     }
59
60     /**
61      * Creates a new instance of SuffixFileFilter.
62      */

63     public SuffixFileFilter(String JavaDoc suffix, String JavaDoc description) {
64         this();
65         this.suffix=suffix;
66         this.description=description;
67     }
68
69
70     // ------------------------------------------------------------------------
71
// --- methods ---
72
// ------------------------------------------------------------------------
73

74     /**
75      * Returns the suffix.
76      */

77     public String JavaDoc getSuffix() {
78         return suffix;
79     }
80
81     /**
82      * Sets the suffix.
83      */

84     public void setSuffix(String JavaDoc _suffix) {
85         suffix = _suffix;
86     }
87
88     /**
89      * Returns the description.
90      */

91     public String JavaDoc getDescription() {
92         return "*."+getSuffix()+" - "+description;
93     }
94
95     /**
96      * Sets the description.
97      */

98     public void setDescription(String JavaDoc _description) {
99         description = _description;
100     }
101
102     public boolean accept(File JavaDoc file) {
103         if (file.isDirectory()) { // must accept to allow user choosing and navigating in directories
104
return true;
105         }
106         String JavaDoc suffix=getSuffix();
107         if ((suffix==null)||suffix.equals("")||suffix.equals("*")) {
108             return true;
109         } else {
110             String JavaDoc f=file.getName();
111             return f.endsWith("."+suffix);
112         }
113     }
114
115 } // end SuffixFileFilter
116
Popular Tags