KickJava   Java API By Example, From Geeks To Geeks.

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


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.JFileChooser JavaDoc;
21 import javax.swing.filechooser.FileFilter JavaDoc;
22
23 /**
24  * @version 1.0
25  * @author
26  */

27 @SuppressWarnings JavaDoc( { "serial", "serial" })
28 public class cFileChooser extends JFileChooser JavaDoc {
29     private FileFilter JavaDoc selectFilter;
30
31     public cFileChooser() {
32     super();
33     }
34
35     public cFileChooser(File JavaDoc currentDir) {
36     super(currentDir);
37     }
38
39     public void setSelectFilter(FileFilter JavaDoc theSelectFilter) {
40     this.selectFilter = theSelectFilter;
41     }
42
43     @Override JavaDoc
44     public void setSelectedFile(File JavaDoc f) {
45     if (this.selectFilter != null) {
46         if (this.selectFilter.accept(f)) {
47         super.setSelectedFile(f);
48         }
49     }
50     }
51
52     @Override JavaDoc
53     public File JavaDoc getSelectedFile() {
54     File JavaDoc currentDir = super.getCurrentDirectory();
55     File JavaDoc selectedFile = super.getSelectedFile();
56
57     if (selectedFile == null) {
58         return null;
59     }
60
61     return new File JavaDoc(currentDir, selectedFile.getName());
62     }
63
64     public void forceSelectedFile(File JavaDoc f) {
65     super.setSelectedFile(f);
66     }
67 }
68
Popular Tags