From ad69997e7967bae13b30470ca6d1ab74e0bb3046 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Thu, 27 Apr 2017 14:58:26 +0100 Subject: [PATCH] JAL-2432 desktop: filter/select columns by threshold as a percentage --- resources/lang/Messages.properties | 1 + src/jalview/gui/AnnotationColumnChooser.java | 24 ++++++++++++-- src/jalview/gui/AnnotationRowFilter.java | 46 ++++++++++++++++++++++++-- 3 files changed, 66 insertions(+), 5 deletions(-) diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index 4ebca62..cc52620 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -908,6 +908,7 @@ label.webservice_job_title_on = {0} using {1} on {2} label.updating_vamsas_session = Updating vamsas session label.loading_file = Loading File: {0} label.edit_params = Edit {0} +label.as_percentage = As Percentage error.not_implemented = Not implemented error.no_such_method_as_clone1_for = No such method as clone1 for {0} error.null_from_clone1 = Null from clone1! diff --git a/src/jalview/gui/AnnotationColumnChooser.java b/src/jalview/gui/AnnotationColumnChooser.java index 637eb30..c321e59 100644 --- a/src/jalview/gui/AnnotationColumnChooser.java +++ b/src/jalview/gui/AnnotationColumnChooser.java @@ -151,6 +151,9 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements thresholdPanel.setFont(JvSwingUtils.getLabelFont()); thresholdPanel.setLayout(new MigLayout("", "[left][right]", "[][]")); + percentThreshold.setBackground(Color.white); + percentThreshold.setFont(JvSwingUtils.getLabelFont()); + JPanel actionPanel = new JPanel(); actionPanel.setBackground(Color.white); actionPanel.setFont(JvSwingUtils.getLabelFont()); @@ -174,8 +177,9 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements ngStructureFilterPanel = new StructureFilterPanel(this); thresholdPanel.add(getThreshold()); - thresholdPanel.add(thresholdValue, "wrap"); - thresholdPanel.add(slider, "grow, span, wrap"); + thresholdPanel.add(percentThreshold, "wrap"); + thresholdPanel.add(slider, "grow"); + thresholdPanel.add(thresholdValue, "span, wrap"); actionPanel.add(ok); actionPanel.add(cancel); @@ -282,12 +286,14 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements slider.setEnabled(true); thresholdValue.setEnabled(true); + percentThreshold.setEnabled(true); if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD) { slider.setEnabled(false); thresholdValue.setEnabled(false); thresholdValue.setText(""); + percentThreshold.setEnabled(false); // build filter params } else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD) @@ -308,7 +314,18 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000)); slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000)); slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000)); - thresholdValue.setText(getCurrentAnnotation().threshold.value + ""); + + if (percentThreshold.isSelected()) + { + thresholdValue + .setText("" + + ((getCurrentAnnotation().threshold.value - getCurrentAnnotation().graphMin) * 100f / (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin))); + } + else + { + thresholdValue.setText(getCurrentAnnotation().threshold.value + ""); + } + slider.setMajorTickSpacing((int) (range / 10f)); slider.setEnabled(true); thresholdValue.setEnabled(true); @@ -392,6 +409,7 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements ap.paintAlignment(true); } + public ColumnSelection getOldColumnSelection() { return oldColumnSelection; diff --git a/src/jalview/gui/AnnotationRowFilter.java b/src/jalview/gui/AnnotationRowFilter.java index c2bf41b..1035a6c 100644 --- a/src/jalview/gui/AnnotationRowFilter.java +++ b/src/jalview/gui/AnnotationRowFilter.java @@ -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,27 @@ public abstract class AnnotationRowFilter extends JPanel { if (!adjusting) { - thresholdValue.setText((slider.getValue() / 1000f) + ""); + setThresholdValueText(); valueChanged(!sliderDragging); } } }); } + protected void setThresholdValueText() + { + adjusting = true; + if (percentThreshold.isSelected()) + { + thresholdValue.setText("" + (slider.getValue() - slider.getMinimum()) + * 100f / (slider.getMaximum() - slider.getMinimum())); + } + else + { + thresholdValue.setText((slider.getValue() / 1000f) + ""); + } + adjusting = false; + } protected void addSliderMouseListeners() { @@ -275,13 +291,27 @@ public abstract class AnnotationRowFilter extends JPanel try { float f = Float.parseFloat(thresholdValue.getText()); - slider.setValue((int) (f * 1000)); + if (percentThreshold.isEnabled()) + { + 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 +469,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); -- 1.7.10.2