KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > qfs > apps > qflog > logview > LogFileFilter


1 // {{{ copyright
2

3 /********************************************************************
4  *
5  * $Id: LogFileFilter.java,v 1.4 2000/07/05 14:07:44 gs Exp $
6  *
7  * The contents of this file are subject to the Mozilla Public
8  * License Version 1.1 (the "License"); you may not use this file
9  * except in compliance with the License. You may obtain a copy of
10  * the License at http://www.mozilla.org/MPL/
11  *
12  * Software distributed under the License is distributed on an "AS
13  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
14  * implied. See the License for the specific language governing
15  * rights and limitations under the License.
16  *
17  * The Original Code is qfs.de code.
18  *
19  * The Initial Developer of the Original Code is Gregor Schmid.
20  * Portions created by Gregor Schmid are
21  * Copyright (C) 1999 Quality First Software, Gregor Schmid.
22  * All Rights Reserved.
23  *
24  * Contributor(s):
25  *
26  *******************************************************************/

27
28 // }}}
29

30 package de.qfs.apps.qflog.logview;
31
32 // {{{ imports
33

34 import java.io.File JavaDoc;
35 import javax.swing.filechooser.FileFilter JavaDoc;
36
37 // }}}
38

39 /**
40  * File filter for log and configuration files.
41  *
42  * @author Gregor Schmid
43  * @version $Revision: 1.4 $
44  */

45 public class LogFileFilter
46     extends FileFilter JavaDoc
47 {
48     // {{{ variables
49

50     /**
51      * The description for the LogFileFilter.
52      */

53     private String JavaDoc desc;
54
55     /**
56      * The extensions to accept.
57      */

58     private String JavaDoc[] ext;
59
60     // }}}
61

62     // {{{ constructors
63

64     /**
65      * Create a new LogFileFilter.
66      *
67      * @param desc The description for the LogFileFilter.
68      * @param ext The extension to accept.
69      */

70     public LogFileFilter (String JavaDoc desc, String JavaDoc ext)
71     {
72         this.ext = new String JavaDoc[] {ext};
73         this.desc = desc;
74     }
75
76     /**
77      * Create a new LogFileFilter.
78      *
79      * @param desc The description for the LogFileFilter.
80      * @param ext The extensions to accept.
81      */

82     public LogFileFilter (String JavaDoc desc, String JavaDoc[] multi)
83     {
84         this.ext = multi;
85         this.desc = desc;
86     }
87
88     // }}}
89

90     // {{{ accept
91

92     /**
93      * Accept or reject a file.
94      *
95      * @param file The file to test.
96      *
97      * @return True if the file's extension matches one of the
98      * LogFileFilter's extensions.
99      */

100     public boolean accept(File JavaDoc file)
101     {
102         if (file.isDirectory()) {
103             return true;
104         }
105         for (int i = 0; i < ext.length; i++) {
106             if (file.getName().endsWith(ext[i])) {
107                 return true;
108             }
109         }
110         return false;
111     }
112
113     // }}}
114
// {{{ getDescription
115

116     /**
117      * Get a description for the LogFileFilter.
118      *
119      * @return The LogFileFilter's description.
120      */

121     public String JavaDoc getDescription()
122     {
123         return desc;
124     }
125
126     // }}}
127
// {{{ forceExtension
128

129     /**
130      * Ensure that a file has the proper extension for the LogFileFilter.
131      *
132      * @param file The file to correct.
133      *
134      * @return The correct file.
135      */

136     public File JavaDoc forceExtension(File JavaDoc file)
137     {
138         if (file.getName().endsWith(ext[0])) {
139             return file;
140         }
141         return new File JavaDoc(file.getPath() + ext[0]);
142     }
143
144     // }}}
145
}
146
Popular Tags