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 jalview.datamodel.AlignmentAnnotation;
25 import jalview.datamodel.HiddenColumns;
26 import jalview.io.cache.JvCacheableInputBox;
27 import jalview.schemes.AnnotationColourGradient;
28 import jalview.util.MessageManager;
29 import jalview.viewmodel.annotationfilter.AnnotationFilterParameter;
31 import java.awt.BorderLayout;
32 import java.awt.CardLayout;
33 import java.awt.Color;
34 import java.awt.Dimension;
35 import java.awt.event.ActionEvent;
36 import java.awt.event.ActionListener;
37 import java.awt.event.FocusAdapter;
38 import java.awt.event.FocusEvent;
39 import java.awt.event.ItemEvent;
40 import java.awt.event.ItemListener;
41 import java.awt.event.KeyEvent;
43 import javax.swing.ButtonGroup;
44 import javax.swing.JCheckBox;
45 import javax.swing.JComboBox;
46 import javax.swing.JInternalFrame;
47 import javax.swing.JLayeredPane;
48 import javax.swing.JPanel;
49 import javax.swing.JRadioButton;
50 import javax.swing.border.TitledBorder;
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 int MIN_WIDTH = 420;
94 protected int MIN_HEIGHT = 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"), 520,
105 frame.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT));
107 addSliderChangeListener();
108 addSliderMouseListeners();
110 if (av.getAlignment().getAlignmentAnnotation() == null)
114 setOldHiddenColumns(av.getAlignment().getHiddenColumns());
117 setAnnotations(new JComboBox<>(getAnnotationItems(false)));
118 populateThresholdComboBox(threshold);
119 AnnotationColumnChooser lastChooser = av
120 .getAnnotationColumnSelectionState();
121 // restore Object state from the previous session if one exists
122 if (lastChooser != null)
124 currentSearchPanel = lastChooser.getCurrentSearchPanel();
125 currentStructureFilterPanel = lastChooser
126 .getCurrentStructureFilterPanel();
127 annotations.setSelectedIndex(
128 lastChooser.getAnnotations().getSelectedIndex());
129 threshold.setSelectedIndex(
130 lastChooser.getThreshold().getSelectedIndex());
131 actionOption = lastChooser.getActionOption();
133 .setSelected(lastChooser.percentThreshold.isSelected());
139 } catch (Exception ex)
150 protected void jbInit()
154 JPanel thresholdPanel = new JPanel();
155 thresholdPanel.setBorder(new TitledBorder(
156 MessageManager.getString("label.threshold_filter")));
157 thresholdPanel.setBackground(Color.white);
158 thresholdPanel.setFont(JvSwingUtils.getLabelFont());
159 thresholdPanel.setLayout(new MigLayout("", "[left][right]", "[][]"));
161 percentThreshold.setBackground(Color.white);
162 percentThreshold.setFont(JvSwingUtils.getLabelFont());
164 JPanel actionPanel = new JPanel();
165 actionPanel.setBackground(Color.white);
166 actionPanel.setFont(JvSwingUtils.getLabelFont());
168 JPanel graphFilterView = new JPanel();
169 graphFilterView.setLayout(new MigLayout("", "[left][right]", "[][]"));
170 graphFilterView.setBackground(Color.white);
172 JPanel noGraphFilterView = new JPanel();
173 noGraphFilterView.setLayout(new MigLayout("", "[left][right]", "[][]"));
174 noGraphFilterView.setBackground(Color.white);
176 annotationComboBoxPanel.setBackground(Color.white);
177 annotationComboBoxPanel.setFont(JvSwingUtils.getLabelFont());
179 gSearchPanel = new SearchPanel(this);
180 ngSearchPanel = new SearchPanel(this);
181 gFurtherActionPanel = new FurtherActionPanel(this);
182 ngFurtherActionPanel = new FurtherActionPanel(this);
183 gStructureFilterPanel = new StructureFilterPanel(this);
184 ngStructureFilterPanel = new StructureFilterPanel(this);
186 thresholdPanel.add(getThreshold());
187 thresholdPanel.add(percentThreshold, "wrap");
188 thresholdPanel.add(slider, "grow");
189 thresholdPanel.add(thresholdValue, "span, wrap");
192 actionPanel.add(cancel);
194 graphFilterView.add(gSearchPanel, "grow, span, wrap");
195 graphFilterView.add(gStructureFilterPanel, "grow, span, wrap");
196 graphFilterView.add(thresholdPanel, "grow, span, wrap");
197 graphFilterView.add(gFurtherActionPanel);
199 noGraphFilterView.add(ngSearchPanel, "grow, span, wrap");
200 noGraphFilterView.add(ngStructureFilterPanel, "grow, span, wrap");
201 noGraphFilterView.add(ngFurtherActionPanel);
203 annotationComboBoxPanel.add(getAnnotations());
204 switchableViewsPanel.add(noGraphFilterView,
205 AnnotationColumnChooser.NO_GRAPH_VIEW);
206 switchableViewsPanel.add(graphFilterView,
207 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
303 - currentAnnotation.graphMin) / 2f,
304 "Threshold", Color.black));
309 setSliderModel(currentAnnotation.graphMin,
310 currentAnnotation.graphMax,
311 currentAnnotation.threshold.value);
313 setThresholdValueText();
315 slider.setEnabled(true);
316 thresholdValue.setEnabled(true);
319 // build filter params
320 filterParams.setThresholdType(
321 AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);
322 if (currentAnnotation.isQuantitative())
325 .setThresholdValue(currentAnnotation.threshold.value);
327 if (selectedThresholdItem == AnnotationColourGradient.ABOVE_THRESHOLD)
329 filterParams.setThresholdType(
330 AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD);
332 else if (selectedThresholdItem == AnnotationColourGradient.BELOW_THRESHOLD)
334 filterParams.setThresholdType(
335 AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD);
340 updateThresholdPanelToolTip();
341 if (currentStructureFilterPanel != null)
343 if (currentStructureFilterPanel.alphaHelix.isSelected())
345 filterParams.setFilterAlphaHelix(true);
347 if (currentStructureFilterPanel.betaStrand.isSelected())
349 filterParams.setFilterBetaSheet(true);
351 if (currentStructureFilterPanel.turn.isSelected())
353 filterParams.setFilterTurn(true);
357 if (currentSearchPanel != null)
359 if (!currentSearchPanel.searchBox.getUserInput().isEmpty())
361 filterParams.setRegexString(
362 currentSearchPanel.searchBox.getUserInput());
363 if (currentSearchPanel.displayName.isSelected())
365 filterParams.addRegexSearchField(
366 AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING);
368 if (currentSearchPanel.description.isSelected())
370 filterParams.addRegexSearchField(
371 AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION);
376 // show hidden columns here, before changing the column selection in
377 // filterAnnotations, because showing hidden columns has the side effect of
378 // adding them to the selection
379 av.showAllHiddenColumns();
380 av.getColumnSelection().filterAnnotations(
381 currentAnnotation.annotations, filterParams);
383 boolean hideCols = getActionOption() == ACTION_OPTION_HIDE;
386 av.hideSelectedColumns();
391 av.setAnnotationColumnSelectionState(this);
392 // only update overview and structures if columns were hidden
393 ap.paintAlignment(hideCols, hideCols);
396 public HiddenColumns getOldHiddenColumns()
398 return oldHiddenColumns;
401 public void setOldHiddenColumns(HiddenColumns currentHiddenColumns)
403 if (currentHiddenColumns != null)
405 this.oldHiddenColumns = new HiddenColumns(currentHiddenColumns);
409 public FurtherActionPanel getCurrentFutherActionPanel()
411 return currentFurtherActionPanel;
414 public void setCurrentFutherActionPanel(
415 FurtherActionPanel currentFutherActionPanel)
417 this.currentFurtherActionPanel = currentFutherActionPanel;
420 public SearchPanel getCurrentSearchPanel()
422 return currentSearchPanel;
425 public void setCurrentSearchPanel(SearchPanel currentSearchPanel)
427 this.currentSearchPanel = currentSearchPanel;
430 public int getActionOption()
435 public void setActionOption(int actionOption)
437 this.actionOption = actionOption;
440 public StructureFilterPanel getCurrentStructureFilterPanel()
442 return currentStructureFilterPanel;
445 public void setCurrentStructureFilterPanel(
446 StructureFilterPanel currentStructureFilterPanel)
448 this.currentStructureFilterPanel = currentStructureFilterPanel;
451 public void select_action(ActionEvent actionEvent)
453 JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
454 if (radioButton.isSelected())
456 setActionOption(ACTION_OPTION_SELECT);
461 public void hide_action(ActionEvent actionEvent)
463 JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
464 if (radioButton.isSelected())
466 setActionOption(ACTION_OPTION_HIDE);
472 public void itemStateChanged(ItemEvent e)
474 selectedAnnotationChanged();
478 public void selectedAnnotationChanged()
480 String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
481 if (av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
482 .getSelectedIndex()]].isQuantitative())
484 currentView = AnnotationColumnChooser.GRAPH_VIEW;
487 gSearchPanel.syncState();
488 gFurtherActionPanel.syncState();
489 gStructureFilterPanel.syncState();
491 ngSearchPanel.syncState();
492 ngFurtherActionPanel.syncState();
493 ngStructureFilterPanel.syncState();
495 CardLayout switchableViewsLayout = (CardLayout) switchableViewsPanel
497 switchableViewsLayout.show(switchableViewsPanel, currentView);
501 public class FurtherActionPanel extends JPanel
503 private AnnotationColumnChooser aColChooser;
505 private JRadioButton hideOption = new JRadioButton();
507 private JRadioButton selectOption = new JRadioButton();
509 private ButtonGroup optionsGroup = new ButtonGroup();
511 public FurtherActionPanel(AnnotationColumnChooser aColChooser)
513 this.aColChooser = aColChooser;
514 JvSwingUtils.jvInitComponent(selectOption, "action.select");
515 selectOption.addActionListener(new ActionListener()
518 public void actionPerformed(ActionEvent actionEvent)
520 selectRadioAction(actionEvent);
524 JvSwingUtils.jvInitComponent(hideOption, "action.hide");
525 hideOption.addActionListener(new ActionListener()
528 public void actionPerformed(ActionEvent actionEvent)
530 hideRadioAction(actionEvent);
534 optionsGroup.add(selectOption);
535 optionsGroup.add(hideOption);
536 optionsGroup.setSelected(selectOption.getModel(), true);
538 JvSwingUtils.jvInitComponent(this);
541 this.add(selectOption);
542 this.add(hideOption);
545 public void selectRadioAction(ActionEvent actionEvent)
547 aColChooser.setCurrentFutherActionPanel(this);
548 aColChooser.select_action(actionEvent);
551 public void hideRadioAction(ActionEvent actionEvent)
553 aColChooser.setCurrentFutherActionPanel(this);
554 aColChooser.hide_action(actionEvent);
557 public void syncState()
560 .getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
562 this.optionsGroup.setSelected(this.hideOption.getModel(), true);
566 this.optionsGroup.setSelected(this.selectOption.getModel(), true);
571 public class StructureFilterPanel extends JPanel
573 private AnnotationColumnChooser aColChooser;
575 private JCheckBox alphaHelix = new JCheckBox();
577 private JCheckBox betaStrand = new JCheckBox();
579 private JCheckBox turn = new JCheckBox();
581 private JCheckBox all = new JCheckBox();
583 public StructureFilterPanel(AnnotationColumnChooser aColChooser)
585 this.aColChooser = aColChooser;
587 JvSwingUtils.jvInitComponent(alphaHelix, "label.alpha_helix");
588 alphaHelix.addActionListener(new ActionListener()
591 public void actionPerformed(ActionEvent actionEvent)
593 alphaHelix_actionPerformed();
597 JvSwingUtils.jvInitComponent(betaStrand, "label.beta_strand");
598 betaStrand.addActionListener(new ActionListener()
601 public void actionPerformed(ActionEvent actionEvent)
603 betaStrand_actionPerformed();
607 JvSwingUtils.jvInitComponent(turn, "label.turn");
608 turn.addActionListener(new ActionListener()
611 public void actionPerformed(ActionEvent actionEvent)
613 turn_actionPerformed();
617 JvSwingUtils.jvInitComponent(all, "label.select_all");
618 all.addActionListener(new ActionListener()
621 public void actionPerformed(ActionEvent actionEvent)
623 all_actionPerformed();
627 this.setBorder(new TitledBorder(
628 MessageManager.getString("label.structures_filter")));
629 JvSwingUtils.jvInitComponent(this);
632 this.add(alphaHelix);
633 this.add(betaStrand);
637 public void alphaHelix_actionPerformed()
639 updateSelectAllState();
640 aColChooser.setCurrentStructureFilterPanel(this);
641 aColChooser.updateView();
644 public void betaStrand_actionPerformed()
646 updateSelectAllState();
647 aColChooser.setCurrentStructureFilterPanel(this);
648 aColChooser.updateView();
651 public void turn_actionPerformed()
653 updateSelectAllState();
654 aColChooser.setCurrentStructureFilterPanel(this);
655 aColChooser.updateView();
658 public void all_actionPerformed()
660 if (all.isSelected())
662 alphaHelix.setSelected(true);
663 betaStrand.setSelected(true);
664 turn.setSelected(true);
668 alphaHelix.setSelected(false);
669 betaStrand.setSelected(false);
670 turn.setSelected(false);
672 aColChooser.setCurrentStructureFilterPanel(this);
673 aColChooser.updateView();
676 public void updateSelectAllState()
678 if (alphaHelix.isSelected() && betaStrand.isSelected()
679 && turn.isSelected())
681 all.setSelected(true);
685 all.setSelected(false);
689 public void syncState()
691 StructureFilterPanel sfp = aColChooser
692 .getCurrentStructureFilterPanel();
695 alphaHelix.setSelected(sfp.alphaHelix.isSelected());
696 betaStrand.setSelected(sfp.betaStrand.isSelected());
697 turn.setSelected(sfp.turn.isSelected());
698 if (sfp.all.isSelected())
700 all.setSelected(true);
701 alphaHelix.setSelected(true);
702 betaStrand.setSelected(true);
703 turn.setSelected(true);
710 public class SearchPanel extends JPanel
712 private AnnotationColumnChooser aColChooser;
714 private JCheckBox displayName = new JCheckBox();
716 private JCheckBox description = new JCheckBox();
718 private static final String FILTER_BY_ANN_CACHE_KEY = "CACHE.SELECT_FILTER_BY_ANNOT";
720 public JvCacheableInputBox<String> searchBox = new JvCacheableInputBox<>(
721 FILTER_BY_ANN_CACHE_KEY);
723 public SearchPanel(AnnotationColumnChooser aColChooser)
726 this.aColChooser = aColChooser;
727 JvSwingUtils.jvInitComponent(this);
728 this.setBorder(new TitledBorder(
729 MessageManager.getString("label.search_filter")));
731 searchBox.setPrototypeDisplayValue("XXXXXXXXXXXXXXXXXXXXXXX");
732 searchBox.setToolTipText(
733 MessageManager.getString("info.enter_search_text_here"));
734 searchBox.getEditor().getEditorComponent()
735 .addKeyListener(new java.awt.event.KeyAdapter()
738 public void keyPressed(KeyEvent e)
740 if (e.getKeyCode() == KeyEvent.VK_ENTER)
743 searchStringAction();
747 searchBox.getEditor().getEditorComponent()
748 .addFocusListener(new FocusAdapter()
751 public void focusLost(FocusEvent e)
753 searchStringAction();
757 JvSwingUtils.jvInitComponent(displayName, "label.label");
758 displayName.addActionListener(new ActionListener()
761 public void actionPerformed(ActionEvent actionEvent)
763 displayNameCheckboxAction();
767 JvSwingUtils.jvInitComponent(description, "label.description");
768 description.addActionListener(new ActionListener()
771 public void actionPerformed(ActionEvent actionEvent)
773 descriptionCheckboxAction();
779 this.add(displayName);
780 this.add(description);
783 public void displayNameCheckboxAction()
785 aColChooser.setCurrentSearchPanel(this);
786 aColChooser.updateView();
789 public void descriptionCheckboxAction()
791 aColChooser.setCurrentSearchPanel(this);
792 aColChooser.updateView();
795 public void searchStringAction()
797 aColChooser.setCurrentSearchPanel(this);
798 aColChooser.updateView();
799 updateSearchPanelToolTips();
800 searchBox.updateCache();
803 public void syncState()
805 SearchPanel sp = aColChooser.getCurrentSearchPanel();
808 description.setEnabled(sp.description.isEnabled());
809 description.setSelected(sp.description.isSelected());
811 displayName.setEnabled(sp.displayName.isEnabled());
812 displayName.setSelected(sp.displayName.isSelected());
814 searchBox.setSelectedItem(sp.searchBox.getUserInput());
816 updateSearchPanelToolTips();
819 public void updateSearchPanelToolTips()
821 String defaultTtip = MessageManager
822 .getString("info.enter_search_text_to_enable");
823 String labelTtip = MessageManager.formatMessage(
824 "info.search_in_annotation_label",
825 annotations.getSelectedItem().toString());
826 String descTtip = MessageManager.formatMessage(
827 "info.search_in_annotation_description",
828 annotations.getSelectedItem().toString());
829 displayName.setToolTipText(
830 displayName.isEnabled() ? labelTtip : defaultTtip);
831 description.setToolTipText(
832 description.isEnabled() ? descTtip : defaultTtip);
837 public void ok_actionPerformed()
840 super.ok_actionPerformed();
844 public void cancel_actionPerformed()
847 super.cancel_actionPerformed();
850 private void saveCache()
852 gSearchPanel.searchBox.persistCache();
853 ngSearchPanel.searchBox.persistCache();
854 gSearchPanel.searchBox.updateCache();
855 ngSearchPanel.searchBox.updateCache();