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 SequenceOntologyI so = SequenceOntologyFactory.getInstance();
255 relatedSoTerms = so.findSequenceOntologyGroupings(
256 this.featureType, fr.getRenderOrder());
259 * save original colours and filters for this feature type,
260 * and any related types, to restore on Cancel
262 originalFilters = new HashMap<>();
263 originalFilters.put(theType, fr.getFeatureFilter(theType));
264 originalColours = new HashMap<>();
265 originalColours.put(theType, fr.getFeatureColours().get(theType));
266 for (List<String> related : relatedSoTerms.values())
268 for (String type : related)
270 originalFilters.put(type, fr.getFeatureFilter(type));
271 originalColours.put(type, fr.getFeatureColours().get(type));
280 } catch (Exception ex)
282 ex.printStackTrace();
292 colourChanged(false);
294 String title = MessageManager
295 .formatMessage("label.display_settings_for", new String[]
297 initDialogFrame(this, true, false, title, 580, 500);
302 * Answers a (possibly empty) map of any Sequence Ontology terms (the current
303 * feature type and its parents) which incorporate additional known feature
304 * types (the map entry).
306 * For example if {@code stop_gained} and {@code stop_lost} are known feature
307 * types, then SO term {@ nonsynonymous_variant} is the first common parent of
311 * the current feature type being configured
312 * @param featureTypes
313 * all known feature types on the alignment
316 protected static Map<String, List<String>> findSequenceOntologyGroupings(
317 String featureType, List<String> featureTypes)
319 List<String> sortedTypes = new ArrayList<>(featureTypes);
320 Collections.sort(sortedTypes);
322 Map<String, List<String>> parents = new HashMap<>();
326 * walk up featureType and all of its parents
327 * find other feature types which are subsumed by each term
328 * add each distinct aggregation of included feature types to the map
330 List<String> candidates = new ArrayList<>();
331 SequenceOntologyI so = SequenceOntologyFactory.getInstance();
332 candidates.add(featureType);
333 while (!candidates.isEmpty())
335 String term = candidates.remove(0);
336 List<String> includedFeatures = new ArrayList<>();
337 for (String type : sortedTypes)
339 if (!type.equals(featureType) && so.isA(type, term))
341 includedFeatures.add(type);
344 if (!includedFeatures.isEmpty()
345 && !parents.containsValue(includedFeatures))
347 parents.put(term, includedFeatures);
349 candidates.addAll(so.getParents(term));
356 * Configures the widgets on the Colours tab according to the current feature
359 private void updateColoursTab()
361 FeatureColourI fc = fr.getFeatureColours().get(featureType);
364 * suppress action handling while updating values programmatically
372 if (fc.isSimpleColour())
374 singleColour.setBackground(fc.getColour());
375 singleColour.setForeground(fc.getColour());
376 simpleColour.setSelected(true);
380 * colour by text (Label or attribute text)
382 if (fc.isColourByLabel())
384 byCategory.setSelected(true);
385 colourByTextCombo.setEnabled(colourByTextCombo.getItemCount() > 1);
386 if (fc.isColourByAttribute())
388 String[] attributeName = fc.getAttributeName();
389 colourByTextCombo.setSelectedItem(
390 FeatureMatcher.toAttributeDisplayName(attributeName));
394 colourByTextCombo.setSelectedItem(LABEL_18N);
399 colourByTextCombo.setEnabled(false);
402 if (!fc.isGraduatedColour())
404 colourByRangeCombo.setEnabled(false);
405 minColour.setEnabled(false);
406 maxColour.setEnabled(false);
407 noValueCombo.setEnabled(false);
408 threshold.setEnabled(false);
409 slider.setEnabled(false);
410 thresholdValue.setEnabled(false);
411 thresholdIsMin.setEnabled(false);
416 * Graduated colour, by score or attribute value range
418 graduatedColour.setSelected(true);
419 updateColourMinMax(); // ensure min, max are set
420 colourByRangeCombo.setEnabled(colourByRangeCombo.getItemCount() > 1);
421 minColour.setEnabled(true);
422 maxColour.setEnabled(true);
423 noValueCombo.setEnabled(true);
424 threshold.setEnabled(true);
425 minColour.setBackground(fc.getMinColour());
426 maxColour.setBackground(fc.getMaxColour());
428 if (fc.isColourByAttribute())
430 String[] attributeName = fc.getAttributeName();
431 colourByRangeCombo.setSelectedItem(
432 FeatureMatcher.toAttributeDisplayName(attributeName));
436 colourByRangeCombo.setSelectedItem(SCORE_18N);
438 Color noColour = fc.getNoColour();
439 if (noColour == null)
441 noValueCombo.setSelectedIndex(NO_COLOUR_OPTION);
443 else if (noColour.equals(fc.getMinColour()))
445 noValueCombo.setSelectedIndex(MIN_COLOUR_OPTION);
447 else if (noColour.equals(fc.getMaxColour()))
449 noValueCombo.setSelectedIndex(MAX_COLOUR_OPTION);
453 * update min-max scaling if there is a range to work with,
454 * else disable the widgets (this shouldn't happen if only
455 * valid options are offered in the combo box)
457 scaleFactor = (max == min) ? 1f : 100f / (max - min);
458 float range = (max - min) * scaleFactor;
459 slider.setMinimum((int) (min * scaleFactor));
460 slider.setMaximum((int) (max * scaleFactor));
461 slider.setMajorTickSpacing((int) (range / 10f));
463 threshline = new GraphLine((max - min) / 2f, "Threshold",
465 threshline.value = fc.getThreshold();
467 if (fc.hasThreshold())
469 threshold.setSelectedIndex(
470 fc.isAboveThreshold() ? ABOVE_THRESHOLD_OPTION
471 : BELOW_THRESHOLD_OPTION);
472 slider.setEnabled(true);
473 slider.setValue((int) (fc.getThreshold() * scaleFactor));
474 thresholdValue.setText(String.valueOf(fc.getThreshold()));
475 thresholdValue.setEnabled(true);
476 thresholdIsMin.setEnabled(true);
480 slider.setEnabled(false);
481 thresholdValue.setEnabled(false);
482 thresholdIsMin.setEnabled(false);
484 thresholdIsMin.setSelected(!fc.isAutoScaled());
492 * Configures the initial layout
494 private void initialise()
496 this.setLayout(new BorderLayout());
499 * an ActionListener that applies colour changes
501 changeColourAction = new ActionListener()
504 public void actionPerformed(ActionEvent e)
511 * first panel/tab: colour options
513 JPanel coloursPanel = initialiseColoursPanel();
514 this.add(coloursPanel, BorderLayout.NORTH);
517 * second panel/tab: filter options
519 JPanel filtersPanel = initialiseFiltersPanel();
520 this.add(filtersPanel, BorderLayout.CENTER);
522 JPanel okCancelPanel = initialiseOkCancelPanel();
524 this.add(okCancelPanel, BorderLayout.SOUTH);
528 * Updates the min-max range if Colour By selected item is Score, or an
529 * attribute, with a min-max range
531 protected void updateColourMinMax()
533 if (!graduatedColour.isSelected())
538 String colourBy = (String) colourByRangeCombo.getSelectedItem();
539 float[] minMax = getMinMax(colourBy);
549 * Retrieves the min-max range:
551 * <li>of feature score, if colour or filter is by Score</li>
552 * <li>else of the selected attribute</li>
558 private float[] getMinMax(String attName)
560 float[] minMax = null;
561 if (SCORE_18N.equals(attName))
563 minMax = fr.getMinMax().get(featureType)[0];
567 // colour by attribute range
568 minMax = FeatureAttributes.getInstance().getMinMax(featureType,
569 FeatureMatcher.fromAttributeDisplayName(attName));
575 * Lay out fields for graduated colour (by score or attribute value)
579 private JPanel initialiseGraduatedColourPanel()
581 JPanel graduatedColourPanel = new JPanel();
582 graduatedColourPanel.setLayout(
583 new BoxLayout(graduatedColourPanel, BoxLayout.Y_AXIS));
584 JvSwingUtils.createTitledBorder(graduatedColourPanel,
585 MessageManager.getString("label.graduated_colour"), true);
586 graduatedColourPanel.setBackground(Color.white);
589 * first row: graduated colour radio button, score/attribute drop-down
591 JPanel graduatedChoicePanel = new JPanel(
592 new FlowLayout(FlowLayout.LEFT));
593 graduatedChoicePanel.setBackground(Color.white);
594 graduatedColour = new JRadioButton(
595 MessageManager.getString("label.by_range_of") + COLON);
596 graduatedColour.setPreferredSize(new Dimension(RADIO_WIDTH, 20));
597 graduatedColour.addItemListener(new ItemListener()
600 public void itemStateChanged(ItemEvent e)
602 if (graduatedColour.isSelected())
608 graduatedChoicePanel.add(graduatedColour);
610 List<String[]> attNames = FeatureAttributes.getInstance()
611 .getAttributes(featureType);
612 colourByRangeCombo = populateAttributesDropdown(attNames, true, false);
613 colourByRangeCombo.addItemListener(new ItemListener()
616 public void itemStateChanged(ItemEvent e)
623 * disable graduated colour option if no range found
625 graduatedColour.setEnabled(colourByRangeCombo.getItemCount() > 0);
627 graduatedChoicePanel.add(colourByRangeCombo);
628 graduatedColourPanel.add(graduatedChoicePanel);
631 * second row - min/max/no colours
633 JPanel colourRangePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
634 colourRangePanel.setBackground(Color.white);
635 graduatedColourPanel.add(colourRangePanel);
637 minColour.setFont(JvSwingUtils.getLabelFont());
638 minColour.setBorder(BorderFactory.createLineBorder(Color.black));
639 minColour.setPreferredSize(new Dimension(40, 20));
640 minColour.setToolTipText(MessageManager.getString("label.min_colour"));
641 minColour.addMouseListener(new MouseAdapter()
644 public void mousePressed(MouseEvent e)
646 if (minColour.isEnabled())
648 showColourChooser(minColour, "label.select_colour_minimum_value");
653 maxColour.setFont(JvSwingUtils.getLabelFont());
654 maxColour.setBorder(BorderFactory.createLineBorder(Color.black));
655 maxColour.setPreferredSize(new Dimension(40, 20));
656 maxColour.setToolTipText(MessageManager.getString("label.max_colour"));
657 maxColour.addMouseListener(new MouseAdapter()
660 public void mousePressed(MouseEvent e)
662 if (maxColour.isEnabled())
664 showColourChooser(maxColour, "label.select_colour_maximum_value");
668 maxColour.setBorder(new LineBorder(Color.black));
671 * if not set, default max colour to last plain colour,
672 * and make min colour a pale version of max colour
674 FeatureColourI originalColour = originalColours.get(featureType);
675 Color max = originalColour.getMaxColour();
678 max = originalColour.getColour();
679 minColour.setBackground(ColorUtils.bleachColour(max, 0.9f));
683 maxColour.setBackground(max);
684 minColour.setBackground(originalColour.getMinColour());
687 noValueCombo = new JComboBox<>();
688 noValueCombo.addItem(MessageManager.getString("label.no_colour"));
689 noValueCombo.addItem(MessageManager.getString("label.min_colour"));
690 noValueCombo.addItem(MessageManager.getString("label.max_colour"));
691 noValueCombo.addItemListener(new ItemListener()
694 public void itemStateChanged(ItemEvent e)
700 JLabel minText = new JLabel(
701 MessageManager.getString("label.min_value") + COLON);
702 minText.setFont(JvSwingUtils.getLabelFont());
703 JLabel maxText = new JLabel(
704 MessageManager.getString("label.max_value") + COLON);
705 maxText.setFont(JvSwingUtils.getLabelFont());
706 JLabel noText = new JLabel(
707 MessageManager.getString("label.no_value") + COLON);
708 noText.setFont(JvSwingUtils.getLabelFont());
710 colourRangePanel.add(minText);
711 colourRangePanel.add(minColour);
712 colourRangePanel.add(maxText);
713 colourRangePanel.add(maxColour);
714 colourRangePanel.add(noText);
715 colourRangePanel.add(noValueCombo);
718 * third row - threshold options and value
720 JPanel thresholdPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
721 thresholdPanel.setBackground(Color.white);
722 graduatedColourPanel.add(thresholdPanel);
724 threshold.addActionListener(changeColourAction);
725 threshold.setToolTipText(MessageManager
726 .getString("label.threshold_feature_display_by_score"));
727 threshold.addItem(MessageManager
728 .getString("label.threshold_feature_no_threshold")); // index 0
729 threshold.addItem(MessageManager
730 .getString("label.threshold_feature_above_threshold")); // index 1
731 threshold.addItem(MessageManager
732 .getString("label.threshold_feature_below_threshold")); // index 2
734 thresholdValue.addActionListener(new ActionListener()
737 public void actionPerformed(ActionEvent e)
739 thresholdValue_actionPerformed();
742 thresholdValue.addFocusListener(new FocusAdapter()
745 public void focusLost(FocusEvent e)
747 thresholdValue_actionPerformed();
750 slider.setPaintLabels(false);
751 slider.setPaintTicks(true);
752 slider.setBackground(Color.white);
753 slider.setEnabled(false);
754 slider.setOpaque(false);
755 slider.setPreferredSize(new Dimension(100, 32));
756 slider.setToolTipText(
757 MessageManager.getString("label.adjust_threshold"));
759 slider.addChangeListener(new ChangeListener()
762 public void stateChanged(ChangeEvent evt)
767 .setText(String.valueOf(slider.getValue() / scaleFactor));
768 thresholdValue.setBackground(Color.white); // to reset red for invalid
769 sliderValueChanged();
773 slider.addMouseListener(new MouseAdapter()
776 public void mouseReleased(MouseEvent evt)
779 * only update Overview and/or structure colouring
780 * when threshold slider drag ends (mouse up)
784 ap.paintAlignment(true, true);
789 thresholdValue.setEnabled(false);
790 thresholdValue.setColumns(7);
792 thresholdPanel.add(threshold);
793 thresholdPanel.add(slider);
794 thresholdPanel.add(thresholdValue);
796 thresholdIsMin.setBackground(Color.white);
798 .setText(MessageManager.getString("label.threshold_minmax"));
799 thresholdIsMin.setToolTipText(MessageManager
800 .getString("label.toggle_absolute_relative_display_threshold"));
801 thresholdIsMin.addActionListener(changeColourAction);
802 thresholdPanel.add(thresholdIsMin);
804 return graduatedColourPanel;
808 * Lay out OK and Cancel buttons
812 private JPanel initialiseOkCancelPanel()
814 JPanel okCancelPanel = new JPanel();
815 // okCancelPanel.setBackground(Color.white);
816 okCancelPanel.add(ok);
817 okCancelPanel.add(cancel);
818 return okCancelPanel;
822 * Lay out Colour options panel, containing
824 * <li>plain colour, with colour picker</li>
825 * <li>colour by text, with choice of Label or other attribute</li>
826 * <li>colour by range, of score or other attribute, when available</li>
831 private JPanel initialiseColoursPanel()
833 JPanel colourByPanel = new JPanel();
834 colourByPanel.setBackground(Color.white);
835 colourByPanel.setLayout(new BoxLayout(colourByPanel, BoxLayout.Y_AXIS));
836 JvSwingUtils.createTitledBorder(colourByPanel,
837 MessageManager.getString("action.colour"), true);
840 * option to apply colour to other selected types as well
842 if (!relatedSoTerms.isEmpty())
844 applyColourToSubtypes = false;
845 colourByPanel.add(initSubtypesPanel(false));
849 * simple colour radio button and colour picker
851 JPanel simpleColourPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
852 simpleColourPanel.setBackground(Color.white);
853 colourByPanel.add(simpleColourPanel);
855 simpleColour = new JRadioButton(
856 MessageManager.getString("label.simple_colour"));
857 simpleColour.setPreferredSize(new Dimension(RADIO_WIDTH, 20));
858 simpleColour.addItemListener(new ItemListener()
861 public void itemStateChanged(ItemEvent e)
863 if (simpleColour.isSelected() && !adjusting)
870 singleColour.setFont(JvSwingUtils.getLabelFont());
871 singleColour.setBorder(BorderFactory.createLineBorder(Color.black));
872 singleColour.setPreferredSize(new Dimension(40, 20));
873 FeatureColourI originalColour = originalColours.get(featureType);
874 singleColour.setBackground(originalColour.getColour());
875 singleColour.setForeground(originalColour.getColour());
877 singleColour.addMouseListener(new MouseAdapter()
880 public void mousePressed(MouseEvent e)
882 if (simpleColour.isSelected())
884 showColourChooser(singleColour, "label.select_colour");
888 simpleColourPanel.add(simpleColour); // radio button
889 simpleColourPanel.add(singleColour); // colour picker button
892 * colour by text (category) radio button and drop-down choice list
894 JPanel byTextPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
895 byTextPanel.setBackground(Color.white);
896 JvSwingUtils.createTitledBorder(byTextPanel,
897 MessageManager.getString("label.colour_by_text"), true);
898 colourByPanel.add(byTextPanel);
899 byCategory = new JRadioButton(
900 MessageManager.getString("label.by_text_of") + COLON);
901 byCategory.setPreferredSize(new Dimension(RADIO_WIDTH, 20));
902 byCategory.addItemListener(new ItemListener()
905 public void itemStateChanged(ItemEvent e)
907 if (byCategory.isSelected())
913 byTextPanel.add(byCategory);
915 List<String[]> attNames = FeatureAttributes.getInstance()
916 .getAttributes(featureType);
917 colourByTextCombo = populateAttributesDropdown(attNames, false, true);
918 colourByTextCombo.addItemListener(new ItemListener()
921 public void itemStateChanged(ItemEvent e)
926 byTextPanel.add(colourByTextCombo);
929 * graduated colour panel
931 JPanel graduatedColourPanel = initialiseGraduatedColourPanel();
932 colourByPanel.add(graduatedColourPanel);
935 * 3 radio buttons select between simple colour,
936 * by category (text), or graduated
938 ButtonGroup bg = new ButtonGroup();
939 bg.add(simpleColour);
941 bg.add(graduatedColour);
943 return colourByPanel;
947 * Constructs and returns a panel with the option to apply any changes also to
948 * sub-types of SO terms at or above the feature type
952 protected JPanel initSubtypesPanel(final boolean forFilters)
954 JPanel toSubtypes = new JPanel(new FlowLayout(FlowLayout.LEFT));
955 toSubtypes.setBackground(Color.WHITE);
958 * checkbox 'apply to sub-types of...'
960 JCheckBox applyToSubtypesCB = new JCheckBox(MessageManager
961 .formatMessage("label.apply_to_subtypes", rootSOTerm));
962 toSubtypes.add(applyToSubtypesCB);
965 * combobox to choose 'parent' of sub-types
967 List<String> soTerms = new ArrayList<>();
968 for (String term : relatedSoTerms.keySet())
972 // sort from most restrictive to most inclusive
973 Collections.sort(soTerms, new Comparator<String>()
976 public int compare(String o1, String o2)
978 return Integer.compare(relatedSoTerms.get(o1).size(),
979 relatedSoTerms.get(o2).size());
982 List<String> tooltips = new ArrayList<>();
983 for (String term : soTerms)
985 tooltips.add(getSOTermsTooltip(relatedSoTerms.get(term)));
987 JComboBox<String> parentType = JvSwingUtils
988 .buildComboWithTooltips(soTerms, tooltips);
989 toSubtypes.add(parentType);
992 * on toggle of checkbox, or change of parent SO term,
993 * reset and then reapply filters to the selected scope
995 final ActionListener action = new ActionListener()
998 * reset and reapply settings on toggle of checkbox
1001 public void actionPerformed(ActionEvent e)
1003 parentSOTerm = (String) parentType.getSelectedItem();
1006 applyFiltersToSubtypes = applyToSubtypesCB.isSelected();
1007 restoreOriginalFilters();
1012 applyColourToSubtypes = applyToSubtypesCB.isSelected();
1013 restoreOriginalColours();
1014 colourChanged(true);
1018 applyToSubtypesCB.addActionListener(action);
1019 parentType.addActionListener(action);
1024 private void showColourChooser(JPanel colourPanel, String key)
1026 Color col = JColorChooser.showDialog(this,
1027 MessageManager.getString(key), colourPanel.getBackground());
1030 colourPanel.setBackground(col);
1031 colourPanel.setForeground(col);
1033 colourPanel.repaint();
1034 colourChanged(true);
1038 * Constructs and sets the selected colour options as the colour for the
1039 * feature type, and repaints the alignment, and optionally the Overview
1040 * and/or structure viewer if open
1042 * @param updateStructsAndOverview
1044 void colourChanged(boolean updateStructsAndOverview)
1049 * ignore action handlers while setting values programmatically
1055 * ensure min-max range is for the latest choice of
1056 * 'graduated colour by'
1058 updateColourMinMax();
1060 FeatureColourI acg = makeColourFromInputs();
1063 * save the colour, and set on subtypes if selected
1065 fr.setColour(featureType, acg);
1066 if (applyColourToSubtypes)
1068 for (String child : relatedSoTerms.get(parentSOTerm))
1070 fr.setColour(child, acg);
1073 refreshFeatureSettings();
1074 ap.paintAlignment(updateStructsAndOverview, updateStructsAndOverview);
1080 * Converts the input values into an instance of FeatureColour
1084 private FeatureColourI makeColourFromInputs()
1087 * min-max range is to (or from) threshold value if
1088 * 'threshold is min/max' is selected
1094 thresh = Float.valueOf(thresholdValue.getText());
1095 } catch (NumberFormatException e)
1097 // invalid inputs are already handled on entry
1099 float minValue = min;
1100 float maxValue = max;
1101 final int thresholdOption = threshold.getSelectedIndex();
1102 if (thresholdIsMin.isSelected()
1103 && thresholdOption == ABOVE_THRESHOLD_OPTION)
1107 if (thresholdIsMin.isSelected()
1108 && thresholdOption == BELOW_THRESHOLD_OPTION)
1112 Color noColour = null;
1113 if (noValueCombo.getSelectedIndex() == MIN_COLOUR_OPTION)
1115 noColour = minColour.getBackground();
1117 else if (noValueCombo.getSelectedIndex() == MAX_COLOUR_OPTION)
1119 noColour = maxColour.getBackground();
1123 * construct a colour that 'remembers' all the options, including
1124 * those not currently selected
1126 FeatureColourI fc = new FeatureColour(singleColour.getBackground(),
1127 minColour.getBackground(), maxColour.getBackground(), noColour,
1128 minValue, maxValue);
1131 * easiest case - a single colour
1133 if (simpleColour.isSelected())
1135 ((FeatureColour) fc).setGraduatedColour(false);
1140 * next easiest case - colour by Label, or attribute text
1142 if (byCategory.isSelected())
1144 fc.setColourByLabel(true);
1145 String byWhat = (String) colourByTextCombo.getSelectedItem();
1146 if (!LABEL_18N.equals(byWhat))
1148 fc.setAttributeName(
1149 FeatureMatcher.fromAttributeDisplayName(byWhat));
1155 * remaining case - graduated colour by score, or attribute value;
1156 * set attribute to colour by if selected
1158 String byWhat = (String) colourByRangeCombo.getSelectedItem();
1159 if (!SCORE_18N.equals(byWhat))
1161 fc.setAttributeName(FeatureMatcher.fromAttributeDisplayName(byWhat));
1165 * set threshold options and 'autoscaled' which is
1166 * false if 'threshold is min/max' is selected
1167 * else true (colour range is on actual range of values)
1169 fc.setThreshold(thresh);
1170 fc.setAutoScaled(!thresholdIsMin.isSelected());
1171 fc.setAboveThreshold(thresholdOption == ABOVE_THRESHOLD_OPTION);
1172 fc.setBelowThreshold(thresholdOption == BELOW_THRESHOLD_OPTION);
1174 if (threshline == null)
1177 * todo not yet implemented: visual indication of feature threshold
1179 threshline = new GraphLine((max - min) / 2f, "Threshold",
1187 protected void raiseClosed()
1189 refreshFeatureSettings();
1192 protected void refreshFeatureSettings()
1194 if (this.featureSettings != null)
1196 featureSettings.actionPerformed(new ActionEvent(this, 0, "REFRESH"));
1201 * Action on OK is just to dismiss the dialog - any changes have already been
1205 public void okPressed()
1210 * Action on Cancel is to restore colour scheme and filters as they were when
1211 * the dialog was opened (including any feature sub-types that may have been
1215 public void cancelPressed()
1217 restoreOriginalColours();
1218 restoreOriginalFilters();
1219 ap.paintAlignment(true, true);
1223 * Restores filters for all feature types to their values when the dialog was
1226 protected void restoreOriginalFilters()
1228 for (Entry<String, FeatureMatcherSetI> entry : originalFilters
1231 fr.setFeatureFilter(entry.getKey(), entry.getValue());
1236 * Restores colours for all feature types to their values when the dialog was
1239 protected void restoreOriginalColours()
1241 for (Entry<String, FeatureColourI> entry : originalColours.entrySet())
1243 fr.setColour(entry.getKey(), entry.getValue());
1248 * Action on text entry of a threshold value
1250 protected void thresholdValue_actionPerformed()
1255 * set 'adjusting' flag while moving the slider, so it
1256 * doesn't then in turn change the value (with rounding)
1259 float f = Float.parseFloat(thresholdValue.getText());
1260 f = Float.max(f, this.min);
1261 f = Float.min(f, this.max);
1262 thresholdValue.setText(String.valueOf(f));
1263 slider.setValue((int) (f * scaleFactor));
1264 threshline.value = f;
1265 thresholdValue.setBackground(Color.white); // ok
1267 colourChanged(true);
1268 } catch (NumberFormatException ex)
1270 thresholdValue.setBackground(Color.red); // not ok
1276 * Action on change of threshold slider value. This may be done interactively
1277 * (by moving the slider), or programmatically (to update the slider after
1278 * manual input of a threshold value).
1280 protected void sliderValueChanged()
1282 threshline.value = getRoundedSliderValue();
1285 * repaint alignment, but not Overview or structure,
1286 * to avoid overload while dragging the slider
1288 colourChanged(false);
1292 * Converts the slider value to its absolute value by dividing by the
1293 * scaleFactor. Rounding errors are squashed by forcing min/max of slider
1294 * range to the actual min/max of feature score range
1298 private float getRoundedSliderValue()
1300 int value = slider.getValue();
1301 float f = value == slider.getMaximum() ? max
1302 : (value == slider.getMinimum() ? min : value / scaleFactor);
1306 void addActionListener(ActionListener listener)
1308 if (featureSettings != null)
1311 "IMPLEMENTATION ISSUE: overwriting action listener for FeatureColourChooser");
1313 featureSettings = listener;
1317 * A helper method to build the drop-down choice of attributes for a feature.
1318 * If 'withRange' is true, then Score, and any attributes with a min-max
1319 * range, are added. If 'withText' is true, Label and any known attributes are
1320 * added. This allows 'categorical numerical' attributes e.g. codon position
1321 * to be coloured by text.
1323 * Where metadata is available with a description for an attribute, that is
1324 * added as a tooltip.
1326 * Attribute names may be 'simple' e.g. "AC" or 'compound' e.g. {"CSQ",
1327 * "Allele"}. Compound names are rendered for display as (e.g.) CSQ:Allele.
1329 * This method does not add any ActionListener to the JComboBox.
1335 protected JComboBox<String> populateAttributesDropdown(
1336 List<String[]> attNames, boolean withRange, boolean withText)
1338 List<String> displayAtts = new ArrayList<>();
1339 List<String> tooltips = new ArrayList<>();
1343 displayAtts.add(LABEL_18N);
1344 tooltips.add(MessageManager.getString("label.description"));
1348 float[][] minMax = fr.getMinMax().get(featureType);
1349 if (minMax != null && minMax[0][0] != minMax[0][1])
1351 displayAtts.add(SCORE_18N);
1352 tooltips.add(SCORE_18N);
1356 FeatureAttributes fa = FeatureAttributes.getInstance();
1357 for (String[] attName : attNames)
1359 float[] minMax = fa.getMinMax(featureType, attName);
1360 boolean hasRange = minMax != null && minMax[0] != minMax[1];
1361 if (!withText && !hasRange)
1365 displayAtts.add(FeatureMatcher.toAttributeDisplayName(attName));
1366 String desc = fa.getDescription(featureType, attName);
1367 if (desc != null && desc.length() > MAX_TOOLTIP_LENGTH)
1369 desc = desc.substring(0, MAX_TOOLTIP_LENGTH) + "...";
1371 tooltips.add(desc == null ? "" : desc);
1374 JComboBox<String> attCombo = JvSwingUtils
1375 .buildComboWithTooltips(displayAtts, tooltips);
1381 * Populates initial layout of the feature attribute filters panel
1383 private JPanel initialiseFiltersPanel()
1385 filters = new ArrayList<>();
1387 JPanel outerPanel = new JPanel();
1388 outerPanel.setLayout(new BoxLayout(outerPanel, BoxLayout.Y_AXIS));
1389 outerPanel.setBackground(Color.white);
1392 * option to apply colour to other selected types as well
1394 if (!relatedSoTerms.isEmpty())
1396 applyFiltersToSubtypes = false;
1397 outerPanel.add(initSubtypesPanel(true));
1400 JPanel filtersPanel = new JPanel();
1401 filtersPanel.setLayout(new BoxLayout(filtersPanel, BoxLayout.Y_AXIS));
1402 filtersPanel.setBackground(Color.white);
1403 JvSwingUtils.createTitledBorder(filtersPanel,
1404 MessageManager.getString("label.filters"), true);
1405 outerPanel.add(filtersPanel);
1407 JPanel andOrPanel = initialiseAndOrPanel();
1408 filtersPanel.add(andOrPanel);
1411 * panel with filters - populated by refreshFiltersDisplay,
1412 * which also sets the layout manager
1414 chooseFiltersPanel = new JPanel();
1415 chooseFiltersPanel.setBackground(Color.white);
1416 filtersPanel.add(chooseFiltersPanel);
1422 * Lays out the panel with radio buttons to AND or OR filter conditions
1426 private JPanel initialiseAndOrPanel()
1428 JPanel andOrPanel = new JPanel(new BorderLayout());
1429 andOrPanel.setBackground(Color.white);
1431 andFilters = new JRadioButton(MessageManager.getString("label.and"));
1432 orFilters = new JRadioButton(MessageManager.getString("label.or"));
1433 ActionListener actionListener = new ActionListener()
1436 public void actionPerformed(ActionEvent e)
1441 andFilters.addActionListener(actionListener);
1442 orFilters.addActionListener(actionListener);
1443 ButtonGroup andOr = new ButtonGroup();
1444 andOr.add(andFilters);
1445 andOr.add(orFilters);
1446 andFilters.setSelected(true);
1448 new JLabel(MessageManager.getString("label.join_conditions")));
1449 andOrPanel.add(andFilters);
1450 andOrPanel.add(orFilters);
1456 * Builds a tooltip for the 'Apply also to...' combobox with a list of known
1457 * feature types (excluding the current type) which are sub-types of the
1458 * selected Sequence Ontology term
1463 protected String getSOTermsTooltip(List<String> list)
1465 StringBuilder sb = new StringBuilder(20 * relatedSoTerms.size());
1466 sb.append(MessageManager.getString("label.apply_also_to"));
1467 for (String child : list)
1469 sb.append("<br>").append(child);
1471 String tooltip = JvSwingUtils.wrapTooltip(true, sb.toString());
1476 * Refreshes the display to show any filters currently configured for the
1477 * selected feature type (editable, with 'remove' option), plus one extra row
1478 * for adding a condition. This should be called after a filter has been
1479 * removed, added or amended.
1481 private void updateFiltersTab()
1484 * clear the panel and list of filter conditions
1486 chooseFiltersPanel.removeAll();
1490 * look up attributes known for feature type
1492 List<String[]> attNames = FeatureAttributes.getInstance()
1493 .getAttributes(featureType);
1496 * if this feature type has filters set, load them first
1498 FeatureMatcherSetI featureFilters = fr.getFeatureFilter(featureType);
1499 if (featureFilters != null)
1501 if (!featureFilters.isAnded())
1503 orFilters.setSelected(true);
1505 featureFilters.getMatchers().forEach(matcher -> filters.add(matcher));
1509 * and an empty filter for the user to populate (add)
1511 filters.add(FeatureMatcher.NULL_MATCHER);
1514 * use GridLayout to 'justify' rows to the top of the panel, until
1515 * there are too many to fit in, then fall back on BoxLayout
1517 if (filters.size() <= 5)
1519 chooseFiltersPanel.setLayout(new GridLayout(5, 1));
1523 chooseFiltersPanel.setLayout(
1524 new BoxLayout(chooseFiltersPanel, BoxLayout.Y_AXIS));
1528 * render the conditions in rows, each in its own JPanel
1530 int filterIndex = 0;
1531 for (FeatureMatcherI filter : filters)
1533 JPanel row = addFilter(filter, attNames, filterIndex);
1534 chooseFiltersPanel.add(row);
1543 * A helper method that constructs a row (panel) with one filter condition:
1545 * <li>a drop-down list of Label, Score and attribute names to choose
1547 * <li>a drop-down list of conditions to choose from</li>
1548 * <li>a text field for input of a match pattern</li>
1549 * <li>optionally, a 'remove' button</li>
1551 * The filter values are set as defaults for the input fields. The 'remove'
1552 * button is added unless the pattern is empty (incomplete filter condition).
1554 * Action handlers on these fields provide for
1556 * <li>validate pattern field - should be numeric if condition is numeric</li>
1557 * <li>save filters and refresh display on any (valid) change</li>
1558 * <li>remove filter and refresh on 'Remove'</li>
1559 * <li>update conditions list on change of Label/Score/Attribute</li>
1560 * <li>refresh value field tooltip with min-max range on change of
1566 * @param filterIndex
1569 protected JPanel addFilter(FeatureMatcherI filter,
1570 List<String[]> attNames, int filterIndex)
1572 String[] attName = filter.getAttribute();
1573 Condition cond = filter.getMatcher().getCondition();
1574 String pattern = filter.getMatcher().getPattern();
1576 JPanel filterRow = new JPanel(new FlowLayout(FlowLayout.LEFT));
1577 filterRow.setBackground(Color.white);
1580 * drop-down choice of attribute, with description as a tooltip
1581 * if we can obtain it
1583 final JComboBox<String> attCombo = populateAttributesDropdown(attNames,
1585 String filterBy = setSelectedAttribute(attCombo, filter);
1587 JComboBox<Condition> condCombo = new JComboBox<>();
1589 JTextField patternField = new JTextField(8);
1590 patternField.setText(pattern);
1593 * action handlers that validate and (if valid) apply changes
1595 ActionListener actionListener = new ActionListener()
1598 public void actionPerformed(ActionEvent e)
1600 if (validateFilter(patternField, condCombo))
1602 if (updateFilter(attCombo, condCombo, patternField, filterIndex))
1609 ItemListener itemListener = new ItemListener()
1612 public void itemStateChanged(ItemEvent e)
1614 actionListener.actionPerformed(null);
1618 if (filter == FeatureMatcher.NULL_MATCHER) // the 'add a condition' row
1620 attCombo.setSelectedIndex(0);
1624 attCombo.setSelectedItem(
1625 FeatureMatcher.toAttributeDisplayName(attName));
1627 attCombo.addItemListener(new ItemListener()
1630 public void itemStateChanged(ItemEvent e)
1633 * on change of attribute, refresh the conditions list to
1634 * ensure it is appropriate for the attribute datatype
1636 populateConditions((String) attCombo.getSelectedItem(),
1637 (Condition) condCombo.getSelectedItem(), condCombo,
1639 actionListener.actionPerformed(null);
1643 filterRow.add(attCombo);
1646 * drop-down choice of test condition
1648 populateConditions(filterBy, cond, condCombo, patternField);
1649 condCombo.setPreferredSize(new Dimension(150, 20));
1650 condCombo.addItemListener(itemListener);
1651 filterRow.add(condCombo);
1654 * pattern to match against
1656 patternField.addActionListener(actionListener);
1657 patternField.addFocusListener(new FocusAdapter()
1660 public void focusLost(FocusEvent e)
1662 actionListener.actionPerformed(null);
1665 filterRow.add(patternField);
1668 * disable pattern field for condition 'Present / NotPresent'
1670 Condition selectedCondition = (Condition) condCombo.getSelectedItem();
1671 patternField.setEnabled(selectedCondition.needsAPattern());
1674 * if a numeric condition is selected, show the value range
1675 * as a tooltip on the value input field
1677 setNumericHints(filterBy, selectedCondition, patternField);
1680 * add remove button if filter is populated (non-empty pattern)
1682 if (!patternField.isEnabled()
1683 || (pattern != null && pattern.trim().length() > 0))
1685 // todo: gif for button drawing '-' or 'x'
1686 JButton removeCondition = new BasicArrowButton(SwingConstants.WEST);
1688 .setToolTipText(MessageManager.getString("label.delete_row"));
1689 removeCondition.addActionListener(new ActionListener()
1692 public void actionPerformed(ActionEvent e)
1694 filters.remove(filterIndex);
1698 filterRow.add(removeCondition);
1705 * Sets the selected item in the Label/Score/Attribute drop-down to match the
1711 private String setSelectedAttribute(JComboBox<String> attCombo,
1712 FeatureMatcherI filter)
1715 if (filter.isByScore())
1719 else if (filter.isByLabel())
1725 item = FeatureMatcher.toAttributeDisplayName(filter.getAttribute());
1727 attCombo.setSelectedItem(item);
1732 * If a numeric comparison condition is selected, retrieves the min-max range
1733 * for the value (score or attribute), and sets it as a tooltip on the value
1734 * field. If the field is currently empty, then pre-populates it with
1736 * <li>the minimum value, if condition is > or >=</li>
1737 * <li>the maximum value, if condition is < or <=</li>
1741 * @param selectedCondition
1742 * @param patternField
1744 private void setNumericHints(String attName, Condition selectedCondition,
1745 JTextField patternField)
1747 patternField.setToolTipText("");
1749 if (selectedCondition.isNumeric())
1751 float[] minMax = getMinMax(attName);
1754 String minFormatted = DECFMT_2_2.format(minMax[0]);
1755 String maxFormatted = DECFMT_2_2.format(minMax[1]);
1756 String tip = String.format("(%s - %s)", minFormatted, maxFormatted);
1757 patternField.setToolTipText(tip);
1758 if (patternField.getText().isEmpty())
1760 if (selectedCondition == Condition.GE
1761 || selectedCondition == Condition.GT)
1763 patternField.setText(minFormatted);
1767 if (selectedCondition == Condition.LE
1768 || selectedCondition == Condition.LT)
1770 patternField.setText(maxFormatted);
1779 * Populates the drop-down list of comparison conditions for the given
1780 * attribute name. The conditions added depend on the datatype of the
1781 * attribute values. The supplied condition is set as the selected item in the
1782 * list, provided it is in the list. If the pattern is now invalid
1783 * (non-numeric pattern for a numeric condition), it is cleared.
1788 * @param patternField
1790 private void populateConditions(String attName, Condition cond,
1791 JComboBox<Condition> condCombo, JTextField patternField)
1793 Datatype type = FeatureAttributes.getInstance().getDatatype(featureType,
1794 FeatureMatcher.fromAttributeDisplayName(attName));
1795 if (LABEL_18N.equals(attName))
1797 type = Datatype.Character;
1799 else if (SCORE_18N.equals(attName))
1801 type = Datatype.Number;
1805 * remove itemListener before starting
1807 ItemListener listener = condCombo.getItemListeners()[0];
1808 condCombo.removeItemListener(listener);
1809 boolean condIsValid = false;
1811 condCombo.removeAllItems();
1812 for (Condition c : Condition.values())
1814 if ((c.isNumeric() && type == Datatype.Number)
1815 || (!c.isNumeric() && type != Datatype.Number))
1817 condCombo.addItem(c);
1826 * set the selected condition (does nothing if not in the list)
1830 condCombo.setSelectedItem(cond);
1834 condCombo.setSelectedIndex(0);
1838 * clear pattern if it is now invalid for condition
1840 if (((Condition) condCombo.getSelectedItem()).isNumeric())
1844 String pattern = patternField.getText().trim();
1845 if (pattern.length() > 0)
1847 Float.valueOf(pattern);
1849 } catch (NumberFormatException e)
1851 patternField.setText("");
1856 * restore the listener
1858 condCombo.addItemListener(listener);
1862 * Answers true unless a numeric condition has been selected with a
1863 * non-numeric value. Sets the value field to RED with a tooltip if in error.
1865 * If the pattern is expected but is empty, this method returns false, but
1866 * does not mark the field as invalid. This supports selecting an attribute
1867 * for a new condition before a match pattern has been entered.
1872 protected boolean validateFilter(JTextField value,
1873 JComboBox<Condition> condCombo)
1875 if (value == null || condCombo == null)
1877 return true; // fields not populated
1880 Condition cond = (Condition) condCombo.getSelectedItem();
1881 if (!cond.needsAPattern())
1886 value.setBackground(Color.white);
1887 value.setToolTipText("");
1888 String v1 = value.getText().trim();
1889 if (v1.length() == 0)
1894 if (cond.isNumeric() && v1.length() > 0)
1899 } catch (NumberFormatException e)
1901 value.setBackground(Color.red);
1902 value.setToolTipText(
1903 MessageManager.getString("label.numeric_required"));
1912 * Constructs a filter condition from the given input fields, and replaces the
1913 * condition at filterIndex with the new one. Does nothing if the pattern
1914 * field is blank (unless the match condition is one that doesn't require a
1915 * pattern, e.g. 'Is present'). Answers true if the filter was updated, else
1918 * This method may update the tooltip on the filter value field to show the
1919 * value range, if a numeric condition is selected. This ensures the tooltip
1920 * is updated when a numeric valued attribute is chosen on the last 'add a
1926 * @param filterIndex
1928 protected boolean updateFilter(JComboBox<String> attCombo,
1929 JComboBox<Condition> condCombo, JTextField valueField,
1932 String attName = (String) attCombo.getSelectedItem();
1933 Condition cond = (Condition) condCombo.getSelectedItem();
1934 String pattern = valueField.getText().trim();
1936 setNumericHints(attName, cond, valueField);
1938 if (pattern.length() == 0 && cond.needsAPattern())
1940 valueField.setEnabled(true); // ensure pattern field is enabled!
1945 * Construct a matcher that operates on Label, Score,
1946 * or named attribute
1948 FeatureMatcherI km = null;
1949 if (LABEL_18N.equals(attName))
1951 km = FeatureMatcher.byLabel(cond, pattern);
1953 else if (SCORE_18N.equals(attName))
1955 km = FeatureMatcher.byScore(cond, pattern);
1959 km = FeatureMatcher.byAttribute(cond, pattern,
1960 FeatureMatcher.fromAttributeDisplayName(attName));
1963 filters.set(filterIndex, km);
1969 * Action on any change to feature filtering, namely
1971 * <li>change of selected attribute</li>
1972 * <li>change of selected condition</li>
1973 * <li>change of match pattern</li>
1974 * <li>removal of a condition</li>
1976 * The inputs are parsed into a combined filter and this is set for the
1977 * feature type, and the alignment redrawn.
1979 protected void filtersChanged()
1982 * update the filter conditions for the feature type
1984 boolean anded = andFilters.isSelected();
1985 FeatureMatcherSetI combined = new FeatureMatcherSet();
1987 for (FeatureMatcherI filter : filters)
1989 String pattern = filter.getMatcher().getPattern();
1990 Condition condition = filter.getMatcher().getCondition();
1991 if (pattern.trim().length() > 0 || !condition.needsAPattern())
1995 combined.and(filter);
1999 combined.or(filter);
2005 * save the filter conditions in the FeatureRenderer
2006 * (note this might now be an empty filter with no conditions)
2008 fr.setFeatureFilter(featureType, combined.isEmpty() ? null : combined);
2009 if (applyFiltersToSubtypes)
2011 for (String child : relatedSoTerms.get(parentSOTerm))
2013 fr.setFeatureFilter(child, combined.isEmpty() ? null : combined);
2017 refreshFeatureSettings();
2018 ap.paintAlignment(true, true);