JAL-2432 honour percentage checkbox when entering values in text box
authorJim Procter <jprocter@issues.jalview.org>
Wed, 3 May 2017 10:47:16 +0000 (11:47 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Wed, 3 May 2017 10:47:39 +0000 (11:47 +0100)
src/jalview/appletgui/AnnotationColumnChooser.java
src/jalview/appletgui/AnnotationRowFilter.java
src/jalview/gui/AnnotationColumnChooser.java
src/jalview/gui/AnnotationRowFilter.java

index 36f8a84..77bb6bb 100644 (file)
@@ -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);
     }
index 6ea0fed..315ce3b 100644 (file)
@@ -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)
     {
     }
index d0f1247..d5bc7d1 100644 (file)
@@ -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);
index 1035a6c..a3ce528 100644 (file)
@@ -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