X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FOptsAndParamsPage.java;h=1505df8e2bf7b4c9149a0eb3fac183afc91a2bf1;hb=04a4d60a50394d846d0479c442facebe360b5b9c;hp=5342c9018ab69a726109ff8c254a6f23120a3752;hpb=653e250e0a2a5dd455ae4c52794c4ce0de340418;p=jalview.git diff --git a/src/jalview/gui/OptsAndParamsPage.java b/src/jalview/gui/OptsAndParamsPage.java index 5342c90..1505df8 100644 --- a/src/jalview/gui/OptsAndParamsPage.java +++ b/src/jalview/gui/OptsAndParamsPage.java @@ -26,6 +26,7 @@ import jalview.ws.params.OptionI; 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; @@ -273,6 +274,9 @@ public class OptsAndParamsPage public class ParamBox extends JPanel implements ChangeListener, ActionListener, MouseListener { + + boolean isLogarithmic; + boolean adjusting = false; boolean choice = false; @@ -325,6 +329,10 @@ public class OptsAndParamsPage choice = true; } } + if (parm instanceof LogarithmicParameter) + { + isLogarithmic = true; + } if (!compact) { @@ -571,13 +579,34 @@ public class OptsAndParamsPage { 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() / 1000000f); + valueField.setText(formatDouble(value)); + } checkIfModified(); } } + public String formatDouble(Double value) + { + String string = String.format("%3.3f", value); + if (value < 0.001) + { + string = String.format("%3.3e", value); + } + return string; + } + public void updateControls(ParameterI parm) { adjusting = true; @@ -648,7 +677,17 @@ public class OptsAndParamsPage } else { - valueField.setText(parm.getValue()); + if (parm instanceof LogarithmicParameter) + { + Double base = ((LogarithmicParameter) parm).getBase(); + Double value = Math.pow(base, + Double.parseDouble(parm.getValue()) / 1000000); + valueField.setText(formatDouble(value)); + } + else + { + valueField.setText(parm.getValue()); + } } } lastVal = updateSliderFromValueField(); @@ -659,6 +698,7 @@ public class OptsAndParamsPage { int iVal; float fVal; + double dVal; if (validator != null) { if (integ) @@ -700,6 +740,54 @@ public class OptsAndParamsPage } 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()) + * 1000000; + + 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; @@ -801,9 +889,9 @@ public class OptsAndParamsPage URL linkImageURL = getClass().getResource("/images/link.gif"); - Map optSet = new java.util.LinkedHashMap(); + Map optSet = new java.util.LinkedHashMap<>(); - Map paramSet = new java.util.LinkedHashMap(); + Map paramSet = new java.util.LinkedHashMap<>(); public Map getOptSet() { @@ -904,7 +992,7 @@ public class OptsAndParamsPage */ public List getCurrentSettings() { - List argSet = new ArrayList(); + List argSet = new ArrayList<>(); for (OptionBox opts : getOptSet().values()) { OptionI opt = opts.getOptionIfEnabled();