Merge branch 'develop' of https://source.jalview.org/git/jalview into features/JAL...
[jalview.git] / src / jalview / gui / AnnotationRowFilter.java
index c2bf41b..a3ce528 100644 (file)
@@ -62,6 +62,8 @@ public abstract class AnnotationRowFilter extends JPanel
 
   protected JCheckBox seqAssociated = new JCheckBox();
 
+  protected JCheckBox percentThreshold = new JCheckBox();
+
   protected JSlider slider = new JSlider();
 
   protected JTextField thresholdValue = new JTextField(20);
@@ -120,13 +122,32 @@ public abstract class AnnotationRowFilter extends JPanel
       {
         if (!adjusting)
         {
-          thresholdValue.setText((slider.getValue() / 1000f) + "");
+          setThresholdValueText();
           valueChanged(!sliderDragging);
         }
       }
     });
   }
 
+  /**
+   * 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())
+    {
+      thresholdValue.setText("" + (slider.getValue() - slider.getMinimum())
+              * 100f / (slider.getMaximum() - slider.getMinimum()));
+    }
+    else
+    {
+      thresholdValue.setText((slider.getValue() / 1000f) + "");
+    }
+    adjusting = oldadj;
+  }
   protected void addSliderMouseListeners()
   {
 
@@ -275,13 +296,27 @@ public abstract class AnnotationRowFilter extends JPanel
     try
     {
       float f = Float.parseFloat(thresholdValue.getText());
-      slider.setValue((int) (f * 1000));
+      if (percentThreshold.isSelected())
+      {
+        slider.setValue(slider.getMinimum()
+                + ((int) ((f / 100f) * (slider.getMaximum() - slider
+                        .getMinimum()))));
+      }
+      else
+      {
+        slider.setValue((int) (f * 1000));
+      }
       updateView();
     } catch (NumberFormatException ex)
     {
     }
   }
 
+  protected void percentageValue_actionPerformed()
+  {
+    setThresholdValueText();
+  }
+
   protected void thresholdIsMin_actionPerformed()
   {
     updateView();
@@ -439,6 +474,18 @@ public abstract class AnnotationRowFilter extends JPanel
       }
     });
 
+    percentThreshold.setText(MessageManager.getString("label.as_percentage"));
+    percentThreshold.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        if (!adjusting)
+        {
+          percentageValue_actionPerformed();
+        }
+      }
+    });
     slider.setPaintLabels(false);
     slider.setPaintTicks(true);
     slider.setBackground(Color.white);