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;
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;
private ActionListener colourEditor = null;
- private JComboBox<String> filterAttribute;
-
- private JComboBox<Condition> filterCondition;
-
- private JTextField filterValue;
-
- private JComboBox<String> filterAttribute2;
-
- private JComboBox<Condition> filterCondition2;
-
- private JTextField filterValue2;
-
/**
* Constructor
*
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<KeyedMatcherI> 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));
this.add(colourByPanel);
this.add(thresholdPanel);
- /*
- * add filter by attributes options only if we know any attributes
- */
- Iterator<String> attributes = FeatureAttributes.getInstance()
- .getAttributes(type).iterator();
- if (attributes.hasNext())
- {
- JPanel filtersPanel = initFiltersPanel(attributes);
- this.add(filtersPanel);
- }
-
this.add(okCancelPanel);
}
return;
}
- if (!validateInputs())
- {
- return;
- }
-
boolean aboveThreshold = false;
boolean belowThreshold = false;
if (threshold.getSelectedIndex() == 1)
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> 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()
{
return cs;
}
- /**
- * Lay out fields for attribute value filters
- *
- * @param attNames
- *
- * @return
- */
- protected JPanel initFiltersPanel(Iterator<String> 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;
- }
-
}