JAL-1933 JAL-2432 percentile filter for select/hide columns by annotation in applet
[jalview.git] / src / jalview / appletgui / AnnotationRowFilter.java
index 8d67d71..f1b97eb 100644 (file)
@@ -60,6 +60,8 @@ public abstract class AnnotationRowFilter extends Panel
 
   protected Scrollbar slider = new Scrollbar(Scrollbar.HORIZONTAL);
 
+  protected Checkbox percentThreshold = new Checkbox();
+
   protected TextField thresholdValue = new TextField(20);
 
   protected Frame frame;
@@ -132,18 +134,49 @@ public abstract class AnnotationRowFilter extends Panel
     updateView();
   }
 
+  protected void setThresholdValueText()
+  {
+    adjusting = true;
+    if (percentThreshold.getState())
+    {
+      double scl = slider.getMaximum() - slider.getMinimum();
+      scl = (slider.getValue() - slider.getMinimum()) / scl;
+      thresholdValue.setText(100 * scl + "");
+    }
+    else
+    {
+      thresholdValue.setText((slider.getValue() / 1000f) + "");
+    }
+    thresholdValue.setCaretPosition(0);
+    adjusting = false;
+  }
+  
   public void thresholdValue_actionPerformed(ActionEvent e)
   {
     try
     {
       float f = Float.parseFloat(thresholdValue.getText());
-      slider.setValue((int) (f * 1000));
+      if (percentThreshold.getState())
+      {
+        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 populateThresholdComboBox(Choice threshold)
   {
     threshold.addItem(MessageManager