From 7362a6f5c2b2c02b14042a9c0a060e399429f6d9 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Wed, 3 May 2017 11:47:16 +0100 Subject: [PATCH] JAL-2432 honour percentage checkbox when entering values in text box --- src/jalview/appletgui/AnnotationColumnChooser.java | 15 ++------------- src/jalview/appletgui/AnnotationRowFilter.java | 17 +++++++++++------ src/jalview/gui/AnnotationColumnChooser.java | 11 +---------- src/jalview/gui/AnnotationRowFilter.java | 9 +++++++-- 4 files changed, 21 insertions(+), 31 deletions(-) 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 -- 1.7.10.2