1 package org.catacomb.druid.swing;
2
3 import java.io.File;
4 import java.util.HashMap;
5
6 import javax.swing.JFileChooser;
7
8
9 public final class DFileChooser extends JFileChooser {
10 static final long serialVersionUID = 1001;
11
12 ExtFileFilter defaultFilter;
13
14 HashMap<String, ExtFileFilter> filters = new HashMap<String, ExtFileFilter>();
15
16
17 public DFileChooser() {
18
19 setFileSelectionMode(FILES_ONLY);
20
21 }
22
23
24 public void addExtensionFilter(String ext, String desc) {
25 if (filters.containsKey(ext)) {
26
27 } else {
28 ExtFileFilter eff = new ExtFileFilter(ext, desc);
29 filters.put(ext, eff);
30 addChoosableFileFilter(eff);
31 if (defaultFilter == null) {
32 defaultFilter = eff;
33 }
34 }
35 setFileFilter(filters.get(ext));
36 }
37
38
39 public void setFilter(String ext) {
40 setFileFilter(filters.get(ext));
41 }
42
43
44
45
46 public void setSelectFiles() {
47 setFileSelectionMode(FILES_ONLY);
48 }
49
50 public void setSelectDirectories() {
51 setFileSelectionMode(DIRECTORIES_ONLY);
52 }
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70 public void setRootDirectory(File f) {
71 if (f != null && f.isDirectory()) {
72 setCurrentDirectory(f);
73 }
74
75 }
76
77 }
78
79