01: //The contents of this file are subject to the Mozilla Public License Version 1.1
02: //(the "License"); you may not use this file except in compliance with the
03: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
04: //
05: //Software distributed under the License is distributed on an "AS IS" basis,
06: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
07: //for the specific language governing rights and
08: //limitations under the License.
09: //
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;
19:
20: import javax.swing.filechooser.FileFilter;
21:
22: public class cFileFilter extends FileFilter {
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
39: public boolean accept(File 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
73: public String getDescription() {
74: //TODO externalize string
75: return new String("Columba File Filter"); //$NON-NLS-1$
76: }
77: }
|