JAL-819 menu options to reinstate missing auto-calculated annotation
[jalview.git] / src / jalview / viewmodel / AlignmentViewport.java
index 8dcd1b3..9de0b94 100644 (file)
@@ -1931,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();
     }
@@ -1988,84 +2001,76 @@ public abstract class AlignmentViewport
     return false;
   }
 
+  @Override
+  public void initConsensus()
+  {
+    consensus = new AlignmentAnnotation("Consensus",
+            MessageManager.getString("label.consensus_descr"),
+            new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
+    initConsensus(consensus);
+  }
+
   private void initConsensus(AlignmentAnnotation aa)
   {
-    aa.hasText = true;
-    aa.autoCalculated = true;
+    consensus = new AlignmentAnnotation("Consensus",
+            MessageManager.getString("label.consensus_descr"),
+            new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
+    consensus.hasText = true;
+    consensus.autoCalculated = true;
 
     if (showConsensus)
     {
-      alignment.addAnnotation(aa);
+      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);
   }
 
   /*