| 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.Locale; |
| 24 |
|
|
| 25 |
|
import jalview.xml.binding.jalview.JalviewUserColours; |
| 26 |
|
|
| 27 |
|
import java.awt.Color; |
| 28 |
|
import java.io.File; |
| 29 |
|
import java.io.FileInputStream; |
| 30 |
|
import java.io.InputStreamReader; |
| 31 |
|
|
| 32 |
|
import javax.xml.bind.JAXBContext; |
| 33 |
|
import javax.xml.bind.JAXBElement; |
| 34 |
|
import javax.xml.stream.XMLInputFactory; |
| 35 |
|
import javax.xml.stream.XMLStreamReader; |
| 36 |
|
|
| |
|
| 0% |
Uncovered Elements: 44 (44) |
Complexity: 7 |
Complexity Density: 0.21 |
|
| 37 |
|
public class ColourSchemeLoader |
| 38 |
|
{ |
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
@param |
| 46 |
|
|
| 47 |
|
@return |
| 48 |
|
|
| |
|
| 0% |
Uncovered Elements: 43 (43) |
Complexity: 7 |
Complexity Density: 0.21 |
|
| 49 |
0 |
public static UserColourScheme loadColourScheme(String filePath)... |
| 50 |
|
{ |
| 51 |
0 |
UserColourScheme ucs = null; |
| 52 |
0 |
Color[] newColours = null; |
| 53 |
0 |
File file = new File(filePath); |
| 54 |
0 |
try |
| 55 |
|
{ |
| 56 |
0 |
InputStreamReader in = new InputStreamReader( |
| 57 |
|
new FileInputStream(file), "UTF-8"); |
| 58 |
|
|
| 59 |
0 |
JAXBContext jc = JAXBContext |
| 60 |
|
.newInstance("jalview.xml.binding.jalview"); |
| 61 |
0 |
javax.xml.bind.Unmarshaller um = jc.createUnmarshaller(); |
| 62 |
0 |
XMLStreamReader streamReader = XMLInputFactory.newInstance() |
| 63 |
|
.createXMLStreamReader(in); |
| 64 |
0 |
JAXBElement<JalviewUserColours> jbe = um.unmarshal(streamReader, |
| 65 |
|
JalviewUserColours.class); |
| 66 |
0 |
JalviewUserColours jucs = jbe.getValue(); |
| 67 |
|
|
| 68 |
|
|
| 69 |
|
|
| 70 |
|
|
| 71 |
|
|
| 72 |
|
|
| 73 |
0 |
newColours = new Color[24]; |
| 74 |
0 |
Color[] lowerCase = new Color[23]; |
| 75 |
0 |
boolean caseSensitive = false; |
| 76 |
|
|
| 77 |
0 |
String name; |
| 78 |
0 |
int index; |
| 79 |
0 |
for (int i = 0; i < jucs.getColour().size(); i++) |
| 80 |
|
{ |
| 81 |
0 |
name = jucs.getColour().get(i).getName(); |
| 82 |
0 |
if (ResidueProperties.aa3Hash.containsKey(name)) |
| 83 |
|
{ |
| 84 |
0 |
index = ResidueProperties.aa3Hash.get(name).intValue(); |
| 85 |
|
} |
| 86 |
|
else |
| 87 |
|
{ |
| 88 |
0 |
index = ResidueProperties.aaIndex[name.charAt(0)]; |
| 89 |
|
} |
| 90 |
0 |
if (index == -1) |
| 91 |
|
{ |
| 92 |
0 |
continue; |
| 93 |
|
} |
| 94 |
|
|
| 95 |
0 |
Color color = new Color( |
| 96 |
|
Integer.parseInt(jucs.getColour().get(i).getRGB(), 16)); |
| 97 |
0 |
if (name.toLowerCase(Locale.ROOT).equals(name)) |
| 98 |
|
{ |
| 99 |
0 |
caseSensitive = true; |
| 100 |
0 |
lowerCase[index] = color; |
| 101 |
|
} |
| 102 |
|
else |
| 103 |
|
{ |
| 104 |
0 |
newColours[index] = color; |
| 105 |
|
} |
| 106 |
|
} |
| 107 |
|
|
| 108 |
|
|
| 109 |
|
|
| 110 |
|
|
| 111 |
0 |
ucs = new UserColourScheme(newColours); |
| 112 |
0 |
ucs.setName(jucs.getSchemeName()); |
| 113 |
0 |
if (caseSensitive) |
| 114 |
|
{ |
| 115 |
0 |
ucs.setLowerCaseColours(lowerCase); |
| 116 |
|
} |
| 117 |
|
} catch (Exception ex) |
| 118 |
|
{ |
| 119 |
|
|
| 120 |
0 |
jalview.bin.Console.errPrintln("Failed to read colour scheme from " |
| 121 |
|
+ filePath + " : " + ex.toString()); |
| 122 |
|
} |
| 123 |
|
|
| 124 |
0 |
return ucs; |
| 125 |
|
} |
| 126 |
|
|
| 127 |
|
} |