Merge branch 'develop' into features/JAL-2094_colourInterface
[jalview.git] / src / jalview / gui / SequenceRenderer.java
index 21286ad..3003c01 100755 (executable)
  */
 package jalview.gui;
 
+import jalview.api.ColorI;
 import jalview.api.FeatureRenderer;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
+import jalview.schemes.Colour;
 import jalview.schemes.ColourSchemeI;
+import jalview.util.ColorUtils;
 
 import java.awt.Color;
 import java.awt.FontMetrics;
 import java.awt.Graphics;
 
-/**
- * DOCUMENT ME!
- * 
- * @author $author$
- * @version $Revision$
- */
 public class SequenceRenderer implements jalview.api.SequenceRenderer
 {
   final static int CHAR_TO_UPPER = 'A' - 'a';
@@ -89,8 +86,9 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer
   }
 
   @Override
-  public Color getResidueBoxColour(SequenceI seq, int i)
+  public ColorI getResidueBoxColour(SequenceI seq, int i)
   {
+    // rate limiting step when rendering overview for lots of groups
     allGroups = av.getAlignment().findAllGroups(seq);
 
     if (inCurrentSequenceGroup(i))
@@ -105,7 +103,7 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer
       getBoxColour(av.getGlobalColourScheme(), seq, i);
     }
 
-    return resBoxColour;
+    return new Colour(resBoxColour);
   }
 
   /**
@@ -119,12 +117,12 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer
    * @return
    */
   @Override
-  public Color getResidueColour(final SequenceI seq, int position,
+  public ColorI getResidueColour(final SequenceI seq, int position,
           FeatureRenderer fr)
   {
     // TODO replace 8 or so code duplications with calls to this method
     // (refactored as needed)
-    Color col = getResidueBoxColour(seq, position);
+    ColorI col = getResidueBoxColour(seq, position);
 
     if (fr != null)
     {
@@ -217,7 +215,7 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer
           int y1)
   {
     if (seq == null)
-     {
+    {
       return; // fix for racecondition
     }
     int i = start;
@@ -303,7 +301,7 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer
     {
       end = seq.getLength() - 1;
     }
-    graphics.setColor(av.getTextColour());
+    graphics.setColor(ColorUtils.getColor(av.getTextColour()));
 
     if (monospacedFont && av.getShowText() && allGroups.length == 0
             && !av.getColourText() && av.getThresholdTextColour() == 0)
@@ -330,7 +328,7 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer
       for (int i = start; i <= end; i++)
       {
 
-        graphics.setColor(av.getTextColour());
+        graphics.setColor(ColorUtils.getColor(av.getTextColour()));
         getboxColour = false;
         s = seq.getCharAt(i);
 
@@ -362,13 +360,13 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer
               if (resBoxColour.getRed() + resBoxColour.getBlue()
                       + resBoxColour.getGreen() < currentSequenceGroup.thresholdTextColour)
               {
-                graphics.setColor(currentSequenceGroup.textColour2);
+                graphics.setColor(ColorUtils.getColor(currentSequenceGroup.textColour2));
               }
             }
           }
           else
           {
-            graphics.setColor(currentSequenceGroup.textColour);
+            graphics.setColor(ColorUtils.getColor(currentSequenceGroup.textColour));
           }
           if (!isarep && !isgrep
                   && currentSequenceGroup.getShowNonconserved()) // todo
@@ -412,12 +410,12 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer
             if (resBoxColour.getRed() + resBoxColour.getBlue()
                     + resBoxColour.getGreen() < av.getThresholdTextColour())
             {
-              graphics.setColor(av.getTextColour2());
+              graphics.setColor(ColorUtils.getColor(av.getTextColour2()));
             }
           }
           if (!isarep && av.getShowUnconserved())
           {
-            s = getDisplayChar(srep, i, s, '.', currentSequenceGroup);
+            s = getDisplayChar(srep, i, s, '.', null);
 
           }
 
@@ -425,8 +423,7 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer
 
         charOffset = (av.getCharWidth() - fm.charWidth(s)) / 2;
         graphics.drawString(String.valueOf(s),
-                charOffset + av.getCharWidth()
-                * (i - start), y1);
+                charOffset + av.getCharWidth() * (i - start), y1);
 
       }
     }
@@ -448,17 +445,22 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer
   {
     // TODO - use currentSequenceGroup rather than alignment
     // currentSequenceGroup.getConsensus()
-    char conschar = (usesrep) ? (currentGroup == null ? av.getAlignment()
+    char conschar = (usesrep) ? (currentGroup == null
+            || position < currentGroup.getStartRes()
+            || position > currentGroup.getEndRes() ? av.getAlignment()
             .getSeqrep().getCharAt(position)
             : (currentGroup.getSeqrep() != null ? currentGroup.getSeqrep()
                     .getCharAt(position) : av.getAlignment().getSeqrep()
                     .getCharAt(position)))
-            : (currentGroup != null && currentGroup.getConsensus() != null) ? currentGroup
+            : (currentGroup != null && currentGroup.getConsensus() != null
+                    && position >= currentGroup.getStartRes()
+                    && position <= currentGroup.getEndRes() && currentGroup
+                    .getConsensus().annotations.length > position) ? currentGroup
                     .getConsensus().annotations[position].displayCharacter
                     .charAt(0)
                     : av.getAlignmentConsensusAnnotation().annotations[position].displayCharacter
                             .charAt(0);
-    if (conschar != '-'
+    if (!jalview.util.Comparison.isGap(conschar)
             && (sequenceChar == conschar || sequenceChar + CHAR_TO_UPPER == conschar))
     {
       sequenceChar = conservedChar;