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.HiddenColumns;
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 HiddenColumns oldHiddenColumns;
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 setOldHiddenColumns(av.getAlignment().getHiddenColumns());
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.getOldHiddenColumns() != null)
236 av.getColumnSelection().clear();
238 if (av.getAnnotationColumnSelectionState() != null)
240 HiddenColumns oldHidden = av
241 .getAnnotationColumnSelectionState()
242 .getOldHiddenColumns();
243 if (oldHidden != null && oldHidden.getListOfCols() != null
244 && !oldHidden.getListOfCols().isEmpty())
246 for (Iterator<int[]> itr = oldHidden.getListOfCols()
247 .iterator(); itr.hasNext();)
249 int positions[] = itr.next();
250 av.hideColumns(positions[0], positions[1]);
253 av.getAlignment().setHiddenColumns(oldHidden);
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 setThresholdValueText();
323 slider.setMajorTickSpacing((int) (range / 10f));
324 slider.setEnabled(true);
325 thresholdValue.setEnabled(true);
328 // build filter params
330 .setThresholdType(AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);
331 if (getCurrentAnnotation().graph != AlignmentAnnotation.NO_GRAPH)
334 .setThresholdValue(getCurrentAnnotation().threshold.value);
336 if (selectedThresholdItem == AnnotationColourGradient.ABOVE_THRESHOLD)
339 .setThresholdType(AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD);
341 else if (selectedThresholdItem == AnnotationColourGradient.BELOW_THRESHOLD)
344 .setThresholdType(AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD);
349 updateThresholdPanelToolTip();
350 if (currentStructureFilterPanel != null)
352 if (currentStructureFilterPanel.alphaHelix.isSelected())
354 filterParams.setFilterAlphaHelix(true);
356 if (currentStructureFilterPanel.betaStrand.isSelected())
358 filterParams.setFilterBetaSheet(true);
360 if (currentStructureFilterPanel.turn.isSelected())
362 filterParams.setFilterTurn(true);
366 if (currentSearchPanel != null)
369 if (!currentSearchPanel.searchBox.getText().isEmpty())
371 currentSearchPanel.description.setEnabled(true);
372 currentSearchPanel.displayName.setEnabled(true);
373 filterParams.setRegexString(currentSearchPanel.searchBox.getText());
374 if (currentSearchPanel.displayName.isSelected())
377 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING);
379 if (currentSearchPanel.description.isSelected())
382 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION);
387 currentSearchPanel.description.setEnabled(false);
388 currentSearchPanel.displayName.setEnabled(false);
392 av.getColumnSelection().filterAnnotations(
393 getCurrentAnnotation().annotations, filterParams);
395 av.showAllHiddenColumns();
396 if (getActionOption() == ACTION_OPTION_HIDE)
398 av.hideSelectedColumns();
402 av.setAnnotationColumnSelectionState(this);
403 ap.paintAlignment(true);
406 public HiddenColumns getOldHiddenColumns()
408 return oldHiddenColumns;
411 public void setOldHiddenColumns(HiddenColumns currentHiddenColumns)
413 if (currentHiddenColumns != null)
415 this.oldHiddenColumns = new HiddenColumns(currentHiddenColumns);
419 public FurtherActionPanel getCurrentFutherActionPanel()
421 return currentFurtherActionPanel;
424 public void setCurrentFutherActionPanel(
425 FurtherActionPanel currentFutherActionPanel)
427 this.currentFurtherActionPanel = currentFutherActionPanel;
430 public SearchPanel getCurrentSearchPanel()
432 return currentSearchPanel;
435 public void setCurrentSearchPanel(SearchPanel currentSearchPanel)
437 this.currentSearchPanel = currentSearchPanel;
440 public int getActionOption()
445 public void setActionOption(int actionOption)
447 this.actionOption = actionOption;
450 public StructureFilterPanel getCurrentStructureFilterPanel()
452 return currentStructureFilterPanel;
455 public void setCurrentStructureFilterPanel(
456 StructureFilterPanel currentStructureFilterPanel)
458 this.currentStructureFilterPanel = currentStructureFilterPanel;
461 public void select_action(ActionEvent actionEvent)
463 JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
464 if (radioButton.isSelected())
466 setActionOption(ACTION_OPTION_SELECT);
471 public void hide_action(ActionEvent actionEvent)
473 JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
474 if (radioButton.isSelected())
476 setActionOption(ACTION_OPTION_HIDE);
482 public void itemStateChanged(ItemEvent e)
484 selectedAnnotationChanged();
488 public void selectedAnnotationChanged()
490 String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
491 if (av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
492 .getSelectedIndex()]].graph != AlignmentAnnotation.NO_GRAPH)
494 currentView = AnnotationColumnChooser.GRAPH_VIEW;
497 gSearchPanel.syncState();
498 gFurtherActionPanel.syncState();
499 gStructureFilterPanel.syncState();
501 ngSearchPanel.syncState();
502 ngFurtherActionPanel.syncState();
503 ngStructureFilterPanel.syncState();
505 CardLayout switchableViewsLayout = (CardLayout) switchableViewsPanel
507 switchableViewsLayout.show(switchableViewsPanel, currentView);
511 public class FurtherActionPanel extends JPanel
513 private AnnotationColumnChooser aColChooser;
515 private JRadioButton hideOption = new JRadioButton();
517 private JRadioButton selectOption = new JRadioButton();
519 private ButtonGroup optionsGroup = new ButtonGroup();
521 public FurtherActionPanel(AnnotationColumnChooser aColChooser)
523 this.aColChooser = aColChooser;
524 JvSwingUtils.jvInitComponent(selectOption, "action.select");
525 selectOption.addActionListener(new ActionListener()
528 public void actionPerformed(ActionEvent actionEvent)
530 selectRadioAction(actionEvent);
534 JvSwingUtils.jvInitComponent(hideOption, "action.hide");
535 hideOption.addActionListener(new ActionListener()
538 public void actionPerformed(ActionEvent actionEvent)
540 hideRadioAction(actionEvent);
544 optionsGroup.add(selectOption);
545 optionsGroup.add(hideOption);
546 optionsGroup.setSelected(selectOption.getModel(), true);
548 JvSwingUtils.jvInitComponent(this);
551 this.add(selectOption);
552 this.add(hideOption);
555 public void selectRadioAction(ActionEvent actionEvent)
557 aColChooser.setCurrentFutherActionPanel(this);
558 aColChooser.select_action(actionEvent);
561 public void hideRadioAction(ActionEvent actionEvent)
563 aColChooser.setCurrentFutherActionPanel(this);
564 aColChooser.hide_action(actionEvent);
567 public void syncState()
569 if (aColChooser.getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
571 this.optionsGroup.setSelected(this.hideOption.getModel(), true);
575 this.optionsGroup.setSelected(this.selectOption.getModel(), true);
580 public class StructureFilterPanel extends JPanel
582 private AnnotationColumnChooser aColChooser;
584 private JCheckBox alphaHelix = new JCheckBox();
586 private JCheckBox betaStrand = new JCheckBox();
588 private JCheckBox turn = new JCheckBox();
590 private JCheckBox all = new JCheckBox();
592 public StructureFilterPanel(AnnotationColumnChooser aColChooser)
594 this.aColChooser = aColChooser;
596 JvSwingUtils.jvInitComponent(alphaHelix, "label.alpha_helix");
597 alphaHelix.addActionListener(new ActionListener()
600 public void actionPerformed(ActionEvent actionEvent)
602 alphaHelix_actionPerformed();
606 JvSwingUtils.jvInitComponent(betaStrand, "label.beta_strand");
607 betaStrand.addActionListener(new ActionListener()
610 public void actionPerformed(ActionEvent actionEvent)
612 betaStrand_actionPerformed();
616 JvSwingUtils.jvInitComponent(turn, "label.turn");
617 turn.addActionListener(new ActionListener()
620 public void actionPerformed(ActionEvent actionEvent)
622 turn_actionPerformed();
626 JvSwingUtils.jvInitComponent(all, "label.select_all");
627 all.addActionListener(new ActionListener()
630 public void actionPerformed(ActionEvent actionEvent)
632 all_actionPerformed();
636 this.setBorder(new TitledBorder(MessageManager
637 .getString("label.structures_filter")));
638 JvSwingUtils.jvInitComponent(this);
641 this.add(alphaHelix);
642 this.add(betaStrand);
646 public void alphaHelix_actionPerformed()
648 updateSelectAllState();
649 aColChooser.setCurrentStructureFilterPanel(this);
650 aColChooser.updateView();
653 public void betaStrand_actionPerformed()
655 updateSelectAllState();
656 aColChooser.setCurrentStructureFilterPanel(this);
657 aColChooser.updateView();
660 public void turn_actionPerformed()
662 updateSelectAllState();
663 aColChooser.setCurrentStructureFilterPanel(this);
664 aColChooser.updateView();
667 public void all_actionPerformed()
669 if (all.isSelected())
671 alphaHelix.setSelected(true);
672 betaStrand.setSelected(true);
673 turn.setSelected(true);
677 alphaHelix.setSelected(false);
678 betaStrand.setSelected(false);
679 turn.setSelected(false);
681 aColChooser.setCurrentStructureFilterPanel(this);
682 aColChooser.updateView();
685 public void updateSelectAllState()
687 if (alphaHelix.isSelected() && betaStrand.isSelected()
688 && turn.isSelected())
690 all.setSelected(true);
694 all.setSelected(false);
698 public void syncState()
700 StructureFilterPanel sfp = aColChooser
701 .getCurrentStructureFilterPanel();
704 alphaHelix.setSelected(sfp.alphaHelix.isSelected());
705 betaStrand.setSelected(sfp.betaStrand.isSelected());
706 turn.setSelected(sfp.turn.isSelected());
707 if (sfp.all.isSelected())
709 all.setSelected(true);
710 alphaHelix.setSelected(true);
711 betaStrand.setSelected(true);
712 turn.setSelected(true);
719 public class SearchPanel extends JPanel
721 private AnnotationColumnChooser aColChooser;
723 private JCheckBox displayName = new JCheckBox();
725 private JCheckBox description = new JCheckBox();
727 private JTextField searchBox = new JTextField(10);
729 public SearchPanel(AnnotationColumnChooser aColChooser)
732 this.aColChooser = aColChooser;
733 JvSwingUtils.jvInitComponent(this);
734 this.setBorder(new TitledBorder(MessageManager
735 .getString("label.search_filter")));
737 JvSwingUtils.jvInitComponent(searchBox);
738 searchBox.setToolTipText(MessageManager
739 .getString("info.enter_search_text_here"));
740 searchBox.getDocument().addDocumentListener(new DocumentListener()
743 public void insertUpdate(DocumentEvent e)
745 searchStringAction();
749 public void removeUpdate(DocumentEvent e)
751 searchStringAction();
755 public void changedUpdate(DocumentEvent e)
757 searchStringAction();
761 JvSwingUtils.jvInitComponent(displayName, "label.label");
762 displayName.setEnabled(false);
763 displayName.addActionListener(new ActionListener()
766 public void actionPerformed(ActionEvent actionEvent)
768 displayNameCheckboxAction();
772 JvSwingUtils.jvInitComponent(description, "label.description");
773 description.setEnabled(false);
774 description.addActionListener(new ActionListener()
777 public void actionPerformed(ActionEvent actionEvent)
779 discriptionCheckboxAction();
785 this.add(displayName);
786 this.add(description);
789 public void displayNameCheckboxAction()
791 aColChooser.setCurrentSearchPanel(this);
792 aColChooser.updateView();
795 public void discriptionCheckboxAction()
797 aColChooser.setCurrentSearchPanel(this);
798 aColChooser.updateView();
801 public void searchStringAction()
803 aColChooser.setCurrentSearchPanel(this);
804 aColChooser.updateView();
805 updateSearchPanelToolTips();
808 public void syncState()
810 SearchPanel sp = aColChooser.getCurrentSearchPanel();
813 description.setEnabled(sp.description.isEnabled());
814 description.setSelected(sp.description.isSelected());
816 displayName.setEnabled(sp.displayName.isEnabled());
817 displayName.setSelected(sp.displayName.isSelected());
819 searchBox.setText(sp.searchBox.getText());
821 updateSearchPanelToolTips();
824 public void updateSearchPanelToolTips()
826 String defaultTtip = MessageManager
827 .getString("info.enter_search_text_to_enable");
828 String labelTtip = MessageManager.formatMessage(
829 "info.search_in_annotation_label", annotations
830 .getSelectedItem().toString());
831 String descTtip = MessageManager.formatMessage(
832 "info.search_in_annotation_description", annotations
833 .getSelectedItem().toString());
834 displayName.setToolTipText(displayName.isEnabled() ? labelTtip
836 description.setToolTipText(description.isEnabled() ? descTtip