JAL-819 fix broken initConsensus
[jalview.git] / src / jalview / viewmodel / AlignmentViewport.java
index 6427b45..69cc645 100644 (file)
@@ -662,7 +662,8 @@ public abstract class AlignmentViewport
          * retain any colour thresholds per group while
          * changing choice of colour scheme (JAL-2386)
          */
-        sg.setColourScheme(cs);
+        sg.setColourScheme(
+                cs == null ? null : cs.getInstance(this, sg));
         if (cs != null)
         {
           sg.getGroupColourScheme().alignmentChanged(sg,
@@ -1636,6 +1637,7 @@ public abstract class AlignmentViewport
   public void invertColumnSelection()
   {
     colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
+    isColSelChanged(true);
   }
 
   @Override
@@ -1929,18 +1931,31 @@ public abstract class AlignmentViewport
     {
       if (!alignment.isNucleotide())
       {
-        initConservation();
-        initQuality();
+        if (showConservation && conservation == null)
+        {
+          initConservation();
+        }
+        if (showQuality && quality == null)
+        {
+          initQuality();
+        }
       }
       else
       {
-        initRNAStructure();
+        if (showConsensus && alignment.hasRNAStructure()
+                && strucConsensus == null)
+        {
+          initRNAStructure();
+        }
+      }
+      if (showConsensus)
+      {
+        initConsensus();
+      }
+      if (showOccupancy)
+      {
+        initOccupancy();
       }
-      consensus = new AlignmentAnnotation("Consensus",
-              MessageManager.getString("label.consensus_descr"),
-              new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
-      initConsensus(consensus);
-      initGapCounts();
 
       initComplementConsensus();
     }
@@ -1978,7 +1993,9 @@ public abstract class AlignmentViewport
                           .getString("label.complement_consensus_descr"),
                   new Annotation[1], 0f, 100f,
                   AlignmentAnnotation.BAR_GRAPH);
-          initConsensus(complementConsensus);
+          complementConsensus.hasText = true;
+          complementConsensus.autoCalculated = true;
+          alignment.addAnnotation(complementConsensus);
           return true;
         }
       }
@@ -1986,84 +2003,64 @@ public abstract class AlignmentViewport
     return false;
   }
 
-  private void initConsensus(AlignmentAnnotation aa)
+  @Override
+  public void initConsensus()
   {
-    aa.hasText = true;
-    aa.autoCalculated = true;
-
-    if (showConsensus)
-    {
-      alignment.addAnnotation(aa);
-    }
+    consensus = new AlignmentAnnotation("Consensus",
+            MessageManager.getString("label.consensus_descr"),
+            new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
+    consensus.hasText = true;
+    consensus.autoCalculated = true;
+    alignment.addAnnotation(consensus);
   }
 
-  // these should be extracted from the view model - style and settings for
-  // derived annotation
-  private void initGapCounts()
+  @Override
+  public void initOccupancy()
   {
-    if (showOccupancy)
-    {
-      gapcounts = new AlignmentAnnotation("Occupancy",
-              MessageManager.getString("label.occupancy_descr"),
-              new Annotation[1], 0f, alignment.getHeight(),
-              AlignmentAnnotation.BAR_GRAPH);
-      gapcounts.hasText = true;
-      gapcounts.autoCalculated = true;
-      gapcounts.scaleColLabel = true;
-      gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
+    gapcounts = new AlignmentAnnotation("Occupancy",
+            MessageManager.getString("label.occupancy_descr"),
+            new Annotation[1], 0f, alignment.getHeight(),
+            AlignmentAnnotation.BAR_GRAPH);
+    gapcounts.hasText = true;
+    gapcounts.autoCalculated = true;
+    gapcounts.scaleColLabel = true;
+    gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
 
-      alignment.addAnnotation(gapcounts);
-    }
+    alignment.addAnnotation(gapcounts);
   }
 
-  private void initConservation()
+  @Override
+  public void initConservation()
   {
-    if (showConservation)
-    {
-      if (conservation == null)
-      {
-        conservation = new AlignmentAnnotation("Conservation",
-                MessageManager.formatMessage("label.conservation_descr",
-                        getConsPercGaps()),
-                new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
-        conservation.hasText = true;
-        conservation.autoCalculated = true;
-        alignment.addAnnotation(conservation);
-      }
-    }
+    conservation = new AlignmentAnnotation("Conservation",
+            MessageManager.formatMessage("label.conservation_descr",
+                    getConsPercGaps()),
+            new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
+    conservation.hasText = true;
+    conservation.autoCalculated = true;
+    alignment.addAnnotation(conservation);
   }
 
-  private void initQuality()
+  @Override
+  public void initQuality()
   {
-    if (showQuality)
-    {
-      if (quality == null)
-      {
-        quality = new AlignmentAnnotation("Quality",
-                MessageManager.getString("label.quality_descr"),
-                new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
-        quality.hasText = true;
-        quality.autoCalculated = true;
-        alignment.addAnnotation(quality);
-      }
-    }
+    quality = new AlignmentAnnotation("Quality",
+            MessageManager.getString("label.quality_descr"),
+            new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
+    quality.hasText = true;
+    quality.autoCalculated = true;
+    alignment.addAnnotation(quality);
   }
 
-  private void initRNAStructure()
+  @Override
+  public void initRNAStructure()
   {
-    if (alignment.hasRNAStructure() && strucConsensus == null)
-    {
-      strucConsensus = new AlignmentAnnotation("StrucConsensus",
-              MessageManager.getString("label.strucconsensus_descr"),
-              new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
-      strucConsensus.hasText = true;
-      strucConsensus.autoCalculated = true;
-
-      if (showConsensus)
-      {
-        alignment.addAnnotation(strucConsensus);
-      }
-    }
+    strucConsensus = new AlignmentAnnotation("StrucConsensus",
+            MessageManager.getString("label.strucconsensus_descr"),
+            new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
+    strucConsensus.hasText = true;
+    strucConsensus.autoCalculated = true;
+    alignment.addAnnotation(strucConsensus);
   }
 
   /*
@@ -2714,6 +2711,30 @@ public abstract class AlignmentViewport
     viewStyle.setProteinFontAsCdna(b);
   }
 
+  @Override
+  public void setShowComplementFeatures(boolean b)
+  {
+    viewStyle.setShowComplementFeatures(b);
+  }
+
+  @Override
+  public boolean isShowComplementFeatures()
+  {
+    return viewStyle.isShowComplementFeatures();
+  }
+
+  @Override
+  public void setShowComplementFeaturesOnTop(boolean b)
+  {
+    viewStyle.setShowComplementFeaturesOnTop(b);
+  }
+
+  @Override
+  public boolean isShowComplementFeaturesOnTop()
+  {
+    return viewStyle.isShowComplementFeaturesOnTop();
+  }
+
   /**
    * @return true if view should scroll to show the highlighted region of a
    *         sequence