From: gmungoc Date: Thu, 21 Nov 2019 13:06:35 +0000 (+0000) Subject: JAL-3485 (enum) constants for Auto-annotation label and preference key X-Git-Url: http://source.jalview.org/gitweb/?p=jalview.git;a=commitdiff_plain;h=b5889c572976c81f068d9743363695ca84e7d413 JAL-3485 (enum) constants for Auto-annotation label and preference key --- diff --git a/src/jalview/appletgui/AnnotationLabels.java b/src/jalview/appletgui/AnnotationLabels.java index 1366f31..c892778 100755 --- a/src/jalview/appletgui/AnnotationLabels.java +++ b/src/jalview/appletgui/AnnotationLabels.java @@ -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( diff --git a/src/jalview/bin/Cache.java b/src/jalview/bin/Cache.java index 19aa800..febc107 100755 --- a/src/jalview/bin/Cache.java +++ b/src/jalview/bin/Cache.java @@ -85,6 +85,7 @@ import org.apache.log4j.SimpleLayout; *
  • SHOW_QUALITY show alignment quality annotation
  • *
  • SHOW_ANNOTATIONS show alignment annotation rows
  • *
  • SHOW_CONSERVATION show alignment conservation annotation
  • + *
  • SHOW_OCCUPANCY show alignment column ungapped count annotation
  • *
  • SORT_ANNOTATIONS currently either SEQUENCE_AND_LABEL or * LABEL_AND_SEQUENCE
  • *
  • 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 diff --git a/src/jalview/datamodel/AlignmentAnnotation.java b/src/jalview/datamodel/AlignmentAnnotation.java index ee9389c..48f840d 100755 --- a/src/jalview/datamodel/AlignmentAnnotation.java +++ b/src/jalview/datamodel/AlignmentAnnotation.java @@ -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"); diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index bc668fd..43fd767 100644 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -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() diff --git a/src/jalview/gui/AnnotationLabels.java b/src/jalview/gui/AnnotationLabels.java index 2f62a41..df15c03 100755 --- a/src/jalview/gui/AnnotationLabels.java +++ b/src/jalview/gui/AnnotationLabels.java @@ -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); diff --git a/src/jalview/gui/IdPanel.java b/src/jalview/gui/IdPanel.java index d11d7a1..e647bfb 100755 --- a/src/jalview/gui/IdPanel.java +++ b/src/jalview/gui/IdPanel.java @@ -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; } diff --git a/src/jalview/gui/Preferences.java b/src/jalview/gui/Preferences.java index ab09f74..663390d 100755 --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@ -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", diff --git a/src/jalview/project/Jalview2XML.java b/src/jalview/project/Jalview2XML.java index b58b01c..59275cd 100644 --- a/src/jalview/project/Jalview2XML.java +++ b/src/jalview/project/Jalview2XML.java @@ -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"; } diff --git a/src/jalview/renderer/AnnotationRenderer.java b/src/jalview/renderer/AnnotationRenderer.java index adca17e..05be67b 100644 --- a/src/jalview/renderer/AnnotationRenderer.java +++ b/src/jalview/renderer/AnnotationRenderer.java @@ -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"); diff --git a/src/jalview/viewmodel/AlignmentViewport.java b/src/jalview/viewmodel/AlignmentViewport.java index 8dc7bbd..01c7bb2 100644 --- a/src/jalview/viewmodel/AlignmentViewport.java +++ b/src/jalview/viewmodel/AlignmentViewport.java @@ -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;