1 Clazz.declarePackage ("jalview.schemes");
2 Clazz.load (["jalview.schemes.ResidueColourScheme"], "jalview.schemes.UserColourScheme", ["jalview.schemes.ColourSchemeProperty", "$.ResidueProperties", "java.awt.Color", "java.util.StringTokenizer"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.lowerCaseColours = null;
5 this.schemeName = null;
6 Clazz.instantialize (this, arguments);
7 }, jalview.schemes, "UserColourScheme", jalview.schemes.ResidueColourScheme);
8 Clazz.makeConstructor (c$,
10 Clazz.superConstructor (this, jalview.schemes.UserColourScheme, [jalview.schemes.ResidueProperties.aaIndex]);
12 Clazz.makeConstructor (c$,
13 function (newColors) {
14 Clazz.superConstructor (this, jalview.schemes.UserColourScheme, [jalview.schemes.ResidueProperties.aaIndex]);
15 this.colors = newColors;
17 Clazz.overrideMethod (c$, "applyTo",
18 function (sg, hiddenRepSequences) {
19 var usc = new jalview.schemes.UserColourScheme (this.colors);
20 if (this.lowerCaseColours != null) {
21 usc.schemeName = String.instantialize (this.schemeName);
22 usc.lowerCaseColours = new Array (this.lowerCaseColours.length);
23 System.arraycopy (this.lowerCaseColours, 0, usc.lowerCaseColours, 0, this.lowerCaseColours.length);
25 }, "jalview.datamodel.AnnotatedCollectionI,java.util.Map");
26 Clazz.makeConstructor (c$,
28 Clazz.superConstructor (this, jalview.schemes.UserColourScheme, [jalview.schemes.ResidueProperties.aaIndex]);
29 var col = this.getColourFromString (colour);
31 System.out.println ("Unknown colour!! " + colour);
32 col = this.createColourFromName (colour);
33 }this.colors = new Array (24);
34 for (var i = 0; i < 24; i++) {
37 this.schemeName = colour;
39 Clazz.defineMethod (c$, "getColours",
43 Clazz.defineMethod (c$, "getLowerCaseColours",
45 return this.lowerCaseColours;
47 Clazz.defineMethod (c$, "setName",
49 this.schemeName = name;
51 Clazz.defineMethod (c$, "getName",
53 return this.schemeName;
55 Clazz.defineMethod (c$, "getColourFromString",
57 colour = colour.trim ();
60 var value = Integer.parseInt (colour, 16);
61 col = new java.awt.Color (value);
63 if (Clazz.exceptionOf (ex, NumberFormatException)) {
69 col = jalview.schemes.ColourSchemeProperty.getAWTColorFromName (colour);
72 var st = new java.util.StringTokenizer (colour, ",");
73 var r = Integer.parseInt (st.nextToken ());
74 var g = Integer.parseInt (st.nextToken ());
75 var b = Integer.parseInt (st.nextToken ());
76 col = new java.awt.Color (r, g, b);
78 if (Clazz.exceptionOf (ex, Exception)) {
85 Clazz.defineMethod (c$, "createColourFromName",
90 var lsize = name.length;
92 var end = Clazz.doubleToInt (lsize / 3);
93 var rgbOffset = Math.abs (name.hashCode () % 10) * 15;
94 r = Math.abs (name.substring (start, end).hashCode () + rgbOffset) % 210 + 20;
96 end += Clazz.doubleToInt (lsize / 3);
99 }g = Math.abs (name.substring (start, end).hashCode () + rgbOffset) % 210 + 20;
100 b = Math.abs (name.substring (end).hashCode () + rgbOffset) % 210 + 20;
101 var color = new java.awt.Color (r, g, b);
104 Clazz.defineMethod (c$, "parseAppletParameter",
105 function (paramValue) {
106 var st = new java.util.StringTokenizer (paramValue, ";");
112 while (st.hasMoreElements ()) {
113 token = st.nextToken ().trim ();
114 residues = token.substring (0, token.indexOf ("="));
115 colour = token.substring (token.indexOf ("=") + 1);
116 st2 = new java.util.StringTokenizer (residues, " ,");
117 while (st2.hasMoreTokens ()) {
118 token = st2.nextToken ();
119 if (jalview.schemes.ResidueProperties.aaIndex[token.charCodeAt (0)] == -1) {
121 }var colIndex = jalview.schemes.ResidueProperties.aaIndex[token.charCodeAt (0)];
122 if (token.equalsIgnoreCase ("lowerCase")) {
123 if (this.lowerCaseColours == null) {
124 this.lowerCaseColours = new Array (23);
125 }for (var i = 0; i < 23; i++) {
126 if (this.lowerCaseColours[i] == null) {
127 this.lowerCaseColours[i] = this.getColourFromString (colour);
130 }if (token.equals (token.toLowerCase ())) {
131 if (this.lowerCaseColours == null) {
132 this.lowerCaseColours = new Array (23);
133 }this.lowerCaseColours[colIndex] = this.getColourFromString (colour);
135 this.colors[colIndex] = this.getColourFromString (colour);
139 if (Clazz.exceptionOf (ex, Exception)) {
140 System.out.println ("Error parsing userDefinedColours:\n" + token + "\n" + ex);
146 Clazz.overrideMethod (c$, "findColourSeq",
147 function (c, j, seq) {
149 var index = jalview.schemes.ResidueProperties.aaIndex[c.charCodeAt (0)];
150 if ((this.threshold == 0) || this.aboveThreshold (c, j)) {
151 if (this.lowerCaseColours != null && 'a' <= c && c <= 'z') {
152 currentColour = this.lowerCaseColours[index];
154 currentColour = this.colors[index];
156 currentColour = java.awt.Color.white;
157 }if (this.conservationColouring) {
158 currentColour = this.applyConservation (currentColour, j);
159 }return currentColour;
160 }, "~S,~N,jalview.datamodel.SequenceI");
161 Clazz.defineMethod (c$, "setLowerCaseColours",
162 function (lcolours) {
163 this.lowerCaseColours = lcolours;