2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.bin.Cache;
24 import jalview.io.DataSourceType;
25 import jalview.io.FileLoader;
26 import jalview.io.JalviewFileChooser;
27 import jalview.io.JalviewFileView;
28 import jalview.util.MessageManager;
29 import jalview.ws.jws2.dm.JabaOption;
30 import jalview.ws.params.ArgumentI;
31 import jalview.ws.params.OptionI;
32 import jalview.ws.params.ParameterI;
33 import jalview.ws.params.ValueConstrainI;
34 import jalview.ws.params.ValueConstrainI.ValueType;
35 import jalview.ws.params.simple.FileParameter;
36 import jalview.ws.params.simple.LogarithmicParameter;
37 import jalview.ws.params.simple.RadioChoiceParameter;
38 import jalview.ws.params.simple.StringParameter;
40 import java.awt.BorderLayout;
41 import java.awt.Color;
42 import java.awt.Component;
43 import java.awt.Container;
44 import java.awt.Dimension;
45 import java.awt.FlowLayout;
47 import java.awt.Rectangle;
48 import java.awt.event.ActionEvent;
49 import java.awt.event.ActionListener;
50 import java.awt.event.KeyAdapter;
51 import java.awt.event.KeyEvent;
52 import java.awt.event.MouseAdapter;
53 import java.awt.event.MouseEvent;
54 import java.awt.event.MouseListener;
57 import java.util.ArrayList;
58 import java.util.LinkedHashMap;
59 import java.util.List;
62 import javax.swing.ButtonGroup;
63 import javax.swing.JButton;
64 import javax.swing.JCheckBox;
65 import javax.swing.JComboBox;
66 import javax.swing.JComponent;
67 import javax.swing.JLabel;
68 import javax.swing.JMenuItem;
69 import javax.swing.JPanel;
70 import javax.swing.JPopupMenu;
71 import javax.swing.JRadioButton;
72 import javax.swing.JScrollPane;
73 import javax.swing.JSlider;
74 import javax.swing.JTextArea;
75 import javax.swing.JTextField;
76 import javax.swing.border.TitledBorder;
77 import javax.swing.event.ChangeEvent;
78 import javax.swing.event.ChangeListener;
80 import net.miginfocom.swing.MigLayout;
83 * GUI generator/manager for options and parameters. Originally abstracted from
84 * the WsJobParameters dialog box.
89 public class OptsAndParamsPage
91 public static final int PARAM_WIDTH = 340;
93 public static final int PARAM_HEIGHT = 150;
95 public static final int PARAM_CLOSEDHEIGHT = 80;
97 URL linkImageURL = getClass().getResource("/images/link.gif");
99 Map<String, OptionBox> optSet = new LinkedHashMap<>();
101 Map<String, ParamBox> paramSet = new LinkedHashMap<>();
104 * compact or verbose style parameters
106 boolean compact = false;
108 OptsParametersContainerI poparent;
111 * A class that models a panel rendering a single option (checkbox or choice
114 public class OptionBox extends JPanel
115 implements MouseListener, ActionListener
121 boolean hasLink = false;
123 boolean initEnabled = false;
125 String initVal = null;
129 JComboBox<Object> val;
132 * Constructs and adds labels and controls to the panel for one Option
136 public OptionBox(OptionI opt)
139 setLayout(new FlowLayout(FlowLayout.LEFT));
140 enabled = new JCheckBox(opt.getLabel());
141 enabled.setSelected(opt.isRequired());
144 * If option is required, show a label, if optional a checkbox
145 * (but not for Jabaws pending JWS-126 resolution)
147 if (opt.isRequired() && !(opt instanceof JabaOption))
150 add(new JLabel(opt.getLabel()));
154 finfo = option.getFurtherDetails();
155 configureCheckbox(opt);
160 * construct the choice box with possible values,
161 * or their display names if provided
163 val = buildComboBox(opt);
164 val.setSelectedItem(opt.getValue());
167 * only show the choicebox if there is more than one option,
168 * or the option is mandatory
170 if (opt.getPossibleValues().size() > 1 || opt.isRequired())
172 val.addActionListener(this);
180 * Configures the checkbox that controls whether or not the option is
185 protected void configureCheckbox(OptionI opt)
187 enabled.setFont(new Font("Verdana", Font.PLAIN, 11));
188 enabled.addActionListener(this);
189 final String desc = opt.getDescription();
193 String description = desc;
194 if (desc == null || desc.trim().isEmpty())
196 description = MessageManager
197 .getString("label.opt_and_params_further_details");
199 description = description + "<br><img src=\"" + linkImageURL
201 String text = JvSwingUtils.wrapTooltip(true, description);
202 enabled.setToolTipText(text);
203 enabled.addMouseListener(this); // for popup menu to show link
207 if (desc != null && desc.trim().length() > 0)
209 enabled.setToolTipText(JvSwingUtils.wrapTooltip(true, desc));
215 public void actionPerformed(ActionEvent e)
217 if (e.getSource() != enabled)
219 enabled.setSelected(true);
224 private void checkIfModified()
226 boolean notmod = (initEnabled == enabled.isSelected());
227 if (enabled.isSelected())
231 notmod &= initVal.equals(val.getSelectedItem());
235 // compare against default service setting
236 notmod &= option.getValue() == null
237 || option.getValue().equals(val.getSelectedItem());
242 notmod &= (initVal != null) ? initVal.equals(val.getSelectedItem())
243 : val.getSelectedItem() != initVal;
245 poparent.argSetModified(this, !notmod);
249 * Answers null if the option is not selected, else a new Option holding the
254 public ArgumentI getSelectedOption()
256 if (!enabled.isSelected())
260 String value = getSelectedValue(option, val.getSelectedIndex());
261 OptionI opt = option.copy();
267 public void mouseClicked(MouseEvent e)
269 if (e.isPopupTrigger()) // for Windows
271 showUrlPopUp(this, finfo.toString(), e.getX(), e.getY());
276 public void mouseEntered(MouseEvent e)
281 public void mouseExited(MouseEvent e)
286 public void mousePressed(MouseEvent e)
288 if (e.isPopupTrigger()) // Mac
290 showUrlPopUp(this, finfo.toString(), e.getX(), e.getY());
295 public void mouseReleased(MouseEvent e)
299 public void resetToDefault(boolean setDefaultParams)
301 enabled.setSelected(false);
302 if (option.isRequired()
303 || (setDefaultParams && option.getValue() != null))
305 // Apply default value
306 selectOption(option, option.getValue());
310 public void setInitialValue()
312 initEnabled = enabled.isSelected();
313 if (option.getPossibleValues() != null
314 && option.getPossibleValues().size() > 1)
316 initVal = (String) val.getSelectedItem();
320 initVal = (initEnabled) ? (String) val.getSelectedItem() : null;
325 * toString representation for identification in the debugger only
328 public String toString()
330 return option == null ? super.toString() : option.toString();
336 * A class that models a panel rendering a single parameter
338 public class ParamBox extends JPanel
339 implements ChangeListener, ActionListener, MouseListener
342 * parameter values (or their logs) are multiplied by this
343 * scaling factor to ensure an integer range for the slider
345 private int sliderScaleFactor = 1;
347 boolean isLogarithmicParameter;
349 boolean isChoiceParameter;
351 boolean isIntegerParameter;
353 boolean isStringParameter;
358 * drop-down list of choice options (if applicable)
360 JComboBox<Object> choicebox;
363 * radio buttons as an alternative to combo box
365 ButtonGroup buttonGroup;
367 JPanel controlsPanel = new JPanel();
369 boolean descriptionIsVisible = false;
371 JScrollPane descPanel = new JScrollPane();
377 ParameterI parameter;
379 final OptsParametersContainerI pmdialogbox;
381 JPanel settingPanel = new JPanel();
385 JTextArea descriptionText = new JTextArea();
387 ValueConstrainI validator;
389 JTextField valueField;
391 private String descTooltip;
393 public ParamBox(final OptsParametersContainerI paramContainer,
396 pmdialogbox = paramContainer;
397 finfo = parm.getFurtherDetails();
398 validator = parm.getValidValue();
401 isLogarithmicParameter = parm instanceof LogarithmicParameter;
403 if (validator != null)
405 ValueType type = validator.getType();
406 isIntegerParameter = type == ValueType.Integer;
407 isStringParameter = type == ValueType.String
408 || type == ValueType.File;
411 * ensure slider has an integer range corresponding to
412 * the min-max range of the parameter
414 if (validator.getMin() != null && validator.getMax() != null
415 // && !isIntegerParameter
416 && !isStringParameter)
418 double min = validator.getMin().doubleValue();
419 double max = validator.getMax().doubleValue();
420 if (isLogarithmicParameter)
425 sliderScaleFactor = (int) (1000000 / (max - min));
426 // todo scaleMin, scaleMax could also be final fields
430 List<String> possibleValues = parameter.getPossibleValues();
431 isChoiceParameter = possibleValues != null
432 && !possibleValues.isEmpty();
436 addCompactParameter(parm);
440 addExpandableParam(parm);
445 * Adds a 'compact' format parameter, with any help text shown as a tooltip
449 private void addCompactParameter(ParameterI parm)
451 setLayout(new MigLayout("", "[][grow]"));
452 String ttipText = null;
454 controlsPanel.setLayout(new BorderLayout());
456 if (parm.getDescription() != null
457 && parm.getDescription().trim().length() > 0)
459 ttipText = (JvSwingUtils.wrapTooltip(true,
460 parm.getDescription() + (finfo != null ? "<br><img src=\""
461 + linkImageURL + "\"/>"
462 + MessageManager.getString(
463 "label.opt_and_params_further_details")
467 JvSwingUtils.addtoLayout(this, ttipText, new JLabel(parm.getName()),
469 updateControls(parm);
474 * Adds an 'expanded' format parameter, with any help shown in a panel that
475 * may be shown or hidden
479 private void addExpandableParam(ParameterI parm)
481 setPreferredSize(new Dimension(PARAM_WIDTH, PARAM_CLOSEDHEIGHT));
482 setBorder(new TitledBorder(parm.getName()));
484 descriptionText.setFont(new Font("Verdana", Font.PLAIN, 11));
485 descriptionText.setBackground(getBackground());
487 descriptionText.setEditable(false);
488 descPanel.getViewport().setView(descriptionText);
490 descPanel.setVisible(false);
492 JPanel firstrow = new JPanel();
493 firstrow.setLayout(null);
494 controlsPanel.setLayout(new BorderLayout());
495 controlsPanel.setBounds(new Rectangle(39, 10, PARAM_WIDTH - 70,
496 PARAM_CLOSEDHEIGHT - 50));
497 firstrow.add(controlsPanel);
498 firstrow.setBounds(new Rectangle(10, 20, PARAM_WIDTH - 30,
499 PARAM_CLOSEDHEIGHT - 30));
501 if (parm.getDescription() != null
502 && parm.getDescription().trim().length() > 0)
504 addExpandableHelp(firstrow, parm);
507 validator = parm.getValidValue();
509 if (validator != null)
511 isIntegerParameter = validator.getType() == ValueType.Integer;
515 if (parameter.getPossibleValues() != null)
517 isChoiceParameter = true;
520 updateControls(parm);
521 descPanel.setBounds(new Rectangle(10, PARAM_CLOSEDHEIGHT,
522 PARAM_WIDTH - 20, PARAM_HEIGHT - PARAM_CLOSEDHEIGHT - 5));
528 * Adds a button which can be clicked to show or hide help text
533 protected void addExpandableHelp(JPanel container, ParameterI param)
535 JButton showDescBtn = new JButton("+");
536 showDescBtn.setFont(new Font("Verdana", Font.PLAIN, 8));
539 descTooltip = JvSwingUtils.wrapTooltip(true,
540 MessageManager.formatMessage(
541 "label.opt_and_params_show_brief_desc_image_link",
543 { linkImageURL.toExternalForm() }));
544 showDescBtn.addMouseListener(this);
548 descTooltip = JvSwingUtils.wrapTooltip(true, MessageManager
549 .getString("label.opt_and_params_show_brief_desc"));
551 showDescBtn.setToolTipText(descTooltip);
552 showDescBtn.addActionListener(new ActionListener()
555 public void actionPerformed(ActionEvent e)
557 descriptionIsVisible = !descriptionIsVisible;
558 showDescBtn.setText(descriptionIsVisible ? "-" : "+");
559 showDescBtn.setToolTipText(
560 descriptionIsVisible ? null : descTooltip);
561 descPanel.setVisible(descriptionIsVisible);
562 descPanel.getVerticalScrollBar().setValue(0);
563 ParamBox.this.setPreferredSize(new Dimension(PARAM_WIDTH,
564 (descriptionIsVisible) ? PARAM_HEIGHT
565 : PARAM_CLOSEDHEIGHT));
566 ParamBox.this.validate();
567 pmdialogbox.refreshParamLayout();
570 descriptionText.setWrapStyleWord(true);
571 descriptionText.setLineWrap(true);
572 descriptionText.setColumns(32);
573 descriptionText.setText(param.getDescription());
574 showDescBtn.setBounds(new Rectangle(10, 10, 16, 16));
575 container.add(showDescBtn);
579 public void actionPerformed(ActionEvent e)
589 * Checks whether the value of this parameter has been changed and notifies
590 * the parent page accordingly
592 private void checkIfModified()
594 Object newValue = updateSliderFromValueField();
595 boolean modified = true;
596 if (newValue.getClass() == lastVal.getClass())
598 modified = !newValue.equals(lastVal);
600 pmdialogbox.argSetModified(this, modified);
604 public int getBaseline(int width, int height)
610 // http://stackoverflow.com/questions/2743177/top-alignment-for-flowlayout
611 // helpful hint of using the Java 1.6 alignBaseLine property of FlowLayout
613 public Component.BaselineResizeBehavior getBaselineResizeBehavior()
615 return Component.BaselineResizeBehavior.CONSTANT_ASCENT;
619 * Answers an argument holding the value entered or selected in the dialog
623 public ArgumentI getParameter()
625 ParameterI prm = parameter.copy();
627 if (parameter instanceof RadioChoiceParameter)
629 value = buttonGroup.getSelection().getActionCommand();
631 else if (isChoiceParameter)
633 value = getSelectedValue(this.parameter,
634 choicebox.getSelectedIndex());
638 value = valueField.getText();
647 // reset the widget's initial value.
652 public void mouseClicked(MouseEvent e)
654 if (e.isPopupTrigger()) // for Windows
656 showUrlPopUp(this, finfo.toString(), e.getX(), e.getY());
661 public void mouseEntered(MouseEvent e)
666 public void mouseExited(MouseEvent e)
671 public void mousePressed(MouseEvent e)
673 if (e.isPopupTrigger()) // for Mac
675 showUrlPopUp(this, finfo.toString(), e.getX(), e.getY());
680 public void mouseReleased(MouseEvent e)
685 public void stateChanged(ChangeEvent e)
694 if (!isLogarithmicParameter)
697 * set (int or float formatted) text field value
699 valueField.setText(isIntegerParameter
700 ? String.valueOf(slider.getValue())
702 slider.getValue() / (float) sliderScaleFactor));
706 double value = Math.pow(Math.E,
707 slider.getValue() / (double) sliderScaleFactor);
708 valueField.setText(formatDouble(value));
718 * Answers the value formatted as a string to 3 decimal places - in
719 * scientific notation if the value is less than 0.001
724 String formatDouble(double value)
726 String format = value < 0.001 ? "%3.1E" : "%3.3f";
727 return String.format(format, value);
731 * Formats a number as integer or float (3dp) or scientific notation (1dp)
736 String formatNumber(Number n)
738 return n instanceof Integer ? String.valueOf(n.intValue())
739 : formatDouble(n.doubleValue());
742 void updateControls(ParameterI parm)
745 boolean init = (choicebox == null && valueField == null
746 && buttonGroup == null);
749 if (parm instanceof RadioChoiceParameter)
751 buttonGroup = addRadioButtons(parameter, controlsPanel);
753 else if (isChoiceParameter)
755 choicebox = buildComboBox(parm);
756 choicebox.addActionListener(this);
757 controlsPanel.add(choicebox, BorderLayout.CENTER);
761 slider = new JSlider();
762 slider.addChangeListener(this);
763 int cols = parm instanceof StringParameter ? 20 : 0;
764 valueField = new JTextField(cols);
765 valueField.addActionListener(this);
766 valueField.addKeyListener(new KeyAdapter()
769 public void keyReleased(KeyEvent e)
771 int keyCode = e.getKeyCode();
772 if (e.isActionKey() && keyCode != KeyEvent.VK_LEFT
773 && keyCode != KeyEvent.VK_RIGHT)
775 if (valueField.getText().trim().length() > 0)
777 actionPerformed(null);
782 valueField.setPreferredSize(new Dimension(65, 25));
783 if (parm instanceof FileParameter)
785 valueField.setToolTipText(MessageManager
786 .getString("label.double_click_to_browse"));
787 valueField.addMouseListener(new MouseAdapter()
790 public void mouseClicked(MouseEvent e)
792 if (e.getClickCount() == 2)
794 String dir = Cache.getProperty("LAST_DIRECTORY");
795 JalviewFileChooser chooser = new JalviewFileChooser(dir);
796 chooser.setFileView(new JalviewFileView());
797 chooser.setDialogTitle(
798 MessageManager.getString("action.select_ddbb"));
800 int val = chooser.showOpenDialog(ParamBox.this);
801 if (val == JalviewFileChooser.APPROVE_OPTION)
803 File choice = chooser.getSelectedFile();
804 String path = choice.getPath();
805 valueField.setText(path);
806 Cache.setProperty("LAST_DIRECTORY", choice.getParent());
807 FileLoader.updateRecentlyOpened(path,
808 DataSourceType.FILE);
815 controlsPanel.add(slider, BorderLayout.WEST);
816 controlsPanel.add(valueField, BorderLayout.EAST);
820 String value = parm.getValue();
823 if (isChoiceParameter)
825 if (!(parm instanceof RadioChoiceParameter))
827 choicebox.setSelectedItem(value);
832 valueField.setText(value);
835 lastVal = updateSliderFromValueField();
840 * Adds a panel to comp, containing a label and radio buttons for the choice
841 * of values of the given option. Returns a ButtonGroup whose members are
842 * the added radio buttons.
849 protected ButtonGroup addRadioButtons(OptionI option, Container comp)
851 ButtonGroup bg = new ButtonGroup();
852 JPanel radioPanel = new JPanel();
853 radioPanel.add(new JLabel(option.getDescription()));
855 String value = option.getValue();
857 for (String opt : option.getPossibleValues())
859 JRadioButton btn = new JRadioButton(opt);
860 btn.setActionCommand(opt);
861 boolean selected = opt.equals(value);
862 btn.setSelected(selected);
863 btn.addActionListener(this);
867 comp.add(radioPanel);
873 * Action depends on the type of the input parameter:
875 * <li>if a text input, returns the trimmed value</li>
876 * <li>if a choice list or radio button, returns the selected value</li>
877 * <li>if a value slider and input field, sets the value of the slider from
878 * the value in the text field, limiting it to any defined min-max
881 * Answers the (possibly modified) input value, as a String, Integer, Float
886 Object updateSliderFromValueField()
888 if (validator == null || isStringParameter)
890 if (isChoiceParameter)
892 if (parameter instanceof RadioChoiceParameter)
894 return buttonGroup.getSelection().getActionCommand();
898 return getSelectedValue(this.parameter,
899 choicebox.getSelectedIndex());
902 slider.setVisible(false);
903 return valueField.getText().trim();
906 if (validator.getMin() == null || validator.getMax() == null)
908 slider.setVisible(false);
911 valueField.setText(valueField.getText().trim());
914 * ensure not outside min-max range
915 * TODO: provide some visual indicator if limit reached
919 valueField.setBackground(Color.WHITE);
920 double d = Double.parseDouble(valueField.getText());
921 if (validator.getMin() != null
922 && validator.getMin().doubleValue() > d)
924 valueField.setText(formatNumber(validator.getMin()));
926 if (validator.getMax() != null
927 && validator.getMax().doubleValue() < d)
929 valueField.setText(formatNumber(validator.getMax()));
931 } catch (NumberFormatException e)
933 valueField.setBackground(Color.yellow);
937 if (isIntegerParameter)
942 iVal = Integer.valueOf(valueField.getText());
943 } catch (Exception e)
945 valueField.setBackground(Color.yellow);
946 return Integer.valueOf(0);
949 if (validator.getMin() != null && validator.getMax() != null)
951 slider.getModel().setRangeProperties(iVal, 1,
952 validator.getMin().intValue(),
953 validator.getMax().intValue() + 1, true);
957 slider.setVisible(false);
959 return Integer.valueOf(iVal);
962 if (isLogarithmicParameter)
967 double eValue = Double.valueOf(valueField.getText());
968 dVal = Math.log(eValue);
969 } catch (Exception e)
971 // shouldn't be possible here
972 valueField.setBackground(Color.yellow);
975 if (validator.getMin() != null && validator.getMax() != null)
977 double scaleMin = Math.log(validator.getMin().doubleValue())
979 double scaleMax = Math.log(validator.getMax().doubleValue())
981 slider.getModel().setRangeProperties(
982 (int) (sliderScaleFactor * dVal), 1,
983 (int) scaleMin, 1 + (int) scaleMax, true);
987 slider.setVisible(false);
989 return Double.valueOf(dVal);
995 fVal = Float.valueOf(valueField.getText());
996 } catch (Exception e)
998 return Float.valueOf(0f); // shouldn't happen
1000 if (validator.getMin() != null && validator.getMax() != null)
1002 float scaleMin = validator.getMin().floatValue()
1003 * sliderScaleFactor;
1004 float scaleMax = validator.getMax().floatValue()
1005 * sliderScaleFactor;
1006 slider.getModel().setRangeProperties(
1007 (int) (fVal * sliderScaleFactor), 1, (int) scaleMin,
1008 1 + (int) scaleMax, true);
1012 slider.setVisible(false);
1014 return Float.valueOf(fVal);
1019 * Constructor with the option to show 'compact' format (parameter description
1020 * as tooltip) or 'expanded' format (parameter description in a textbox which
1021 * may be opened or closed). Use compact for simple description text, expanded
1022 * for more wordy or formatted text.
1024 * @param paramContainer
1026 public OptsAndParamsPage(OptsParametersContainerI paramContainer,
1029 poparent = paramContainer;
1030 this.compact = compact;
1033 public static void showUrlPopUp(JComponent invoker, final String finfo,
1037 JPopupMenu mnu = new JPopupMenu();
1038 JMenuItem mitem = new JMenuItem(
1039 MessageManager.formatMessage("label.view_params", new String[]
1041 mitem.addActionListener(new ActionListener()
1045 public void actionPerformed(ActionEvent e)
1047 Desktop.showUrl(finfo);
1052 mnu.show(invoker, x, y);
1055 public Map<String, OptionBox> getOptSet()
1060 public void setOptSet(Map<String, OptionBox> optSet)
1062 this.optSet = optSet;
1065 public Map<String, ParamBox> getParamSet()
1070 public void setParamSet(Map<String, ParamBox> paramSet)
1072 this.paramSet = paramSet;
1075 OptionBox addOption(OptionI opt)
1077 OptionBox cb = optSet.get(opt.getName());
1080 cb = new OptionBox(opt);
1081 optSet.put(opt.getName(), cb);
1082 // jobOptions.add(cb, FlowLayout.LEFT);
1087 ParamBox addParameter(ParameterI arg)
1089 ParamBox pb = paramSet.get(arg.getName());
1092 pb = new ParamBox(poparent, arg);
1093 paramSet.put(arg.getName(), pb);
1094 // paramList.add(pb);
1097 // take the defaults from the parameter
1098 pb.updateControls(arg);
1102 void selectOption(OptionI option, String string)
1104 OptionBox cb = optSet.get(option.getName());
1107 cb = addOption(option);
1109 cb.enabled.setSelected(string != null); // initial state for an option.
1112 if (option.getPossibleValues().contains(string))
1114 cb.val.setSelectedItem(string);
1118 throw new Error(String.format("Invalid value '%s' for option '%s'",
1119 string, option.getName()));
1122 if (option.isRequired() && !cb.enabled.isSelected())
1124 // TODO: indicate paramset is not valid.. option needs to be selected!
1126 cb.setInitialValue();
1129 void setParameter(ParameterI arg)
1131 ParamBox pb = paramSet.get(arg.getName());
1138 pb.updateControls(arg);
1144 * Answers a list of arguments representing all the options and arguments
1145 * selected on the dialog, holding their chosen or input values. Optional
1146 * parameters which were not selected are not included.
1150 public List<ArgumentI> getCurrentSettings()
1152 List<ArgumentI> argSet = new ArrayList<>();
1153 for (OptionBox opts : getOptSet().values())
1155 ArgumentI opt = opts.getSelectedOption();
1161 for (ParamBox parambox : getParamSet().values())
1163 ArgumentI parm = parambox.getParameter();
1174 * A helper method that constructs and returns a CombBox for choice of the
1175 * possible option values. If display names are provided, then these are added
1176 * as options, otherwise the actual values are added.
1181 protected static JComboBox<Object> buildComboBox(OptionI opt)
1183 JComboBox<Object> cb = null;
1184 List<String> displayNames = opt.getDisplayNames();
1185 if (displayNames != null)
1187 List<Object> displayNamesObjects = new ArrayList<>();
1188 displayNamesObjects.addAll(displayNames);
1189 cb = JvSwingUtils.buildComboWithTooltips(displayNamesObjects,
1190 opt.getPossibleValues());
1194 cb = new JComboBox<>();
1195 for (String v : opt.getPossibleValues())
1204 * Answers the value corresponding to the selected item in the choice combo
1205 * box. Note that this returns the underlying value even if a different
1206 * display name is used in the combo box.
1210 protected static String getSelectedValue(OptionI opt, int sel)
1212 List<String> possibleValues = opt.getPossibleValues();
1213 String value = null;
1214 if (possibleValues != null && possibleValues.size() == 1)
1216 // Hack to make sure the default value for an enabled option with only
1217 // one value is actually returned even if this.val is not displayed
1218 value = possibleValues.get(0);
1220 else if (sel >= 0 && sel < possibleValues.size())
1222 value = possibleValues.get(sel);