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(e);
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(e);
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(e);
208 thresholdValue.setEnabled(false);
209 thresholdValue.setColumns(7);
210 thresholdValue.addActionListener(new ActionListener()
213 public void actionPerformed(ActionEvent e)
215 thresholdValue_actionPerformed(e);
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 threshold = getThreshold().getSelectedItem().toString();
292 if (threshold.equalsIgnoreCase("No Threshold"))
294 thresholdValue.setToolTipText(defaultTtip);
295 slider.setToolTipText(defaultTtip);
301 if (this.getOldColumnSelection() != null)
303 av.getColumnSelection().clear();
305 if (av.getAnnotationColumnSelectionState() != null)
307 ColumnSelection oldSelection = av
308 .getAnnotationColumnSelectionState()
309 .getOldColumnSelection();
310 if (oldSelection != null && oldSelection.getHiddenColumns() != null
311 && !oldSelection.getHiddenColumns().isEmpty())
313 for (Iterator<int[]> itr = oldSelection.getHiddenColumns()
314 .iterator(); itr.hasNext();)
316 int positions[] = itr.next();
317 av.hideColumns(positions[0], positions[1]);
320 av.setColumnSelection(oldSelection);
322 ap.paintAlignment(true);
327 public void valueChanged(boolean updateAllAnnotation)
329 if (slider.isEnabled())
331 getCurrentAnnotation().threshold.value = slider.getValue() / 1000f;
333 propagateSeqAssociatedThreshold(updateAllAnnotation,
334 getCurrentAnnotation());
335 ap.paintAlignment(false);
339 public JComboBox<String> getThreshold()
344 public void setThreshold(JComboBox<String> threshold)
346 this.threshold = threshold;
349 public JComboBox<String> getAnnotations()
354 public void setAnnotations(JComboBox<String> annotations)
356 this.annotations = annotations;
360 public void updateView()
362 // Check if combobox is still adjusting
368 AnnotationFilterParameter filterParams = new AnnotationFilterParameter();
370 setCurrentAnnotation(av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
371 .getSelectedIndex()]]);
373 int selectedThresholdItem = getSelectedThresholdItem(getThreshold()
374 .getSelectedIndex());
376 slider.setEnabled(true);
377 thresholdValue.setEnabled(true);
379 if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
381 slider.setEnabled(false);
382 thresholdValue.setEnabled(false);
383 thresholdValue.setText("");
384 // build filter params
386 else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
388 if (getCurrentAnnotation().threshold == null)
390 getCurrentAnnotation()
392 new jalview.datamodel.GraphLine(
393 (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin) / 2f,
394 "Threshold", Color.black));
398 float range = getCurrentAnnotation().graphMax * 1000
399 - getCurrentAnnotation().graphMin * 1000;
401 slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
402 slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
403 slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000));
404 thresholdValue.setText(getCurrentAnnotation().threshold.value + "");
405 slider.setMajorTickSpacing((int) (range / 10f));
406 slider.setEnabled(true);
407 thresholdValue.setEnabled(true);
410 // build filter params
412 .setThresholdType(AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);
413 if (getCurrentAnnotation().graph != AlignmentAnnotation.NO_GRAPH)
416 .setThresholdValue(getCurrentAnnotation().threshold.value);
418 if (selectedThresholdItem == AnnotationColourGradient.ABOVE_THRESHOLD)
421 .setThresholdType(AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD);
423 else if (selectedThresholdItem == AnnotationColourGradient.BELOW_THRESHOLD)
426 .setThresholdType(AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD);
431 updateThresholdPanelToolTip();
432 if (currentStructureFilterPanel != null)
434 if (currentStructureFilterPanel.alphaHelix.isSelected())
436 filterParams.setFilterAlphaHelix(true);
438 if (currentStructureFilterPanel.betaStrand.isSelected())
440 filterParams.setFilterBetaSheet(true);
442 if (currentStructureFilterPanel.turn.isSelected())
444 filterParams.setFilterTurn(true);
448 if (currentSearchPanel != null)
451 if (!currentSearchPanel.searchBox.getText().isEmpty())
453 currentSearchPanel.description.setEnabled(true);
454 currentSearchPanel.displayName.setEnabled(true);
455 filterParams.setRegexString(currentSearchPanel.searchBox.getText());
456 if (currentSearchPanel.displayName.isSelected())
459 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING);
461 if (currentSearchPanel.description.isSelected())
464 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION);
469 currentSearchPanel.description.setEnabled(false);
470 currentSearchPanel.displayName.setEnabled(false);
474 av.getColumnSelection().filterAnnotations(
475 getCurrentAnnotation().annotations, filterParams);
477 av.showAllHiddenColumns();
478 if (getActionOption() == ACTION_OPTION_HIDE)
480 av.hideSelectedColumns();
484 av.setAnnotationColumnSelectionState(this);
485 ap.paintAlignment(true);
488 public ColumnSelection getOldColumnSelection()
490 return oldColumnSelection;
493 public void setOldColumnSelection(ColumnSelection currentColumnSelection)
495 if (currentColumnSelection != null)
497 this.oldColumnSelection = new ColumnSelection(currentColumnSelection);
501 public FurtherActionPanel getCurrentFutherActionPanel()
503 return currentFurtherActionPanel;
506 public void setCurrentFutherActionPanel(
507 FurtherActionPanel currentFutherActionPanel)
509 this.currentFurtherActionPanel = currentFutherActionPanel;
512 public SearchPanel getCurrentSearchPanel()
514 return currentSearchPanel;
517 public void setCurrentSearchPanel(SearchPanel currentSearchPanel)
519 this.currentSearchPanel = currentSearchPanel;
522 public int getActionOption()
527 public void setActionOption(int actionOption)
529 this.actionOption = actionOption;
532 public StructureFilterPanel getCurrentStructureFilterPanel()
534 return currentStructureFilterPanel;
537 public void setCurrentStructureFilterPanel(
538 StructureFilterPanel currentStructureFilterPanel)
540 this.currentStructureFilterPanel = currentStructureFilterPanel;
543 public void select_action(ActionEvent actionEvent)
545 JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
546 if (radioButton.isSelected())
548 setActionOption(ACTION_OPTION_SELECT);
553 public void hide_action(ActionEvent actionEvent)
555 JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
556 if (radioButton.isSelected())
558 setActionOption(ACTION_OPTION_HIDE);
564 public void itemStateChanged(ItemEvent e)
566 selectedAnnotationChanged();
569 public void selectedAnnotationChanged()
571 String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
572 if (av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
573 .getSelectedIndex()]].graph != AlignmentAnnotation.NO_GRAPH)
575 currentView = AnnotationColumnChooser.GRAPH_VIEW;
578 gSearchPanel.syncState();
579 gFurtherActionPanel.syncState();
580 gStructureFilterPanel.syncState();
582 ngSearchPanel.syncState();
583 ngFurtherActionPanel.syncState();
584 ngStructureFilterPanel.syncState();
586 switchableViewsLayout.show(switchableViewsPanel, currentView);
590 public class FurtherActionPanel extends JPanel
592 private AnnotationColumnChooser aColChooser;
594 private JRadioButton hideOption = new JRadioButton();
596 private JRadioButton selectOption = new JRadioButton();
598 private ButtonGroup optionsGroup = new ButtonGroup();
600 public FurtherActionPanel(AnnotationColumnChooser aColChooser)
602 this.aColChooser = aColChooser;
603 JvSwingUtils.jvInitComponent(selectOption, "action.select");
604 selectOption.addActionListener(new ActionListener()
607 public void actionPerformed(ActionEvent actionEvent)
609 selectRadioAction(actionEvent);
613 JvSwingUtils.jvInitComponent(hideOption, "action.hide");
614 hideOption.addActionListener(new ActionListener()
617 public void actionPerformed(ActionEvent actionEvent)
619 hideRadioAction(actionEvent);
623 optionsGroup.add(selectOption);
624 optionsGroup.add(hideOption);
625 optionsGroup.setSelected(selectOption.getModel(), true);
627 JvSwingUtils.jvInitComponent(this);
630 this.add(selectOption);
631 this.add(hideOption);
634 public void selectRadioAction(ActionEvent actionEvent)
636 aColChooser.setCurrentFutherActionPanel(this);
637 aColChooser.select_action(actionEvent);
640 public void hideRadioAction(ActionEvent actionEvent)
642 aColChooser.setCurrentFutherActionPanel(this);
643 aColChooser.hide_action(actionEvent);
646 public void syncState()
648 if (aColChooser.getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
650 this.optionsGroup.setSelected(this.hideOption.getModel(), true);
654 this.optionsGroup.setSelected(this.selectOption.getModel(), true);
659 public class StructureFilterPanel extends JPanel
661 private AnnotationColumnChooser aColChooser;
663 private JCheckBox alphaHelix = new JCheckBox();
665 private JCheckBox betaStrand = new JCheckBox();
667 private JCheckBox turn = new JCheckBox();
669 private JCheckBox all = new JCheckBox();
671 public StructureFilterPanel(AnnotationColumnChooser aColChooser)
673 this.aColChooser = aColChooser;
675 JvSwingUtils.jvInitComponent(alphaHelix, "label.alpha_helix");
676 alphaHelix.addActionListener(new ActionListener()
679 public void actionPerformed(ActionEvent actionEvent)
681 alphaHelix_actionPerformed();
685 JvSwingUtils.jvInitComponent(betaStrand, "label.beta_strand");
686 betaStrand.addActionListener(new ActionListener()
689 public void actionPerformed(ActionEvent actionEvent)
691 betaStrand_actionPerformed();
695 JvSwingUtils.jvInitComponent(turn, "label.turn");
696 turn.addActionListener(new ActionListener()
699 public void actionPerformed(ActionEvent actionEvent)
701 turn_actionPerformed();
705 JvSwingUtils.jvInitComponent(all, "label.select_all");
706 all.addActionListener(new ActionListener()
709 public void actionPerformed(ActionEvent actionEvent)
711 all_actionPerformed();
715 this.setBorder(new TitledBorder(MessageManager
716 .getString("label.structures_filter")));
717 JvSwingUtils.jvInitComponent(this);
720 this.add(alphaHelix);
721 this.add(betaStrand);
725 public void alphaHelix_actionPerformed()
727 updateSelectAllState();
728 aColChooser.setCurrentStructureFilterPanel(this);
729 aColChooser.updateView();
732 public void betaStrand_actionPerformed()
734 updateSelectAllState();
735 aColChooser.setCurrentStructureFilterPanel(this);
736 aColChooser.updateView();
739 public void turn_actionPerformed()
741 updateSelectAllState();
742 aColChooser.setCurrentStructureFilterPanel(this);
743 aColChooser.updateView();
746 public void all_actionPerformed()
748 if (all.isSelected())
750 alphaHelix.setSelected(true);
751 betaStrand.setSelected(true);
752 turn.setSelected(true);
756 alphaHelix.setSelected(false);
757 betaStrand.setSelected(false);
758 turn.setSelected(false);
760 aColChooser.setCurrentStructureFilterPanel(this);
761 aColChooser.updateView();
764 public void updateSelectAllState()
766 if (alphaHelix.isSelected() && betaStrand.isSelected()
767 && turn.isSelected())
769 all.setSelected(true);
773 all.setSelected(false);
777 public void syncState()
779 StructureFilterPanel sfp = aColChooser
780 .getCurrentStructureFilterPanel();
783 alphaHelix.setSelected(sfp.alphaHelix.isSelected());
784 betaStrand.setSelected(sfp.betaStrand.isSelected());
785 turn.setSelected(sfp.turn.isSelected());
786 if (sfp.all.isSelected())
788 all.setSelected(true);
789 alphaHelix.setSelected(true);
790 betaStrand.setSelected(true);
791 turn.setSelected(true);
798 public class SearchPanel extends JPanel
800 private AnnotationColumnChooser aColChooser;
802 private JCheckBox displayName = new JCheckBox();
804 private JCheckBox description = new JCheckBox();
806 private JTextField searchBox = new JTextField(10);
808 public SearchPanel(AnnotationColumnChooser aColChooser)
811 this.aColChooser = aColChooser;
812 JvSwingUtils.jvInitComponent(this);
813 this.setBorder(new TitledBorder(MessageManager
814 .getString("label.search_filter")));
816 JvSwingUtils.jvInitComponent(searchBox);
817 searchBox.setToolTipText(MessageManager
818 .getString("info.enter_search_text_here"));
819 searchBox.getDocument().addDocumentListener(new DocumentListener()
822 public void insertUpdate(DocumentEvent e)
824 searchStringAction();
828 public void removeUpdate(DocumentEvent e)
830 searchStringAction();
834 public void changedUpdate(DocumentEvent e)
836 searchStringAction();
840 JvSwingUtils.jvInitComponent(displayName, "label.label");
841 displayName.setEnabled(false);
842 displayName.addActionListener(new ActionListener()
845 public void actionPerformed(ActionEvent actionEvent)
847 displayNameCheckboxAction();
851 JvSwingUtils.jvInitComponent(description, "label.description");
852 description.setEnabled(false);
853 description.addActionListener(new ActionListener()
856 public void actionPerformed(ActionEvent actionEvent)
858 discriptionCheckboxAction();
864 this.add(displayName);
865 this.add(description);
868 public void displayNameCheckboxAction()
870 aColChooser.setCurrentSearchPanel(this);
871 aColChooser.updateView();
874 public void discriptionCheckboxAction()
876 aColChooser.setCurrentSearchPanel(this);
877 aColChooser.updateView();
880 public void searchStringAction()
882 aColChooser.setCurrentSearchPanel(this);
883 aColChooser.updateView();
884 updateSearchPanelToolTips();
887 public void syncState()
889 SearchPanel sp = aColChooser.getCurrentSearchPanel();
892 description.setEnabled(sp.description.isEnabled());
893 description.setSelected(sp.description.isSelected());
895 displayName.setEnabled(sp.displayName.isEnabled());
896 displayName.setSelected(sp.displayName.isSelected());
898 searchBox.setText(sp.searchBox.getText());
900 updateSearchPanelToolTips();
903 public void updateSearchPanelToolTips()
905 String defaultTtip = MessageManager
906 .getString("info.enter_search_text_to_enable");
907 String labelTtip = MessageManager.formatMessage(
908 "info.search_in_annotation_label", annotations
909 .getSelectedItem().toString());
910 String descTtip = MessageManager.formatMessage(
911 "info.search_in_annotation_description", annotations
912 .getSelectedItem().toString());
913 displayName.setToolTipText(displayName.isEnabled() ? labelTtip
915 description.setToolTipText(description.isEnabled() ? descTtip