JAL-2386 simplify changeColour (doesn't change colour thresholds)
[jalview.git] / src / jalview / viewmodel / AlignmentViewport.java
index 0803773..9f53f02 100644 (file)
@@ -599,7 +599,7 @@ public abstract class AlignmentViewport implements AlignViewportI,
 
   protected boolean ignoreGapsInConsensusCalculation = false;
 
-  protected CollectionColourScheme globalColourScheme;
+  protected CollectionColourSchemeI globalColourScheme;
 
   @Override
   public void setGlobalColourScheme(ColourSchemeI cs)
@@ -614,6 +614,8 @@ public abstract class AlignmentViewport implements AlignViewportI,
 
     /*
      * only instantiate colour scheme once, thereafter update it
+     * this means that any conservation or PID threshold settings
+     * persist when the alignment colour scheme is changed
      */
     if (globalColourScheme == null)
     {
@@ -621,72 +623,38 @@ public abstract class AlignmentViewport implements AlignViewportI,
     }
     globalColourScheme.setColourScheme(cs);
 
-    boolean recalc = false;
+    // boolean recalc = false;
+    // TODO: do threshold and increment belong in ViewStyle or colour scheme?
+    // problem: groups need this but do not currently have a ViewStyle
+
     if (cs != null)
     {
-      recalc = getConservationSelected();
-      if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
+      if (getConservationSelected() || getAbovePIDThreshold()
+              || cs instanceof PIDColourScheme
               || cs instanceof Blosum62ColourScheme)
       {
-        recalc = true;
-        globalColourScheme.setThreshold(viewStyle.getThreshold(),
-                ignoreGapsInConsensusCalculation);
-      }
-      else
-      {
-        globalColourScheme
-                .setThreshold(0, ignoreGapsInConsensusCalculation);
-      }
-      if (recalc)
-      {
-        globalColourScheme.setConsensus(hconsensus);
         globalColourScheme.setConservation(hconservation);
       }
-      globalColourScheme.setConservationApplied(getConservationSelected());
       globalColourScheme.alignmentChanged(alignment, hiddenRepSequences);
     }
+
+    /*
+     * if 'apply colour to all groups' is selected... do so
+     * (but don't transfer any colour threshold settings to groups)
+     */
     if (getColourAppliesToAllGroups())
     {
       for (SequenceGroup sg : getAlignment().getGroups())
       {
-        if (cs == null)
-        {
-          sg.setColourScheme(null);
-          continue;
-        }
-        CollectionColourScheme groupColour = new CollectionColourScheme(cs.getInstance(sg,
-                getHiddenRepSequences()));
-        sg.setGroupColourScheme(groupColour);
-        sg.setConsPercGaps(ConsPercGaps);
-        if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
-                || cs instanceof Blosum62ColourScheme)
-        {
-          groupColour.setThreshold(viewStyle.getThreshold(),
-                  isIgnoreGapsConsensus());
-          recalc = true;
-        }
-        else
-        {
-          groupColour.setThreshold(0, isIgnoreGapsConsensus());
-        }
-
-        if (getConservationSelected())
-        {
-          groupColour.setConservationApplied(true);
-          recalc = true;
-        }
-        else
-        {
-          groupColour.setConservation(null);
-          // sg.cs.setThreshold(0, getIgnoreGapsConsensus());
-        }
-        if (recalc)
-        {
-          sg.recalcConservation();
-        }
-        else
+        /*
+         * retain any colour thresholds per group while
+         * changing choice of colour scheme (JAL-2386)
+         */
+        sg.setColourScheme(cs);
+        if (cs != null)
         {
-          groupColour.alignmentChanged(sg, hiddenRepSequences);
+          sg.getGroupColourScheme()
+                  .alignmentChanged(sg, hiddenRepSequences);
         }
       }
     }
@@ -1880,7 +1848,7 @@ public abstract class AlignmentViewport implements AlignViewportI,
    */
   void resetAllColourSchemes()
   {
-    CollectionColourScheme cs = globalColourScheme;
+    CollectionColourSchemeI cs = globalColourScheme;
     if (cs != null)
     {
       cs.alignmentChanged(alignment, hiddenRepSequences);