/*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9)
- * Copyright (C) 2015 The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
*
* This file is part of Jalview.
*
import jalview.ws.params.ParameterI;
import jalview.ws.params.ValueConstrainI;
import jalview.ws.params.ValueConstrainI.ValueType;
+import jalview.ws.params.simple.LogarithmicParameter;
import java.awt.BorderLayout;
import java.awt.Component;
*/
boolean compact = false;
- public class OptionBox extends JPanel implements MouseListener,
- ActionListener
+ public class OptionBox extends JPanel
+ implements MouseListener, ActionListener
{
JCheckBox enabled = new JCheckBox();
{
hasLink = true;
- enabled.setToolTipText(JvSwingUtils
- .wrapTooltip(
- true,
- ((desc == null || desc.trim().length() == 0) ? MessageManager
- .getString("label.opt_and_params_further_details ")
- : desc)
- + "<br><img src=\"" + linkImageURL + "\"/>"));
+ enabled.setToolTipText(JvSwingUtils.wrapTooltip(true,
+ ((desc == null || desc.trim().length() == 0)
+ ? MessageManager.getString(
+ "label.opt_and_params_further_details")
+ : desc) + "<br><img src=\"" + linkImageURL
+ + "\"/>"));
enabled.addMouseListener(this);
}
else
{
if (desc != null && desc.trim().length() > 0)
{
- enabled.setToolTipText(JvSwingUtils.wrapTooltip(true,
- opt.getDescription()));
+ enabled.setToolTipText(
+ JvSwingUtils.wrapTooltip(true, opt.getDescription()));
}
}
add(enabled, BorderLayout.NORTH);
for (Object str : opt.getPossibleValues())
{
- val.addItem((String) str);
+ val.addItem(str);
}
- val.setSelectedItem((String) opt.getValue());
+ val.setSelectedItem(opt.getValue());
if (opt.getPossibleValues().size() > 1)
{
setLayout(new GridLayout(1, 2));
setInitialValue();
}
+ @Override
public void actionPerformed(ActionEvent e)
{
if (e.getSource() != enabled)
return opt;
}
+ @Override
public void mouseClicked(MouseEvent e)
{
- if (javax.swing.SwingUtilities.isRightMouseButton(e))
+ if (e.isPopupTrigger()) // for Windows
{
showUrlPopUp(this, finfo.toString(), e.getX(), e.getY());
}
}
+ @Override
public void mouseEntered(MouseEvent e)
{
// TODO Auto-generated method stub
}
+ @Override
public void mouseExited(MouseEvent e)
{
// TODO Auto-generated method stub
}
+ @Override
public void mousePressed(MouseEvent e)
{
- // TODO Auto-generated method stub
-
+ if (e.isPopupTrigger()) // Mac
+ {
+ showUrlPopUp(this, finfo.toString(), e.getX(), e.getY());
+ }
}
+ @Override
public void mouseReleased(MouseEvent e)
{
- // TODO Auto-generated method stub
-
}
public void resetToDefault(boolean setDefaultParams)
}
- public class ParamBox extends JPanel implements ChangeListener,
- ActionListener, MouseListener
+ public class ParamBox extends JPanel
+ implements ChangeListener, ActionListener, MouseListener
{
+
+ boolean isLogarithmic;
+
boolean adjusting = false;
boolean choice = false;
JTextField valueField = null;
- public ParamBox(final OptsParametersContainerI pmlayout, ParameterI parm)
+ public ParamBox(final OptsParametersContainerI pmlayout,
+ ParameterI parm)
{
pmdialogbox = pmlayout;
finfo = parm.getFurtherDetails();
choice = true;
}
}
+ if (parm instanceof LogarithmicParameter)
+ {
+ isLogarithmic = true;
+ }
if (!compact)
{
&& 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
- + "\"/>"
- + MessageManager
- .getString("label.opt_and_params_further_detail")
- : "")));
- }
-
- JvSwingUtils.mgAddtoLayout(this, ttipText,
- new JLabel(parm.getName()), controlPanel, "");
+ ttipText = (JvSwingUtils.wrapTooltip(true,
+ parm.getDescription() + (finfo != null ? "<br><img src=\""
+ + linkImageURL + "\"/>"
+ + MessageManager.getString(
+ "label.opt_and_params_further_details")
+ : "")));
+ }
+
+ JvSwingUtils.mgAddtoLayout(this, ttipText, new JLabel(parm.getName()),
+ controlPanel, "");
updateControls(parm);
validate();
}
// 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.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.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;
validate();
}
+ @Override
public void actionPerformed(ActionEvent e)
{
if (adjusting)
lastVal = null;
}
+ @Override
public void mouseClicked(MouseEvent e)
{
- if (javax.swing.SwingUtilities.isRightMouseButton(e))
+ if (e.isPopupTrigger()) // for Windows
{
showUrlPopUp(this, finfo.toString(), e.getX(), e.getY());
}
}
+ @Override
public void mouseEntered(MouseEvent e)
{
// TODO Auto-generated method stub
}
+ @Override
public void mouseExited(MouseEvent e)
{
// TODO Auto-generated method stub
}
+ @Override
public void mousePressed(MouseEvent e)
{
- // TODO Auto-generated method stub
-
+ if (e.isPopupTrigger()) // for Mac
+ {
+ showUrlPopUp(this, finfo.toString(), e.getX(), e.getY());
+ }
}
+ @Override
public void mouseReleased(MouseEvent e)
{
// TODO Auto-generated method stub
}
+ @Override
public void stateChanged(ChangeEvent e)
{
if (!adjusting)
{
- valueField.setText(""
- + ((integ) ? ("" + (int) slider.getValue())
- : ("" + (float) (slider.getValue() / 1000f))));
+ if (!isLogarithmic)
+ {
+ valueField.setText("" + ((integ) ? ("" + slider.getValue())
+ : ("" + slider.getValue() / 1000f)));
+ }
+ else
+ {
+ Double base = ((LogarithmicParameter) parameter).getBase();
+ Double value = Math.pow(
+ base,
+ slider.getValue());
+ valueField.setText(formatDouble(value));
+ }
checkIfModified();
}
}
+ public String formatDouble(Double value)
+ {
+ String string = "";
+ if (value < 0.0000001)
+ {
+ string = String.format("%3.3e", value);
+ }
+ else
+ {
+ string = value.toString();
+ }
+ return string;
+ }
+
public void updateControls(ParameterI parm)
{
adjusting = true;
{
int iVal;
float fVal;
+ double dVal;
if (validator != null)
{
if (integ)
}
return new int[] { iVal };
}
+ else if (isLogarithmic)
+ {
+ double eValue;
+ dVal = 0d;
+ try
+ {
+ valueField.setText(valueField.getText().trim());
+ eValue = Double.valueOf(valueField.getText());
+
+ dVal = Math.log(eValue) / Math
+ .log(((LogarithmicParameter) parameter).getBase());
+
+ 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)
+ {
+ }
+ ;
+ if (validator.getMin() != null && validator.getMax() != null)
+ {
+ slider.getModel().setRangeProperties((int) (dVal), 1,
+ (int) (validator.getMin().doubleValue()),
+ 1 + (int) (validator.getMax().doubleValue()),
+ true);
+ }
+ else
+ {
+ slider.setVisible(false);
+ }
+ return new double[] { dVal };
+ }
else
{
fVal = 0f;
{
JPopupMenu mnu = new JPopupMenu();
- JMenuItem mitem = new JMenuItem(MessageManager.formatMessage(
- "label.view_params", new String[] { finfo }));
+ JMenuItem mitem = new JMenuItem(
+ MessageManager.formatMessage("label.view_params", new String[]
+ { finfo }));
mitem.addActionListener(new ActionListener()
{
URL linkImageURL = getClass().getResource("/images/link.gif");
- Map<String, OptionBox> optSet = new java.util.LinkedHashMap<String, OptionBox>();
+ Map<String, OptionBox> optSet = new java.util.LinkedHashMap<>();
- Map<String, ParamBox> paramSet = new java.util.LinkedHashMap<String, ParamBox>();
+ Map<String, ParamBox> paramSet = new java.util.LinkedHashMap<>();
public Map<String, OptionBox> getOptSet()
{
else
{
throw new Error(MessageManager.formatMessage(
- "error.invalid_value_for_option", new String[] { string,
- option.getName() }));
+ "error.invalid_value_for_option", new String[]
+ { string, option.getName() }));
}
}
*/
public List<ArgumentI> getCurrentSettings()
{
- List<ArgumentI> argSet = new ArrayList<ArgumentI>();
+ List<ArgumentI> argSet = new ArrayList<>();
for (OptionBox opts : getOptSet().values())
{
OptionI opt = opts.getOptionIfEnabled();