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;
39 import java.awt.BorderLayout;
40 import java.awt.Color;
41 import java.awt.Component;
42 import java.awt.Container;
43 import java.awt.Dimension;
44 import java.awt.FlowLayout;
46 import java.awt.Rectangle;
47 import java.awt.event.ActionEvent;
48 import java.awt.event.ActionListener;
49 import java.awt.event.FocusAdapter;
50 import java.awt.event.FocusEvent;
51 import java.awt.event.KeyAdapter;
52 import java.awt.event.KeyEvent;
53 import java.awt.event.MouseAdapter;
54 import java.awt.event.MouseEvent;
55 import java.awt.event.MouseListener;
58 import java.util.ArrayList;
59 import java.util.LinkedHashMap;
60 import java.util.List;
63 import javax.swing.ButtonGroup;
64 import javax.swing.JButton;
65 import javax.swing.JCheckBox;
66 import javax.swing.JComboBox;
67 import javax.swing.JComponent;
68 import javax.swing.JLabel;
69 import javax.swing.JMenuItem;
70 import javax.swing.JPanel;
71 import javax.swing.JPopupMenu;
72 import javax.swing.JRadioButton;
73 import javax.swing.JScrollPane;
74 import javax.swing.JSlider;
75 import javax.swing.JTextArea;
76 import javax.swing.JTextField;
77 import javax.swing.border.TitledBorder;
78 import javax.swing.event.ChangeEvent;
79 import javax.swing.event.ChangeListener;
81 import net.miginfocom.swing.MigLayout;
84 * GUI generator/manager for options and parameters. Originally abstracted from
85 * the WsJobParameters dialog box.
90 public class OptsAndParamsPage
92 public static final int PARAM_WIDTH = 340;
94 public static final int PARAM_HEIGHT = 150;
96 public static final int PARAM_CLOSEDHEIGHT = 80;
98 URL linkImageURL = getClass().getResource("/images/link.gif");
100 Map<String, OptionBox> optSet = new LinkedHashMap<>();
102 Map<String, ParamBox> paramSet = new LinkedHashMap<>();
105 * compact or verbose style parameters
107 boolean compact = false;
109 OptsParametersContainerI poparent;
112 * A class that models a panel rendering a single option (checkbox or choice
115 public class OptionBox extends JPanel
116 implements MouseListener, ActionListener
122 boolean hasLink = false;
124 boolean initEnabled = false;
126 String initVal = null;
130 JComboBox<Object> val;
133 * Constructs and adds labels and controls to the panel for one Option
138 public OptionBox(OptionI opt)
141 setLayout(new FlowLayout(FlowLayout.LEFT));
142 enabled = new JCheckBox(opt.getLabel());
143 enabled.setSelected(opt.isRequired());
146 * If option is required, show a label, if optional a checkbox
147 * (but not for Jabaws pending JWS-126 resolution)
149 if (opt.isRequired() && !(opt instanceof JabaOption))
152 add(new JLabel(opt.getLabel()));
156 finfo = option.getFurtherDetails();
157 configureCheckbox(opt);
162 * construct the choice box with possible values,
163 * or their display names if provided
165 val = buildComboBox(opt);
166 val.setSelectedItem(opt.getValue());
169 * only show the choicebox if there is more than one option,
170 * or the option is mandatory
172 if (opt.getPossibleValues().size() > 1 || opt.isRequired())
174 val.addActionListener(this);
182 * Configures the checkbox that controls whether or not the option is
187 protected void configureCheckbox(OptionI opt)
189 enabled.setFont(new Font("Verdana", Font.PLAIN, 11));
190 enabled.addActionListener(this);
191 final String desc = opt.getDescription();
196 String description = desc;
197 if (desc == null || desc.trim().isEmpty())
199 description = MessageManager
200 .getString("label.opt_and_params_further_details");
202 description = description + "<br><img src=\"" + linkImageURL
204 String text = JvSwingUtils.wrapTooltip(true, description);
205 enabled.setToolTipText(text);
206 enabled.addMouseListener(this); // for popup menu to show link
210 if (desc != null && desc.trim().length() > 0)
212 enabled.setToolTipText(JvSwingUtils.wrapTooltip(true, desc));
218 public void actionPerformed(ActionEvent e)
220 if (e.getSource() != enabled)
222 enabled.setSelected(true);
227 private void checkIfModified()
229 boolean notmod = (initEnabled == enabled.isSelected());
230 if (enabled.isSelected())
234 notmod &= initVal.equals(val.getSelectedItem());
238 // compare against default service setting
239 notmod &= option.getValue() == null
240 || option.getValue().equals(val.getSelectedItem());
245 notmod &= (initVal != null) ? initVal.equals(val.getSelectedItem())
246 : val.getSelectedItem() != initVal;
248 poparent.argSetModified(this, !notmod);
252 * Answers null if the option is not selected, else a new Option holding the
257 public ArgumentI getSelectedOption()
259 if (!enabled.isSelected())
263 String value = getSelectedValue(option, val.getSelectedIndex());
264 OptionI opt = option.copy();
270 public void mouseClicked(MouseEvent e)
272 if (e.isPopupTrigger()) // for Windows
274 showUrlPopUp(this, finfo.toString(), e.getX(), e.getY());
279 public void mouseEntered(MouseEvent e)
285 public void mouseExited(MouseEvent e)
291 public void mousePressed(MouseEvent e)
293 if (e.isPopupTrigger()) // Mac
295 showUrlPopUp(this, finfo.toString(), e.getX(), e.getY());
300 public void mouseReleased(MouseEvent e)
304 public void resetToDefault(boolean setDefaultParams)
306 enabled.setSelected(false);
307 if (option.isRequired()
308 || (setDefaultParams && option.getValue() != null))
310 // Apply default value
311 selectOption(option, option.getValue());
315 public void setInitialValue()
317 initEnabled = enabled.isSelected();
318 if (option.getPossibleValues() != null
319 && option.getPossibleValues().size() > 1)
321 initVal = (String) val.getSelectedItem();
325 initVal = (initEnabled) ? (String) val.getSelectedItem() : null;
330 * toString representation for identification in the debugger only
333 public String toString()
335 return option == null ? super.toString() : option.toString();
340 * A class that models a panel rendering a single parameter
342 public class ParamBox extends JPanel
343 implements ChangeListener, ActionListener, MouseListener
346 * parameter values (or their logs) are multiplied by this
347 * scaling factor to ensure an integer range for the slider
349 private int sliderScaleFactor = 1;
351 boolean isLogarithmicParameter;
353 boolean isChoiceParameter;
355 boolean isIntegerParameter;
357 boolean isStringParameter;
362 * drop-down list of choice options (if applicable)
364 JComboBox<Object> choicebox;
367 * radio buttons as an alternative to combo box
369 ButtonGroup buttonGroup;
371 JPanel controlsPanel = new JPanel();
373 boolean descriptionIsVisible = false;
375 JScrollPane descPanel = new JScrollPane();
381 ParameterI parameter;
383 final OptsParametersContainerI pmdialogbox;
385 JPanel settingPanel = new JPanel();
389 JTextArea descriptionText = new JTextArea();
391 ValueConstrainI validator;
393 JTextField valueField;
395 private String descTooltip;
397 public ParamBox(final OptsParametersContainerI paramContainer,
400 pmdialogbox = paramContainer;
401 finfo = parm.getFurtherDetails();
402 validator = parm.getValidValue();
404 isLogarithmicParameter = parm instanceof LogarithmicParameter;
405 if (validator != null)
407 ValueType type = validator.getType();
408 isIntegerParameter = type == ValueType.Integer;
409 isStringParameter = type == ValueType.String
410 || type == ValueType.File;
413 * ensure slider has an integer range corresponding to
414 * the min-max range of the parameter
416 if (validator.getMin() != null && validator.getMax() != null
417 // && !isIntegerParameter
418 && !isStringParameter)
420 double min = validator.getMin().doubleValue();
421 double max = validator.getMax().doubleValue();
422 if (isLogarithmicParameter)
427 sliderScaleFactor = (int) (1000000 / (max - min));
428 // todo scaleMin, scaleMax could also be final fields
432 List<String> possibleValues = parameter.getPossibleValues();
433 isChoiceParameter = possibleValues != null
434 && !possibleValues.isEmpty();
438 addCompactParameter(parm);
442 addExpandableParam(parm);
448 * Adds a 'compact' format parameter, with any help text shown as a tooltip
452 private void addCompactParameter(ParameterI parm)
454 setLayout(new MigLayout("", "[][grow]"));
456 String ttipText = null;
458 controlsPanel.setLayout(new BorderLayout());
460 if (parm.getDescription() != null
461 && parm.getDescription().trim().length() > 0)
463 ttipText = (JvSwingUtils.wrapTooltip(true,
464 parm.getDescription() + (finfo != null ? "<br><img src=\""
465 + linkImageURL + "\"/>"
466 + MessageManager.getString(
467 "label.opt_and_params_further_details")
471 JvSwingUtils.addtoLayout(this, ttipText, new JLabel(parm.getName()),
473 updateControls(parm);
478 * Adds an 'expanded' format parameter, with any help shown in a panel that
479 * may be shown or hidden
483 private void addExpandableParam(ParameterI parm)
485 setPreferredSize(new Dimension(PARAM_WIDTH, PARAM_CLOSEDHEIGHT));
486 setBorder(new TitledBorder(parm.getName()));
488 descriptionText.setFont(new Font("Verdana", Font.PLAIN, 11));
489 descriptionText.setBackground(getBackground());
491 descriptionText.setEditable(false);
492 descPanel.getViewport().setView(descriptionText);
494 descPanel.setVisible(false);
496 JPanel firstrow = new JPanel();
497 firstrow.setLayout(null);
498 controlsPanel.setLayout(new BorderLayout());
499 controlsPanel.setBounds(new Rectangle(39, 10, PARAM_WIDTH - 70,
500 PARAM_CLOSEDHEIGHT - 50));
501 firstrow.add(controlsPanel);
502 firstrow.setBounds(new Rectangle(10, 20, PARAM_WIDTH - 30,
503 PARAM_CLOSEDHEIGHT - 30));
506 if (parm.getDescription() != null
507 && parm.getDescription().trim().length() > 0)
509 addExpandableHelp(firstrow, parm);
512 validator = parm.getValidValue();
514 if (validator != null)
516 isIntegerParameter = validator.getType() == ValueType.Integer;
520 if (parameter.getPossibleValues() != null)
522 isChoiceParameter = true;
525 updateControls(parm);
526 descPanel.setBounds(new Rectangle(10, PARAM_CLOSEDHEIGHT,
527 PARAM_WIDTH - 20, PARAM_HEIGHT - PARAM_CLOSEDHEIGHT - 5));
533 * Adds a button which can be clicked to show or hide help text
538 protected void addExpandableHelp(JPanel container, ParameterI param)
540 JButton showDescBtn = new JButton("+");
541 showDescBtn.setFont(new Font("Verdana", Font.PLAIN, 8));
544 descTooltip = JvSwingUtils.wrapTooltip(true,
545 MessageManager.formatMessage(
546 "label.opt_and_params_show_brief_desc_image_link",
548 { linkImageURL.toExternalForm() }));
549 showDescBtn.addMouseListener(this);
553 descTooltip = JvSwingUtils.wrapTooltip(true, MessageManager
554 .getString("label.opt_and_params_show_brief_desc"));
556 showDescBtn.setToolTipText(descTooltip);
557 showDescBtn.addActionListener(new ActionListener()
560 public void actionPerformed(ActionEvent e)
562 descriptionIsVisible = !descriptionIsVisible;
563 showDescBtn.setText(descriptionIsVisible ? "-" : "+");
564 showDescBtn.setToolTipText(
565 descriptionIsVisible ? null : descTooltip);
566 descPanel.setVisible(descriptionIsVisible);
567 descPanel.getVerticalScrollBar().setValue(0);
568 ParamBox.this.setPreferredSize(new Dimension(PARAM_WIDTH,
569 (descriptionIsVisible) ? PARAM_HEIGHT
570 : PARAM_CLOSEDHEIGHT));
571 ParamBox.this.validate();
572 pmdialogbox.refreshParamLayout();
575 descriptionText.setWrapStyleWord(true);
576 descriptionText.setLineWrap(true);
577 descriptionText.setColumns(32);
578 descriptionText.setText(param.getDescription());
579 showDescBtn.setBounds(new Rectangle(10, 10, 16, 16));
580 container.add(showDescBtn);
583 public void actionPerformed(ActionEvent e)
593 * Checks whether the value of this parameter has been changed and notifies
594 * the parent page accordingly
596 private void checkIfModified()
598 Object newValue = updateSliderFromValueField();
599 boolean modified = true;
600 if (newValue.getClass() == lastVal.getClass())
602 modified = !newValue.equals(lastVal);
604 pmdialogbox.argSetModified(this, modified);
609 public int getBaseline(int width, int height)
615 // http://stackoverflow.com/questions/2743177/top-alignment-for-flowlayout
616 // helpful hint of using the Java 1.6 alignBaseLine property of FlowLayout
618 public Component.BaselineResizeBehavior getBaselineResizeBehavior()
620 return Component.BaselineResizeBehavior.CONSTANT_ASCENT;
624 * Answers an argument holding the value entered or selected in the dialog
628 public ArgumentI getParameter()
630 ParameterI prm = parameter.copy();
632 if (parameter instanceof RadioChoiceParameter)
634 value = buttonGroup.getSelection().getActionCommand();
636 else if (isChoiceParameter)
638 value = getSelectedValue(this.parameter,
639 choicebox.getSelectedIndex());
643 value = valueField.getText();
651 // reset the widget's initial value.
656 public void mouseClicked(MouseEvent e)
658 if (e.isPopupTrigger()) // for Windows
660 showUrlPopUp(this, finfo.toString(), e.getX(), e.getY());
665 public void mouseEntered(MouseEvent e)
671 public void mouseExited(MouseEvent e)
677 public void mousePressed(MouseEvent e)
679 if (e.isPopupTrigger()) // for Mac
681 showUrlPopUp(this, finfo.toString(), e.getX(), e.getY());
686 public void mouseReleased(MouseEvent e)
692 public void stateChanged(ChangeEvent e)
701 if (!isLogarithmicParameter)
704 * set (int or float formatted) text field value
706 valueField.setText(isIntegerParameter
707 ? String.valueOf(slider.getValue())
709 slider.getValue() / (float) sliderScaleFactor));
713 double value = Math.pow(Math.E,
714 slider.getValue() / (double) sliderScaleFactor);
715 valueField.setText(formatDouble(value));
725 * Answers the value formatted as a string to 3 decimal places - in
726 * scientific notation if the value is less than 0.001
731 String formatDouble(double value)
733 String format = value < 0.001 ? "%3.1E" : "%3.3f";
734 return String.format(format, value);
738 * Formats a number as integer or float (3dp) or scientific notation (1dp)
743 String formatNumber(Number n)
745 return n instanceof Integer ? String.valueOf(n.intValue())
746 : formatDouble(n.doubleValue());
749 void updateControls(ParameterI parm)
752 boolean init = (choicebox == null && valueField == null
753 && buttonGroup == null);
756 if (parm instanceof RadioChoiceParameter)
758 buttonGroup = addRadioButtons(parameter, controlsPanel);
760 else if (isChoiceParameter)
762 choicebox = buildComboBox(parm);
763 choicebox.addActionListener(this);
764 controlsPanel.add(choicebox, BorderLayout.CENTER);
768 slider = new JSlider();
769 slider.addChangeListener(this);
770 int cols = parm instanceof StringParameter ? 20 : 0;
771 valueField = new JTextField(cols);
772 valueField.addActionListener(this);
773 valueField.addKeyListener(new KeyAdapter()
778 public void keyReleased(KeyEvent e)
780 int keyCode = e.getKeyCode();
781 if (e.isActionKey() && keyCode != KeyEvent.VK_LEFT
782 && keyCode != KeyEvent.VK_RIGHT)
784 if (valueField.getText().trim().length() > 0)
786 actionPerformed(null);
792 valueField.addFocusListener(new FocusAdapter() {
795 public void focusLost(FocusEvent e)
797 actionPerformed(null);
801 valueField.setPreferredSize(new Dimension(65, 25));
802 if (parm instanceof FileParameter)
804 valueField.setToolTipText(MessageManager
805 .getString("label.double_click_to_browse"));
806 valueField.addMouseListener(new MouseAdapter()
809 public void mouseClicked(MouseEvent e)
811 if (e.getClickCount() == 2)
813 String dir = Cache.getProperty("LAST_DIRECTORY");
814 JalviewFileChooser chooser = new JalviewFileChooser(dir);
815 chooser.setFileView(new JalviewFileView());
816 chooser.setDialogTitle(
817 MessageManager.getString("action.select_ddbb"));
819 int val = chooser.showOpenDialog(ParamBox.this);
820 if (val == JalviewFileChooser.APPROVE_OPTION)
822 File choice = chooser.getSelectedFile();
823 String path = choice.getPath();
824 valueField.setText(path);
825 Cache.setProperty("LAST_DIRECTORY", choice.getParent());
826 FileLoader.updateRecentlyOpened(path,
827 DataSourceType.FILE);
834 controlsPanel.add(slider, BorderLayout.WEST);
835 controlsPanel.add(valueField, BorderLayout.EAST);
839 String value = parm.getValue();
842 if (isChoiceParameter)
844 if (!(parm instanceof RadioChoiceParameter))
846 choicebox.setSelectedItem(value);
851 valueField.setText(value);
854 lastVal = updateSliderFromValueField();
859 * Adds a panel to comp, containing a label and radio buttons for the choice
860 * of values of the given option. Returns a ButtonGroup whose members are
861 * the added radio buttons.
868 protected ButtonGroup addRadioButtons(OptionI option, Container comp)
870 ButtonGroup bg = new ButtonGroup();
871 JPanel radioPanel = new JPanel();
872 radioPanel.add(new JLabel(option.getDescription()));
874 String value = option.getValue();
876 for (String opt : option.getPossibleValues())
878 JRadioButton btn = new JRadioButton(opt);
879 btn.setActionCommand(opt);
880 boolean selected = opt.equals(value);
881 btn.setSelected(selected);
882 btn.addActionListener(this);
886 comp.add(radioPanel);
892 * Action depends on the type of the input parameter:
894 * <li>if a text input, returns the trimmed value</li>
895 * <li>if a choice list or radio button, returns the selected value</li>
896 * <li>if a value slider and input field, sets the value of the slider from
897 * the value in the text field, limiting it to any defined min-max
900 * Answers the (possibly modified) input value, as a String, Integer, Float
905 Object updateSliderFromValueField()
907 if (validator == null || isStringParameter)
909 if (isChoiceParameter)
911 if (parameter instanceof RadioChoiceParameter)
913 return buttonGroup.getSelection().getActionCommand();
917 return getSelectedValue(this.parameter,
918 choicebox.getSelectedIndex());
921 slider.setVisible(false);
922 return valueField.getText().trim();
925 if (validator.getMin() == null || validator.getMax() == null)
927 slider.setVisible(false);
930 valueField.setText(valueField.getText().trim());
933 * ensure not outside min-max range
934 * TODO: provide some visual indicator if limit reached
938 valueField.setBackground(Color.WHITE);
939 double d = Double.parseDouble(valueField.getText());
940 if (validator.getMin() != null
941 && validator.getMin().doubleValue() > d)
943 valueField.setText(formatNumber(validator.getMin()));
945 if (validator.getMax() != null
946 && validator.getMax().doubleValue() < d)
948 valueField.setText(formatNumber(validator.getMax()));
950 } catch (NumberFormatException e)
952 valueField.setBackground(Color.yellow);
955 if (isIntegerParameter)
960 iVal = Integer.valueOf(valueField.getText());
961 } catch (Exception e)
963 valueField.setBackground(Color.yellow);
964 return Integer.valueOf(0);
967 if (validator.getMin() != null && validator.getMax() != null)
969 slider.getModel().setRangeProperties(iVal, 1,
970 validator.getMin().intValue(),
971 validator.getMax().intValue() + 1, true);
975 slider.setVisible(false);
977 return Integer.valueOf(iVal);
979 if (isLogarithmicParameter)
984 double eValue = Double.valueOf(valueField.getText());
985 dVal = Math.log(eValue);
986 } catch (Exception e)
988 // shouldn't be possible here
989 valueField.setBackground(Color.yellow);
992 if (validator.getMin() != null && validator.getMax() != null)
994 double scaleMin = Math.log(validator.getMin().doubleValue())
996 double scaleMax = Math.log(validator.getMax().doubleValue())
998 slider.getModel().setRangeProperties(
999 (int) (sliderScaleFactor * dVal), 1,
1000 (int) scaleMin, 1 + (int) scaleMax, true);
1004 slider.setVisible(false);
1006 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);