KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > tool > common > FilenameFilter


1
2 /*
3  * Enhydra Java Application Server Project
4  *
5  * The contents of this file are subject to the Enhydra Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License on
8  * the Enhydra web site ( http://www.enhydra.org/ ).
9  *
10  * Software distributed under the License is distributed on an "AS IS"
11  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12  * the License for the specific terms governing rights and limitations
13  * under the License.
14  *
15  * The Initial Developer of the Enhydra Application Server is Lutris
16  * Technologies, Inc. The Enhydra Application Server and portions created
17  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
18  * All Rights Reserved.
19  *
20  * Contributor(s):
21  * Paul Mahar
22  *
23  */

24 package org.enhydra.tool.common;
25
26 // JDK
27
import java.io.File JavaDoc;
28 import javax.swing.filechooser.FileFilter JavaDoc;
29
30 /**
31  * An implementation of FileFilter that filters out all files
32  * except for those matching a set of given extensions.
33  */

34 public class FilenameFilter extends FileFilter JavaDoc
35     implements java.io.FileFilter JavaDoc {
36     private String JavaDoc includeName = new String JavaDoc();
37     private String JavaDoc descTitle = new String JavaDoc();
38     private boolean directoryValid = true;
39     private boolean excludeOnly = false;
40
41     /**
42      * Creates an extension file filter without an extensions set.
43      */

44     public FilenameFilter() {}
45
46     /**
47      * Return true if this file should be shown in a file chooser.
48      */

49     public boolean accept(File JavaDoc f) {
50         boolean acceptFile = false;
51         PathHandle handle = null;
52
53         if (f == null) {
54             acceptFile = true;
55         } else if (f.isDirectory()) {
56             acceptFile = isDirectoryValid();
57         } else {
58             handle = PathHandle.createPathHandle(f);
59             acceptFile = handle.endsWith(File.separator + includeName);
60         }
61         return acceptFile;
62     }
63
64     /**
65      * Returns the human readable description of this filter.
66      */

67     public String JavaDoc getDescription() {
68         StringBuffer JavaDoc desc = new StringBuffer JavaDoc();
69
70         desc.append(getDescriptionTitle());
71         desc.append(' ');
72         desc.append('(');
73         desc.append(includeName);
74         desc.append(')');
75         return desc.toString();
76     }
77
78     /**
79      * Sets the portion of the description that does not
80      * include extensions.
81      */

82     public void setDescriptionTitle(String JavaDoc d) {
83         this.descTitle = d;
84     }
85
86     /**
87      * Gets the portion of the description that does not
88      * include extensions.
89      */

90     public String JavaDoc getDescriptionTitle() {
91         return descTitle;
92     }
93
94     public void setDirectoryValid(boolean valid) {
95         directoryValid = valid;
96     }
97
98     public boolean isDirectoryValid() {
99         return directoryValid;
100     }
101
102     public void setIncludeName(String JavaDoc n) {
103         includeName = n;
104     }
105
106     public String JavaDoc getIncludeName() {
107         return includeName;
108     }
109
110
111
112 }
113
Popular Tags