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 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);
407 public ColumnSelection getOldColumnSelection()
409 return oldColumnSelection;
412 public void setOldColumnSelection(ColumnSelection currentColumnSelection)
414 if (currentColumnSelection != null)
416 this.oldColumnSelection = new ColumnSelection(currentColumnSelection);
420 public FurtherActionPanel getCurrentFutherActionPanel()
422 return currentFurtherActionPanel;
425 public void setCurrentFutherActionPanel(
426 FurtherActionPanel currentFutherActionPanel)
428 this.currentFurtherActionPanel = currentFutherActionPanel;
431 public SearchPanel getCurrentSearchPanel()
433 return currentSearchPanel;
436 public void setCurrentSearchPanel(SearchPanel currentSearchPanel)
438 this.currentSearchPanel = currentSearchPanel;
441 public int getActionOption()
446 public void setActionOption(int actionOption)
448 this.actionOption = actionOption;
451 public StructureFilterPanel getCurrentStructureFilterPanel()
453 return currentStructureFilterPanel;
456 public void setCurrentStructureFilterPanel(
457 StructureFilterPanel currentStructureFilterPanel)
459 this.currentStructureFilterPanel = currentStructureFilterPanel;
462 public void select_action(ActionEvent actionEvent)
464 JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
465 if (radioButton.isSelected())
467 setActionOption(ACTION_OPTION_SELECT);
472 public void hide_action(ActionEvent actionEvent)
474 JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
475 if (radioButton.isSelected())
477 setActionOption(ACTION_OPTION_HIDE);
483 public void itemStateChanged(ItemEvent e)
485 selectedAnnotationChanged();
489 public void selectedAnnotationChanged()
491 String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
492 if (av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
493 .getSelectedIndex()]].graph != AlignmentAnnotation.NO_GRAPH)
495 currentView = AnnotationColumnChooser.GRAPH_VIEW;
498 gSearchPanel.syncState();
499 gFurtherActionPanel.syncState();
500 gStructureFilterPanel.syncState();
502 ngSearchPanel.syncState();
503 ngFurtherActionPanel.syncState();
504 ngStructureFilterPanel.syncState();
506 CardLayout switchableViewsLayout = (CardLayout) switchableViewsPanel
508 switchableViewsLayout.show(switchableViewsPanel, currentView);
512 public class FurtherActionPanel extends JPanel
514 private AnnotationColumnChooser aColChooser;
516 private JRadioButton hideOption = new JRadioButton();
518 private JRadioButton selectOption = new JRadioButton();
520 private ButtonGroup optionsGroup = new ButtonGroup();
522 public FurtherActionPanel(AnnotationColumnChooser aColChooser)
524 this.aColChooser = aColChooser;
525 JvSwingUtils.jvInitComponent(selectOption, "action.select");
526 selectOption.addActionListener(new ActionListener()
529 public void actionPerformed(ActionEvent actionEvent)
531 selectRadioAction(actionEvent);
535 JvSwingUtils.jvInitComponent(hideOption, "action.hide");
536 hideOption.addActionListener(new ActionListener()
539 public void actionPerformed(ActionEvent actionEvent)
541 hideRadioAction(actionEvent);
545 optionsGroup.add(selectOption);
546 optionsGroup.add(hideOption);
547 optionsGroup.setSelected(selectOption.getModel(), true);
549 JvSwingUtils.jvInitComponent(this);
552 this.add(selectOption);
553 this.add(hideOption);
556 public void selectRadioAction(ActionEvent actionEvent)
558 aColChooser.setCurrentFutherActionPanel(this);
559 aColChooser.select_action(actionEvent);
562 public void hideRadioAction(ActionEvent actionEvent)
564 aColChooser.setCurrentFutherActionPanel(this);
565 aColChooser.hide_action(actionEvent);
568 public void syncState()
570 if (aColChooser.getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
572 this.optionsGroup.setSelected(this.hideOption.getModel(), true);
576 this.optionsGroup.setSelected(this.selectOption.getModel(), true);
581 public class StructureFilterPanel extends JPanel
583 private AnnotationColumnChooser aColChooser;
585 private JCheckBox alphaHelix = new JCheckBox();
587 private JCheckBox betaStrand = new JCheckBox();
589 private JCheckBox turn = new JCheckBox();
591 private JCheckBox all = new JCheckBox();
593 public StructureFilterPanel(AnnotationColumnChooser aColChooser)
595 this.aColChooser = aColChooser;
597 JvSwingUtils.jvInitComponent(alphaHelix, "label.alpha_helix");
598 alphaHelix.addActionListener(new ActionListener()
601 public void actionPerformed(ActionEvent actionEvent)
603 alphaHelix_actionPerformed();
607 JvSwingUtils.jvInitComponent(betaStrand, "label.beta_strand");
608 betaStrand.addActionListener(new ActionListener()
611 public void actionPerformed(ActionEvent actionEvent)
613 betaStrand_actionPerformed();
617 JvSwingUtils.jvInitComponent(turn, "label.turn");
618 turn.addActionListener(new ActionListener()
621 public void actionPerformed(ActionEvent actionEvent)
623 turn_actionPerformed();
627 JvSwingUtils.jvInitComponent(all, "label.select_all");
628 all.addActionListener(new ActionListener()
631 public void actionPerformed(ActionEvent actionEvent)
633 all_actionPerformed();
637 this.setBorder(new TitledBorder(MessageManager
638 .getString("label.structures_filter")));
639 JvSwingUtils.jvInitComponent(this);
642 this.add(alphaHelix);
643 this.add(betaStrand);
647 public void alphaHelix_actionPerformed()
649 updateSelectAllState();
650 aColChooser.setCurrentStructureFilterPanel(this);
651 aColChooser.updateView();
654 public void betaStrand_actionPerformed()
656 updateSelectAllState();
657 aColChooser.setCurrentStructureFilterPanel(this);
658 aColChooser.updateView();
661 public void turn_actionPerformed()
663 updateSelectAllState();
664 aColChooser.setCurrentStructureFilterPanel(this);
665 aColChooser.updateView();
668 public void all_actionPerformed()
670 if (all.isSelected())
672 alphaHelix.setSelected(true);
673 betaStrand.setSelected(true);
674 turn.setSelected(true);
678 alphaHelix.setSelected(false);
679 betaStrand.setSelected(false);
680 turn.setSelected(false);
682 aColChooser.setCurrentStructureFilterPanel(this);
683 aColChooser.updateView();
686 public void updateSelectAllState()
688 if (alphaHelix.isSelected() && betaStrand.isSelected()
689 && turn.isSelected())
691 all.setSelected(true);
695 all.setSelected(false);
699 public void syncState()
701 StructureFilterPanel sfp = aColChooser
702 .getCurrentStructureFilterPanel();
705 alphaHelix.setSelected(sfp.alphaHelix.isSelected());
706 betaStrand.setSelected(sfp.betaStrand.isSelected());
707 turn.setSelected(sfp.turn.isSelected());
708 if (sfp.all.isSelected())
710 all.setSelected(true);
711 alphaHelix.setSelected(true);
712 betaStrand.setSelected(true);
713 turn.setSelected(true);
720 public class SearchPanel extends JPanel
722 private AnnotationColumnChooser aColChooser;
724 private JCheckBox displayName = new JCheckBox();
726 private JCheckBox description = new JCheckBox();
728 private JTextField searchBox = new JTextField(10);
730 public SearchPanel(AnnotationColumnChooser aColChooser)
733 this.aColChooser = aColChooser;
734 JvSwingUtils.jvInitComponent(this);
735 this.setBorder(new TitledBorder(MessageManager
736 .getString("label.search_filter")));
738 JvSwingUtils.jvInitComponent(searchBox);
739 searchBox.setToolTipText(MessageManager
740 .getString("info.enter_search_text_here"));
741 searchBox.getDocument().addDocumentListener(new DocumentListener()
744 public void insertUpdate(DocumentEvent e)
746 searchStringAction();
750 public void removeUpdate(DocumentEvent e)
752 searchStringAction();
756 public void changedUpdate(DocumentEvent e)
758 searchStringAction();
762 JvSwingUtils.jvInitComponent(displayName, "label.label");
763 displayName.setEnabled(false);
764 displayName.addActionListener(new ActionListener()
767 public void actionPerformed(ActionEvent actionEvent)
769 displayNameCheckboxAction();
773 JvSwingUtils.jvInitComponent(description, "label.description");
774 description.setEnabled(false);
775 description.addActionListener(new ActionListener()
778 public void actionPerformed(ActionEvent actionEvent)
780 discriptionCheckboxAction();
786 this.add(displayName);
787 this.add(description);
790 public void displayNameCheckboxAction()
792 aColChooser.setCurrentSearchPanel(this);
793 aColChooser.updateView();
796 public void discriptionCheckboxAction()
798 aColChooser.setCurrentSearchPanel(this);
799 aColChooser.updateView();
802 public void searchStringAction()
804 aColChooser.setCurrentSearchPanel(this);
805 aColChooser.updateView();
806 updateSearchPanelToolTips();
809 public void syncState()
811 SearchPanel sp = aColChooser.getCurrentSearchPanel();
814 description.setEnabled(sp.description.isEnabled());
815 description.setSelected(sp.description.isSelected());
817 displayName.setEnabled(sp.displayName.isEnabled());
818 displayName.setSelected(sp.displayName.isSelected());
820 searchBox.setText(sp.searchBox.getText());
822 updateSearchPanelToolTips();
825 public void updateSearchPanelToolTips()
827 String defaultTtip = MessageManager
828 .getString("info.enter_search_text_to_enable");
829 String labelTtip = MessageManager.formatMessage(
830 "info.search_in_annotation_label", annotations
831 .getSelectedItem().toString());
832 String descTtip = MessageManager.formatMessage(
833 "info.search_in_annotation_description", annotations
834 .getSelectedItem().toString());
835 displayName.setToolTipText(displayName.isEnabled() ? labelTtip
837 description.setToolTipText(description.isEnabled() ? descTtip