X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FFeatureColourChooser.java;h=da3819c81298e6ae4c20d1a9c01f21acbd91d5d7;hb=f8b17a9e7363b8a9e7cd12d61bc6d611c7c97d7d;hp=6280a648ee9d04c315cc8c9df252922ff266f5da;hpb=05d220bbea0e8ce667490219436b96ebdf9826df;p=jalview.git diff --git a/src/jalview/gui/FeatureColourChooser.java b/src/jalview/gui/FeatureColourChooser.java index 6280a64..da3819c 100644 --- a/src/jalview/gui/FeatureColourChooser.java +++ b/src/jalview/gui/FeatureColourChooser.java @@ -57,8 +57,16 @@ import javax.swing.event.ChangeListener; public class FeatureColourChooser extends JalviewDialog { + private static final String COLON = ":"; + private static final int MAX_TOOLTIP_LENGTH = 50; + private static int NO_COLOUR_OPTION = 0; + + private static int MIN_COLOUR_OPTION = 1; + + private static int MAX_COLOUR_OPTION = 2; + private FeatureRenderer fr; private FeatureColourI cs; @@ -157,9 +165,8 @@ public class FeatureColourChooser extends JalviewDialog this.fr = frender; this.type = theType; ap = fr.ap; - String title = MessageManager - .formatMessage("label.graduated_color_for_params", new String[] - { theType }); + String title = MessageManager.formatMessage("label.variable_color_for", + new String[] { theType }); initDialogFrame(this, true, blocking, title, 470, 300); slider.addChangeListener(new ChangeListener() @@ -190,6 +197,7 @@ public class FeatureColourChooser extends JalviewDialog } }); + // todo move all threshold setup inside a method float mm[] = fr.getMinMax().get(theType)[0]; min = mm[0]; max = mm[1]; @@ -231,6 +239,8 @@ public class FeatureColourChooser extends JalviewDialog } minColour.setBackground(oldminColour = cs.getMinColour()); maxColour.setBackground(oldmaxColour = cs.getMaxColour()); + noColour = cs.getNoColour(); + adjusting = true; try @@ -245,15 +255,15 @@ public class FeatureColourChooser extends JalviewDialog /* * set the initial state of options on screen */ - thresholdIsMin.setSelected(!cs.isAutoScaled()); - if (cs.isColourByLabel()) { if (cs.isColourByAttribute()) { byAttributeText.setSelected(true); textAttributeCombo.setEnabled(true); - textAttributeCombo.setSelectedItem(cs.getAttributeName()); + String[] attributeName = cs.getAttributeName(); + textAttributeCombo + .setSelectedItem(String.join(COLON, attributeName)); } else { @@ -266,8 +276,9 @@ public class FeatureColourChooser extends JalviewDialog if (cs.isColourByAttribute()) { byAttributeValue.setSelected(true); - String attributeName = cs.getAttributeName(); - valueAttributeCombo.setSelectedItem(attributeName); + String[] attributeName = cs.getAttributeName(); + valueAttributeCombo + .setSelectedItem(String.join(COLON, attributeName)); valueAttributeCombo.setEnabled(true); updateMinMax(); } @@ -278,6 +289,19 @@ public class FeatureColourChooser extends JalviewDialog } } + if (noColour == null) + { + noValueCombo.setSelectedIndex(NO_COLOUR_OPTION); + } + else if (noColour.equals(oldminColour)) + { + noValueCombo.setSelectedIndex(MIN_COLOUR_OPTION); + } + else if (noColour.equals(oldmaxColour)) + { + noValueCombo.setSelectedIndex(MAX_COLOUR_OPTION); + } + threshline = new GraphLine((max - min) / 2f, "Threshold", Color.black); threshline.value = cs.getThreshold(); @@ -369,7 +393,8 @@ public class FeatureColourChooser extends JalviewDialog else if (byAttributeValue.isSelected()) { String attName = (String) valueAttributeCombo.getSelectedItem(); - minMax = FeatureAttributes.getInstance().getMinMax(type, attName); + String[] attNames = attName.split(COLON); + minMax = FeatureAttributes.getInstance().getMinMax(type, attNames); } if (minMax != null) { @@ -408,8 +433,8 @@ public class FeatureColourChooser extends JalviewDialog byAttributeValue.addActionListener(changeMinMaxAction); byWhatPanel.add(byAttributeValue); - List attNames = FeatureAttributes.getInstance().getAttributes( - type); + List attNames = FeatureAttributes.getInstance() + .getAttributes(type); valueAttributeCombo = populateAttributesDropdown(type, attNames, true); /* @@ -555,21 +580,21 @@ public class FeatureColourChooser extends JalviewDialog } /** - * Action on user choice of no / min / max colour when there is no value to - * colour by + * Action on user choice of no / min / max colour to use when there is no + * value to colour by */ protected void setNoValueColour() { int i = noValueCombo.getSelectedIndex(); - if (i == 0) + if (i == NO_COLOUR_OPTION) { noColour = null; } - else if (i == 1) + else if (i == MIN_COLOUR_OPTION) { noColour = minColour.getBackground(); } - else if (i == 2) + else if (i == MAX_COLOUR_OPTION) { noColour = maxColour.getBackground(); } @@ -612,8 +637,8 @@ public class FeatureColourChooser extends JalviewDialog byAttributeText.addActionListener(changeColourAction); byTextPanel.add(byAttributeText); - List attNames = FeatureAttributes.getInstance().getAttributes( - type); + List attNames = FeatureAttributes.getInstance() + .getAttributes(type); textAttributeCombo = populateAttributesDropdown(type, attNames, false); byTextPanel.add(textAttributeCombo); @@ -715,13 +740,18 @@ public class FeatureColourChooser extends JalviewDialog { attribute = (String) textAttributeCombo.getSelectedItem(); textAttributeCombo.setEnabled(true); + acg.setAttributeName(attribute.split(COLON)); } else if (byAttributeValue.isSelected()) { attribute = (String) valueAttributeCombo.getSelectedItem(); valueAttributeCombo.setEnabled(true); + acg.setAttributeName(attribute.split(COLON)); + } + else + { + acg.setAttributeName((String) null); } - acg.setAttributeName(attribute); if (!hasThreshold) { @@ -798,6 +828,7 @@ public class FeatureColourChooser extends JalviewDialog maxColour.setForeground(oldmaxColour); minColour.setBackground(oldminColour); minColour.setForeground(oldminColour); + noColour = oldNoColour; } /* @@ -912,23 +943,26 @@ public class FeatureColourChooser extends JalviewDialog /** * A helper method to build the drop-down choice of attributes for a feature. * Where metadata is available with a description for an attribute, that is - * added as a tooltip. The list may be restricted to attributes for which we - * hold a range of numerical values (so suitable candidates for a graduated - * colour scheme). + * added as a tooltip. The list may optionally be restricted to attributes for + * which we hold a range of numerical values (so suitable candidates for a + * graduated colour scheme). + *

+ * Attribute names may be 'simple' e.g. "AC" or 'compound' e.g. {"CSQ", + * "Allele"}. Compound names are rendered for display as (e.g.) CSQ:Allele. * * @param featureType * @param attNames * @param withNumericRange */ protected JComboBox populateAttributesDropdown( - String featureType, List attNames, + String featureType, List attNames, boolean withNumericRange) { List validAtts = new ArrayList<>(); List tooltips = new ArrayList<>(); FeatureAttributes fa = FeatureAttributes.getInstance(); - for (String attName : attNames) + for (String[] attName : attNames) { if (withNumericRange) { @@ -938,7 +972,7 @@ public class FeatureColourChooser extends JalviewDialog continue; } } - validAtts.add(attName); + validAtts.add(String.join(COLON, attName)); String desc = fa.getDescription(featureType, attName); if (desc != null && desc.length() > MAX_TOOLTIP_LENGTH) {