1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.io; |
22 |
|
|
23 |
|
import java.io.File; |
24 |
|
import java.net.URL; |
25 |
|
import java.util.HashMap; |
26 |
|
import java.util.Map; |
27 |
|
|
28 |
|
import javax.swing.Icon; |
29 |
|
import javax.swing.ImageIcon; |
30 |
|
import javax.swing.filechooser.FileView; |
31 |
|
|
|
|
| 85.5% |
Uncovered Elements: 9 (62) |
Complexity: 16 |
Complexity Density: 0.42 |
|
32 |
|
public class JalviewFileView extends FileView |
33 |
|
{ |
34 |
|
private static Map<String, String> extensions; |
35 |
|
|
36 |
|
private static Map<String, ImageIcon> icons; |
37 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
38 |
1 |
private void loadExtensions()... |
39 |
|
{ |
40 |
1 |
extensions = new HashMap<String, String>(); |
41 |
1 |
for (FileFormatI ff : FileFormats.getInstance().getFormats()) |
42 |
|
{ |
43 |
19 |
String desc = ff.getName() + " file"; |
44 |
19 |
String exts = ff.getExtensions(); |
45 |
19 |
for (String ext : exts.split(",")) |
46 |
|
{ |
47 |
27 |
extensions.put(ext.trim().toLowerCase(), |
48 |
27 |
desc + ("jar".equals(ext) ? " (old)" : "")); |
49 |
|
} |
50 |
|
} |
51 |
|
} |
52 |
|
|
|
|
| 90% |
Uncovered Elements: 1 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
53 |
26 |
@Override... |
54 |
|
public String getTypeDescription(File f) |
55 |
|
{ |
56 |
26 |
String extension = getExtension(f); |
57 |
26 |
String type = getDescriptionForExtension(extension); |
58 |
26 |
if (extension != null) |
59 |
|
{ |
60 |
26 |
if (extensions.containsKey(extension)) |
61 |
|
{ |
62 |
25 |
type = extensions.get(extension).toString(); |
63 |
|
} |
64 |
|
} |
65 |
|
|
66 |
26 |
return type; |
67 |
|
} |
68 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
69 |
26 |
private String getDescriptionForExtension(String extension)... |
70 |
|
{ |
71 |
26 |
synchronized (this) |
72 |
|
{ |
73 |
26 |
if (extensions == null) |
74 |
|
{ |
75 |
1 |
loadExtensions(); |
76 |
|
} |
77 |
|
} |
78 |
26 |
return extensions.get(extension); |
79 |
|
} |
80 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
81 |
0 |
@Override... |
82 |
|
public Icon getIcon(File f) |
83 |
|
{ |
84 |
0 |
String extension = getExtension(f); |
85 |
0 |
Icon icon = null; |
86 |
|
|
87 |
0 |
if (getDescriptionForExtension(extension) != null) |
88 |
|
{ |
89 |
0 |
icon = getImageIcon("/images/file.png"); |
90 |
|
} |
91 |
|
|
92 |
0 |
return icon; |
93 |
|
} |
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
99 |
30 |
public static String getExtension(File f)... |
100 |
|
{ |
101 |
30 |
String ext = null; |
102 |
30 |
String s = f.getName(); |
103 |
30 |
int i = s.lastIndexOf('.'); |
104 |
|
|
105 |
30 |
if ((i > 0) && (i < (s.length() - 1))) |
106 |
|
{ |
107 |
28 |
ext = s.substring(i + 1).toLowerCase(); |
108 |
|
} |
109 |
|
|
110 |
30 |
return ext; |
111 |
|
} |
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
@param |
117 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 4 |
Complexity Density: 0.36 |
|
118 |
6 |
protected ImageIcon getImageIcon(String filePath)... |
119 |
|
{ |
120 |
|
|
121 |
|
|
122 |
|
|
123 |
6 |
synchronized (this) |
124 |
|
{ |
125 |
6 |
if (icons == null) |
126 |
|
{ |
127 |
1 |
icons = new HashMap<String, ImageIcon>(); |
128 |
|
} |
129 |
6 |
if (!icons.containsKey(filePath)) |
130 |
|
{ |
131 |
4 |
ImageIcon icon = null; |
132 |
4 |
URL imgURL = JalviewFileView.class.getResource(filePath); |
133 |
4 |
if (imgURL != null) |
134 |
|
{ |
135 |
2 |
icon = new ImageIcon(imgURL); |
136 |
|
} |
137 |
|
else |
138 |
|
{ |
139 |
2 |
System.err.println( |
140 |
|
"JalviewFileView.createImageIcon: Couldn't find file: " |
141 |
|
+ filePath); |
142 |
|
} |
143 |
4 |
icons.put(filePath, icon); |
144 |
|
} |
145 |
|
} |
146 |
|
|
147 |
|
|
148 |
|
|
149 |
|
|
150 |
|
|
151 |
6 |
return icons.get(filePath); |
152 |
|
} |
153 |
|
} |