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 jalview.binding.JalviewUserColours; |
24 |
|
|
25 |
|
import java.awt.Color; |
26 |
|
import java.io.File; |
27 |
|
import java.io.FileInputStream; |
28 |
|
import java.io.InputStreamReader; |
29 |
|
|
30 |
|
import org.exolab.castor.xml.Unmarshaller; |
31 |
|
|
|
|
| 0% |
Uncovered Elements: 57 (57) |
Complexity: 10 |
Complexity Density: 0.24 |
|
32 |
|
public class ColourSchemeLoader |
33 |
|
{ |
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
@param |
41 |
|
|
42 |
|
@return |
43 |
|
|
|
|
| 0% |
Uncovered Elements: 56 (56) |
Complexity: 10 |
Complexity Density: 0.24 |
|
44 |
0 |
public static UserColourScheme loadColourScheme(String filePath)... |
45 |
|
{ |
46 |
0 |
UserColourScheme ucs = null; |
47 |
0 |
Color[] newColours = null; |
48 |
0 |
File file = new File(filePath); |
49 |
0 |
try |
50 |
|
{ |
51 |
0 |
InputStreamReader in = new InputStreamReader( |
52 |
|
new FileInputStream(file), "UTF-8"); |
53 |
|
|
54 |
0 |
jalview.schemabinding.version2.JalviewUserColours jucs = new jalview.schemabinding.version2.JalviewUserColours(); |
55 |
|
|
56 |
0 |
org.exolab.castor.xml.Unmarshaller unmar = new org.exolab.castor.xml.Unmarshaller( |
57 |
|
jucs); |
58 |
0 |
jucs = (jalview.schemabinding.version2.JalviewUserColours) unmar |
59 |
|
.unmarshal(in); |
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
0 |
newColours = new Color[24]; |
67 |
0 |
Color[] lowerCase = new Color[23]; |
68 |
0 |
boolean caseSensitive = false; |
69 |
|
|
70 |
0 |
String name; |
71 |
0 |
int index; |
72 |
0 |
for (int i = 0; i < jucs.getColourCount(); i++) |
73 |
|
{ |
74 |
0 |
name = jucs.getColour(i).getName(); |
75 |
0 |
if (ResidueProperties.aa3Hash.containsKey(name)) |
76 |
|
{ |
77 |
0 |
index = ResidueProperties.aa3Hash.get(name).intValue(); |
78 |
|
} |
79 |
|
else |
80 |
|
{ |
81 |
0 |
index = ResidueProperties.aaIndex[name.charAt(0)]; |
82 |
|
} |
83 |
0 |
if (index == -1) |
84 |
|
{ |
85 |
0 |
continue; |
86 |
|
} |
87 |
|
|
88 |
0 |
Color color = new Color( |
89 |
|
Integer.parseInt(jucs.getColour(i).getRGB(), 16)); |
90 |
0 |
if (name.toLowerCase().equals(name)) |
91 |
|
{ |
92 |
0 |
caseSensitive = true; |
93 |
0 |
lowerCase[index] = color; |
94 |
|
} |
95 |
|
else |
96 |
|
{ |
97 |
0 |
newColours[index] = color; |
98 |
|
} |
99 |
|
} |
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
|
104 |
0 |
ucs = new UserColourScheme(newColours); |
105 |
0 |
ucs.setName(jucs.getSchemeName()); |
106 |
0 |
if (caseSensitive) |
107 |
|
{ |
108 |
0 |
ucs.setLowerCaseColours(lowerCase); |
109 |
|
} |
110 |
|
} catch (Exception ex) |
111 |
|
{ |
112 |
|
|
113 |
0 |
try |
114 |
|
{ |
115 |
0 |
InputStreamReader in = new InputStreamReader( |
116 |
|
new FileInputStream(file), "UTF-8"); |
117 |
|
|
118 |
0 |
jalview.binding.JalviewUserColours jucs = new jalview.binding.JalviewUserColours(); |
119 |
|
|
120 |
0 |
jucs = JalviewUserColours.unmarshal(in); |
121 |
|
|
122 |
0 |
newColours = new Color[jucs.getColourCount()]; |
123 |
|
|
124 |
0 |
for (int i = 0; i < 24; i++) |
125 |
|
{ |
126 |
0 |
newColours[i] = new Color( |
127 |
|
Integer.parseInt(jucs.getColour(i).getRGB(), 16)); |
128 |
|
} |
129 |
0 |
ucs = new UserColourScheme(newColours); |
130 |
0 |
ucs.setName(jucs.getSchemeName()); |
131 |
|
} catch (Exception ex2) |
132 |
|
{ |
133 |
0 |
ex2.printStackTrace(); |
134 |
|
} |
135 |
|
|
136 |
0 |
if (newColours == null) |
137 |
|
{ |
138 |
0 |
System.out.println("Error loading User ColourFile\n" + ex); |
139 |
|
} |
140 |
|
} |
141 |
|
|
142 |
0 |
return ucs; |
143 |
|
} |
144 |
|
|
145 |
|
} |