* @param attNames
* @param cond
* @param pattern
- * @param i
+ * @param filterIndex
* @return
*/
protected JPanel addFilter(String attribute, List<String> 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);
/*
* inputs for attribute, condition, pattern
*/
- JComboBox<String> attCombo = new JComboBox<>();
+ final JComboBox<String> attCombo = new JComboBox<>();
JComboBox<Condition> condCombo = new JComboBox<>();
JTextField patternField = new JTextField(8);
{
if (validateFilter(patternField, condCombo))
{
- updateFilter(attCombo, condCombo, patternField, i);
+ updateFilter(attCombo, condCombo, patternField, filterIndex);
filtersChanged();
}
}
};
/*
- * 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);
/*
@Override
public void actionPerformed(ActionEvent e)
{
- filters.remove(i);
+ filters.remove(filterIndex);
filtersChanged();
}
});
}
/**
+ * 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<String> attCombo, String featureType,
+ List<String> attNames)
+ {
+ final ComboBoxTooltipRenderer renderer = new ComboBoxTooltipRenderer();
+ attCombo.setRenderer(renderer);
+ List<String> tips = new ArrayList<String>();
+ 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
* <ul>
* <li>change of selected attribute</li>