|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| package edu.rice.cs.drjava.ui.config; |
|
38 |
| |
|
39 |
| |
|
40 |
| import java.awt.event.*; |
|
41 |
| import java.io.File; |
|
42 |
| import javax.swing.filechooser.FileFilter; |
|
43 |
| import javax.swing.*; |
|
44 |
| |
|
45 |
| import java.util.Vector; |
|
46 |
| import java.util.List; |
|
47 |
| |
|
48 |
| import edu.rice.cs.drjava.ui.*; |
|
49 |
| import edu.rice.cs.drjava.config.*; |
|
50 |
| import edu.rice.cs.util.swing.SwingFrame; |
|
51 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| public class VectorFileOptionComponent extends VectorOptionComponent<File> implements OptionConstants { |
|
57 |
| private JFileChooser _jfc; |
|
58 |
| protected File _baseDir = null; |
|
59 |
| |
|
60 |
3
| public VectorFileOptionComponent(VectorOption<File> opt, String text, SwingFrame parent) {
|
|
61 |
3
| this(opt, text, parent, null);
|
|
62 |
| } |
|
63 |
| |
|
64 |
| |
|
65 |
3
| public VectorFileOptionComponent(VectorOption<File> opt, String text, SwingFrame parent, String description) {
|
|
66 |
3
| this(opt, text, parent, description, false);
|
|
67 |
| } |
|
68 |
| |
|
69 |
| |
|
70 |
79
| public VectorFileOptionComponent(VectorOption<File> opt, String text, SwingFrame parent,
|
|
71 |
| String description, boolean moveButtonEnabled) { |
|
72 |
79
| super(opt, text, parent, new String[] { }, description, moveButtonEnabled);
|
|
73 |
| |
|
74 |
| |
|
75 |
79
| File workDir = new File(System.getProperty("user.home"));
|
|
76 |
| |
|
77 |
79
| _jfc = new JFileChooser(workDir);
|
|
78 |
79
| _jfc.setDialogTitle("Select");
|
|
79 |
79
| _jfc.setApproveButtonText("Select");
|
|
80 |
79
| _jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
|
|
81 |
79
| _jfc.setMultiSelectionEnabled(true);
|
|
82 |
79
| _jfc.setFileFilter(ClassPathFilter.ONLY);
|
|
83 |
| } |
|
84 |
| |
|
85 |
| |
|
86 |
0
| public void setBaseDir(File f) {
|
|
87 |
0
| if (f.isDirectory()) { _baseDir = f; }
|
|
88 |
| } |
|
89 |
| |
|
90 |
| |
|
91 |
0
| public void chooseFile() {
|
|
92 |
0
| int[] rows = _table.getSelectedRows();
|
|
93 |
0
| File selection = (rows.length==1)?_data.get(rows[0]):null;
|
|
94 |
0
| if (selection != null) {
|
|
95 |
0
| File parent = selection.getParentFile();
|
|
96 |
0
| if (parent != null) {
|
|
97 |
0
| _jfc.setCurrentDirectory(parent);
|
|
98 |
| } |
|
99 |
| } |
|
100 |
| else { |
|
101 |
0
| if (_baseDir != null) { _jfc.setCurrentDirectory(_baseDir); }
|
|
102 |
| } |
|
103 |
| |
|
104 |
0
| File[] c = null;
|
|
105 |
0
| int returnValue = _jfc.showDialog(_parent, null);
|
|
106 |
0
| if (returnValue == JFileChooser.APPROVE_OPTION) {
|
|
107 |
0
| c = _jfc.getSelectedFiles();
|
|
108 |
| } |
|
109 |
0
| if (c != null) {
|
|
110 |
0
| _table.getSelectionModel().clearSelection();
|
|
111 |
0
| for(int i = 0; i < c.length; i++) {
|
|
112 |
0
| _addValue(c[i]);
|
|
113 |
| } |
|
114 |
| } |
|
115 |
| } |
|
116 |
| |
|
117 |
| |
|
118 |
38
| public JFileChooser getFileChooser() {
|
|
119 |
38
| return _jfc;
|
|
120 |
| } |
|
121 |
| |
|
122 |
79
| protected Action _getAddAction() {
|
|
123 |
79
| return new AbstractAction("Add") {
|
|
124 |
0
| public void actionPerformed(ActionEvent ae) {
|
|
125 |
0
| chooseFile();
|
|
126 |
| } |
|
127 |
| }; |
|
128 |
| } |
|
129 |
| } |