JAL-3485 (enum) constants for Auto-annotation label and preference key
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 21 Nov 2019 13:06:35 +0000 (13:06 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 21 Nov 2019 13:06:35 +0000 (13:06 +0000)
src/jalview/appletgui/AnnotationLabels.java
src/jalview/bin/Cache.java
src/jalview/datamodel/AlignmentAnnotation.java
src/jalview/gui/AlignViewport.java
src/jalview/gui/AnnotationLabels.java
src/jalview/gui/IdPanel.java
src/jalview/gui/Preferences.java
src/jalview/project/Jalview2XML.java
src/jalview/renderer/AnnotationRenderer.java
src/jalview/viewmodel/AlignmentViewport.java

index 1366f31..c892778 100755 (executable)
@@ -28,6 +28,7 @@ import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
 import jalview.util.MessageManager;
 import jalview.util.ParseHtmlBodyAndLinks;
+import jalview.viewmodel.AlignmentViewport.AutoAnnotation;
 
 import java.awt.Checkbox;
 import java.awt.CheckboxMenuItem;
@@ -527,7 +528,8 @@ public class AnnotationLabels extends Panel
       {
         if (aa[selectedRow].autoCalculated)
         {
-          if (aa[selectedRow].label.indexOf("Consensus") > -1)
+          if (aa[selectedRow].label
+                  .indexOf(AutoAnnotation.CONSENSUS.label) > -1)
           {
             popup.addSeparator();
             final CheckboxMenuItem cbmi = new CheckboxMenuItem(
index 19aa800..febc107 100755 (executable)
@@ -85,6 +85,7 @@ import org.apache.log4j.SimpleLayout;
  * <li>SHOW_QUALITY show alignment quality annotation</li>
  * <li>SHOW_ANNOTATIONS show alignment annotation rows</li>
  * <li>SHOW_CONSERVATION show alignment conservation annotation</li>
+ * <li>SHOW_OCCUPANCY show alignment column ungapped count annotation</li>
  * <li>SORT_ANNOTATIONS currently either SEQUENCE_AND_LABEL or
  * LABEL_AND_SEQUENCE</li>
  * <li>SHOW_AUTOCALC_ABOVE true to show autocalculated annotations above
@@ -574,7 +575,6 @@ public class Cache
   {
     return applicationProperties.getProperty(key);
   }
-
   /**
    * These methods are used when checking if the saved preference is different
    * to the default setting
index ee9389c..48f840d 100755 (executable)
@@ -23,6 +23,7 @@ package jalview.datamodel;
 import jalview.analysis.Rna;
 import jalview.analysis.SecStrConsensus.SimpleBP;
 import jalview.analysis.WUSSParseException;
+import jalview.viewmodel.AlignmentViewport.AutoAnnotation;
 
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -924,7 +925,7 @@ public class AlignmentAnnotation
       buffer.append(", ");
     }
     // TODO: remove disgusting hack for 'special' treatment of consensus line.
-    if (label.indexOf("Consensus") == 0)
+    if (label.indexOf(AutoAnnotation.CONSENSUS.label) == 0)
     {
       buffer.append("\n");
 
index bc668fd..43fd767 100644 (file)
@@ -263,8 +263,10 @@ public class AlignViewport extends AlignmentViewport
     {
       if (!alignment.isNucleotide())
       {
-        showConservation = Cache.getDefault("SHOW_CONSERVATION", true);
-        showQuality = Cache.getDefault("SHOW_QUALITY", true);
+        showConservation = Cache.getDefault(
+                AutoAnnotation.CONSERVATION.preferenceKey, true);
+        showQuality = Cache.getDefault(AutoAnnotation.QUALITY.preferenceKey,
+                true);
         showGroupConservation = Cache.getDefault("SHOW_GROUP_CONSERVATION",
                 false);
       }
@@ -274,9 +276,11 @@ public class AlignViewport extends AlignmentViewport
       normaliseSequenceLogo = Cache.getDefault("NORMALISE_CONSENSUS_LOGO",
               false);
       showGroupConsensus = Cache.getDefault("SHOW_GROUP_CONSENSUS", false);
-      showConsensus = Cache.getDefault("SHOW_IDENTITY", true);
+      showConsensus = Cache
+              .getDefault(AutoAnnotation.CONSENSUS.preferenceKey, true);
 
-      showOccupancy = Cache.getDefault(Preferences.SHOW_OCCUPANCY, true);
+      showOccupancy = Cache
+              .getDefault(AutoAnnotation.OCCUPANCY.preferenceKey, true);
     }
     initAutoAnnotation();
     String colourProperty = alignment.isNucleotide()
index 2f62a41..df15c03 100755 (executable)
@@ -35,6 +35,7 @@ import jalview.io.FormatAdapter;
 import jalview.util.Comparison;
 import jalview.util.MessageManager;
 import jalview.util.Platform;
+import jalview.viewmodel.AlignmentViewport.AutoAnnotation;
 
 import java.awt.Color;
 import java.awt.Cursor;
@@ -413,7 +414,7 @@ public class AnnotationLabels extends JPanel
           pop.add(item);
         }
       }
-      else if (label.indexOf("Consensus") > -1)
+      else if (label.indexOf(AutoAnnotation.CONSENSUS.label) > -1)
       {
         addConsensusMenuOptions(ap, aa[selectedRow], pop);
 
index d11d7a1..e647bfb 100755 (executable)
@@ -30,6 +30,7 @@ import jalview.io.SequenceAnnotationReport;
 import jalview.util.MessageManager;
 import jalview.util.Platform;
 import jalview.viewmodel.AlignmentViewport;
+import jalview.viewmodel.AlignmentViewport.AutoAnnotation;
 import jalview.viewmodel.ViewportRanges;
 
 import java.awt.BorderLayout;
@@ -414,7 +415,7 @@ public class IdPanel extends JPanel
       return;
     }
     AlignmentAnnotation ann = anns[pos.annotationIndex];
-    if (!ann.label.contains("Consensus"))
+    if (!ann.label.contains(AutoAnnotation.CONSENSUS.label))
     {
       return;
     }
index ab09f74..663390d 100755 (executable)
@@ -40,6 +40,7 @@ import jalview.urls.desktop.DesktopUrlProviderFactory;
 import jalview.util.MessageManager;
 import jalview.util.Platform;
 import jalview.util.UrlConstants;
+import jalview.viewmodel.AlignmentViewport.AutoAnnotation;
 import jalview.ws.sifts.SiftsSettings;
 
 import java.awt.BorderLayout;
@@ -108,8 +109,6 @@ public class Preferences extends GPreferences
 
   public static final String SHOW_AUTOCALC_ABOVE = "SHOW_AUTOCALC_ABOVE";
 
-  public static final String SHOW_OCCUPANCY = "SHOW_OCCUPANCY";
-
   public static final String SHOW_OV_HIDDEN_AT_START = "SHOW_OV_HIDDEN_AT_START";
 
   public static final String USE_LEGACY_GAP = "USE_LEGACY_GAP";
@@ -211,13 +210,17 @@ public class Preferences extends GPreferences
     fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
     annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
 
-    conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
-    quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
-    identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
+    conservation.setSelected(Cache
+            .getDefault(AutoAnnotation.CONSERVATION.preferenceKey, true));
+    quality.setSelected(
+            Cache.getDefault(AutoAnnotation.QUALITY.preferenceKey, true));
+    identity.setSelected(
+            Cache.getDefault(AutoAnnotation.CONSENSUS.preferenceKey, true));
     openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
     showUnconserved
             .setSelected(Cache.getDefault("SHOW_UNCONSERVED", false));
-    showOccupancy.setSelected(Cache.getDefault(SHOW_OCCUPANCY, false));
+    showOccupancy.setSelected(Cache
+            .getDefault(AutoAnnotation.OCCUPANCY.preferenceKey, false));
     showGroupConsensus
             .setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS", false));
     showGroupConservation.setSelected(
@@ -582,12 +585,18 @@ public class Preferences extends GPreferences
             Boolean.toString(openoverv.isSelected()));
     Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
             Boolean.toString(annotations.isSelected()));
-    Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
+    Cache.applicationProperties.setProperty(
+            AutoAnnotation.CONSERVATION.preferenceKey,
             Boolean.toString(conservation.isSelected()));
-    Cache.applicationProperties.setProperty("SHOW_QUALITY",
+    Cache.applicationProperties.setProperty(
+            AutoAnnotation.QUALITY.preferenceKey,
             Boolean.toString(quality.isSelected()));
-    Cache.applicationProperties.setProperty("SHOW_IDENTITY",
+    Cache.applicationProperties.setProperty(
+            AutoAnnotation.CONSENSUS.preferenceKey,
             Boolean.toString(identity.isSelected()));
+    Cache.applicationProperties.setProperty(
+            AutoAnnotation.OCCUPANCY.preferenceKey,
+            Boolean.toString(showOccupancy.isSelected()));
 
     Cache.applicationProperties.setProperty("GAP_SYMBOL",
             gapSymbolCB.getSelectedItem().toString());
@@ -603,8 +612,6 @@ public class Preferences extends GPreferences
             Boolean.toString(idItalics.isSelected()));
     Cache.applicationProperties.setProperty("SHOW_UNCONSERVED",
             Boolean.toString(showUnconserved.isSelected()));
-    Cache.applicationProperties.setProperty(SHOW_OCCUPANCY,
-            Boolean.toString(showOccupancy.isSelected()));
     Cache.applicationProperties.setProperty("SHOW_GROUP_CONSENSUS",
             Boolean.toString(showGroupConsensus.isSelected()));
     Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION",
index b58b01c..59275cd 100644 (file)
@@ -92,6 +92,7 @@ import jalview.util.StringUtils;
 import jalview.util.jarInputStreamProvider;
 import jalview.util.matcher.Condition;
 import jalview.viewmodel.AlignmentViewport;
+import jalview.viewmodel.AlignmentViewport.AutoAnnotation;
 import jalview.viewmodel.PCAModel;
 import jalview.viewmodel.ViewportRanges;
 import jalview.viewmodel.seqfeatures.FeatureRendererSettings;
@@ -210,6 +211,10 @@ import javax.xml.stream.XMLStreamReader;
  */
 public class Jalview2XML
 {
+  private static final String TRUE = "true";
+
+  private static final String FALSE = "false";
+
   private static final String VIEWER_PREFIX = "viewer_";
 
   private static final String RNA_PREFIX = "rna_";
@@ -3642,17 +3647,14 @@ public class Jalview2XML
          * test if annotation is automatically calculated for this view only
          */
         boolean autoForView = false;
-        if (annotation.getLabel().equals("Quality")
-                || annotation.getLabel().equals("Conservation")
-                || annotation.getLabel().equals("Consensus"))
+        if (annotation.getLabel().equals(AutoAnnotation.QUALITY.label)
+                || annotation.getLabel()
+                        .equals(AutoAnnotation.CONSERVATION.label)
+                || annotation.getLabel()
+                        .equals(AutoAnnotation.CONSENSUS.label))
         {
           // Kludge for pre 2.5 projects which lacked the autocalculated flag
           autoForView = true;
-          // JAXB has no has() test; schema defaults value to false
-          // if (!annotation.hasAutoCalculated())
-          // {
-          // annotation.setAutoCalculated(true);
-          // }
         }
         if (autoForView || annotation.isAutoCalculated())
         {
@@ -4589,7 +4591,7 @@ public class Jalview2XML
       {
         if (val.contains("e")) // eh? what can it be?
         {
-          if (val.trim().equals("true"))
+          if (val.trim().equals(TRUE))
           {
             val = "1";
           }
index adca17e..05be67b 100644 (file)
@@ -35,6 +35,7 @@ import jalview.schemes.NucleotideColourScheme;
 import jalview.schemes.ResidueProperties;
 import jalview.schemes.ZappoColourScheme;
 import jalview.util.Platform;
+import jalview.viewmodel.AlignmentViewport.AutoAnnotation;
 
 import java.awt.BasicStroke;
 import java.awt.Color;
@@ -362,7 +363,8 @@ public class AnnotationRenderer
     // properties/rendering attributes as a global 'alignment group' which holds
     // all vis settings for the alignment as a whole rather than a subset
     //
-    if (aa.autoCalculated && (aa.label.startsWith("Consensus")
+    if (aa.autoCalculated
+            && (aa.label.startsWith(AutoAnnotation.CONSENSUS.label)
             || aa.label.startsWith("cDNA Consensus")))
     {
       boolean forComplement = aa.label.startsWith("cDNA Consensus");
index 8dc7bbd..01c7bb2 100644 (file)
@@ -81,6 +81,27 @@ import java.util.Map;
 public abstract class AlignmentViewport
         implements AlignViewportI, CommandListener, VamsasSource
 {
+  /**
+   * An enum for auto-calculated annotations, with constants for the
+   * annotation's label, and the key for the property to show it or not
+   */
+  public enum AutoAnnotation
+  {
+    CONSERVATION("Conservation", "SHOW_CONSERVATION"),
+    QUALITY("Quality", "SHOW_QUALITY"),
+    CONSENSUS("Consensus", "SHOW_IDENTITY"),
+    OCCUPANCY("Occupancy", "SHOW_OCCUPANCY");
+    
+    public final String label;
+    public final String preferenceKey;
+    
+    private AutoAnnotation(String lbl, String prefKey)
+    {
+      this.label = lbl;
+      this.preferenceKey = prefKey;
+    }
+  }
+
   protected ViewportRanges ranges;
 
   protected ViewStyleI viewStyle = new ViewStyle();
@@ -1938,7 +1959,7 @@ public abstract class AlignmentViewport
       {
         initRNAStructure();
       }
-      consensus = new AlignmentAnnotation("Consensus",
+      consensus = new AlignmentAnnotation(AutoAnnotation.CONSENSUS.label,
               MessageManager.getString("label.consensus_descr"),
               new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
       initConsensus(consensus);
@@ -1999,13 +2020,11 @@ public abstract class AlignmentViewport
     }
   }
 
-  // these should be extracted from the view model - style and settings for
-  // derived annotation
   private void initGapCounts()
   {
     if (showOccupancy)
     {
-      gapcounts = new AlignmentAnnotation("Occupancy",
+      gapcounts = new AlignmentAnnotation(AutoAnnotation.OCCUPANCY.label,
               MessageManager.getString("label.occupancy_descr"),
               new Annotation[1], 0f, alignment.getHeight(),
               AlignmentAnnotation.BAR_GRAPH);
@@ -2024,7 +2043,8 @@ public abstract class AlignmentViewport
     {
       if (conservation == null)
       {
-        conservation = new AlignmentAnnotation("Conservation",
+        conservation = new AlignmentAnnotation(
+                AutoAnnotation.CONSERVATION.label,
                 MessageManager.formatMessage("label.conservation_descr",
                         getConsPercGaps()),
                 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
@@ -2041,7 +2061,7 @@ public abstract class AlignmentViewport
     {
       if (quality == null)
       {
-        quality = new AlignmentAnnotation("Quality",
+        quality = new AlignmentAnnotation(AutoAnnotation.QUALITY.label,
                 MessageManager.getString("label.quality_descr"),
                 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
         quality.hasText = true;