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.Dimension;
34 import java.awt.event.ActionEvent;
35 import java.awt.event.ActionListener;
36 import java.awt.event.ItemEvent;
37 import java.awt.event.ItemListener;
38 import java.util.Iterator;
40 import javax.swing.ButtonGroup;
41 import javax.swing.JCheckBox;
42 import javax.swing.JComboBox;
43 import javax.swing.JInternalFrame;
44 import javax.swing.JLayeredPane;
45 import javax.swing.JPanel;
46 import javax.swing.JRadioButton;
47 import javax.swing.JTextField;
48 import javax.swing.border.TitledBorder;
49 import javax.swing.event.DocumentEvent;
50 import javax.swing.event.DocumentListener;
52 import net.miginfocom.swing.MigLayout;
54 @SuppressWarnings("serial")
55 public class AnnotationColumnChooser extends AnnotationRowFilter implements
59 private JComboBox<String> annotations;
61 private JPanel actionPanel = new JPanel();
63 private JPanel thresholdPanel = new JPanel();
65 private JPanel switchableViewsPanel = new JPanel(new CardLayout());
67 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();
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();
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();
208 thresholdValue.setEnabled(false);
209 thresholdValue.setColumns(7);
210 thresholdValue.addActionListener(new ActionListener()
213 public void actionPerformed(ActionEvent e)
215 thresholdValue_actionPerformed();
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 thresh = getThreshold().getSelectedItem().toString();
292 if (thresh.equalsIgnoreCase("No Threshold"))
294 thresholdValue.setToolTipText(defaultTtip);
295 slider.setToolTipText(defaultTtip);
302 if (this.getOldColumnSelection() != null)
304 av.getColumnSelection().clear();
306 if (av.getAnnotationColumnSelectionState() != null)
308 ColumnSelection oldSelection = av
309 .getAnnotationColumnSelectionState()
310 .getOldColumnSelection();
311 if (oldSelection != null && oldSelection.getHiddenColumns() != null
312 && !oldSelection.getHiddenColumns().isEmpty())
314 for (Iterator<int[]> itr = oldSelection.getHiddenColumns()
315 .iterator(); itr.hasNext();)
317 int positions[] = itr.next();
318 av.hideColumns(positions[0], positions[1]);
321 av.setColumnSelection(oldSelection);
323 ap.paintAlignment(true);
329 public void valueChanged(boolean updateAllAnnotation)
331 if (slider.isEnabled())
333 getCurrentAnnotation().threshold.value = slider.getValue() / 1000f;
335 propagateSeqAssociatedThreshold(updateAllAnnotation,
336 getCurrentAnnotation());
337 ap.paintAlignment(false);
341 public JComboBox<String> getThreshold()
346 public void setThreshold(JComboBox<String> threshold)
348 this.threshold = threshold;
351 public JComboBox<String> getAnnotations()
356 public void setAnnotations(JComboBox<String> annotations)
358 this.annotations = annotations;
362 public void updateView()
364 // Check if combobox is still adjusting
370 AnnotationFilterParameter filterParams = new AnnotationFilterParameter();
372 setCurrentAnnotation(av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
373 .getSelectedIndex()]]);
375 int selectedThresholdItem = getSelectedThresholdItem(getThreshold()
376 .getSelectedIndex());
378 slider.setEnabled(true);
379 thresholdValue.setEnabled(true);
381 if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
383 slider.setEnabled(false);
384 thresholdValue.setEnabled(false);
385 thresholdValue.setText("");
386 // build filter params
388 else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
390 if (getCurrentAnnotation().threshold == null)
392 getCurrentAnnotation()
394 new jalview.datamodel.GraphLine(
395 (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin) / 2f,
396 "Threshold", Color.black));
400 float range = getCurrentAnnotation().graphMax * 1000
401 - getCurrentAnnotation().graphMin * 1000;
403 slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
404 slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
405 slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000));
406 thresholdValue.setText(getCurrentAnnotation().threshold.value + "");
407 slider.setMajorTickSpacing((int) (range / 10f));
408 slider.setEnabled(true);
409 thresholdValue.setEnabled(true);
412 // build filter params
414 .setThresholdType(AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);
415 if (getCurrentAnnotation().graph != AlignmentAnnotation.NO_GRAPH)
418 .setThresholdValue(getCurrentAnnotation().threshold.value);
420 if (selectedThresholdItem == AnnotationColourGradient.ABOVE_THRESHOLD)
423 .setThresholdType(AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD);
425 else if (selectedThresholdItem == AnnotationColourGradient.BELOW_THRESHOLD)
428 .setThresholdType(AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD);
433 updateThresholdPanelToolTip();
434 if (currentStructureFilterPanel != null)
436 if (currentStructureFilterPanel.alphaHelix.isSelected())
438 filterParams.setFilterAlphaHelix(true);
440 if (currentStructureFilterPanel.betaStrand.isSelected())
442 filterParams.setFilterBetaSheet(true);
444 if (currentStructureFilterPanel.turn.isSelected())
446 filterParams.setFilterTurn(true);
450 if (currentSearchPanel != null)
453 if (!currentSearchPanel.searchBox.getText().isEmpty())
455 currentSearchPanel.description.setEnabled(true);
456 currentSearchPanel.displayName.setEnabled(true);
457 filterParams.setRegexString(currentSearchPanel.searchBox.getText());
458 if (currentSearchPanel.displayName.isSelected())
461 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING);
463 if (currentSearchPanel.description.isSelected())
466 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION);
471 currentSearchPanel.description.setEnabled(false);
472 currentSearchPanel.displayName.setEnabled(false);
476 av.getColumnSelection().filterAnnotations(
477 getCurrentAnnotation().annotations, filterParams);
479 av.showAllHiddenColumns();
480 if (getActionOption() == ACTION_OPTION_HIDE)
482 av.hideSelectedColumns();
486 av.setAnnotationColumnSelectionState(this);
487 ap.paintAlignment(true);
490 public ColumnSelection getOldColumnSelection()
492 return oldColumnSelection;
495 public void setOldColumnSelection(ColumnSelection currentColumnSelection)
497 if (currentColumnSelection != null)
499 this.oldColumnSelection = new ColumnSelection(currentColumnSelection);
503 public FurtherActionPanel getCurrentFutherActionPanel()
505 return currentFurtherActionPanel;
508 public void setCurrentFutherActionPanel(
509 FurtherActionPanel currentFutherActionPanel)
511 this.currentFurtherActionPanel = currentFutherActionPanel;
514 public SearchPanel getCurrentSearchPanel()
516 return currentSearchPanel;
519 public void setCurrentSearchPanel(SearchPanel currentSearchPanel)
521 this.currentSearchPanel = currentSearchPanel;
524 public int getActionOption()
529 public void setActionOption(int actionOption)
531 this.actionOption = actionOption;
534 public StructureFilterPanel getCurrentStructureFilterPanel()
536 return currentStructureFilterPanel;
539 public void setCurrentStructureFilterPanel(
540 StructureFilterPanel currentStructureFilterPanel)
542 this.currentStructureFilterPanel = currentStructureFilterPanel;
545 public void select_action(ActionEvent actionEvent)
547 JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
548 if (radioButton.isSelected())
550 setActionOption(ACTION_OPTION_SELECT);
555 public void hide_action(ActionEvent actionEvent)
557 JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
558 if (radioButton.isSelected())
560 setActionOption(ACTION_OPTION_HIDE);
566 public void itemStateChanged(ItemEvent e)
568 selectedAnnotationChanged();
571 public void selectedAnnotationChanged()
573 String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
574 if (av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
575 .getSelectedIndex()]].graph != AlignmentAnnotation.NO_GRAPH)
577 currentView = AnnotationColumnChooser.GRAPH_VIEW;
580 gSearchPanel.syncState();
581 gFurtherActionPanel.syncState();
582 gStructureFilterPanel.syncState();
584 ngSearchPanel.syncState();
585 ngFurtherActionPanel.syncState();
586 ngStructureFilterPanel.syncState();
588 switchableViewsLayout.show(switchableViewsPanel, currentView);
592 public class FurtherActionPanel extends JPanel
594 private AnnotationColumnChooser aColChooser;
596 private JRadioButton hideOption = new JRadioButton();
598 private JRadioButton selectOption = new JRadioButton();
600 private ButtonGroup optionsGroup = new ButtonGroup();
602 public FurtherActionPanel(AnnotationColumnChooser aColChooser)
604 this.aColChooser = aColChooser;
605 JvSwingUtils.jvInitComponent(selectOption, "action.select");
606 selectOption.addActionListener(new ActionListener()
609 public void actionPerformed(ActionEvent actionEvent)
611 selectRadioAction(actionEvent);
615 JvSwingUtils.jvInitComponent(hideOption, "action.hide");
616 hideOption.addActionListener(new ActionListener()
619 public void actionPerformed(ActionEvent actionEvent)
621 hideRadioAction(actionEvent);
625 optionsGroup.add(selectOption);
626 optionsGroup.add(hideOption);
627 optionsGroup.setSelected(selectOption.getModel(), true);
629 JvSwingUtils.jvInitComponent(this);
632 this.add(selectOption);
633 this.add(hideOption);
636 public void selectRadioAction(ActionEvent actionEvent)
638 aColChooser.setCurrentFutherActionPanel(this);
639 aColChooser.select_action(actionEvent);
642 public void hideRadioAction(ActionEvent actionEvent)
644 aColChooser.setCurrentFutherActionPanel(this);
645 aColChooser.hide_action(actionEvent);
648 public void syncState()
650 if (aColChooser.getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
652 this.optionsGroup.setSelected(this.hideOption.getModel(), true);
656 this.optionsGroup.setSelected(this.selectOption.getModel(), true);
661 public class StructureFilterPanel extends JPanel
663 private AnnotationColumnChooser aColChooser;
665 private JCheckBox alphaHelix = new JCheckBox();
667 private JCheckBox betaStrand = new JCheckBox();
669 private JCheckBox turn = new JCheckBox();
671 private JCheckBox all = new JCheckBox();
673 public StructureFilterPanel(AnnotationColumnChooser aColChooser)
675 this.aColChooser = aColChooser;
677 JvSwingUtils.jvInitComponent(alphaHelix, "label.alpha_helix");
678 alphaHelix.addActionListener(new ActionListener()
681 public void actionPerformed(ActionEvent actionEvent)
683 alphaHelix_actionPerformed();
687 JvSwingUtils.jvInitComponent(betaStrand, "label.beta_strand");
688 betaStrand.addActionListener(new ActionListener()
691 public void actionPerformed(ActionEvent actionEvent)
693 betaStrand_actionPerformed();
697 JvSwingUtils.jvInitComponent(turn, "label.turn");
698 turn.addActionListener(new ActionListener()
701 public void actionPerformed(ActionEvent actionEvent)
703 turn_actionPerformed();
707 JvSwingUtils.jvInitComponent(all, "label.select_all");
708 all.addActionListener(new ActionListener()
711 public void actionPerformed(ActionEvent actionEvent)
713 all_actionPerformed();
717 this.setBorder(new TitledBorder(MessageManager
718 .getString("label.structures_filter")));
719 JvSwingUtils.jvInitComponent(this);
722 this.add(alphaHelix);
723 this.add(betaStrand);
727 public void alphaHelix_actionPerformed()
729 updateSelectAllState();
730 aColChooser.setCurrentStructureFilterPanel(this);
731 aColChooser.updateView();
734 public void betaStrand_actionPerformed()
736 updateSelectAllState();
737 aColChooser.setCurrentStructureFilterPanel(this);
738 aColChooser.updateView();
741 public void turn_actionPerformed()
743 updateSelectAllState();
744 aColChooser.setCurrentStructureFilterPanel(this);
745 aColChooser.updateView();
748 public void all_actionPerformed()
750 if (all.isSelected())
752 alphaHelix.setSelected(true);
753 betaStrand.setSelected(true);
754 turn.setSelected(true);
758 alphaHelix.setSelected(false);
759 betaStrand.setSelected(false);
760 turn.setSelected(false);
762 aColChooser.setCurrentStructureFilterPanel(this);
763 aColChooser.updateView();
766 public void updateSelectAllState()
768 if (alphaHelix.isSelected() && betaStrand.isSelected()
769 && turn.isSelected())
771 all.setSelected(true);
775 all.setSelected(false);
779 public void syncState()
781 StructureFilterPanel sfp = aColChooser
782 .getCurrentStructureFilterPanel();
785 alphaHelix.setSelected(sfp.alphaHelix.isSelected());
786 betaStrand.setSelected(sfp.betaStrand.isSelected());
787 turn.setSelected(sfp.turn.isSelected());
788 if (sfp.all.isSelected())
790 all.setSelected(true);
791 alphaHelix.setSelected(true);
792 betaStrand.setSelected(true);
793 turn.setSelected(true);
800 public class SearchPanel extends JPanel
802 private AnnotationColumnChooser aColChooser;
804 private JCheckBox displayName = new JCheckBox();
806 private JCheckBox description = new JCheckBox();
808 private JTextField searchBox = new JTextField(10);
810 public SearchPanel(AnnotationColumnChooser aColChooser)
813 this.aColChooser = aColChooser;
814 JvSwingUtils.jvInitComponent(this);
815 this.setBorder(new TitledBorder(MessageManager
816 .getString("label.search_filter")));
818 JvSwingUtils.jvInitComponent(searchBox);
819 searchBox.setToolTipText(MessageManager
820 .getString("info.enter_search_text_here"));
821 searchBox.getDocument().addDocumentListener(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.formatMessage(
910 "info.search_in_annotation_label", annotations
911 .getSelectedItem().toString());
912 String descTtip = MessageManager.formatMessage(
913 "info.search_in_annotation_description", annotations
914 .getSelectedItem().toString());
915 displayName.setToolTipText(displayName.isEnabled() ? labelTtip
917 description.setToolTipText(description.isEnabled() ? descTtip