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;
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()
}
});
+ // todo move all threshold setup inside a method
float mm[] = fr.getMinMax().get(theType)[0];
min = mm[0];
max = mm[1];
}
minColour.setBackground(oldminColour = cs.getMinColour());
maxColour.setBackground(oldmaxColour = cs.getMaxColour());
+ noColour = cs.getNoColour();
+
adjusting = true;
try
/*
* 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
{
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();
}
}
}
+ 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();
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)
{
byAttributeValue.addActionListener(changeMinMaxAction);
byWhatPanel.add(byAttributeValue);
- List<String> attNames = FeatureAttributes.getInstance().getAttributes(
- type);
+ List<String[]> attNames = FeatureAttributes.getInstance()
+ .getAttributes(type);
valueAttributeCombo = populateAttributesDropdown(type, attNames, true);
/*
}
/**
- * 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();
}
byAttributeText.addActionListener(changeColourAction);
byTextPanel.add(byAttributeText);
- List<String> attNames = FeatureAttributes.getInstance().getAttributes(
- type);
+ List<String[]> attNames = FeatureAttributes.getInstance()
+ .getAttributes(type);
textAttributeCombo = populateAttributesDropdown(type, attNames, false);
byTextPanel.add(textAttributeCombo);
{
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)
{
maxColour.setForeground(oldmaxColour);
minColour.setBackground(oldminColour);
minColour.setForeground(oldminColour);
+ noColour = oldNoColour;
}
/*
/**
* 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).
+ * <p>
+ * 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<String> populateAttributesDropdown(
- String featureType, List<String> attNames,
+ String featureType, List<String[]> attNames,
boolean withNumericRange)
{
List<String> validAtts = new ArrayList<>();
List<String> tooltips = new ArrayList<>();
FeatureAttributes fa = FeatureAttributes.getInstance();
- for (String attName : attNames)
+ for (String[] attName : attNames)
{
if (withNumericRange)
{
continue;
}
}
- validAtts.add(attName);
+ validAtts.add(String.join(COLON, attName));
String desc = fa.getDescription(featureType, attName);
if (desc != null && desc.length() > MAX_TOOLTIP_LENGTH)
{