JAL-1551 tidy
[jalview.git] / src / jalview / gui / SequenceRenderer.java
index 70acb7b..427eb08 100755 (executable)
@@ -29,12 +29,6 @@ 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';
@@ -217,7 +211,7 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer
           int y1)
   {
     if (seq == null)
-     {
+    {
       return; // fix for racecondition
     }
     int i = start;
@@ -323,11 +317,17 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer
     {
       boolean srep = av.isDisplayReferenceSeq();
       boolean getboxColour = false;
+      boolean isarep = av.getAlignment().getSeqrep() == seq;
+      boolean isgrep = currentSequenceGroup != null ? currentSequenceGroup
+              .getSeqrep() == seq : false;
+      char sr_c;
       for (int i = start; i <= end; i++)
       {
+
         graphics.setColor(av.getTextColour());
         getboxColour = false;
         s = seq.getCharAt(i);
+
         if (!renderGaps && jalview.util.Comparison.isGap(s))
         {
           continue;
@@ -364,11 +364,12 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer
           {
             graphics.setColor(currentSequenceGroup.textColour);
           }
-          if (currentSequenceGroup.getShowNonconserved()) // todo optimize
+          if (!isarep && !isgrep
+                  && currentSequenceGroup.getShowNonconserved()) // todo
+                                                                 // optimize
           {
             // todo - use sequence group consensus
-            s = getDisplayChar(srep, i, s,
-                    '.');
+            s = getDisplayChar(srep, i, s, '.', currentSequenceGroup);
 
           }
 
@@ -408,10 +409,9 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer
               graphics.setColor(av.getTextColour2());
             }
           }
-          if (av.getShowUnconserved())
+          if (!isarep && av.getShowUnconserved())
           {
-            s = getDisplayChar(srep, i, s,
-                    '.');
+            s = getDisplayChar(srep, i, s, '.', null);
 
           }
 
@@ -419,8 +419,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);
 
       }
     }
@@ -438,13 +437,26 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer
    * @return
    */
   private char getDisplayChar(final boolean usesrep, int position,
-          char sequenceChar, char conservedChar)
+          char sequenceChar, char conservedChar, SequenceGroup currentGroup)
   {
     // TODO - use currentSequenceGroup rather than alignment
     // currentSequenceGroup.getConsensus()
-    char conschar = (usesrep) ? av.getAlignment().getSeqrep().getCharAt(position) : av.getAlignmentConsensusAnnotation().annotations[position].displayCharacter
-            .charAt(0);
-    if (conschar != '-'
+    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
+                    && 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 (!jalview.util.Comparison.isGap(conschar)
             && (sequenceChar == conschar || sequenceChar + CHAR_TO_UPPER == conschar))
     {
       sequenceChar = conservedChar;