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.HiddenColumns;
25 import jalview.io.cache.JvCacheableInputBox;
26 import jalview.schemes.AnnotationColourGradient;
27 import jalview.util.MessageManager;
28 import jalview.viewmodel.annotationfilter.AnnotationFilterParameter;
30 import java.awt.BorderLayout;
31 import java.awt.CardLayout;
32 import java.awt.Color;
33 import java.awt.Dimension;
34 import java.awt.event.ActionEvent;
35 import java.awt.event.ActionListener;
36 import java.awt.event.FocusAdapter;
37 import java.awt.event.FocusEvent;
38 import java.awt.event.ItemEvent;
39 import java.awt.event.ItemListener;
40 import java.awt.event.KeyEvent;
42 import javax.swing.ButtonGroup;
43 import javax.swing.JCheckBox;
44 import javax.swing.JComboBox;
45 import javax.swing.JInternalFrame;
46 import javax.swing.JLayeredPane;
47 import javax.swing.JPanel;
48 import javax.swing.JRadioButton;
49 import javax.swing.border.TitledBorder;
51 import net.miginfocom.swing.MigLayout;
53 @SuppressWarnings("serial")
54 public class AnnotationColumnChooser extends AnnotationRowFilter
55 implements ItemListener
57 private JPanel switchableViewsPanel = new JPanel(new CardLayout());
59 private JPanel annotationComboBoxPanel = new JPanel();
61 private StructureFilterPanel gStructureFilterPanel;
63 private StructureFilterPanel ngStructureFilterPanel;
65 private StructureFilterPanel currentStructureFilterPanel;
67 private SearchPanel currentSearchPanel;
69 private SearchPanel gSearchPanel;
71 private SearchPanel ngSearchPanel;
73 private FurtherActionPanel currentFurtherActionPanel;
75 private FurtherActionPanel gFurtherActionPanel;
77 private FurtherActionPanel ngFurtherActionPanel;
79 public static final int ACTION_OPTION_SELECT = 1;
81 public static int ACTION_OPTION_HIDE = 2;
83 public static String NO_GRAPH_VIEW = "0";
85 public static String GRAPH_VIEW = "1";
87 private int actionOption = ACTION_OPTION_SELECT;
89 private HiddenColumns oldHiddenColumns;
91 protected int MIN_WIDTH = 420;
93 protected int MIN_HEIGHT = 430;
95 public AnnotationColumnChooser(AlignViewport av, final AlignmentPanel ap)
98 frame = new JInternalFrame();
99 frame.setContentPane(this);
100 frame.setLayer(JLayeredPane.PALETTE_LAYER);
101 Desktop.addInternalFrame(frame,
102 MessageManager.getString("label.select_by_annotation"), 520,
104 frame.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT));
106 addSliderChangeListener();
107 addSliderMouseListeners();
109 if (av.getAlignment().getAlignmentAnnotation() == null)
113 setOldHiddenColumns(av.getAlignment().getHiddenColumns());
116 setAnnotations(new JComboBox<>(getAnnotationItems(false)));
117 populateThresholdComboBox(threshold);
118 AnnotationColumnChooser lastChooser = av
119 .getAnnotationColumnSelectionState();
120 // restore Object state from the previous session if one exists
121 if (lastChooser != null)
123 currentSearchPanel = lastChooser.getCurrentSearchPanel();
124 currentStructureFilterPanel = lastChooser
125 .getCurrentStructureFilterPanel();
126 annotations.setSelectedIndex(
127 lastChooser.getAnnotations().getSelectedIndex());
128 threshold.setSelectedIndex(
129 lastChooser.getThreshold().getSelectedIndex());
130 actionOption = lastChooser.getActionOption();
132 .setSelected(lastChooser.percentThreshold.isSelected());
138 } catch (Exception ex)
149 protected void jbInit()
153 JPanel thresholdPanel = new JPanel();
154 thresholdPanel.setBorder(new TitledBorder(
155 MessageManager.getString("label.threshold_filter")));
156 thresholdPanel.setBackground(Color.white);
157 thresholdPanel.setFont(JvSwingUtils.getLabelFont());
158 thresholdPanel.setLayout(new MigLayout("", "[left][right]", "[][]"));
160 percentThreshold.setBackground(Color.white);
161 percentThreshold.setFont(JvSwingUtils.getLabelFont());
163 JPanel actionPanel = new JPanel();
164 actionPanel.setBackground(Color.white);
165 actionPanel.setFont(JvSwingUtils.getLabelFont());
167 JPanel graphFilterView = new JPanel();
168 graphFilterView.setLayout(new MigLayout("", "[left][right]", "[][]"));
169 graphFilterView.setBackground(Color.white);
171 JPanel noGraphFilterView = new JPanel();
172 noGraphFilterView.setLayout(new MigLayout("", "[left][right]", "[][]"));
173 noGraphFilterView.setBackground(Color.white);
175 annotationComboBoxPanel.setBackground(Color.white);
176 annotationComboBoxPanel.setFont(JvSwingUtils.getLabelFont());
178 gSearchPanel = new SearchPanel(this);
179 ngSearchPanel = new SearchPanel(this);
180 gFurtherActionPanel = new FurtherActionPanel(this);
181 ngFurtherActionPanel = new FurtherActionPanel(this);
182 gStructureFilterPanel = new StructureFilterPanel(this);
183 ngStructureFilterPanel = new StructureFilterPanel(this);
185 thresholdPanel.add(getThreshold());
186 thresholdPanel.add(percentThreshold, "wrap");
187 thresholdPanel.add(slider, "grow");
188 thresholdPanel.add(thresholdValue, "span, wrap");
191 actionPanel.add(cancel);
193 graphFilterView.add(gSearchPanel, "grow, span, wrap");
194 graphFilterView.add(gStructureFilterPanel, "grow, span, wrap");
195 graphFilterView.add(thresholdPanel, "grow, span, wrap");
196 graphFilterView.add(gFurtherActionPanel);
198 noGraphFilterView.add(ngSearchPanel, "grow, span, wrap");
199 noGraphFilterView.add(ngStructureFilterPanel, "grow, span, wrap");
200 noGraphFilterView.add(ngFurtherActionPanel);
202 annotationComboBoxPanel.add(getAnnotations());
203 switchableViewsPanel.add(noGraphFilterView,
204 AnnotationColumnChooser.NO_GRAPH_VIEW);
205 switchableViewsPanel.add(graphFilterView,
206 AnnotationColumnChooser.GRAPH_VIEW);
208 this.setLayout(new BorderLayout());
209 this.add(annotationComboBoxPanel, java.awt.BorderLayout.PAGE_START);
210 this.add(switchableViewsPanel, java.awt.BorderLayout.CENTER);
211 this.add(actionPanel, java.awt.BorderLayout.SOUTH);
213 selectedAnnotationChanged();
214 updateThresholdPanelToolTip();
218 protected void updateThresholdPanelToolTip()
220 thresholdValue.setToolTipText("");
221 slider.setToolTipText("");
223 String defaultTtip = MessageManager
224 .getString("info.change_threshold_mode_to_enable");
226 String thresh = getThreshold().getSelectedItem().toString();
227 if (thresh.equalsIgnoreCase("No Threshold"))
229 thresholdValue.setToolTipText(defaultTtip);
230 slider.setToolTipText(defaultTtip);
235 protected void reset()
237 if (this.getOldHiddenColumns() != null)
239 av.getColumnSelection().clear();
241 if (av.getAnnotationColumnSelectionState() != null)
243 HiddenColumns oldHidden = av.getAnnotationColumnSelectionState()
244 .getOldHiddenColumns();
245 av.getAlignment().setHiddenColumns(oldHidden);
248 ap.paintAlignment(true, true);
253 public void valueChanged(boolean updateAllAnnotation)
255 if (slider.isEnabled())
257 getCurrentAnnotation().threshold.value = slider.getValue() / 1000f;
259 propagateSeqAssociatedThreshold(updateAllAnnotation,
260 getCurrentAnnotation());
261 ap.paintAlignment(false, false);
266 public void updateView()
268 // Check if combobox is still adjusting
274 AnnotationFilterParameter filterParams = new AnnotationFilterParameter();
276 setCurrentAnnotation(av.getAlignment()
277 .getAlignmentAnnotation()[annmap[getAnnotations()
278 .getSelectedIndex()]]);
280 int selectedThresholdItem = getSelectedThresholdItem(
281 getThreshold().getSelectedIndex());
283 slider.setEnabled(true);
284 thresholdValue.setEnabled(true);
285 percentThreshold.setEnabled(true);
287 if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
289 slider.setEnabled(false);
290 thresholdValue.setEnabled(false);
291 thresholdValue.setText("");
292 percentThreshold.setEnabled(false);
293 // build filter params
295 else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
297 if (getCurrentAnnotation().threshold == null)
299 getCurrentAnnotation().setThreshold(new jalview.datamodel.GraphLine(
300 (getCurrentAnnotation().graphMax
301 - getCurrentAnnotation().graphMin) / 2f,
302 "Threshold", Color.black));
306 float range = getCurrentAnnotation().graphMax * 1000
307 - getCurrentAnnotation().graphMin * 1000;
309 slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
310 slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
312 (int) (getCurrentAnnotation().threshold.value * 1000));
314 setThresholdValueText();
316 slider.setMajorTickSpacing((int) (range / 10f));
317 slider.setEnabled(true);
318 thresholdValue.setEnabled(true);
321 // build filter params
322 filterParams.setThresholdType(
323 AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);
324 if (getCurrentAnnotation().isQuantitative())
327 .setThresholdValue(getCurrentAnnotation().threshold.value);
329 if (selectedThresholdItem == AnnotationColourGradient.ABOVE_THRESHOLD)
331 filterParams.setThresholdType(
332 AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD);
334 else if (selectedThresholdItem == AnnotationColourGradient.BELOW_THRESHOLD)
336 filterParams.setThresholdType(
337 AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD);
342 updateThresholdPanelToolTip();
343 if (currentStructureFilterPanel != null)
345 if (currentStructureFilterPanel.alphaHelix.isSelected())
347 filterParams.setFilterAlphaHelix(true);
349 if (currentStructureFilterPanel.betaStrand.isSelected())
351 filterParams.setFilterBetaSheet(true);
353 if (currentStructureFilterPanel.turn.isSelected())
355 filterParams.setFilterTurn(true);
359 if (currentSearchPanel != null)
361 if (!currentSearchPanel.searchBox.getUserInput().isEmpty())
363 filterParams.setRegexString(
364 currentSearchPanel.searchBox.getUserInput());
365 if (currentSearchPanel.displayName.isSelected())
367 filterParams.addRegexSearchField(
368 AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING);
370 if (currentSearchPanel.description.isSelected())
372 filterParams.addRegexSearchField(
373 AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION);
378 // show hidden columns here, before changing the column selection in
379 // filterAnnotations, because showing hidden columns has the side effect of
380 // adding them to the selection
381 av.showAllHiddenColumns();
382 av.getColumnSelection().filterAnnotations(
383 getCurrentAnnotation().annotations, filterParams);
385 boolean hideCols = getActionOption() == ACTION_OPTION_HIDE;
388 av.hideSelectedColumns();
393 av.setAnnotationColumnSelectionState(this);
394 // only update overview and structures if columns were hidden
395 ap.paintAlignment(hideCols, hideCols);
398 public HiddenColumns getOldHiddenColumns()
400 return oldHiddenColumns;
403 public void setOldHiddenColumns(HiddenColumns currentHiddenColumns)
405 if (currentHiddenColumns != null)
407 this.oldHiddenColumns = new HiddenColumns(currentHiddenColumns);
411 public FurtherActionPanel getCurrentFutherActionPanel()
413 return currentFurtherActionPanel;
416 public void setCurrentFutherActionPanel(
417 FurtherActionPanel currentFutherActionPanel)
419 this.currentFurtherActionPanel = currentFutherActionPanel;
422 public SearchPanel getCurrentSearchPanel()
424 return currentSearchPanel;
427 public void setCurrentSearchPanel(SearchPanel currentSearchPanel)
429 this.currentSearchPanel = currentSearchPanel;
432 public int getActionOption()
437 public void setActionOption(int actionOption)
439 this.actionOption = actionOption;
442 public StructureFilterPanel getCurrentStructureFilterPanel()
444 return currentStructureFilterPanel;
447 public void setCurrentStructureFilterPanel(
448 StructureFilterPanel currentStructureFilterPanel)
450 this.currentStructureFilterPanel = currentStructureFilterPanel;
453 public void select_action(ActionEvent actionEvent)
455 JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
456 if (radioButton.isSelected())
458 setActionOption(ACTION_OPTION_SELECT);
463 public void hide_action(ActionEvent actionEvent)
465 JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
466 if (radioButton.isSelected())
468 setActionOption(ACTION_OPTION_HIDE);
474 public void itemStateChanged(ItemEvent e)
476 selectedAnnotationChanged();
480 public void selectedAnnotationChanged()
482 String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
483 if (av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
484 .getSelectedIndex()]].isQuantitative())
486 currentView = AnnotationColumnChooser.GRAPH_VIEW;
489 gSearchPanel.syncState();
490 gFurtherActionPanel.syncState();
491 gStructureFilterPanel.syncState();
493 ngSearchPanel.syncState();
494 ngFurtherActionPanel.syncState();
495 ngStructureFilterPanel.syncState();
497 CardLayout switchableViewsLayout = (CardLayout) switchableViewsPanel
499 switchableViewsLayout.show(switchableViewsPanel, currentView);
503 public class FurtherActionPanel extends JPanel
505 private AnnotationColumnChooser aColChooser;
507 private JRadioButton hideOption = new JRadioButton();
509 private JRadioButton selectOption = new JRadioButton();
511 private ButtonGroup optionsGroup = new ButtonGroup();
513 public FurtherActionPanel(AnnotationColumnChooser aColChooser)
515 this.aColChooser = aColChooser;
516 JvSwingUtils.jvInitComponent(selectOption, "action.select");
517 selectOption.addActionListener(new ActionListener()
520 public void actionPerformed(ActionEvent actionEvent)
522 selectRadioAction(actionEvent);
526 JvSwingUtils.jvInitComponent(hideOption, "action.hide");
527 hideOption.addActionListener(new ActionListener()
530 public void actionPerformed(ActionEvent actionEvent)
532 hideRadioAction(actionEvent);
536 optionsGroup.add(selectOption);
537 optionsGroup.add(hideOption);
538 optionsGroup.setSelected(selectOption.getModel(), true);
540 JvSwingUtils.jvInitComponent(this);
543 this.add(selectOption);
544 this.add(hideOption);
547 public void selectRadioAction(ActionEvent actionEvent)
549 aColChooser.setCurrentFutherActionPanel(this);
550 aColChooser.select_action(actionEvent);
553 public void hideRadioAction(ActionEvent actionEvent)
555 aColChooser.setCurrentFutherActionPanel(this);
556 aColChooser.hide_action(actionEvent);
559 public void syncState()
562 .getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
564 this.optionsGroup.setSelected(this.hideOption.getModel(), true);
568 this.optionsGroup.setSelected(this.selectOption.getModel(), true);
573 public class StructureFilterPanel extends JPanel
575 private AnnotationColumnChooser aColChooser;
577 private JCheckBox alphaHelix = new JCheckBox();
579 private JCheckBox betaStrand = new JCheckBox();
581 private JCheckBox turn = new JCheckBox();
583 private JCheckBox all = new JCheckBox();
585 public StructureFilterPanel(AnnotationColumnChooser aColChooser)
587 this.aColChooser = aColChooser;
589 JvSwingUtils.jvInitComponent(alphaHelix, "label.alpha_helix");
590 alphaHelix.addActionListener(new ActionListener()
593 public void actionPerformed(ActionEvent actionEvent)
595 alphaHelix_actionPerformed();
599 JvSwingUtils.jvInitComponent(betaStrand, "label.beta_strand");
600 betaStrand.addActionListener(new ActionListener()
603 public void actionPerformed(ActionEvent actionEvent)
605 betaStrand_actionPerformed();
609 JvSwingUtils.jvInitComponent(turn, "label.turn");
610 turn.addActionListener(new ActionListener()
613 public void actionPerformed(ActionEvent actionEvent)
615 turn_actionPerformed();
619 JvSwingUtils.jvInitComponent(all, "label.select_all");
620 all.addActionListener(new ActionListener()
623 public void actionPerformed(ActionEvent actionEvent)
625 all_actionPerformed();
629 this.setBorder(new TitledBorder(
630 MessageManager.getString("label.structures_filter")));
631 JvSwingUtils.jvInitComponent(this);
634 this.add(alphaHelix);
635 this.add(betaStrand);
639 public void alphaHelix_actionPerformed()
641 updateSelectAllState();
642 aColChooser.setCurrentStructureFilterPanel(this);
643 aColChooser.updateView();
646 public void betaStrand_actionPerformed()
648 updateSelectAllState();
649 aColChooser.setCurrentStructureFilterPanel(this);
650 aColChooser.updateView();
653 public void turn_actionPerformed()
655 updateSelectAllState();
656 aColChooser.setCurrentStructureFilterPanel(this);
657 aColChooser.updateView();
660 public void all_actionPerformed()
662 if (all.isSelected())
664 alphaHelix.setSelected(true);
665 betaStrand.setSelected(true);
666 turn.setSelected(true);
670 alphaHelix.setSelected(false);
671 betaStrand.setSelected(false);
672 turn.setSelected(false);
674 aColChooser.setCurrentStructureFilterPanel(this);
675 aColChooser.updateView();
678 public void updateSelectAllState()
680 if (alphaHelix.isSelected() && betaStrand.isSelected()
681 && turn.isSelected())
683 all.setSelected(true);
687 all.setSelected(false);
691 public void syncState()
693 StructureFilterPanel sfp = aColChooser
694 .getCurrentStructureFilterPanel();
697 alphaHelix.setSelected(sfp.alphaHelix.isSelected());
698 betaStrand.setSelected(sfp.betaStrand.isSelected());
699 turn.setSelected(sfp.turn.isSelected());
700 if (sfp.all.isSelected())
702 all.setSelected(true);
703 alphaHelix.setSelected(true);
704 betaStrand.setSelected(true);
705 turn.setSelected(true);
712 public class SearchPanel extends JPanel
714 private AnnotationColumnChooser aColChooser;
716 private JCheckBox displayName = new JCheckBox();
718 private JCheckBox description = new JCheckBox();
720 private static final String FILTER_BY_ANN_CACHE_KEY = "CACHE.SELECT_FILTER_BY_ANNOT";
722 public JvCacheableInputBox<String> searchBox = new JvCacheableInputBox<>(
723 FILTER_BY_ANN_CACHE_KEY);
725 public SearchPanel(AnnotationColumnChooser aColChooser)
728 this.aColChooser = aColChooser;
729 JvSwingUtils.jvInitComponent(this);
730 this.setBorder(new TitledBorder(
731 MessageManager.getString("label.search_filter")));
733 searchBox.setPrototypeDisplayValue("XXXXXXXXXXXXXXXXXXXXXXX");
734 searchBox.getComponent().setToolTipText(
735 MessageManager.getString("info.enter_search_text_here"));
736 searchBox.addKeyListener(new java.awt.event.KeyAdapter()
739 public void keyPressed(KeyEvent e)
741 if (e.getKeyCode() == KeyEvent.VK_ENTER)
744 searchStringAction();
748 searchBox.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();
778 this.add(searchBox.getComponent());
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();