From: Jim Procter Date: Wed, 3 May 2017 10:47:16 +0000 (+0100) Subject: JAL-2432 honour percentage checkbox when entering values in text box X-Git-Tag: Release_2_10_2~3^2~109^2~2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=7362a6f5c2b2c02b14042a9c0a060e399429f6d9;p=jalview.git JAL-2432 honour percentage checkbox when entering values in text box --- diff --git a/src/jalview/appletgui/AnnotationColumnChooser.java b/src/jalview/appletgui/AnnotationColumnChooser.java index 36f8a84..77bb6bb 100644 --- a/src/jalview/appletgui/AnnotationColumnChooser.java +++ b/src/jalview/appletgui/AnnotationColumnChooser.java @@ -320,7 +320,7 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements { if (!adjusting) { - thresholdValue.setText((slider.getValue() / 1000f) + ""); + setThresholdValueText(); valueChanged(!sliderDragging); } } @@ -895,19 +895,8 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements @Override public void actionPerformed(ActionEvent evt) { - if (evt.getSource() == thresholdValue) - { - try - { - float f = new Float(thresholdValue.getText()).floatValue(); - slider.setValue((int) (f * 1000)); - adjustmentValueChanged(null); - } catch (NumberFormatException ex) - { - } - } - else if (evt.getSource() == ok) + if (evt.getSource() == ok) { ok_actionPerformed(null); } diff --git a/src/jalview/appletgui/AnnotationRowFilter.java b/src/jalview/appletgui/AnnotationRowFilter.java index 6ea0fed..315ce3b 100644 --- a/src/jalview/appletgui/AnnotationRowFilter.java +++ b/src/jalview/appletgui/AnnotationRowFilter.java @@ -133,21 +133,26 @@ public abstract class AnnotationRowFilter extends Panel updateView(); } + /** + * update the text field from the threshold slider. preserves state of + * 'adjusting' so safe to call in init. + */ protected void setThresholdValueText() { + boolean oldadj = adjusting; adjusting = true; if (percentThreshold.getState()) { double scl = slider.getMaximum() - slider.getMinimum(); scl = (slider.getValue() - slider.getMinimum()) / scl; - thresholdValue.setText(100 * scl + ""); + thresholdValue.setText(100f * scl + ""); } else { thresholdValue.setText((slider.getValue() / 1000f) + ""); } thresholdValue.setCaretPosition(0); - adjusting = false; + adjusting = oldadj; } public void thresholdValue_actionPerformed(ActionEvent e) @@ -157,15 +162,15 @@ public abstract class AnnotationRowFilter extends Panel float f = Float.parseFloat(thresholdValue.getText()); if (percentThreshold.getState()) { - slider.setValue(slider.getMinimum() - + ((int) ((f / 100f) * (slider.getMaximum() - slider - .getMinimum())))); + int pos = slider.getMinimum() + + (int) ((slider.getMaximum() - slider.getMinimum()) * f / 100f); + slider.setValue(pos); } else { slider.setValue((int) (f * 1000)); } - updateView(); + valueChanged(false); } catch (NumberFormatException ex) { } diff --git a/src/jalview/gui/AnnotationColumnChooser.java b/src/jalview/gui/AnnotationColumnChooser.java index d0f1247..d5bc7d1 100644 --- a/src/jalview/gui/AnnotationColumnChooser.java +++ b/src/jalview/gui/AnnotationColumnChooser.java @@ -318,16 +318,7 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000)); slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000)); - if (percentThreshold.isSelected()) - { - thresholdValue - .setText("" - + ((getCurrentAnnotation().threshold.value - getCurrentAnnotation().graphMin) * 100f / (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin))); - } - else - { - thresholdValue.setText(getCurrentAnnotation().threshold.value + ""); - } + setThresholdValueText(); slider.setMajorTickSpacing((int) (range / 10f)); slider.setEnabled(true); diff --git a/src/jalview/gui/AnnotationRowFilter.java b/src/jalview/gui/AnnotationRowFilter.java index 1035a6c..a3ce528 100644 --- a/src/jalview/gui/AnnotationRowFilter.java +++ b/src/jalview/gui/AnnotationRowFilter.java @@ -129,8 +129,13 @@ public abstract class AnnotationRowFilter extends JPanel }); } + /** + * update the text field from the threshold slider. preserves state of + * 'adjusting' so safe to call in init. + */ protected void setThresholdValueText() { + boolean oldadj = adjusting; adjusting = true; if (percentThreshold.isSelected()) { @@ -141,7 +146,7 @@ public abstract class AnnotationRowFilter extends JPanel { thresholdValue.setText((slider.getValue() / 1000f) + ""); } - adjusting = false; + adjusting = oldadj; } protected void addSliderMouseListeners() { @@ -291,7 +296,7 @@ public abstract class AnnotationRowFilter extends JPanel try { float f = Float.parseFloat(thresholdValue.getText()); - if (percentThreshold.isEnabled()) + if (percentThreshold.isSelected()) { slider.setValue(slider.getMinimum() + ((int) ((f / 100f) * (slider.getMaximum() - slider