no need to send consensus everytime
[jalview.git] / src / jalview / gui / SequenceRenderer.java
index 6483e8b..54785ef 100755 (executable)
@@ -11,7 +11,8 @@ public class SequenceRenderer implements RendererI
   FontMetrics fm;\r
   boolean renderGaps = true;\r
   SequenceGroup currentSequenceGroup = null;\r
-  Color resBoxColour = Color.white;\r
+  SequenceGroup [] allGroups = null;\r
+  Color resBoxColour;\r
   Graphics graphics;\r
 \r
   public SequenceRenderer(AlignViewport av)\r
@@ -33,34 +34,33 @@ public class SequenceRenderer implements RendererI
 \r
   void getBoxColour(ColourSchemeI cs, SequenceI seq, int i)\r
   {\r
-\r
    if (cs != null)\r
-       resBoxColour = cs.findColour(seq.getSequence(i, i + 1), i, av.getConsensus(false));\r
+       resBoxColour = cs.findColour(seq.getSequence(i, i + 1), i);\r
    else\r
        resBoxColour = Color.white;\r
   }\r
 \r
-  public void drawSequence(Graphics g,SequenceI seq,SequenceGroup sg, int start, int end, int x1, int y1, int width, int height, Vector pid, int seqnum)\r
+  public void drawSequence(Graphics g,SequenceI seq,SequenceGroup [] sg, int start, int end, int x1, int y1, int width, int height, Vector pid, int seqnum)\r
   {\r
-    currentSequenceGroup = sg;\r
+    allGroups = sg;\r
 \r
     graphics = g;\r
 \r
-    drawBoxes(seq, start, end, x1, y1, (int) width, height, pid);\r
+    drawBoxes(seq, start, end, x1, y1, (int) width, height);\r
 \r
     fm = g.getFontMetrics();\r
     drawText(seq,start,end,x1,y1,(int)width,height);\r
 \r
   }\r
 \r
-  public void drawBoxes(SequenceI seq,int start, int end, int x1, int y1, int width, int height,Vector freq) {\r
+  public void drawBoxes(SequenceI seq,int start, int end, int x1, int y1, int width, int height) {\r
     int i      = start;\r
     int length = seq.getLength();\r
 \r
-    int curStart = x1;\r
+    int curStart = -1;\r
     int curWidth = width;\r
 \r
-    Color tempColour = Color.red;\r
+    Color tempColour = null;\r
     while (i <= end && i < length)\r
     {\r
       if(inCurrentSequenceGroup(i))\r
@@ -69,11 +69,15 @@ public class SequenceRenderer implements RendererI
              getBoxColour(currentSequenceGroup.cs, seq, i);\r
       }\r
       else if(av.getShowBoxes())\r
-           getBoxColour(av.getGlobalColourScheme(), seq, i);\r
+            getBoxColour(av.getGlobalColourScheme(), seq, i);\r
+      else\r
+        resBoxColour = Color.white;\r
+\r
 \r
       if (resBoxColour != tempColour)\r
       {\r
-        graphics.fillRect(x1+width*(curStart-start),y1,curWidth,height);\r
+        if(tempColour!=null)\r
+          graphics.fillRect(x1+width*(curStart-start),y1,curWidth,height);\r
         graphics.setColor(resBoxColour);\r
 \r
         curStart = i;\r
@@ -86,7 +90,9 @@ public class SequenceRenderer implements RendererI
 \r
       i++;\r
     }\r
-    graphics.fillRect(x1+width*(curStart-start),y1,curWidth,height);\r
+\r
+\r
+     graphics.fillRect(x1+width*(curStart-start),y1,curWidth,height);\r
   }\r
 \r
   public void drawText(SequenceI seq,int start, int end, int x1, int y1, int width, int height)\r
@@ -95,25 +101,30 @@ public class SequenceRenderer implements RendererI
     int charOffset=0;\r
     char s;\r
     // Need to find the sequence position here.\r
+\r
+    graphics.setColor(Color.black);\r
+    String sequence  = seq.getSequence();\r
     for (int i = start; i <= end; i++)\r
     {\r
-        if(i<seq.getLength())\r
-          s = seq.getSequence().charAt(i);\r
+        if(i<sequence.length())\r
+          s = sequence.charAt(i);\r
         else\r
           s = ' ';\r
 \r
         if(!renderGaps && jalview.util.Comparison.isGap(s))\r
           continue;\r
 \r
-        graphics.setColor(Color.black);\r
 \r
         if (inCurrentSequenceGroup(i))\r
         {\r
           if(!currentSequenceGroup.getDisplayText())\r
             continue;\r
 \r
-          if(currentSequenceGroup.getColourText())\r
-            graphics.setColor(resBoxColour.darker());\r
+            if (currentSequenceGroup.getColourText())\r
+            {\r
+              getBoxColour(currentSequenceGroup.cs, seq, i);\r
+              graphics.setColor(resBoxColour.darker());\r
+            }\r
         }\r
         else\r
         {\r
@@ -121,22 +132,37 @@ public class SequenceRenderer implements RendererI
             continue;\r
 \r
           if(av.getColourText())\r
-            graphics.setColor(resBoxColour.darker());\r
+           {\r
+             getBoxColour(av.getGlobalColourScheme(), seq, i);\r
+             if(av.getShowBoxes())\r
+              graphics.setColor(resBoxColour.darker());\r
+            else\r
+              graphics.setColor(resBoxColour);\r
+           }\r
         }\r
 \r
-      charOffset =  (width - fm.charWidth(s))/2;\r
-      graphics.drawString(String.valueOf(s), charOffset + x1 + width * (i - start), y1 + height - pady);\r
-    }\r
+          charOffset =  (width - fm.charWidth(s))/2;\r
+          graphics.drawString(String.valueOf(s),\r
+                              charOffset + x1 + width * (i - start),\r
+                              y1 + height - pady);\r
+        }\r
 \r
 \r
   }\r
 \r
   boolean inCurrentSequenceGroup(int res)\r
   {\r
-    if(currentSequenceGroup==null)\r
+    if(allGroups ==null)\r
       return false;\r
 \r
-    return (currentSequenceGroup.getStartRes()<=res && currentSequenceGroup.getEndRes()>=res)?true:false;\r
+    for(int i=0; i<allGroups.length; i++)\r
+      if(allGroups[i].getStartRes()<=res && allGroups[i].getEndRes()>=res)\r
+      {\r
+         currentSequenceGroup = allGroups[i];\r
+         return true;\r
+      }\r
+\r
+    return false;\r
   }\r
 \r
   public void drawHighlightedText(SequenceI seq,int start, int end, int x1, int y1, int width, int height)\r
@@ -154,7 +180,7 @@ public class SequenceRenderer implements RendererI
        if(i<seq.getLength())\r
           s = seq.getSequence().charAt(i);\r
 \r
-      charOffset =  (width - fm.charWidth(s))/2;\r
+     charOffset =  (width - fm.charWidth(s))/2;\r
       graphics.drawString(String.valueOf(s), charOffset + x1 + width * (i - start), y1 + height - pady);\r
     }\r
   }\r