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);
95 protected static int MIN_HEIGHT = (Platform.isJS() ? 370 : 430);
97 public AnnotationColumnChooser(AlignViewport av, final AlignmentPanel ap)
100 frame = new JInternalFrame();
101 frame.setContentPane(this);
102 frame.setLayer(JLayeredPane.PALETTE_LAYER);
103 Desktop.addInternalFrame(frame,
104 MessageManager.getString("label.select_by_annotation"), 0, 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 - currentAnnotation.graphMin)
305 "Threshold", Color.black));
310 setSliderModel(currentAnnotation.graphMin, 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())
324 filterParams.setThresholdValue(currentAnnotation.threshold.value);
326 if (selectedThresholdItem == AnnotationColourGradient.ABOVE_THRESHOLD)
328 filterParams.setThresholdType(
329 AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD);
331 else if (selectedThresholdItem == AnnotationColourGradient.BELOW_THRESHOLD)
333 filterParams.setThresholdType(
334 AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD);
339 updateThresholdPanelToolTip();
340 if (currentStructureFilterPanel != null)
342 if (currentStructureFilterPanel.alphaHelix.isSelected())
344 filterParams.setFilterAlphaHelix(true);
346 if (currentStructureFilterPanel.betaStrand.isSelected())
348 filterParams.setFilterBetaSheet(true);
350 if (currentStructureFilterPanel.turn.isSelected())
352 filterParams.setFilterTurn(true);
356 if (currentSearchPanel != null)
358 if (!currentSearchPanel.searchBox.getUserInput().isEmpty())
360 filterParams.setRegexString(
361 currentSearchPanel.searchBox.getUserInput());
362 if (currentSearchPanel.displayName.isSelected())
364 filterParams.addRegexSearchField(
365 AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING);
367 if (currentSearchPanel.description.isSelected())
369 filterParams.addRegexSearchField(
370 AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION);
375 // show hidden columns here, before changing the column selection in
376 // filterAnnotations, because showing hidden columns has the side effect of
377 // adding them to the selection
378 av.showAllHiddenColumns();
379 av.getColumnSelection().filterAnnotations(currentAnnotation.annotations,
382 boolean hideCols = getActionOption() == ACTION_OPTION_HIDE;
385 av.hideSelectedColumns();
390 av.setAnnotationColumnSelectionState(this);
391 // only update overview and structures if columns were hidden
392 ap.paintAlignment(hideCols, hideCols);
395 public HiddenColumns getOldHiddenColumns()
397 return oldHiddenColumns;
400 public void setOldHiddenColumns(HiddenColumns currentHiddenColumns)
402 if (currentHiddenColumns != null)
404 this.oldHiddenColumns = new HiddenColumns(currentHiddenColumns);
408 public FurtherActionPanel getCurrentFutherActionPanel()
410 return currentFurtherActionPanel;
413 public void setCurrentFutherActionPanel(
414 FurtherActionPanel currentFutherActionPanel)
416 this.currentFurtherActionPanel = currentFutherActionPanel;
419 public SearchPanel getCurrentSearchPanel()
421 return currentSearchPanel;
424 public void setCurrentSearchPanel(SearchPanel currentSearchPanel)
426 this.currentSearchPanel = currentSearchPanel;
429 public int getActionOption()
434 public void setActionOption(int actionOption)
436 this.actionOption = actionOption;
439 public StructureFilterPanel getCurrentStructureFilterPanel()
441 return currentStructureFilterPanel;
444 public void setCurrentStructureFilterPanel(
445 StructureFilterPanel currentStructureFilterPanel)
447 this.currentStructureFilterPanel = currentStructureFilterPanel;
450 public void select_action(ActionEvent actionEvent)
452 JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
453 if (radioButton.isSelected())
455 setActionOption(ACTION_OPTION_SELECT);
460 public void hide_action(ActionEvent actionEvent)
462 JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
463 if (radioButton.isSelected())
465 setActionOption(ACTION_OPTION_HIDE);
471 public void itemStateChanged(ItemEvent e)
473 selectedAnnotationChanged();
477 public void selectedAnnotationChanged()
479 String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
480 if (av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
481 .getSelectedIndex()]].isQuantitative())
483 currentView = AnnotationColumnChooser.GRAPH_VIEW;
486 gSearchPanel.syncState();
487 gFurtherActionPanel.syncState();
488 gStructureFilterPanel.syncState();
490 ngSearchPanel.syncState();
491 ngFurtherActionPanel.syncState();
492 ngStructureFilterPanel.syncState();
494 CardLayout switchableViewsLayout = (CardLayout) switchableViewsPanel
496 switchableViewsLayout.show(switchableViewsPanel, currentView);
500 public class FurtherActionPanel extends JPanel
502 private AnnotationColumnChooser aColChooser;
504 private JRadioButton hideOption = new JRadioButton();
506 private JRadioButton selectOption = new JRadioButton();
508 private ButtonGroup optionsGroup = new ButtonGroup();
510 public FurtherActionPanel(AnnotationColumnChooser aColChooser)
512 this.aColChooser = aColChooser;
513 JvSwingUtils.jvInitComponent(selectOption, "action.select");
514 selectOption.addActionListener(new ActionListener()
517 public void actionPerformed(ActionEvent actionEvent)
519 selectRadioAction(actionEvent);
523 JvSwingUtils.jvInitComponent(hideOption, "action.hide");
524 hideOption.addActionListener(new ActionListener()
527 public void actionPerformed(ActionEvent actionEvent)
529 hideRadioAction(actionEvent);
533 optionsGroup.add(selectOption);
534 optionsGroup.add(hideOption);
535 optionsGroup.setSelected(selectOption.getModel(), true);
537 JvSwingUtils.jvInitComponent(this);
540 this.add(selectOption);
541 this.add(hideOption);
544 public void selectRadioAction(ActionEvent actionEvent)
546 aColChooser.setCurrentFutherActionPanel(this);
547 aColChooser.select_action(actionEvent);
550 public void hideRadioAction(ActionEvent actionEvent)
552 aColChooser.setCurrentFutherActionPanel(this);
553 aColChooser.hide_action(actionEvent);
556 public void syncState()
559 .getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
561 this.optionsGroup.setSelected(this.hideOption.getModel(), true);
565 this.optionsGroup.setSelected(this.selectOption.getModel(), true);
570 public class StructureFilterPanel extends JPanel
572 private AnnotationColumnChooser aColChooser;
574 private JCheckBox alphaHelix = new JCheckBox();
576 private JCheckBox betaStrand = new JCheckBox();
578 private JCheckBox turn = new JCheckBox();
580 private JCheckBox all = new JCheckBox();
582 public StructureFilterPanel(AnnotationColumnChooser aColChooser)
584 this.aColChooser = aColChooser;
586 JvSwingUtils.jvInitComponent(alphaHelix, "label.alpha_helix");
587 alphaHelix.addActionListener(new ActionListener()
590 public void actionPerformed(ActionEvent actionEvent)
592 alphaHelix_actionPerformed();
596 JvSwingUtils.jvInitComponent(betaStrand, "label.beta_strand");
597 betaStrand.addActionListener(new ActionListener()
600 public void actionPerformed(ActionEvent actionEvent)
602 betaStrand_actionPerformed();
606 JvSwingUtils.jvInitComponent(turn, "label.turn");
607 turn.addActionListener(new ActionListener()
610 public void actionPerformed(ActionEvent actionEvent)
612 turn_actionPerformed();
616 JvSwingUtils.jvInitComponent(all, "label.select_all");
617 all.addActionListener(new ActionListener()
620 public void actionPerformed(ActionEvent actionEvent)
622 all_actionPerformed();
626 this.setBorder(new TitledBorder(
627 MessageManager.getString("label.structures_filter")));
628 JvSwingUtils.jvInitComponent(this);
631 this.add(alphaHelix);
632 this.add(betaStrand);
636 public void alphaHelix_actionPerformed()
638 updateSelectAllState();
639 aColChooser.setCurrentStructureFilterPanel(this);
640 aColChooser.updateView();
643 public void betaStrand_actionPerformed()
645 updateSelectAllState();
646 aColChooser.setCurrentStructureFilterPanel(this);
647 aColChooser.updateView();
650 public void turn_actionPerformed()
652 updateSelectAllState();
653 aColChooser.setCurrentStructureFilterPanel(this);
654 aColChooser.updateView();
657 public void all_actionPerformed()
659 if (all.isSelected())
661 alphaHelix.setSelected(true);
662 betaStrand.setSelected(true);
663 turn.setSelected(true);
667 alphaHelix.setSelected(false);
668 betaStrand.setSelected(false);
669 turn.setSelected(false);
671 aColChooser.setCurrentStructureFilterPanel(this);
672 aColChooser.updateView();
675 public void updateSelectAllState()
677 if (alphaHelix.isSelected() && betaStrand.isSelected()
678 && turn.isSelected())
680 all.setSelected(true);
684 all.setSelected(false);
688 public void syncState()
690 StructureFilterPanel sfp = aColChooser
691 .getCurrentStructureFilterPanel();
694 alphaHelix.setSelected(sfp.alphaHelix.isSelected());
695 betaStrand.setSelected(sfp.betaStrand.isSelected());
696 turn.setSelected(sfp.turn.isSelected());
697 if (sfp.all.isSelected())
699 all.setSelected(true);
700 alphaHelix.setSelected(true);
701 betaStrand.setSelected(true);
702 turn.setSelected(true);
709 public class SearchPanel extends JPanel
711 private AnnotationColumnChooser aColChooser;
713 private JCheckBox displayName = new JCheckBox();
715 private JCheckBox description = new JCheckBox();
717 private static final String FILTER_BY_ANN_CACHE_KEY = "CACHE.SELECT_FILTER_BY_ANNOT";
719 public JvCacheableInputBox<String> searchBox = new JvCacheableInputBox<>(
720 FILTER_BY_ANN_CACHE_KEY, 23);
722 public SearchPanel(AnnotationColumnChooser aColChooser)
725 this.aColChooser = aColChooser;
726 JvSwingUtils.jvInitComponent(this);
727 this.setBorder(new TitledBorder(
728 MessageManager.getString("label.search_filter")));
730 searchBox.getComponent().setToolTipText(
731 MessageManager.getString("info.enter_search_text_here"));
732 searchBox.addKeyListener(new java.awt.event.KeyAdapter()
735 public void keyPressed(KeyEvent e)
737 if (e.getKeyCode() == KeyEvent.VK_ENTER)
740 searchStringAction();
744 searchBox.addFocusListener(new FocusAdapter()
747 public void focusLost(FocusEvent e)
749 searchStringAction();
753 JvSwingUtils.jvInitComponent(displayName, "label.label");
754 displayName.addActionListener(new ActionListener()
757 public void actionPerformed(ActionEvent actionEvent)
759 displayNameCheckboxAction();
763 JvSwingUtils.jvInitComponent(description, "label.description");
764 description.addActionListener(new ActionListener()
767 public void actionPerformed(ActionEvent actionEvent)
769 descriptionCheckboxAction();
774 this.add(searchBox.getComponent());
775 this.add(displayName);
776 this.add(description);
779 public void displayNameCheckboxAction()
781 aColChooser.setCurrentSearchPanel(this);
782 aColChooser.updateView();
785 public void descriptionCheckboxAction()
787 aColChooser.setCurrentSearchPanel(this);
788 aColChooser.updateView();
791 public void searchStringAction()
793 aColChooser.setCurrentSearchPanel(this);
794 aColChooser.updateView();
795 updateSearchPanelToolTips();
796 searchBox.updateCache();
799 public void syncState()
801 SearchPanel sp = aColChooser.getCurrentSearchPanel();
804 description.setEnabled(sp.description.isEnabled());
805 description.setSelected(sp.description.isSelected());
807 displayName.setEnabled(sp.displayName.isEnabled());
808 displayName.setSelected(sp.displayName.isSelected());
810 searchBox.setSelectedItem(sp.searchBox.getUserInput());
812 updateSearchPanelToolTips();
815 public void updateSearchPanelToolTips()
817 String defaultTtip = MessageManager
818 .getString("info.enter_search_text_to_enable");
819 String labelTtip = MessageManager.formatMessage(
820 "info.search_in_annotation_label",
821 annotations.getSelectedItem().toString());
822 String descTtip = MessageManager.formatMessage(
823 "info.search_in_annotation_description",
824 annotations.getSelectedItem().toString());
825 displayName.setToolTipText(
826 displayName.isEnabled() ? labelTtip : defaultTtip);
827 description.setToolTipText(
828 description.isEnabled() ? descTtip : defaultTtip);
833 public void ok_actionPerformed()
836 super.ok_actionPerformed();
840 public void cancel_actionPerformed()
843 super.cancel_actionPerformed();
846 private void saveCache()
848 gSearchPanel.searchBox.persistCache();
849 ngSearchPanel.searchBox.persistCache();
850 gSearchPanel.searchBox.updateCache();
851 ngSearchPanel.searchBox.updateCache();