JAL-2443 push getResidueBoxColour inside getResidueColour
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Wed, 15 Mar 2017 12:55:25 +0000 (12:55 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Wed, 15 Mar 2017 12:55:25 +0000 (12:55 +0000)
src/MCview/AppletPDBCanvas.java
src/MCview/PDBCanvas.java
src/jalview/api/SequenceRenderer.java
src/jalview/appletgui/OverviewPanel.java
src/jalview/appletgui/SequenceRenderer.java
src/jalview/ext/jmol/JmolCommands.java
src/jalview/ext/varna/VarnaCommands.java
src/jalview/gui/OverviewPanel.java
src/jalview/gui/SequenceRenderer.java
test/jalview/gui/SequenceRendererTest.java
test/jalview/schemes/ColourSchemesTest.java

index 1602cb4..3ae0650 100644 (file)
@@ -607,23 +607,15 @@ public class AppletPDBCanvas extends Panel implements MouseListener,
                 if (pos > 0)
                 {
                   pos = sequence[s].findIndex(pos);
-                  tmp.startCol = sr.getResidueBoxColour(sequence[s], pos);
-                  if (showFeatures)
-                  {
-                    tmp.startCol = finder.findFeatureColour(tmp.startCol,
-                            sequence[s], pos);
-                  }
+                  tmp.startCol = sr.getResidueColour(sequence[s], pos,
+                          finder);
                 }
                 pos = mapping[m].getSeqPos(tmp.at2.resNumber) - 1;
                 if (pos > 0)
                 {
                   pos = sequence[s].findIndex(pos);
-                  tmp.endCol = sr.getResidueBoxColour(sequence[s], pos);
-                  if (showFeatures)
-                  {
-                    tmp.endCol = finder.findFeatureColour(tmp.endCol,
-                            sequence[s], pos);
-                  }
+                  tmp.endCol = sr
+                          .getResidueColour(sequence[s], pos, finder);
                 }
               }
             }
index ae58758..08bca8c 100644 (file)
@@ -575,23 +575,15 @@ public class PDBCanvas extends JPanel implements MouseListener,
                 if (pos > 0)
                 {
                   pos = sequence[s].findIndex(pos);
-                  tmp.startCol = sr.getResidueBoxColour(sequence[s], pos);
-                  if (showFeatures)
-                  {
-                    tmp.startCol = finder.findFeatureColour(tmp.startCol,
-                            sequence[s], pos);
-                  }
+                  tmp.startCol = sr.getResidueColour(sequence[s], pos,
+                          finder);
                 }
                 pos = mapping[m].getSeqPos(tmp.at2.resNumber) - 1;
                 if (pos > 0)
                 {
                   pos = sequence[s].findIndex(pos);
-                  tmp.endCol = sr.getResidueBoxColour(sequence[s], pos);
-                  if (showFeatures)
-                  {
-                    tmp.endCol = finder.findFeatureColour(tmp.endCol,
-                            sequence[s], pos);
-                  }
+                  tmp.endCol = sr
+                          .getResidueColour(sequence[s], pos, finder);
                 }
 
               }
index 5e772a4..54f7fb6 100644 (file)
@@ -28,8 +28,6 @@ import java.awt.Color;
 public interface SequenceRenderer
 {
 
-  Color getResidueBoxColour(SequenceI sequenceI, int r);
-
   Color getResidueColour(SequenceI seq, int position,
           FeatureColourFinder finder);
 
index 8427c77..251e1c8 100755 (executable)
@@ -352,16 +352,11 @@ public class OverviewPanel extends Panel implements Runnable,
 
         if (seq.getLength() > lastcol)
         {
-          color = sr.getResidueBoxColour(seq, lastcol);
-
-          if (av.isShowSequenceFeatures())
-          {
-            color = finder.findFeatureColour(color, seq, lastcol);
-          }
+          color = sr.getResidueColour(seq, lastcol, finder);
         }
         else
         {
-          color = Color.white; // White
+          color = Color.white;
         }
 
         if (hiddenRow
index b5586c9..78ed4a3 100755 (executable)
@@ -69,8 +69,7 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer
     this.renderGaps = renderGaps;
   }
 
-  @Override
-  public Color getResidueBoxColour(SequenceI seq, int i)
+  protected Color getResidueBoxColour(SequenceI seq, int i)
   {
     allGroups = av.getAlignment().findAllGroups(seq);
 
index a1ff3c5..4212749 100644 (file)
@@ -102,13 +102,8 @@ public class JmolCommands
 
               lastPos = pos;
 
-              Color col = sr.getResidueBoxColour(sequence[pdbfnum][s], r);
-
-              if (fr != null)
-              {
-                col = finder
-                        .findFeatureColour(col, sequence[pdbfnum][s], r);
-              }
+              Color col = sr.getResidueColour(sequence[pdbfnum][s], r,
+                      finder);
 
               /*
                * shade hidden regions darker
index 617dc8f..d65f1d5 100644 (file)
@@ -48,7 +48,7 @@ public class VarnaCommands
   public static String[] getColourBySequenceCommand(
           StructureSelectionManager ssm, String[] files,
           SequenceI[][] sequence, SequenceRenderer sr,
-          FeatureColourFinder fr,
+          FeatureColourFinder finder,
           AlignmentI alignment)
   {
     ArrayList<String> str = new ArrayList<String>();
@@ -88,12 +88,9 @@ public class VarnaCommands
 
               lastPos = pos;
 
-              Color col = sr.getResidueBoxColour(sequence[pdbfnum][s], r);
+              Color col = sr.getResidueColour(sequence[pdbfnum][s], r,
+                      finder);
 
-              if (fr != null)
-              {
-                col = fr.findFeatureColour(col, sequence[pdbfnum][s], r);
-              }
               String newSelcom = (mapping[m].getChain() != " " ? ":"
                       + mapping[m].getChain() : "")
                       + "/"
index 7fdb610..4097c40 100755 (executable)
@@ -370,12 +370,7 @@ public class OverviewPanel extends JPanel implements Runnable
 
         if (seq.getLength() > lastcol)
         {
-          color = sr.getResidueBoxColour(seq, lastcol);
-
-          if (av.isShowSequenceFeatures())
-          {
-            color = finder.findFeatureColour(color, seq, lastcol);
-          }
+          color = sr.getResidueColour(seq, lastcol, finder);
         }
         else
         {
index 764ef3f..1c0420d 100755 (executable)
@@ -53,14 +53,13 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer
   boolean forOverview = false;
 
   /**
-   * Creates a new SequenceRenderer object.
+   * Creates a new SequenceRenderer object
    * 
-   * @param av
-   *          DOCUMENT ME!
+   * @param viewport
    */
-  public SequenceRenderer(AlignViewport av)
+  public SequenceRenderer(AlignViewport viewport)
   {
-    this.av = av;
+    this.av = viewport;
   }
 
   /**
@@ -83,8 +82,7 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer
     this.renderGaps = renderGaps;
   }
 
-  @Override
-  public Color getResidueBoxColour(SequenceI seq, int i)
+  protected Color getResidueBoxColour(SequenceI seq, int i)
   {
     // rate limiting step when rendering overview for lots of groups
     allGroups = av.getAlignment().findAllGroups(seq);
@@ -118,8 +116,6 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer
   public Color getResidueColour(final SequenceI seq, int position,
           FeatureColourFinder finder)
   {
-    // TODO replace 8 or so code duplications with calls to this method
-    // (refactored as needed)
     Color col = getResidueBoxColour(seq, position);
 
     if (finder != null)
index 81289b0..29a9a52 100644 (file)
@@ -53,10 +53,10 @@ public class SequenceRendererTest
     av.setGlobalColourScheme(new ZappoColourScheme());
 
     // @see ResidueProperties.zappo
-    assertEquals(Color.pink, sr.getResidueColour(seq, 0, null)); // M
-    assertEquals(Color.green, sr.getResidueColour(seq, 2, null)); // T
-    assertEquals(Color.magenta, sr.getResidueColour(seq, 5, null)); // G
-    assertEquals(Color.orange, sr.getResidueColour(seq, 12, null)); // F
+    assertEquals(Color.pink, sr.getResidueBoxColour(seq, 0)); // M
+    assertEquals(Color.green, sr.getResidueBoxColour(seq, 2)); // T
+    assertEquals(Color.magenta, sr.getResidueBoxColour(seq, 5)); // G
+    assertEquals(Color.orange, sr.getResidueBoxColour(seq, 12)); // F
   }
   // TODO more tests for getResidueBoxColour covering groups, feature rendering,
   // gaps, overview...
index 4618ed7..0aaa38c 100644 (file)
@@ -228,9 +228,9 @@ public class ColourSchemesTest
      * set and check Taylor colours
      */
     af.changeColour_actionPerformed(JalviewColourScheme.Taylor.toString());
-    Color taylor1 = sr.getResidueBoxColour(seq, 88); // E 255,0,102
-    Color taylor2 = sr.getResidueBoxColour(seq, 89); // A 204,255,0
-    Color taylor3 = sr.getResidueBoxColour(seq, 90); // G 255,153,0
+    Color taylor1 = sr.getResidueColour(seq, 88, null); // E 255,0,102
+    Color taylor2 = sr.getResidueColour(seq, 89, null); // A 204,255,0
+    Color taylor3 = sr.getResidueColour(seq, 90, null); // G 255,153,0
     assertEquals(taylor1, new Color(255, 0, 102));
     assertEquals(taylor2, new Color(204, 255, 0));
     assertEquals(taylor3, new Color(255, 153, 0));
@@ -239,9 +239,9 @@ public class ColourSchemesTest
      * set and check Zappo colours
      */
     af.changeColour_actionPerformed(JalviewColourScheme.Zappo.toString());
-    Color zappo1 = sr.getResidueBoxColour(seq, 88); // E red
-    Color zappo2 = sr.getResidueBoxColour(seq, 89); // A pink
-    Color zappo3 = sr.getResidueBoxColour(seq, 90); // G magenta
+    Color zappo1 = sr.getResidueColour(seq, 88, null); // E red
+    Color zappo2 = sr.getResidueColour(seq, 89, null); // A pink
+    Color zappo3 = sr.getResidueColour(seq, 90, null); // G magenta
     assertEquals(zappo1, Color.red);
     assertEquals(zappo2, Color.pink);
     assertEquals(zappo3, Color.magenta);
@@ -250,9 +250,9 @@ public class ColourSchemesTest
      * set 'stripy' colours - odd columns are Taylor and even are Zappo 
      */
     af.changeColour_actionPerformed("stripy");
-    Color stripy1 = sr.getResidueBoxColour(seq, 88);
-    Color stripy2 = sr.getResidueBoxColour(seq, 89);
-    Color stripy3 = sr.getResidueBoxColour(seq, 90);
+    Color stripy1 = sr.getResidueColour(seq, 88, null);
+    Color stripy2 = sr.getResidueColour(seq, 89, null);
+    Color stripy3 = sr.getResidueColour(seq, 90, null);
     assertEquals(stripy1, zappo1);
     assertEquals(stripy2, taylor2);
     assertEquals(stripy3, zappo3);
@@ -261,9 +261,9 @@ public class ColourSchemesTest
      * set and check Clustal colours
      */
     af.changeColour_actionPerformed(JalviewColourScheme.Clustal.toString());
-    Color clustal1 = sr.getResidueBoxColour(seq, 88);
-    Color clustal2 = sr.getResidueBoxColour(seq, 89);
-    Color clustal3 = sr.getResidueBoxColour(seq, 90);
+    Color clustal1 = sr.getResidueColour(seq, 88, null);
+    Color clustal2 = sr.getResidueColour(seq, 89, null);
+    Color clustal3 = sr.getResidueColour(seq, 90, null);
     assertEquals(clustal1, ClustalColour.MAGENTA.colour);
     assertEquals(clustal2, ClustalColour.BLUE.colour);
     assertEquals(clustal3, ClustalColour.ORANGE.colour);
@@ -272,9 +272,9 @@ public class ColourSchemesTest
      * set 'MyClustal' colours - uses AWT colour equivalents
      */
     af.changeColour_actionPerformed("MyClustal");
-    Color myclustal1 = sr.getResidueBoxColour(seq, 88);
-    Color myclustal2 = sr.getResidueBoxColour(seq, 89);
-    Color myclustal3 = sr.getResidueBoxColour(seq, 90);
+    Color myclustal1 = sr.getResidueColour(seq, 88, null);
+    Color myclustal2 = sr.getResidueColour(seq, 89, null);
+    Color myclustal3 = sr.getResidueColour(seq, 90, null);
     assertEquals(myclustal1, Color.MAGENTA);
     assertEquals(myclustal2, Color.BLUE);
     assertEquals(myclustal3, Color.ORANGE);