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