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.Enumeration; |
25 |
|
import java.util.Hashtable; |
26 |
|
import java.util.StringTokenizer; |
27 |
|
|
28 |
|
import javax.swing.filechooser.FileFilter; |
29 |
|
|
|
|
| 69.9% |
Uncovered Elements: 25 (83) |
Complexity: 28 |
Complexity Density: 0.64 |
|
30 |
|
public class JalviewFileFilter extends FileFilter |
31 |
|
{ |
32 |
|
public static Hashtable suffixHash = new Hashtable(); |
33 |
|
|
34 |
|
private Hashtable filters = null; |
35 |
|
|
36 |
|
private String description = "no description"; |
37 |
|
|
38 |
|
private String fullDescription = "full description"; |
39 |
|
|
40 |
|
private boolean useExtensionsInDescription = true; |
41 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
42 |
187 |
public JalviewFileFilter(String extension, String description)... |
43 |
|
{ |
44 |
187 |
StringTokenizer st = new StringTokenizer(extension, ","); |
45 |
|
|
46 |
462 |
while (st.hasMoreElements()) |
47 |
|
{ |
48 |
275 |
addExtension(st.nextToken().trim()); |
49 |
|
} |
50 |
|
|
51 |
187 |
setDescription(description); |
52 |
|
} |
53 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
54 |
0 |
public JalviewFileFilter(String[] filts)... |
55 |
|
{ |
56 |
0 |
this(filts, null); |
57 |
|
} |
58 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.75 |
|
59 |
0 |
public JalviewFileFilter(String[] filts, String description)... |
60 |
|
{ |
61 |
0 |
for (int i = 0; i < filts.length; i++) |
62 |
|
{ |
63 |
|
|
64 |
0 |
addExtension(filts[i]); |
65 |
|
} |
66 |
|
|
67 |
0 |
if (description != null) |
68 |
|
{ |
69 |
0 |
setDescription(description); |
70 |
|
} |
71 |
|
} |
72 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
73 |
0 |
public String getAcceptableExtension()... |
74 |
|
{ |
75 |
0 |
return filters.keys().nextElement().toString(); |
76 |
|
} |
77 |
|
|
78 |
|
|
|
|
| 76.9% |
Uncovered Elements: 3 (13) |
Complexity: 5 |
Complexity Density: 0.71 |
|
79 |
72 |
public boolean accept(File f)... |
80 |
|
{ |
81 |
72 |
if (f != null) |
82 |
|
{ |
83 |
72 |
String extension = getExtension(f); |
84 |
|
|
85 |
72 |
if (f.isDirectory()) |
86 |
|
{ |
87 |
60 |
return true; |
88 |
|
} |
89 |
|
|
90 |
12 |
if ((extension != null) && (filters.get(getExtension(f)) != null)) |
91 |
|
{ |
92 |
0 |
return true; |
93 |
|
} |
94 |
|
} |
95 |
|
|
96 |
12 |
return false; |
97 |
|
} |
98 |
|
|
|
|
| 90.9% |
Uncovered Elements: 1 (11) |
Complexity: 4 |
Complexity Density: 0.57 |
|
99 |
84 |
public String getExtension(File f)... |
100 |
|
{ |
101 |
84 |
if (f != null) |
102 |
|
{ |
103 |
84 |
String filename = f.getName(); |
104 |
84 |
int i = filename.lastIndexOf('.'); |
105 |
|
|
106 |
84 |
if ((i > 0) && (i < (filename.length() - 1))) |
107 |
|
{ |
108 |
36 |
return filename.substring(i + 1).toLowerCase(); |
109 |
|
} |
110 |
|
|
111 |
48 |
; |
112 |
|
} |
113 |
|
|
114 |
48 |
return ""; |
115 |
|
} |
116 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
117 |
275 |
public void addExtension(String extension)... |
118 |
|
{ |
119 |
275 |
if (filters == null) |
120 |
|
{ |
121 |
187 |
filters = new Hashtable(5); |
122 |
|
} |
123 |
|
|
124 |
275 |
filters.put(extension.toLowerCase(), this); |
125 |
275 |
fullDescription = null; |
126 |
|
} |
127 |
|
|
|
|
| 76.2% |
Uncovered Elements: 5 (21) |
Complexity: 7 |
Complexity Density: 0.64 |
|
128 |
187 |
public String getDescription()... |
129 |
|
{ |
130 |
187 |
if (fullDescription == null) |
131 |
|
{ |
132 |
187 |
if ((description == null) || isExtensionListInDescription()) |
133 |
|
{ |
134 |
187 |
fullDescription = (description == null) ? "(" |
135 |
|
: (description + " ("); |
136 |
|
|
137 |
|
|
138 |
187 |
Enumeration extensions = filters.keys(); |
139 |
|
|
140 |
187 |
if (extensions != null) |
141 |
|
{ |
142 |
187 |
fullDescription += ("." + (String) extensions.nextElement()); |
143 |
|
|
144 |
275 |
while (extensions.hasMoreElements()) |
145 |
|
{ |
146 |
88 |
fullDescription += (", " + (String) extensions.nextElement()); |
147 |
|
} |
148 |
|
} |
149 |
|
|
150 |
187 |
fullDescription += ")"; |
151 |
|
} |
152 |
|
else |
153 |
|
{ |
154 |
0 |
fullDescription = description; |
155 |
|
} |
156 |
|
} |
157 |
|
|
158 |
187 |
return fullDescription; |
159 |
|
} |
160 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
161 |
187 |
public void setDescription(String description)... |
162 |
|
{ |
163 |
187 |
this.description = description; |
164 |
187 |
fullDescription = null; |
165 |
|
} |
166 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
167 |
0 |
public void setExtensionListInDescription(boolean b)... |
168 |
|
{ |
169 |
0 |
useExtensionsInDescription = b; |
170 |
0 |
fullDescription = null; |
171 |
|
} |
172 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
173 |
187 |
public boolean isExtensionListInDescription()... |
174 |
|
{ |
175 |
187 |
return useExtensionsInDescription; |
176 |
|
} |
177 |
|
} |