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