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.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.event.ActionEvent;
34 import java.awt.event.ActionListener;
35 import java.awt.event.ItemEvent;
36 import java.awt.event.ItemListener;
37 import java.util.Iterator;
39 import javax.swing.ButtonGroup;
40 import javax.swing.JCheckBox;
41 import javax.swing.JComboBox;
42 import javax.swing.JInternalFrame;
43 import javax.swing.JLayeredPane;
44 import javax.swing.JPanel;
45 import javax.swing.JRadioButton;
46 import javax.swing.JTextField;
47 import javax.swing.border.TitledBorder;
48 import javax.swing.event.DocumentEvent;
49 import javax.swing.event.DocumentListener;
51 import net.miginfocom.swing.MigLayout;
53 @SuppressWarnings("serial")
54 public class AnnotationColumnChooser extends AnnotationRowFilter implements
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 ColumnSelection oldColumnSelection;
91 public AnnotationColumnChooser(AlignViewport av, final AlignmentPanel ap)
94 frame = new JInternalFrame();
95 frame.setContentPane(this);
96 frame.setLayer(JLayeredPane.PALETTE_LAYER);
97 Desktop.addInternalFrame(frame,
98 MessageManager.getString("label.select_by_annotation"), 520,
101 addSliderChangeListener();
102 addSliderMouseListeners();
104 if (av.getAlignment().getAlignmentAnnotation() == null)
108 setOldColumnSelection(av.getColumnSelection());
111 setAnnotations(new JComboBox<String>(getAnnotationItems(false)));
112 populateThresholdComboBox(threshold);
114 // restore Object state from the previous session if one exists
115 if (av.getAnnotationColumnSelectionState() != null)
117 currentSearchPanel = av.getAnnotationColumnSelectionState()
118 .getCurrentSearchPanel();
119 currentStructureFilterPanel = av.getAnnotationColumnSelectionState()
120 .getCurrentStructureFilterPanel();
121 annotations.setSelectedIndex(av.getAnnotationColumnSelectionState()
122 .getAnnotations().getSelectedIndex());
123 threshold.setSelectedIndex(av.getAnnotationColumnSelectionState()
124 .getThreshold().getSelectedIndex());
125 actionOption = av.getAnnotationColumnSelectionState()
132 } catch (Exception ex)
143 protected void jbInit()
147 JPanel thresholdPanel = new JPanel();
148 thresholdPanel.setBorder(new TitledBorder(MessageManager
149 .getString("label.threshold_filter")));
150 thresholdPanel.setBackground(Color.white);
151 thresholdPanel.setFont(JvSwingUtils.getLabelFont());
152 thresholdPanel.setLayout(new MigLayout("", "[left][right]", "[][]"));
154 JPanel actionPanel = new JPanel();
155 actionPanel.setBackground(Color.white);
156 actionPanel.setFont(JvSwingUtils.getLabelFont());
158 JPanel graphFilterView = new JPanel();
159 graphFilterView.setLayout(new MigLayout("", "[left][right]", "[][]"));
160 graphFilterView.setBackground(Color.white);
162 JPanel noGraphFilterView = new JPanel();
163 noGraphFilterView.setLayout(new MigLayout("", "[left][right]", "[][]"));
164 noGraphFilterView.setBackground(Color.white);
166 annotationComboBoxPanel.setBackground(Color.white);
167 annotationComboBoxPanel.setFont(JvSwingUtils.getLabelFont());
169 gSearchPanel = new SearchPanel(this);
170 ngSearchPanel = new SearchPanel(this);
171 gFurtherActionPanel = new FurtherActionPanel(this);
172 ngFurtherActionPanel = new FurtherActionPanel(this);
173 gStructureFilterPanel = new StructureFilterPanel(this);
174 ngStructureFilterPanel = new StructureFilterPanel(this);
176 thresholdPanel.add(getThreshold());
177 thresholdPanel.add(thresholdValue, "wrap");
178 thresholdPanel.add(slider, "grow, span, wrap");
181 actionPanel.add(cancel);
183 graphFilterView.add(gSearchPanel, "grow, span, wrap");
184 graphFilterView.add(gStructureFilterPanel, "grow, span, wrap");
185 graphFilterView.add(thresholdPanel, "grow, span, wrap");
186 graphFilterView.add(gFurtherActionPanel);
188 noGraphFilterView.add(ngSearchPanel, "grow, span, wrap");
189 noGraphFilterView.add(ngStructureFilterPanel, "grow, span, wrap");
190 noGraphFilterView.add(ngFurtherActionPanel);
192 annotationComboBoxPanel.add(getAnnotations());
193 switchableViewsPanel.add(noGraphFilterView,
194 AnnotationColumnChooser.NO_GRAPH_VIEW);
195 switchableViewsPanel.add(graphFilterView,
196 AnnotationColumnChooser.GRAPH_VIEW);
198 this.setLayout(new BorderLayout());
199 this.add(annotationComboBoxPanel, java.awt.BorderLayout.PAGE_START);
200 this.add(switchableViewsPanel, java.awt.BorderLayout.CENTER);
201 this.add(actionPanel, java.awt.BorderLayout.SOUTH);
203 selectedAnnotationChanged();
204 updateThresholdPanelToolTip();
208 protected void updateThresholdPanelToolTip()
210 thresholdValue.setToolTipText("");
211 slider.setToolTipText("");
213 String defaultTtip = MessageManager
214 .getString("info.change_threshold_mode_to_enable");
216 String thresh = getThreshold().getSelectedItem().toString();
217 if (thresh.equalsIgnoreCase("No Threshold"))
219 thresholdValue.setToolTipText(defaultTtip);
220 slider.setToolTipText(defaultTtip);
225 protected void reset()
227 if (this.getOldColumnSelection() != null)
229 av.getColumnSelection().clear();
231 if (av.getAnnotationColumnSelectionState() != null)
233 ColumnSelection oldSelection = av
234 .getAnnotationColumnSelectionState()
235 .getOldColumnSelection();
236 if (oldSelection != null && oldSelection.getHiddenColumns() != null
237 && !oldSelection.getHiddenColumns().isEmpty())
239 for (Iterator<int[]> itr = oldSelection.getHiddenColumns()
240 .iterator(); itr.hasNext();)
242 int positions[] = itr.next();
243 av.hideColumns(positions[0], positions[1]);
246 av.setColumnSelection(oldSelection);
248 ap.paintAlignment(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);
267 public void updateView()
269 // Check if combobox is still adjusting
275 AnnotationFilterParameter filterParams = new AnnotationFilterParameter();
277 setCurrentAnnotation(av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
278 .getSelectedIndex()]]);
280 int selectedThresholdItem = getSelectedThresholdItem(getThreshold()
281 .getSelectedIndex());
283 slider.setEnabled(true);
284 thresholdValue.setEnabled(true);
286 if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
288 slider.setEnabled(false);
289 thresholdValue.setEnabled(false);
290 thresholdValue.setText("");
291 // build filter params
293 else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
295 if (getCurrentAnnotation().threshold == null)
297 getCurrentAnnotation()
299 new jalview.datamodel.GraphLine(
300 (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin) / 2f,
301 "Threshold", Color.black));
305 float range = getCurrentAnnotation().graphMax * 1000
306 - getCurrentAnnotation().graphMin * 1000;
308 slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
309 slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
310 slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000));
311 thresholdValue.setText(getCurrentAnnotation().threshold.value + "");
312 slider.setMajorTickSpacing((int) (range / 10f));
313 slider.setEnabled(true);
314 thresholdValue.setEnabled(true);
317 // build filter params
319 .setThresholdType(AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);
320 if (getCurrentAnnotation().graph != AlignmentAnnotation.NO_GRAPH)
323 .setThresholdValue(getCurrentAnnotation().threshold.value);
325 if (selectedThresholdItem == AnnotationColourGradient.ABOVE_THRESHOLD)
328 .setThresholdType(AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD);
330 else if (selectedThresholdItem == AnnotationColourGradient.BELOW_THRESHOLD)
333 .setThresholdType(AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD);
338 updateThresholdPanelToolTip();
339 if (currentStructureFilterPanel != null)
341 if (currentStructureFilterPanel.alphaHelix.isSelected())
343 filterParams.setFilterAlphaHelix(true);
345 if (currentStructureFilterPanel.betaStrand.isSelected())
347 filterParams.setFilterBetaSheet(true);
349 if (currentStructureFilterPanel.turn.isSelected())
351 filterParams.setFilterTurn(true);
355 if (currentSearchPanel != null)
358 if (!currentSearchPanel.searchBox.getText().isEmpty())
360 currentSearchPanel.description.setEnabled(true);
361 currentSearchPanel.displayName.setEnabled(true);
362 filterParams.setRegexString(currentSearchPanel.searchBox.getText());
363 if (currentSearchPanel.displayName.isSelected())
366 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING);
368 if (currentSearchPanel.description.isSelected())
371 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION);
376 currentSearchPanel.description.setEnabled(false);
377 currentSearchPanel.displayName.setEnabled(false);
381 av.getColumnSelection().filterAnnotations(
382 getCurrentAnnotation().annotations, filterParams);
384 av.showAllHiddenColumns();
385 if (getActionOption() == ACTION_OPTION_HIDE)
387 av.hideSelectedColumns();
391 av.setAnnotationColumnSelectionState(this);
392 ap.paintAlignment(true);
395 public ColumnSelection getOldColumnSelection()
397 return oldColumnSelection;
400 public void setOldColumnSelection(ColumnSelection currentColumnSelection)
402 if (currentColumnSelection != null)
404 this.oldColumnSelection = new ColumnSelection(currentColumnSelection);
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()]].graph != AlignmentAnnotation.NO_GRAPH)
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()
558 if (aColChooser.getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
560 this.optionsGroup.setSelected(this.hideOption.getModel(), true);
564 this.optionsGroup.setSelected(this.selectOption.getModel(), true);
569 public class StructureFilterPanel extends JPanel
571 private AnnotationColumnChooser aColChooser;
573 private JCheckBox alphaHelix = new JCheckBox();
575 private JCheckBox betaStrand = new JCheckBox();
577 private JCheckBox turn = new JCheckBox();
579 private JCheckBox all = new JCheckBox();
581 public StructureFilterPanel(AnnotationColumnChooser aColChooser)
583 this.aColChooser = aColChooser;
585 JvSwingUtils.jvInitComponent(alphaHelix, "label.alpha_helix");
586 alphaHelix.addActionListener(new ActionListener()
589 public void actionPerformed(ActionEvent actionEvent)
591 alphaHelix_actionPerformed();
595 JvSwingUtils.jvInitComponent(betaStrand, "label.beta_strand");
596 betaStrand.addActionListener(new ActionListener()
599 public void actionPerformed(ActionEvent actionEvent)
601 betaStrand_actionPerformed();
605 JvSwingUtils.jvInitComponent(turn, "label.turn");
606 turn.addActionListener(new ActionListener()
609 public void actionPerformed(ActionEvent actionEvent)
611 turn_actionPerformed();
615 JvSwingUtils.jvInitComponent(all, "label.select_all");
616 all.addActionListener(new ActionListener()
619 public void actionPerformed(ActionEvent actionEvent)
621 all_actionPerformed();
625 this.setBorder(new TitledBorder(MessageManager
626 .getString("label.structures_filter")));
627 JvSwingUtils.jvInitComponent(this);
630 this.add(alphaHelix);
631 this.add(betaStrand);
635 public void alphaHelix_actionPerformed()
637 updateSelectAllState();
638 aColChooser.setCurrentStructureFilterPanel(this);
639 aColChooser.updateView();
642 public void betaStrand_actionPerformed()
644 updateSelectAllState();
645 aColChooser.setCurrentStructureFilterPanel(this);
646 aColChooser.updateView();
649 public void turn_actionPerformed()
651 updateSelectAllState();
652 aColChooser.setCurrentStructureFilterPanel(this);
653 aColChooser.updateView();
656 public void all_actionPerformed()
658 if (all.isSelected())
660 alphaHelix.setSelected(true);
661 betaStrand.setSelected(true);
662 turn.setSelected(true);
666 alphaHelix.setSelected(false);
667 betaStrand.setSelected(false);
668 turn.setSelected(false);
670 aColChooser.setCurrentStructureFilterPanel(this);
671 aColChooser.updateView();
674 public void updateSelectAllState()
676 if (alphaHelix.isSelected() && betaStrand.isSelected()
677 && turn.isSelected())
679 all.setSelected(true);
683 all.setSelected(false);
687 public void syncState()
689 StructureFilterPanel sfp = aColChooser
690 .getCurrentStructureFilterPanel();
693 alphaHelix.setSelected(sfp.alphaHelix.isSelected());
694 betaStrand.setSelected(sfp.betaStrand.isSelected());
695 turn.setSelected(sfp.turn.isSelected());
696 if (sfp.all.isSelected())
698 all.setSelected(true);
699 alphaHelix.setSelected(true);
700 betaStrand.setSelected(true);
701 turn.setSelected(true);
708 public class SearchPanel extends JPanel
710 private AnnotationColumnChooser aColChooser;
712 private JCheckBox displayName = new JCheckBox();
714 private JCheckBox description = new JCheckBox();
716 private JTextField searchBox = new JTextField(10);
718 public SearchPanel(AnnotationColumnChooser aColChooser)
721 this.aColChooser = aColChooser;
722 JvSwingUtils.jvInitComponent(this);
723 this.setBorder(new TitledBorder(MessageManager
724 .getString("label.search_filter")));
726 JvSwingUtils.jvInitComponent(searchBox);
727 searchBox.setToolTipText(MessageManager
728 .getString("info.enter_search_text_here"));
729 searchBox.getDocument().addDocumentListener(new DocumentListener()
732 public void insertUpdate(DocumentEvent e)
734 searchStringAction();
738 public void removeUpdate(DocumentEvent e)
740 searchStringAction();
744 public void changedUpdate(DocumentEvent e)
746 searchStringAction();
750 JvSwingUtils.jvInitComponent(displayName, "label.label");
751 displayName.setEnabled(false);
752 displayName.addActionListener(new ActionListener()
755 public void actionPerformed(ActionEvent actionEvent)
757 displayNameCheckboxAction();
761 JvSwingUtils.jvInitComponent(description, "label.description");
762 description.setEnabled(false);
763 description.addActionListener(new ActionListener()
766 public void actionPerformed(ActionEvent actionEvent)
768 discriptionCheckboxAction();
774 this.add(displayName);
775 this.add(description);
778 public void displayNameCheckboxAction()
780 aColChooser.setCurrentSearchPanel(this);
781 aColChooser.updateView();
784 public void discriptionCheckboxAction()
786 aColChooser.setCurrentSearchPanel(this);
787 aColChooser.updateView();
790 public void searchStringAction()
792 aColChooser.setCurrentSearchPanel(this);
793 aColChooser.updateView();
794 updateSearchPanelToolTips();
797 public void syncState()
799 SearchPanel sp = aColChooser.getCurrentSearchPanel();
802 description.setEnabled(sp.description.isEnabled());
803 description.setSelected(sp.description.isSelected());
805 displayName.setEnabled(sp.displayName.isEnabled());
806 displayName.setSelected(sp.displayName.isSelected());
808 searchBox.setText(sp.searchBox.getText());
810 updateSearchPanelToolTips();
813 public void updateSearchPanelToolTips()
815 String defaultTtip = MessageManager
816 .getString("info.enter_search_text_to_enable");
817 String labelTtip = MessageManager.formatMessage(
818 "info.search_in_annotation_label", annotations
819 .getSelectedItem().toString());
820 String descTtip = MessageManager.formatMessage(
821 "info.search_in_annotation_description", annotations
822 .getSelectedItem().toString());
823 displayName.setToolTipText(displayName.isEnabled() ? labelTtip
825 description.setToolTipText(description.isEnabled() ? descTtip