From: gmungoc Date: Fri, 3 Nov 2017 11:51:18 +0000 (+0000) Subject: JAL-2808 attribute description as tooltip in dropdown if known X-Git-Tag: Release_2_11_0~154 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=ab106c5adab9123dbb03e8b187b4b45687646f15;p=jalview.git JAL-2808 attribute description as tooltip in dropdown if known --- diff --git a/src/jalview/gui/FeatureSettings.java b/src/jalview/gui/FeatureSettings.java index d724b8c..0928ec1 100644 --- a/src/jalview/gui/FeatureSettings.java +++ b/src/jalview/gui/FeatureSettings.java @@ -1562,11 +1562,11 @@ public class FeatureSettings extends JPanel * @param attNames * @param cond * @param pattern - * @param i + * @param filterIndex * @return */ protected JPanel addFilter(String attribute, List attNames, - Condition cond, String pattern, int i) + Condition cond, String pattern, int filterIndex) { JPanel filterRow = new JPanel(new FlowLayout(FlowLayout.LEFT)); filterRow.setBackground(Color.white); @@ -1574,7 +1574,7 @@ public class FeatureSettings extends JPanel /* * inputs for attribute, condition, pattern */ - JComboBox attCombo = new JComboBox<>(); + final JComboBox attCombo = new JComboBox<>(); JComboBox condCombo = new JComboBox<>(); JTextField patternField = new JTextField(8); @@ -1590,7 +1590,7 @@ public class FeatureSettings extends JPanel { if (validateFilter(patternField, condCombo)) { - updateFilter(attCombo, condCombo, patternField, i); + updateFilter(attCombo, condCombo, patternField, filterIndex); filtersChanged(); } } @@ -1606,31 +1606,21 @@ public class FeatureSettings extends JPanel }; /* - * drop-down choice of attribute + * drop-down choice of attribute, with description as a tooltip + * if we can obtain it */ - if (attNames.isEmpty()) + String featureType = (String) filteredFeatureChoice.getSelectedItem(); + populateAttributesDropdown(attCombo, featureType, attNames); + if ("".equals(attribute)) { - attCombo.addItem("---"); - attCombo.setToolTipText(MessageManager - .getString("label.no_attributes_known")); + attCombo.setSelectedItem(null); } else { - attCombo.setToolTipText(""); - for (String attName : attNames) - { - attCombo.addItem(attName); - } - if ("".equals(attribute)) - { - attCombo.setSelectedItem(null); - } - else - { - attCombo.setSelectedItem(attribute); - } - attCombo.addItemListener(itemListener); + attCombo.setSelectedItem(attribute); } + attCombo.addItemListener(itemListener); + filterRow.add(attCombo); /* @@ -1676,7 +1666,7 @@ public class FeatureSettings extends JPanel @Override public void actionPerformed(ActionEvent e) { - filters.remove(i); + filters.remove(filterIndex); filtersChanged(); } }); @@ -1687,6 +1677,64 @@ public class FeatureSettings extends JPanel } /** + * 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. + * + * @param attCombo + * @param featureType + * @param attNames + */ + protected void populateAttributesDropdown( + final JComboBox attCombo, String featureType, + List attNames) + { + final ComboBoxTooltipRenderer renderer = new ComboBoxTooltipRenderer(); + attCombo.setRenderer(renderer); + List tips = new ArrayList(); + if (attNames.isEmpty()) + { + attCombo.addItem("---"); + attCombo.setToolTipText(MessageManager + .getString("label.no_attributes_known")); + } + else + { + attCombo.setToolTipText(""); + FeatureAttributes fs = FeatureAttributes.getInstance(); + for (String attName : attNames) + { + attCombo.addItem(attName); + String desc = fs.getDescription(featureType, attName); + tips.add(desc == null ? "" : desc); + } + } + renderer.setTooltips(tips); + final MouseAdapter mouseListener = new MouseAdapter() + { + @Override + public void mouseEntered(MouseEvent e) + { + int j = attCombo.getSelectedIndex(); + if (j > -1) + { + attCombo.setToolTipText(tips.get(j)); + } + } + + @Override + public void mouseExited(MouseEvent e) + { + attCombo.setToolTipText(null); + } + }; + for (Component c : attCombo.getComponents()) + { + c.addMouseListener(mouseListener); + } + } + + /** * Action on any change to feature filtering, namely *
    *
  • change of selected attribute