From: gmungoc Date: Thu, 2 Nov 2017 14:41:59 +0000 (+0000) Subject: JAL-2808 attribute filtering removed, extract method refactoring left in X-Git-Tag: Release_2_11_0~161 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=43c826c1389654c7cce8bb92d6bc62fa1bb4027b;p=jalview.git JAL-2808 attribute filtering removed, extract method refactoring left in --- diff --git a/src/jalview/gui/FeatureColourChooser.java b/src/jalview/gui/FeatureColourChooser.java index fbe8437..89b64a7 100644 --- a/src/jalview/gui/FeatureColourChooser.java +++ b/src/jalview/gui/FeatureColourChooser.java @@ -22,14 +22,8 @@ package jalview.gui; import jalview.api.FeatureColourI; import jalview.datamodel.GraphLine; -import jalview.datamodel.features.FeatureAttributes; import jalview.schemes.FeatureColour; import jalview.util.MessageManager; -import jalview.util.matcher.Condition; -import jalview.util.matcher.KeyedMatcher; -import jalview.util.matcher.KeyedMatcherI; -import jalview.util.matcher.KeyedMatcherSet; -import jalview.util.matcher.KeyedMatcherSetI; import java.awt.BorderLayout; import java.awt.Color; @@ -40,11 +34,8 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.FocusAdapter; import java.awt.event.FocusEvent; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import java.util.Iterator; import javax.swing.BorderFactory; import javax.swing.JCheckBox; @@ -104,18 +95,6 @@ public class FeatureColourChooser extends JalviewDialog private ActionListener colourEditor = null; - private JComboBox filterAttribute; - - private JComboBox filterCondition; - - private JTextField filterValue; - - private JComboBox filterAttribute2; - - private JComboBox filterCondition2; - - private JTextField filterValue2; - /** * Constructor * @@ -235,48 +214,12 @@ public class FeatureColourChooser extends JalviewDialog threshline.value = cs.getThreshold(); } - setInitialFilters(cs.getAttributeFilters()); - adjusting = false; changeColour(false); waitForInput(); } - /** - * Populates the attribute filter fields for the initial display - * - * @param filters - */ - void setInitialFilters(KeyedMatcherSetI filters) - { - // todo generalise to populate N conditions - - if (filters == null) - { - return; - } - - Iterator theFilters = filters.getMatchers(); - if (theFilters.hasNext()) - { - KeyedMatcherI filter = theFilters.next(); - filterAttribute.setSelectedItem(filter.getKey()); - filterCondition.setSelectedItem(filter.getMatcher().getCondition()); - filterValue.setText(filter.getMatcher().getPattern()); - } - if (theFilters.hasNext()) - { - KeyedMatcherI filter = theFilters.next(); - boolean anded = filters.isAnded(); - // todo add OR/AND condition to gui - // - user choice for the second condition, fixed thereafter - filterAttribute2.setSelectedItem(filter.getKey()); - filterCondition2.setSelectedItem(filter.getMatcher().getCondition()); - filterValue2.setText(filter.getMatcher().getPattern()); - } - } - private void jbInit() throws Exception { this.setLayout(new GridLayout(4, 1)); @@ -290,17 +233,6 @@ public class FeatureColourChooser extends JalviewDialog this.add(colourByPanel); this.add(thresholdPanel); - /* - * add filter by attributes options only if we know any attributes - */ - Iterator attributes = FeatureAttributes.getInstance() - .getAttributes(type).iterator(); - if (attributes.hasNext()) - { - JPanel filtersPanel = initFiltersPanel(attributes); - this.add(filtersPanel); - } - this.add(okCancelPanel); } @@ -515,11 +447,6 @@ public class FeatureColourChooser extends JalviewDialog return; } - if (!validateInputs()) - { - return; - } - boolean aboveThreshold = false; boolean belowThreshold = false; if (threshold.getSelectedIndex() == 1) @@ -620,100 +547,11 @@ public class FeatureColourChooser extends JalviewDialog minColour.setForeground(oldminColour); } - /* - * add attribute filters if entered - */ - if (filterAttribute != null) - { - setAttributeFilters(acg); - } - fr.setColour(type, acg); cs = acg; ap.paintAlignment(updateStructsAndOverview, updateStructsAndOverview); } - /** - * Checks inputs are valid, and answers true if they are, else false. Also - * sets the colour of invalid inputs to red. - * - * @return - */ - boolean validateInputs() - { - // todo generalise to N filters - return isValidFilter(filterValue, filterCondition) - || isValidFilter(filterValue2, filterCondition2); - } - - /** - * Answers true unless a numeric condition has been selected with a - * non-numeric value - * - * @param value - * @param condition - */ - protected boolean isValidFilter(JTextField value, JComboBox condition) - { - if (value == null || condition == null) - { - return true; // fields not populated - } - - value.setBackground(Color.white); - String v1 = value.getText().trim(); - if (v1.length() > 0) - { - Condition c1 = (Condition) condition.getSelectedItem(); - if (c1.isNumeric()) - { - try - { - Float.valueOf(v1); - } catch (NumberFormatException e) - { - value.setBackground(Color.red); - return false; - } - } - } - - return true; - } - - /** - * Sets any attribute value filters entered in the dialog as filters on the - * colour scheme - * - * @param acg - */ - protected void setAttributeFilters(FeatureColourI acg) - { - String attribute = (String) filterAttribute.getSelectedItem(); - Condition cond = (Condition) filterCondition.getSelectedItem(); - String pattern = filterValue.getText().trim(); - if (pattern.length() > 0) - { - KeyedMatcherSetI filters = new KeyedMatcherSet(); - KeyedMatcherI km = new KeyedMatcher(attribute, cond, pattern); - filters.and(km); - - /* - * is there a second condition? - * todo: allow N conditions with choice of AND or OR (but not both!) - */ - pattern = filterValue2.getText().trim(); - if (pattern.length() > 1) - { - attribute = (String) filterAttribute2.getSelectedItem(); - cond = (Condition) filterCondition2.getSelectedItem(); - KeyedMatcherI km2 = new KeyedMatcher(attribute, cond, pattern); - filters.and(km2); - } - acg.setAttributeFilters(filters); - } - } - @Override protected void raiseClosed() { @@ -815,130 +653,4 @@ public class FeatureColourChooser extends JalviewDialog return cs; } - /** - * Lay out fields for attribute value filters - * - * @param attNames - * - * @return - */ - protected JPanel initFiltersPanel(Iterator attNames) - { - JPanel filtersPanel = new JPanel(); - filtersPanel.setLayout(new GridLayout(2, 3)); - filtersPanel.setBackground(Color.white); - - /* - * drop-down choice of attribute - */ - filterAttribute = new JComboBox<>(); - filterAttribute2 = new JComboBox<>(); - while (attNames.hasNext()) - { - String attName = attNames.next(); - filterAttribute.addItem(attName); - filterAttribute2.addItem(attName); - } - filterAttribute.addItemListener(new ItemListener() - { - @Override - public void itemStateChanged(ItemEvent e) - { - changeColour(true); - } - }); - - /* - * drop-down choice of test condition - */ - filterCondition = new JComboBox<>(); - for (Condition cond : Condition.values()) - { - filterCondition.addItem(cond); - } - filterCondition.addItemListener(new ItemListener() - { - @Override - public void itemStateChanged(ItemEvent e) - { - changeColour(true); - } - }); - - filterValue = new JTextField(12); - filterValue.addActionListener(new ActionListener() - { - @Override - public void actionPerformed(ActionEvent e) - { - changeColour(true); - } - }); - filterValue.addFocusListener(new FocusAdapter() - { - @Override - public void focusLost(FocusEvent e) - { - changeColour(true); - } - }); - - /* - * repeat for a second filter - * todo: generalise to N filters - */ - filterAttribute2.addActionListener(new ActionListener() - { - @Override - public void actionPerformed(ActionEvent e) - { - changeColour(true); - } - }); - - /* - * drop-down choice of test condition - */ - filterCondition2 = new JComboBox<>(); - for (Condition cond : Condition.values()) - { - filterCondition2.addItem(cond); - } - filterCondition2.addActionListener(new ActionListener() - { - @Override - public void actionPerformed(ActionEvent e) - { - changeColour(true); - } - }); - - filterValue2 = new JTextField(12); - filterValue2.addActionListener(new ActionListener() - { - @Override - public void actionPerformed(ActionEvent e) - { - changeColour(true); - } - }); - filterValue2.addFocusListener(new FocusAdapter() - { - @Override - public void focusLost(FocusEvent e) - { - changeColour(true); - } - }); - - filtersPanel.add(filterAttribute); - filtersPanel.add(filterCondition); - filtersPanel.add(filterValue); - filtersPanel.add(filterAttribute2); - filtersPanel.add(filterCondition2); - filtersPanel.add(filterValue2); - - return filtersPanel; - } - }