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.util.Hashtable; |
25 |
|
import java.util.Iterator; |
26 |
|
import java.util.LinkedHashMap; |
27 |
|
import java.util.Map; |
28 |
|
import java.util.StringTokenizer; |
29 |
|
|
30 |
|
import javax.swing.filechooser.FileFilter; |
31 |
|
|
|
|
| 58.8% |
Uncovered Elements: 42 (102) |
Complexity: 34 |
Complexity Density: 0.63 |
|
32 |
|
public class JalviewFileFilter extends FileFilter |
33 |
|
{ |
34 |
|
public static Hashtable suffixHash = new Hashtable(); |
35 |
|
|
36 |
|
private Map<String, JalviewFileFilter> filters = null; |
37 |
|
|
38 |
|
private String description = "no description"; |
39 |
|
|
40 |
|
private String fullDescription = "full description"; |
41 |
|
|
42 |
|
private boolean useExtensionsInDescription = true; |
43 |
|
|
44 |
|
private JalviewFileChooser parentJFC = null; |
45 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
46 |
306 |
public JalviewFileFilter(String extension, String description)... |
47 |
|
{ |
48 |
306 |
StringTokenizer st = new StringTokenizer(extension, ","); |
49 |
|
|
50 |
756 |
while (st.hasMoreElements()) |
51 |
|
{ |
52 |
450 |
addExtension(st.nextToken().trim()); |
53 |
|
} |
54 |
|
|
55 |
306 |
setDescription(description); |
56 |
|
} |
57 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
58 |
0 |
public JalviewFileFilter(String[] filts)... |
59 |
|
{ |
60 |
0 |
this(filts, null); |
61 |
|
} |
62 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.75 |
|
63 |
0 |
public JalviewFileFilter(String[] filts, String description)... |
64 |
|
{ |
65 |
0 |
for (int i = 0; i < filts.length; i++) |
66 |
|
{ |
67 |
|
|
68 |
0 |
addExtension(filts[i]); |
69 |
|
} |
70 |
|
|
71 |
0 |
if (description != null) |
72 |
|
{ |
73 |
0 |
setDescription(description); |
74 |
|
} |
75 |
|
} |
76 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
77 |
0 |
public String getAcceptableExtension()... |
78 |
|
{ |
79 |
0 |
return filters.keySet().iterator().next().toString(); |
80 |
|
} |
81 |
|
|
82 |
|
|
|
|
| 40% |
Uncovered Elements: 18 (30) |
Complexity: 10 |
Complexity Density: 0.62 |
|
83 |
233 |
@Override... |
84 |
|
public boolean accept(File f) |
85 |
|
{ |
86 |
|
|
87 |
233 |
if (f != null) |
88 |
|
{ |
89 |
233 |
String extension = getExtension(f); |
90 |
|
|
91 |
233 |
if (f.isDirectory()) |
92 |
|
{ |
93 |
191 |
return true; |
94 |
|
} |
95 |
|
|
96 |
42 |
if ((extension != null) && (filters.get(extension) != null)) |
97 |
|
{ |
98 |
0 |
return true; |
99 |
|
} |
100 |
|
|
101 |
|
} |
102 |
|
|
103 |
42 |
if (parentJFC != null && parentJFC.includeBackupFiles) |
104 |
|
{ |
105 |
0 |
Iterator<String> it = filters.keySet().iterator(); |
106 |
0 |
EXTENSION: while (it.hasNext()) |
107 |
|
{ |
108 |
0 |
String ext = it.next(); |
109 |
|
|
110 |
|
|
111 |
0 |
if (!f.getName().contains(ext)) |
112 |
|
{ |
113 |
0 |
continue EXTENSION; |
114 |
|
} |
115 |
|
|
116 |
0 |
BackupFilenameParts bfp = BackupFilenameParts |
117 |
|
.currentBackupFilenameParts(f.getName(), ext, true); |
118 |
0 |
if (bfp.isBackupFile()) |
119 |
|
{ |
120 |
0 |
return true; |
121 |
|
} |
122 |
|
} |
123 |
|
} |
124 |
|
|
125 |
42 |
return false; |
126 |
|
} |
127 |
|
|
|
|
| 90.9% |
Uncovered Elements: 1 (11) |
Complexity: 4 |
Complexity Density: 0.57 |
|
128 |
233 |
public String getExtension(File f)... |
129 |
|
{ |
130 |
233 |
if (f != null) |
131 |
|
{ |
132 |
233 |
String filename = f.getName(); |
133 |
233 |
int i = filename.lastIndexOf('.'); |
134 |
|
|
135 |
233 |
if ((i > 0) && (i < (filename.length() - 1))) |
136 |
|
{ |
137 |
64 |
return filename.substring(i + 1).toLowerCase(); |
138 |
|
} |
139 |
|
|
140 |
169 |
; |
141 |
|
} |
142 |
|
|
143 |
169 |
return ""; |
144 |
|
} |
145 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
146 |
450 |
public void addExtension(String extension)... |
147 |
|
{ |
148 |
450 |
if (filters == null) |
149 |
|
{ |
150 |
306 |
filters = new LinkedHashMap<>(5); |
151 |
|
} |
152 |
|
|
153 |
450 |
filters.put(extension.toLowerCase(), this); |
154 |
450 |
fullDescription = null; |
155 |
|
} |
156 |
|
|
|
|
| 76.2% |
Uncovered Elements: 5 (21) |
Complexity: 7 |
Complexity Density: 0.64 |
|
157 |
306 |
@Override... |
158 |
|
public String getDescription() |
159 |
|
{ |
160 |
306 |
if (fullDescription == null) |
161 |
|
{ |
162 |
306 |
if ((description == null) || isExtensionListInDescription()) |
163 |
|
{ |
164 |
306 |
fullDescription = (description == null) ? "(" |
165 |
|
: (description + " ("); |
166 |
|
|
167 |
|
|
168 |
306 |
Iterator<String> extensions = filters.keySet().iterator(); |
169 |
|
|
170 |
306 |
if (extensions != null) |
171 |
|
{ |
172 |
306 |
fullDescription += ("." + extensions.next()); |
173 |
|
|
174 |
450 |
while (extensions.hasNext()) |
175 |
|
{ |
176 |
144 |
fullDescription += (", " + extensions.next()); |
177 |
|
} |
178 |
|
} |
179 |
|
|
180 |
306 |
fullDescription += ")"; |
181 |
|
} |
182 |
|
else |
183 |
|
{ |
184 |
0 |
fullDescription = description; |
185 |
|
} |
186 |
|
} |
187 |
|
|
188 |
306 |
return fullDescription; |
189 |
|
} |
190 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
191 |
306 |
public void setDescription(String description)... |
192 |
|
{ |
193 |
306 |
this.description = description; |
194 |
306 |
fullDescription = null; |
195 |
|
} |
196 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
197 |
0 |
public void setExtensionListInDescription(boolean b)... |
198 |
|
{ |
199 |
0 |
useExtensionsInDescription = b; |
200 |
0 |
fullDescription = null; |
201 |
|
} |
202 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
203 |
306 |
public boolean isExtensionListInDescription()... |
204 |
|
{ |
205 |
306 |
return useExtensionsInDescription; |
206 |
|
} |
207 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
208 |
0 |
protected void setParentJFC(JalviewFileChooser p)... |
209 |
|
{ |
210 |
0 |
this.parentJFC = p; |
211 |
|
} |
212 |
|
|
213 |
|
} |