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
58 private JPanel switchableViewsPanel = new JPanel(new CardLayout());
60 private JPanel annotationComboBoxPanel = new JPanel();
62 private StructureFilterPanel gStructureFilterPanel;
64 private StructureFilterPanel ngStructureFilterPanel;
66 private StructureFilterPanel currentStructureFilterPanel;
68 private SearchPanel currentSearchPanel;
70 private SearchPanel gSearchPanel;
72 private SearchPanel ngSearchPanel;
74 private FurtherActionPanel currentFurtherActionPanel;
76 private FurtherActionPanel gFurtherActionPanel;
78 private FurtherActionPanel ngFurtherActionPanel;
80 public static final int ACTION_OPTION_SELECT = 1;
82 public static int ACTION_OPTION_HIDE = 2;
84 public static String NO_GRAPH_VIEW = "0";
86 public static String GRAPH_VIEW = "1";
88 private int actionOption = ACTION_OPTION_SELECT;
90 private ColumnSelection oldColumnSelection;
92 protected int MIN_WIDTH = 420;
94 protected int MIN_HEIGHT = 430;
96 public AnnotationColumnChooser(AlignViewport av, final AlignmentPanel ap)
99 frame = new JInternalFrame();
100 frame.setContentPane(this);
101 frame.setLayer(JLayeredPane.PALETTE_LAYER);
102 Desktop.addInternalFrame(frame,
103 MessageManager.getString("label.select_by_annotation"), 520,
105 frame.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT));
107 addSliderChangeListener();
108 addSliderMouseListeners();
110 if (av.getAlignment().getAlignmentAnnotation() == null)
114 setOldColumnSelection(av.getColumnSelection());
117 setAnnotations(new JComboBox<String>(getAnnotationItems(false)));
118 populateThresholdComboBox(threshold);
120 // restore Object state from the previous session if one exists
121 if (av.getAnnotationColumnSelectionState() != null)
123 currentSearchPanel = av.getAnnotationColumnSelectionState()
124 .getCurrentSearchPanel();
125 currentStructureFilterPanel = av.getAnnotationColumnSelectionState()
126 .getCurrentStructureFilterPanel();
127 annotations.setSelectedIndex(av.getAnnotationColumnSelectionState()
128 .getAnnotations().getSelectedIndex());
129 threshold.setSelectedIndex(av.getAnnotationColumnSelectionState()
130 .getThreshold().getSelectedIndex());
131 actionOption = av.getAnnotationColumnSelectionState()
138 } catch (Exception ex)
149 protected void jbInit()
153 JPanel thresholdPanel = new JPanel();
154 thresholdPanel.setBorder(new TitledBorder(MessageManager
155 .getString("label.threshold_filter")));
156 thresholdPanel.setBackground(Color.white);
157 thresholdPanel.setFont(JvSwingUtils.getLabelFont());
158 thresholdPanel.setLayout(new MigLayout("", "[left][right]", "[][]"));
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(thresholdValue, "wrap");
184 thresholdPanel.add(slider, "grow, span, wrap");
187 actionPanel.add(cancel);
189 graphFilterView.add(gSearchPanel, "grow, span, wrap");
190 graphFilterView.add(gStructureFilterPanel, "grow, span, wrap");
191 graphFilterView.add(thresholdPanel, "grow, span, wrap");
192 graphFilterView.add(gFurtherActionPanel);
194 noGraphFilterView.add(ngSearchPanel, "grow, span, wrap");
195 noGraphFilterView.add(ngStructureFilterPanel, "grow, span, wrap");
196 noGraphFilterView.add(ngFurtherActionPanel);
198 annotationComboBoxPanel.add(getAnnotations());
199 switchableViewsPanel.add(noGraphFilterView,
200 AnnotationColumnChooser.NO_GRAPH_VIEW);
201 switchableViewsPanel.add(graphFilterView,
202 AnnotationColumnChooser.GRAPH_VIEW);
204 this.setLayout(new BorderLayout());
205 this.add(annotationComboBoxPanel, java.awt.BorderLayout.PAGE_START);
206 this.add(switchableViewsPanel, java.awt.BorderLayout.CENTER);
207 this.add(actionPanel, java.awt.BorderLayout.SOUTH);
209 selectedAnnotationChanged();
210 updateThresholdPanelToolTip();
214 protected void updateThresholdPanelToolTip()
216 thresholdValue.setToolTipText("");
217 slider.setToolTipText("");
219 String defaultTtip = MessageManager
220 .getString("info.change_threshold_mode_to_enable");
222 String thresh = getThreshold().getSelectedItem().toString();
223 if (thresh.equalsIgnoreCase("No Threshold"))
225 thresholdValue.setToolTipText(defaultTtip);
226 slider.setToolTipText(defaultTtip);
231 protected void reset()
233 if (this.getOldColumnSelection() != null)
235 av.getColumnSelection().clear();
237 if (av.getAnnotationColumnSelectionState() != null)
239 ColumnSelection oldSelection = av
240 .getAnnotationColumnSelectionState()
241 .getOldColumnSelection();
242 if (oldSelection != null && oldSelection.getHiddenColumns() != null
243 && !oldSelection.getHiddenColumns().isEmpty())
245 for (Iterator<int[]> itr = oldSelection.getHiddenColumns()
246 .iterator(); itr.hasNext();)
248 int positions[] = itr.next();
249 av.hideColumns(positions[0], positions[1]);
252 av.setColumnSelection(oldSelection);
254 ap.paintAlignment(true);
260 public void valueChanged(boolean updateAllAnnotation)
262 if (slider.isEnabled())
264 getCurrentAnnotation().threshold.value = slider.getValue() / 1000f;
266 propagateSeqAssociatedThreshold(updateAllAnnotation,
267 getCurrentAnnotation());
268 ap.paintAlignment(false);
273 public void updateView()
275 // Check if combobox is still adjusting
281 AnnotationFilterParameter filterParams = new AnnotationFilterParameter();
283 setCurrentAnnotation(av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
284 .getSelectedIndex()]]);
286 int selectedThresholdItem = getSelectedThresholdItem(getThreshold()
287 .getSelectedIndex());
289 slider.setEnabled(true);
290 thresholdValue.setEnabled(true);
292 if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
294 slider.setEnabled(false);
295 thresholdValue.setEnabled(false);
296 thresholdValue.setText("");
297 // build filter params
299 else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
301 if (getCurrentAnnotation().threshold == null)
303 getCurrentAnnotation()
305 new jalview.datamodel.GraphLine(
306 (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin) / 2f,
307 "Threshold", Color.black));
311 float range = getCurrentAnnotation().graphMax * 1000
312 - getCurrentAnnotation().graphMin * 1000;
314 slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
315 slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
316 slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000));
317 thresholdValue.setText(getCurrentAnnotation().threshold.value + "");
318 slider.setMajorTickSpacing((int) (range / 10f));
319 slider.setEnabled(true);
320 thresholdValue.setEnabled(true);
323 // build filter params
325 .setThresholdType(AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);
326 if (getCurrentAnnotation().graph != AlignmentAnnotation.NO_GRAPH)
329 .setThresholdValue(getCurrentAnnotation().threshold.value);
331 if (selectedThresholdItem == AnnotationColourGradient.ABOVE_THRESHOLD)
334 .setThresholdType(AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD);
336 else if (selectedThresholdItem == AnnotationColourGradient.BELOW_THRESHOLD)
339 .setThresholdType(AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD);
344 updateThresholdPanelToolTip();
345 if (currentStructureFilterPanel != null)
347 if (currentStructureFilterPanel.alphaHelix.isSelected())
349 filterParams.setFilterAlphaHelix(true);
351 if (currentStructureFilterPanel.betaStrand.isSelected())
353 filterParams.setFilterBetaSheet(true);
355 if (currentStructureFilterPanel.turn.isSelected())
357 filterParams.setFilterTurn(true);
361 if (currentSearchPanel != null)
364 if (!currentSearchPanel.searchBox.getText().isEmpty())
366 currentSearchPanel.description.setEnabled(true);
367 currentSearchPanel.displayName.setEnabled(true);
368 filterParams.setRegexString(currentSearchPanel.searchBox.getText());
369 if (currentSearchPanel.displayName.isSelected())
372 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING);
374 if (currentSearchPanel.description.isSelected())
377 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION);
382 currentSearchPanel.description.setEnabled(false);
383 currentSearchPanel.displayName.setEnabled(false);
387 av.getColumnSelection().filterAnnotations(
388 getCurrentAnnotation().annotations, filterParams);
390 av.showAllHiddenColumns();
391 if (getActionOption() == ACTION_OPTION_HIDE)
393 av.hideSelectedColumns();
397 av.setAnnotationColumnSelectionState(this);
398 ap.paintAlignment(true);
401 public ColumnSelection getOldColumnSelection()
403 return oldColumnSelection;
406 public void setOldColumnSelection(ColumnSelection currentColumnSelection)
408 if (currentColumnSelection != null)
410 this.oldColumnSelection = new ColumnSelection(currentColumnSelection);
414 public FurtherActionPanel getCurrentFutherActionPanel()
416 return currentFurtherActionPanel;
419 public void setCurrentFutherActionPanel(
420 FurtherActionPanel currentFutherActionPanel)
422 this.currentFurtherActionPanel = currentFutherActionPanel;
425 public SearchPanel getCurrentSearchPanel()
427 return currentSearchPanel;
430 public void setCurrentSearchPanel(SearchPanel currentSearchPanel)
432 this.currentSearchPanel = currentSearchPanel;
435 public int getActionOption()
440 public void setActionOption(int actionOption)
442 this.actionOption = actionOption;
445 public StructureFilterPanel getCurrentStructureFilterPanel()
447 return currentStructureFilterPanel;
450 public void setCurrentStructureFilterPanel(
451 StructureFilterPanel currentStructureFilterPanel)
453 this.currentStructureFilterPanel = currentStructureFilterPanel;
456 public void select_action(ActionEvent actionEvent)
458 JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
459 if (radioButton.isSelected())
461 setActionOption(ACTION_OPTION_SELECT);
466 public void hide_action(ActionEvent actionEvent)
468 JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
469 if (radioButton.isSelected())
471 setActionOption(ACTION_OPTION_HIDE);
477 public void itemStateChanged(ItemEvent e)
479 selectedAnnotationChanged();
483 public void selectedAnnotationChanged()
485 String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
486 if (av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
487 .getSelectedIndex()]].graph != AlignmentAnnotation.NO_GRAPH)
489 currentView = AnnotationColumnChooser.GRAPH_VIEW;
492 gSearchPanel.syncState();
493 gFurtherActionPanel.syncState();
494 gStructureFilterPanel.syncState();
496 ngSearchPanel.syncState();
497 ngFurtherActionPanel.syncState();
498 ngStructureFilterPanel.syncState();
500 CardLayout switchableViewsLayout = (CardLayout) switchableViewsPanel
502 switchableViewsLayout.show(switchableViewsPanel, currentView);
506 public class FurtherActionPanel extends JPanel
508 private AnnotationColumnChooser aColChooser;
510 private JRadioButton hideOption = new JRadioButton();
512 private JRadioButton selectOption = new JRadioButton();
514 private ButtonGroup optionsGroup = new ButtonGroup();
516 public FurtherActionPanel(AnnotationColumnChooser aColChooser)
518 this.aColChooser = aColChooser;
519 JvSwingUtils.jvInitComponent(selectOption, "action.select");
520 selectOption.addActionListener(new ActionListener()
523 public void actionPerformed(ActionEvent actionEvent)
525 selectRadioAction(actionEvent);
529 JvSwingUtils.jvInitComponent(hideOption, "action.hide");
530 hideOption.addActionListener(new ActionListener()
533 public void actionPerformed(ActionEvent actionEvent)
535 hideRadioAction(actionEvent);
539 optionsGroup.add(selectOption);
540 optionsGroup.add(hideOption);
541 optionsGroup.setSelected(selectOption.getModel(), true);
543 JvSwingUtils.jvInitComponent(this);
546 this.add(selectOption);
547 this.add(hideOption);
550 public void selectRadioAction(ActionEvent actionEvent)
552 aColChooser.setCurrentFutherActionPanel(this);
553 aColChooser.select_action(actionEvent);
556 public void hideRadioAction(ActionEvent actionEvent)
558 aColChooser.setCurrentFutherActionPanel(this);
559 aColChooser.hide_action(actionEvent);
562 public void syncState()
564 if (aColChooser.getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
566 this.optionsGroup.setSelected(this.hideOption.getModel(), true);
570 this.optionsGroup.setSelected(this.selectOption.getModel(), true);
575 public class StructureFilterPanel extends JPanel
577 private AnnotationColumnChooser aColChooser;
579 private JCheckBox alphaHelix = new JCheckBox();
581 private JCheckBox betaStrand = new JCheckBox();
583 private JCheckBox turn = new JCheckBox();
585 private JCheckBox all = new JCheckBox();
587 public StructureFilterPanel(AnnotationColumnChooser aColChooser)
589 this.aColChooser = aColChooser;
591 JvSwingUtils.jvInitComponent(alphaHelix, "label.alpha_helix");
592 alphaHelix.addActionListener(new ActionListener()
595 public void actionPerformed(ActionEvent actionEvent)
597 alphaHelix_actionPerformed();
601 JvSwingUtils.jvInitComponent(betaStrand, "label.beta_strand");
602 betaStrand.addActionListener(new ActionListener()
605 public void actionPerformed(ActionEvent actionEvent)
607 betaStrand_actionPerformed();
611 JvSwingUtils.jvInitComponent(turn, "label.turn");
612 turn.addActionListener(new ActionListener()
615 public void actionPerformed(ActionEvent actionEvent)
617 turn_actionPerformed();
621 JvSwingUtils.jvInitComponent(all, "label.select_all");
622 all.addActionListener(new ActionListener()
625 public void actionPerformed(ActionEvent actionEvent)
627 all_actionPerformed();
631 this.setBorder(new TitledBorder(MessageManager
632 .getString("label.structures_filter")));
633 JvSwingUtils.jvInitComponent(this);
636 this.add(alphaHelix);
637 this.add(betaStrand);
641 public void alphaHelix_actionPerformed()
643 updateSelectAllState();
644 aColChooser.setCurrentStructureFilterPanel(this);
645 aColChooser.updateView();
648 public void betaStrand_actionPerformed()
650 updateSelectAllState();
651 aColChooser.setCurrentStructureFilterPanel(this);
652 aColChooser.updateView();
655 public void turn_actionPerformed()
657 updateSelectAllState();
658 aColChooser.setCurrentStructureFilterPanel(this);
659 aColChooser.updateView();
662 public void all_actionPerformed()
664 if (all.isSelected())
666 alphaHelix.setSelected(true);
667 betaStrand.setSelected(true);
668 turn.setSelected(true);
672 alphaHelix.setSelected(false);
673 betaStrand.setSelected(false);
674 turn.setSelected(false);
676 aColChooser.setCurrentStructureFilterPanel(this);
677 aColChooser.updateView();
680 public void updateSelectAllState()
682 if (alphaHelix.isSelected() && betaStrand.isSelected()
683 && turn.isSelected())
685 all.setSelected(true);
689 all.setSelected(false);
693 public void syncState()
695 StructureFilterPanel sfp = aColChooser
696 .getCurrentStructureFilterPanel();
699 alphaHelix.setSelected(sfp.alphaHelix.isSelected());
700 betaStrand.setSelected(sfp.betaStrand.isSelected());
701 turn.setSelected(sfp.turn.isSelected());
702 if (sfp.all.isSelected())
704 all.setSelected(true);
705 alphaHelix.setSelected(true);
706 betaStrand.setSelected(true);
707 turn.setSelected(true);
714 public class SearchPanel extends JPanel
716 private AnnotationColumnChooser aColChooser;
718 private JCheckBox displayName = new JCheckBox();
720 private JCheckBox description = new JCheckBox();
722 private JTextField searchBox = new JTextField(10);
724 public SearchPanel(AnnotationColumnChooser aColChooser)
727 this.aColChooser = aColChooser;
728 JvSwingUtils.jvInitComponent(this);
729 this.setBorder(new TitledBorder(MessageManager
730 .getString("label.search_filter")));
732 JvSwingUtils.jvInitComponent(searchBox);
733 searchBox.setToolTipText(MessageManager
734 .getString("info.enter_search_text_here"));
735 searchBox.getDocument().addDocumentListener(new DocumentListener()
738 public void insertUpdate(DocumentEvent e)
740 searchStringAction();
744 public void removeUpdate(DocumentEvent e)
746 searchStringAction();
750 public void changedUpdate(DocumentEvent e)
752 searchStringAction();
756 JvSwingUtils.jvInitComponent(displayName, "label.label");
757 displayName.setEnabled(false);
758 displayName.addActionListener(new ActionListener()
761 public void actionPerformed(ActionEvent actionEvent)
763 displayNameCheckboxAction();
767 JvSwingUtils.jvInitComponent(description, "label.description");
768 description.setEnabled(false);
769 description.addActionListener(new ActionListener()
772 public void actionPerformed(ActionEvent actionEvent)
774 discriptionCheckboxAction();
780 this.add(displayName);
781 this.add(description);
784 public void displayNameCheckboxAction()
786 aColChooser.setCurrentSearchPanel(this);
787 aColChooser.updateView();
790 public void discriptionCheckboxAction()
792 aColChooser.setCurrentSearchPanel(this);
793 aColChooser.updateView();
796 public void searchStringAction()
798 aColChooser.setCurrentSearchPanel(this);
799 aColChooser.updateView();
800 updateSearchPanelToolTips();
803 public void syncState()
805 SearchPanel sp = aColChooser.getCurrentSearchPanel();
808 description.setEnabled(sp.description.isEnabled());
809 description.setSelected(sp.description.isSelected());
811 displayName.setEnabled(sp.displayName.isEnabled());
812 displayName.setSelected(sp.displayName.isSelected());
814 searchBox.setText(sp.searchBox.getText());
816 updateSearchPanelToolTips();
819 public void updateSearchPanelToolTips()
821 String defaultTtip = MessageManager
822 .getString("info.enter_search_text_to_enable");
823 String labelTtip = MessageManager.formatMessage(
824 "info.search_in_annotation_label", annotations
825 .getSelectedItem().toString());
826 String descTtip = MessageManager.formatMessage(
827 "info.search_in_annotation_description", annotations
828 .getSelectedItem().toString());
829 displayName.setToolTipText(displayName.isEnabled() ? labelTtip
831 description.setToolTipText(description.isEnabled() ? descTtip