| 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 |
|
|
| |
|
| 65.1% |
Uncovered Elements: 29 (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 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
| 43 |
1 |
private void loadExtensions()... |
| 44 |
|
{ |
| 45 |
1 |
extensions = new HashMap<>(); |
| 46 |
1 |
for (FileFormatI ff : FileFormats.getInstance().getFormats()) |
| 47 |
|
{ |
| 48 |
26 |
String desc = ff.getName() + " file"; |
| 49 |
26 |
String exts = ff.getExtensions(); |
| 50 |
26 |
for (String ext : exts.split(",")) |
| 51 |
|
{ |
| 52 |
36 |
ext = ext.trim().toLowerCase(Locale.ROOT); |
| 53 |
36 |
extensions.put(ext, desc + ("jar".equals(ext) ? " (old)" : "")); |
| 54 |
|
} |
| 55 |
|
} |
| 56 |
|
} |
| 57 |
|
|
| |
|
| 90% |
Uncovered Elements: 1 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
| 58 |
26 |
@Override... |
| 59 |
|
public String getTypeDescription(File f) |
| 60 |
|
{ |
| 61 |
26 |
String extension = getExtension(f); |
| 62 |
|
|
| 63 |
26 |
String type = getDescriptionForExtension(extension); |
| 64 |
|
|
| 65 |
26 |
if (extension != null) |
| 66 |
|
{ |
| 67 |
26 |
if (extensions.containsKey(extension)) |
| 68 |
|
{ |
| 69 |
25 |
type = extensions.get(extension).toString(); |
| 70 |
|
} |
| 71 |
|
} |
| 72 |
|
|
| 73 |
26 |
return type; |
| 74 |
|
} |
| 75 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 76 |
26 |
private String getDescriptionForExtension(String extension)... |
| 77 |
|
{ |
| 78 |
26 |
synchronized (this) |
| 79 |
|
{ |
| 80 |
26 |
if (extensions == null) |
| 81 |
|
{ |
| 82 |
1 |
loadExtensions(); |
| 83 |
|
} |
| 84 |
|
} |
| 85 |
26 |
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 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
| 132 |
30 |
public static String getExtension(File f)... |
| 133 |
|
{ |
| 134 |
30 |
String ext = null; |
| 135 |
30 |
String s = f.getName(); |
| 136 |
30 |
int i = s.lastIndexOf('.'); |
| 137 |
|
|
| 138 |
30 |
if ((i > 0) && (i < (s.length() - 1))) |
| 139 |
|
{ |
| 140 |
28 |
ext = s.substring(i + 1).toLowerCase(Locale.ROOT); |
| 141 |
|
} |
| 142 |
|
|
| 143 |
30 |
return ext; |
| 144 |
|
} |
| 145 |
|
|
| 146 |
|
|
| 147 |
|
|
| 148 |
|
|
| 149 |
|
@param |
| 150 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 4 |
Complexity Density: 0.36 |
|
| 151 |
6 |
protected ImageIcon getImageIcon(String filePath)... |
| 152 |
|
{ |
| 153 |
|
|
| 154 |
|
|
| 155 |
|
|
| 156 |
6 |
synchronized (this) |
| 157 |
|
{ |
| 158 |
6 |
if (icons == null) |
| 159 |
|
{ |
| 160 |
1 |
icons = new HashMap<>(); |
| 161 |
|
} |
| 162 |
6 |
if (!icons.containsKey(filePath)) |
| 163 |
|
{ |
| 164 |
4 |
ImageIcon icon = null; |
| 165 |
4 |
URL imgURL = JalviewFileView.class.getResource(filePath); |
| 166 |
4 |
if (imgURL != null) |
| 167 |
|
{ |
| 168 |
2 |
icon = new ImageIcon(imgURL); |
| 169 |
|
} |
| 170 |
|
else |
| 171 |
|
{ |
| 172 |
2 |
jalview.bin.Console.errPrintln( |
| 173 |
|
"JalviewFileView.createImageIcon: Couldn't find file: " |
| 174 |
|
+ filePath); |
| 175 |
|
} |
| 176 |
4 |
icons.put(filePath, icon); |
| 177 |
|
} |
| 178 |
|
} |
| 179 |
|
|
| 180 |
|
|
| 181 |
|
|
| 182 |
|
|
| 183 |
|
|
| 184 |
6 |
return icons.get(filePath); |
| 185 |
|
} |
| 186 |
|
} |