2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.api.AlignmentViewPanel;
24 import jalview.api.FeatureColourI;
25 import jalview.datamodel.GraphLine;
26 import jalview.datamodel.features.FeatureAttributes;
27 import jalview.datamodel.features.FeatureAttributes.Datatype;
28 import jalview.datamodel.features.FeatureMatcher;
29 import jalview.datamodel.features.FeatureMatcherI;
30 import jalview.datamodel.features.FeatureMatcherSet;
31 import jalview.datamodel.features.FeatureMatcherSetI;
32 import jalview.io.gff.SequenceOntologyFactory;
33 import jalview.io.gff.SequenceOntologyI;
34 import jalview.schemes.FeatureColour;
35 import jalview.util.ColorUtils;
36 import jalview.util.MessageManager;
37 import jalview.util.matcher.Condition;
39 import java.awt.BorderLayout;
40 import java.awt.Color;
41 import java.awt.Dimension;
42 import java.awt.FlowLayout;
43 import java.awt.GridLayout;
44 import java.awt.event.ActionEvent;
45 import java.awt.event.ActionListener;
46 import java.awt.event.FocusAdapter;
47 import java.awt.event.FocusEvent;
48 import java.awt.event.ItemEvent;
49 import java.awt.event.ItemListener;
50 import java.awt.event.MouseAdapter;
51 import java.awt.event.MouseEvent;
52 import java.text.DecimalFormat;
53 import java.util.ArrayList;
54 import java.util.Collections;
55 import java.util.Comparator;
56 import java.util.HashMap;
57 import java.util.List;
59 import java.util.Map.Entry;
61 import javax.swing.BorderFactory;
62 import javax.swing.BoxLayout;
63 import javax.swing.ButtonGroup;
64 import javax.swing.JButton;
65 import javax.swing.JCheckBox;
66 import javax.swing.JColorChooser;
67 import javax.swing.JComboBox;
68 import javax.swing.JLabel;
69 import javax.swing.JPanel;
70 import javax.swing.JRadioButton;
71 import javax.swing.JSlider;
72 import javax.swing.JTextField;
73 import javax.swing.SwingConstants;
74 import javax.swing.border.LineBorder;
75 import javax.swing.event.ChangeEvent;
76 import javax.swing.event.ChangeListener;
77 import javax.swing.plaf.basic.BasicArrowButton;
80 * A dialog where the user can configure colour scheme, and any filters, for one
83 * (Was FeatureColourChooser prior to Jalview 1.11, renamed with the addition of
86 public class FeatureTypeSettings extends JalviewDialog
88 private final static String LABEL_18N = MessageManager
89 .getString("label.label");
91 private final static String SCORE_18N = MessageManager
92 .getString("label.score");
94 private static final int RADIO_WIDTH = 130;
96 private static final String COLON = ":";
98 private static final int MAX_TOOLTIP_LENGTH = 50;
100 private static final int NO_COLOUR_OPTION = 0;
102 private static final int MIN_COLOUR_OPTION = 1;
104 private static final int MAX_COLOUR_OPTION = 2;
106 private static final int ABOVE_THRESHOLD_OPTION = 1;
108 private static final int BELOW_THRESHOLD_OPTION = 2;
110 private static final DecimalFormat DECFMT_2_2 = new DecimalFormat(
114 * FeatureRenderer holds colour scheme and filters for feature types
116 private final FeatureRenderer fr; // todo refactor to allow interface type
120 * the view panel to update when settings change
122 private final AlignmentViewPanel ap;
124 private final String featureType;
127 * the colour and filters to reset to on Cancel
128 * (including feature sub-types if modified)
130 private Map<String, FeatureColourI> originalColours;
132 private Map<String, FeatureMatcherSetI> originalFilters;
135 * set flag to true when setting values programmatically,
136 * to avoid invocation of action handlers
138 private boolean adjusting = false;
141 * minimum of the value range for graduated colour
142 * (may be for feature score or for a numeric attribute)
147 * maximum of the value range for graduated colour
152 * scale factor for conversion between absolute min-max and slider
154 private float scaleFactor;
157 * radio button group, to select what to colour by:
158 * simple colour, by category (text), or graduated
160 private JRadioButton simpleColour = new JRadioButton();
162 private JRadioButton byCategory = new JRadioButton();
164 private JRadioButton graduatedColour = new JRadioButton();
167 * colours and filters are shown in tabbed view or single content pane
169 JPanel coloursPanel, filtersPanel;
171 JPanel singleColour = new JPanel();
173 private JPanel minColour = new JPanel();
175 private JPanel maxColour = new JPanel();
177 private JComboBox<String> threshold = new JComboBox<>();
179 private JSlider slider = new JSlider();
181 private JTextField thresholdValue = new JTextField(20);
183 private JCheckBox thresholdIsMin = new JCheckBox();
185 private GraphLine threshline;
187 private ActionListener featureSettings = null;
189 private ActionListener changeColourAction;
192 * choice of option for 'colour for no value'
194 private JComboBox<String> noValueCombo;
197 * choice of what to colour by text (Label or attribute)
199 private JComboBox<String> colourByTextCombo;
202 * choice of what to colour by range (Score or attribute)
204 private JComboBox<String> colourByRangeCombo;
206 private JRadioButton andFilters;
208 private JRadioButton orFilters;
211 * filters for the currently selected feature type
213 private List<FeatureMatcherI> filters;
215 private JPanel chooseFiltersPanel;
218 * the root Sequence Ontology terms (if any) that is a parent of
219 * the current feature type
221 private String rootSOTerm;
224 * a map whose keys are Sequence Ontology terms - selected from the
225 * current term and its parents in the SO - whose subterms include
226 * additional feature types; the map entry is the list of additional
227 * feature types that match the key or have it as a parent term; in
228 * other words, distinct 'aggregations' that include the current feature type
230 private final Map<String, List<String>> relatedSoTerms;
233 * if true, filter or colour settings are also applied to
234 * any sub-types of parentTerm in the Sequence Ontology
236 private boolean applyFiltersToSubtypes;
238 private boolean applyColourToSubtypes;
240 private String parentSOTerm;
248 public FeatureTypeSettings(FeatureRenderer frender, String theType)
251 this.featureType = theType;
254 relatedSoTerms = findSequenceOntologyGroupings(this.featureType,
255 fr.getRenderOrder());
258 * save original colours and filters for this feature type,
259 * and any related types, to restore on Cancel
261 originalFilters = new HashMap<>();
262 originalFilters.put(theType, fr.getFeatureFilter(theType));
263 originalColours = new HashMap<>();
264 originalColours.put(theType, fr.getFeatureColours().get(theType));
265 for (List<String> related : relatedSoTerms.values())
267 for (String type : related)
269 originalFilters.put(type, fr.getFeatureFilter(type));
270 originalColours.put(type, fr.getFeatureColours().get(type));
279 } catch (Exception ex)
281 ex.printStackTrace();
291 colourChanged(false);
293 String title = MessageManager
294 .formatMessage("label.display_settings_for", new String[]
296 initDialogFrame(this, true, false, title, 580, 500);
301 * Answers a (possibly empty) map of any Sequence Ontology terms (the current
302 * feature type and its parents) which incorporate additional known feature
303 * types (the map entry).
305 * For example if {@code stop_gained} and {@code stop_lost} are known feature
306 * types, then SO term {@ nonsynonymous_variant} is the first common parent of
310 * the current feature type being configured
311 * @param featureTypes
312 * all known feature types on the alignment
315 protected static Map<String, List<String>> findSequenceOntologyGroupings(
316 String featureType, List<String> featureTypes)
318 List<String> sortedTypes = new ArrayList<>(featureTypes);
319 Collections.sort(sortedTypes);
321 Map<String, List<String>> parents = new HashMap<>();
325 * walk up featureType and all of its parents
326 * find other feature types which are subsumed by each term
327 * add each distinct aggregation of included feature types to the map
329 List<String> candidates = new ArrayList<>();
330 SequenceOntologyI so = SequenceOntologyFactory.getInstance();
331 candidates.add(featureType);
332 while (!candidates.isEmpty())
334 String term = candidates.remove(0);
335 List<String> includedFeatures = new ArrayList<>();
336 for (String type : sortedTypes)
338 if (!type.equals(featureType) && so.isA(type, term))
340 includedFeatures.add(type);
343 if (!includedFeatures.isEmpty()
344 && !parents.containsValue(includedFeatures))
346 parents.put(term, includedFeatures);
348 candidates.addAll(so.getParents(term));
355 * Configures the widgets on the Colours tab according to the current feature
358 private void updateColoursTab()
360 FeatureColourI fc = fr.getFeatureColours().get(featureType);
363 * suppress action handling while updating values programmatically
371 if (fc.isSimpleColour())
373 singleColour.setBackground(fc.getColour());
374 singleColour.setForeground(fc.getColour());
375 simpleColour.setSelected(true);
379 * colour by text (Label or attribute text)
381 if (fc.isColourByLabel())
383 byCategory.setSelected(true);
384 colourByTextCombo.setEnabled(colourByTextCombo.getItemCount() > 1);
385 if (fc.isColourByAttribute())
387 String[] attributeName = fc.getAttributeName();
388 colourByTextCombo.setSelectedItem(
389 FeatureMatcher.toAttributeDisplayName(attributeName));
393 colourByTextCombo.setSelectedItem(LABEL_18N);
398 colourByTextCombo.setEnabled(false);
401 if (!fc.isGraduatedColour())
403 colourByRangeCombo.setEnabled(false);
404 minColour.setEnabled(false);
405 maxColour.setEnabled(false);
406 noValueCombo.setEnabled(false);
407 threshold.setEnabled(false);
408 slider.setEnabled(false);
409 thresholdValue.setEnabled(false);
410 thresholdIsMin.setEnabled(false);
415 * Graduated colour, by score or attribute value range
417 graduatedColour.setSelected(true);
418 updateColourMinMax(); // ensure min, max are set
419 colourByRangeCombo.setEnabled(colourByRangeCombo.getItemCount() > 1);
420 minColour.setEnabled(true);
421 maxColour.setEnabled(true);
422 noValueCombo.setEnabled(true);
423 threshold.setEnabled(true);
424 minColour.setBackground(fc.getMinColour());
425 maxColour.setBackground(fc.getMaxColour());
427 if (fc.isColourByAttribute())
429 String[] attributeName = fc.getAttributeName();
430 colourByRangeCombo.setSelectedItem(
431 FeatureMatcher.toAttributeDisplayName(attributeName));
435 colourByRangeCombo.setSelectedItem(SCORE_18N);
437 Color noColour = fc.getNoColour();
438 if (noColour == null)
440 noValueCombo.setSelectedIndex(NO_COLOUR_OPTION);
442 else if (noColour.equals(fc.getMinColour()))
444 noValueCombo.setSelectedIndex(MIN_COLOUR_OPTION);
446 else if (noColour.equals(fc.getMaxColour()))
448 noValueCombo.setSelectedIndex(MAX_COLOUR_OPTION);
452 * update min-max scaling if there is a range to work with,
453 * else disable the widgets (this shouldn't happen if only
454 * valid options are offered in the combo box)
456 scaleFactor = (max == min) ? 1f : 100f / (max - min);
457 float range = (max - min) * scaleFactor;
458 slider.setMinimum((int) (min * scaleFactor));
459 slider.setMaximum((int) (max * scaleFactor));
460 slider.setMajorTickSpacing((int) (range / 10f));
462 threshline = new GraphLine((max - min) / 2f, "Threshold",
464 threshline.value = fc.getThreshold();
466 if (fc.hasThreshold())
468 threshold.setSelectedIndex(
469 fc.isAboveThreshold() ? ABOVE_THRESHOLD_OPTION
470 : BELOW_THRESHOLD_OPTION);
471 slider.setEnabled(true);
472 slider.setValue((int) (fc.getThreshold() * scaleFactor));
473 thresholdValue.setText(String.valueOf(fc.getThreshold()));
474 thresholdValue.setEnabled(true);
475 thresholdIsMin.setEnabled(true);
479 slider.setEnabled(false);
480 thresholdValue.setEnabled(false);
481 thresholdIsMin.setEnabled(false);
483 thresholdIsMin.setSelected(!fc.isAutoScaled());
491 * Configures the initial layout
493 private void initialise()
495 this.setLayout(new BorderLayout());
498 * an ActionListener that applies colour changes
500 changeColourAction = new ActionListener()
503 public void actionPerformed(ActionEvent e)
510 * first panel/tab: colour options
512 JPanel coloursPanel = initialiseColoursPanel();
513 this.add(coloursPanel, BorderLayout.NORTH);
516 * second panel/tab: filter options
518 JPanel filtersPanel = initialiseFiltersPanel();
519 this.add(filtersPanel, BorderLayout.CENTER);
521 JPanel okCancelPanel = initialiseOkCancelPanel();
523 this.add(okCancelPanel, BorderLayout.SOUTH);
527 * Updates the min-max range if Colour By selected item is Score, or an
528 * attribute, with a min-max range
530 protected void updateColourMinMax()
532 if (!graduatedColour.isSelected())
537 String colourBy = (String) colourByRangeCombo.getSelectedItem();
538 float[] minMax = getMinMax(colourBy);
548 * Retrieves the min-max range:
550 * <li>of feature score, if colour or filter is by Score</li>
551 * <li>else of the selected attribute</li>
557 private float[] getMinMax(String attName)
559 float[] minMax = null;
560 if (SCORE_18N.equals(attName))
562 minMax = fr.getMinMax().get(featureType)[0];
566 // colour by attribute range
567 minMax = FeatureAttributes.getInstance().getMinMax(featureType,
568 FeatureMatcher.fromAttributeDisplayName(attName));
574 * Lay out fields for graduated colour (by score or attribute value)
578 private JPanel initialiseGraduatedColourPanel()
580 JPanel graduatedColourPanel = new JPanel();
581 graduatedColourPanel.setLayout(
582 new BoxLayout(graduatedColourPanel, BoxLayout.Y_AXIS));
583 JvSwingUtils.createTitledBorder(graduatedColourPanel,
584 MessageManager.getString("label.graduated_colour"), true);
585 graduatedColourPanel.setBackground(Color.white);
588 * first row: graduated colour radio button, score/attribute drop-down
590 JPanel graduatedChoicePanel = new JPanel(
591 new FlowLayout(FlowLayout.LEFT));
592 graduatedChoicePanel.setBackground(Color.white);
593 graduatedColour = new JRadioButton(
594 MessageManager.getString("label.by_range_of") + COLON);
595 graduatedColour.setPreferredSize(new Dimension(RADIO_WIDTH, 20));
596 graduatedColour.addItemListener(new ItemListener()
599 public void itemStateChanged(ItemEvent e)
601 if (graduatedColour.isSelected())
607 graduatedChoicePanel.add(graduatedColour);
609 List<String[]> attNames = FeatureAttributes.getInstance()
610 .getAttributes(featureType);
611 colourByRangeCombo = populateAttributesDropdown(attNames, true, false);
612 colourByRangeCombo.addItemListener(new ItemListener()
615 public void itemStateChanged(ItemEvent e)
622 * disable graduated colour option if no range found
624 graduatedColour.setEnabled(colourByRangeCombo.getItemCount() > 0);
626 graduatedChoicePanel.add(colourByRangeCombo);
627 graduatedColourPanel.add(graduatedChoicePanel);
630 * second row - min/max/no colours
632 JPanel colourRangePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
633 colourRangePanel.setBackground(Color.white);
634 graduatedColourPanel.add(colourRangePanel);
636 minColour.setFont(JvSwingUtils.getLabelFont());
637 minColour.setBorder(BorderFactory.createLineBorder(Color.black));
638 minColour.setPreferredSize(new Dimension(40, 20));
639 minColour.setToolTipText(MessageManager.getString("label.min_colour"));
640 minColour.addMouseListener(new MouseAdapter()
643 public void mousePressed(MouseEvent e)
645 if (minColour.isEnabled())
647 showColourChooser(minColour, "label.select_colour_minimum_value");
652 maxColour.setFont(JvSwingUtils.getLabelFont());
653 maxColour.setBorder(BorderFactory.createLineBorder(Color.black));
654 maxColour.setPreferredSize(new Dimension(40, 20));
655 maxColour.setToolTipText(MessageManager.getString("label.max_colour"));
656 maxColour.addMouseListener(new MouseAdapter()
659 public void mousePressed(MouseEvent e)
661 if (maxColour.isEnabled())
663 showColourChooser(maxColour, "label.select_colour_maximum_value");
667 maxColour.setBorder(new LineBorder(Color.black));
670 * if not set, default max colour to last plain colour,
671 * and make min colour a pale version of max colour
673 FeatureColourI originalColour = originalColours.get(featureType);
674 Color max = originalColour.getMaxColour();
677 max = originalColour.getColour();
678 minColour.setBackground(ColorUtils.bleachColour(max, 0.9f));
682 maxColour.setBackground(max);
683 minColour.setBackground(originalColour.getMinColour());
686 noValueCombo = new JComboBox<>();
687 noValueCombo.addItem(MessageManager.getString("label.no_colour"));
688 noValueCombo.addItem(MessageManager.getString("label.min_colour"));
689 noValueCombo.addItem(MessageManager.getString("label.max_colour"));
690 noValueCombo.addItemListener(new ItemListener()
693 public void itemStateChanged(ItemEvent e)
699 JLabel minText = new JLabel(
700 MessageManager.getString("label.min_value") + COLON);
701 minText.setFont(JvSwingUtils.getLabelFont());
702 JLabel maxText = new JLabel(
703 MessageManager.getString("label.max_value") + COLON);
704 maxText.setFont(JvSwingUtils.getLabelFont());
705 JLabel noText = new JLabel(
706 MessageManager.getString("label.no_value") + COLON);
707 noText.setFont(JvSwingUtils.getLabelFont());
709 colourRangePanel.add(minText);
710 colourRangePanel.add(minColour);
711 colourRangePanel.add(maxText);
712 colourRangePanel.add(maxColour);
713 colourRangePanel.add(noText);
714 colourRangePanel.add(noValueCombo);
717 * third row - threshold options and value
719 JPanel thresholdPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
720 thresholdPanel.setBackground(Color.white);
721 graduatedColourPanel.add(thresholdPanel);
723 threshold.addActionListener(changeColourAction);
724 threshold.setToolTipText(MessageManager
725 .getString("label.threshold_feature_display_by_score"));
726 threshold.addItem(MessageManager
727 .getString("label.threshold_feature_no_threshold")); // index 0
728 threshold.addItem(MessageManager
729 .getString("label.threshold_feature_above_threshold")); // index 1
730 threshold.addItem(MessageManager
731 .getString("label.threshold_feature_below_threshold")); // index 2
733 thresholdValue.addActionListener(new ActionListener()
736 public void actionPerformed(ActionEvent e)
738 thresholdValue_actionPerformed();
741 thresholdValue.addFocusListener(new FocusAdapter()
744 public void focusLost(FocusEvent e)
746 thresholdValue_actionPerformed();
749 slider.setPaintLabels(false);
750 slider.setPaintTicks(true);
751 slider.setBackground(Color.white);
752 slider.setEnabled(false);
753 slider.setOpaque(false);
754 slider.setPreferredSize(new Dimension(100, 32));
755 slider.setToolTipText(
756 MessageManager.getString("label.adjust_threshold"));
758 slider.addChangeListener(new ChangeListener()
761 public void stateChanged(ChangeEvent evt)
766 .setText(String.valueOf(slider.getValue() / scaleFactor));
767 thresholdValue.setBackground(Color.white); // to reset red for invalid
768 sliderValueChanged();
772 slider.addMouseListener(new MouseAdapter()
775 public void mouseReleased(MouseEvent evt)
778 * only update Overview and/or structure colouring
779 * when threshold slider drag ends (mouse up)
783 ap.paintAlignment(true, true);
788 thresholdValue.setEnabled(false);
789 thresholdValue.setColumns(7);
791 thresholdPanel.add(threshold);
792 thresholdPanel.add(slider);
793 thresholdPanel.add(thresholdValue);
795 thresholdIsMin.setBackground(Color.white);
797 .setText(MessageManager.getString("label.threshold_minmax"));
798 thresholdIsMin.setToolTipText(MessageManager
799 .getString("label.toggle_absolute_relative_display_threshold"));
800 thresholdIsMin.addActionListener(changeColourAction);
801 thresholdPanel.add(thresholdIsMin);
803 return graduatedColourPanel;
807 * Lay out OK and Cancel buttons
811 private JPanel initialiseOkCancelPanel()
813 JPanel okCancelPanel = new JPanel();
814 // okCancelPanel.setBackground(Color.white);
815 okCancelPanel.add(ok);
816 okCancelPanel.add(cancel);
817 return okCancelPanel;
821 * Lay out Colour options panel, containing
823 * <li>plain colour, with colour picker</li>
824 * <li>colour by text, with choice of Label or other attribute</li>
825 * <li>colour by range, of score or other attribute, when available</li>
830 private JPanel initialiseColoursPanel()
832 JPanel colourByPanel = new JPanel();
833 colourByPanel.setBackground(Color.white);
834 colourByPanel.setLayout(new BoxLayout(colourByPanel, BoxLayout.Y_AXIS));
835 JvSwingUtils.createTitledBorder(colourByPanel,
836 MessageManager.getString("action.colour"), true);
839 * option to apply colour to other selected types as well
841 if (!relatedSoTerms.isEmpty())
843 applyColourToSubtypes = false;
844 colourByPanel.add(initSubtypesPanel(false));
848 * simple colour radio button and colour picker
850 JPanel simpleColourPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
851 simpleColourPanel.setBackground(Color.white);
852 colourByPanel.add(simpleColourPanel);
854 simpleColour = new JRadioButton(
855 MessageManager.getString("label.simple_colour"));
856 simpleColour.setPreferredSize(new Dimension(RADIO_WIDTH, 20));
857 simpleColour.addItemListener(new ItemListener()
860 public void itemStateChanged(ItemEvent e)
862 if (simpleColour.isSelected() && !adjusting)
869 singleColour.setFont(JvSwingUtils.getLabelFont());
870 singleColour.setBorder(BorderFactory.createLineBorder(Color.black));
871 singleColour.setPreferredSize(new Dimension(40, 20));
872 FeatureColourI originalColour = originalColours.get(featureType);
873 singleColour.setBackground(originalColour.getColour());
874 singleColour.setForeground(originalColour.getColour());
876 singleColour.addMouseListener(new MouseAdapter()
879 public void mousePressed(MouseEvent e)
881 if (simpleColour.isSelected())
883 showColourChooser(singleColour, "label.select_colour");
887 simpleColourPanel.add(simpleColour); // radio button
888 simpleColourPanel.add(singleColour); // colour picker button
891 * colour by text (category) radio button and drop-down choice list
893 JPanel byTextPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
894 byTextPanel.setBackground(Color.white);
895 JvSwingUtils.createTitledBorder(byTextPanel,
896 MessageManager.getString("label.colour_by_text"), true);
897 colourByPanel.add(byTextPanel);
898 byCategory = new JRadioButton(
899 MessageManager.getString("label.by_text_of") + COLON);
900 byCategory.setPreferredSize(new Dimension(RADIO_WIDTH, 20));
901 byCategory.addItemListener(new ItemListener()
904 public void itemStateChanged(ItemEvent e)
906 if (byCategory.isSelected())
912 byTextPanel.add(byCategory);
914 List<String[]> attNames = FeatureAttributes.getInstance()
915 .getAttributes(featureType);
916 colourByTextCombo = populateAttributesDropdown(attNames, false, true);
917 colourByTextCombo.addItemListener(new ItemListener()
920 public void itemStateChanged(ItemEvent e)
925 byTextPanel.add(colourByTextCombo);
928 * graduated colour panel
930 JPanel graduatedColourPanel = initialiseGraduatedColourPanel();
931 colourByPanel.add(graduatedColourPanel);
934 * 3 radio buttons select between simple colour,
935 * by category (text), or graduated
937 ButtonGroup bg = new ButtonGroup();
938 bg.add(simpleColour);
940 bg.add(graduatedColour);
942 return colourByPanel;
946 * Constructs and returns a panel with the option to apply any changes also to
947 * sub-types of SO terms at or above the feature type
951 protected JPanel initSubtypesPanel(final boolean forFilters)
953 JPanel toSubtypes = new JPanel(new FlowLayout(FlowLayout.LEFT));
954 toSubtypes.setBackground(Color.WHITE);
957 * checkbox 'apply to sub-types of...'
959 JCheckBox applyToSubtypesCB = new JCheckBox(MessageManager
960 .formatMessage("label.apply_to_subtypes", rootSOTerm));
961 toSubtypes.add(applyToSubtypesCB);
964 * combobox to choose 'parent' of sub-types
966 List<String> soTerms = new ArrayList<>();
967 for (String term : relatedSoTerms.keySet())
971 // sort from most restrictive to most inclusive
972 Collections.sort(soTerms, new Comparator<String>()
975 public int compare(String o1, String o2)
977 return Integer.compare(relatedSoTerms.get(o1).size(),
978 relatedSoTerms.get(o2).size());
981 List<String> tooltips = new ArrayList<>();
982 for (String term : soTerms)
984 tooltips.add(getSOTermsTooltip(relatedSoTerms.get(term)));
986 JComboBox<String> parentType = JvSwingUtils
987 .buildComboWithTooltips(soTerms, tooltips);
988 toSubtypes.add(parentType);
991 * on toggle of checkbox, or change of parent SO term,
992 * reset and then reapply filters to the selected scope
994 final ActionListener action = new ActionListener()
997 * reset and reapply settings on toggle of checkbox
1000 public void actionPerformed(ActionEvent e)
1002 parentSOTerm = (String) parentType.getSelectedItem();
1005 applyFiltersToSubtypes = applyToSubtypesCB.isSelected();
1006 restoreOriginalFilters();
1011 applyColourToSubtypes = applyToSubtypesCB.isSelected();
1012 restoreOriginalColours();
1013 colourChanged(true);
1017 applyToSubtypesCB.addActionListener(action);
1018 parentType.addActionListener(action);
1023 private void showColourChooser(JPanel colourPanel, String key)
1025 Color col = JColorChooser.showDialog(this,
1026 MessageManager.getString(key), colourPanel.getBackground());
1029 colourPanel.setBackground(col);
1030 colourPanel.setForeground(col);
1032 colourPanel.repaint();
1033 colourChanged(true);
1037 * Constructs and sets the selected colour options as the colour for the
1038 * feature type, and repaints the alignment, and optionally the Overview
1039 * and/or structure viewer if open
1041 * @param updateStructsAndOverview
1043 void colourChanged(boolean updateStructsAndOverview)
1048 * ignore action handlers while setting values programmatically
1054 * ensure min-max range is for the latest choice of
1055 * 'graduated colour by'
1057 updateColourMinMax();
1059 FeatureColourI acg = makeColourFromInputs();
1062 * save the colour, and set on subtypes if selected
1064 fr.setColour(featureType, acg);
1065 if (applyColourToSubtypes)
1067 for (String child : relatedSoTerms.get(parentSOTerm))
1069 fr.setColour(child, acg);
1072 refreshFeatureSettings();
1073 ap.paintAlignment(updateStructsAndOverview, updateStructsAndOverview);
1079 * Converts the input values into an instance of FeatureColour
1083 private FeatureColourI makeColourFromInputs()
1086 * min-max range is to (or from) threshold value if
1087 * 'threshold is min/max' is selected
1093 thresh = Float.valueOf(thresholdValue.getText());
1094 } catch (NumberFormatException e)
1096 // invalid inputs are already handled on entry
1098 float minValue = min;
1099 float maxValue = max;
1100 final int thresholdOption = threshold.getSelectedIndex();
1101 if (thresholdIsMin.isSelected()
1102 && thresholdOption == ABOVE_THRESHOLD_OPTION)
1106 if (thresholdIsMin.isSelected()
1107 && thresholdOption == BELOW_THRESHOLD_OPTION)
1111 Color noColour = null;
1112 if (noValueCombo.getSelectedIndex() == MIN_COLOUR_OPTION)
1114 noColour = minColour.getBackground();
1116 else if (noValueCombo.getSelectedIndex() == MAX_COLOUR_OPTION)
1118 noColour = maxColour.getBackground();
1122 * construct a colour that 'remembers' all the options, including
1123 * those not currently selected
1125 FeatureColourI fc = new FeatureColour(singleColour.getBackground(),
1126 minColour.getBackground(), maxColour.getBackground(), noColour,
1127 minValue, maxValue);
1130 * easiest case - a single colour
1132 if (simpleColour.isSelected())
1134 ((FeatureColour) fc).setGraduatedColour(false);
1139 * next easiest case - colour by Label, or attribute text
1141 if (byCategory.isSelected())
1143 fc.setColourByLabel(true);
1144 String byWhat = (String) colourByTextCombo.getSelectedItem();
1145 if (!LABEL_18N.equals(byWhat))
1147 fc.setAttributeName(
1148 FeatureMatcher.fromAttributeDisplayName(byWhat));
1154 * remaining case - graduated colour by score, or attribute value;
1155 * set attribute to colour by if selected
1157 String byWhat = (String) colourByRangeCombo.getSelectedItem();
1158 if (!SCORE_18N.equals(byWhat))
1160 fc.setAttributeName(FeatureMatcher.fromAttributeDisplayName(byWhat));
1164 * set threshold options and 'autoscaled' which is
1165 * false if 'threshold is min/max' is selected
1166 * else true (colour range is on actual range of values)
1168 fc.setThreshold(thresh);
1169 fc.setAutoScaled(!thresholdIsMin.isSelected());
1170 fc.setAboveThreshold(thresholdOption == ABOVE_THRESHOLD_OPTION);
1171 fc.setBelowThreshold(thresholdOption == BELOW_THRESHOLD_OPTION);
1173 if (threshline == null)
1176 * todo not yet implemented: visual indication of feature threshold
1178 threshline = new GraphLine((max - min) / 2f, "Threshold",
1186 protected void raiseClosed()
1188 refreshFeatureSettings();
1191 protected void refreshFeatureSettings()
1193 if (this.featureSettings != null)
1195 featureSettings.actionPerformed(new ActionEvent(this, 0, "REFRESH"));
1200 * Action on OK is just to dismiss the dialog - any changes have already been
1204 public void okPressed()
1209 * Action on Cancel is to restore colour scheme and filters as they were when
1210 * the dialog was opened (including any feature sub-types that may have been
1214 public void cancelPressed()
1216 restoreOriginalColours();
1217 restoreOriginalFilters();
1218 ap.paintAlignment(true, true);
1222 * Restores filters for all feature types to their values when the dialog was
1225 protected void restoreOriginalFilters()
1227 for (Entry<String, FeatureMatcherSetI> entry : originalFilters
1230 fr.setFeatureFilter(entry.getKey(), entry.getValue());
1235 * Restores colours for all feature types to their values when the dialog was
1238 protected void restoreOriginalColours()
1240 for (Entry<String, FeatureColourI> entry : originalColours.entrySet())
1242 fr.setColour(entry.getKey(), entry.getValue());
1247 * Action on text entry of a threshold value
1249 protected void thresholdValue_actionPerformed()
1254 * set 'adjusting' flag while moving the slider, so it
1255 * doesn't then in turn change the value (with rounding)
1258 float f = Float.parseFloat(thresholdValue.getText());
1259 f = Float.max(f, this.min);
1260 f = Float.min(f, this.max);
1261 thresholdValue.setText(String.valueOf(f));
1262 slider.setValue((int) (f * scaleFactor));
1263 threshline.value = f;
1264 thresholdValue.setBackground(Color.white); // ok
1266 colourChanged(true);
1267 } catch (NumberFormatException ex)
1269 thresholdValue.setBackground(Color.red); // not ok
1275 * Action on change of threshold slider value. This may be done interactively
1276 * (by moving the slider), or programmatically (to update the slider after
1277 * manual input of a threshold value).
1279 protected void sliderValueChanged()
1281 threshline.value = getRoundedSliderValue();
1284 * repaint alignment, but not Overview or structure,
1285 * to avoid overload while dragging the slider
1287 colourChanged(false);
1291 * Converts the slider value to its absolute value by dividing by the
1292 * scaleFactor. Rounding errors are squashed by forcing min/max of slider
1293 * range to the actual min/max of feature score range
1297 private float getRoundedSliderValue()
1299 int value = slider.getValue();
1300 float f = value == slider.getMaximum() ? max
1301 : (value == slider.getMinimum() ? min : value / scaleFactor);
1305 void addActionListener(ActionListener listener)
1307 if (featureSettings != null)
1310 "IMPLEMENTATION ISSUE: overwriting action listener for FeatureColourChooser");
1312 featureSettings = listener;
1316 * A helper method to build the drop-down choice of attributes for a feature.
1317 * If 'withRange' is true, then Score, and any attributes with a min-max
1318 * range, are added. If 'withText' is true, Label and any known attributes are
1319 * added. This allows 'categorical numerical' attributes e.g. codon position
1320 * to be coloured by text.
1322 * Where metadata is available with a description for an attribute, that is
1323 * added as a tooltip.
1325 * Attribute names may be 'simple' e.g. "AC" or 'compound' e.g. {"CSQ",
1326 * "Allele"}. Compound names are rendered for display as (e.g.) CSQ:Allele.
1328 * This method does not add any ActionListener to the JComboBox.
1334 protected JComboBox<String> populateAttributesDropdown(
1335 List<String[]> attNames, boolean withRange, boolean withText)
1337 List<String> displayAtts = new ArrayList<>();
1338 List<String> tooltips = new ArrayList<>();
1342 displayAtts.add(LABEL_18N);
1343 tooltips.add(MessageManager.getString("label.description"));
1347 float[][] minMax = fr.getMinMax().get(featureType);
1348 if (minMax != null && minMax[0][0] != minMax[0][1])
1350 displayAtts.add(SCORE_18N);
1351 tooltips.add(SCORE_18N);
1355 FeatureAttributes fa = FeatureAttributes.getInstance();
1356 for (String[] attName : attNames)
1358 float[] minMax = fa.getMinMax(featureType, attName);
1359 boolean hasRange = minMax != null && minMax[0] != minMax[1];
1360 if (!withText && !hasRange)
1364 displayAtts.add(FeatureMatcher.toAttributeDisplayName(attName));
1365 String desc = fa.getDescription(featureType, attName);
1366 if (desc != null && desc.length() > MAX_TOOLTIP_LENGTH)
1368 desc = desc.substring(0, MAX_TOOLTIP_LENGTH) + "...";
1370 tooltips.add(desc == null ? "" : desc);
1373 JComboBox<String> attCombo = JvSwingUtils
1374 .buildComboWithTooltips(displayAtts, tooltips);
1380 * Populates initial layout of the feature attribute filters panel
1382 private JPanel initialiseFiltersPanel()
1384 filters = new ArrayList<>();
1386 JPanel outerPanel = new JPanel();
1387 outerPanel.setLayout(new BoxLayout(outerPanel, BoxLayout.Y_AXIS));
1388 outerPanel.setBackground(Color.white);
1391 * option to apply colour to other selected types as well
1393 if (!relatedSoTerms.isEmpty())
1395 applyFiltersToSubtypes = false;
1396 outerPanel.add(initSubtypesPanel(true));
1399 JPanel filtersPanel = new JPanel();
1400 filtersPanel.setLayout(new BoxLayout(filtersPanel, BoxLayout.Y_AXIS));
1401 filtersPanel.setBackground(Color.white);
1402 JvSwingUtils.createTitledBorder(filtersPanel,
1403 MessageManager.getString("label.filters"), true);
1404 outerPanel.add(filtersPanel);
1406 JPanel andOrPanel = initialiseAndOrPanel();
1407 filtersPanel.add(andOrPanel);
1410 * panel with filters - populated by refreshFiltersDisplay,
1411 * which also sets the layout manager
1413 chooseFiltersPanel = new JPanel();
1414 chooseFiltersPanel.setBackground(Color.white);
1415 filtersPanel.add(chooseFiltersPanel);
1421 * Lays out the panel with radio buttons to AND or OR filter conditions
1425 private JPanel initialiseAndOrPanel()
1427 JPanel andOrPanel = new JPanel(new BorderLayout());
1428 andOrPanel.setBackground(Color.white);
1430 andFilters = new JRadioButton(MessageManager.getString("label.and"));
1431 orFilters = new JRadioButton(MessageManager.getString("label.or"));
1432 ActionListener actionListener = new ActionListener()
1435 public void actionPerformed(ActionEvent e)
1440 andFilters.addActionListener(actionListener);
1441 orFilters.addActionListener(actionListener);
1442 ButtonGroup andOr = new ButtonGroup();
1443 andOr.add(andFilters);
1444 andOr.add(orFilters);
1445 andFilters.setSelected(true);
1447 new JLabel(MessageManager.getString("label.join_conditions")));
1448 andOrPanel.add(andFilters);
1449 andOrPanel.add(orFilters);
1455 * Builds a tooltip for the 'Apply also to...' combobox with a list of known
1456 * feature types (excluding the current type) which are sub-types of the
1457 * selected Sequence Ontology term
1462 protected String getSOTermsTooltip(List<String> list)
1464 StringBuilder sb = new StringBuilder(20 * relatedSoTerms.size());
1465 sb.append(MessageManager.getString("label.apply_also_to"));
1466 for (String child : list)
1468 sb.append("<br>").append(child);
1470 String tooltip = JvSwingUtils.wrapTooltip(true, sb.toString());
1475 * Refreshes the display to show any filters currently configured for the
1476 * selected feature type (editable, with 'remove' option), plus one extra row
1477 * for adding a condition. This should be called after a filter has been
1478 * removed, added or amended.
1480 private void updateFiltersTab()
1483 * clear the panel and list of filter conditions
1485 chooseFiltersPanel.removeAll();
1489 * look up attributes known for feature type
1491 List<String[]> attNames = FeatureAttributes.getInstance()
1492 .getAttributes(featureType);
1495 * if this feature type has filters set, load them first
1497 FeatureMatcherSetI featureFilters = fr.getFeatureFilter(featureType);
1498 if (featureFilters != null)
1500 if (!featureFilters.isAnded())
1502 orFilters.setSelected(true);
1504 featureFilters.getMatchers().forEach(matcher -> filters.add(matcher));
1508 * and an empty filter for the user to populate (add)
1510 filters.add(FeatureMatcher.NULL_MATCHER);
1513 * use GridLayout to 'justify' rows to the top of the panel, until
1514 * there are too many to fit in, then fall back on BoxLayout
1516 if (filters.size() <= 5)
1518 chooseFiltersPanel.setLayout(new GridLayout(5, 1));
1522 chooseFiltersPanel.setLayout(
1523 new BoxLayout(chooseFiltersPanel, BoxLayout.Y_AXIS));
1527 * render the conditions in rows, each in its own JPanel
1529 int filterIndex = 0;
1530 for (FeatureMatcherI filter : filters)
1532 JPanel row = addFilter(filter, attNames, filterIndex);
1533 chooseFiltersPanel.add(row);
1542 * A helper method that constructs a row (panel) with one filter condition:
1544 * <li>a drop-down list of Label, Score and attribute names to choose
1546 * <li>a drop-down list of conditions to choose from</li>
1547 * <li>a text field for input of a match pattern</li>
1548 * <li>optionally, a 'remove' button</li>
1550 * The filter values are set as defaults for the input fields. The 'remove'
1551 * button is added unless the pattern is empty (incomplete filter condition).
1553 * Action handlers on these fields provide for
1555 * <li>validate pattern field - should be numeric if condition is numeric</li>
1556 * <li>save filters and refresh display on any (valid) change</li>
1557 * <li>remove filter and refresh on 'Remove'</li>
1558 * <li>update conditions list on change of Label/Score/Attribute</li>
1559 * <li>refresh value field tooltip with min-max range on change of
1565 * @param filterIndex
1568 protected JPanel addFilter(FeatureMatcherI filter,
1569 List<String[]> attNames, int filterIndex)
1571 String[] attName = filter.getAttribute();
1572 Condition cond = filter.getMatcher().getCondition();
1573 String pattern = filter.getMatcher().getPattern();
1575 JPanel filterRow = new JPanel(new FlowLayout(FlowLayout.LEFT));
1576 filterRow.setBackground(Color.white);
1579 * drop-down choice of attribute, with description as a tooltip
1580 * if we can obtain it
1582 final JComboBox<String> attCombo = populateAttributesDropdown(attNames,
1584 String filterBy = setSelectedAttribute(attCombo, filter);
1586 JComboBox<Condition> condCombo = new JComboBox<>();
1588 JTextField patternField = new JTextField(8);
1589 patternField.setText(pattern);
1592 * action handlers that validate and (if valid) apply changes
1594 ActionListener actionListener = new ActionListener()
1597 public void actionPerformed(ActionEvent e)
1599 if (validateFilter(patternField, condCombo))
1601 if (updateFilter(attCombo, condCombo, patternField, filterIndex))
1608 ItemListener itemListener = new ItemListener()
1611 public void itemStateChanged(ItemEvent e)
1613 actionListener.actionPerformed(null);
1617 if (filter == FeatureMatcher.NULL_MATCHER) // the 'add a condition' row
1619 attCombo.setSelectedIndex(0);
1623 attCombo.setSelectedItem(
1624 FeatureMatcher.toAttributeDisplayName(attName));
1626 attCombo.addItemListener(new ItemListener()
1629 public void itemStateChanged(ItemEvent e)
1632 * on change of attribute, refresh the conditions list to
1633 * ensure it is appropriate for the attribute datatype
1635 populateConditions((String) attCombo.getSelectedItem(),
1636 (Condition) condCombo.getSelectedItem(), condCombo,
1638 actionListener.actionPerformed(null);
1642 filterRow.add(attCombo);
1645 * drop-down choice of test condition
1647 populateConditions(filterBy, cond, condCombo, patternField);
1648 condCombo.setPreferredSize(new Dimension(150, 20));
1649 condCombo.addItemListener(itemListener);
1650 filterRow.add(condCombo);
1653 * pattern to match against
1655 patternField.addActionListener(actionListener);
1656 patternField.addFocusListener(new FocusAdapter()
1659 public void focusLost(FocusEvent e)
1661 actionListener.actionPerformed(null);
1664 filterRow.add(patternField);
1667 * disable pattern field for condition 'Present / NotPresent'
1669 Condition selectedCondition = (Condition) condCombo.getSelectedItem();
1670 patternField.setEnabled(selectedCondition.needsAPattern());
1673 * if a numeric condition is selected, show the value range
1674 * as a tooltip on the value input field
1676 setNumericHints(filterBy, selectedCondition, patternField);
1679 * add remove button if filter is populated (non-empty pattern)
1681 if (!patternField.isEnabled()
1682 || (pattern != null && pattern.trim().length() > 0))
1684 // todo: gif for button drawing '-' or 'x'
1685 JButton removeCondition = new BasicArrowButton(SwingConstants.WEST);
1687 .setToolTipText(MessageManager.getString("label.delete_row"));
1688 removeCondition.addActionListener(new ActionListener()
1691 public void actionPerformed(ActionEvent e)
1693 filters.remove(filterIndex);
1697 filterRow.add(removeCondition);
1704 * Sets the selected item in the Label/Score/Attribute drop-down to match the
1710 private String setSelectedAttribute(JComboBox<String> attCombo,
1711 FeatureMatcherI filter)
1714 if (filter.isByScore())
1718 else if (filter.isByLabel())
1724 item = FeatureMatcher.toAttributeDisplayName(filter.getAttribute());
1726 attCombo.setSelectedItem(item);
1731 * If a numeric comparison condition is selected, retrieves the min-max range
1732 * for the value (score or attribute), and sets it as a tooltip on the value
1733 * field. If the field is currently empty, then pre-populates it with
1735 * <li>the minimum value, if condition is > or >=</li>
1736 * <li>the maximum value, if condition is < or <=</li>
1740 * @param selectedCondition
1741 * @param patternField
1743 private void setNumericHints(String attName, Condition selectedCondition,
1744 JTextField patternField)
1746 patternField.setToolTipText("");
1748 if (selectedCondition.isNumeric())
1750 float[] minMax = getMinMax(attName);
1753 String minFormatted = DECFMT_2_2.format(minMax[0]);
1754 String maxFormatted = DECFMT_2_2.format(minMax[1]);
1755 String tip = String.format("(%s - %s)", minFormatted, maxFormatted);
1756 patternField.setToolTipText(tip);
1757 if (patternField.getText().isEmpty())
1759 if (selectedCondition == Condition.GE
1760 || selectedCondition == Condition.GT)
1762 patternField.setText(minFormatted);
1766 if (selectedCondition == Condition.LE
1767 || selectedCondition == Condition.LT)
1769 patternField.setText(maxFormatted);
1778 * Populates the drop-down list of comparison conditions for the given
1779 * attribute name. The conditions added depend on the datatype of the
1780 * attribute values. The supplied condition is set as the selected item in the
1781 * list, provided it is in the list. If the pattern is now invalid
1782 * (non-numeric pattern for a numeric condition), it is cleared.
1787 * @param patternField
1789 private void populateConditions(String attName, Condition cond,
1790 JComboBox<Condition> condCombo, JTextField patternField)
1792 Datatype type = FeatureAttributes.getInstance().getDatatype(featureType,
1793 FeatureMatcher.fromAttributeDisplayName(attName));
1794 if (LABEL_18N.equals(attName))
1796 type = Datatype.Character;
1798 else if (SCORE_18N.equals(attName))
1800 type = Datatype.Number;
1804 * remove itemListener before starting
1806 ItemListener listener = condCombo.getItemListeners()[0];
1807 condCombo.removeItemListener(listener);
1808 boolean condIsValid = false;
1810 condCombo.removeAllItems();
1811 for (Condition c : Condition.values())
1813 if ((c.isNumeric() && type == Datatype.Number)
1814 || (!c.isNumeric() && type != Datatype.Number))
1816 condCombo.addItem(c);
1825 * set the selected condition (does nothing if not in the list)
1829 condCombo.setSelectedItem(cond);
1833 condCombo.setSelectedIndex(0);
1837 * clear pattern if it is now invalid for condition
1839 if (((Condition) condCombo.getSelectedItem()).isNumeric())
1843 String pattern = patternField.getText().trim();
1844 if (pattern.length() > 0)
1846 Float.valueOf(pattern);
1848 } catch (NumberFormatException e)
1850 patternField.setText("");
1855 * restore the listener
1857 condCombo.addItemListener(listener);
1861 * Answers true unless a numeric condition has been selected with a
1862 * non-numeric value. Sets the value field to RED with a tooltip if in error.
1864 * If the pattern is expected but is empty, this method returns false, but
1865 * does not mark the field as invalid. This supports selecting an attribute
1866 * for a new condition before a match pattern has been entered.
1871 protected boolean validateFilter(JTextField value,
1872 JComboBox<Condition> condCombo)
1874 if (value == null || condCombo == null)
1876 return true; // fields not populated
1879 Condition cond = (Condition) condCombo.getSelectedItem();
1880 if (!cond.needsAPattern())
1885 value.setBackground(Color.white);
1886 value.setToolTipText("");
1887 String v1 = value.getText().trim();
1888 if (v1.length() == 0)
1893 if (cond.isNumeric() && v1.length() > 0)
1898 } catch (NumberFormatException e)
1900 value.setBackground(Color.red);
1901 value.setToolTipText(
1902 MessageManager.getString("label.numeric_required"));
1911 * Constructs a filter condition from the given input fields, and replaces the
1912 * condition at filterIndex with the new one. Does nothing if the pattern
1913 * field is blank (unless the match condition is one that doesn't require a
1914 * pattern, e.g. 'Is present'). Answers true if the filter was updated, else
1917 * This method may update the tooltip on the filter value field to show the
1918 * value range, if a numeric condition is selected. This ensures the tooltip
1919 * is updated when a numeric valued attribute is chosen on the last 'add a
1925 * @param filterIndex
1927 protected boolean updateFilter(JComboBox<String> attCombo,
1928 JComboBox<Condition> condCombo, JTextField valueField,
1931 String attName = (String) attCombo.getSelectedItem();
1932 Condition cond = (Condition) condCombo.getSelectedItem();
1933 String pattern = valueField.getText().trim();
1935 setNumericHints(attName, cond, valueField);
1937 if (pattern.length() == 0 && cond.needsAPattern())
1939 valueField.setEnabled(true); // ensure pattern field is enabled!
1944 * Construct a matcher that operates on Label, Score,
1945 * or named attribute
1947 FeatureMatcherI km = null;
1948 if (LABEL_18N.equals(attName))
1950 km = FeatureMatcher.byLabel(cond, pattern);
1952 else if (SCORE_18N.equals(attName))
1954 km = FeatureMatcher.byScore(cond, pattern);
1958 km = FeatureMatcher.byAttribute(cond, pattern,
1959 FeatureMatcher.fromAttributeDisplayName(attName));
1962 filters.set(filterIndex, km);
1968 * Action on any change to feature filtering, namely
1970 * <li>change of selected attribute</li>
1971 * <li>change of selected condition</li>
1972 * <li>change of match pattern</li>
1973 * <li>removal of a condition</li>
1975 * The inputs are parsed into a combined filter and this is set for the
1976 * feature type, and the alignment redrawn.
1978 protected void filtersChanged()
1981 * update the filter conditions for the feature type
1983 boolean anded = andFilters.isSelected();
1984 FeatureMatcherSetI combined = new FeatureMatcherSet();
1986 for (FeatureMatcherI filter : filters)
1988 String pattern = filter.getMatcher().getPattern();
1989 Condition condition = filter.getMatcher().getCondition();
1990 if (pattern.trim().length() > 0 || !condition.needsAPattern())
1994 combined.and(filter);
1998 combined.or(filter);
2004 * save the filter conditions in the FeatureRenderer
2005 * (note this might now be an empty filter with no conditions)
2007 fr.setFeatureFilter(featureType, combined.isEmpty() ? null : combined);
2008 if (applyFiltersToSubtypes)
2010 for (String child : relatedSoTerms.get(parentSOTerm))
2012 fr.setFeatureFilter(child, combined.isEmpty() ? null : combined);
2016 refreshFeatureSettings();
2017 ap.paintAlignment(true, true);