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);
113 AnnotationColumnChooser lastChooser = av
114 .getAnnotationColumnSelectionState();
115 // restore Object state from the previous session if one exists
116 if (lastChooser != null)
118 currentSearchPanel = lastChooser
119 .getCurrentSearchPanel();
120 currentStructureFilterPanel = lastChooser
121 .getCurrentStructureFilterPanel();
122 annotations.setSelectedIndex(lastChooser
123 .getAnnotations().getSelectedIndex());
124 threshold.setSelectedIndex(lastChooser
125 .getThreshold().getSelectedIndex());
126 actionOption = lastChooser
128 percentThreshold.setSelected(lastChooser.percentThreshold
135 } catch (Exception ex)
146 protected void jbInit()
150 JPanel thresholdPanel = new JPanel();
151 thresholdPanel.setBorder(new TitledBorder(MessageManager
152 .getString("label.threshold_filter")));
153 thresholdPanel.setBackground(Color.white);
154 thresholdPanel.setFont(JvSwingUtils.getLabelFont());
155 thresholdPanel.setLayout(new MigLayout("", "[left][right]", "[][]"));
157 percentThreshold.setBackground(Color.white);
158 percentThreshold.setFont(JvSwingUtils.getLabelFont());
160 JPanel actionPanel = new JPanel();
161 actionPanel.setBackground(Color.white);
162 actionPanel.setFont(JvSwingUtils.getLabelFont());
164 JPanel graphFilterView = new JPanel();
165 graphFilterView.setLayout(new MigLayout("", "[left][right]", "[][]"));
166 graphFilterView.setBackground(Color.white);
168 JPanel noGraphFilterView = new JPanel();
169 noGraphFilterView.setLayout(new MigLayout("", "[left][right]", "[][]"));
170 noGraphFilterView.setBackground(Color.white);
172 annotationComboBoxPanel.setBackground(Color.white);
173 annotationComboBoxPanel.setFont(JvSwingUtils.getLabelFont());
175 gSearchPanel = new SearchPanel(this);
176 ngSearchPanel = new SearchPanel(this);
177 gFurtherActionPanel = new FurtherActionPanel(this);
178 ngFurtherActionPanel = new FurtherActionPanel(this);
179 gStructureFilterPanel = new StructureFilterPanel(this);
180 ngStructureFilterPanel = new StructureFilterPanel(this);
182 thresholdPanel.add(getThreshold());
183 thresholdPanel.add(percentThreshold, "wrap");
184 thresholdPanel.add(slider, "grow");
185 thresholdPanel.add(thresholdValue, "span, wrap");
188 actionPanel.add(cancel);
190 graphFilterView.add(gSearchPanel, "grow, span, wrap");
191 graphFilterView.add(gStructureFilterPanel, "grow, span, wrap");
192 graphFilterView.add(thresholdPanel, "grow, span, wrap");
193 graphFilterView.add(gFurtherActionPanel);
195 noGraphFilterView.add(ngSearchPanel, "grow, span, wrap");
196 noGraphFilterView.add(ngStructureFilterPanel, "grow, span, wrap");
197 noGraphFilterView.add(ngFurtherActionPanel);
199 annotationComboBoxPanel.add(getAnnotations());
200 switchableViewsPanel.add(noGraphFilterView,
201 AnnotationColumnChooser.NO_GRAPH_VIEW);
202 switchableViewsPanel.add(graphFilterView,
203 AnnotationColumnChooser.GRAPH_VIEW);
205 this.setLayout(new BorderLayout());
206 this.add(annotationComboBoxPanel, java.awt.BorderLayout.PAGE_START);
207 this.add(switchableViewsPanel, java.awt.BorderLayout.CENTER);
208 this.add(actionPanel, java.awt.BorderLayout.SOUTH);
210 selectedAnnotationChanged();
211 updateThresholdPanelToolTip();
215 protected void updateThresholdPanelToolTip()
217 thresholdValue.setToolTipText("");
218 slider.setToolTipText("");
220 String defaultTtip = MessageManager
221 .getString("info.change_threshold_mode_to_enable");
223 String thresh = getThreshold().getSelectedItem().toString();
224 if (thresh.equalsIgnoreCase("No Threshold"))
226 thresholdValue.setToolTipText(defaultTtip);
227 slider.setToolTipText(defaultTtip);
232 protected void reset()
234 if (this.getOldColumnSelection() != null)
236 av.getColumnSelection().clear();
238 if (av.getAnnotationColumnSelectionState() != null)
240 ColumnSelection oldSelection = av
241 .getAnnotationColumnSelectionState()
242 .getOldColumnSelection();
243 if (oldSelection != null && oldSelection.getHiddenColumns() != null
244 && !oldSelection.getHiddenColumns().isEmpty())
246 for (Iterator<int[]> itr = oldSelection.getHiddenColumns()
247 .iterator(); itr.hasNext();)
249 int positions[] = itr.next();
250 av.hideColumns(positions[0], positions[1]);
253 av.setColumnSelection(oldSelection);
255 ap.paintAlignment(true);
261 public void valueChanged(boolean updateAllAnnotation)
263 if (slider.isEnabled())
265 getCurrentAnnotation().threshold.value = slider.getValue() / 1000f;
267 propagateSeqAssociatedThreshold(updateAllAnnotation,
268 getCurrentAnnotation());
269 ap.paintAlignment(false);
274 public void updateView()
276 // Check if combobox is still adjusting
282 AnnotationFilterParameter filterParams = new AnnotationFilterParameter();
284 setCurrentAnnotation(av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
285 .getSelectedIndex()]]);
287 int selectedThresholdItem = getSelectedThresholdItem(getThreshold()
288 .getSelectedIndex());
290 slider.setEnabled(true);
291 thresholdValue.setEnabled(true);
292 percentThreshold.setEnabled(true);
294 if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
296 slider.setEnabled(false);
297 thresholdValue.setEnabled(false);
298 thresholdValue.setText("");
299 percentThreshold.setEnabled(false);
300 // build filter params
302 else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
304 if (getCurrentAnnotation().threshold == null)
306 getCurrentAnnotation()
308 new jalview.datamodel.GraphLine(
309 (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin) / 2f,
310 "Threshold", Color.black));
314 float range = getCurrentAnnotation().graphMax * 1000
315 - getCurrentAnnotation().graphMin * 1000;
317 slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
318 slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
319 slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000));
321 if (percentThreshold.isSelected())
325 + ((getCurrentAnnotation().threshold.value - getCurrentAnnotation().graphMin) * 100f / (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin)));
329 thresholdValue.setText(getCurrentAnnotation().threshold.value + "");
332 slider.setMajorTickSpacing((int) (range / 10f));
333 slider.setEnabled(true);
334 thresholdValue.setEnabled(true);
337 // build filter params
339 .setThresholdType(AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);
340 if (getCurrentAnnotation().graph != AlignmentAnnotation.NO_GRAPH)
343 .setThresholdValue(getCurrentAnnotation().threshold.value);
345 if (selectedThresholdItem == AnnotationColourGradient.ABOVE_THRESHOLD)
348 .setThresholdType(AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD);
350 else if (selectedThresholdItem == AnnotationColourGradient.BELOW_THRESHOLD)
353 .setThresholdType(AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD);
358 updateThresholdPanelToolTip();
359 if (currentStructureFilterPanel != null)
361 if (currentStructureFilterPanel.alphaHelix.isSelected())
363 filterParams.setFilterAlphaHelix(true);
365 if (currentStructureFilterPanel.betaStrand.isSelected())
367 filterParams.setFilterBetaSheet(true);
369 if (currentStructureFilterPanel.turn.isSelected())
371 filterParams.setFilterTurn(true);
375 if (currentSearchPanel != null)
378 if (!currentSearchPanel.searchBox.getText().isEmpty())
380 currentSearchPanel.description.setEnabled(true);
381 currentSearchPanel.displayName.setEnabled(true);
382 filterParams.setRegexString(currentSearchPanel.searchBox.getText());
383 if (currentSearchPanel.displayName.isSelected())
386 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING);
388 if (currentSearchPanel.description.isSelected())
391 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION);
396 currentSearchPanel.description.setEnabled(false);
397 currentSearchPanel.displayName.setEnabled(false);
401 av.getColumnSelection().filterAnnotations(
402 getCurrentAnnotation().annotations, filterParams);
404 av.showAllHiddenColumns();
405 if (getActionOption() == ACTION_OPTION_HIDE)
407 av.hideSelectedColumns();
411 av.setAnnotationColumnSelectionState(this);
412 ap.paintAlignment(true);
416 public ColumnSelection getOldColumnSelection()
418 return oldColumnSelection;
421 public void setOldColumnSelection(ColumnSelection currentColumnSelection)
423 if (currentColumnSelection != null)
425 this.oldColumnSelection = new ColumnSelection(currentColumnSelection);
429 public FurtherActionPanel getCurrentFutherActionPanel()
431 return currentFurtherActionPanel;
434 public void setCurrentFutherActionPanel(
435 FurtherActionPanel currentFutherActionPanel)
437 this.currentFurtherActionPanel = currentFutherActionPanel;
440 public SearchPanel getCurrentSearchPanel()
442 return currentSearchPanel;
445 public void setCurrentSearchPanel(SearchPanel currentSearchPanel)
447 this.currentSearchPanel = currentSearchPanel;
450 public int getActionOption()
455 public void setActionOption(int actionOption)
457 this.actionOption = actionOption;
460 public StructureFilterPanel getCurrentStructureFilterPanel()
462 return currentStructureFilterPanel;
465 public void setCurrentStructureFilterPanel(
466 StructureFilterPanel currentStructureFilterPanel)
468 this.currentStructureFilterPanel = currentStructureFilterPanel;
471 public void select_action(ActionEvent actionEvent)
473 JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
474 if (radioButton.isSelected())
476 setActionOption(ACTION_OPTION_SELECT);
481 public void hide_action(ActionEvent actionEvent)
483 JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
484 if (radioButton.isSelected())
486 setActionOption(ACTION_OPTION_HIDE);
492 public void itemStateChanged(ItemEvent e)
494 selectedAnnotationChanged();
498 public void selectedAnnotationChanged()
500 String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
501 if (av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
502 .getSelectedIndex()]].graph != AlignmentAnnotation.NO_GRAPH)
504 currentView = AnnotationColumnChooser.GRAPH_VIEW;
507 gSearchPanel.syncState();
508 gFurtherActionPanel.syncState();
509 gStructureFilterPanel.syncState();
511 ngSearchPanel.syncState();
512 ngFurtherActionPanel.syncState();
513 ngStructureFilterPanel.syncState();
515 CardLayout switchableViewsLayout = (CardLayout) switchableViewsPanel
517 switchableViewsLayout.show(switchableViewsPanel, currentView);
521 public class FurtherActionPanel extends JPanel
523 private AnnotationColumnChooser aColChooser;
525 private JRadioButton hideOption = new JRadioButton();
527 private JRadioButton selectOption = new JRadioButton();
529 private ButtonGroup optionsGroup = new ButtonGroup();
531 public FurtherActionPanel(AnnotationColumnChooser aColChooser)
533 this.aColChooser = aColChooser;
534 JvSwingUtils.jvInitComponent(selectOption, "action.select");
535 selectOption.addActionListener(new ActionListener()
538 public void actionPerformed(ActionEvent actionEvent)
540 selectRadioAction(actionEvent);
544 JvSwingUtils.jvInitComponent(hideOption, "action.hide");
545 hideOption.addActionListener(new ActionListener()
548 public void actionPerformed(ActionEvent actionEvent)
550 hideRadioAction(actionEvent);
554 optionsGroup.add(selectOption);
555 optionsGroup.add(hideOption);
556 optionsGroup.setSelected(selectOption.getModel(), true);
558 JvSwingUtils.jvInitComponent(this);
561 this.add(selectOption);
562 this.add(hideOption);
565 public void selectRadioAction(ActionEvent actionEvent)
567 aColChooser.setCurrentFutherActionPanel(this);
568 aColChooser.select_action(actionEvent);
571 public void hideRadioAction(ActionEvent actionEvent)
573 aColChooser.setCurrentFutherActionPanel(this);
574 aColChooser.hide_action(actionEvent);
577 public void syncState()
579 if (aColChooser.getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
581 this.optionsGroup.setSelected(this.hideOption.getModel(), true);
585 this.optionsGroup.setSelected(this.selectOption.getModel(), true);
590 public class StructureFilterPanel extends JPanel
592 private AnnotationColumnChooser aColChooser;
594 private JCheckBox alphaHelix = new JCheckBox();
596 private JCheckBox betaStrand = new JCheckBox();
598 private JCheckBox turn = new JCheckBox();
600 private JCheckBox all = new JCheckBox();
602 public StructureFilterPanel(AnnotationColumnChooser aColChooser)
604 this.aColChooser = aColChooser;
606 JvSwingUtils.jvInitComponent(alphaHelix, "label.alpha_helix");
607 alphaHelix.addActionListener(new ActionListener()
610 public void actionPerformed(ActionEvent actionEvent)
612 alphaHelix_actionPerformed();
616 JvSwingUtils.jvInitComponent(betaStrand, "label.beta_strand");
617 betaStrand.addActionListener(new ActionListener()
620 public void actionPerformed(ActionEvent actionEvent)
622 betaStrand_actionPerformed();
626 JvSwingUtils.jvInitComponent(turn, "label.turn");
627 turn.addActionListener(new ActionListener()
630 public void actionPerformed(ActionEvent actionEvent)
632 turn_actionPerformed();
636 JvSwingUtils.jvInitComponent(all, "label.select_all");
637 all.addActionListener(new ActionListener()
640 public void actionPerformed(ActionEvent actionEvent)
642 all_actionPerformed();
646 this.setBorder(new TitledBorder(MessageManager
647 .getString("label.structures_filter")));
648 JvSwingUtils.jvInitComponent(this);
651 this.add(alphaHelix);
652 this.add(betaStrand);
656 public void alphaHelix_actionPerformed()
658 updateSelectAllState();
659 aColChooser.setCurrentStructureFilterPanel(this);
660 aColChooser.updateView();
663 public void betaStrand_actionPerformed()
665 updateSelectAllState();
666 aColChooser.setCurrentStructureFilterPanel(this);
667 aColChooser.updateView();
670 public void turn_actionPerformed()
672 updateSelectAllState();
673 aColChooser.setCurrentStructureFilterPanel(this);
674 aColChooser.updateView();
677 public void all_actionPerformed()
679 if (all.isSelected())
681 alphaHelix.setSelected(true);
682 betaStrand.setSelected(true);
683 turn.setSelected(true);
687 alphaHelix.setSelected(false);
688 betaStrand.setSelected(false);
689 turn.setSelected(false);
691 aColChooser.setCurrentStructureFilterPanel(this);
692 aColChooser.updateView();
695 public void updateSelectAllState()
697 if (alphaHelix.isSelected() && betaStrand.isSelected()
698 && turn.isSelected())
700 all.setSelected(true);
704 all.setSelected(false);
708 public void syncState()
710 StructureFilterPanel sfp = aColChooser
711 .getCurrentStructureFilterPanel();
714 alphaHelix.setSelected(sfp.alphaHelix.isSelected());
715 betaStrand.setSelected(sfp.betaStrand.isSelected());
716 turn.setSelected(sfp.turn.isSelected());
717 if (sfp.all.isSelected())
719 all.setSelected(true);
720 alphaHelix.setSelected(true);
721 betaStrand.setSelected(true);
722 turn.setSelected(true);
729 public class SearchPanel extends JPanel
731 private AnnotationColumnChooser aColChooser;
733 private JCheckBox displayName = new JCheckBox();
735 private JCheckBox description = new JCheckBox();
737 private JTextField searchBox = new JTextField(10);
739 public SearchPanel(AnnotationColumnChooser aColChooser)
742 this.aColChooser = aColChooser;
743 JvSwingUtils.jvInitComponent(this);
744 this.setBorder(new TitledBorder(MessageManager
745 .getString("label.search_filter")));
747 JvSwingUtils.jvInitComponent(searchBox);
748 searchBox.setToolTipText(MessageManager
749 .getString("info.enter_search_text_here"));
750 searchBox.getDocument().addDocumentListener(new DocumentListener()
753 public void insertUpdate(DocumentEvent e)
755 searchStringAction();
759 public void removeUpdate(DocumentEvent e)
761 searchStringAction();
765 public void changedUpdate(DocumentEvent e)
767 searchStringAction();
771 JvSwingUtils.jvInitComponent(displayName, "label.label");
772 displayName.setEnabled(false);
773 displayName.addActionListener(new ActionListener()
776 public void actionPerformed(ActionEvent actionEvent)
778 displayNameCheckboxAction();
782 JvSwingUtils.jvInitComponent(description, "label.description");
783 description.setEnabled(false);
784 description.addActionListener(new ActionListener()
787 public void actionPerformed(ActionEvent actionEvent)
789 discriptionCheckboxAction();
795 this.add(displayName);
796 this.add(description);
799 public void displayNameCheckboxAction()
801 aColChooser.setCurrentSearchPanel(this);
802 aColChooser.updateView();
805 public void discriptionCheckboxAction()
807 aColChooser.setCurrentSearchPanel(this);
808 aColChooser.updateView();
811 public void searchStringAction()
813 aColChooser.setCurrentSearchPanel(this);
814 aColChooser.updateView();
815 updateSearchPanelToolTips();
818 public void syncState()
820 SearchPanel sp = aColChooser.getCurrentSearchPanel();
823 description.setEnabled(sp.description.isEnabled());
824 description.setSelected(sp.description.isSelected());
826 displayName.setEnabled(sp.displayName.isEnabled());
827 displayName.setSelected(sp.displayName.isSelected());
829 searchBox.setText(sp.searchBox.getText());
831 updateSearchPanelToolTips();
834 public void updateSearchPanelToolTips()
836 String defaultTtip = MessageManager
837 .getString("info.enter_search_text_to_enable");
838 String labelTtip = MessageManager.formatMessage(
839 "info.search_in_annotation_label", annotations
840 .getSelectedItem().toString());
841 String descTtip = MessageManager.formatMessage(
842 "info.search_in_annotation_description", annotations
843 .getSelectedItem().toString());
844 displayName.setToolTipText(displayName.isEnabled() ? labelTtip
846 description.setToolTipText(description.isEnabled() ? descTtip