CurrentColour must not be accessed by multiple sequence renderers
[jalview.git] / src / jalview / schemes / ResidueColourScheme.java
index 0d2db23..b905c45 100755 (executable)
@@ -41,7 +41,7 @@ public class ResidueColourScheme implements ColourSchemeI
     int threshold = 0;\r
 \r
     /* Set when threshold colouring to either pid_gaps or pid_nogaps*/\r
-    protected String ignoreGaps = "pid_gaps";\r
+    protected String ignoreGaps = AAFrequency.PID_GAPS;\r
 \r
     /** Consenus as a hashtable array */\r
     Hashtable [] consensus;\r
@@ -52,12 +52,6 @@ public class ResidueColourScheme implements ColourSchemeI
    /** DOCUMENT ME!! */\r
    int inc = 30;\r
 \r
-   /**\r
-    * The colour to be calculated, manipulated and returned\r
-    */\r
-   Color currentColour = null;\r
-\r
-\r
 \r
     /**\r
      * Creates a new ResidueColourScheme object.\r
@@ -83,15 +77,15 @@ public class ResidueColourScheme implements ColourSchemeI
     */\r
    public Color findColour(String aa)\r
    {\r
-       return colors[((Integer) (ResidueProperties.aaHash.get(aa))).intValue()];\r
+       return colors[ResidueProperties.aaIndex[aa.charAt(0)]];\r
    }\r
 \r
 \r
 \r
    public Color findColour(String s, int j)\r
    {\r
-\r
-       int index = ((Integer) (ResidueProperties.aaHash.get(s))).intValue();\r
+       Color currentColour;\r
+       int index = ResidueProperties.aaIndex[s.charAt(0)];\r
 \r
        if ((threshold == 0) || aboveThreshold(ResidueProperties.aa[index], j))\r
        {\r
@@ -103,7 +97,7 @@ public class ResidueColourScheme implements ColourSchemeI
        }\r
 \r
        if(conservationColouring)\r
-         applyConservation(j);\r
+         currentColour = applyConservation(currentColour, j);\r
 \r
 \r
        return currentColour;\r
@@ -129,9 +123,9 @@ public class ResidueColourScheme implements ColourSchemeI
     {\r
         threshold = ct;\r
         if(ignoreGaps)\r
-          this.ignoreGaps = "pid_nogaps";\r
+          this.ignoreGaps = AAFrequency.PID_NOGAPS;\r
         else\r
-          this.ignoreGaps = "pid_gaps";\r
+          this.ignoreGaps = AAFrequency.PID_GAPS;\r
     }\r
 \r
     /**\r
@@ -144,13 +138,25 @@ public class ResidueColourScheme implements ColourSchemeI
      */\r
     public boolean aboveThreshold(String s, int j)\r
     {\r
-        if ((((Integer) consensus[j].get("maxCount")).intValue() != -1) &&\r
-                consensus[j].contains(s))\r
+      char c = s.charAt(0);\r
+      if ('a' <= c && c <= 'z')\r
         {\r
-            if (((Float)consensus[j].get(ignoreGaps)).floatValue() >= threshold)\r
-            {\r
-                return true;\r
-            }\r
+          // TO UPPERCASE !!!\r
+          //Faster than toUpperCase\r
+          c -= ('a' - 'A');\r
+          s = String.valueOf(c);\r
+        }\r
+\r
+        if (consensus == null || consensus[j] == null)\r
+          return false;\r
+\r
+        if ( ( ( (Integer) consensus[j].get(AAFrequency.MAXCOUNT)).intValue() != -1) &&\r
+            consensus[j].contains(s))\r
+        {\r
+          if ( ( (Float) consensus[j].get(ignoreGaps)).floatValue() >= threshold)\r
+          {\r
+            return true;\r
+          }\r
         }\r
 \r
         return false;\r
@@ -177,18 +183,16 @@ public class ResidueColourScheme implements ColourSchemeI
      *\r
      * @param consensus DOCUMENT ME!\r
      */\r
-    public void setConsensus(Vector vconsensus)\r
+    public void setConsensus(Hashtable [] consensus)\r
     {\r
-      if(vconsensus==null)\r
+      if(consensus==null)\r
         return;\r
 \r
-       int i, iSize=vconsensus.size();\r
-       consensus = new Hashtable[iSize];\r
-       for(i=0; i<iSize; i++)\r
-        consensus[i] = (Hashtable)vconsensus.elementAt(i);\r
+      this.consensus = consensus;\r
     }\r
 \r
 \r
+\r
     public void setConservation(Conservation cons)\r
     {\r
       if(cons==null)\r
@@ -217,7 +221,7 @@ public class ResidueColourScheme implements ColourSchemeI
     * @return DOCUMENT ME!\r
     */\r
 \r
-   void applyConservation(int i)\r
+   Color applyConservation(Color currentColour, int i)\r
    {\r
 \r
      if ((conservation[i] != '*') && (conservation[i] != '+'))\r
@@ -231,8 +235,7 @@ public class ResidueColourScheme implements ColourSchemeI
          float t = 11 - (conservation[i] - '0');\r
          if(t==0)\r
          {\r
-           currentColour = Color.white;\r
-           return;\r
+           return Color.white;\r
          }\r
 \r
          int red = currentColour.getRed();\r
@@ -257,6 +260,7 @@ public class ResidueColourScheme implements ColourSchemeI
            currentColour = new Color(red, green, blue);\r
        }\r
        }\r
+       return currentColour;\r
    }\r
 \r
 \r