1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.schemes; |
22 |
|
|
23 |
|
import java.util.LinkedHashMap; |
24 |
|
import java.util.Locale; |
25 |
|
import java.util.Map; |
26 |
|
|
27 |
|
import jalview.api.AlignViewportI; |
28 |
|
import jalview.datamodel.AnnotatedCollectionI; |
29 |
|
import jalview.datamodel.SequenceCollectionI; |
30 |
|
import jalview.datamodel.SequenceI; |
31 |
|
|
|
|
| 0% |
Uncovered Elements: 57 (57) |
Complexity: 20 |
Complexity Density: 0.62 |
|
32 |
|
public class ColourSchemes |
33 |
|
{ |
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
private static ColourSchemes instance = new ColourSchemes(); |
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
private Map<String, ColourSchemeI> schemes; |
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
@return |
48 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
49 |
0 |
public static ColourSchemes getInstance()... |
50 |
|
{ |
51 |
0 |
return instance; |
52 |
|
} |
53 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
54 |
0 |
private ColourSchemes()... |
55 |
|
{ |
56 |
0 |
loadColourSchemes(); |
57 |
|
} |
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
@return |
63 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 3 |
Complexity Density: 0.43 |
|
64 |
0 |
void loadColourSchemes()... |
65 |
|
{ |
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
0 |
schemes = new LinkedHashMap<>(); |
71 |
|
|
72 |
0 |
for (JalviewColourScheme cs : JalviewColourScheme.values()) |
73 |
|
{ |
74 |
0 |
try |
75 |
|
{ |
76 |
0 |
registerColourScheme( |
77 |
|
cs.getSchemeClass().getDeclaredConstructor().newInstance()); |
78 |
|
} catch (InstantiationException | IllegalAccessException e) |
79 |
|
{ |
80 |
0 |
jalview.bin.Console |
81 |
|
.errPrintln("Error instantiating colour scheme for " |
82 |
|
+ cs.toString() + " " + e.getMessage()); |
83 |
0 |
e.printStackTrace(); |
84 |
|
} catch (ReflectiveOperationException roe) |
85 |
|
{ |
86 |
0 |
roe.printStackTrace(); |
87 |
|
} |
88 |
|
} |
89 |
|
} |
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
@param |
95 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
96 |
0 |
public void registerColourScheme(ColourSchemeI cs)... |
97 |
|
{ |
98 |
0 |
String name = cs.getSchemeName(); |
99 |
0 |
if (name == null) |
100 |
|
{ |
101 |
0 |
jalview.bin.Console.errPrintln("ColourScheme name may not be null"); |
102 |
0 |
return; |
103 |
|
} |
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
|
109 |
0 |
String lower = getColourSchemeShortName(cs); |
110 |
0 |
if (schemes.containsKey(lower)) |
111 |
|
{ |
112 |
0 |
System.err |
113 |
|
.println("Warning: overwriting colour scheme named " + name); |
114 |
|
} |
115 |
0 |
schemes.put(lower, cs); |
116 |
|
} |
117 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
118 |
0 |
private String getColourSchemeShortName(ColourSchemeI cs)... |
119 |
|
{ |
120 |
0 |
return getColourSchemeShortName(cs.getSchemeName()); |
121 |
|
} |
122 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
123 |
0 |
private String getColourSchemeShortName(String name)... |
124 |
|
{ |
125 |
0 |
if (name == null) |
126 |
0 |
return null; |
127 |
0 |
return name.toLowerCase(Locale.ROOT).replaceAll("%", "pc") |
128 |
|
.replaceAll("[^a-z0-9]", "-").replaceAll("--+", "-"); |
129 |
|
} |
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
@param |
135 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
136 |
0 |
public void removeColourScheme(String name)... |
137 |
|
{ |
138 |
0 |
if (name != null) |
139 |
|
{ |
140 |
0 |
schemes.remove(getColourSchemeShortName(name)); |
141 |
|
} |
142 |
|
} |
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
|
147 |
|
|
148 |
|
@param |
149 |
|
|
150 |
|
@param |
151 |
|
@param |
152 |
|
|
153 |
|
@param |
154 |
|
|
155 |
|
|
156 |
|
@return |
157 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.75 |
|
158 |
0 |
public ColourSchemeI getColourScheme(String name, AlignViewportI viewport,... |
159 |
|
AnnotatedCollectionI forData, |
160 |
|
Map<SequenceI, SequenceCollectionI> hiddenRepSequences) |
161 |
|
{ |
162 |
0 |
if (name == null) |
163 |
|
{ |
164 |
0 |
return null; |
165 |
|
} |
166 |
0 |
ColourSchemeI cs = schemes.get(getColourSchemeShortName(name)); |
167 |
0 |
return cs == null ? null : cs.getInstance(viewport, forData); |
168 |
|
} |
169 |
|
|
170 |
|
|
171 |
|
|
172 |
|
|
173 |
|
|
174 |
|
@param |
175 |
|
|
176 |
|
@param |
177 |
|
|
178 |
|
@return |
179 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
180 |
0 |
public ColourSchemeI getColourScheme(String name,... |
181 |
|
AnnotatedCollectionI forData) |
182 |
|
{ |
183 |
0 |
return getColourScheme(name, null, forData, null); |
184 |
|
} |
185 |
|
|
186 |
|
|
187 |
|
|
188 |
|
|
189 |
|
|
190 |
|
@return |
191 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
192 |
0 |
public Iterable<ColourSchemeI> getColourSchemes()... |
193 |
|
{ |
194 |
0 |
return schemes.values(); |
195 |
|
} |
196 |
|
|
197 |
|
|
198 |
|
|
199 |
|
|
200 |
|
|
201 |
|
@param |
202 |
|
@return |
203 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
204 |
0 |
public boolean nameExists(String name)... |
205 |
|
{ |
206 |
0 |
if (name == null) |
207 |
|
{ |
208 |
0 |
return false; |
209 |
|
} |
210 |
0 |
return schemes.containsKey(getColourSchemeShortName(name)); |
211 |
|
} |
212 |
|
} |