1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
package jalview.io; |
23 |
|
|
24 |
|
import java.awt.Component; |
25 |
|
import java.awt.Dimension; |
26 |
|
import java.awt.EventQueue; |
27 |
|
import java.awt.HeadlessException; |
28 |
|
import java.awt.event.ActionEvent; |
29 |
|
import java.awt.event.ActionListener; |
30 |
|
import java.awt.event.MouseAdapter; |
31 |
|
import java.awt.event.MouseEvent; |
32 |
|
import java.beans.PropertyChangeEvent; |
33 |
|
import java.beans.PropertyChangeListener; |
34 |
|
import java.io.File; |
35 |
|
import java.util.ArrayList; |
36 |
|
import java.util.HashMap; |
37 |
|
import java.util.List; |
38 |
|
import java.util.Map; |
39 |
|
import java.util.StringTokenizer; |
40 |
|
import java.util.Vector; |
41 |
|
|
42 |
|
import javax.swing.BoxLayout; |
43 |
|
import javax.swing.JCheckBox; |
44 |
|
import javax.swing.JDialog; |
45 |
|
import javax.swing.JFileChooser; |
46 |
|
import javax.swing.JLabel; |
47 |
|
import javax.swing.JList; |
48 |
|
import javax.swing.JOptionPane; |
49 |
|
import javax.swing.JPanel; |
50 |
|
import javax.swing.JScrollPane; |
51 |
|
import javax.swing.ListCellRenderer; |
52 |
|
import javax.swing.SpringLayout; |
53 |
|
import javax.swing.SwingConstants; |
54 |
|
import javax.swing.SwingUtilities; |
55 |
|
import javax.swing.border.TitledBorder; |
56 |
|
import javax.swing.filechooser.FileFilter; |
57 |
|
import javax.swing.plaf.basic.BasicFileChooserUI; |
58 |
|
|
59 |
|
import jalview.bin.Cache; |
60 |
|
import jalview.gui.JvOptionPane; |
61 |
|
import jalview.util.ChannelProperties; |
62 |
|
import jalview.util.MessageManager; |
63 |
|
import jalview.util.Platform; |
64 |
|
import jalview.util.dialogrunner.DialogRunnerI; |
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
@author |
73 |
|
|
74 |
|
|
|
|
| 29.5% |
Uncovered Elements: 191 (271) |
Complexity: 77 |
Complexity Density: 0.45 |
|
75 |
|
public class JalviewFileChooser extends JFileChooser |
76 |
|
implements DialogRunnerI, PropertyChangeListener |
77 |
|
{ |
78 |
|
private static final long serialVersionUID = 1L; |
79 |
|
|
80 |
|
private Map<Object, Runnable> callbacks = new HashMap<>(); |
81 |
|
|
82 |
|
File selectedFile = null; |
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
private JCheckBox backupfilesCheckBox = null; |
89 |
|
|
90 |
|
protected boolean includeBackupFiles = false; |
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
@param |
97 |
|
@param |
98 |
|
@return |
99 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
100 |
75 |
public static JalviewFileChooser forRead(String directory,... |
101 |
|
String selected) |
102 |
|
{ |
103 |
75 |
return JalviewFileChooser.forRead(directory, selected, false); |
104 |
|
} |
105 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
106 |
75 |
public static JalviewFileChooser forRead(String directory,... |
107 |
|
String selected, boolean allowBackupFiles) |
108 |
|
{ |
109 |
75 |
List<String> extensions = new ArrayList<>(); |
110 |
75 |
List<String> descs = new ArrayList<>(); |
111 |
75 |
for (FileFormatI format : FileFormats.getInstance().getFormats()) |
112 |
|
{ |
113 |
1650 |
if (format.isReadable()) |
114 |
|
{ |
115 |
1425 |
extensions.add(format.getExtensions()); |
116 |
1425 |
descs.add(format.getName()); |
117 |
|
} |
118 |
|
} |
119 |
|
|
120 |
75 |
return new JalviewFileChooser(directory, |
121 |
|
extensions.toArray(new String[extensions.size()]), |
122 |
|
descs.toArray(new String[descs.size()]), selected, true, |
123 |
|
allowBackupFiles); |
124 |
|
} |
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
|
129 |
|
|
130 |
|
@param |
131 |
|
@param |
132 |
|
@return |
133 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
134 |
0 |
public static JalviewFileChooser forWrite(String directory,... |
135 |
|
String selected) |
136 |
|
{ |
137 |
|
|
138 |
|
|
139 |
0 |
List<String> extensions = new ArrayList<>(); |
140 |
0 |
List<String> descs = new ArrayList<>(); |
141 |
0 |
for (FileFormatI format : FileFormats.getInstance().getFormats()) |
142 |
|
{ |
143 |
0 |
if (format.isWritable()) |
144 |
|
{ |
145 |
0 |
extensions.add(format.getExtensions()); |
146 |
0 |
descs.add(format.getName()); |
147 |
|
} |
148 |
|
} |
149 |
0 |
return new JalviewFileChooser(directory, |
150 |
|
extensions.toArray(new String[extensions.size()]), |
151 |
|
descs.toArray(new String[descs.size()]), selected, false); |
152 |
|
} |
153 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
154 |
0 |
public JalviewFileChooser(String dir)... |
155 |
|
{ |
156 |
0 |
super(safePath(dir)); |
157 |
0 |
setAccessory(new RecentlyOpened()); |
158 |
|
} |
159 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
160 |
0 |
public JalviewFileChooser(String dir, String[] suffix, String[] desc,... |
161 |
|
String selected) |
162 |
|
{ |
163 |
0 |
this(dir, suffix, desc, selected, true); |
164 |
|
} |
165 |
|
|
166 |
|
|
167 |
|
|
168 |
|
|
169 |
|
@param |
170 |
|
@param |
171 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
172 |
0 |
public JalviewFileChooser(String extension, String desc)... |
173 |
|
{ |
174 |
0 |
this(Cache.getProperty("LAST_DIRECTORY"), new String[] { extension }, |
175 |
|
new String[] |
176 |
|
{ desc }, desc, true); |
177 |
|
} |
178 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
179 |
0 |
JalviewFileChooser(String dir, String[] extensions, String[] descs,... |
180 |
|
String selected, boolean acceptAny) |
181 |
|
{ |
182 |
0 |
this(dir, extensions, descs, selected, acceptAny, false); |
183 |
|
} |
184 |
|
|
|
|
| 81.8% |
Uncovered Elements: 2 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
185 |
74 |
public JalviewFileChooser(String dir, String[] extensions, String[] descs,... |
186 |
|
String selected, boolean acceptAny, boolean allowBackupFiles) |
187 |
|
{ |
188 |
74 |
super(safePath(dir)); |
189 |
74 |
if (extensions.length == descs.length) |
190 |
|
{ |
191 |
74 |
List<String[]> formats = new ArrayList<>(); |
192 |
1480 |
for (int i = 0; i < extensions.length; i++) |
193 |
|
{ |
194 |
1406 |
formats.add(new String[] { extensions[i], descs[i] }); |
195 |
|
} |
196 |
74 |
init(formats, selected, acceptAny, allowBackupFiles); |
197 |
|
} |
198 |
|
else |
199 |
|
{ |
200 |
0 |
jalview.bin.Console |
201 |
|
.errPrintln("JalviewFileChooser arguments mismatch: " |
202 |
|
+ extensions + ", " + descs); |
203 |
|
} |
204 |
|
} |
205 |
|
|
|
|
| 80% |
Uncovered Elements: 2 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
206 |
75 |
private static File safePath(String dir)... |
207 |
|
{ |
208 |
75 |
if (dir == null) |
209 |
|
{ |
210 |
42 |
return null; |
211 |
|
} |
212 |
|
|
213 |
33 |
File f = new File(dir); |
214 |
33 |
if (f.getName().indexOf(':') > -1) |
215 |
|
{ |
216 |
0 |
return null; |
217 |
|
} |
218 |
33 |
return f; |
219 |
|
} |
220 |
|
|
221 |
|
|
222 |
|
|
223 |
|
|
224 |
|
|
225 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
226 |
0 |
@Override... |
227 |
|
public int showOpenDialog(Component parent) |
228 |
|
{ |
229 |
0 |
int value = super.showOpenDialog(this); |
230 |
|
|
231 |
0 |
if (!Platform.isJS()) |
232 |
|
|
233 |
|
|
234 |
|
|
235 |
|
|
236 |
|
|
237 |
|
{ |
238 |
|
|
239 |
|
|
240 |
|
|
241 |
|
|
242 |
0 |
handleResponse(value); |
243 |
|
} |
244 |
0 |
return value; |
245 |
|
} |
246 |
|
|
247 |
|
|
248 |
|
|
249 |
|
@param |
250 |
|
|
251 |
|
@param |
252 |
|
@param |
253 |
|
|
254 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
255 |
0 |
void init(List<String[]> formats, String selected, boolean acceptAny)... |
256 |
|
{ |
257 |
0 |
init(formats, selected, acceptAny, false); |
258 |
|
} |
259 |
|
|
|
|
| 63% |
Uncovered Elements: 20 (54) |
Complexity: 10 |
Complexity Density: 0.25 |
|
260 |
74 |
void init(List<String[]> formats, String selected, boolean acceptAny,... |
261 |
|
boolean allowBackupFiles) |
262 |
|
{ |
263 |
|
|
264 |
74 |
JalviewFileFilter chosen = null; |
265 |
|
|
266 |
|
|
267 |
|
|
268 |
74 |
setAcceptAllFileFilterUsed(acceptAny); |
269 |
|
|
270 |
|
|
271 |
74 |
List<String> allExtensions = new ArrayList<>(); |
272 |
74 |
for (String[] format : formats) |
273 |
|
{ |
274 |
1406 |
String[] extensions = format[0].split(","); |
275 |
1406 |
for (String ext : extensions) |
276 |
|
{ |
277 |
2072 |
if (!allExtensions.contains(ext)) |
278 |
|
{ |
279 |
2072 |
allExtensions.add(ext); |
280 |
|
} |
281 |
|
} |
282 |
|
} |
283 |
74 |
allExtensions.sort(null); |
284 |
74 |
JalviewFileFilter alljvf = new JalviewFileFilter( |
285 |
|
allExtensions.toArray(new String[] {}), |
286 |
|
MessageManager.getString("label.all_known_alignment_files")); |
287 |
74 |
alljvf.setMultiFormat(true); |
288 |
74 |
alljvf.setExtensionListInDescription(false); |
289 |
74 |
addChoosableFileFilter(alljvf); |
290 |
|
|
291 |
74 |
if (selected == null) |
292 |
|
{ |
293 |
16 |
chosen = alljvf; |
294 |
|
} |
295 |
|
|
296 |
74 |
for (String[] format : formats) |
297 |
|
{ |
298 |
1406 |
JalviewFileFilter jvf = new JalviewFileFilter(format[0], format[1]); |
299 |
1406 |
if (allowBackupFiles) |
300 |
|
{ |
301 |
0 |
jvf.setParentJFC(this); |
302 |
|
} |
303 |
1406 |
addChoosableFileFilter(jvf); |
304 |
1406 |
if ((selected != null) && selected.equalsIgnoreCase(format[1])) |
305 |
|
{ |
306 |
58 |
chosen = jvf; |
307 |
|
} |
308 |
|
} |
309 |
|
|
310 |
74 |
if (chosen != null) |
311 |
|
{ |
312 |
74 |
setFileFilter(chosen); |
313 |
|
} |
314 |
|
|
315 |
72 |
if (allowBackupFiles) |
316 |
|
{ |
317 |
0 |
JPanel multi = new JPanel(); |
318 |
0 |
multi.setLayout(new BoxLayout(multi, BoxLayout.PAGE_AXIS)); |
319 |
0 |
if (backupfilesCheckBox == null) |
320 |
|
{ |
321 |
0 |
try |
322 |
|
{ |
323 |
0 |
includeBackupFiles = Boolean.parseBoolean( |
324 |
|
Cache.getProperty(BackupFiles.NS + "_FC_INCLUDE")); |
325 |
|
} catch (Exception e) |
326 |
|
{ |
327 |
0 |
includeBackupFiles = false; |
328 |
|
} |
329 |
0 |
backupfilesCheckBox = new JCheckBox( |
330 |
|
MessageManager.getString("label.include_backup_files"), |
331 |
|
includeBackupFiles); |
332 |
0 |
backupfilesCheckBox.setAlignmentX(Component.CENTER_ALIGNMENT); |
333 |
0 |
JalviewFileChooser jfc = this; |
334 |
0 |
backupfilesCheckBox.addActionListener(new ActionListener() |
335 |
|
{ |
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 3 |
Complexity Density: 0.25 |
|
336 |
0 |
@Override... |
337 |
|
public void actionPerformed(ActionEvent e) |
338 |
|
{ |
339 |
0 |
includeBackupFiles = backupfilesCheckBox.isSelected(); |
340 |
0 |
Cache.setProperty(BackupFiles.NS + "_FC_INCLUDE", |
341 |
|
String.valueOf(includeBackupFiles)); |
342 |
|
|
343 |
0 |
FileFilter f = jfc.getFileFilter(); |
344 |
|
|
345 |
0 |
File selectedFile = jfc.getSelectedFile(); |
346 |
0 |
if (selectedFile != null && !f.accept(selectedFile)) |
347 |
|
{ |
348 |
0 |
jfc.setSelectedFile(null); |
349 |
|
} |
350 |
|
|
351 |
0 |
String s = jfc.getApproveButtonText(); |
352 |
0 |
jfc.firePropertyChange(APPROVE_BUTTON_TEXT_CHANGED_PROPERTY, |
353 |
|
null, s); |
354 |
|
|
355 |
0 |
jfc.firePropertyChange(FILE_FILTER_CHANGED_PROPERTY, null, f); |
356 |
|
|
357 |
0 |
jfc.rescanCurrentDirectory(); |
358 |
0 |
jfc.revalidate(); |
359 |
0 |
jfc.repaint(); |
360 |
|
} |
361 |
|
}); |
362 |
|
} |
363 |
0 |
multi.add(new RecentlyOpened()); |
364 |
0 |
multi.add(backupfilesCheckBox); |
365 |
0 |
setAccessory(multi); |
366 |
|
} |
367 |
|
else |
368 |
|
{ |
369 |
|
|
370 |
|
|
371 |
72 |
includeBackupFiles = false; |
372 |
72 |
setAccessory(new RecentlyOpened()); |
373 |
|
} |
374 |
|
} |
375 |
|
|
|
|
| 69.2% |
Uncovered Elements: 4 (13) |
Complexity: 5 |
Complexity Density: 0.56 |
|
376 |
372 |
@Override... |
377 |
|
public void setFileFilter(javax.swing.filechooser.FileFilter filter) |
378 |
|
{ |
379 |
372 |
super.setFileFilter(filter); |
380 |
|
|
381 |
370 |
try |
382 |
|
{ |
383 |
370 |
if (getUI() instanceof BasicFileChooserUI) |
384 |
|
{ |
385 |
370 |
final BasicFileChooserUI fcui = (BasicFileChooserUI) getUI(); |
386 |
370 |
final String name = fcui.getFileName().trim(); |
387 |
|
|
388 |
370 |
if ((name == null) || (name.length() == 0)) |
389 |
|
{ |
390 |
370 |
return; |
391 |
|
} |
392 |
|
|
393 |
0 |
EventQueue.invokeLater(new Thread() |
394 |
|
{ |
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
395 |
0 |
@Override... |
396 |
|
public void run() |
397 |
|
{ |
398 |
0 |
String currentName = fcui.getFileName(); |
399 |
0 |
if ((currentName == null) || (currentName.length() == 0)) |
400 |
|
{ |
401 |
0 |
fcui.setFileName(name); |
402 |
|
} |
403 |
|
} |
404 |
|
}); |
405 |
|
} |
406 |
|
} catch (Exception ex) |
407 |
|
{ |
408 |
0 |
ex.printStackTrace(); |
409 |
|
|
410 |
|
} |
411 |
|
} |
412 |
|
|
413 |
|
|
414 |
|
|
415 |
|
|
416 |
|
@return |
417 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 4 |
Complexity Density: 0.4 |
|
418 |
0 |
public FileFormatI getSelectedFormat()... |
419 |
|
{ |
420 |
0 |
if (getFileFilter() == null) |
421 |
|
{ |
422 |
0 |
return null; |
423 |
|
} |
424 |
|
|
425 |
|
|
426 |
|
|
427 |
|
|
428 |
|
|
429 |
|
|
430 |
|
@see |
431 |
|
|
432 |
0 |
String format = getFileFilter().getDescription(); |
433 |
0 |
int parenPos = format.indexOf("("); |
434 |
0 |
if (parenPos > 0) |
435 |
|
{ |
436 |
0 |
format = format.substring(0, parenPos).trim(); |
437 |
0 |
try |
438 |
|
{ |
439 |
0 |
return FileFormats.getInstance().forName(format); |
440 |
|
} catch (IllegalArgumentException e) |
441 |
|
{ |
442 |
0 |
jalview.bin.Console.errPrintln("Unexpected format: " + format); |
443 |
|
} |
444 |
|
} |
445 |
0 |
return null; |
446 |
|
} |
447 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
448 |
75 |
@Override... |
449 |
|
public File getSelectedFile() |
450 |
|
{ |
451 |
75 |
File f = super.getSelectedFile(); |
452 |
75 |
return f == null ? selectedFile : f; |
453 |
|
} |
454 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
455 |
0 |
@Override... |
456 |
|
public int showSaveDialog(Component parent) throws HeadlessException |
457 |
|
{ |
458 |
0 |
this.setAccessory(null); |
459 |
|
|
460 |
0 |
this.setSelectedFile(null); |
461 |
|
|
462 |
0 |
return super.showSaveDialog(parent); |
463 |
|
} |
464 |
|
|
465 |
|
|
466 |
|
|
467 |
|
|
468 |
|
|
469 |
|
|
470 |
|
@see |
471 |
|
|
|
|
| 0% |
Uncovered Elements: 50 (50) |
Complexity: 16 |
Complexity Density: 0.57 |
|
472 |
0 |
@Override... |
473 |
|
public void approveSelection() |
474 |
|
{ |
475 |
0 |
if (getDialogType() != SAVE_DIALOG) |
476 |
|
{ |
477 |
0 |
super.approveSelection(); |
478 |
0 |
return; |
479 |
|
} |
480 |
|
|
481 |
0 |
selectedFile = getSelectedFile(); |
482 |
|
|
483 |
0 |
if (selectedFile == null) |
484 |
|
{ |
485 |
|
|
486 |
|
|
487 |
0 |
try |
488 |
|
{ |
489 |
0 |
String filename = ((BasicFileChooserUI) getUI()).getFileName(); |
490 |
0 |
if (filename != null && filename.length() > 0) |
491 |
|
{ |
492 |
0 |
selectedFile = new File(getCurrentDirectory(), filename); |
493 |
|
} |
494 |
|
} catch (Throwable x) |
495 |
|
{ |
496 |
0 |
jalview.bin.Console.errPrintln( |
497 |
|
"Unexpected exception when trying to get filename."); |
498 |
0 |
x.printStackTrace(); |
499 |
|
} |
500 |
|
|
501 |
|
|
502 |
|
|
503 |
|
} |
504 |
|
|
505 |
0 |
if (selectedFile == null) |
506 |
|
{ |
507 |
0 |
return; |
508 |
|
} |
509 |
|
|
510 |
0 |
if (getFileFilter() instanceof JalviewFileFilter) |
511 |
|
{ |
512 |
0 |
JalviewFileFilter jvf = (JalviewFileFilter) getFileFilter(); |
513 |
|
|
514 |
0 |
if (!jvf.accept(selectedFile) && !jvf.isMultiFormat()) |
515 |
|
{ |
516 |
0 |
String withExtension = getSelectedFile().getName() + "." |
517 |
|
+ jvf.getAcceptableExtension(); |
518 |
0 |
selectedFile = (new File(getCurrentDirectory(), withExtension)); |
519 |
0 |
setSelectedFile(selectedFile); |
520 |
|
} |
521 |
0 |
else if (jvf.isMultiFormat() && jvf.accept(selectedFile)) |
522 |
|
{ |
523 |
|
|
524 |
|
|
525 |
0 |
for (FileFilter jff : this.getChoosableFileFilters()) |
526 |
|
{ |
527 |
0 |
if (jff.accept(selectedFile)) |
528 |
|
{ |
529 |
0 |
this.setFileFilter(jff); |
530 |
|
} |
531 |
|
} |
532 |
|
} |
533 |
|
} |
534 |
|
|
535 |
0 |
if (selectedFile.exists()) |
536 |
|
{ |
537 |
0 |
int confirm = Cache.getDefault("CONFIRM_OVERWRITE_FILE", true) |
538 |
|
? JvOptionPane.showConfirmDialog(this, |
539 |
|
MessageManager |
540 |
|
.getString("label.overwrite_existing_file"), |
541 |
|
MessageManager.getString("label.file_already_exists"), |
542 |
|
JvOptionPane.YES_NO_OPTION) |
543 |
|
: JOptionPane.YES_OPTION; |
544 |
|
|
545 |
0 |
if (confirm != JvOptionPane.YES_OPTION) |
546 |
|
{ |
547 |
0 |
return; |
548 |
|
} |
549 |
|
} |
550 |
|
|
551 |
0 |
super.approveSelection(); |
552 |
|
} |
553 |
|
|
|
|
| 0% |
Uncovered Elements: 18 (18) |
Complexity: 6 |
Complexity Density: 0.6 |
|
554 |
0 |
void recentListSelectionChanged(Object selection)... |
555 |
|
{ |
556 |
0 |
setSelectedFile(null); |
557 |
0 |
if (selection != null) |
558 |
|
{ |
559 |
0 |
File file = new File((String) selection); |
560 |
0 |
if (getFileFilter() instanceof JalviewFileFilter) |
561 |
|
{ |
562 |
0 |
JalviewFileFilter jvf = (JalviewFileFilter) this.getFileFilter(); |
563 |
|
|
564 |
0 |
if (!jvf.accept(file)) |
565 |
|
{ |
566 |
0 |
setFileFilter(getChoosableFileFilters()[0]); |
567 |
|
} |
568 |
|
} |
569 |
|
|
570 |
0 |
if (!file.isAbsolute() && file.exists()) |
571 |
|
{ |
572 |
0 |
file = file.getAbsoluteFile(); |
573 |
|
} |
574 |
|
|
575 |
0 |
setSelectedFile(file); |
576 |
|
} |
577 |
|
} |
578 |
|
|
|
|
| 93.3% |
Uncovered Elements: 2 (30) |
Complexity: 5 |
Complexity Density: 0.22 |
|
579 |
|
class RecentlyOpened extends JPanel |
580 |
|
{ |
581 |
|
private static final long serialVersionUID = 1L; |
582 |
|
|
583 |
|
JList<String> list; |
584 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (25) |
Complexity: 3 |
Complexity Density: 0.14 |
|
585 |
72 |
RecentlyOpened()... |
586 |
|
{ |
587 |
72 |
setPreferredSize(new Dimension(300, 100)); |
588 |
72 |
String historyItems = Cache.getProperty("RECENT_FILE"); |
589 |
72 |
StringTokenizer st; |
590 |
72 |
Vector<String> recent = new Vector<>(); |
591 |
|
|
592 |
72 |
if (historyItems != null) |
593 |
|
{ |
594 |
61 |
st = new StringTokenizer(historyItems, "\t"); |
595 |
|
|
596 |
358 |
while (st.hasMoreTokens()) |
597 |
|
{ |
598 |
297 |
recent.addElement(st.nextToken()); |
599 |
|
} |
600 |
|
} |
601 |
|
|
602 |
72 |
list = new JList<>(recent); |
603 |
72 |
list.setCellRenderer(new recentlyOpenedCellRenderer()); |
604 |
|
|
605 |
72 |
list.addMouseListener(new MouseAdapter() |
606 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
607 |
0 |
@Override... |
608 |
|
public void mousePressed(MouseEvent evt) |
609 |
|
{ |
610 |
0 |
recentListSelectionChanged(list.getSelectedValue()); |
611 |
|
} |
612 |
|
}); |
613 |
|
|
614 |
72 |
TitledBorder recentlyOpenedBorder = new TitledBorder( |
615 |
|
MessageManager.getString("label.recently_opened")); |
616 |
72 |
recentlyOpenedBorder.setTitleFont( |
617 |
|
recentlyOpenedBorder.getTitleFont().deriveFont(10f)); |
618 |
72 |
this.setBorder(recentlyOpenedBorder); |
619 |
|
|
620 |
72 |
final JScrollPane scroller = new JScrollPane(list); |
621 |
|
|
622 |
72 |
SpringLayout layout = new SpringLayout(); |
623 |
72 |
layout.putConstraint(SpringLayout.WEST, scroller, 5, |
624 |
|
SpringLayout.WEST, this); |
625 |
72 |
layout.putConstraint(SpringLayout.NORTH, scroller, 5, |
626 |
|
SpringLayout.NORTH, this); |
627 |
|
|
628 |
|
|
629 |
72 |
scroller.setPreferredSize(new Dimension(280, 105)); |
630 |
72 |
this.add(scroller); |
631 |
|
|
632 |
72 |
SwingUtilities.invokeLater(new Runnable() |
633 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
634 |
71 |
@Override... |
635 |
|
public void run() |
636 |
|
{ |
637 |
71 |
scroller.getHorizontalScrollBar() |
638 |
|
.setValue(scroller.getHorizontalScrollBar().getMaximum()); |
639 |
|
} |
640 |
|
}); |
641 |
|
|
642 |
|
} |
643 |
|
|
644 |
|
} |
645 |
|
|
|
|
| 87% |
Uncovered Elements: 6 (46) |
Complexity: 10 |
Complexity Density: 0.3 |
|
646 |
|
class recentlyOpenedCellRenderer extends JLabel |
647 |
|
implements ListCellRenderer<String> |
648 |
|
{ |
649 |
|
private final static int maxChars = 46; |
650 |
|
|
651 |
|
private final static String ellipsis = "..."; |
652 |
|
|
|
|
| 86.7% |
Uncovered Elements: 6 (45) |
Complexity: 10 |
Complexity Density: 0.3 |
|
653 |
297 |
@Override... |
654 |
|
public Component getListCellRendererComponent( |
655 |
|
JList<? extends String> list, String value, int index, |
656 |
|
boolean isSelected, boolean cellHasFocus) |
657 |
|
{ |
658 |
297 |
String filename = value.toString(); |
659 |
297 |
String displayFilename; |
660 |
297 |
if (filename.length() > maxChars) |
661 |
|
{ |
662 |
164 |
StringBuilder displayFileSB = new StringBuilder(); |
663 |
164 |
File file = new File(filename); |
664 |
164 |
displayFileSB.append(file.getName()); |
665 |
164 |
if (file.getParent() != null) |
666 |
|
{ |
667 |
164 |
File parent = file; |
668 |
164 |
boolean spaceleft = true; |
669 |
983 |
while (spaceleft && parent.getParent() != null) |
670 |
|
{ |
671 |
819 |
parent = parent.getParentFile(); |
672 |
819 |
String name = parent.getName(); |
673 |
819 |
displayFileSB.insert(0, File.separator); |
674 |
819 |
if (displayFileSB.length() + name.length() < maxChars - 1) |
675 |
|
{ |
676 |
655 |
displayFileSB.insert(0, name); |
677 |
|
} |
678 |
|
else |
679 |
|
{ |
680 |
164 |
displayFileSB.insert(0, ellipsis); |
681 |
164 |
spaceleft = false; |
682 |
|
} |
683 |
|
} |
684 |
164 |
if (spaceleft && filename.startsWith(File.separator) |
685 |
|
&& !(displayFileSB.charAt(0) == File.separatorChar)) |
686 |
|
{ |
687 |
0 |
displayFileSB.insert(0, File.separator); |
688 |
|
} |
689 |
|
} |
690 |
164 |
displayFilename = displayFileSB.toString(); |
691 |
|
} |
692 |
|
else |
693 |
|
{ |
694 |
133 |
displayFilename = filename; |
695 |
|
} |
696 |
297 |
this.setText(displayFilename.toString()); |
697 |
297 |
this.setToolTipText(filename); |
698 |
297 |
if (isSelected) |
699 |
|
{ |
700 |
0 |
setBackground(list.getSelectionBackground()); |
701 |
0 |
setForeground(list.getSelectionForeground()); |
702 |
|
} |
703 |
|
else |
704 |
|
{ |
705 |
297 |
setBackground(list.getBackground()); |
706 |
297 |
setForeground(list.getForeground()); |
707 |
|
} |
708 |
297 |
this.setHorizontalAlignment(SwingConstants.TRAILING); |
709 |
297 |
this.setEnabled(list.isEnabled()); |
710 |
297 |
this.setFont(list.getFont().deriveFont(12f)); |
711 |
297 |
this.setOpaque(true); |
712 |
297 |
return this; |
713 |
|
} |
714 |
|
|
715 |
|
} |
716 |
|
|
717 |
|
|
718 |
|
|
719 |
|
|
720 |
|
|
721 |
|
|
722 |
|
|
723 |
|
|
724 |
|
|
725 |
|
|
726 |
|
|
727 |
|
|
728 |
|
|
729 |
|
|
730 |
|
|
731 |
|
|
732 |
|
|
733 |
|
|
734 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
735 |
0 |
@Override... |
736 |
|
public DialogRunnerI setResponseHandler(Object response, Runnable action) |
737 |
|
{ |
738 |
0 |
callbacks.put(response, action); |
739 |
0 |
return this; |
740 |
|
} |
741 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 5 |
Complexity Density: 0.71 |
|
742 |
0 |
@Override... |
743 |
|
public void handleResponse(Object response) |
744 |
|
{ |
745 |
|
|
746 |
|
|
747 |
|
|
748 |
0 |
if (response != null && !response.equals(response)) |
749 |
|
{ |
750 |
0 |
return; |
751 |
|
} |
752 |
0 |
Runnable action = callbacks.get(response); |
753 |
0 |
if (action != null) |
754 |
|
{ |
755 |
0 |
try |
756 |
|
{ |
757 |
0 |
action.run(); |
758 |
|
} catch (Exception e) |
759 |
|
{ |
760 |
0 |
e.printStackTrace(); |
761 |
|
} |
762 |
|
} |
763 |
|
} |
764 |
|
|
765 |
|
|
766 |
|
|
767 |
|
|
768 |
|
|
769 |
|
|
770 |
|
@param |
771 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
772 |
0 |
@Override... |
773 |
|
public void propertyChange(PropertyChangeEvent evt) |
774 |
|
{ |
775 |
|
|
776 |
0 |
switch (evt.getPropertyName()) |
777 |
|
{ |
778 |
|
|
779 |
|
|
780 |
|
|
781 |
0 |
case "SelectedFile": |
782 |
0 |
handleResponse(APPROVE_OPTION); |
783 |
0 |
break; |
784 |
|
} |
785 |
|
} |
786 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
787 |
0 |
@Override... |
788 |
|
protected JDialog createDialog(Component parent) throws HeadlessException |
789 |
|
{ |
790 |
0 |
JDialog dialog = super.createDialog(parent); |
791 |
0 |
dialog.setIconImages(ChannelProperties.getIconList()); |
792 |
0 |
return dialog; |
793 |
|
} |
794 |
|
|
795 |
|
} |