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.border.EmptyBorder;
74 import javax.swing.border.LineBorder;
75 import javax.swing.event.ChangeEvent;
76 import javax.swing.event.ChangeListener;
79 * A dialog where the user can configure colour scheme, and any filters, for one
82 * (Was FeatureColourChooser prior to Jalview 1.11, renamed with the addition of
85 public class FeatureTypeSettings extends JalviewDialog
87 private final static String LABEL_18N = MessageManager
88 .getString("label.label");
90 private final static String SCORE_18N = MessageManager
91 .getString("label.score");
93 private static final int RADIO_WIDTH = 130;
95 private static final String COLON = ":";
97 private static final int MAX_TOOLTIP_LENGTH = 50;
99 private static final int NO_COLOUR_OPTION = 0;
101 private static final int MIN_COLOUR_OPTION = 1;
103 private static final int MAX_COLOUR_OPTION = 2;
105 private static final int ABOVE_THRESHOLD_OPTION = 1;
107 private static final int BELOW_THRESHOLD_OPTION = 2;
109 private static final DecimalFormat DECFMT_2_2 = new DecimalFormat(
113 * FeatureRenderer holds colour scheme and filters for feature types
115 private final FeatureRenderer fr; // todo refactor to allow interface type
119 * the view panel to update when settings change
121 private final AlignmentViewPanel ap;
123 private final String featureType;
126 * the colour and filters to reset to on Cancel
127 * (including feature sub-types if modified)
129 private Map<String, FeatureColourI> originalColours;
131 private Map<String, FeatureMatcherSetI> originalFilters;
134 * set flag to true when setting values programmatically,
135 * to avoid invocation of action handlers
137 private boolean adjusting = false;
140 * minimum of the value range for graduated colour
141 * (may be for feature score or for a numeric attribute)
146 * maximum of the value range for graduated colour
151 * scale factor for conversion between absolute min-max and slider
153 private float scaleFactor;
156 * radio button group, to select what to colour by:
157 * simple colour, by category (text), or graduated
159 private JRadioButton simpleColour = new JRadioButton();
161 private JRadioButton byCategory = new JRadioButton();
163 private JRadioButton graduatedColour = new JRadioButton();
166 * colours and filters are shown in tabbed view or single content pane
168 JPanel coloursPanel, filtersPanel;
170 JPanel singleColour = new JPanel();
172 private JPanel minColour = new JPanel();
174 private JPanel maxColour = new JPanel();
176 private JComboBox<String> threshold = new JComboBox<>();
178 private JSlider slider = new JSlider();
180 private JTextField thresholdValue = new JTextField(20);
182 private JCheckBox thresholdIsMin = new JCheckBox();
184 private GraphLine threshline;
186 private ActionListener featureSettings = null;
188 private ActionListener changeColourAction;
191 * choice of option for 'colour for no value'
193 private JComboBox<String> noValueCombo;
196 * choice of what to colour by text (Label or attribute)
198 private JComboBox<String> colourByTextCombo;
201 * choice of what to colour by range (Score or attribute)
203 private JComboBox<String> colourByRangeCombo;
205 private JRadioButton andFilters;
207 private JRadioButton orFilters;
210 * filters for the currently selected feature type
212 private List<FeatureMatcherI> filters;
214 private JPanel chooseFiltersPanel;
217 * the root Sequence Ontology terms (if any) that is a parent of
218 * the current feature type
220 private String rootSOTerm;
223 * a map whose keys are Sequence Ontology terms - selected from the
224 * current term and its parents in the SO - whose subterms include
225 * additional feature types; the map entry is the list of additional
226 * feature types that match the key or have it as a parent term; in
227 * other words, distinct 'aggregations' that include the current feature type
229 private final Map<String, List<String>> relatedSoTerms;
232 * if true, filter or colour settings are also applied to
233 * any sub-types of parentTerm in the Sequence Ontology
235 private boolean applyFiltersToSubtypes;
237 private boolean applyColourToSubtypes;
239 private String parentSOTerm;
247 public FeatureTypeSettings(FeatureRenderer frender, String theType)
250 this.featureType = theType;
253 SequenceOntologyI so = SequenceOntologyFactory.getInstance();
254 relatedSoTerms = so.findSequenceOntologyGroupings(
255 this.featureType, 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);
963 .setToolTipText(MessageManager.getString("label.group_by_so"));
966 * combobox to choose 'parent' of sub-types
968 List<String> soTerms = new ArrayList<>();
969 for (String term : relatedSoTerms.keySet())
973 // sort from most restrictive to most inclusive
974 Collections.sort(soTerms, new Comparator<String>()
977 public int compare(String o1, String o2)
979 return Integer.compare(relatedSoTerms.get(o1).size(),
980 relatedSoTerms.get(o2).size());
983 List<String> tooltips = new ArrayList<>();
984 for (String term : soTerms)
986 tooltips.add(getSOTermsTooltip(relatedSoTerms.get(term)));
988 JComboBox<String> parentType = JvSwingUtils
989 .buildComboWithTooltips(soTerms, tooltips);
990 toSubtypes.add(parentType);
993 * on toggle of checkbox, or change of parent SO term,
994 * reset and then reapply filters to the selected scope
996 final ActionListener action = new ActionListener()
999 * reset and reapply settings on toggle of checkbox
1002 public void actionPerformed(ActionEvent e)
1004 parentSOTerm = (String) parentType.getSelectedItem();
1007 applyFiltersToSubtypes = applyToSubtypesCB.isSelected();
1008 restoreOriginalFilters();
1013 applyColourToSubtypes = applyToSubtypesCB.isSelected();
1014 restoreOriginalColours();
1015 colourChanged(true);
1019 applyToSubtypesCB.addActionListener(action);
1020 parentType.addActionListener(action);
1025 private void showColourChooser(JPanel colourPanel, String key)
1027 Color col = JColorChooser.showDialog(this,
1028 MessageManager.getString(key), colourPanel.getBackground());
1031 colourPanel.setBackground(col);
1032 colourPanel.setForeground(col);
1034 colourPanel.repaint();
1035 colourChanged(true);
1039 * Constructs and sets the selected colour options as the colour for the
1040 * feature type, and repaints the alignment, and optionally the Overview
1041 * and/or structure viewer if open
1043 * @param updateStructsAndOverview
1045 void colourChanged(boolean updateStructsAndOverview)
1050 * ignore action handlers while setting values programmatically
1056 * ensure min-max range is for the latest choice of
1057 * 'graduated colour by'
1059 updateColourMinMax();
1061 FeatureColourI acg = makeColourFromInputs();
1064 * save the colour, and set on subtypes if selected
1066 fr.setColour(featureType, acg);
1067 if (applyColourToSubtypes)
1069 for (String child : relatedSoTerms.get(parentSOTerm))
1071 fr.setColour(child, acg);
1074 refreshFeatureSettings();
1075 ap.paintAlignment(updateStructsAndOverview, updateStructsAndOverview);
1081 * Converts the input values into an instance of FeatureColour
1085 private FeatureColourI makeColourFromInputs()
1088 * min-max range is to (or from) threshold value if
1089 * 'threshold is min/max' is selected
1095 thresh = Float.valueOf(thresholdValue.getText());
1096 } catch (NumberFormatException e)
1098 // invalid inputs are already handled on entry
1100 float minValue = min;
1101 float maxValue = max;
1102 final int thresholdOption = threshold.getSelectedIndex();
1103 if (thresholdIsMin.isSelected()
1104 && thresholdOption == ABOVE_THRESHOLD_OPTION)
1108 if (thresholdIsMin.isSelected()
1109 && thresholdOption == BELOW_THRESHOLD_OPTION)
1113 Color noColour = null;
1114 if (noValueCombo.getSelectedIndex() == MIN_COLOUR_OPTION)
1116 noColour = minColour.getBackground();
1118 else if (noValueCombo.getSelectedIndex() == MAX_COLOUR_OPTION)
1120 noColour = maxColour.getBackground();
1124 * construct a colour that 'remembers' all the options, including
1125 * those not currently selected
1127 FeatureColourI fc = new FeatureColour(singleColour.getBackground(),
1128 minColour.getBackground(), maxColour.getBackground(), noColour,
1129 minValue, maxValue);
1132 * easiest case - a single colour
1134 if (simpleColour.isSelected())
1136 ((FeatureColour) fc).setGraduatedColour(false);
1141 * next easiest case - colour by Label, or attribute text
1143 if (byCategory.isSelected())
1145 fc.setColourByLabel(true);
1146 String byWhat = (String) colourByTextCombo.getSelectedItem();
1147 if (!LABEL_18N.equals(byWhat))
1149 fc.setAttributeName(
1150 FeatureMatcher.fromAttributeDisplayName(byWhat));
1156 * remaining case - graduated colour by score, or attribute value;
1157 * set attribute to colour by if selected
1159 String byWhat = (String) colourByRangeCombo.getSelectedItem();
1160 if (!SCORE_18N.equals(byWhat))
1162 fc.setAttributeName(FeatureMatcher.fromAttributeDisplayName(byWhat));
1166 * set threshold options and 'autoscaled' which is
1167 * false if 'threshold is min/max' is selected
1168 * else true (colour range is on actual range of values)
1170 fc.setThreshold(thresh);
1171 fc.setAutoScaled(!thresholdIsMin.isSelected());
1172 fc.setAboveThreshold(thresholdOption == ABOVE_THRESHOLD_OPTION);
1173 fc.setBelowThreshold(thresholdOption == BELOW_THRESHOLD_OPTION);
1175 if (threshline == null)
1178 * todo not yet implemented: visual indication of feature threshold
1180 threshline = new GraphLine((max - min) / 2f, "Threshold",
1188 protected void raiseClosed()
1190 refreshFeatureSettings();
1193 protected void refreshFeatureSettings()
1195 if (this.featureSettings != null)
1197 featureSettings.actionPerformed(new ActionEvent(this, 0, "REFRESH"));
1202 * Action on OK is just to dismiss the dialog - any changes have already been
1206 public void okPressed()
1211 * Action on Cancel is to restore colour scheme and filters as they were when
1212 * the dialog was opened (including any feature sub-types that may have been
1216 public void cancelPressed()
1218 restoreOriginalColours();
1219 restoreOriginalFilters();
1220 ap.paintAlignment(true, true);
1224 * Restores filters for all feature types to their values when the dialog was
1227 protected void restoreOriginalFilters()
1229 for (Entry<String, FeatureMatcherSetI> entry : originalFilters
1232 fr.setFeatureFilter(entry.getKey(), entry.getValue());
1237 * Restores colours for all feature types to their values when the dialog was
1240 protected void restoreOriginalColours()
1242 for (Entry<String, FeatureColourI> entry : originalColours.entrySet())
1244 fr.setColour(entry.getKey(), entry.getValue());
1249 * Action on text entry of a threshold value
1251 protected void thresholdValue_actionPerformed()
1256 * set 'adjusting' flag while moving the slider, so it
1257 * doesn't then in turn change the value (with rounding)
1260 float f = Float.parseFloat(thresholdValue.getText());
1261 f = Float.max(f, this.min);
1262 f = Float.min(f, this.max);
1263 thresholdValue.setText(String.valueOf(f));
1264 slider.setValue((int) (f * scaleFactor));
1265 threshline.value = f;
1266 thresholdValue.setBackground(Color.white); // ok
1268 colourChanged(true);
1269 } catch (NumberFormatException ex)
1271 thresholdValue.setBackground(Color.red); // not ok
1277 * Action on change of threshold slider value. This may be done interactively
1278 * (by moving the slider), or programmatically (to update the slider after
1279 * manual input of a threshold value).
1281 protected void sliderValueChanged()
1283 threshline.value = getRoundedSliderValue();
1286 * repaint alignment, but not Overview or structure,
1287 * to avoid overload while dragging the slider
1289 colourChanged(false);
1293 * Converts the slider value to its absolute value by dividing by the
1294 * scaleFactor. Rounding errors are squashed by forcing min/max of slider
1295 * range to the actual min/max of feature score range
1299 private float getRoundedSliderValue()
1301 int value = slider.getValue();
1302 float f = value == slider.getMaximum() ? max
1303 : (value == slider.getMinimum() ? min : value / scaleFactor);
1307 void addActionListener(ActionListener listener)
1309 if (featureSettings != null)
1312 "IMPLEMENTATION ISSUE: overwriting action listener for FeatureColourChooser");
1314 featureSettings = listener;
1318 * A helper method to build the drop-down choice of attributes for a feature.
1319 * If 'withRange' is true, then Score, and any attributes with a min-max
1320 * range, are added. If 'withText' is true, Label and any known attributes are
1321 * added. This allows 'categorical numerical' attributes e.g. codon position
1322 * to be coloured by text.
1324 * Where metadata is available with a description for an attribute, that is
1325 * added as a tooltip.
1327 * Attribute names may be 'simple' e.g. "AC" or 'compound' e.g. {"CSQ",
1328 * "Allele"}. Compound names are rendered for display as (e.g.) CSQ:Allele.
1330 * This method does not add any ActionListener to the JComboBox.
1336 protected JComboBox<String> populateAttributesDropdown(
1337 List<String[]> attNames, boolean withRange, boolean withText)
1339 List<String> displayAtts = new ArrayList<>();
1340 List<String> tooltips = new ArrayList<>();
1344 displayAtts.add(LABEL_18N);
1345 tooltips.add(MessageManager.getString("label.description"));
1349 float[][] minMax = fr.getMinMax().get(featureType);
1350 if (minMax != null && minMax[0][0] != minMax[0][1])
1352 displayAtts.add(SCORE_18N);
1353 tooltips.add(SCORE_18N);
1357 FeatureAttributes fa = FeatureAttributes.getInstance();
1358 for (String[] attName : attNames)
1360 float[] minMax = fa.getMinMax(featureType, attName);
1361 boolean hasRange = minMax != null && minMax[0] != minMax[1];
1362 if (!withText && !hasRange)
1366 displayAtts.add(FeatureMatcher.toAttributeDisplayName(attName));
1367 String desc = fa.getDescription(featureType, attName);
1368 if (desc != null && desc.length() > MAX_TOOLTIP_LENGTH)
1370 desc = desc.substring(0, MAX_TOOLTIP_LENGTH) + "...";
1372 tooltips.add(desc == null ? "" : desc);
1375 JComboBox<String> attCombo = JvSwingUtils
1376 .buildComboWithTooltips(displayAtts, tooltips);
1382 * Populates initial layout of the feature attribute filters panel
1384 private JPanel initialiseFiltersPanel()
1386 filters = new ArrayList<>();
1388 JPanel outerPanel = new JPanel();
1389 outerPanel.setLayout(new BoxLayout(outerPanel, BoxLayout.Y_AXIS));
1390 outerPanel.setBackground(Color.white);
1393 * option to apply colour to other selected types as well
1395 if (!relatedSoTerms.isEmpty())
1397 applyFiltersToSubtypes = false;
1398 outerPanel.add(initSubtypesPanel(true));
1401 JPanel filtersPanel = new JPanel();
1402 filtersPanel.setLayout(new BoxLayout(filtersPanel, BoxLayout.Y_AXIS));
1403 filtersPanel.setBackground(Color.white);
1404 JvSwingUtils.createTitledBorder(filtersPanel,
1405 MessageManager.getString("label.filters"), true);
1406 outerPanel.add(filtersPanel);
1408 JPanel andOrPanel = initialiseAndOrPanel();
1409 filtersPanel.add(andOrPanel);
1412 * panel with filters - populated by refreshFiltersDisplay,
1413 * which also sets the layout manager
1415 chooseFiltersPanel = new JPanel();
1416 chooseFiltersPanel.setBackground(Color.white);
1417 filtersPanel.add(chooseFiltersPanel);
1423 * Lays out the panel with radio buttons to AND or OR filter conditions
1427 private JPanel initialiseAndOrPanel()
1429 JPanel andOrPanel = new JPanel(new BorderLayout());
1430 andOrPanel.setBackground(Color.white);
1432 andFilters = new JRadioButton(MessageManager.getString("label.and"));
1433 orFilters = new JRadioButton(MessageManager.getString("label.or"));
1434 ActionListener actionListener = new ActionListener()
1437 public void actionPerformed(ActionEvent e)
1442 andFilters.addActionListener(actionListener);
1443 orFilters.addActionListener(actionListener);
1444 ButtonGroup andOr = new ButtonGroup();
1445 andOr.add(andFilters);
1446 andOr.add(orFilters);
1447 andFilters.setSelected(true);
1449 new JLabel(MessageManager.getString("label.join_conditions")));
1450 andOrPanel.add(andFilters);
1451 andOrPanel.add(orFilters);
1457 * Builds a tooltip for the 'Apply also to...' combobox with a list of known
1458 * feature types (excluding the current type) which are sub-types of the
1459 * selected Sequence Ontology term
1464 protected String getSOTermsTooltip(List<String> list)
1466 StringBuilder sb = new StringBuilder(20 * relatedSoTerms.size());
1467 sb.append(MessageManager.getString("label.apply_also_to"));
1468 for (String child : list)
1470 sb.append("<br>").append(child);
1472 String tooltip = JvSwingUtils.wrapTooltip(true, sb.toString());
1477 * Refreshes the display to show any filters currently configured for the
1478 * selected feature type (editable, with 'remove' option), plus one extra row
1479 * for adding a condition. This should be called after a filter has been
1480 * removed, added or amended.
1482 private void updateFiltersTab()
1485 * clear the panel and list of filter conditions
1487 chooseFiltersPanel.removeAll();
1491 * look up attributes known for feature type
1493 List<String[]> attNames = FeatureAttributes.getInstance()
1494 .getAttributes(featureType);
1497 * if this feature type has filters set, load them first
1499 FeatureMatcherSetI featureFilters = fr.getFeatureFilter(featureType);
1500 if (featureFilters != null)
1502 if (!featureFilters.isAnded())
1504 orFilters.setSelected(true);
1506 featureFilters.getMatchers().forEach(matcher -> filters.add(matcher));
1510 * and an empty filter for the user to populate (add)
1512 filters.add(FeatureMatcher.NULL_MATCHER);
1515 * use GridLayout to 'justify' rows to the top of the panel, until
1516 * there are too many to fit in, then fall back on BoxLayout
1518 if (filters.size() <= 5)
1520 chooseFiltersPanel.setLayout(new GridLayout(5, 1));
1524 chooseFiltersPanel.setLayout(
1525 new BoxLayout(chooseFiltersPanel, BoxLayout.Y_AXIS));
1529 * render the conditions in rows, each in its own JPanel
1531 int filterIndex = 0;
1532 for (FeatureMatcherI filter : filters)
1534 JPanel row = addFilter(filter, attNames, filterIndex);
1535 chooseFiltersPanel.add(row);
1544 * A helper method that constructs a row (panel) with one filter condition:
1546 * <li>a drop-down list of Label, Score and attribute names to choose
1548 * <li>a drop-down list of conditions to choose from</li>
1549 * <li>a text field for input of a match pattern</li>
1550 * <li>optionally, a 'remove' button</li>
1552 * The filter values are set as defaults for the input fields. The 'remove'
1553 * button is added unless the pattern is empty (incomplete filter condition).
1555 * Action handlers on these fields provide for
1557 * <li>validate pattern field - should be numeric if condition is numeric</li>
1558 * <li>save filters and refresh display on any (valid) change</li>
1559 * <li>remove filter and refresh on 'Remove'</li>
1560 * <li>update conditions list on change of Label/Score/Attribute</li>
1561 * <li>refresh value field tooltip with min-max range on change of
1567 * @param filterIndex
1570 protected JPanel addFilter(FeatureMatcherI filter,
1571 List<String[]> attNames, int filterIndex)
1573 String[] attName = filter.getAttribute();
1574 Condition cond = filter.getMatcher().getCondition();
1575 String pattern = filter.getMatcher().getPattern();
1577 JPanel filterRow = new JPanel(new FlowLayout(FlowLayout.LEFT));
1578 filterRow.setBackground(Color.white);
1581 * drop-down choice of attribute, with description as a tooltip
1582 * if we can obtain it
1584 final JComboBox<String> attCombo = populateAttributesDropdown(attNames,
1586 String filterBy = setSelectedAttribute(attCombo, filter);
1588 JComboBox<Condition> condCombo = new JComboBox<>();
1590 JTextField patternField = new JTextField(8);
1591 patternField.setText(pattern);
1594 * action handlers that validate and (if valid) apply changes
1596 ActionListener actionListener = new ActionListener()
1599 public void actionPerformed(ActionEvent e)
1601 if (validateFilter(patternField, condCombo))
1603 if (updateFilter(attCombo, condCombo, patternField, filterIndex))
1610 ItemListener itemListener = new ItemListener()
1613 public void itemStateChanged(ItemEvent e)
1615 actionListener.actionPerformed(null);
1619 if (filter == FeatureMatcher.NULL_MATCHER) // the 'add a condition' row
1621 attCombo.setSelectedIndex(0);
1625 attCombo.setSelectedItem(
1626 FeatureMatcher.toAttributeDisplayName(attName));
1628 attCombo.addItemListener(new ItemListener()
1631 public void itemStateChanged(ItemEvent e)
1634 * on change of attribute, refresh the conditions list to
1635 * ensure it is appropriate for the attribute datatype
1637 populateConditions((String) attCombo.getSelectedItem(),
1638 (Condition) condCombo.getSelectedItem(), condCombo,
1640 actionListener.actionPerformed(null);
1644 filterRow.add(attCombo);
1647 * drop-down choice of test condition
1649 populateConditions(filterBy, cond, condCombo, patternField);
1650 condCombo.setPreferredSize(new Dimension(150, 20));
1651 condCombo.addItemListener(itemListener);
1652 filterRow.add(condCombo);
1655 * pattern to match against
1657 patternField.addActionListener(actionListener);
1658 patternField.addFocusListener(new FocusAdapter()
1661 public void focusLost(FocusEvent e)
1663 actionListener.actionPerformed(null);
1666 filterRow.add(patternField);
1669 * disable pattern field for condition 'Present / NotPresent'
1671 Condition selectedCondition = (Condition) condCombo.getSelectedItem();
1672 patternField.setEnabled(selectedCondition.needsAPattern());
1675 * if a numeric condition is selected, show the value range
1676 * as a tooltip on the value input field
1678 setNumericHints(filterBy, selectedCondition, patternField);
1681 * add remove button if filter is populated (non-empty pattern)
1683 if (!patternField.isEnabled()
1684 || (pattern != null && pattern.trim().length() > 0))
1686 JButton removeCondition = new JButton("\u2717"); // Dingbats cursive x
1687 removeCondition.setToolTipText(
1688 MessageManager.getString("label.delete_condition"));
1689 removeCondition.setBorder(new EmptyBorder(0, 0, 0, 0));
1690 removeCondition.addActionListener(new ActionListener()
1693 public void actionPerformed(ActionEvent e)
1695 filters.remove(filterIndex);
1699 filterRow.add(removeCondition);
1706 * Sets the selected item in the Label/Score/Attribute drop-down to match the
1712 private String setSelectedAttribute(JComboBox<String> attCombo,
1713 FeatureMatcherI filter)
1716 if (filter.isByScore())
1720 else if (filter.isByLabel())
1726 item = FeatureMatcher.toAttributeDisplayName(filter.getAttribute());
1728 attCombo.setSelectedItem(item);
1733 * If a numeric comparison condition is selected, retrieves the min-max range
1734 * for the value (score or attribute), and sets it as a tooltip on the value
1735 * field. If the field is currently empty, then pre-populates it with
1737 * <li>the minimum value, if condition is > or >=</li>
1738 * <li>the maximum value, if condition is < or <=</li>
1742 * @param selectedCondition
1743 * @param patternField
1745 private void setNumericHints(String attName, Condition selectedCondition,
1746 JTextField patternField)
1748 patternField.setToolTipText("");
1750 if (selectedCondition.isNumeric())
1752 float[] minMax = getMinMax(attName);
1755 String minFormatted = DECFMT_2_2.format(minMax[0]);
1756 String maxFormatted = DECFMT_2_2.format(minMax[1]);
1757 String tip = String.format("(%s - %s)", minFormatted, maxFormatted);
1758 patternField.setToolTipText(tip);
1759 if (patternField.getText().isEmpty())
1761 if (selectedCondition == Condition.GE
1762 || selectedCondition == Condition.GT)
1764 patternField.setText(minFormatted);
1768 if (selectedCondition == Condition.LE
1769 || selectedCondition == Condition.LT)
1771 patternField.setText(maxFormatted);
1780 * Populates the drop-down list of comparison conditions for the given
1781 * attribute name. The conditions added depend on the datatype of the
1782 * attribute values. The supplied condition is set as the selected item in the
1783 * list, provided it is in the list. If the pattern is now invalid
1784 * (non-numeric pattern for a numeric condition), it is cleared.
1789 * @param patternField
1791 private void populateConditions(String attName, Condition cond,
1792 JComboBox<Condition> condCombo, JTextField patternField)
1794 Datatype type = FeatureAttributes.getInstance().getDatatype(featureType,
1795 FeatureMatcher.fromAttributeDisplayName(attName));
1796 if (LABEL_18N.equals(attName))
1798 type = Datatype.Character;
1800 else if (SCORE_18N.equals(attName))
1802 type = Datatype.Number;
1806 * remove itemListener before starting
1808 ItemListener listener = condCombo.getItemListeners()[0];
1809 condCombo.removeItemListener(listener);
1810 boolean condIsValid = false;
1812 condCombo.removeAllItems();
1813 for (Condition c : Condition.values())
1815 if ((c.isNumeric() && type == Datatype.Number)
1816 || (!c.isNumeric() && type != Datatype.Number))
1818 condCombo.addItem(c);
1827 * set the selected condition (does nothing if not in the list)
1831 condCombo.setSelectedItem(cond);
1835 condCombo.setSelectedIndex(0);
1839 * clear pattern if it is now invalid for condition
1841 if (((Condition) condCombo.getSelectedItem()).isNumeric())
1845 String pattern = patternField.getText().trim();
1846 if (pattern.length() > 0)
1848 Float.valueOf(pattern);
1850 } catch (NumberFormatException e)
1852 patternField.setText("");
1857 * restore the listener
1859 condCombo.addItemListener(listener);
1863 * Answers true unless a numeric condition has been selected with a
1864 * non-numeric value. Sets the value field to RED with a tooltip if in error.
1866 * If the pattern is expected but is empty, this method returns false, but
1867 * does not mark the field as invalid. This supports selecting an attribute
1868 * for a new condition before a match pattern has been entered.
1873 protected boolean validateFilter(JTextField value,
1874 JComboBox<Condition> condCombo)
1876 if (value == null || condCombo == null)
1878 return true; // fields not populated
1881 Condition cond = (Condition) condCombo.getSelectedItem();
1882 if (!cond.needsAPattern())
1887 value.setBackground(Color.white);
1888 value.setToolTipText("");
1889 String v1 = value.getText().trim();
1890 if (v1.length() == 0)
1895 if (cond.isNumeric() && v1.length() > 0)
1900 } catch (NumberFormatException e)
1902 value.setBackground(Color.red);
1903 value.setToolTipText(
1904 MessageManager.getString("label.numeric_required"));
1913 * Constructs a filter condition from the given input fields, and replaces the
1914 * condition at filterIndex with the new one. Does nothing if the pattern
1915 * field is blank (unless the match condition is one that doesn't require a
1916 * pattern, e.g. 'Is present'). Answers true if the filter was updated, else
1919 * This method may update the tooltip on the filter value field to show the
1920 * value range, if a numeric condition is selected. This ensures the tooltip
1921 * is updated when a numeric valued attribute is chosen on the last 'add a
1927 * @param filterIndex
1929 protected boolean updateFilter(JComboBox<String> attCombo,
1930 JComboBox<Condition> condCombo, JTextField valueField,
1933 String attName = (String) attCombo.getSelectedItem();
1934 Condition cond = (Condition) condCombo.getSelectedItem();
1935 String pattern = valueField.getText().trim();
1937 setNumericHints(attName, cond, valueField);
1939 if (pattern.length() == 0 && cond.needsAPattern())
1941 valueField.setEnabled(true); // ensure pattern field is enabled!
1946 * Construct a matcher that operates on Label, Score,
1947 * or named attribute
1949 FeatureMatcherI km = null;
1950 if (LABEL_18N.equals(attName))
1952 km = FeatureMatcher.byLabel(cond, pattern);
1954 else if (SCORE_18N.equals(attName))
1956 km = FeatureMatcher.byScore(cond, pattern);
1960 km = FeatureMatcher.byAttribute(cond, pattern,
1961 FeatureMatcher.fromAttributeDisplayName(attName));
1964 filters.set(filterIndex, km);
1970 * Action on any change to feature filtering, namely
1972 * <li>change of selected attribute</li>
1973 * <li>change of selected condition</li>
1974 * <li>change of match pattern</li>
1975 * <li>removal of a condition</li>
1977 * The inputs are parsed into a combined filter and this is set for the
1978 * feature type, and the alignment redrawn.
1980 protected void filtersChanged()
1983 * update the filter conditions for the feature type
1985 boolean anded = andFilters.isSelected();
1986 FeatureMatcherSetI combined = new FeatureMatcherSet();
1988 for (FeatureMatcherI filter : filters)
1990 String pattern = filter.getMatcher().getPattern();
1991 Condition condition = filter.getMatcher().getCondition();
1992 if (pattern.trim().length() > 0 || !condition.needsAPattern())
1996 combined.and(filter);
2000 combined.or(filter);
2006 * save the filter conditions in the FeatureRenderer
2007 * (note this might now be an empty filter with no conditions)
2009 fr.setFeatureFilter(featureType, combined.isEmpty() ? null : combined);
2010 if (applyFiltersToSubtypes)
2012 for (String child : relatedSoTerms.get(parentSOTerm))
2014 fr.setFeatureFilter(child, combined.isEmpty() ? null : combined);
2018 refreshFeatureSettings();
2019 ap.paintAlignment(true, true);