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
137 public OptionBox(OptionI opt)
140 setLayout(new FlowLayout(FlowLayout.LEFT));
141 enabled = new JCheckBox(opt.getLabel());
142 enabled.setSelected(opt.isRequired());
145 * If option is required, show a label, if optional a checkbox
146 * (but not for Jabaws pending JWS-126 resolution)
148 if (opt.isRequired() && !(opt instanceof JabaOption))
151 add(new JLabel(opt.getLabel()));
155 finfo = option.getFurtherDetails();
156 configureCheckbox(opt);
161 * construct the choice box with possible values,
162 * or their display names if provided
164 val = buildComboBox(opt);
165 val.setSelectedItem(opt.getValue());
168 * only show the choicebox if there is more than one option,
169 * or the option is mandatory
171 if (opt.getPossibleValues().size() > 1 || opt.isRequired())
173 val.addActionListener(this);
181 * Configures the checkbox that controls whether or not the option is
186 protected void configureCheckbox(OptionI opt)
188 enabled.setFont(new Font("Verdana", Font.PLAIN, 11));
189 enabled.addActionListener(this);
190 final String desc = opt.getDescription();
195 String description = desc;
196 if (desc == null || desc.trim().isEmpty())
198 description = MessageManager
199 .getString("label.opt_and_params_further_details");
201 description = description + "<br><img src=\"" + linkImageURL
203 String text = JvSwingUtils.wrapTooltip(true, description);
204 enabled.setToolTipText(text);
205 enabled.addMouseListener(this); // for popup menu to show link
209 if (desc != null && desc.trim().length() > 0)
211 enabled.setToolTipText(JvSwingUtils.wrapTooltip(true, desc));
217 public void actionPerformed(ActionEvent e)
219 if (e.getSource() != enabled)
221 enabled.setSelected(true);
226 private void checkIfModified()
228 boolean notmod = (initEnabled == enabled.isSelected());
229 if (enabled.isSelected())
233 notmod &= initVal.equals(val.getSelectedItem());
237 // compare against default service setting
238 notmod &= option.getValue() == null
239 || option.getValue().equals(val.getSelectedItem());
244 notmod &= (initVal != null) ? initVal.equals(val.getSelectedItem())
245 : val.getSelectedItem() != initVal;
247 poparent.argSetModified(this, !notmod);
251 * Answers null if the option is not selected, else a new Option holding the
256 public ArgumentI getSelectedOption()
258 if (!enabled.isSelected())
262 String value = getSelectedValue(option, val.getSelectedIndex());
263 OptionI opt = option.copy();
269 public void mouseClicked(MouseEvent e)
271 if (e.isPopupTrigger()) // for Windows
273 showUrlPopUp(this, finfo.toString(), e.getX(), e.getY());
278 public void mouseEntered(MouseEvent e)
284 public void mouseExited(MouseEvent e)
290 public void mousePressed(MouseEvent e)
292 if (e.isPopupTrigger()) // Mac
294 showUrlPopUp(this, finfo.toString(), e.getX(), e.getY());
299 public void mouseReleased(MouseEvent e)
303 public void resetToDefault(boolean setDefaultParams)
305 enabled.setSelected(false);
306 if (option.isRequired()
307 || (setDefaultParams && option.getValue() != null))
309 // Apply default value
310 selectOption(option, option.getValue());
314 public void setInitialValue()
316 initEnabled = enabled.isSelected();
317 if (option.getPossibleValues() != null
318 && option.getPossibleValues().size() > 1)
320 initVal = (String) val.getSelectedItem();
324 initVal = (initEnabled) ? (String) val.getSelectedItem() : null;
329 * toString representation for identification in the debugger only
332 public String toString()
334 return option == null ? super.toString() : option.toString();
339 * A class that models a panel rendering a single parameter
341 public class ParamBox extends JPanel
342 implements ChangeListener, ActionListener, MouseListener
345 * parameter values (or their logs) are multiplied by this
346 * scaling factor to ensure an integer range for the slider
348 private int sliderScaleFactor = 1;
350 boolean isLogarithmicParameter;
352 boolean isChoiceParameter;
354 boolean isIntegerParameter;
356 boolean isStringParameter;
361 * drop-down list of choice options (if applicable)
363 JComboBox<Object> choicebox;
366 * radio buttons as an alternative to combo box
368 ButtonGroup buttonGroup;
370 JPanel controlsPanel = new JPanel();
372 boolean descriptionIsVisible = false;
374 JScrollPane descPanel = new JScrollPane();
380 ParameterI parameter;
382 final OptsParametersContainerI pmdialogbox;
384 JPanel settingPanel = new JPanel();
388 JTextArea descriptionText = new JTextArea();
390 ValueConstrainI validator;
392 JTextField valueField;
394 private String descTooltip;
396 public ParamBox(final OptsParametersContainerI paramContainer,
399 pmdialogbox = paramContainer;
400 finfo = parm.getFurtherDetails();
401 validator = parm.getValidValue();
403 isLogarithmicParameter = parm instanceof LogarithmicParameter;
404 if (validator != null)
406 ValueType type = validator.getType();
407 isIntegerParameter = type == ValueType.Integer;
408 isStringParameter = type == ValueType.String
409 || type == ValueType.File;
412 * ensure slider has an integer range corresponding to
413 * the min-max range of the parameter
415 if (validator.getMin() != null && validator.getMax() != null
416 // && !isIntegerParameter
417 && !isStringParameter)
419 double min = validator.getMin().doubleValue();
420 double max = validator.getMax().doubleValue();
421 if (isLogarithmicParameter)
426 sliderScaleFactor = (int) (1000000 / (max - min));
427 // todo scaleMin, scaleMax could also be final fields
431 List<String> possibleValues = parameter.getPossibleValues();
432 isChoiceParameter = possibleValues != null
433 && !possibleValues.isEmpty();
437 addCompactParameter(parm);
441 addExpandableParam(parm);
447 * Adds a 'compact' format parameter, with any help text shown as a tooltip
451 private void addCompactParameter(ParameterI parm)
453 setLayout(new MigLayout("", "[][grow]"));
455 String ttipText = null;
457 controlsPanel.setLayout(new BorderLayout());
459 if (parm.getDescription() != null
460 && parm.getDescription().trim().length() > 0)
462 ttipText = (JvSwingUtils.wrapTooltip(true,
463 parm.getDescription() + (finfo != null ? "<br><img src=\""
464 + linkImageURL + "\"/>"
465 + MessageManager.getString(
466 "label.opt_and_params_further_details")
470 JvSwingUtils.addtoLayout(this, ttipText, new JLabel(parm.getName()),
472 updateControls(parm);
477 * Adds an 'expanded' format parameter, with any help shown in a panel that
478 * may be shown or hidden
482 private void addExpandableParam(ParameterI parm)
484 setPreferredSize(new Dimension(PARAM_WIDTH, PARAM_CLOSEDHEIGHT));
485 setBorder(new TitledBorder(parm.getName()));
487 descriptionText.setFont(new Font("Verdana", Font.PLAIN, 11));
488 descriptionText.setBackground(getBackground());
490 descriptionText.setEditable(false);
491 descPanel.getViewport().setView(descriptionText);
493 descPanel.setVisible(false);
495 JPanel firstrow = new JPanel();
496 firstrow.setLayout(null);
497 controlsPanel.setLayout(new BorderLayout());
498 controlsPanel.setBounds(new Rectangle(39, 10, PARAM_WIDTH - 70,
499 PARAM_CLOSEDHEIGHT - 50));
500 firstrow.add(controlsPanel);
501 firstrow.setBounds(new Rectangle(10, 20, PARAM_WIDTH - 30,
502 PARAM_CLOSEDHEIGHT - 30));
505 if (parm.getDescription() != null
506 && parm.getDescription().trim().length() > 0)
508 addExpandableHelp(firstrow, parm);
511 validator = parm.getValidValue();
513 if (validator != null)
515 isIntegerParameter = validator.getType() == ValueType.Integer;
519 if (parameter.getPossibleValues() != null)
521 isChoiceParameter = true;
524 updateControls(parm);
525 descPanel.setBounds(new Rectangle(10, PARAM_CLOSEDHEIGHT,
526 PARAM_WIDTH - 20, PARAM_HEIGHT - PARAM_CLOSEDHEIGHT - 5));
532 * Adds a button which can be clicked to show or hide help text
537 protected void addExpandableHelp(JPanel container, ParameterI param)
539 JButton showDescBtn = new JButton("+");
540 showDescBtn.setFont(new Font("Verdana", Font.PLAIN, 8));
543 descTooltip = JvSwingUtils.wrapTooltip(true,
544 MessageManager.formatMessage(
545 "label.opt_and_params_show_brief_desc_image_link",
547 { linkImageURL.toExternalForm() }));
548 showDescBtn.addMouseListener(this);
552 descTooltip = JvSwingUtils.wrapTooltip(true, MessageManager
553 .getString("label.opt_and_params_show_brief_desc"));
555 showDescBtn.setToolTipText(descTooltip);
556 showDescBtn.addActionListener(new ActionListener()
559 public void actionPerformed(ActionEvent e)
561 descriptionIsVisible = !descriptionIsVisible;
562 showDescBtn.setText(descriptionIsVisible ? "-" : "+");
563 showDescBtn.setToolTipText(
564 descriptionIsVisible ? null : descTooltip);
565 descPanel.setVisible(descriptionIsVisible);
566 descPanel.getVerticalScrollBar().setValue(0);
567 ParamBox.this.setPreferredSize(new Dimension(PARAM_WIDTH,
568 (descriptionIsVisible) ? PARAM_HEIGHT
569 : PARAM_CLOSEDHEIGHT));
570 ParamBox.this.validate();
571 pmdialogbox.refreshParamLayout();
574 descriptionText.setWrapStyleWord(true);
575 descriptionText.setLineWrap(true);
576 descriptionText.setColumns(32);
577 descriptionText.setText(param.getDescription());
578 showDescBtn.setBounds(new Rectangle(10, 10, 16, 16));
579 container.add(showDescBtn);
582 public void actionPerformed(ActionEvent e)
592 * Checks whether the value of this parameter has been changed and notifies
593 * the parent page accordingly
595 private void checkIfModified()
597 Object newValue = updateSliderFromValueField();
598 boolean modified = true;
599 if (newValue.getClass() == lastVal.getClass())
601 modified = !newValue.equals(lastVal);
603 pmdialogbox.argSetModified(this, modified);
607 public int getBaseline(int width, int height)
613 // http://stackoverflow.com/questions/2743177/top-alignment-for-flowlayout
614 // helpful hint of using the Java 1.6 alignBaseLine property of FlowLayout
616 public Component.BaselineResizeBehavior getBaselineResizeBehavior()
618 return Component.BaselineResizeBehavior.CONSTANT_ASCENT;
622 * Answers an argument holding the value entered or selected in the dialog
626 public ArgumentI getParameter()
628 ParameterI prm = parameter.copy();
630 if (parameter instanceof RadioChoiceParameter)
632 value = buttonGroup.getSelection().getActionCommand();
634 else if (isChoiceParameter)
636 value = getSelectedValue(this.parameter,
637 choicebox.getSelectedIndex());
641 value = valueField.getText();
649 // reset the widget's initial value.
654 public void mouseClicked(MouseEvent e)
656 if (e.isPopupTrigger()) // for Windows
658 showUrlPopUp(this, finfo.toString(), e.getX(), e.getY());
663 public void mouseEntered(MouseEvent e)
669 public void mouseExited(MouseEvent e)
675 public void mousePressed(MouseEvent e)
677 if (e.isPopupTrigger()) // for Mac
679 showUrlPopUp(this, finfo.toString(), e.getX(), e.getY());
684 public void mouseReleased(MouseEvent e)
690 public void stateChanged(ChangeEvent e)
699 if (!isLogarithmicParameter)
702 * set (int or float formatted) text field value
704 valueField.setText(isIntegerParameter
705 ? String.valueOf(slider.getValue())
707 slider.getValue() / (float) sliderScaleFactor));
711 double value = Math.pow(Math.E,
712 slider.getValue() / (double) sliderScaleFactor);
713 valueField.setText(formatDouble(value));
723 * Answers the value formatted as a string to 3 decimal places - in
724 * scientific notation if the value is less than 0.001
729 String formatDouble(double value)
731 String format = value < 0.001 ? "%3.1E" : "%3.3f";
732 return String.format(format, value);
736 * Formats a number as integer or float (3dp) or scientific notation (1dp)
741 String formatNumber(Number n)
743 return n instanceof Integer ? String.valueOf(n.intValue())
744 : formatDouble(n.doubleValue());
747 void updateControls(ParameterI parm)
750 boolean init = (choicebox == null && valueField == null
751 && buttonGroup == null);
754 if (parm instanceof RadioChoiceParameter)
756 buttonGroup = addRadioButtons(parameter, controlsPanel);
758 else if (isChoiceParameter)
760 choicebox = buildComboBox(parm);
761 choicebox.addActionListener(this);
762 controlsPanel.add(choicebox, BorderLayout.CENTER);
766 slider = new JSlider();
767 slider.addChangeListener(this);
768 int cols = parm instanceof StringParameter ? 20 : 0;
769 valueField = new JTextField(cols);
770 valueField.addActionListener(this);
771 valueField.addKeyListener(new KeyAdapter()
776 public void keyReleased(KeyEvent e)
778 int keyCode = e.getKeyCode();
779 if (e.isActionKey() && keyCode != KeyEvent.VK_LEFT
780 && keyCode != KeyEvent.VK_RIGHT)
782 if (valueField.getText().trim().length() > 0)
784 actionPerformed(null);
790 valueField.addFocusListener(new FocusAdapter() {
793 public void focusLost(FocusEvent e)
795 actionPerformed(null);
799 valueField.setPreferredSize(new Dimension(65, 25));
800 if (parm instanceof FileParameter)
802 valueField.setToolTipText(MessageManager
803 .getString("label.double_click_to_browse"));
804 valueField.addMouseListener(new MouseAdapter()
807 public void mouseClicked(MouseEvent e)
809 if (e.getClickCount() == 2)
811 String dir = Cache.getProperty("LAST_DIRECTORY");
812 JalviewFileChooser chooser = new JalviewFileChooser(dir);
813 chooser.setFileView(new JalviewFileView());
814 chooser.setDialogTitle(
815 MessageManager.getString("action.select_ddbb"));
817 int val = chooser.showOpenDialog(ParamBox.this);
818 if (val == JalviewFileChooser.APPROVE_OPTION)
820 File choice = chooser.getSelectedFile();
821 String path = choice.getPath();
822 valueField.setText(path);
823 Cache.setProperty("LAST_DIRECTORY", choice.getParent());
824 FileLoader.updateRecentlyOpened(path,
825 DataSourceType.FILE);
832 controlsPanel.add(slider, BorderLayout.WEST);
833 controlsPanel.add(valueField, BorderLayout.EAST);
837 String value = parm.getValue();
840 if (isChoiceParameter)
842 if (!(parm instanceof RadioChoiceParameter))
844 choicebox.setSelectedItem(value);
849 valueField.setText(value);
852 lastVal = updateSliderFromValueField();
857 * Adds a panel to comp, containing a label and radio buttons for the choice
858 * of values of the given option. Returns a ButtonGroup whose members are
859 * the added radio buttons.
866 protected ButtonGroup addRadioButtons(OptionI option, Container comp)
868 ButtonGroup bg = new ButtonGroup();
869 JPanel radioPanel = new JPanel();
870 radioPanel.add(new JLabel(option.getDescription()));
872 String value = option.getValue();
874 for (String opt : option.getPossibleValues())
876 JRadioButton btn = new JRadioButton(opt);
877 btn.setActionCommand(opt);
878 boolean selected = opt.equals(value);
879 btn.setSelected(selected);
880 btn.addActionListener(this);
884 comp.add(radioPanel);
890 * Action depends on the type of the input parameter:
892 * <li>if a text input, returns the trimmed value</li>
893 * <li>if a choice list or radio button, returns the selected value</li>
894 * <li>if a value slider and input field, sets the value of the slider from
895 * the value in the text field, limiting it to any defined min-max
898 * Answers the (possibly modified) input value, as a String, Integer, Float
903 Object updateSliderFromValueField()
905 if (validator == null || isStringParameter)
907 if (isChoiceParameter)
909 if (parameter instanceof RadioChoiceParameter)
911 return buttonGroup.getSelection().getActionCommand();
915 return getSelectedValue(this.parameter,
916 choicebox.getSelectedIndex());
919 slider.setVisible(false);
920 return valueField.getText().trim();
923 if (validator.getMin() == null || validator.getMax() == null)
925 slider.setVisible(false);
928 valueField.setText(valueField.getText().trim());
931 * ensure not outside min-max range
932 * TODO: provide some visual indicator if limit reached
936 valueField.setBackground(Color.WHITE);
937 double d = Double.parseDouble(valueField.getText());
938 if (validator.getMin() != null
939 && validator.getMin().doubleValue() > d)
941 valueField.setText(formatNumber(validator.getMin()));
943 if (validator.getMax() != null
944 && validator.getMax().doubleValue() < d)
946 valueField.setText(formatNumber(validator.getMax()));
948 } catch (NumberFormatException e)
950 valueField.setBackground(Color.yellow);
953 if (isIntegerParameter)
958 iVal = Integer.valueOf(valueField.getText());
959 } catch (Exception e)
961 valueField.setBackground(Color.yellow);
962 return Integer.valueOf(0);
965 if (validator.getMin() != null && validator.getMax() != null)
967 slider.getModel().setRangeProperties(iVal, 1,
968 validator.getMin().intValue(),
969 validator.getMax().intValue() + 1, true);
973 slider.setVisible(false);
975 return Integer.valueOf(iVal);
978 if (isLogarithmicParameter)
983 double eValue = Double.valueOf(valueField.getText());
984 dVal = Math.log(eValue);
985 } catch (Exception e)
987 // shouldn't be possible here
988 valueField.setBackground(Color.yellow);
991 if (validator.getMin() != null && validator.getMax() != null)
993 double scaleMin = Math.log(validator.getMin().doubleValue())
995 double scaleMax = Math.log(validator.getMax().doubleValue())
997 slider.getModel().setRangeProperties(
998 (int) (sliderScaleFactor * dVal), 1,
999 (int) scaleMin, 1 + (int) scaleMax, true);
1003 slider.setVisible(false);
1005 return Double.valueOf(dVal);
1011 fVal = Float.valueOf(valueField.getText());
1012 } catch (Exception e)
1014 return Float.valueOf(0f); // shouldn't happen
1016 if (validator.getMin() != null && validator.getMax() != null)
1018 float scaleMin = validator.getMin().floatValue()
1019 * sliderScaleFactor;
1020 float scaleMax = validator.getMax().floatValue()
1021 * sliderScaleFactor;
1022 slider.getModel().setRangeProperties(
1023 (int) (fVal * sliderScaleFactor), 1, (int) scaleMin,
1024 1 + (int) scaleMax, true);
1028 slider.setVisible(false);
1030 return Float.valueOf(fVal);
1035 * Constructor with the option to show 'compact' format (parameter description
1036 * as tooltip) or 'expanded' format (parameter description in a textbox which
1037 * may be opened or closed). Use compact for simple description text, expanded
1038 * for more wordy or formatted text.
1040 * @param paramContainer
1043 public OptsAndParamsPage(OptsParametersContainerI paramContainer,
1046 poparent = paramContainer;
1047 this.compact = compact;
1050 public static void showUrlPopUp(JComponent invoker, final String finfo,
1054 JPopupMenu mnu = new JPopupMenu();
1055 JMenuItem mitem = new JMenuItem(
1056 MessageManager.formatMessage("label.view_params", new String[]
1058 mitem.addActionListener(new ActionListener()
1062 public void actionPerformed(ActionEvent e)
1064 Desktop.showUrl(finfo);
1069 mnu.show(invoker, x, y);
1073 public Map<String, OptionBox> getOptSet()
1078 public void setOptSet(Map<String, OptionBox> optSet)
1080 this.optSet = optSet;
1083 public Map<String, ParamBox> getParamSet()
1088 public void setParamSet(Map<String, ParamBox> paramSet)
1090 this.paramSet = paramSet;
1094 OptionBox addOption(OptionI opt)
1096 OptionBox cb = optSet.get(opt.getName());
1099 cb = new OptionBox(opt);
1100 optSet.put(opt.getName(), cb);
1101 // jobOptions.add(cb, FlowLayout.LEFT);
1106 ParamBox addParameter(ParameterI arg)
1108 ParamBox pb = paramSet.get(arg.getName());
1111 pb = new ParamBox(poparent, arg);
1112 paramSet.put(arg.getName(), pb);
1113 // paramList.add(pb);
1116 // take the defaults from the parameter
1117 pb.updateControls(arg);
1121 void selectOption(OptionI option, String string)
1123 OptionBox cb = optSet.get(option.getName());
1126 cb = addOption(option);
1128 cb.enabled.setSelected(string != null); // initial state for an option.
1131 if (option.getPossibleValues().contains(string))
1133 cb.val.setSelectedItem(string);
1137 throw new Error(MessageManager.formatMessage(
1138 "error.invalid_value_for_option", new String[]
1139 { string, option.getName() }));
1143 if (option.isRequired() && !cb.enabled.isSelected())
1145 // TODO: indicate paramset is not valid.. option needs to be selected!
1147 cb.setInitialValue();
1150 void setParameter(ParameterI arg)
1152 ParamBox pb = paramSet.get(arg.getName());
1159 pb.updateControls(arg);
1165 * Answers a list of arguments representing all the options and arguments
1166 * selected on the dialog, holding their chosen or input values. Optional
1167 * parameters which were not selected are not included.
1171 public List<ArgumentI> getCurrentSettings()
1173 List<ArgumentI> argSet = new ArrayList<>();
1174 for (OptionBox opts : getOptSet().values())
1176 ArgumentI opt = opts.getSelectedOption();
1182 for (ParamBox parambox : getParamSet().values())
1184 ArgumentI parm = parambox.getParameter();
1195 * A helper method that constructs and returns a CombBox for choice of the
1196 * possible option values. If display names are provided, then these are added
1197 * as options, otherwise the actual values are added.
1202 protected static JComboBox<Object> buildComboBox(OptionI opt)
1204 JComboBox<Object> cb = null;
1205 List<String> displayNames = opt.getDisplayNames();
1206 if (displayNames != null)
1208 List<Object> displayNamesObjects = new ArrayList<>();
1209 displayNamesObjects.addAll(displayNames);
1210 cb = JvSwingUtils.buildComboWithTooltips(displayNamesObjects,
1211 opt.getPossibleValues());
1215 cb = new JComboBox<>();
1216 for (String v : opt.getPossibleValues())
1225 * Answers the value corresponding to the selected item in the choice combo
1226 * box. Note that this returns the underlying value even if a different
1227 * display name is used in the combo box.
1231 protected static String getSelectedValue(OptionI opt, int sel)
1233 List<String> possibleValues = opt.getPossibleValues();
1234 String value = null;
1235 if (possibleValues != null && possibleValues.size() == 1)
1237 // Hack to make sure the default value for an enabled option with only
1238 // one value is actually returned even if this.val is not displayed
1239 value = possibleValues.get(0);
1241 else if (sel >= 0 && sel < possibleValues.size())
1243 value = possibleValues.get(sel);