KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > base > cFileFilter


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
10
//The Original Code is "The Columba Project"
11
//
12
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14
//
15
//All Rights Reserved.
16
package org.columba.core.base;
17
18 import java.io.File JavaDoc;
19
20 import javax.swing.filechooser.FileFilter JavaDoc;
21
22 public class cFileFilter extends FileFilter JavaDoc {
23     public static final int FILEPROPERTY_FILE = 0x0001;
24
25     public static final int FILEPROPERTY_DIRECTORY = 0x0002;
26
27     public static final int FILEPROPERTY_HIDDEN = 0x0004;
28
29     private int property;
30
31     public cFileFilter() {
32     this.property = 0x0000; // Check for no property
33
}
34
35     /**
36          * @see FileFilter#accept(File)
37          */

38     @Override JavaDoc
39     public boolean accept(File JavaDoc f) {
40     boolean result = true;
41
42     if (f == null) {
43         return false;
44     }
45
46     if (!f.exists()) {
47         return true; // return true for new files
48
}
49
50     if ((this.property & FILEPROPERTY_FILE) > 0) {
51         result = result && f.isFile();
52     }
53
54     if ((this.property & FILEPROPERTY_DIRECTORY) > 0) {
55         result = result && f.isDirectory();
56     }
57
58     if ((this.property & FILEPROPERTY_HIDDEN) > 0) {
59         result = result && f.isHidden();
60     }
61
62     return result;
63     }
64
65     public void acceptFilesWithProperty(int newprop) {
66     this.property = newprop;
67     }
68
69     /**
70          * @see FileFilter#getDescription()
71          */

72     @Override JavaDoc
73     public String JavaDoc getDescription() {
74     //TODO externalize string
75
return new String JavaDoc("Columba File Filter"); //$NON-NLS-1$
76
}
77 }
78
Popular Tags