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.
24 import java.awt.BorderLayout;
25 import java.awt.CardLayout;
26 import java.awt.Color;
27 import java.awt.Dimension;
28 import java.awt.event.ActionEvent;
29 import java.awt.event.ActionListener;
30 import java.awt.event.FocusAdapter;
31 import java.awt.event.FocusEvent;
32 import java.awt.event.ItemEvent;
33 import java.awt.event.ItemListener;
34 import java.awt.event.KeyEvent;
36 import javax.swing.ButtonGroup;
37 import javax.swing.JCheckBox;
38 import javax.swing.JComboBox;
39 import javax.swing.JInternalFrame;
40 import javax.swing.JLayeredPane;
41 import javax.swing.JPanel;
42 import javax.swing.JRadioButton;
43 import javax.swing.border.TitledBorder;
45 import jalview.datamodel.AlignmentAnnotation;
46 import jalview.datamodel.HiddenColumns;
47 import jalview.io.cache.JvCacheableInputBox;
48 import jalview.schemes.AnnotationColourGradient;
49 import jalview.util.MessageManager;
50 import jalview.util.Platform;
51 import jalview.viewmodel.annotationfilter.AnnotationFilterParameter;
52 import net.miginfocom.swing.MigLayout;
54 @SuppressWarnings("serial")
55 public class AnnotationColumnChooser extends AnnotationRowFilter
56 implements ItemListener
58 private JPanel switchableViewsPanel = new JPanel(new CardLayout());
60 private JPanel annotationComboBoxPanel = new JPanel();
62 private StructureFilterPanel gStructureFilterPanel;
64 private StructureFilterPanel ngStructureFilterPanel;
66 private StructureFilterPanel currentStructureFilterPanel;
68 private SearchPanel currentSearchPanel;
70 private SearchPanel gSearchPanel;
72 private SearchPanel ngSearchPanel;
74 private FurtherActionPanel currentFurtherActionPanel;
76 private FurtherActionPanel gFurtherActionPanel;
78 private FurtherActionPanel ngFurtherActionPanel;
80 public static final int ACTION_OPTION_SELECT = 1;
82 public static int ACTION_OPTION_HIDE = 2;
84 public static String NO_GRAPH_VIEW = "0";
86 public static String GRAPH_VIEW = "1";
88 private int actionOption = ACTION_OPTION_SELECT;
90 private HiddenColumns oldHiddenColumns;
92 protected static int MIN_WIDTH = (Platform.isJS() ? 370 : 420);
94 protected static int MIN_HEIGHT = (Platform.isJS() ? 370 : 430);
96 public AnnotationColumnChooser(AlignViewport av, final AlignmentPanel ap)
99 frame = new JInternalFrame();
100 frame.setContentPane(this);
101 frame.setLayer(JLayeredPane.PALETTE_LAYER);
102 Desktop.addInternalFrame(frame,
103 MessageManager.getString("label.select_by_annotation"), 0, 0);
104 // BH note: MIGLayout ignores this completely,
105 // possibly creating a frame smaller than specified:
106 frame.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT));
108 addSliderChangeListener();
109 addSliderMouseListeners();
111 if (av.getAlignment().getAlignmentAnnotation() == null)
115 setOldHiddenColumns(av.getAlignment().getHiddenColumns());
118 setAnnotations(new JComboBox<>(getAnnotationItems(false)));
119 populateThresholdComboBox(threshold);
120 AnnotationColumnChooser lastChooser = av
121 .getAnnotationColumnSelectionState();
122 // restore Object state from the previous session if one exists
123 if (lastChooser != null)
125 currentSearchPanel = lastChooser.getCurrentSearchPanel();
126 currentStructureFilterPanel = lastChooser
127 .getCurrentStructureFilterPanel();
128 annotations.setSelectedIndex(
129 lastChooser.getAnnotations().getSelectedIndex());
130 threshold.setSelectedIndex(
131 lastChooser.getThreshold().getSelectedIndex());
132 actionOption = lastChooser.getActionOption();
134 .setSelected(lastChooser.percentThreshold.isSelected());
140 } catch (Exception ex)
151 protected void jbInit()
155 JPanel thresholdPanel = new JPanel();
156 thresholdPanel.setBorder(new TitledBorder(
157 MessageManager.getString("label.threshold_filter")));
158 thresholdPanel.setBackground(Color.white);
159 thresholdPanel.setFont(JvSwingUtils.getLabelFont());
160 thresholdPanel.setLayout(new MigLayout("", "[left][right]", "[][]"));
162 percentThreshold.setBackground(Color.white);
163 percentThreshold.setFont(JvSwingUtils.getLabelFont());
165 JPanel actionPanel = new JPanel();
166 actionPanel.setBackground(Color.white);
167 actionPanel.setFont(JvSwingUtils.getLabelFont());
169 JPanel graphFilterView = new JPanel();
170 graphFilterView.setLayout(new MigLayout("", "[left][right]", "[][]"));
171 graphFilterView.setBackground(Color.white);
173 JPanel noGraphFilterView = new JPanel();
174 noGraphFilterView.setLayout(new MigLayout("", "[left][right]", "[][]"));
175 noGraphFilterView.setBackground(Color.white);
177 annotationComboBoxPanel.setBackground(Color.white);
178 annotationComboBoxPanel.setFont(JvSwingUtils.getLabelFont());
180 gSearchPanel = new SearchPanel(this);
181 ngSearchPanel = new SearchPanel(this);
182 gFurtherActionPanel = new FurtherActionPanel(this);
183 ngFurtherActionPanel = new FurtherActionPanel(this);
184 gStructureFilterPanel = new StructureFilterPanel(this);
185 ngStructureFilterPanel = new StructureFilterPanel(this);
187 thresholdPanel.add(getThreshold());
188 thresholdPanel.add(percentThreshold, "wrap");
189 thresholdPanel.add(slider, "grow");
190 thresholdPanel.add(thresholdValue, "span, wrap");
193 actionPanel.add(cancel);
195 graphFilterView.add(gSearchPanel, "grow, span, wrap");
196 graphFilterView.add(gStructureFilterPanel, "grow, span, wrap");
197 graphFilterView.add(thresholdPanel, "grow, span, wrap");
198 graphFilterView.add(gFurtherActionPanel);
200 noGraphFilterView.add(ngSearchPanel, "grow, span, wrap");
201 noGraphFilterView.add(ngStructureFilterPanel, "grow, span, wrap");
202 noGraphFilterView.add(ngFurtherActionPanel);
204 annotationComboBoxPanel.add(getAnnotations());
205 switchableViewsPanel.add(noGraphFilterView,
206 AnnotationColumnChooser.NO_GRAPH_VIEW);
207 switchableViewsPanel.add(graphFilterView,
208 AnnotationColumnChooser.GRAPH_VIEW);
209 this.setLayout(new BorderLayout());
210 this.add(annotationComboBoxPanel, java.awt.BorderLayout.PAGE_START);
211 this.add(switchableViewsPanel, java.awt.BorderLayout.CENTER);
212 this.add(actionPanel, java.awt.BorderLayout.SOUTH);
214 selectedAnnotationChanged();
215 updateThresholdPanelToolTip();
219 protected void updateThresholdPanelToolTip()
221 thresholdValue.setToolTipText("");
222 slider.setToolTipText("");
224 String defaultTtip = MessageManager
225 .getString("info.change_threshold_mode_to_enable");
227 String thresh = getThreshold().getSelectedItem().toString();
228 if (thresh.equalsIgnoreCase("No Threshold"))
230 thresholdValue.setToolTipText(defaultTtip);
231 slider.setToolTipText(defaultTtip);
236 protected void reset()
238 if (this.getOldHiddenColumns() != null)
240 av.getColumnSelection().clear();
242 if (av.getAnnotationColumnSelectionState() != null)
244 HiddenColumns oldHidden = av.getAnnotationColumnSelectionState()
245 .getOldHiddenColumns();
246 av.getAlignment().setHiddenColumns(oldHidden);
249 ap.paintAlignment(true, true);
254 public void valueChanged(boolean updateAllAnnotation)
256 if (slider.isEnabled())
258 getCurrentAnnotation().threshold.value = getSliderValue();
260 propagateSeqAssociatedThreshold(updateAllAnnotation,
261 getCurrentAnnotation());
262 ap.paintAlignment(false, false);
267 public void updateView()
269 // Check if combobox is still adjusting
275 AnnotationFilterParameter filterParams = new AnnotationFilterParameter();
277 setCurrentAnnotation(av.getAlignment()
278 .getAlignmentAnnotation()[annmap[getAnnotations()
279 .getSelectedIndex()]]);
281 int selectedThresholdItem = getSelectedThresholdItem(
282 getThreshold().getSelectedIndex());
284 slider.setEnabled(true);
285 thresholdValue.setEnabled(true);
286 percentThreshold.setEnabled(true);
288 final AlignmentAnnotation currentAnnotation = getCurrentAnnotation();
289 if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
291 slider.setEnabled(false);
292 thresholdValue.setEnabled(false);
293 thresholdValue.setText("");
294 percentThreshold.setEnabled(false);
295 // build filter params
297 else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
299 if (currentAnnotation.threshold == null)
301 currentAnnotation.setThreshold(new jalview.datamodel.GraphLine(
302 (currentAnnotation.graphMax - currentAnnotation.graphMin)
304 "Threshold", Color.black));
309 setSliderModel(currentAnnotation.graphMin, currentAnnotation.graphMax,
310 currentAnnotation.threshold.value);
312 setThresholdValueText();
314 slider.setEnabled(true);
315 thresholdValue.setEnabled(true);
318 // build filter params
319 filterParams.setThresholdType(
320 AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);
321 if (currentAnnotation.isQuantitative())
323 filterParams.setThresholdValue(currentAnnotation.threshold.value);
325 if (selectedThresholdItem == AnnotationColourGradient.ABOVE_THRESHOLD)
327 filterParams.setThresholdType(
328 AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD);
330 else if (selectedThresholdItem == AnnotationColourGradient.BELOW_THRESHOLD)
332 filterParams.setThresholdType(
333 AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD);
338 updateThresholdPanelToolTip();
339 if (currentStructureFilterPanel != null)
341 if (currentStructureFilterPanel.alphaHelix.isSelected())
343 filterParams.setFilterAlphaHelix(true);
345 if (currentStructureFilterPanel.betaStrand.isSelected())
347 filterParams.setFilterBetaSheet(true);
349 if (currentStructureFilterPanel.turn.isSelected())
351 filterParams.setFilterTurn(true);
355 if (currentSearchPanel != null)
357 if (!currentSearchPanel.searchBox.getUserInput().isEmpty())
359 filterParams.setRegexString(
360 currentSearchPanel.searchBox.getUserInput());
361 if (currentSearchPanel.displayName.isSelected())
363 filterParams.addRegexSearchField(
364 AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING);
366 if (currentSearchPanel.description.isSelected())
368 filterParams.addRegexSearchField(
369 AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION);
374 // show hidden columns here, before changing the column selection in
375 // filterAnnotations, because showing hidden columns has the side effect of
376 // adding them to the selection
377 av.showAllHiddenColumns();
378 av.getColumnSelection().filterAnnotations(currentAnnotation,
381 boolean hideCols = getActionOption() == ACTION_OPTION_HIDE;
384 av.hideSelectedColumns();
389 av.setAnnotationColumnSelectionState(this);
390 // only update overview and structures if columns were hidden
391 ap.paintAlignment(hideCols, hideCols);
394 public HiddenColumns getOldHiddenColumns()
396 return oldHiddenColumns;
399 public void setOldHiddenColumns(HiddenColumns currentHiddenColumns)
401 if (currentHiddenColumns != null)
403 this.oldHiddenColumns = new HiddenColumns(currentHiddenColumns);
407 public FurtherActionPanel getCurrentFutherActionPanel()
409 return currentFurtherActionPanel;
412 public void setCurrentFutherActionPanel(
413 FurtherActionPanel currentFutherActionPanel)
415 this.currentFurtherActionPanel = currentFutherActionPanel;
418 public SearchPanel getCurrentSearchPanel()
420 return currentSearchPanel;
423 public void setCurrentSearchPanel(SearchPanel currentSearchPanel)
425 this.currentSearchPanel = currentSearchPanel;
428 public int getActionOption()
433 public void setActionOption(int actionOption)
435 this.actionOption = actionOption;
438 public StructureFilterPanel getCurrentStructureFilterPanel()
440 return currentStructureFilterPanel;
443 public void setCurrentStructureFilterPanel(
444 StructureFilterPanel currentStructureFilterPanel)
446 this.currentStructureFilterPanel = currentStructureFilterPanel;
449 public void select_action(ActionEvent actionEvent)
451 JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
452 if (radioButton.isSelected())
454 setActionOption(ACTION_OPTION_SELECT);
459 public void hide_action(ActionEvent actionEvent)
461 JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
462 if (radioButton.isSelected())
464 setActionOption(ACTION_OPTION_HIDE);
470 public void itemStateChanged(ItemEvent e)
472 selectedAnnotationChanged();
476 public void selectedAnnotationChanged()
478 String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
479 if (av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
480 .getSelectedIndex()]].isQuantitative())
482 currentView = AnnotationColumnChooser.GRAPH_VIEW;
485 gSearchPanel.syncState();
486 gFurtherActionPanel.syncState();
487 gStructureFilterPanel.syncState();
489 ngSearchPanel.syncState();
490 ngFurtherActionPanel.syncState();
491 ngStructureFilterPanel.syncState();
493 CardLayout switchableViewsLayout = (CardLayout) switchableViewsPanel
495 switchableViewsLayout.show(switchableViewsPanel, currentView);
499 public class FurtherActionPanel extends JPanel
501 private AnnotationColumnChooser aColChooser;
503 private JRadioButton hideOption = new JRadioButton();
505 private JRadioButton selectOption = new JRadioButton();
507 private ButtonGroup optionsGroup = new ButtonGroup();
509 public FurtherActionPanel(AnnotationColumnChooser aColChooser)
511 this.aColChooser = aColChooser;
512 JvSwingUtils.jvInitComponent(selectOption, "action.select");
513 selectOption.addActionListener(new ActionListener()
516 public void actionPerformed(ActionEvent actionEvent)
518 selectRadioAction(actionEvent);
522 JvSwingUtils.jvInitComponent(hideOption, "action.hide");
523 hideOption.addActionListener(new ActionListener()
526 public void actionPerformed(ActionEvent actionEvent)
528 hideRadioAction(actionEvent);
532 optionsGroup.add(selectOption);
533 optionsGroup.add(hideOption);
534 optionsGroup.setSelected(selectOption.getModel(), true);
536 JvSwingUtils.jvInitComponent(this);
539 this.add(selectOption);
540 this.add(hideOption);
543 public void selectRadioAction(ActionEvent actionEvent)
545 aColChooser.setCurrentFutherActionPanel(this);
546 aColChooser.select_action(actionEvent);
549 public void hideRadioAction(ActionEvent actionEvent)
551 aColChooser.setCurrentFutherActionPanel(this);
552 aColChooser.hide_action(actionEvent);
555 public void syncState()
558 .getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
560 this.optionsGroup.setSelected(this.hideOption.getModel(), true);
564 this.optionsGroup.setSelected(this.selectOption.getModel(), true);
569 public class StructureFilterPanel extends JPanel
571 private AnnotationColumnChooser aColChooser;
573 private JCheckBox alphaHelix = new JCheckBox();
575 private JCheckBox betaStrand = new JCheckBox();
577 private JCheckBox turn = new JCheckBox();
579 private JCheckBox all = new JCheckBox();
581 public StructureFilterPanel(AnnotationColumnChooser aColChooser)
583 this.aColChooser = aColChooser;
585 JvSwingUtils.jvInitComponent(alphaHelix, "label.alpha_helix");
586 alphaHelix.addActionListener(new ActionListener()
589 public void actionPerformed(ActionEvent actionEvent)
591 alphaHelix_actionPerformed();
595 JvSwingUtils.jvInitComponent(betaStrand, "label.beta_strand");
596 betaStrand.addActionListener(new ActionListener()
599 public void actionPerformed(ActionEvent actionEvent)
601 betaStrand_actionPerformed();
605 JvSwingUtils.jvInitComponent(turn, "label.turn");
606 turn.addActionListener(new ActionListener()
609 public void actionPerformed(ActionEvent actionEvent)
611 turn_actionPerformed();
615 JvSwingUtils.jvInitComponent(all, "label.select_all");
616 all.addActionListener(new ActionListener()
619 public void actionPerformed(ActionEvent actionEvent)
621 all_actionPerformed();
625 this.setBorder(new TitledBorder(
626 MessageManager.getString("label.structures_filter")));
627 JvSwingUtils.jvInitComponent(this);
630 this.add(alphaHelix);
631 this.add(betaStrand);
635 public void alphaHelix_actionPerformed()
637 updateSelectAllState();
638 aColChooser.setCurrentStructureFilterPanel(this);
639 aColChooser.updateView();
642 public void betaStrand_actionPerformed()
644 updateSelectAllState();
645 aColChooser.setCurrentStructureFilterPanel(this);
646 aColChooser.updateView();
649 public void turn_actionPerformed()
651 updateSelectAllState();
652 aColChooser.setCurrentStructureFilterPanel(this);
653 aColChooser.updateView();
656 public void all_actionPerformed()
658 if (all.isSelected())
660 alphaHelix.setSelected(true);
661 betaStrand.setSelected(true);
662 turn.setSelected(true);
666 alphaHelix.setSelected(false);
667 betaStrand.setSelected(false);
668 turn.setSelected(false);
670 aColChooser.setCurrentStructureFilterPanel(this);
671 aColChooser.updateView();
674 public void updateSelectAllState()
676 if (alphaHelix.isSelected() && betaStrand.isSelected()
677 && turn.isSelected())
679 all.setSelected(true);
683 all.setSelected(false);
687 public void syncState()
689 StructureFilterPanel sfp = aColChooser
690 .getCurrentStructureFilterPanel();
693 alphaHelix.setSelected(sfp.alphaHelix.isSelected());
694 betaStrand.setSelected(sfp.betaStrand.isSelected());
695 turn.setSelected(sfp.turn.isSelected());
696 if (sfp.all.isSelected())
698 all.setSelected(true);
699 alphaHelix.setSelected(true);
700 betaStrand.setSelected(true);
701 turn.setSelected(true);
708 public class SearchPanel extends JPanel
710 private AnnotationColumnChooser aColChooser;
712 private JCheckBox displayName = new JCheckBox();
714 private JCheckBox description = new JCheckBox();
716 private static final String FILTER_BY_ANN_CACHE_KEY = "CACHE.SELECT_FILTER_BY_ANNOT";
718 public JvCacheableInputBox<String> searchBox = new JvCacheableInputBox<>(
719 FILTER_BY_ANN_CACHE_KEY, 23);
721 public SearchPanel(AnnotationColumnChooser aColChooser)
724 this.aColChooser = aColChooser;
725 JvSwingUtils.jvInitComponent(this);
726 this.setBorder(new TitledBorder(
727 MessageManager.getString("label.search_filter")));
729 searchBox.getComponent().setToolTipText(
730 MessageManager.getString("info.enter_search_text_here"));
731 searchBox.addKeyListener(new java.awt.event.KeyAdapter()
734 public void keyPressed(KeyEvent e)
736 if (e.getKeyCode() == KeyEvent.VK_ENTER)
739 searchStringAction();
743 searchBox.addFocusListener(new FocusAdapter()
746 public void focusLost(FocusEvent e)
748 searchStringAction();
752 JvSwingUtils.jvInitComponent(displayName, "label.label");
753 displayName.addActionListener(new ActionListener()
756 public void actionPerformed(ActionEvent actionEvent)
758 displayNameCheckboxAction();
762 JvSwingUtils.jvInitComponent(description, "label.description");
763 description.addActionListener(new ActionListener()
766 public void actionPerformed(ActionEvent actionEvent)
768 descriptionCheckboxAction();
773 this.add(searchBox.getComponent());
774 this.add(displayName);
775 this.add(description);
778 public void displayNameCheckboxAction()
780 aColChooser.setCurrentSearchPanel(this);
781 aColChooser.updateView();
784 public void descriptionCheckboxAction()
786 aColChooser.setCurrentSearchPanel(this);
787 aColChooser.updateView();
790 public void searchStringAction()
792 aColChooser.setCurrentSearchPanel(this);
793 aColChooser.updateView();
794 updateSearchPanelToolTips();
795 searchBox.updateCache();
798 public void syncState()
800 SearchPanel sp = aColChooser.getCurrentSearchPanel();
803 description.setEnabled(sp.description.isEnabled());
804 description.setSelected(sp.description.isSelected());
806 displayName.setEnabled(sp.displayName.isEnabled());
807 displayName.setSelected(sp.displayName.isSelected());
809 searchBox.setSelectedItem(sp.searchBox.getUserInput());
811 updateSearchPanelToolTips();
814 public void updateSearchPanelToolTips()
816 String defaultTtip = MessageManager
817 .getString("info.enter_search_text_to_enable");
818 String labelTtip = MessageManager.formatMessage(
819 "info.search_in_annotation_label",
820 annotations.getSelectedItem().toString());
821 String descTtip = MessageManager.formatMessage(
822 "info.search_in_annotation_description",
823 annotations.getSelectedItem().toString());
824 displayName.setToolTipText(
825 displayName.isEnabled() ? labelTtip : defaultTtip);
826 description.setToolTipText(
827 description.isEnabled() ? descTtip : defaultTtip);
832 public void ok_actionPerformed()
835 super.ok_actionPerformed();
839 public void cancel_actionPerformed()
842 super.cancel_actionPerformed();
845 private void saveCache()
847 gSearchPanel.searchBox.persistCache();
848 ngSearchPanel.searchBox.persistCache();
849 gSearchPanel.searchBox.updateCache();
850 ngSearchPanel.searchBox.updateCache();