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.util.Platform;
30 import jalview.viewmodel.annotationfilter.AnnotationFilterParameter;
32 import java.awt.BorderLayout;
33 import java.awt.CardLayout;
34 import java.awt.Color;
35 import java.awt.Dimension;
36 import java.awt.event.ActionEvent;
37 import java.awt.event.ActionListener;
38 import java.awt.event.FocusAdapter;
39 import java.awt.event.FocusEvent;
40 import java.awt.event.ItemEvent;
41 import java.awt.event.ItemListener;
42 import java.awt.event.KeyEvent;
44 import javax.swing.ButtonGroup;
45 import javax.swing.JCheckBox;
46 import javax.swing.JComboBox;
47 import javax.swing.JInternalFrame;
48 import javax.swing.JLayeredPane;
49 import javax.swing.JPanel;
50 import javax.swing.JRadioButton;
51 import javax.swing.border.TitledBorder;
53 import net.miginfocom.swing.MigLayout;
55 @SuppressWarnings("serial")
56 public class AnnotationColumnChooser extends AnnotationRowFilter
57 implements ItemListener
59 private JPanel switchableViewsPanel = new JPanel(new CardLayout());
61 private JPanel annotationComboBoxPanel = new JPanel();
63 private StructureFilterPanel gStructureFilterPanel;
65 private StructureFilterPanel ngStructureFilterPanel;
67 private StructureFilterPanel currentStructureFilterPanel;
69 private SearchPanel currentSearchPanel;
71 private SearchPanel gSearchPanel;
73 private SearchPanel ngSearchPanel;
75 private FurtherActionPanel currentFurtherActionPanel;
77 private FurtherActionPanel gFurtherActionPanel;
79 private FurtherActionPanel ngFurtherActionPanel;
81 public static final int ACTION_OPTION_SELECT = 1;
83 public static int ACTION_OPTION_HIDE = 2;
85 public static String NO_GRAPH_VIEW = "0";
87 public static String GRAPH_VIEW = "1";
89 private int actionOption = ACTION_OPTION_SELECT;
91 private HiddenColumns oldHiddenColumns;
93 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,
105 // BH note: MIGLayout ignores this completely,
106 // possibly creating a frame smaller than specified:
107 frame.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT));
109 addSliderChangeListener();
110 addSliderMouseListeners();
112 if (av.getAlignment().getAlignmentAnnotation() == null)
116 setOldHiddenColumns(av.getAlignment().getHiddenColumns());
119 setAnnotations(new JComboBox<>(getAnnotationItems(false)));
120 populateThresholdComboBox(threshold);
121 AnnotationColumnChooser lastChooser = av
122 .getAnnotationColumnSelectionState();
123 // restore Object state from the previous session if one exists
124 if (lastChooser != null)
126 currentSearchPanel = lastChooser.getCurrentSearchPanel();
127 currentStructureFilterPanel = lastChooser
128 .getCurrentStructureFilterPanel();
129 annotations.setSelectedIndex(
130 lastChooser.getAnnotations().getSelectedIndex());
131 threshold.setSelectedIndex(
132 lastChooser.getThreshold().getSelectedIndex());
133 actionOption = lastChooser.getActionOption();
135 .setSelected(lastChooser.percentThreshold.isSelected());
141 } catch (Exception ex)
152 protected void jbInit()
156 JPanel thresholdPanel = new JPanel();
157 thresholdPanel.setBorder(new TitledBorder(
158 MessageManager.getString("label.threshold_filter")));
159 thresholdPanel.setBackground(Color.white);
160 thresholdPanel.setFont(JvSwingUtils.getLabelFont());
161 thresholdPanel.setLayout(new MigLayout("", "[left][right]", "[][]") );
163 percentThreshold.setBackground(Color.white);
164 percentThreshold.setFont(JvSwingUtils.getLabelFont());
166 JPanel actionPanel = new JPanel();
167 actionPanel.setBackground(Color.white);
168 actionPanel.setFont(JvSwingUtils.getLabelFont());
170 JPanel graphFilterView = new JPanel();
171 graphFilterView.setLayout(new MigLayout("", "[left][right]", "[][]"));
172 graphFilterView.setBackground(Color.white);
174 JPanel noGraphFilterView = new JPanel();
175 noGraphFilterView.setLayout(new MigLayout("", "[left][right]", "[][]"));
176 noGraphFilterView.setBackground(Color.white);
178 annotationComboBoxPanel.setBackground(Color.white);
179 annotationComboBoxPanel.setFont(JvSwingUtils.getLabelFont());
181 gSearchPanel = new SearchPanel(this);
182 ngSearchPanel = new SearchPanel(this);
183 gFurtherActionPanel = new FurtherActionPanel(this);
184 ngFurtherActionPanel = new FurtherActionPanel(this);
185 gStructureFilterPanel = new StructureFilterPanel(this);
186 ngStructureFilterPanel = new StructureFilterPanel(this);
188 thresholdPanel.add(getThreshold());
189 thresholdPanel.add(percentThreshold, "wrap");
190 thresholdPanel.add(slider, "grow");
191 thresholdPanel.add(thresholdValue, "span, wrap");
194 actionPanel.add(cancel);
196 graphFilterView.add(gSearchPanel, "grow, span, wrap");
197 graphFilterView.add(gStructureFilterPanel, "grow, span, wrap");
198 graphFilterView.add(thresholdPanel, "grow, span, wrap");
199 graphFilterView.add(gFurtherActionPanel);
201 noGraphFilterView.add(ngSearchPanel, "grow, span, wrap");
202 noGraphFilterView.add(ngStructureFilterPanel, "grow, span, wrap");
203 noGraphFilterView.add(ngFurtherActionPanel);
205 annotationComboBoxPanel.add(getAnnotations());
206 switchableViewsPanel.add(noGraphFilterView,
207 AnnotationColumnChooser.NO_GRAPH_VIEW);
208 switchableViewsPanel.add(graphFilterView,
209 AnnotationColumnChooser.GRAPH_VIEW);
210 this.setLayout(new BorderLayout());
211 this.add(annotationComboBoxPanel, java.awt.BorderLayout.PAGE_START);
212 this.add(switchableViewsPanel, java.awt.BorderLayout.CENTER);
213 this.add(actionPanel, java.awt.BorderLayout.SOUTH);
215 selectedAnnotationChanged();
216 updateThresholdPanelToolTip();
220 protected void updateThresholdPanelToolTip()
222 thresholdValue.setToolTipText("");
223 slider.setToolTipText("");
225 String defaultTtip = MessageManager
226 .getString("info.change_threshold_mode_to_enable");
228 String thresh = getThreshold().getSelectedItem().toString();
229 if (thresh.equalsIgnoreCase("No Threshold"))
231 thresholdValue.setToolTipText(defaultTtip);
232 slider.setToolTipText(defaultTtip);
237 protected void reset()
239 if (this.getOldHiddenColumns() != null)
241 av.getColumnSelection().clear();
243 if (av.getAnnotationColumnSelectionState() != null)
245 HiddenColumns oldHidden = av.getAnnotationColumnSelectionState()
246 .getOldHiddenColumns();
247 av.getAlignment().setHiddenColumns(oldHidden);
250 ap.paintAlignment(true, true);
255 public void valueChanged(boolean updateAllAnnotation)
257 if (slider.isEnabled())
259 getCurrentAnnotation().threshold.value = getSliderValue();
261 propagateSeqAssociatedThreshold(updateAllAnnotation,
262 getCurrentAnnotation());
263 ap.paintAlignment(false, false);
268 public void updateView()
270 // Check if combobox is still adjusting
276 AnnotationFilterParameter filterParams = new AnnotationFilterParameter();
278 setCurrentAnnotation(av.getAlignment()
279 .getAlignmentAnnotation()[annmap[getAnnotations()
280 .getSelectedIndex()]]);
282 int selectedThresholdItem = getSelectedThresholdItem(
283 getThreshold().getSelectedIndex());
285 slider.setEnabled(true);
286 thresholdValue.setEnabled(true);
287 percentThreshold.setEnabled(true);
289 final AlignmentAnnotation currentAnnotation = getCurrentAnnotation();
290 if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
292 slider.setEnabled(false);
293 thresholdValue.setEnabled(false);
294 thresholdValue.setText("");
295 percentThreshold.setEnabled(false);
296 // build filter params
298 else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
300 if (currentAnnotation.threshold == null)
302 currentAnnotation.setThreshold(new jalview.datamodel.GraphLine(
303 (currentAnnotation.graphMax
304 - currentAnnotation.graphMin) / 2f,
305 "Threshold", Color.black));
310 setSliderModel(currentAnnotation.graphMin,
311 currentAnnotation.graphMax,
312 currentAnnotation.threshold.value);
314 setThresholdValueText();
316 slider.setEnabled(true);
317 thresholdValue.setEnabled(true);
320 // build filter params
321 filterParams.setThresholdType(
322 AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);
323 if (currentAnnotation.isQuantitative())
326 .setThresholdValue(currentAnnotation.threshold.value);
328 if (selectedThresholdItem == AnnotationColourGradient.ABOVE_THRESHOLD)
330 filterParams.setThresholdType(
331 AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD);
333 else if (selectedThresholdItem == AnnotationColourGradient.BELOW_THRESHOLD)
335 filterParams.setThresholdType(
336 AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD);
341 updateThresholdPanelToolTip();
342 if (currentStructureFilterPanel != null)
344 if (currentStructureFilterPanel.alphaHelix.isSelected())
346 filterParams.setFilterAlphaHelix(true);
348 if (currentStructureFilterPanel.betaStrand.isSelected())
350 filterParams.setFilterBetaSheet(true);
352 if (currentStructureFilterPanel.turn.isSelected())
354 filterParams.setFilterTurn(true);
358 if (currentSearchPanel != null)
360 if (!currentSearchPanel.searchBox.getUserInput().isEmpty())
362 filterParams.setRegexString(
363 currentSearchPanel.searchBox.getUserInput());
364 if (currentSearchPanel.displayName.isSelected())
366 filterParams.addRegexSearchField(
367 AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING);
369 if (currentSearchPanel.description.isSelected())
371 filterParams.addRegexSearchField(
372 AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION);
377 // show hidden columns here, before changing the column selection in
378 // filterAnnotations, because showing hidden columns has the side effect of
379 // adding them to the selection
380 av.showAllHiddenColumns();
381 av.getColumnSelection().filterAnnotations(
382 currentAnnotation.annotations, filterParams);
384 boolean hideCols = getActionOption() == ACTION_OPTION_HIDE;
387 av.hideSelectedColumns();
392 av.setAnnotationColumnSelectionState(this);
393 // only update overview and structures if columns were hidden
394 ap.paintAlignment(hideCols, hideCols);
397 public HiddenColumns getOldHiddenColumns()
399 return oldHiddenColumns;
402 public void setOldHiddenColumns(HiddenColumns currentHiddenColumns)
404 if (currentHiddenColumns != null)
406 this.oldHiddenColumns = new HiddenColumns(currentHiddenColumns);
410 public FurtherActionPanel getCurrentFutherActionPanel()
412 return currentFurtherActionPanel;
415 public void setCurrentFutherActionPanel(
416 FurtherActionPanel currentFutherActionPanel)
418 this.currentFurtherActionPanel = currentFutherActionPanel;
421 public SearchPanel getCurrentSearchPanel()
423 return currentSearchPanel;
426 public void setCurrentSearchPanel(SearchPanel currentSearchPanel)
428 this.currentSearchPanel = currentSearchPanel;
431 public int getActionOption()
436 public void setActionOption(int actionOption)
438 this.actionOption = actionOption;
441 public StructureFilterPanel getCurrentStructureFilterPanel()
443 return currentStructureFilterPanel;
446 public void setCurrentStructureFilterPanel(
447 StructureFilterPanel currentStructureFilterPanel)
449 this.currentStructureFilterPanel = currentStructureFilterPanel;
452 public void select_action(ActionEvent actionEvent)
454 JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
455 if (radioButton.isSelected())
457 setActionOption(ACTION_OPTION_SELECT);
462 public void hide_action(ActionEvent actionEvent)
464 JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
465 if (radioButton.isSelected())
467 setActionOption(ACTION_OPTION_HIDE);
473 public void itemStateChanged(ItemEvent e)
475 selectedAnnotationChanged();
479 public void selectedAnnotationChanged()
481 String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
482 if (av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
483 .getSelectedIndex()]].isQuantitative())
485 currentView = AnnotationColumnChooser.GRAPH_VIEW;
488 gSearchPanel.syncState();
489 gFurtherActionPanel.syncState();
490 gStructureFilterPanel.syncState();
492 ngSearchPanel.syncState();
493 ngFurtherActionPanel.syncState();
494 ngStructureFilterPanel.syncState();
496 CardLayout switchableViewsLayout = (CardLayout) switchableViewsPanel
498 switchableViewsLayout.show(switchableViewsPanel, currentView);
502 public class FurtherActionPanel extends JPanel
504 private AnnotationColumnChooser aColChooser;
506 private JRadioButton hideOption = new JRadioButton();
508 private JRadioButton selectOption = new JRadioButton();
510 private ButtonGroup optionsGroup = new ButtonGroup();
512 public FurtherActionPanel(AnnotationColumnChooser aColChooser)
514 this.aColChooser = aColChooser;
515 JvSwingUtils.jvInitComponent(selectOption, "action.select");
516 selectOption.addActionListener(new ActionListener()
519 public void actionPerformed(ActionEvent actionEvent)
521 selectRadioAction(actionEvent);
525 JvSwingUtils.jvInitComponent(hideOption, "action.hide");
526 hideOption.addActionListener(new ActionListener()
529 public void actionPerformed(ActionEvent actionEvent)
531 hideRadioAction(actionEvent);
535 optionsGroup.add(selectOption);
536 optionsGroup.add(hideOption);
537 optionsGroup.setSelected(selectOption.getModel(), true);
539 JvSwingUtils.jvInitComponent(this);
542 this.add(selectOption);
543 this.add(hideOption);
546 public void selectRadioAction(ActionEvent actionEvent)
548 aColChooser.setCurrentFutherActionPanel(this);
549 aColChooser.select_action(actionEvent);
552 public void hideRadioAction(ActionEvent actionEvent)
554 aColChooser.setCurrentFutherActionPanel(this);
555 aColChooser.hide_action(actionEvent);
558 public void syncState()
561 .getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
563 this.optionsGroup.setSelected(this.hideOption.getModel(), true);
567 this.optionsGroup.setSelected(this.selectOption.getModel(), true);
572 public class StructureFilterPanel extends JPanel
574 private AnnotationColumnChooser aColChooser;
576 private JCheckBox alphaHelix = new JCheckBox();
578 private JCheckBox betaStrand = new JCheckBox();
580 private JCheckBox turn = new JCheckBox();
582 private JCheckBox all = new JCheckBox();
584 public StructureFilterPanel(AnnotationColumnChooser aColChooser)
586 this.aColChooser = aColChooser;
588 JvSwingUtils.jvInitComponent(alphaHelix, "label.alpha_helix");
589 alphaHelix.addActionListener(new ActionListener()
592 public void actionPerformed(ActionEvent actionEvent)
594 alphaHelix_actionPerformed();
598 JvSwingUtils.jvInitComponent(betaStrand, "label.beta_strand");
599 betaStrand.addActionListener(new ActionListener()
602 public void actionPerformed(ActionEvent actionEvent)
604 betaStrand_actionPerformed();
608 JvSwingUtils.jvInitComponent(turn, "label.turn");
609 turn.addActionListener(new ActionListener()
612 public void actionPerformed(ActionEvent actionEvent)
614 turn_actionPerformed();
618 JvSwingUtils.jvInitComponent(all, "label.select_all");
619 all.addActionListener(new ActionListener()
622 public void actionPerformed(ActionEvent actionEvent)
624 all_actionPerformed();
628 this.setBorder(new TitledBorder(
629 MessageManager.getString("label.structures_filter")));
630 JvSwingUtils.jvInitComponent(this);
633 this.add(alphaHelix);
634 this.add(betaStrand);
638 public void alphaHelix_actionPerformed()
640 updateSelectAllState();
641 aColChooser.setCurrentStructureFilterPanel(this);
642 aColChooser.updateView();
645 public void betaStrand_actionPerformed()
647 updateSelectAllState();
648 aColChooser.setCurrentStructureFilterPanel(this);
649 aColChooser.updateView();
652 public void turn_actionPerformed()
654 updateSelectAllState();
655 aColChooser.setCurrentStructureFilterPanel(this);
656 aColChooser.updateView();
659 public void all_actionPerformed()
661 if (all.isSelected())
663 alphaHelix.setSelected(true);
664 betaStrand.setSelected(true);
665 turn.setSelected(true);
669 alphaHelix.setSelected(false);
670 betaStrand.setSelected(false);
671 turn.setSelected(false);
673 aColChooser.setCurrentStructureFilterPanel(this);
674 aColChooser.updateView();
677 public void updateSelectAllState()
679 if (alphaHelix.isSelected() && betaStrand.isSelected()
680 && turn.isSelected())
682 all.setSelected(true);
686 all.setSelected(false);
690 public void syncState()
692 StructureFilterPanel sfp = aColChooser
693 .getCurrentStructureFilterPanel();
696 alphaHelix.setSelected(sfp.alphaHelix.isSelected());
697 betaStrand.setSelected(sfp.betaStrand.isSelected());
698 turn.setSelected(sfp.turn.isSelected());
699 if (sfp.all.isSelected())
701 all.setSelected(true);
702 alphaHelix.setSelected(true);
703 betaStrand.setSelected(true);
704 turn.setSelected(true);
711 public class SearchPanel extends JPanel
713 private AnnotationColumnChooser aColChooser;
715 private JCheckBox displayName = new JCheckBox();
717 private JCheckBox description = new JCheckBox();
719 private static final String FILTER_BY_ANN_CACHE_KEY = "CACHE.SELECT_FILTER_BY_ANNOT";
721 public JvCacheableInputBox<String> searchBox = new JvCacheableInputBox<>(
722 FILTER_BY_ANN_CACHE_KEY, 23);
724 public SearchPanel(AnnotationColumnChooser aColChooser)
727 this.aColChooser = aColChooser;
728 JvSwingUtils.jvInitComponent(this);
729 this.setBorder(new TitledBorder(
730 MessageManager.getString("label.search_filter")));
732 searchBox.getComponent().setToolTipText(
733 MessageManager.getString("info.enter_search_text_here"));
734 searchBox.addKeyListener(new java.awt.event.KeyAdapter()
737 public void keyPressed(KeyEvent e)
739 if (e.getKeyCode() == KeyEvent.VK_ENTER)
742 searchStringAction();
746 searchBox.addFocusListener(new FocusAdapter()
749 public void focusLost(FocusEvent e)
751 searchStringAction();
755 JvSwingUtils.jvInitComponent(displayName, "label.label");
756 displayName.addActionListener(new ActionListener()
759 public void actionPerformed(ActionEvent actionEvent)
761 displayNameCheckboxAction();
765 JvSwingUtils.jvInitComponent(description, "label.description");
766 description.addActionListener(new ActionListener()
769 public void actionPerformed(ActionEvent actionEvent)
771 descriptionCheckboxAction();
776 this.add(searchBox.getComponent());
777 this.add(displayName);
778 this.add(description);
781 public void displayNameCheckboxAction()
783 aColChooser.setCurrentSearchPanel(this);
784 aColChooser.updateView();
787 public void descriptionCheckboxAction()
789 aColChooser.setCurrentSearchPanel(this);
790 aColChooser.updateView();
793 public void searchStringAction()
795 aColChooser.setCurrentSearchPanel(this);
796 aColChooser.updateView();
797 updateSearchPanelToolTips();
798 searchBox.updateCache();
801 public void syncState()
803 SearchPanel sp = aColChooser.getCurrentSearchPanel();
806 description.setEnabled(sp.description.isEnabled());
807 description.setSelected(sp.description.isSelected());
809 displayName.setEnabled(sp.displayName.isEnabled());
810 displayName.setSelected(sp.displayName.isSelected());
812 searchBox.setSelectedItem(sp.searchBox.getUserInput());
814 updateSearchPanelToolTips();
817 public void updateSearchPanelToolTips()
819 String defaultTtip = MessageManager
820 .getString("info.enter_search_text_to_enable");
821 String labelTtip = MessageManager.formatMessage(
822 "info.search_in_annotation_label",
823 annotations.getSelectedItem().toString());
824 String descTtip = MessageManager.formatMessage(
825 "info.search_in_annotation_description",
826 annotations.getSelectedItem().toString());
827 displayName.setToolTipText(
828 displayName.isEnabled() ? labelTtip : defaultTtip);
829 description.setToolTipText(
830 description.isEnabled() ? descTtip : defaultTtip);
835 public void ok_actionPerformed()
838 super.ok_actionPerformed();
842 public void cancel_actionPerformed()
845 super.cancel_actionPerformed();
848 private void saveCache()
850 gSearchPanel.searchBox.persistCache();
851 ngSearchPanel.searchBox.persistCache();
852 gSearchPanel.searchBox.updateCache();
853 ngSearchPanel.searchBox.updateCache();