+
+ /**
+ * A helper method that constructs and returns a CombBox for choice of the
+ * possible option values. If display names are provided, then these are added
+ * as options, otherwise the actual values are added.
+ *
+ * @param opt
+ * @return
+ */
+ protected JComboBox<String> buildComboBox(OptionI opt)
+ {
+ JComboBox<String> cb = null;
+ List<String> displayNames = opt.getDisplayNames();
+ if (displayNames != null)
+ {
+ cb = JvSwingUtils.buildComboWithTooltips(displayNames,
+ opt.getPossibleValues());
+ }
+ else
+ {
+ cb = new JComboBox<>();
+ for (String v : opt.getPossibleValues())
+ {
+ cb.addItem(v);
+ }
+ }
+ return cb;
+ }
+
+ /*
+ * Answers the value corresponding to the selected item in the choice combo
+ * box. If display names were not provided, this is simply the selected
+ * value. If display names were provided, it is the value corresponding to
+ * the selected item index.
+ *
+ * @return
+ */
+ protected static String getSelectedValue(OptionI opt, int sel)
+ {
+ List<String> possibleValues = opt.getPossibleValues();
+ String value = null;
+ if (possibleValues != null && possibleValues.size() == 1)
+ {
+ // Hack to make sure the default value for an enabled option with only
+ // one value is actually returned even if this.val is not displayed
+ value = possibleValues.get(0);
+ }
+ else
+ {
+ if (sel >= 0 && sel < possibleValues.size())
+ {
+ value = possibleValues.get(sel);
+ }
+ else
+ {
+ value = opt.getValue();
+ }
+ }
+ return value;
+ }