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.ColumnSelection;
26 import jalview.datamodel.GraphLine;
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.ItemEvent;
38 import java.awt.event.ItemListener;
39 import java.util.Iterator;
41 import javax.swing.ButtonGroup;
42 import javax.swing.JCheckBox;
43 import javax.swing.JComboBox;
44 import javax.swing.JInternalFrame;
45 import javax.swing.JLayeredPane;
46 import javax.swing.JPanel;
47 import javax.swing.JRadioButton;
48 import javax.swing.JTextField;
49 import javax.swing.border.TitledBorder;
50 import javax.swing.event.DocumentEvent;
51 import javax.swing.event.DocumentListener;
53 import net.miginfocom.swing.MigLayout;
55 @SuppressWarnings("serial")
56 public class AnnotationColumnChooser extends AnnotationRowFilter implements
60 private JComboBox<String> annotations;
62 private JPanel actionPanel = new JPanel();
64 private JPanel thresholdPanel = new JPanel();
66 private JPanel switchableViewsPanel = new JPanel(new CardLayout());
68 private CardLayout switchableViewsLayout = (CardLayout) (switchableViewsPanel
70 private JPanel noGraphFilterView = new JPanel();
72 private JPanel graphFilterView = new JPanel();
74 private JPanel annotationComboBoxPanel = new JPanel();
76 private BorderLayout borderLayout1 = new BorderLayout();
78 private JComboBox<String> threshold = new JComboBox<String>();
80 private StructureFilterPanel gStructureFilterPanel;
82 private StructureFilterPanel ngStructureFilterPanel;
84 private StructureFilterPanel currentStructureFilterPanel;
86 private SearchPanel currentSearchPanel;
88 private SearchPanel gSearchPanel;
90 private SearchPanel ngSearchPanel;
92 private FurtherActionPanel currentFurtherActionPanel;
94 private FurtherActionPanel gFurtherActionPanel;
96 private FurtherActionPanel ngFurtherActionPanel;
98 public static final int ACTION_OPTION_SELECT = 1;
100 public static int ACTION_OPTION_HIDE = 2;
102 public static String NO_GRAPH_VIEW = "0";
104 public static String GRAPH_VIEW = "1";
106 private int actionOption = ACTION_OPTION_SELECT;
108 private ColumnSelection oldColumnSelection;
110 public AnnotationColumnChooser()
115 } catch (Exception ex)
117 ex.printStackTrace();
121 public AnnotationColumnChooser(AlignViewport av, final AlignmentPanel ap)
124 frame = new JInternalFrame();
125 frame.setContentPane(this);
126 frame.setLayer(JLayeredPane.PALETTE_LAYER);
127 Desktop.addInternalFrame(frame,
128 MessageManager.getString("label.select_by_annotation"), 520,
131 addSliderChangeListener();
132 addSliderMouseListeners();
134 if (av.getAlignment().getAlignmentAnnotation() == null)
138 setOldColumnSelection(av.getColumnSelection());
141 setAnnotations(new JComboBox<String>(getAnnotationItems(false)));
142 populateThresholdComboBox(threshold);
144 // restore Object state from the previous session if one exists
145 if (av.getAnnotationColumnSelectionState() != null)
147 currentSearchPanel = av.getAnnotationColumnSelectionState()
148 .getCurrentSearchPanel();
149 currentStructureFilterPanel = av.getAnnotationColumnSelectionState()
150 .getCurrentStructureFilterPanel();
151 annotations.setSelectedIndex(av.getAnnotationColumnSelectionState()
152 .getAnnotations().getSelectedIndex());
153 threshold.setSelectedIndex(av.getAnnotationColumnSelectionState()
154 .getThreshold().getSelectedIndex());
155 actionOption = av.getAnnotationColumnSelectionState()
162 } catch (Exception ex)
172 private void jbInit() throws Exception
175 ok.setText(MessageManager.getString("action.ok"));
176 ok.addActionListener(new ActionListener()
179 public void actionPerformed(ActionEvent e)
181 ok_actionPerformed(e);
185 cancel.setOpaque(false);
186 cancel.setText(MessageManager.getString("action.cancel"));
187 cancel.addActionListener(new ActionListener()
190 public void actionPerformed(ActionEvent e)
192 cancel_actionPerformed(e);
196 annotations.addItemListener(this);
197 annotations.setToolTipText(MessageManager
198 .getString("info.select_annotation_row"));
199 threshold.addActionListener(new ActionListener()
202 public void actionPerformed(ActionEvent e)
204 threshold_actionPerformed(e);
208 thresholdValue.setEnabled(false);
209 thresholdValue.setColumns(7);
210 thresholdValue.addActionListener(new ActionListener()
213 public void actionPerformed(ActionEvent e)
215 thresholdValue_actionPerformed(e);
219 slider.setPaintLabels(false);
220 slider.setPaintTicks(true);
221 slider.setBackground(Color.white);
222 slider.setEnabled(false);
223 slider.setOpaque(false);
224 slider.setPreferredSize(new Dimension(100, 32));
226 thresholdPanel.setBorder(new TitledBorder(MessageManager
227 .getString("label.threshold_filter")));
228 thresholdPanel.setBackground(Color.white);
229 thresholdPanel.setFont(JvSwingUtils.getLabelFont());
230 thresholdPanel.setLayout(new MigLayout("", "[left][right]", "[][]"));
232 actionPanel.setBackground(Color.white);
233 actionPanel.setFont(JvSwingUtils.getLabelFont());
235 graphFilterView.setLayout(new MigLayout("", "[left][right]", "[][]"));
236 graphFilterView.setBackground(Color.white);
238 noGraphFilterView.setLayout(new MigLayout("", "[left][right]", "[][]"));
239 noGraphFilterView.setBackground(Color.white);
241 annotationComboBoxPanel.setBackground(Color.white);
242 annotationComboBoxPanel.setFont(JvSwingUtils.getLabelFont());
244 gSearchPanel = new SearchPanel(this);
245 ngSearchPanel = new SearchPanel(this);
246 gFurtherActionPanel = new FurtherActionPanel(this);
247 ngFurtherActionPanel = new FurtherActionPanel(this);
248 gStructureFilterPanel = new StructureFilterPanel(this);
249 ngStructureFilterPanel = new StructureFilterPanel(this);
251 thresholdPanel.add(getThreshold());
252 thresholdPanel.add(thresholdValue, "wrap");
253 thresholdPanel.add(slider, "grow, span, wrap");
256 actionPanel.add(cancel);
258 graphFilterView.add(gSearchPanel, "grow, span, wrap");
259 graphFilterView.add(gStructureFilterPanel, "grow, span, wrap");
260 graphFilterView.add(thresholdPanel, "grow, span, wrap");
261 graphFilterView.add(gFurtherActionPanel);
263 noGraphFilterView.add(ngSearchPanel, "grow, span, wrap");
264 noGraphFilterView.add(ngStructureFilterPanel, "grow, span, wrap");
265 noGraphFilterView.add(ngFurtherActionPanel);
267 annotationComboBoxPanel.add(getAnnotations());
268 switchableViewsPanel.add(noGraphFilterView,
269 AnnotationColumnChooser.NO_GRAPH_VIEW);
270 switchableViewsPanel.add(graphFilterView,
271 AnnotationColumnChooser.GRAPH_VIEW);
273 this.setLayout(borderLayout1);
274 this.add(annotationComboBoxPanel, java.awt.BorderLayout.PAGE_START);
275 this.add(switchableViewsPanel, java.awt.BorderLayout.CENTER);
276 this.add(actionPanel, java.awt.BorderLayout.SOUTH);
278 selectedAnnotationChanged();
279 updateThresholdPanelToolTip();
283 public void updateThresholdPanelToolTip()
285 thresholdValue.setToolTipText("");
286 slider.setToolTipText("");
288 String defaultTtip = MessageManager
289 .getString("info.change_threshold_mode_to_enable");
291 String threshold = getThreshold().getSelectedItem().toString();
292 if (threshold.equalsIgnoreCase("No Threshold"))
294 thresholdValue.setToolTipText(defaultTtip);
295 slider.setToolTipText(defaultTtip);
300 if (this.getOldColumnSelection() != null)
302 av.getColumnSelection().clear();
304 if (av.getAnnotationColumnSelectionState() != null)
306 ColumnSelection oldSelection = av
307 .getAnnotationColumnSelectionState()
308 .getOldColumnSelection();
309 if (oldSelection != null && oldSelection.getHiddenColumns() != null
310 && !oldSelection.getHiddenColumns().isEmpty())
312 for (Iterator<int[]> itr = oldSelection.getHiddenColumns()
313 .iterator(); itr.hasNext();)
315 int positions[] = itr.next();
316 av.hideColumns(positions[0], positions[1]);
319 av.setColumnSelection(oldSelection);
321 ap.paintAlignment(true);
326 public void valueChanged(boolean updateAllAnnotation)
328 if (slider.isEnabled())
330 getCurrentAnnotation().threshold.value = slider.getValue() / 1000f;
332 propagateSeqAssociatedThreshold(updateAllAnnotation,
333 getCurrentAnnotation());
334 ap.paintAlignment(false);
338 public JComboBox<String> getThreshold()
343 public void setThreshold(JComboBox<String> threshold)
345 this.threshold = threshold;
348 public JComboBox<String> getAnnotations()
353 public void setAnnotations(JComboBox<String> annotations)
355 this.annotations = annotations;
359 public void updateView()
361 // Check if combobox is still adjusting
367 AnnotationFilterParameter filterParams = new AnnotationFilterParameter();
369 setCurrentAnnotation(av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
370 .getSelectedIndex()]]);
372 int selectedThresholdItem = getSelectedThresholdItem(getThreshold()
373 .getSelectedIndex());
375 slider.setEnabled(true);
376 thresholdValue.setEnabled(true);
378 if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
380 slider.setEnabled(false);
381 thresholdValue.setEnabled(false);
382 thresholdValue.setText("");
383 // build filter params
385 else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
387 if (getCurrentAnnotation().threshold == null)
389 getCurrentAnnotation()
392 (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin) / 2f,
393 "Threshold", Color.black));
397 float range = getCurrentAnnotation().graphMax * 1000
398 - getCurrentAnnotation().graphMin * 1000;
400 slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
401 slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
402 slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000));
403 thresholdValue.setText(getCurrentAnnotation().threshold.value + "");
404 slider.setMajorTickSpacing((int) (range / 10f));
405 slider.setEnabled(true);
406 thresholdValue.setEnabled(true);
409 // build filter params
411 .setThresholdType(AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);
412 if (getCurrentAnnotation().graph != AlignmentAnnotation.NO_GRAPH)
415 .setThresholdValue(getCurrentAnnotation().threshold.value);
417 if (selectedThresholdItem == AnnotationColourGradient.ABOVE_THRESHOLD)
420 .setThresholdType(AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD);
422 else if (selectedThresholdItem == AnnotationColourGradient.BELOW_THRESHOLD)
425 .setThresholdType(AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD);
430 updateThresholdPanelToolTip();
431 if (currentStructureFilterPanel != null)
433 if (currentStructureFilterPanel.alphaHelix.isSelected())
435 filterParams.setFilterAlphaHelix(true);
437 if (currentStructureFilterPanel.betaStrand.isSelected())
439 filterParams.setFilterBetaSheet(true);
441 if (currentStructureFilterPanel.turn.isSelected())
443 filterParams.setFilterTurn(true);
447 if (currentSearchPanel != null)
450 if (!currentSearchPanel.searchBox.getText().isEmpty())
452 currentSearchPanel.description.setEnabled(true);
453 currentSearchPanel.displayName.setEnabled(true);
454 filterParams.setRegexString(currentSearchPanel.searchBox.getText());
455 if (currentSearchPanel.displayName.isSelected())
458 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING);
460 if (currentSearchPanel.description.isSelected())
463 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION);
468 currentSearchPanel.description.setEnabled(false);
469 currentSearchPanel.displayName.setEnabled(false);
473 av.getColumnSelection().filterAnnotations(
474 getCurrentAnnotation().annotations, filterParams);
476 av.showAllHiddenColumns();
477 if (getActionOption() == ACTION_OPTION_HIDE)
479 av.hideSelectedColumns();
483 av.setAnnotationColumnSelectionState(this);
484 ap.paintAlignment(true);
487 public ColumnSelection getOldColumnSelection()
489 return oldColumnSelection;
492 public void setOldColumnSelection(ColumnSelection currentColumnSelection)
494 if (currentColumnSelection != null)
496 this.oldColumnSelection = new ColumnSelection(currentColumnSelection);
500 public FurtherActionPanel getCurrentFutherActionPanel()
502 return currentFurtherActionPanel;
505 public void setCurrentFutherActionPanel(
506 FurtherActionPanel currentFutherActionPanel)
508 this.currentFurtherActionPanel = currentFutherActionPanel;
511 public SearchPanel getCurrentSearchPanel()
513 return currentSearchPanel;
516 public void setCurrentSearchPanel(SearchPanel currentSearchPanel)
518 this.currentSearchPanel = currentSearchPanel;
521 public int getActionOption()
526 public void setActionOption(int actionOption)
528 this.actionOption = actionOption;
531 public StructureFilterPanel getCurrentStructureFilterPanel()
533 return currentStructureFilterPanel;
536 public void setCurrentStructureFilterPanel(
537 StructureFilterPanel currentStructureFilterPanel)
539 this.currentStructureFilterPanel = currentStructureFilterPanel;
542 public void select_action(ActionEvent actionEvent)
544 JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
545 if (radioButton.isSelected())
547 setActionOption(ACTION_OPTION_SELECT);
552 public void hide_action(ActionEvent actionEvent)
554 JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
555 if (radioButton.isSelected())
557 setActionOption(ACTION_OPTION_HIDE);
563 public void itemStateChanged(ItemEvent e)
565 selectedAnnotationChanged();
568 public void selectedAnnotationChanged()
570 String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
571 if (av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
572 .getSelectedIndex()]].graph != AlignmentAnnotation.NO_GRAPH)
574 currentView = AnnotationColumnChooser.GRAPH_VIEW;
577 gSearchPanel.syncState();
578 gFurtherActionPanel.syncState();
579 gStructureFilterPanel.syncState();
581 ngSearchPanel.syncState();
582 ngFurtherActionPanel.syncState();
583 ngStructureFilterPanel.syncState();
585 switchableViewsLayout.show(switchableViewsPanel, currentView);
590 public class FurtherActionPanel extends JPanel
592 private AnnotationColumnChooser aColChooser;
594 private JRadioButton hideOption = new JRadioButton();
596 private JRadioButton selectOption = new JRadioButton();
598 private ButtonGroup optionsGroup = new ButtonGroup();
600 public FurtherActionPanel(AnnotationColumnChooser aColChooser)
602 this.aColChooser = aColChooser;
603 JvSwingUtils.jvInitComponent(selectOption, "action.select");
604 selectOption.addActionListener(new ActionListener()
607 public void actionPerformed(ActionEvent actionEvent)
609 selectRadioAction(actionEvent);
613 JvSwingUtils.jvInitComponent(hideOption, "action.hide");
614 hideOption.addActionListener(new ActionListener()
617 public void actionPerformed(ActionEvent actionEvent)
619 hideRadioAction(actionEvent);
623 optionsGroup.add(selectOption);
624 optionsGroup.add(hideOption);
625 optionsGroup.setSelected(selectOption.getModel(), true);
627 JvSwingUtils.jvInitComponent(this);
630 this.add(selectOption);
631 this.add(hideOption);
634 public void selectRadioAction(ActionEvent actionEvent)
636 aColChooser.setCurrentFutherActionPanel(this);
637 aColChooser.select_action(actionEvent);
640 public void hideRadioAction(ActionEvent actionEvent)
642 aColChooser.setCurrentFutherActionPanel(this);
643 aColChooser.hide_action(actionEvent);
646 public void syncState()
648 if (aColChooser.getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
650 this.optionsGroup.setSelected(this.hideOption.getModel(),
655 this.optionsGroup.setSelected(this.selectOption.getModel(), true);
660 public class StructureFilterPanel extends JPanel
662 private AnnotationColumnChooser aColChooser;
664 private JCheckBox alphaHelix = new JCheckBox();
666 private JCheckBox betaStrand = new JCheckBox();
668 private JCheckBox turn = new JCheckBox();
670 private JCheckBox all = new JCheckBox();
672 public StructureFilterPanel(AnnotationColumnChooser aColChooser)
674 this.aColChooser = aColChooser;
676 JvSwingUtils.jvInitComponent(alphaHelix, "label.alpha_helix");
677 alphaHelix.addActionListener(new ActionListener()
680 public void actionPerformed(ActionEvent actionEvent)
682 alphaHelix_actionPerformed();
686 JvSwingUtils.jvInitComponent(betaStrand, "label.beta_strand");
687 betaStrand.addActionListener(new ActionListener()
690 public void actionPerformed(ActionEvent actionEvent)
692 betaStrand_actionPerformed();
696 JvSwingUtils.jvInitComponent(turn, "label.turn");
697 turn.addActionListener(new ActionListener()
700 public void actionPerformed(ActionEvent actionEvent)
702 turn_actionPerformed();
706 JvSwingUtils.jvInitComponent(all, "label.select_all");
707 all.addActionListener(new ActionListener()
710 public void actionPerformed(ActionEvent actionEvent)
712 all_actionPerformed();
716 this.setBorder(new TitledBorder(MessageManager
717 .getString("label.structures_filter")));
718 JvSwingUtils.jvInitComponent(this);
721 this.add(alphaHelix);
722 this.add(betaStrand);
726 public void alphaHelix_actionPerformed()
728 updateSelectAllState();
729 aColChooser.setCurrentStructureFilterPanel(this);
730 aColChooser.updateView();
733 public void betaStrand_actionPerformed()
735 updateSelectAllState();
736 aColChooser.setCurrentStructureFilterPanel(this);
737 aColChooser.updateView();
740 public void turn_actionPerformed()
742 updateSelectAllState();
743 aColChooser.setCurrentStructureFilterPanel(this);
744 aColChooser.updateView();
747 public void all_actionPerformed()
749 if (all.isSelected())
751 alphaHelix.setSelected(true);
752 betaStrand.setSelected(true);
753 turn.setSelected(true);
757 alphaHelix.setSelected(false);
758 betaStrand.setSelected(false);
759 turn.setSelected(false);
761 aColChooser.setCurrentStructureFilterPanel(this);
762 aColChooser.updateView();
765 public void updateSelectAllState()
767 if (alphaHelix.isSelected() && betaStrand.isSelected()
768 && turn.isSelected())
770 all.setSelected(true);
774 all.setSelected(false);
778 public void syncState()
780 StructureFilterPanel sfp = aColChooser
781 .getCurrentStructureFilterPanel();
784 alphaHelix.setSelected(sfp.alphaHelix.isSelected());
785 betaStrand.setSelected(sfp.betaStrand.isSelected());
786 turn.setSelected(sfp.turn.isSelected());
787 if (sfp.all.isSelected())
789 all.setSelected(true);
790 alphaHelix.setSelected(true);
791 betaStrand.setSelected(true);
792 turn.setSelected(true);
799 public class SearchPanel extends JPanel
801 private AnnotationColumnChooser aColChooser;
803 private JCheckBox displayName = new JCheckBox();
805 private JCheckBox description = new JCheckBox();
807 private JTextField searchBox = new JTextField(10);
809 public SearchPanel(AnnotationColumnChooser aColChooser)
812 this.aColChooser = aColChooser;
813 JvSwingUtils.jvInitComponent(this);
814 this.setBorder(new TitledBorder(MessageManager
815 .getString("label.search_filter")));
817 JvSwingUtils.jvInitComponent(searchBox);
818 searchBox.setToolTipText(MessageManager
819 .getString("info.enter_search_text_here"));
820 searchBox.getDocument().addDocumentListener(
821 new DocumentListener()
824 public void insertUpdate(DocumentEvent e)
826 searchStringAction();
830 public void removeUpdate(DocumentEvent e)
832 searchStringAction();
836 public void changedUpdate(DocumentEvent e)
838 searchStringAction();
842 JvSwingUtils.jvInitComponent(displayName, "label.label");
843 displayName.setEnabled(false);
844 displayName.addActionListener(new ActionListener()
847 public void actionPerformed(ActionEvent actionEvent)
849 displayNameCheckboxAction();
853 JvSwingUtils.jvInitComponent(description, "label.description");
854 description.setEnabled(false);
855 description.addActionListener(new ActionListener()
858 public void actionPerformed(ActionEvent actionEvent)
860 discriptionCheckboxAction();
866 this.add(displayName);
867 this.add(description);
870 public void displayNameCheckboxAction()
872 aColChooser.setCurrentSearchPanel(this);
873 aColChooser.updateView();
876 public void discriptionCheckboxAction()
878 aColChooser.setCurrentSearchPanel(this);
879 aColChooser.updateView();
882 public void searchStringAction()
884 aColChooser.setCurrentSearchPanel(this);
885 aColChooser.updateView();
886 updateSearchPanelToolTips();
889 public void syncState()
891 SearchPanel sp = aColChooser.getCurrentSearchPanel();
894 description.setEnabled(sp.description.isEnabled());
895 description.setSelected(sp.description.isSelected());
897 displayName.setEnabled(sp.displayName.isEnabled());
898 displayName.setSelected(sp.displayName.isSelected());
900 searchBox.setText(sp.searchBox.getText());
902 updateSearchPanelToolTips();
905 public void updateSearchPanelToolTips()
907 String defaultTtip = MessageManager
908 .getString("info.enter_search_text_to_enable");
909 String labelTtip = MessageManager
911 "info.search_in_annotation_label", annotations
912 .getSelectedItem().toString());
913 String descTtip = MessageManager
915 "info.search_in_annotation_description", annotations
916 .getSelectedItem().toString());
917 displayName.setToolTipText(displayName.isEnabled() ? labelTtip : defaultTtip);
918 description.setToolTipText(description.isEnabled() ? descTtip