GetResidueBoxColour altered for faster rendering
authoramwaterhouse <Andrew Waterhouse>
Thu, 13 Jan 2005 12:05:10 +0000 (12:05 +0000)
committeramwaterhouse <Andrew Waterhouse>
Thu, 13 Jan 2005 12:05:10 +0000 (12:05 +0000)
src/jalview/gui/SequenceRenderer.java

index 5022050..6483e8b 100755 (executable)
@@ -11,7 +11,8 @@ public class SequenceRenderer implements RendererI
   FontMetrics fm;\r
   boolean renderGaps = true;\r
   SequenceGroup currentSequenceGroup = null;\r
-  Color color;\r
+  Color resBoxColour = Color.white;\r
+  Graphics graphics;\r
 \r
   public SequenceRenderer(AlignViewport av)\r
   {\r
@@ -26,72 +27,72 @@ public class SequenceRenderer implements RendererI
 \r
   public Color getResidueBoxColour(ColourSchemeI cs, SequenceI seq, int i)\r
   {\r
-   Color c = Color.white;\r
-try{\r
-     if (cs != null)\r
-       c = cs.findColour(seq.getSequence(i, i + 1), i, av.getConsensus(false));\r
-   }catch(Exception ex){}\r
+    getBoxColour(cs, seq, i);\r
+    return resBoxColour;\r
+  }\r
+\r
+  void getBoxColour(ColourSchemeI cs, SequenceI seq, int i)\r
+  {\r
 \r
-    return c;\r
+   if (cs != null)\r
+       resBoxColour = cs.findColour(seq.getSequence(i, i + 1), i, av.getConsensus(false));\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
   {\r
     currentSequenceGroup = sg;\r
 \r
-    drawBoxes(g, seq, start, end, x1, y1, (int) width, height, pid);\r
+    graphics = g;\r
+\r
+    drawBoxes(seq, start, end, x1, y1, (int) width, height, pid);\r
 \r
     fm = g.getFontMetrics();\r
-    drawText(g,seq,start,end,x1,y1,(int)width,height);\r
+    drawText(seq,start,end,x1,y1,(int)width,height);\r
 \r
   }\r
 \r
-  public void drawBoxes(Graphics g, 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,Vector freq) {\r
     int i      = start;\r
     int length = seq.getLength();\r
 \r
-    Color currentColor = Color.WHITE;\r
-\r
     int curStart = x1;\r
     int curWidth = width;\r
 \r
+    Color tempColour = Color.red;\r
     while (i <= end && i < length)\r
     {\r
-      color = color.white;\r
-\r
       if(inCurrentSequenceGroup(i))\r
       {\r
         if( currentSequenceGroup.getDisplayBoxes())\r
-             color = getResidueBoxColour(currentSequenceGroup.cs, seq, i);\r
+             getBoxColour(currentSequenceGroup.cs, seq, i);\r
       }\r
       else if(av.getShowBoxes())\r
-           color = getResidueBoxColour(av.getGlobalColourScheme(), seq, i);\r
-\r
+           getBoxColour(av.getGlobalColourScheme(), seq, i);\r
 \r
-      if (color != currentColor || color != null)\r
+      if (resBoxColour != tempColour)\r
       {\r
-        g.fillRect(x1+width*(curStart-start),y1,curWidth,height);\r
-\r
-        currentColor = color;\r
-        g.setColor(color);\r
+        graphics.fillRect(x1+width*(curStart-start),y1,curWidth,height);\r
+        graphics.setColor(resBoxColour);\r
 \r
         curStart = i;\r
         curWidth = width;\r
+        tempColour = resBoxColour;\r
+\r
       }\r
       else\r
         curWidth += width;\r
 \r
       i++;\r
     }\r
-    g.fillRect(x1+width*(curStart-start),y1,curWidth,height);\r
+    graphics.fillRect(x1+width*(curStart-start),y1,curWidth,height);\r
   }\r
 \r
-  public void drawText(Graphics g, SequenceI seq,int start, int end, int x1, int y1, int width, int height)\r
+  public void drawText(SequenceI seq,int start, int end, int x1, int y1, int width, int height)\r
   {\r
     int pady = height/5;\r
     int charOffset=0;\r
-    g.setColor(Color.black);\r
-\r
     char s;\r
     // Need to find the sequence position here.\r
     for (int i = start; i <= end; i++)\r
@@ -104,7 +105,7 @@ try{
         if(!renderGaps && jalview.util.Comparison.isGap(s))\r
           continue;\r
 \r
-        g.setColor(Color.black);\r
+        graphics.setColor(Color.black);\r
 \r
         if (inCurrentSequenceGroup(i))\r
         {\r
@@ -112,7 +113,7 @@ try{
             continue;\r
 \r
           if(currentSequenceGroup.getColourText())\r
-            g.setColor(getResidueBoxColour(currentSequenceGroup.cs, seq, i).darker());\r
+            graphics.setColor(resBoxColour.darker());\r
         }\r
         else\r
         {\r
@@ -120,11 +121,11 @@ try{
             continue;\r
 \r
           if(av.getColourText())\r
-            g.setColor(getResidueBoxColour(av.getGlobalColourScheme(), seq, i).darker());\r
+            graphics.setColor(resBoxColour.darker());\r
         }\r
 \r
       charOffset =  (width - fm.charWidth(s))/2;\r
-      g.drawString(String.valueOf(s), charOffset + x1 + width * (i - start), y1 + height - pady);\r
+      graphics.drawString(String.valueOf(s), charOffset + x1 + width * (i - start), y1 + height - pady);\r
     }\r
 \r
 \r
@@ -138,13 +139,13 @@ try{
     return (currentSequenceGroup.getStartRes()<=res && currentSequenceGroup.getEndRes()>=res)?true:false;\r
   }\r
 \r
-  public void drawHighlightedText(Graphics g, SequenceI seq,int start, int end, int x1, int y1, int width, int height)\r
+  public void drawHighlightedText(SequenceI seq,int start, int end, int x1, int y1, int width, int height)\r
   {\r
     int pady = height/5;\r
     int charOffset=0;\r
-    g.setColor(Color.BLACK);\r
-    g.fillRect(x1,y1,width*(end-start+1),height);\r
-    g.setColor(Color.white);\r
+    graphics.setColor(Color.BLACK);\r
+    graphics.fillRect(x1,y1,width*(end-start+1),height);\r
+    graphics.setColor(Color.white);\r
 \r
     char s='~';\r
     // Need to find the sequence position here.\r
@@ -154,7 +155,7 @@ try{
           s = seq.getSequence().charAt(i);\r
 \r
       charOffset =  (width - fm.charWidth(s))/2;\r
-      g.drawString(String.valueOf(s), charOffset + x1 + width * (i - start), y1 + height - pady);\r
+      graphics.drawString(String.valueOf(s), charOffset + x1 + width * (i - start), y1 + height - pady);\r
     }\r
   }\r
 \r