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.util.Platform;
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 static int MIN_WIDTH = (Platform.isJS() ? 370 : 420);
93 protected static int MIN_HEIGHT = (Platform.isJS() ? 370 : 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"), 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 = slider.getValue() / 1000f;
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 if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
290 slider.setEnabled(false);
291 thresholdValue.setEnabled(false);
292 thresholdValue.setText("");
293 percentThreshold.setEnabled(false);
294 // build filter params
296 else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
298 if (getCurrentAnnotation().threshold == null)
300 getCurrentAnnotation().setThreshold(new jalview.datamodel.GraphLine(
301 (getCurrentAnnotation().graphMax
302 - getCurrentAnnotation().graphMin) / 2f,
303 "Threshold", Color.black));
307 float range = getCurrentAnnotation().graphMax * 1000
308 - getCurrentAnnotation().graphMin * 1000;
310 slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
311 slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
313 (int) (getCurrentAnnotation().threshold.value * 1000));
315 setThresholdValueText();
317 slider.setMajorTickSpacing((int) (range / 10f));
318 slider.setEnabled(true);
319 thresholdValue.setEnabled(true);
322 // build filter params
323 filterParams.setThresholdType(
324 AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);
325 if (getCurrentAnnotation().isQuantitative())
328 .setThresholdValue(getCurrentAnnotation().threshold.value);
330 if (selectedThresholdItem == AnnotationColourGradient.ABOVE_THRESHOLD)
332 filterParams.setThresholdType(
333 AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD);
335 else if (selectedThresholdItem == AnnotationColourGradient.BELOW_THRESHOLD)
337 filterParams.setThresholdType(
338 AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD);
343 updateThresholdPanelToolTip();
344 if (currentStructureFilterPanel != null)
346 if (currentStructureFilterPanel.alphaHelix.isSelected())
348 filterParams.setFilterAlphaHelix(true);
350 if (currentStructureFilterPanel.betaStrand.isSelected())
352 filterParams.setFilterBetaSheet(true);
354 if (currentStructureFilterPanel.turn.isSelected())
356 filterParams.setFilterTurn(true);
360 if (currentSearchPanel != null)
362 if (!currentSearchPanel.searchBox.getUserInput().isEmpty())
364 filterParams.setRegexString(
365 currentSearchPanel.searchBox.getUserInput());
366 if (currentSearchPanel.displayName.isSelected())
368 filterParams.addRegexSearchField(
369 AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING);
371 if (currentSearchPanel.description.isSelected())
373 filterParams.addRegexSearchField(
374 AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION);
379 // show hidden columns here, before changing the column selection in
380 // filterAnnotations, because showing hidden columns has the side effect of
381 // adding them to the selection
382 av.showAllHiddenColumns();
383 av.getColumnSelection().filterAnnotations(
384 getCurrentAnnotation().annotations, filterParams);
386 boolean hideCols = getActionOption() == ACTION_OPTION_HIDE;
389 av.hideSelectedColumns();
394 av.setAnnotationColumnSelectionState(this);
395 // only update overview and structures if columns were hidden
396 ap.paintAlignment(hideCols, hideCols);
399 public HiddenColumns getOldHiddenColumns()
401 return oldHiddenColumns;
404 public void setOldHiddenColumns(HiddenColumns currentHiddenColumns)
406 if (currentHiddenColumns != null)
408 this.oldHiddenColumns = new HiddenColumns(currentHiddenColumns);
412 public FurtherActionPanel getCurrentFutherActionPanel()
414 return currentFurtherActionPanel;
417 public void setCurrentFutherActionPanel(
418 FurtherActionPanel currentFutherActionPanel)
420 this.currentFurtherActionPanel = currentFutherActionPanel;
423 public SearchPanel getCurrentSearchPanel()
425 return currentSearchPanel;
428 public void setCurrentSearchPanel(SearchPanel currentSearchPanel)
430 this.currentSearchPanel = currentSearchPanel;
433 public int getActionOption()
438 public void setActionOption(int actionOption)
440 this.actionOption = actionOption;
443 public StructureFilterPanel getCurrentStructureFilterPanel()
445 return currentStructureFilterPanel;
448 public void setCurrentStructureFilterPanel(
449 StructureFilterPanel currentStructureFilterPanel)
451 this.currentStructureFilterPanel = currentStructureFilterPanel;
454 public void select_action(ActionEvent actionEvent)
456 JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
457 if (radioButton.isSelected())
459 setActionOption(ACTION_OPTION_SELECT);
464 public void hide_action(ActionEvent actionEvent)
466 JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
467 if (radioButton.isSelected())
469 setActionOption(ACTION_OPTION_HIDE);
475 public void itemStateChanged(ItemEvent e)
477 selectedAnnotationChanged();
481 public void selectedAnnotationChanged()
483 String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
484 if (av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
485 .getSelectedIndex()]].isQuantitative())
487 currentView = AnnotationColumnChooser.GRAPH_VIEW;
490 gSearchPanel.syncState();
491 gFurtherActionPanel.syncState();
492 gStructureFilterPanel.syncState();
494 ngSearchPanel.syncState();
495 ngFurtherActionPanel.syncState();
496 ngStructureFilterPanel.syncState();
498 CardLayout switchableViewsLayout = (CardLayout) switchableViewsPanel
500 switchableViewsLayout.show(switchableViewsPanel, currentView);
504 public class FurtherActionPanel extends JPanel
506 private AnnotationColumnChooser aColChooser;
508 private JRadioButton hideOption = new JRadioButton();
510 private JRadioButton selectOption = new JRadioButton();
512 private ButtonGroup optionsGroup = new ButtonGroup();
514 public FurtherActionPanel(AnnotationColumnChooser aColChooser)
516 this.aColChooser = aColChooser;
517 JvSwingUtils.jvInitComponent(selectOption, "action.select");
518 selectOption.addActionListener(new ActionListener()
521 public void actionPerformed(ActionEvent actionEvent)
523 selectRadioAction(actionEvent);
527 JvSwingUtils.jvInitComponent(hideOption, "action.hide");
528 hideOption.addActionListener(new ActionListener()
531 public void actionPerformed(ActionEvent actionEvent)
533 hideRadioAction(actionEvent);
537 optionsGroup.add(selectOption);
538 optionsGroup.add(hideOption);
539 optionsGroup.setSelected(selectOption.getModel(), true);
541 JvSwingUtils.jvInitComponent(this);
544 this.add(selectOption);
545 this.add(hideOption);
548 public void selectRadioAction(ActionEvent actionEvent)
550 aColChooser.setCurrentFutherActionPanel(this);
551 aColChooser.select_action(actionEvent);
554 public void hideRadioAction(ActionEvent actionEvent)
556 aColChooser.setCurrentFutherActionPanel(this);
557 aColChooser.hide_action(actionEvent);
560 public void syncState()
563 .getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
565 this.optionsGroup.setSelected(this.hideOption.getModel(), true);
569 this.optionsGroup.setSelected(this.selectOption.getModel(), true);
574 public class StructureFilterPanel extends JPanel
576 private AnnotationColumnChooser aColChooser;
578 private JCheckBox alphaHelix = new JCheckBox();
580 private JCheckBox betaStrand = new JCheckBox();
582 private JCheckBox turn = new JCheckBox();
584 private JCheckBox all = new JCheckBox();
586 public StructureFilterPanel(AnnotationColumnChooser aColChooser)
588 this.aColChooser = aColChooser;
590 JvSwingUtils.jvInitComponent(alphaHelix, "label.alpha_helix");
591 alphaHelix.addActionListener(new ActionListener()
594 public void actionPerformed(ActionEvent actionEvent)
596 alphaHelix_actionPerformed();
600 JvSwingUtils.jvInitComponent(betaStrand, "label.beta_strand");
601 betaStrand.addActionListener(new ActionListener()
604 public void actionPerformed(ActionEvent actionEvent)
606 betaStrand_actionPerformed();
610 JvSwingUtils.jvInitComponent(turn, "label.turn");
611 turn.addActionListener(new ActionListener()
614 public void actionPerformed(ActionEvent actionEvent)
616 turn_actionPerformed();
620 JvSwingUtils.jvInitComponent(all, "label.select_all");
621 all.addActionListener(new ActionListener()
624 public void actionPerformed(ActionEvent actionEvent)
626 all_actionPerformed();
630 this.setBorder(new TitledBorder(
631 MessageManager.getString("label.structures_filter")));
632 JvSwingUtils.jvInitComponent(this);
635 this.add(alphaHelix);
636 this.add(betaStrand);
640 public void alphaHelix_actionPerformed()
642 updateSelectAllState();
643 aColChooser.setCurrentStructureFilterPanel(this);
644 aColChooser.updateView();
647 public void betaStrand_actionPerformed()
649 updateSelectAllState();
650 aColChooser.setCurrentStructureFilterPanel(this);
651 aColChooser.updateView();
654 public void turn_actionPerformed()
656 updateSelectAllState();
657 aColChooser.setCurrentStructureFilterPanel(this);
658 aColChooser.updateView();
661 public void all_actionPerformed()
663 if (all.isSelected())
665 alphaHelix.setSelected(true);
666 betaStrand.setSelected(true);
667 turn.setSelected(true);
671 alphaHelix.setSelected(false);
672 betaStrand.setSelected(false);
673 turn.setSelected(false);
675 aColChooser.setCurrentStructureFilterPanel(this);
676 aColChooser.updateView();
679 public void updateSelectAllState()
681 if (alphaHelix.isSelected() && betaStrand.isSelected()
682 && turn.isSelected())
684 all.setSelected(true);
688 all.setSelected(false);
692 public void syncState()
694 StructureFilterPanel sfp = aColChooser
695 .getCurrentStructureFilterPanel();
698 alphaHelix.setSelected(sfp.alphaHelix.isSelected());
699 betaStrand.setSelected(sfp.betaStrand.isSelected());
700 turn.setSelected(sfp.turn.isSelected());
701 if (sfp.all.isSelected())
703 all.setSelected(true);
704 alphaHelix.setSelected(true);
705 betaStrand.setSelected(true);
706 turn.setSelected(true);
713 public class SearchPanel extends JPanel
715 private AnnotationColumnChooser aColChooser;
717 private JCheckBox displayName = new JCheckBox();
719 private JCheckBox description = new JCheckBox();
721 private static final String FILTER_BY_ANN_CACHE_KEY = "CACHE.SELECT_FILTER_BY_ANNOT";
723 public JvCacheableInputBox<String> searchBox = new JvCacheableInputBox<>(
724 FILTER_BY_ANN_CACHE_KEY);
726 public SearchPanel(AnnotationColumnChooser aColChooser)
729 this.aColChooser = aColChooser;
730 JvSwingUtils.jvInitComponent(this);
731 this.setBorder(new TitledBorder(
732 MessageManager.getString("label.search_filter")));
734 searchBox.setPrototypeDisplayValue("XXXXXXXXXXXXXXXXXXXXXXX");
735 searchBox.getComponent().setToolTipText(
736 MessageManager.getString("info.enter_search_text_here"));
737 searchBox.addKeyListener(new java.awt.event.KeyAdapter()
740 public void keyPressed(KeyEvent e)
742 if (e.getKeyCode() == KeyEvent.VK_ENTER)
745 searchStringAction();
749 searchBox.addFocusListener(new FocusAdapter()
752 public void focusLost(FocusEvent e)
754 searchStringAction();
758 JvSwingUtils.jvInitComponent(displayName, "label.label");
759 displayName.addActionListener(new ActionListener()
762 public void actionPerformed(ActionEvent actionEvent)
764 displayNameCheckboxAction();
768 JvSwingUtils.jvInitComponent(description, "label.description");
769 description.addActionListener(new ActionListener()
772 public void actionPerformed(ActionEvent actionEvent)
774 descriptionCheckboxAction();
779 this.add(searchBox.getComponent());
780 this.add(displayName);
781 this.add(description);
784 public void displayNameCheckboxAction()
786 aColChooser.setCurrentSearchPanel(this);
787 aColChooser.updateView();
790 public void descriptionCheckboxAction()
792 aColChooser.setCurrentSearchPanel(this);
793 aColChooser.updateView();
796 public void searchStringAction()
798 aColChooser.setCurrentSearchPanel(this);
799 aColChooser.updateView();
800 updateSearchPanelToolTips();
801 searchBox.updateCache();
804 public void syncState()
806 SearchPanel sp = aColChooser.getCurrentSearchPanel();
809 description.setEnabled(sp.description.isEnabled());
810 description.setSelected(sp.description.isSelected());
812 displayName.setEnabled(sp.displayName.isEnabled());
813 displayName.setSelected(sp.displayName.isSelected());
815 searchBox.setSelectedItem(sp.searchBox.getUserInput());
817 updateSearchPanelToolTips();
820 public void updateSearchPanelToolTips()
822 String defaultTtip = MessageManager
823 .getString("info.enter_search_text_to_enable");
824 String labelTtip = MessageManager.formatMessage(
825 "info.search_in_annotation_label",
826 annotations.getSelectedItem().toString());
827 String descTtip = MessageManager.formatMessage(
828 "info.search_in_annotation_description",
829 annotations.getSelectedItem().toString());
830 displayName.setToolTipText(
831 displayName.isEnabled() ? labelTtip : defaultTtip);
832 description.setToolTipText(
833 description.isEnabled() ? descTtip : defaultTtip);
838 public void ok_actionPerformed()
841 super.ok_actionPerformed();
845 public void cancel_actionPerformed()
848 super.cancel_actionPerformed();
851 private void saveCache()
853 gSearchPanel.searchBox.persistCache();
854 ngSearchPanel.searchBox.persistCache();
855 gSearchPanel.searchBox.updateCache();
856 ngSearchPanel.searchBox.updateCache();