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;
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<String, FeatureColourI> featureColours = new Hashtable<>();
- Map<String, Float> 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<String, Boolean> 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)
}
/**
+ * Loads feature settings data from project XML and stores
+ * <ul>
+ * <li>feature type visibility in the Viewport</li>
+ * <li>other data in the FeatureRenderer:
+ * <ul>
+ * <li>feature type render order</li>
+ * <li>feature type colours</li>
+ * <li>feature type filters</li>
+ * <li>feature groups and their visibility</li>
+ * </ul>
+ * </li>
+ * </ul>
+ *
+ * @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<String, FeatureColourI> featureColours = new Hashtable<>();
+ Map<String, Float> featureOrder = new Hashtable<>();
+ Map<String, FeatureMatcherSetI> 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<String, Boolean> 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
+ * <code>setting</code> 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