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 jalview.util.MessageManager; |
24 |
|
|
25 |
|
import java.io.File; |
26 |
|
import java.net.URL; |
27 |
|
import java.util.HashMap; |
28 |
|
import java.util.Iterator; |
29 |
|
import java.util.Map; |
30 |
|
|
31 |
|
import javax.swing.Icon; |
32 |
|
import javax.swing.ImageIcon; |
33 |
|
import javax.swing.filechooser.FileView; |
34 |
|
|
|
|
| 65.1% |
Uncovered Elements: 29 (83) |
Complexity: 20 |
Complexity Density: 0.39 |
|
35 |
|
public class JalviewFileView extends FileView |
36 |
|
{ |
37 |
|
private static Map<String, String> extensions; |
38 |
|
|
39 |
|
private static Map<String, ImageIcon> icons; |
40 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
41 |
1 |
private void loadExtensions()... |
42 |
|
{ |
43 |
1 |
extensions = new HashMap<>(); |
44 |
1 |
for (FileFormatI ff : FileFormats.getInstance().getFormats()) |
45 |
|
{ |
46 |
19 |
String desc = ff.getName() + " file"; |
47 |
19 |
String exts = ff.getExtensions(); |
48 |
19 |
for (String ext : exts.split(",")) |
49 |
|
{ |
50 |
27 |
ext = ext.trim().toLowerCase(); |
51 |
27 |
extensions.put(ext, |
52 |
27 |
desc + ("jar".equals(ext) ? " (old)" : "")); |
53 |
|
} |
54 |
|
} |
55 |
|
} |
56 |
|
|
|
|
| 90% |
Uncovered Elements: 1 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
57 |
26 |
@Override... |
58 |
|
public String getTypeDescription(File f) |
59 |
|
{ |
60 |
26 |
String extension = getExtension(f); |
61 |
|
|
62 |
26 |
String type = getDescriptionForExtension(extension); |
63 |
|
|
64 |
26 |
if (extension != null) |
65 |
|
{ |
66 |
26 |
if (extensions.containsKey(extension)) |
67 |
|
{ |
68 |
25 |
type = extensions.get(extension).toString(); |
69 |
|
} |
70 |
|
} |
71 |
|
|
72 |
26 |
return type; |
73 |
|
} |
74 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
75 |
26 |
private String getDescriptionForExtension(String extension)... |
76 |
|
{ |
77 |
26 |
synchronized (this) |
78 |
|
{ |
79 |
26 |
if (extensions == null) |
80 |
|
{ |
81 |
1 |
loadExtensions(); |
82 |
|
} |
83 |
|
} |
84 |
26 |
return extensions.get(extension); |
85 |
|
} |
86 |
|
|
|
|
| 0% |
Uncovered Elements: 27 (27) |
Complexity: 6 |
Complexity Density: 0.35 |
|
87 |
0 |
@Override... |
88 |
|
public Icon getIcon(File f) |
89 |
|
{ |
90 |
0 |
String extension = getExtension(f); |
91 |
0 |
Icon icon = null; |
92 |
0 |
String type = getDescriptionForExtension(extension); |
93 |
|
|
94 |
0 |
if (type == null) |
95 |
|
{ |
96 |
0 |
Iterator<String> it = extensions.keySet().iterator(); |
97 |
0 |
EXTENSION: while (it.hasNext()) |
98 |
|
{ |
99 |
0 |
String ext = it.next(); |
100 |
|
|
101 |
|
|
102 |
0 |
if (!f.getName().contains(ext)) |
103 |
|
{ |
104 |
0 |
continue EXTENSION; |
105 |
|
} |
106 |
|
|
107 |
0 |
BackupFilenameParts bfp = BackupFilenameParts |
108 |
|
.currentBackupFilenameParts(f.getName(), ext, true); |
109 |
0 |
if (bfp.isBackupFile()) |
110 |
|
{ |
111 |
0 |
extension = ext; |
112 |
0 |
type = getDescriptionForExtension(extension) |
113 |
|
+ MessageManager.getString("label.backup"); |
114 |
0 |
break; |
115 |
|
} |
116 |
|
} |
117 |
|
} |
118 |
|
|
119 |
0 |
if (type != null) |
120 |
|
{ |
121 |
0 |
icon = getImageIcon("/images/file.png"); |
122 |
|
} |
123 |
|
|
124 |
0 |
return icon; |
125 |
|
} |
126 |
|
|
127 |
|
|
128 |
|
|
129 |
|
|
130 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
131 |
30 |
public static String getExtension(File f)... |
132 |
|
{ |
133 |
30 |
String ext = null; |
134 |
30 |
String s = f.getName(); |
135 |
30 |
int i = s.lastIndexOf('.'); |
136 |
|
|
137 |
30 |
if ((i > 0) && (i < (s.length() - 1))) |
138 |
|
{ |
139 |
28 |
ext = s.substring(i + 1).toLowerCase(); |
140 |
|
} |
141 |
|
|
142 |
30 |
return ext; |
143 |
|
} |
144 |
|
|
145 |
|
|
146 |
|
|
147 |
|
|
148 |
|
@param |
149 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 4 |
Complexity Density: 0.36 |
|
150 |
6 |
protected ImageIcon getImageIcon(String filePath)... |
151 |
|
{ |
152 |
|
|
153 |
|
|
154 |
|
|
155 |
6 |
synchronized (this) |
156 |
|
{ |
157 |
6 |
if (icons == null) |
158 |
|
{ |
159 |
1 |
icons = new HashMap<>(); |
160 |
|
} |
161 |
6 |
if (!icons.containsKey(filePath)) |
162 |
|
{ |
163 |
4 |
ImageIcon icon = null; |
164 |
4 |
URL imgURL = JalviewFileView.class.getResource(filePath); |
165 |
4 |
if (imgURL != null) |
166 |
|
{ |
167 |
2 |
icon = new ImageIcon(imgURL); |
168 |
|
} |
169 |
|
else |
170 |
|
{ |
171 |
2 |
System.err.println( |
172 |
|
"JalviewFileView.createImageIcon: Couldn't find file: " |
173 |
|
+ filePath); |
174 |
|
} |
175 |
4 |
icons.put(filePath, icon); |
176 |
|
} |
177 |
|
} |
178 |
|
|
179 |
|
|
180 |
|
|
181 |
|
|
182 |
|
|
183 |
6 |
return icons.get(filePath); |
184 |
|
} |
185 |
|
} |