From 30b23d19ad4985ef3cdaf5f54936f5c48b31251d Mon Sep 17 00:00:00 2001 From: gmungoc Date: Mon, 14 Jan 2019 12:14:59 +0000 Subject: [PATCH] JAL-3184 JAL-2843 restore saved feature filters correctly --- src/jalview/gui/Jalview2XML.java | 273 +++++++++++--------- src/jalview/gui/Jalview2XML_V1.java | 11 +- .../seqfeatures/FeatureRendererSettings.java | 16 +- 3 files changed, 176 insertions(+), 124 deletions(-) diff --git a/src/jalview/gui/Jalview2XML.java b/src/jalview/gui/Jalview2XML.java index 9285754..c8e887b 100644 --- a/src/jalview/gui/Jalview2XML.java +++ b/src/jalview/gui/Jalview2XML.java @@ -52,7 +52,6 @@ import jalview.schemabinding.version2.Annotation; import jalview.schemabinding.version2.AnnotationColours; import jalview.schemabinding.version2.AnnotationElement; import jalview.schemabinding.version2.CalcIdParam; -import jalview.schemabinding.version2.Colour; import jalview.schemabinding.version2.CompoundMatcher; import jalview.schemabinding.version2.DBRef; import jalview.schemabinding.version2.Features; @@ -4639,125 +4638,9 @@ public class Jalview2XML af.viewport.setShowGroupConservation(false); } - // recover feature settings if (jms.getFeatureSettings() != null) { - FeatureRenderer fr = af.alignPanel.getSeqPanel().seqCanvas - .getFeatureRenderer(); - FeaturesDisplayed fdi; - af.viewport.setFeaturesDisplayed(fdi = new FeaturesDisplayed()); - String[] renderOrder = new String[jms.getFeatureSettings() - .getSettingCount()]; - Map featureColours = new Hashtable<>(); - Map featureOrder = new Hashtable<>(); - - for (int fs = 0; fs < jms.getFeatureSettings() - .getSettingCount(); fs++) - { - Setting setting = jms.getFeatureSettings().getSetting(fs); - String featureType = setting.getType(); - - /* - * restore feature filters (if any) - */ - MatcherSet filters = setting.getMatcherSet(); - if (filters != null) - { - FeatureMatcherSetI filter = Jalview2XML - .unmarshalFilter(featureType, filters); - if (!filter.isEmpty()) - { - fr.setFeatureFilter(featureType, filter); - } - } - - /* - * restore feature colour scheme - */ - Color maxColour = new Color(setting.getColour()); - if (setting.hasMincolour()) - { - /* - * minColour is always set unless a simple colour - * (including for colour by label though it doesn't use it) - */ - Color minColour = new Color(setting.getMincolour()); - Color noValueColour = minColour; - NoValueColour noColour = setting.getNoValueColour(); - if (noColour == NoValueColour.NONE) - { - noValueColour = null; - } - else if (noColour == NoValueColour.MAX) - { - noValueColour = maxColour; - } - float min = setting.hasMin() ? setting.getMin() : 0f; - float max = setting.hasMin() ? setting.getMax() : 1f; - FeatureColourI gc = new FeatureColour(minColour, maxColour, - noValueColour, min, max); - if (setting.getAttributeNameCount() > 0) - { - gc.setAttributeName(setting.getAttributeName()); - } - if (setting.hasThreshold()) - { - gc.setThreshold(setting.getThreshold()); - int threshstate = setting.getThreshstate(); - // -1 = None, 0 = Below, 1 = Above threshold - if (threshstate == 0) - { - gc.setBelowThreshold(true); - } - else if (threshstate == 1) - { - gc.setAboveThreshold(true); - } - } - gc.setAutoScaled(true); // default - if (setting.hasAutoScale()) - { - gc.setAutoScaled(setting.getAutoScale()); - } - if (setting.hasColourByLabel()) - { - gc.setColourByLabel(setting.getColourByLabel()); - } - // and put in the feature colour table. - featureColours.put(featureType, gc); - } - else - { - featureColours.put(featureType, - new FeatureColour(maxColour)); - } - renderOrder[fs] = featureType; - if (setting.hasOrder()) - { - featureOrder.put(featureType, setting.getOrder()); - } - else - { - featureOrder.put(featureType, new Float( - fs / jms.getFeatureSettings().getSettingCount())); - } - if (setting.getDisplay()) - { - fdi.setVisible(featureType); - } - } - Map fgtable = new Hashtable<>(); - for (int gs = 0; gs < jms.getFeatureSettings().getGroupCount(); gs++) - { - Group grp = jms.getFeatureSettings().getGroup(gs); - fgtable.put(grp.getName(), new Boolean(grp.getDisplay())); - } - // FeatureRendererSettings frs = new FeatureRendererSettings(renderOrder, - // fgtable, featureColours, jms.getFeatureSettings().hasTransparency() ? - // jms.getFeatureSettings().getTransparency() : 0.0, featureOrder); - FeatureRendererSettings frs = new FeatureRendererSettings(renderOrder, - fgtable, featureColours, 1.0f, featureOrder); - fr.transferSettings(frs); + loadFeatureSettings(jms, af); } if (view.getHiddenColumnsCount() > 0) @@ -4812,6 +4695,160 @@ public class Jalview2XML } /** + * Loads feature settings data from project XML and stores + *
    + *
  • feature type visibility in the Viewport
  • + *
  • other data in the FeatureRenderer: + *
      + *
    • feature type render order
    • + *
    • feature type colours
    • + *
    • feature type filters
    • + *
    • feature groups and their visibility
    • + *
    + *
  • + *
+ * + * @param jms + * @param af + */ + static void loadFeatureSettings(JalviewModelSequence jms, AlignFrame af) + { + FeatureRenderer fr = af.getFeatureRenderer(); + FeaturesDisplayed fdi = new FeaturesDisplayed(); + af.viewport.setFeaturesDisplayed(fdi); + String[] renderOrder = new String[jms.getFeatureSettings() + .getSettingCount()]; + Map featureColours = new Hashtable<>(); + Map featureOrder = new Hashtable<>(); + Map filters = new HashMap<>(); + + for (int fs = 0; fs < jms.getFeatureSettings() + .getSettingCount(); fs++) + { + Setting setting = jms.getFeatureSettings().getSetting(fs); + String featureType = setting.getType(); + + /* + * restore feature filters (if any) + */ + MatcherSet matchers = setting.getMatcherSet(); + if (matchers != null) + { + FeatureMatcherSetI filter = Jalview2XML + .unmarshalFilter(featureType, matchers); + if (!filter.isEmpty()) + { + filters.put(featureType, filter); + } + } + + /* + * restore feature colour scheme + */ + FeatureColourI featureColour = loadFeatureColour(setting); + featureColours.put(featureType, featureColour); + + renderOrder[fs] = featureType; + if (setting.hasOrder()) + { + featureOrder.put(featureType, setting.getOrder()); + } + else + { + featureOrder.put(featureType, new Float( + fs / jms.getFeatureSettings().getSettingCount())); + } + if (setting.getDisplay()) + { + fdi.setVisible(featureType); + } + } + Map fgtable = new Hashtable<>(); + for (int gs = 0; gs < jms.getFeatureSettings().getGroupCount(); gs++) + { + Group grp = jms.getFeatureSettings().getGroup(gs); + fgtable.put(grp.getName(), new Boolean(grp.getDisplay())); + } + + /* + * todo: save transparency in project (JAL-1147) + */ + float transparency = 1.0f; + FeatureRendererSettings frs = new FeatureRendererSettings(renderOrder, + fgtable, featureColours, transparency, featureOrder, filters); + fr.transferSettings(frs); + } + + /** + * Constructs a FeatureColour from the data saved for one FeatureSetting + * setting element + * + * @param setting + * @return + */ + static FeatureColourI loadFeatureColour(Setting setting) + { + FeatureColourI featureColour; + Color maxColour = new Color(setting.getColour()); + if (setting.hasMincolour()) + { + /* + * minColour is always set unless a simple colour + * (including for colour by label though it doesn't use it) + */ + Color minColour = new Color(setting.getMincolour()); + Color noValueColour = minColour; + NoValueColour noColour = setting.getNoValueColour(); + if (noColour == NoValueColour.NONE) + { + noValueColour = null; + } + else if (noColour == NoValueColour.MAX) + { + noValueColour = maxColour; + } + float min = setting.hasMin() ? setting.getMin() : 0f; + float max = setting.hasMin() ? setting.getMax() : 1f; + FeatureColourI gc = new FeatureColour(minColour, maxColour, + noValueColour, min, max); + if (setting.getAttributeNameCount() > 0) + { + gc.setAttributeName(setting.getAttributeName()); + } + if (setting.hasThreshold()) + { + gc.setThreshold(setting.getThreshold()); + int threshstate = setting.getThreshstate(); + // -1 = None, 0 = Below, 1 = Above threshold + if (threshstate == 0) + { + gc.setBelowThreshold(true); + } + else if (threshstate == 1) + { + gc.setAboveThreshold(true); + } + } + gc.setAutoScaled(true); // default + if (setting.hasAutoScale()) + { + gc.setAutoScaled(setting.getAutoScale()); + } + if (setting.hasColourByLabel()) + { + gc.setColourByLabel(setting.getColourByLabel()); + } + featureColour = gc; + } + else + { + featureColour = new FeatureColour(maxColour); + } + + return featureColour; + } + + /** * Reads saved data to restore Colour by Annotation settings * * @param viewAnnColour diff --git a/src/jalview/gui/Jalview2XML_V1.java b/src/jalview/gui/Jalview2XML_V1.java index 331e738..d2ba95b 100755 --- a/src/jalview/gui/Jalview2XML_V1.java +++ b/src/jalview/gui/Jalview2XML_V1.java @@ -21,6 +21,7 @@ package jalview.gui; import jalview.analysis.Conservation; +import jalview.api.FeatureColourI; import jalview.binding.Annotation; import jalview.binding.AnnotationElement; import jalview.binding.Features; @@ -40,6 +41,7 @@ import jalview.datamodel.SequenceFeature; import jalview.io.FileFormat; import jalview.schemes.ColourSchemeI; import jalview.schemes.ColourSchemeProperty; +import jalview.schemes.FeatureColour; import jalview.structure.StructureSelectionManager; import jalview.util.MessageManager; import jalview.util.jarInputStreamProvider; @@ -428,8 +430,8 @@ public class Jalview2XML_V1 if (jms.getFeatureSettings() != null) { - Hashtable featuresDisplayed = new Hashtable(); - Hashtable featureColours = new Hashtable(); + Hashtable featuresDisplayed = new Hashtable<>(); + Hashtable featureColours = new Hashtable<>(); String[] renderOrder = new String[jms.getFeatureSettings() .getSettingCount()]; for (int fs = 0; fs < jms.getFeatureSettings() @@ -438,7 +440,7 @@ public class Jalview2XML_V1 Setting setting = jms.getFeatureSettings().getSetting(fs); featureColours.put(setting.getType(), - new java.awt.Color(setting.getColour())); + new FeatureColour(new java.awt.Color(setting.getColour()))); renderOrder[fs] = setting.getType(); @@ -449,7 +451,8 @@ public class Jalview2XML_V1 } } FeatureRendererSettings frs = new FeatureRendererSettings(renderOrder, - new Hashtable(), featureColours, 1.0f, null); + new Hashtable(), featureColours, 1.0f, null, + null); af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer() .transferSettings(frs); } diff --git a/src/jalview/viewmodel/seqfeatures/FeatureRendererSettings.java b/src/jalview/viewmodel/seqfeatures/FeatureRendererSettings.java index 02b7f35..cd6f51b 100644 --- a/src/jalview/viewmodel/seqfeatures/FeatureRendererSettings.java +++ b/src/jalview/viewmodel/seqfeatures/FeatureRendererSettings.java @@ -41,7 +41,7 @@ import java.util.concurrent.ConcurrentHashMap; * * Note that feature type visibility settings are not held here. */ -public class FeatureRendererSettings implements Cloneable +public class FeatureRendererSettings { String[] renderOrder; @@ -64,10 +64,21 @@ public class FeatureRendererSettings implements Cloneable Map featureOrder; + /** + * Constructor + * + * @param renderOrder + * @param featureGroups + * @param featureColours + * @param transparency + * @param featureOrder + * @param filters + */ public FeatureRendererSettings(String[] renderOrder, Map featureGroups, Map featureColours, float transparency, - Map featureOrder) + Map featureOrder, + Map filters) { super(); this.renderOrder = Arrays.copyOf(renderOrder, renderOrder.length); @@ -77,6 +88,7 @@ public class FeatureRendererSettings implements Cloneable featureColours); this.transparency = transparency; this.featureOrder = new ConcurrentHashMap<>(featureOrder); + featureFilters = filters; } /** -- 1.7.10.2