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;
public class ParamBox extends JPanel
implements ChangeListener, ActionListener, MouseListener
{
+
+ boolean isLogarithmic;
+
boolean adjusting = false;
boolean choice = false;
choice = true;
}
}
+ if (parm instanceof LogarithmicParameter)
+ {
+ isLogarithmic = true;
+ }
if (!compact)
{
{
if (!adjusting)
{
- valueField.setText("" + ((integ) ? ("" + slider.getValue())
- : ("" + 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;
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()
{
*/
public List<ArgumentI> getCurrentSettings()
{
- List<ArgumentI> argSet = new ArrayList<ArgumentI>();
+ List<ArgumentI> argSet = new ArrayList<>();
for (OptionBox opts : getOptSet().values())
{
OptionI opt = opts.getOptionIfEnabled();
--- /dev/null
+package jalview.ws.params.simple;
+
+import jalview.ws.params.ParameterI;
+import jalview.ws.params.ValueConstrainI;
+
+/**
+ *
+ * @author TZVanaalten
+ *
+ */
+public class LogarithmicParameter extends Option implements ParameterI
+{
+ Double defval;
+
+ Double min, max;
+
+ Double base;
+
+ @Override
+ public ValueConstrainI getValidValue()
+ {
+ return new ValueConstrainI()
+ {
+
+ @Override
+ public ValueType getType()
+ {
+ return ValueType.Double;
+ }
+
+ @Override
+ public Number getMin()
+ {
+ if (min < max)
+ {
+ return min;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ @Override
+ public Number getMax()
+ {
+ if (min < max)
+ {
+ return max;
+ }
+ else
+ {
+ return null;
+ }
+ }
+ };
+ }
+
+ public LogarithmicParameter(LogarithmicParameter parm)
+ {
+ super(parm);
+ max = parm.max;
+ min = parm.min;
+ base = parm.base;
+ }
+
+ public LogarithmicParameter(String name, String description,
+ boolean required, Double defValue, Double min, Double max,
+ Double base)
+ {
+ super(name, description, required, String.valueOf(defValue), null, null,
+ null);
+ defval = defValue;
+ this.min = min;
+ this.max = max;
+ this.base = base;
+ }
+
+ public LogarithmicParameter(String name, String description,
+ boolean required, Double defValue, Double value, Double min,
+ Double max, Double base)
+ {
+ super(name, description, required, String.valueOf(defValue),
+ String.valueOf(value), null, null);
+ defval = defValue;
+ this.min = min;
+ this.max = max;
+ this.base = base;
+ }
+
+ @Override
+ public LogarithmicParameter copy()
+ {
+ return new LogarithmicParameter(this);
+ }
+
+ public Double getBase()
+ {
+ return base;
+ }
+}