* construct the choice box with possible values,
* or their display names if provided
*/
- List<String> displayNames = opt.getDisplayNames();
- if (displayNames != null)
- {
- val = JvSwingUtils.buildComboWithTooltips(displayNames,
- opt.getPossibleValues());
- }
- else
- {
- val = new JComboBox<>();
- for (String v : opt.getPossibleValues())
- {
- val.addItem(v);
- }
- }
+ val = buildComboBox(opt);
val.setSelectedItem(opt.getValue());
/*
*
* @return
*/
- public OptionI getSelectedOption()
+ public ArgumentI getSelectedOption()
{
if (!enabled.isSelected())
{
return null;
}
- String value = getSelectedValue();
+ String value = getSelectedValue(option, val.getSelectedIndex());
OptionI opt = option.copy();
opt.setValue(value);
return opt;
}
- /*
- * 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 String getSelectedValue()
- {
- List<String> possibleValues = option.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
- {
- int sel = val.getSelectedIndex();
- if (sel >= 0 && sel < possibleValues.size())
- {
- value = possibleValues.get(sel);
- }
- else
- {
- value = option.getValue();
- }
- }
- return value;
- }
-
@Override
public void mouseClicked(MouseEvent e)
{
return Component.BaselineResizeBehavior.CONSTANT_ASCENT;
}
- public ParameterI getParameter()
+ /**
+ * Answers an argument holding the value entered or selected in the dialog
+ *
+ * @return
+ */
+ public ArgumentI getParameter()
{
ParameterI prm = parameter.copy();
if (isChoiceParameter)
{
- String value = getChoice();
+ String value = getSelectedValue(this.parameter, choicebox.getSelectedIndex());
prm.setValue(value);
}
else
return prm;
}
- /**
- * 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 String getChoice()
- {
- int sel = choicebox.getSelectedIndex();
- if (sel < 0 || sel >= parameter.getPossibleValues().size())
- {
- return null;
- }
- return parameter.getPossibleValues().get(sel);
- }
-
public void init()
{
// reset the widget's initial value.
{
adjusting = true;
boolean init = (choicebox == null && valueField == null);
- List<String> displayNames = parm.getDisplayNames();
if (init)
{
if (isChoiceParameter)
{
- if (displayNames != null)
- {
- choicebox = JvSwingUtils.buildComboWithTooltips(displayNames,
- parm.getPossibleValues());
- }
- else
- {
- choicebox = new JComboBox<>();
- for (String val : parm.getPossibleValues())
- {
- choicebox.addItem(val);
- }
- }
- choicebox.addActionListener(this);
+ choicebox = buildComboBox(parm);
controlsPanel.add(choicebox, BorderLayout.CENTER);
}
else
{
if (isChoiceParameter)
{
- return getChoice();
+ return getSelectedValue(this.parameter, choicebox.getSelectedIndex());
}
slider.setVisible(false);
return valueField.getText().trim();
}
/**
- * recover options and parameters from GUI
+ * Answers a list of arguments representing all the options and arguments
+ * selected on the dialog, holding their chosen or input values. Optional
+ * parameters which were not selected are not included.
*
* @return
*/
List<ArgumentI> argSet = new ArrayList<>();
for (OptionBox opts : getOptSet().values())
{
- OptionI opt = opts.getSelectedOption();
+ ArgumentI opt = opts.getSelectedOption();
if (opt != null)
{
argSet.add(opt);
}
for (ParamBox parambox : getParamSet().values())
{
- ParameterI parm = parambox.getParameter();
+ ArgumentI parm = parambox.getParameter();
if (parm != null)
{
argSet.add(parm);
return argSet;
}
+
+ /**
+ * 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;
+ }
}