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;
}
-
}