From 11e8324f332f5648ba0f13b902621dc7a20137e4 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Thu, 31 May 2018 11:43:40 +0100 Subject: [PATCH] JAL-2808 pre-fill numeric inequality filter with min/max range value --- src/jalview/gui/FeatureTypeSettings.java | 44 ++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/src/jalview/gui/FeatureTypeSettings.java b/src/jalview/gui/FeatureTypeSettings.java index 6eb583c..89c693f 100644 --- a/src/jalview/gui/FeatureTypeSettings.java +++ b/src/jalview/gui/FeatureTypeSettings.java @@ -1414,7 +1414,7 @@ public class FeatureTypeSettings extends JalviewDialog * if a numeric condition is selected, show the value range * as a tooltip on the value input field */ - setPatternTooltip(filterBy, selectedCondition, patternField); + setNumericHints(filterBy, selectedCondition, patternField); /* * add remove button if filter is populated (non-empty pattern) @@ -1469,14 +1469,19 @@ public class FeatureTypeSettings extends JalviewDialog } /** - * If a numeric comparison condition is selected, retrieve the min-max range for - * the value (score or attribute), and set it as a tooltip on the value file + * If a numeric comparison condition is selected, retrieves the min-max range + * for the value (score or attribute), and sets it as a tooltip on the value + * field. If the field is currently empty, then pre-populates it with + * * * @param attName * @param selectedCondition * @param patternField */ - private void setPatternTooltip(String attName, + private void setNumericHints(String attName, Condition selectedCondition, JTextField patternField) { patternField.setToolTipText(""); @@ -1486,9 +1491,26 @@ public class FeatureTypeSettings extends JalviewDialog float[] minMax = getMinMax(attName); if (minMax != null) { - String tip = String.format("(%s - %s)", - DECFMT_2_2.format(minMax[0]), DECFMT_2_2.format(minMax[1])); + String minFormatted = DECFMT_2_2.format(minMax[0]); + String maxFormatted = DECFMT_2_2.format(minMax[1]); + String tip = String.format("(%s - %s)", minFormatted, maxFormatted); patternField.setToolTipText(tip); + if (patternField.getText().isEmpty()) + { + if (selectedCondition == Condition.GE + || selectedCondition == Condition.GT) + { + patternField.setText(minFormatted); + } + else + { + if (selectedCondition == Condition.LE + || selectedCondition == Condition.LT) + { + patternField.setText(maxFormatted); + } + } + } } } } @@ -1525,6 +1547,7 @@ public class FeatureTypeSettings extends JalviewDialog ItemListener listener = condCombo.getItemListeners()[0]; condCombo.removeItemListener(listener); boolean condIsValid = false; + condCombo.removeAllItems(); for (Condition c : Condition.values()) { @@ -1551,8 +1574,6 @@ public class FeatureTypeSettings extends JalviewDialog condCombo.setSelectedIndex(0); } - condCombo.addItemListener(listener); - /* * clear pattern if it is now invalid for condition */ @@ -1570,6 +1591,11 @@ public class FeatureTypeSettings extends JalviewDialog patternField.setText(""); } } + + /* + * restore the listener + */ + condCombo.addItemListener(listener); } /** @@ -1646,7 +1672,7 @@ public class FeatureTypeSettings extends JalviewDialog Condition cond = (Condition) condCombo.getSelectedItem(); String pattern = valueField.getText().trim(); - setPatternTooltip(attName, cond, valueField); + setNumericHints(attName, cond, valueField); if (pattern.length() == 0 && cond.needsAPattern()) { -- 1.7.10.2