+ /**
+ * 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).
+ *
+ * @param featureType
+ * @param attNames
+ * @param withNumericRange
+ */
+ protected JComboBox<String> populateAttributesDropdown(
+ 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)
+ {
+ if (withNumericRange)
+ {
+ float[] minMax = fa.getMinMax(featureType, attName);
+ if (minMax == null)
+ {
+ continue;
+ }
+ }
+ validAtts.add(attName);
+ String desc = fa.getDescription(featureType, attName);
+ if (desc != null && desc.length() > MAX_TOOLTIP_LENGTH)
+ {
+ desc = desc.substring(0, MAX_TOOLTIP_LENGTH) + "...";
+ }
+ tooltips.add(desc == null ? "" : desc);
+ }
+
+ JComboBox<String> attCombo = JvSwingUtils.buildComboWithTooltips(
+ validAtts, tooltips);
+
+ attCombo.addItemListener(new ItemListener()
+ {
+ @Override
+ public void itemStateChanged(ItemEvent e)
+ {
+ setAttributeMinMax(attCombo.getSelectedItem().toString());
+ changeColour(true);
+ }
+ });
+
+ if (validAtts.isEmpty())
+ {
+ attCombo.setToolTipText(MessageManager
+ .getString(withNumericRange ? "label.no_numeric_attributes"
+ : "label.no_attributes"));
+ }