import static jalview.ws.params.simple.LogarithmicParameter.LOGSLIDERSCALE;
+import jalview.bin.Cache;
import jalview.util.MessageManager;
import jalview.ws.params.ArgumentI;
import jalview.ws.params.OptionI;
import jalview.ws.params.ValueConstrainI;
import jalview.ws.params.ValueConstrainI.ValueType;
import jalview.ws.params.simple.LogarithmicParameter;
+import jalview.ws.params.simple.StringParameter;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
+import java.awt.FlowLayout;
import java.awt.Font;
-import java.awt.GridLayout;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public OptionBox(OptionI opt)
{
option = opt;
- setLayout(new BorderLayout());
+ setLayout(new FlowLayout(FlowLayout.LEFT));
enabled.setSelected(opt.isRequired()); // TODO: lock required options
- // enabled.setEnabled(!opt.isRequired());
enabled.setFont(new Font("Verdana", Font.PLAIN, 11));
enabled.setText("");
enabled.setText(opt.getName());
JvSwingUtils.wrapTooltip(true, opt.getDescription()));
}
}
- add(enabled, BorderLayout.NORTH);
+ add(enabled);
for (String str : opt.getPossibleValues())
{
val.addItem(str);
}
val.setSelectedItem(opt.getValue());
- if (opt.getPossibleValues().size() > 1)
+ if (opt.getPossibleValues().size() > 1 || opt.isRequired())
{
- setLayout(new GridLayout(1, 2));
val.addActionListener(this);
- add(val, BorderLayout.SOUTH);
+ add(val);
}
// TODO: add actionListeners for popup (to open further info),
// and to update list of parameters if an option is enabled
@Override
public void mouseEntered(MouseEvent e)
{
- // TODO Auto-generated method stub
-
}
@Override
public void mouseExited(MouseEvent e)
{
- // TODO Auto-generated method stub
-
}
@Override
}
}
+ /**
+ * toString representation for identification in the debugger only
+ */
+ @Override
+ public String toString()
+ {
+ return option == null ? super.toString() : option.toString();
+ }
+
}
/**
{
private static final float SLIDERSCALE = 1000f;
- boolean isLogarithmic;
+ boolean isLogarithmicParameter;
+
+ boolean isChoiceParameter;
- boolean adjusting = false;
+ boolean isIntegerParameter;
- boolean choice = false;
+ boolean adjusting;
JComboBox<String> choicebox;
- JPanel controlPanel = new JPanel();
+ JPanel controlsPanel = new JPanel();
- boolean descisvisible = false;
+ boolean descriptionIsVisible = false;
JScrollPane descPanel = new JScrollPane();
final URL finfo;
- boolean integ = false;
-
Object lastVal;
ParameterI parameter;
JPanel settingPanel = new JPanel();
- JButton showDesc = new JButton();
+ JSlider slider;
- JSlider slider = null;
+ JTextArea descriptionText = new JTextArea();
- JTextArea string = new JTextArea();
+ ValueConstrainI validator;
- ValueConstrainI validator = null;
+ JTextField valueField;
- JTextField valueField = null;
+ private String descTooltip;
- public ParamBox(final OptsParametersContainerI pmlayout,
+ public ParamBox(final OptsParametersContainerI paramContainer,
ParameterI parm)
{
- pmdialogbox = pmlayout;
+ pmdialogbox = paramContainer;
finfo = parm.getFurtherDetails();
validator = parm.getValidValue();
parameter = parm;
if (validator != null)
{
- integ = validator.getType() == ValueType.Integer;
+ isIntegerParameter = validator.getType() == ValueType.Integer;
}
- else
+ else if (parameter.getPossibleValues() != null)
{
- if (parameter.getPossibleValues() != null)
- {
- choice = true;
- }
+ isChoiceParameter = true;
}
if (parm instanceof LogarithmicParameter)
{
- isLogarithmic = true;
+ isLogarithmicParameter = true;
}
- if (!compact)
+ if (compact)
{
- makeExpanderParam(parm);
+ addCompactParameter(parm);
}
else
{
- makeCompactParam(parm);
-
+ addExpandableParam(parm);
}
}
- private void makeCompactParam(ParameterI parm)
+ /**
+ * Adds a 'compact' format parameter, with any help text shown as a tooltip
+ *
+ * @param parm
+ */
+ private void addCompactParameter(ParameterI parm)
{
setLayout(new MigLayout("", "[][grow]"));
-
String ttipText = null;
- controlPanel.setLayout(new BorderLayout());
+ controlsPanel.setLayout(new BorderLayout());
if (parm.getDescription() != null
&& parm.getDescription().trim().length() > 0)
{
- // Only create description boxes if there actually is a description.
ttipText = (JvSwingUtils.wrapTooltip(true,
parm.getDescription() + (finfo != null ? "<br><img src=\""
+ linkImageURL + "\"/>"
: "")));
}
- JvSwingUtils.mgAddtoLayout(this, ttipText, new JLabel(parm.getName()),
- controlPanel, "");
+ JvSwingUtils.addtoLayout(this, ttipText, new JLabel(parm.getName()),
+ controlsPanel, "");
updateControls(parm);
validate();
}
- private void makeExpanderParam(ParameterI parm)
+ /**
+ * Adds an 'expanded' format parameter, with any help shown in a panel that
+ * may be shown or hidden
+ *
+ * @param parm
+ */
+ private void addExpandableParam(ParameterI parm)
{
setPreferredSize(new Dimension(PARAM_WIDTH, PARAM_CLOSEDHEIGHT));
setBorder(new TitledBorder(parm.getName()));
setLayout(null);
- showDesc.setFont(new Font("Verdana", Font.PLAIN, 6));
- showDesc.setText("+");
- string.setFont(new Font("Verdana", Font.PLAIN, 11));
- string.setBackground(getBackground());
+ descriptionText.setFont(new Font("Verdana", Font.PLAIN, 11));
+ descriptionText.setBackground(getBackground());
- string.setEditable(false);
- descPanel.getViewport().setView(string);
+ descriptionText.setEditable(false);
+ descPanel.getViewport().setView(descriptionText);
descPanel.setVisible(false);
JPanel firstrow = new JPanel();
firstrow.setLayout(null);
- controlPanel.setLayout(new BorderLayout());
- controlPanel.setBounds(new Rectangle(39, 10, PARAM_WIDTH - 70,
+ controlsPanel.setLayout(new BorderLayout());
+ controlsPanel.setBounds(new Rectangle(39, 10, PARAM_WIDTH - 70,
PARAM_CLOSEDHEIGHT - 50));
- firstrow.add(controlPanel);
+ firstrow.add(controlsPanel);
firstrow.setBounds(new Rectangle(10, 20, PARAM_WIDTH - 30,
PARAM_CLOSEDHEIGHT - 30));
- final ParamBox me = this;
-
if (parm.getDescription() != null
&& parm.getDescription().trim().length() > 0)
{
- // Only create description boxes if there actually is a description.
- if (finfo != null)
- {
- showDesc.setToolTipText(JvSwingUtils.wrapTooltip(true,
- MessageManager.formatMessage(
- "label.opt_and_params_show_brief_desc_image_link",
- new String[]
- { linkImageURL.toExternalForm() })));
- showDesc.addMouseListener(this);
- }
- else
- {
- showDesc.setToolTipText(
- JvSwingUtils.wrapTooltip(true, MessageManager.getString(
- "label.opt_and_params_show_brief_desc")));
- }
- showDesc.addActionListener(new ActionListener()
- {
-
- @Override
- public void actionPerformed(ActionEvent e)
- {
- descisvisible = !descisvisible;
- descPanel.setVisible(descisvisible);
- descPanel.getVerticalScrollBar().setValue(0);
- me.setPreferredSize(new Dimension(PARAM_WIDTH,
- (descisvisible) ? PARAM_HEIGHT : PARAM_CLOSEDHEIGHT));
- me.validate();
- pmdialogbox.refreshParamLayout();
- }
- });
- string.setWrapStyleWord(true);
- string.setLineWrap(true);
- string.setColumns(32);
- string.setText(parm.getDescription());
- showDesc.setBounds(new Rectangle(10, 10, 16, 16));
- firstrow.add(showDesc);
+ addExpandableHelp(firstrow, parm);
}
add(firstrow);
validator = parm.getValidValue();
parameter = parm;
if (validator != null)
{
- integ = validator.getType() == ValueType.Integer;
+ isIntegerParameter = validator.getType() == ValueType.Integer;
}
else
{
if (parameter.getPossibleValues() != null)
{
- choice = true;
+ isChoiceParameter = true;
}
}
updateControls(parm);
validate();
}
+ /**
+ * Adds a button which can be clicked to show or hide help text
+ *
+ * @param container
+ * @param param
+ */
+ protected void addExpandableHelp(JPanel container, ParameterI param)
+ {
+ JButton showDescBtn = new JButton("+");
+ showDescBtn.setFont(new Font("Verdana", Font.PLAIN, 8));
+ if (finfo != null)
+ {
+ descTooltip = JvSwingUtils.wrapTooltip(true,
+ MessageManager.formatMessage(
+ "label.opt_and_params_show_brief_desc_image_link",
+ new String[]
+ { linkImageURL.toExternalForm() }));
+ showDescBtn.addMouseListener(this);
+ }
+ else
+ {
+ descTooltip = JvSwingUtils.wrapTooltip(true, MessageManager
+ .getString("label.opt_and_params_show_brief_desc"));
+ }
+ showDescBtn.setToolTipText(descTooltip);
+ showDescBtn.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ descriptionIsVisible = !descriptionIsVisible;
+ showDescBtn.setText(descriptionIsVisible ? "-" : "+");
+ showDescBtn.setToolTipText(
+ descriptionIsVisible ? null : descTooltip);
+ descPanel.setVisible(descriptionIsVisible);
+ descPanel.getVerticalScrollBar().setValue(0);
+ ParamBox.this.setPreferredSize(new Dimension(PARAM_WIDTH,
+ (descriptionIsVisible) ? PARAM_HEIGHT
+ : PARAM_CLOSEDHEIGHT));
+ ParamBox.this.validate();
+ pmdialogbox.refreshParamLayout();
+ }
+ });
+ descriptionText.setWrapStyleWord(true);
+ descriptionText.setLineWrap(true);
+ descriptionText.setColumns(32);
+ descriptionText.setText(param.getDescription());
+ showDescBtn.setBounds(new Rectangle(10, 10, 16, 16));
+ container.add(showDescBtn);
+ }
+
@Override
public void actionPerformed(ActionEvent e)
{
{
return;
}
- if (!choice)
+ if (!isChoiceParameter)
{
updateSliderFromValueField();
}
checkIfModified();
}
+ /**
+ * Checks whether the value of this parameter has been changed and notifies
+ * the parent page accordingly
+ */
private void checkIfModified()
{
- Object cstate = updateSliderFromValueField();
- boolean notmod = false;
- if (cstate.getClass() == lastVal.getClass())
+ Object newValue = updateSliderFromValueField();
+ boolean modified = true;
+ if (newValue.getClass() == lastVal.getClass())
{
- if (cstate instanceof int[])
- {
- notmod = (((int[]) cstate)[0] == ((int[]) lastVal)[0]);
- }
- else if (cstate instanceof float[])
- {
- notmod = (((float[]) cstate)[0] == ((float[]) lastVal)[0]);
- }
- else if (cstate instanceof String[])
- {
- notmod = (((String[]) cstate)[0].equals(((String[]) lastVal)[0]));
- }
+ modified = !newValue.equals(lastVal);
}
- pmdialogbox.argSetModified(this, !notmod);
+ pmdialogbox.argSetModified(this, modified);
}
@Override
return Component.BaselineResizeBehavior.CONSTANT_ASCENT;
}
- public int getBoxHeight()
- {
- return (descisvisible ? PARAM_HEIGHT : PARAM_CLOSEDHEIGHT);
- }
-
public ParameterI getParameter()
{
ParameterI prm = parameter.copy();
- if (choice)
+ if (isChoiceParameter)
{
prm.setValue((String) choicebox.getSelectedItem());
}
{
if (!adjusting)
{
- if (!isLogarithmic)
+ if (!isLogarithmicParameter)
{
/*
* set (int or float formatted) text field value
*/
- valueField.setText(integ ? String.valueOf(slider.getValue())
+ valueField.setText(isIntegerParameter ? String.valueOf(slider.getValue())
: String.valueOf(slider.getValue() / SLIDERSCALE));
}
else
* @param value
* @return
*/
- public String formatDouble(double value)
+ String formatDouble(double value)
{
String format = value < 0.001 ? "%3.3e" : "%3.3f";
return String.format(format, value);
}
- public void updateControls(ParameterI parm)
+ void updateControls(ParameterI parm)
{
adjusting = true;
boolean init = (choicebox == null && valueField == null);
if (init)
{
- if (choice)
+ if (isChoiceParameter)
{
choicebox = new JComboBox<>();
choicebox.addActionListener(this);
- controlPanel.add(choicebox, BorderLayout.CENTER);
+ controlsPanel.add(choicebox, BorderLayout.CENTER);
}
else
{
slider = new JSlider();
slider.addChangeListener(this);
- valueField = new JTextField();
+ int cols = parm instanceof StringParameter ? 20 : 0;
+ valueField = new JTextField(cols);
valueField.addActionListener(this);
valueField.addKeyListener(new KeyAdapter()
{
}
}
});
- valueField.setPreferredSize(new Dimension(80, 25));
- controlPanel.add(slider, BorderLayout.WEST);
- controlPanel.add(valueField, BorderLayout.EAST);
+ valueField.setPreferredSize(new Dimension(60, 25));
+ controlsPanel.add(slider, BorderLayout.WEST);
+ controlsPanel.add(valueField, BorderLayout.EAST);
}
}
if (parm != null)
{
- if (choice)
+ if (isChoiceParameter)
{
if (init)
{
adjusting = false;
}
- public Object updateSliderFromValueField()
+ /**
+ * Action depends on the type of the input parameter:
+ * <ul>
+ * <li>if a text input, returns the trimmed value</li>
+ * <li>if a choice list, returns the selected value</li>
+ * <li>if a value slider and input field, sets the value of the slider from
+ * the value in the text field, limiting it to any defined min-max
+ * range.</li>
+ * </ul>
+ * Answers the (possibly modified) input value, as a String, Integer, Float
+ * or Double.
+ *
+ * @return
+ */
+ Object updateSliderFromValueField()
{
- int iVal;
- float fVal;
- double dVal;
- if (validator != null)
+ if (validator == null)
{
- if (integ)
+ if (!isChoiceParameter)
{
- iVal = 0;
- try
- {
- valueField.setText(valueField.getText().trim());
- iVal = Integer.valueOf(valueField.getText());
- if (validator.getMin() != null
- && validator.getMin().intValue() > iVal)
- {
- iVal = validator.getMin().intValue();
- // TODO: provide visual indication that hard limit was reached for
- // this parameter
- }
- if (validator.getMax() != null
- && validator.getMax().intValue() < iVal)
- {
- iVal = validator.getMax().intValue();
- // TODO: provide visual indication that hard limit was reached for
- // this parameter
- }
- } catch (Exception e)
- {
- System.err.println(e.getMessage());
- }
- // update value field to reflect any bound checking we performed.
- valueField.setText("" + iVal);
- if (validator.getMin() != null && validator.getMax() != null)
+ slider.setVisible(false);
+ return valueField.getText().trim();
+ }
+ else
+ {
+ return choicebox.getSelectedItem();
+ }
+ }
+ if (isIntegerParameter)
+ {
+ int iVal = 0;
+ try
+ {
+ valueField.setText(valueField.getText().trim());
+ iVal = Integer.valueOf(valueField.getText());
+
+ /*
+ * ensure not outside min-max range
+ * TODO: provide some visual indicator if limit reached
+ */
+ if (validator.getMin() != null
+ && validator.getMin().intValue() > iVal)
{
- slider.getModel().setRangeProperties(iVal, 1,
- validator.getMin().intValue(),
- validator.getMax().intValue() + 1, true);
+ iVal = validator.getMin().intValue();
+ valueField.setText(String.valueOf(iVal));
}
- else
+ if (validator.getMax() != null
+ && validator.getMax().intValue() < iVal)
{
- slider.setVisible(false);
+ iVal = validator.getMax().intValue();
+ valueField.setText(String.valueOf(iVal));
}
- return new int[] { iVal };
- }
- else if (isLogarithmic)
+ } catch (Exception e)
{
- dVal = 0d;
- try
- {
- valueField.setText(valueField.getText().trim());
- double eValue = Double.valueOf(valueField.getText());
+ Cache.log.error(e.getMessage());
+ }
- dVal = Math.log(eValue) / Math
- .log(((LogarithmicParameter) parameter).getBase())
- * LOGSLIDERSCALE;
+ if (validator.getMin() != null && validator.getMax() != null)
+ {
+ slider.getModel().setRangeProperties(iVal, 1,
+ validator.getMin().intValue(),
+ validator.getMax().intValue() + 1, true);
+ }
+ else
+ {
+ slider.setVisible(false);
+ }
+ return new Integer(iVal);
+ }
+ else if (isLogarithmicParameter)
+ {
+ double dVal = 0d;
+ try
+ {
+ valueField.setText(valueField.getText().trim());
+ double eValue = Double.valueOf(valueField.getText());
- if (validator.getMin() != null
- && validator.getMin().doubleValue() > dVal)
- {
- dVal = validator.getMin().doubleValue();
- // TODO: provide visual indication that hard limit was reached for
- // this parameter
- // update value field to reflect any bound checking we performed.
- valueField.setText(formatDouble(eValue));
- }
- if (validator.getMax() != null
- && validator.getMax().doubleValue() < dVal)
- {
- dVal = validator.getMax().doubleValue();
- // TODO: provide visual indication that hard limit was reached for
- // this parameter
- // update value field to reflect any bound checking we performed.
- valueField.setText(formatDouble(eValue));
- }
- } catch (Exception e)
- {
- }
+ dVal = Math.log(eValue)
+ / Math.log(((LogarithmicParameter) parameter).getBase())
+ * LOGSLIDERSCALE;
- if (validator.getMin() != null && validator.getMax() != null)
+ /*
+ * ensure not outside min-max range
+ * TODO: provide some visual indicator if limit reached
+ */
+ if (validator.getMin() != null
+ && validator.getMin().doubleValue() > dVal)
{
- slider.getModel().setRangeProperties((int) (dVal), 1,
- (int) (validator.getMin().doubleValue()),
- 1 + (int) (validator.getMax().doubleValue()),
- true);
+ dVal = validator.getMin().doubleValue();
+ valueField.setText(formatDouble(eValue));
}
- else
+ if (validator.getMax() != null
+ && validator.getMax().doubleValue() < dVal)
{
- slider.setVisible(false);
+ dVal = validator.getMax().doubleValue();
+ valueField.setText(formatDouble(eValue));
}
- return new double[] { dVal };
+ } catch (Exception e)
+ {
+ }
+
+ if (validator.getMin() != null && validator.getMax() != null)
+ {
+ slider.getModel().setRangeProperties((int) (dVal), 1,
+ (int) (validator.getMin().doubleValue()),
+ 1 + (int) (validator.getMax().doubleValue()), true);
}
else
{
- fVal = 0f;
- try
- {
- valueField.setText(valueField.getText().trim());
- fVal = Float.valueOf(valueField.getText());
- if (validator.getMin() != null
- && validator.getMin().floatValue() > fVal)
- {
- fVal = validator.getMin().floatValue();
- // TODO: provide visual indication that hard limit was reached for
- // this parameter
- // update value field to reflect any bound checking we performed.
- valueField.setText("" + fVal);
- }
- if (validator.getMax() != null
- && validator.getMax().floatValue() < fVal)
- {
- fVal = validator.getMax().floatValue();
- // TODO: provide visual indication that hard limit was reached for
- // this parameter
- // update value field to reflect any bound checking we performed.
- valueField.setText("" + fVal);
- }
- } catch (Exception e)
- {
- }
+ slider.setVisible(false);
+ }
+ return new Double(dVal);
+ }
+ else
+ {
+ float fVal = 0f;
+ try
+ {
+ valueField.setText(valueField.getText().trim());
+ fVal = Float.valueOf(valueField.getText());
- if (validator.getMin() != null && validator.getMax() != null)
+ /*
+ * ensure not outside min-max range
+ * TODO: provide some visual indicator if limit reached
+ */
+ if (validator.getMin() != null
+ && validator.getMin().floatValue() > fVal)
{
- slider.getModel().setRangeProperties((int) (fVal * SLIDERSCALE), 1,
- (int) (validator.getMin().floatValue() * SLIDERSCALE),
- 1 + (int) (validator.getMax().floatValue() * SLIDERSCALE),
- true);
+ fVal = validator.getMin().floatValue();
+ valueField.setText(String.valueOf(fVal));
}
- else
+ if (validator.getMax() != null
+ && validator.getMax().floatValue() < fVal)
{
- slider.setVisible(false);
+ fVal = validator.getMax().floatValue();
+ valueField.setText(String.valueOf(fVal));
}
- return new float[] { fVal };
+ } catch (Exception e)
+ {
}
- }
- else
- {
- if (!choice)
+
+ if (validator.getMin() != null && validator.getMax() != null)
{
- slider.setVisible(false);
- return new String[] { valueField.getText().trim() };
+ slider.getModel().setRangeProperties((int) (fVal * SLIDERSCALE),
+ 1, (int) (validator.getMin().floatValue() * SLIDERSCALE),
+ 1 + (int) (validator.getMax().floatValue() * SLIDERSCALE),
+ true);
}
else
{
- return new String[] { (String) choicebox.getSelectedItem() };
+ slider.setVisible(false);
}
+ return new Float(fVal);
}
-
}
}
- public OptsAndParamsPage(OptsParametersContainerI paramContainer)
- {
- this(paramContainer, false);
- }
-
+ /**
+ * Constructor with the option to show 'compact' format (parameter description
+ * as tooltip) or 'expanded' format (parameter description in a textbox which
+ * may be opened or closed). Use compact for simple description text, expanded
+ * for more wordy or formatted text.
+ *
+ * @param paramContainer
+ */
public OptsAndParamsPage(OptsParametersContainerI paramContainer,
boolean compact)
{
return argSet;
}
-
}
import java.awt.event.ItemListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
-import java.net.URL;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
-import javax.swing.JSplitPane;
import javax.swing.JTextArea;
import javax.swing.border.TitledBorder;
import javax.swing.event.DocumentEvent;
import compbio.metadata.Parameter;
import compbio.metadata.Preset;
import compbio.metadata.PresetManager;
-import compbio.metadata.RunnerConfig;
import net.miginfocom.swing.MigLayout;
/**
private static final int DEFAULT_HEIGHT = 640;
- URL linkImageURL = getClass().getResource("/images/link.gif");
+ // the default parameter set shown to the user
+ private static final String SVC_DEF = "Defaults";
- private static final String SVC_DEF = "Defaults"; // this is the null
- // parameter set as shown to
- // user
+ private int maxOptWidth = 200;
- /**
- * manager for options and parameters.
+ // URL linkImageURL = getClass().getResource("/images/link.gif");
+
+ /*
+ * controller for options and parameters layout
*/
- OptsAndParamsPage opanp = new OptsAndParamsPage(this);
+ OptsAndParamsPage opanp;
- /**
+ /*
* panel containing job options
*/
- JPanel jobOptions = new JPanel();
+ JPanel optionsPanel = new JPanel();
- /**
+ /*
* panel containing job parameters
*/
- JPanel paramList = new JPanel();
-
- JPanel SetNamePanel = new JPanel();
-
- JPanel setDetails = new JPanel();
-
- JSplitPane settingsPanel = new JSplitPane();
-
- JPanel jobPanel = new JPanel();
+ JPanel paramsPanel = new JPanel();
- JScrollPane jobOptionsPane = new JScrollPane();
+ JPanel setNamePanel = new JPanel();
JButton createpref = new JButton();
JButton updatepref = new JButton();
- JButton startjob = new JButton();
-
- JButton canceljob = new JButton();
-
- JComboBox setName = new JComboBox();
+ JComboBox<String> setName = new JComboBox<>();
JTextArea setDescr = new JTextArea();
JScrollPane paramPane = new JScrollPane();
- // ScrollablePanel optsAndparams = new ScrollablePanel();
- JPanel optsAndparams = new JPanel();
+ ParamDatastoreI paramStore;
- RunnerConfig serviceOptions;
+ // set true when 'Start Job' is clicked
+ boolean startJob = false;
- ParamDatastoreI paramStore;
+ JDialog frame = null;
- private int MAX_OPTWIDTH = 200;
+ Jws2Instance service;
- WsJobParameters(Jws2Instance service)
- {
- this(service, null);
- }
+ /*
+ * list of service presets in the gui
+ */
+ Hashtable<String, String> servicePresets = null;
+
+ /*
+ * set if dialog is being set - so handlers will avoid spurious events
+ */
+ boolean settingDialog = false;
+
+ private Hashtable<Object, Object> modifiedElements = new Hashtable<>();
+
+ String lastParmSet = null;
public WsJobParameters(ParamDatastoreI store, WsParamSetI preset,
List<ArgumentI> args)
{
super();
+
+ // parameters dialog in 'compact' format (help as tooltips)
+ opanp = new OptsAndParamsPage(this, true);
jbInit();
this.paramStore = store;
this.service = null;
- // argSetModified(false);
- // populate parameter table
init(preset, args);
- // display in new JFrame attached to parent.
validate();
}
- public WsJobParameters(Jws2Instance service, WsParamSetI preset)
- {
- this(service, preset, null);
- }
-
- /**
- *
- * @param service
- * @param preset
- */
- public WsJobParameters(Jws2Instance service,
- WsParamSetI preset, List<Argument> jobArgset)
- {
- this(null, service, preset, jobArgset);
- }
-
/**
+ * Constructor given a set of parameters and presets, a service to be invoked,
+ * and a list of (Jabaws client) arguments
*
* @param paramStorei
* @param service
WsParamSetI preset, List<Argument> jobArgset)
{
super();
+
+ // parameters dialog in 'expanded' format (help text boxes)
+ opanp = new OptsAndParamsPage(this, false);
+
jbInit();
this.paramStore = paramStorei;
if (paramStore == null && service != null)
paramStore = service.getParamStore();
}
this.service = service;
- // argSetModified(false);
- // populate parameter table
initForService(preset, jobArgset);
- // display in new JFrame attached to parent.
validate();
}
- int response = -1;
-
- JDialog frame = null;
-
/**
- * shows a modal dialog containing the parameters.
+ * Shows a modal dialog containing the parameters and Start or Cancel options.
+ * Answers true if the job is started, false if cancelled.
*
* @return
*/
});
frame.setVisible(true);
- if (response > 0)
- {
- return true;
- }
- return false;
+ return startJob;
}
private void jbInit()
@Override
public void actionPerformed(ActionEvent e)
{
- update_actionPerformed(e);
+ update_actionPerformed();
}
});
deletepref = JvSwingUtils.makeButton(
@Override
public void actionPerformed(ActionEvent e)
{
- delete_actionPerformed(e);
+ delete_actionPerformed();
}
});
createpref = JvSwingUtils.makeButton(
@Override
public void actionPerformed(ActionEvent e)
{
- create_actionPerformed(e);
+ create_actionPerformed();
}
});
revertpref = JvSwingUtils.makeButton(
@Override
public void actionPerformed(ActionEvent e)
{
- revert_actionPerformed(e);
+ revert_actionPerformed();
}
});
- startjob = JvSwingUtils.makeButton(
+
+ JButton startjob = JvSwingUtils.makeButton(
MessageManager.getString("action.start_job"),
MessageManager.getString("label.start_job_current_settings"),
new ActionListener()
@Override
public void actionPerformed(ActionEvent e)
{
- startjob_actionPerformed(e);
+ startjob_actionPerformed();
}
});
- canceljob = JvSwingUtils.makeButton(
+ JButton canceljob = JvSwingUtils.makeButton(
MessageManager.getString("action.cancel_job"),
MessageManager.getString("label.cancel_job_close_dialog"),
new ActionListener()
@Override
public void actionPerformed(ActionEvent e)
{
- canceljob_actionPerformed(e);
+ canceljob_actionPerformed();
}
});
+ JPanel setDetails = new JPanel();
setDetails.setBorder(
new TitledBorder(MessageManager.getString("label.details")));
setDetails.setLayout(new BorderLayout());
setName.getEditor().addActionListener(this);
JPanel setNameInfo = new JPanel(new FlowLayout(FlowLayout.LEFT));
GridBagLayout gbl = new GridBagLayout();
- SetNamePanel.setLayout(gbl);
+ setNamePanel.setLayout(gbl);
JLabel setNameLabel = new JLabel(
MessageManager.getString("label.current_parameter_set_name"));
revertpref.setVisible(false);
createpref.setVisible(false);
JPanel setsavebuts = new JPanel();
- setsavebuts.setLayout(new FlowLayout(FlowLayout.LEFT)); // GridLayout(1,2));
- ((FlowLayout) setsavebuts.getLayout()).setHgap(10);
- ((FlowLayout) setsavebuts.getLayout()).setVgap(0);
+ setsavebuts.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 0)); // GridLayout(1,2));
JPanel spacer = new JPanel();
spacer.setPreferredSize(new Dimension(2, 30));
setsavebuts.add(spacer);
// setsavebuts.setSize(new Dimension(150, 30));
JPanel buttonArea = new JPanel(new GridLayout(1, 1));
buttonArea.add(setsavebuts);
- SetNamePanel.add(setNameInfo);
+ setNamePanel.add(setNameInfo);
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridheight = 2;
gbl.setConstraints(setNameInfo, gbc);
- SetNamePanel.add(buttonArea);
+ setNamePanel.add(buttonArea);
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 2;
// paramPane.setPreferredSize(new Dimension(360, 400));
// paramPane.setPreferredSize(null);
- jobOptions.setBorder(
+ optionsPanel.setBorder(
new TitledBorder(MessageManager.getString("label.options")));
- jobOptions.setOpaque(true);
- paramList.setBorder(
+ optionsPanel.setOpaque(true);
+ paramsPanel.setBorder(
new TitledBorder(MessageManager.getString("label.parameters")));
- paramList.setOpaque(true);
- JPanel bjo = new JPanel(new BorderLayout());
- JPanel bjp = new JPanel(new BorderLayout());
- bjo.add(jobOptions, BorderLayout.CENTER);
- bjp.add(paramList, BorderLayout.CENTER);
- bjp.setOpaque(true);
- bjo.setOpaque(true);
+ paramsPanel.setOpaque(true);
// optsAndparams.setScrollableWidth(ScrollableSizeHint.FIT);
// optsAndparams.setScrollableHeight(ScrollableSizeHint.NONE);
// optsAndparams.setLayout(new BorderLayout());
+ JPanel optsAndparams = new JPanel();
optsAndparams.setLayout(new BorderLayout());
- optsAndparams.add(jobOptions, BorderLayout.NORTH);
- optsAndparams.add(paramList, BorderLayout.CENTER);
+ optsAndparams.add(optionsPanel, BorderLayout.NORTH);
+ optsAndparams.add(paramsPanel, BorderLayout.CENTER);
JPanel jp = new JPanel(new BorderLayout());
jp.add(optsAndparams, BorderLayout.CENTER);
paramPane.getViewport().setView(jp);
paramPane.setBorder(null);
setLayout(new BorderLayout());
+
+ JPanel jobPanel = new JPanel();
jobPanel.setPreferredSize(null);
jobPanel.setLayout(new BorderLayout());
jobPanel.add(setDetails, BorderLayout.NORTH);
jobPanel.add(paramPane, BorderLayout.CENTER);
// jobPanel.setOrientation(JSplitPane.VERTICAL_SPLIT);
- add(SetNamePanel, BorderLayout.NORTH);
+ add(setNamePanel, BorderLayout.NORTH);
add(jobPanel, BorderLayout.CENTER);
JPanel dialogpanel = new JPanel();
validate();
}
- protected void revert_actionPerformed(ActionEvent e)
+ protected void revert_actionPerformed()
{
reInitDialog(lastParmSet);
updateWebServiceMenus();
}
- protected void update_actionPerformed(ActionEvent e)
+ protected void update_actionPerformed()
{
if (isUserPreset)
{
paramStore.deletePreset(lastParmSet2);
}
- protected void delete_actionPerformed(ActionEvent e)
+ protected void delete_actionPerformed()
{
if (isUserPreset)
{
updateWebServiceMenus();
}
- protected void create_actionPerformed(ActionEvent e)
+ protected void create_actionPerformed()
{
String curname = ((String) setName.getSelectedItem()).trim();
if (curname.length() > 0)
}
}
- protected void canceljob_actionPerformed(ActionEvent e)
+ protected void canceljob_actionPerformed()
{
- response = 0;
+ startJob = false;
if (frame != null)
{
frame.setVisible(false);
}
}
- protected void startjob_actionPerformed(ActionEvent e)
+ protected void startjob_actionPerformed()
{
- response = 1;
+ startJob = true;
if (frame != null)
{
frame.setVisible(false);
}
}
- Jws2Instance service;
-
- /**
- * list of service presets in the gui
- */
- Hashtable servicePresets = null;
-
- /**
- * set if dialog is being set - so handlers will avoid spurious events
- */
- boolean settingDialog = false;
-
void initForService(WsParamSetI jabap, List<Argument> jabajobArgset)
{
WsParamSetI p = null;
void init(WsParamSetI p, List<ArgumentI> jobArgset)
{
- Hashtable exnames = new Hashtable();
+ Hashtable<String, String> exnames = new Hashtable<>();
for (int i = 0, iSize = setName.getItemCount(); i < iSize; i++)
{
exnames.put(setName.getItemAt(i), setName.getItemAt(i));
}
- servicePresets = new Hashtable();
+ servicePresets = new Hashtable<>();
// Add the default entry - if not present already.
if (!exnames.contains(SVC_DEF))
{
exnames.put(SVC_DEF, SVC_DEF);
servicePresets.put(SVC_DEF, SVC_DEF);
}
- String curname = (p == null ? "" : p.getName());
+
+ // String curname = (p == null ? "" : p.getName());
for (WsParamSetI pr : paramStore.getPresets())
{
if (!pr.isModifiable())
OptionI opt = (OptionI) myarg;
OptionBox ob = opanp.addOption(opt);
ob.resetToDefault(setDefaultParams);
- if (MAX_OPTWIDTH < ob.getPreferredSize().width)
+ if (maxOptWidth < ob.getPreferredSize().width)
{
- MAX_OPTWIDTH = ob.getPreferredSize().width;
+ maxOptWidth = ob.getPreferredSize().width;
}
ob.validate();
cw += ob.getPreferredSize().width + 5;
return modifiedElements.size() > 0;
}
- private Hashtable modifiedElements = new Hashtable();
-
/**
* reset gui and modification state settings
*/
if (b && modifiedElements.size() > 0)
{
makeSetNameValid(!isUserPreset);
- SetNamePanel.revalidate();
+ setNamePanel.revalidate();
}
updateButtonDisplay();
}
// sync the gui with the preset database
for (int i = 0, iS = setName.getItemCount(); i < iS; i++)
{
- String snm = (String) setName.getItemAt(i);
+ String snm = setName.getItemAt(i);
if (snm.equals(nm))
{
makeupdate = true;
@Override
public void refreshParamLayout()
{
- // optsAndparams.setPreferredSize(null);
- FlowLayout fl = new FlowLayout(FlowLayout.LEFT);
- int sep = fl.getVgap();
- boolean fh = true;
- int s = jobOptions.getBorder().getBorderInsets(jobOptions).bottom
- + jobOptions.getBorder().getBorderInsets(jobOptions).top
- + 2 * sep;
-
- int panewidth = paramPane.getViewport().getSize().width - 120
- - jobOptions.getBorder().getBorderInsets(jobOptions).left
- + jobOptions.getBorder().getBorderInsets(jobOptions).right;
-
- // int w = 2 * fl.getHgap()
- // + (MAX_OPTWIDTH > OptsAndParamsPage.PARAM_WIDTH ? MAX_OPTWIDTH
- // : OptsAndParamsPage.PARAM_WIDTH);
- int hgap = fl.getHgap();
- int cw = hgap;
+ final int rightMargin = 40;
+ final int availableWidth = paramPane.getViewport().getSize().width
+ - rightMargin
+ - optionsPanel.getBorder().getBorderInsets(optionsPanel).left
+ + optionsPanel.getBorder().getBorderInsets(optionsPanel).right;
if (opanp.getOptSet().size() > 0)
{
+ int hgap = 5;
+ int currentWidth = hgap;
- jobOptions.setLayout(new MigLayout("", "", ""));
- jobOptions.removeAll();
+ optionsPanel.setLayout(new MigLayout("nogrid", "", ""));
+ optionsPanel.removeAll();
+ JPanel lastAdded = null;
for (OptionBox pbox : opanp.getOptSet().values())
{
pbox.validate();
- cw += pbox.getSize().width + hgap;
- if (cw + 120 > panewidth)
- {
- jobOptions.add(pbox, "wrap");
- // System.out.println("Wrap on "+pbox.option.getName());
- cw = hgap + pbox.getSize().width;
- fh = true;
- }
- else
- {
- jobOptions.add(pbox);
- }
- if (fh)
+ int boxWidth = pbox.getSize().width;
+ currentWidth += boxWidth + hgap;
+ boolean wrapAfterLast = currentWidth > availableWidth
+ && lastAdded != null;
+ // System.out.println(String.format(
+ // "%s width=%d, paneWidth=%d, currentWidth=%d, wrapAfterLast=%s",
+ // pbox.toString(), boxWidth, panewidth, currentWidth,
+ // wrapAfterLast));
+ if (wrapAfterLast)
{
- // finalh += pbox.getSize().height + fl.getVgap();
- fh = false;
+ optionsPanel.remove(lastAdded);
+ optionsPanel.add(lastAdded, "wrap");
+ currentWidth = hgap + boxWidth;
}
+ optionsPanel.add(pbox);
+ lastAdded = pbox;
}
- jobOptions.revalidate();
+ optionsPanel.revalidate();
}
else
{
- jobOptions.setVisible(false);
+ optionsPanel.setVisible(false);
}
- // Now layout the parameters assuming they occupy one column - to calculate
- // total height of options+parameters
- fl = new FlowLayout(FlowLayout.LEFT);
- // helpful hint from
- // http://stackoverflow.com/questions/2743177/top-alignment-for-flowlayout
- fl.setAlignOnBaseline(true);
if (opanp.getParamSet().size() > 0)
{
- paramList.removeAll();
- paramList.setLayout(new MigLayout("", "", ""));
- fh = true;
+ paramsPanel.removeAll();
+ paramsPanel.setLayout(new MigLayout("", "", ""));
+ int hgap = 5;
+ int currentWidth = hgap;
+
+ JPanel lastAdded = null;
for (ParamBox pbox : opanp.getParamSet().values())
{
pbox.validate();
- cw += pbox.getSize().width + hgap;
- if (cw + 160 > panewidth)
- {
- paramList.add(pbox, "wrap");
- cw = pbox.getSize().width + hgap;
- fh = true;
- }
- else
- {
- paramList.add(pbox);
- }
- if (fh)
+ currentWidth += pbox.getSize().width + hgap;
+ if (currentWidth /*+ 160*/ > availableWidth && lastAdded != null)
{
- // finalh += pbox.getSize().height + fl.getVgap();
- fh = false;
+ paramsPanel.remove(lastAdded);
+ paramsPanel.add(lastAdded, "wrap");
+ currentWidth = pbox.getSize().width + hgap;
}
-
+ paramsPanel.add(pbox);
+ lastAdded = pbox;
}
+
/*
* s = 2 * sep; for (ParamBox pbox : opanp.getParamSet().values()) {
* pbox.validate(); s += sep +
* .getBorder().getBorderInsets(paramList).bottom+paramList
* .getBorder().getBorderInsets(paramList).top;
*/
- paramList.revalidate();
+ paramsPanel.revalidate();
}
else
{
- paramList.setVisible(false);
+ paramsPanel.setVisible(false);
}
// TODO: waste some time trying to eliminate any unnecessary .validate calls
// here
e.printStackTrace();
}
}
- WsJobParameters pgui = new WsJobParameters(lastserv,
- new JabaPreset(lastserv, pr));
+ WsJobParameters pgui = new WsJobParameters(null, lastserv,
+ new JabaPreset(lastserv, pr), null);
JFrame jf = new JFrame(MessageManager
.formatMessage("label.ws_parameters_for", new String[]
{ lastserv.getActionText() }));
return opanp.getCurrentSettings();
}
- String lastParmSet = null;
-
/*
* Hashtable<String, Object[]> editedParams = new Hashtable<String,
* Object[]>();
int n = 0;
// remove any set names in the drop down menu that aren't either a reserved
// setting, or a user defined or service preset.
- Vector items = new Vector();
+ Vector<String> items = new Vector<>();
while (n < setName.getItemCount())
{
- String item = (String) setName.getItemAt(n);
+ String item = setName.getItemAt(n);
if (!item.equals(SVC_DEF) && !paramStore.presetExists(item))
{
setName.removeItemAt(n);
initArgSetModified();
syncSetNamesWithStore();
setName.setSelectedItem(lastParmSet);
- SetNamePanel.validate();
+ setNamePanel.validate();
validate();
settingDialog = false;
}
@Override
public void itemStateChanged(ItemEvent e)
{
- if (e.getSource() == setName && e.getStateChange() == e.SELECTED)
+ if (e.getSource() == setName
+ && e.getStateChange() == ItemEvent.SELECTED)
{
final String setname = (String) setName.getSelectedItem();
// System.out.println("Item state changed for " + setname
import jalview.ws.jws2.dm.AAConSettings;
import jalview.ws.jws2.dm.JabaWsParamSet;
import jalview.ws.jws2.jabaws2.Jws2Instance;
+import jalview.ws.params.ParamDatastoreI;
import jalview.ws.params.WsParamSetI;
import jalview.ws.uimodel.AlignAnalysisUIText;
}
WsJobParameters jobParams = (preset == null && paramset != null
&& paramset.size() > 0)
- ? new WsJobParameters(sh, null, paramset)
- : new WsJobParameters(sh, preset);
+ ? new WsJobParameters((ParamDatastoreI) null, sh,
+ (WsParamSetI) null,
+ paramset)
+ : new WsJobParameters((ParamDatastoreI) null, sh,
+ preset,
+ (List<Argument>) null);
if (adjustingExisting)
{
jobParams.setName(MessageManager
}
if (!jobParams.showRunDialog())
{
- return false;
+ return false; // dialog cancelled
}
+
WsParamSetI prset = jobParams.getPreset();
if (prset == null)
{
*/
public class DoubleParameter extends Option implements ParameterI
{
- Double defval;
+ double defval;
- Double min, max;
+ double min;
+
+ double max;
@Override
public ValueConstrainI getValidValue()
{
return new ValueConstrainI()
{
-
@Override
public ValueType getType()
{
@Override
public Number getMin()
{
- if (min < max)
- {
- return min;
- }
- else
- {
- return null;
- }
+ return min < max ? min : null;
}
@Override
public Number getMax()
{
- if (min < max)
- {
- return max;
- }
- else
- {
- return null;
- }
+ return min < max ? max : null;
}
};
}
}
public DoubleParameter(String name, String description, boolean required,
- Double defValue, Double min, Double max)
+ Double defValue, double min, double max)
{
super(name, description, required, String.valueOf(defValue), null, null,
null);
}
public DoubleParameter(String name, String description, boolean required,
- Double defValue, Double value, Double min, Double max)
+ Double defValue, Double value, double min, double max)
{
super(name, description, required, String.valueOf(defValue),
String.valueOf(value), null, null);
{
int defval;
- int min, max;
+ int min;
+ int max;
+
+ @Override
public ValueConstrainI getValidValue()
{
return new ValueConstrainI()
@Override
public Number getMin()
{
- if (min < max)
- {
- return min;
- }
- else
- {
- return null;
- }
+ return min < max ? min : null;
}
@Override
public Number getMax()
{
- if (min < max)
- {
- return max;
- }
- else
- {
- return null;
- }
+ return min < max ? max : null;
}
};
}
}
public LogarithmicParameter(String name, String description,
- boolean required, double defValue, double min, double max,
+ boolean required, Double defValue, double min, double max,
double base)
{
super(name, description, required, String.valueOf(defValue), null, null,
}
public LogarithmicParameter(String name, String description,
- boolean required, double defValue, double value, double min,
+ boolean required, Double defValue, double value, double min,
double max, double base)
{
super(name, description, required, String.valueOf(defValue),
public class Option implements OptionI
{
+ String name;
- String name, value, defvalue, description;
+ /*
+ * current value in string format, or "null" if undefined
+ */
+ String value;
- ArrayList<String> possibleVals = new ArrayList<String>();
+ /*
+ * default value in string format, or "null" if undefined
+ */
+ String defvalue;
+
+ String description;
+
+ ArrayList<String> possibleVals = new ArrayList<>();
boolean required;
{
name = new String(opt.name);
if (opt.value != null)
+ {
value = new String(opt.value);
+ }
if (opt.defvalue != null)
+ {
defvalue = new String(opt.defvalue);
+ }
if (opt.description != null)
+ {
description = new String(opt.description);
+ }
if (opt.possibleVals != null)
{
possibleVals = (ArrayList<String>) opt.possibleVals.clone();
this.defvalue = defValue;
if (possibleVals != null)
{
- this.possibleVals = new ArrayList<String>();
+ this.possibleVals = new ArrayList<>();
this.possibleVals.addAll(possibleVals);
}
this.fdetails = fdetails;
Option opt = new Option(this);
return opt;
}
+
+ /**
+ * toString method to help identify options in the debugger only
+ */
+ @Override
+ public String toString()
+ {
+ return this.getClass().getName() + ":" + name;
+ }
}
import jalview.ws.jws2.JabaPreset;
import jalview.ws.jws2.Jws2Discoverer;
import jalview.ws.jws2.jabaws2.Jws2Instance;
+import jalview.ws.params.ParamDatastoreI;
import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
+import compbio.metadata.Argument;
import compbio.metadata.Preset;
import compbio.metadata.PresetManager;
/**
* which services to test
*/
- public static List<String> serviceTests = new ArrayList<String>();
+ public static List<String> serviceTests = new ArrayList<>();
/**
* which presets to test for services
*/
- public static List<String> presetTests = new ArrayList<String>();
+ public static List<String> presetTests = new ArrayList<>();
static
{
serviceTests.add("AAConWS".toLowerCase());
}
pr = en.next();
}
- WsJobParameters pgui = new WsJobParameters(service,
- new JabaPreset(service, pr));
- JFrame jf = new JFrame(MessageManager.formatMessage(
- "label.ws_parameters_for",
- new String[] { service.getActionText() }));
+ WsJobParameters pgui = new WsJobParameters((ParamDatastoreI) null,
+ service, new JabaPreset(service, pr),
+ (List<Argument>) null);
+ JFrame jf = new JFrame(MessageManager
+ .formatMessage("label.ws_parameters_for", new String[]
+ { service.getActionText() }));
jf.setSize(700, 800);
JPanel cont = new JPanel(new BorderLayout());
pgui.validate();