KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > josql > filters > JoSQLSwingFileFilter


1 /*
2  * Copyright 2004-2005 Gary Bentley
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may
5  * not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */

15 package org.josql.filters;
16
17 import java.io.File JavaDoc;
18
19 import javax.swing.filechooser.FileFilter JavaDoc;
20
21 import org.josql.Query;
22 import org.josql.QueryParseException;
23
24 /**
25  * A {@link FileFilter} that uses a JoSQL statement to provide the filtering.
26  * The value returned by the {@link #accept(File)} method is determined by executing the
27  * WHERE clause of a JoSQL statement on each File passed in. This just uses an instance of:
28  * {@link JoSQLFileFilter} to do it's job, see that class for details of usage.
29  * <p>
30  * Last Modified By: $Author: barrygently $<br />
31  * Last Modified On: $Date: 2005/01/07 17:10:40 $<br />
32  * Current Revision: $Revision: 1.1 $<br />
33  */

34 public class JoSQLSwingFileFilter extends FileFilter JavaDoc
35 {
36
37     // Like I'm gonna re-invent the wheel!
38
private JoSQLFileFilter ff = null;
39
40     private String JavaDoc d = null;
41
42     /**
43      * Init this file filter with the query.
44      *
45      * @param q The query.
46      * @throws QueryParseException If there is an issue with the parsing of the query,
47      * or if the FROM class is not {@link File}.
48      */

49     public JoSQLSwingFileFilter (String JavaDoc q)
50                              throws QueryParseException
51     {
52
53     this.ff = new JoSQLFileFilter (q);
54
55     }
56
57     /**
58      * Init this file filter with the query already built and parsed.
59      *
60      * @param q The query.
61      * @throws IllegalStateException If the Query object has not been parsed.
62      * @throws QueryParseException If the FROM class is not {@link File}.
63      */

64     public JoSQLSwingFileFilter (Query q)
65                              throws IllegalStateException JavaDoc,
66                                     QueryParseException
67     {
68
69     this.ff = new JoSQLFileFilter (q);
70
71     }
72
73     /**
74      * Set the JoSQLFileFilter that should be used to handle the {@link #accept(File)} method.
75      *
76      * @param ff The file filter.
77      */

78     public void setJoSQLFileFilter (JoSQLFileFilter ff)
79     {
80
81     this.ff = ff;
82
83     }
84
85     /**
86      * Set the description that should be used.
87      *
88      * @param d The description.
89      */

90     public void setDescription (String JavaDoc d)
91     {
92
93     this.d = d;
94
95     }
96
97     /**
98      * Return the description for the filter.
99      *
100      * @return The description.
101      */

102     public String JavaDoc getDescription ()
103     {
104
105     return this.d;
106
107     }
108
109     /**
110      * Get the file filter being used "under the hoodie" in the {@link #accept(File)} method.
111      * You should also check that file filter to see if an exception has occurred.
112      *
113      * @return The JoSQLFileFilter that is being used to perform the match.
114      */

115     public JoSQLFileFilter getJoSQLFileFilter ()
116     {
117
118     return this.ff;
119
120     }
121
122     /**
123      * Apply the WHERE clause of the statement to the {@link File} passed in.
124      * This is just a wrapper call to: {@link JoSQLFileFilter#accept(File)}.
125      *
126      * @param f The file to evaluate the WHERE on.
127      * @return <code>true</code> if the WHERE clause evaluates to <code>true</code>.
128      */

129     public boolean accept (File JavaDoc f)
130     {
131     
132     return this.ff.accept (f);
133
134     }
135
136 }
137
Popular Tags