|
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 edu.rice.cs.util.AbsRelFile; |
|
43 |
| import javax.swing.filechooser.FileFilter; |
|
44 |
| import javax.swing.*; |
|
45 |
| import javax.swing.table.*; |
|
46 |
| |
|
47 |
| import java.util.Vector; |
|
48 |
| import java.util.List; |
|
49 |
| |
|
50 |
| import edu.rice.cs.drjava.ui.*; |
|
51 |
| import edu.rice.cs.drjava.config.*; |
|
52 |
| import edu.rice.cs.util.swing.SwingFrame; |
|
53 |
| import edu.rice.cs.util.swing.CheckBoxJList; |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
| |
|
59 |
| public class VectorAbsRelFileOptionComponent extends VectorOptionComponent<AbsRelFile> implements OptionConstants { |
|
60 |
| private FileFilter _fileFilter; |
|
61 |
| private JFileChooser _jfc; |
|
62 |
| protected File _baseDir = null; |
|
63 |
| |
|
64 |
0
| public VectorAbsRelFileOptionComponent (VectorOption<AbsRelFile> opt, String text, SwingFrame parent) {
|
|
65 |
0
| this(opt, text, parent, null);
|
|
66 |
| } |
|
67 |
| |
|
68 |
| |
|
69 |
0
| public VectorAbsRelFileOptionComponent (VectorOption<AbsRelFile> opt, String text, SwingFrame parent, String description) {
|
|
70 |
0
| this(opt, text, parent, description, false);
|
|
71 |
| } |
|
72 |
| |
|
73 |
| |
|
74 |
0
| public VectorAbsRelFileOptionComponent (VectorOption<AbsRelFile> opt, String text, SwingFrame parent,
|
|
75 |
| String description, boolean moveButtonEnabled) { |
|
76 |
0
| super(opt, text, parent, new String[] { "File", "Absolute" }, description, moveButtonEnabled);
|
|
77 |
| |
|
78 |
| |
|
79 |
0
| _table.getColumnModel().getColumn(1).setMinWidth(80);
|
|
80 |
0
| _table.getColumnModel().getColumn(1).setMaxWidth(80);
|
|
81 |
| |
|
82 |
| |
|
83 |
0
| File workDir = new File(System.getProperty("user.home"));
|
|
84 |
| |
|
85 |
0
| _jfc = new JFileChooser(workDir);
|
|
86 |
0
| _jfc.setDialogTitle("Select");
|
|
87 |
0
| _jfc.setApproveButtonText("Select");
|
|
88 |
0
| _jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
|
|
89 |
0
| _jfc.setMultiSelectionEnabled(true);
|
|
90 |
0
| _fileFilter = ClassPathFilter.ONLY;
|
|
91 |
| |
|
92 |
0
| final TableCellRenderer renderer = _table.getTableHeader().getDefaultRenderer();
|
|
93 |
0
| int w = renderer.getTableCellRendererComponent(_table,_table.getModel().getColumnName(1), false, false, 0, 1).getPreferredSize().width;
|
|
94 |
0
| _table.getColumnModel().getColumn(1).setPreferredWidth(w);
|
|
95 |
| } |
|
96 |
| |
|
97 |
| |
|
98 |
0
| protected AbstractTableModel _makeTableModel() {
|
|
99 |
0
| return new AbstractTableModel() {
|
|
100 |
0
| public String getColumnName(int col) { return (_columnNames.length == 0)?super.getColumnName(col):_columnNames[col]; }
|
|
101 |
0
| public int getRowCount() { return _data.size(); }
|
|
102 |
0
| public int getColumnCount() { return 2; }
|
|
103 |
0
| public Object getValueAt(int row, int col) {
|
|
104 |
0
| switch(col) {
|
|
105 |
0
| case 0: return _data.get(row);
|
|
106 |
0
| case 1: return _data.get(row).keepAbsolute();
|
|
107 |
| } |
|
108 |
0
| throw new IllegalArgumentException("Illegal column");
|
|
109 |
| } |
|
110 |
0
| public Class<?> getColumnClass(int col) {
|
|
111 |
0
| switch(col) {
|
|
112 |
0
| case 0: return String.class;
|
|
113 |
0
| case 1: return Boolean.class;
|
|
114 |
| } |
|
115 |
0
| throw new IllegalArgumentException("Illegal column");
|
|
116 |
| } |
|
117 |
0
| public boolean isCellEditable(int row, int col) {
|
|
118 |
0
| if (col<1) {
|
|
119 |
0
| return false;
|
|
120 |
| } else { |
|
121 |
0
| return true;
|
|
122 |
| } |
|
123 |
| } |
|
124 |
0
| public void setValueAt(Object value, int row, int col) {
|
|
125 |
0
| AbsRelFile f = _data.get(row);
|
|
126 |
0
| switch(col) {
|
|
127 |
0
| case 1:
|
|
128 |
0
| f.keepAbsolute((Boolean)value);
|
|
129 |
0
| break;
|
|
130 |
0
| default:
|
|
131 |
0
| throw new IllegalArgumentException("Illegal column");
|
|
132 |
| } |
|
133 |
0
| fireTableCellUpdated(row, col);
|
|
134 |
| } |
|
135 |
| }; |
|
136 |
| } |
|
137 |
| |
|
138 |
| |
|
139 |
0
| public void setFileFilter(FileFilter fileFilter) {
|
|
140 |
0
| _fileFilter = fileFilter;
|
|
141 |
| } |
|
142 |
| |
|
143 |
| |
|
144 |
0
| public void setBaseDir(File f) {
|
|
145 |
0
| if (f.isDirectory()) { _baseDir = f; }
|
|
146 |
| } |
|
147 |
| |
|
148 |
| |
|
149 |
0
| public void chooseFile() {
|
|
150 |
0
| int[] rows = _table.getSelectedRows();
|
|
151 |
0
| File selection = (rows.length==1)?_data.get(rows[0]):null;
|
|
152 |
0
| if (selection != null) {
|
|
153 |
0
| File parent = selection.getParentFile();
|
|
154 |
0
| if (parent != null) {
|
|
155 |
0
| _jfc.setCurrentDirectory(parent);
|
|
156 |
| } |
|
157 |
| } |
|
158 |
| else { |
|
159 |
0
| if (_baseDir != null) { _jfc.setCurrentDirectory(_baseDir); }
|
|
160 |
| } |
|
161 |
| |
|
162 |
0
| _jfc.setFileFilter(_fileFilter);
|
|
163 |
| |
|
164 |
0
| File[] c = null;
|
|
165 |
0
| int returnValue = _jfc.showDialog(_parent, null);
|
|
166 |
0
| if (returnValue == JFileChooser.APPROVE_OPTION) {
|
|
167 |
0
| c = _jfc.getSelectedFiles();
|
|
168 |
| } |
|
169 |
0
| if (c != null) {
|
|
170 |
0
| _table.getSelectionModel().clearSelection();
|
|
171 |
0
| for(int i = 0; i < c.length; i++) {
|
|
172 |
0
| _addValue(new AbsRelFile(c[i]));
|
|
173 |
| } |
|
174 |
| } |
|
175 |
| } |
|
176 |
| |
|
177 |
0
| protected Action _getAddAction() {
|
|
178 |
0
| return new AbstractAction("Add") {
|
|
179 |
0
| public void actionPerformed(ActionEvent ae) {
|
|
180 |
0
| chooseFile();
|
|
181 |
| } |
|
182 |
| }; |
|
183 |
| } |
|
184 |
| } |