- }
-
- Map<String, OptionBox> optSet = new Hashtable<String, OptionBox>();
-
- public class OptionBox extends JPanel implements ActionListener
- {
- JComboBox val = new JComboBox();
-
- JCheckBox enabled = new JCheckBox();
-
- Option option;
-
- public OptionBox(Option opt)
- {
- option = opt;
- setLayout(new BorderLayout());
- enabled.setSelected(opt.isRequired()); // TODO: lock required options
- enabled.setFont(new Font("Verdana", Font.PLAIN, 11));
- enabled.setText(opt.getName());
- enabled.setToolTipText(opt.getDescription());
- enabled.addActionListener(this);
- add(enabled, BorderLayout.NORTH);
- if (opt.getPossibleValues().size() > 1)
- {
- setLayout(new GridLayout(1, 2));
- for (Object str : opt.getPossibleValues())
- {
- val.addItem((String) str);
- }
- val.setSelectedItem((String) opt.getDefaultValue());
- val.addActionListener(this);
- add(val, BorderLayout.SOUTH);
- }
- // TODO: add actionListeners for popup (to open further info),
- // and to update list of parameters if an option is enabled
- // that takes a value.
- setInitialValue();
- }
-
- public void resetToDefault()
- {
- enabled.setSelected(false);
- if (option.isRequired())
- {
- // Apply default value
- selectOption(option, option.getDefaultValue());
- }
- }
-
- boolean initEnabled = false;
-
- String initVal = null;
-
- public void setInitialValue()
- {
- initEnabled = enabled.isSelected();
- if (option.getPossibleValues() != null
- && option.getPossibleValues().size() > 1)
- {
- initVal = (String) val.getSelectedItem();
- }
- else
- {
- initVal = null;
- }
- }
-
- public Option getOptionIfEnabled()
- {
- if (!enabled.isSelected())
- {
- return null;
- }
- try
- {
- if (val.getSelectedItem() != null)
- {
- option.setDefaultValue((String) val.getSelectedItem());
- }
- } catch (WrongParameterException e)
- {
- e.printStackTrace();
- return null;
- }
- return option;
- }
-
- public void actionPerformed(ActionEvent e)
- {
- if (e.getSource() != enabled)
- {
- enabled.setSelected(true);
- }
- checkIfModified();
- }
-
- private void checkIfModified()
- {
- boolean notmod = (initEnabled == enabled.isSelected());
- if (enabled.isSelected() && initVal != null)
- {
- notmod |= initVal.equals(val.getSelectedItem());
- }
- argSetModified(this, !notmod);
- }
- }
-
- private OptionBox addOption(Option opt)
- {
- OptionBox cb = optSet.get(opt.getName());
- if (cb == null)
- {
- cb = new OptionBox(opt);
- optSet.put(opt.getName(), cb);
- jobOptions.add(cb);
- }
- return cb;
- }
-
- protected void refreshParamLayout()
- {
- int s = 100;
- for (ParamBox pbox : paramSet.values())
- {
- s += pbox.getBoxHeight();
- }
- paramList.setPreferredSize(new Dimension(PARAM_WIDTH, s));
- paramList.setLayout(new FlowLayout());
- validate();