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
69 private JPanel noGraphFilterView = new JPanel();
71 private JPanel graphFilterView = new JPanel();
73 private JPanel annotationComboBoxPanel = new JPanel();
75 private BorderLayout borderLayout1 = new BorderLayout();
77 private JComboBox<String> threshold = new JComboBox<String>();
79 private StructureFilterPanel gStructureFilterPanel;
81 private StructureFilterPanel ngStructureFilterPanel;
83 private StructureFilterPanel currentStructureFilterPanel;
85 private SearchPanel currentSearchPanel;
87 private SearchPanel gSearchPanel;
89 private SearchPanel ngSearchPanel;
91 private FurtherActionPanel currentFurtherActionPanel;
93 private FurtherActionPanel gFurtherActionPanel;
95 private FurtherActionPanel ngFurtherActionPanel;
97 public static final int ACTION_OPTION_SELECT = 1;
99 public static int ACTION_OPTION_HIDE = 2;
101 public static String NO_GRAPH_VIEW = "0";
103 public static String GRAPH_VIEW = "1";
105 private int actionOption = ACTION_OPTION_SELECT;
107 private ColumnSelection oldColumnSelection;
109 public AnnotationColumnChooser()
114 } catch (Exception ex)
116 ex.printStackTrace();
120 public AnnotationColumnChooser(AlignViewport av, final AlignmentPanel ap)
123 frame = new JInternalFrame();
124 frame.setContentPane(this);
125 frame.setLayer(JLayeredPane.PALETTE_LAYER);
126 Desktop.addInternalFrame(frame,
127 MessageManager.getString("label.select_by_annotation"), 520,
130 addSliderChangeListener();
131 addSliderMouseListeners();
133 if (av.getAlignment().getAlignmentAnnotation() == null)
137 setOldColumnSelection(av.getColumnSelection());
140 setAnnotations(new JComboBox<String>(getAnnotationItems(false)));
141 populateThresholdComboBox(threshold);
143 // restore Object state from the previous session if one exists
144 if (av.getAnnotationColumnSelectionState() != null)
146 currentSearchPanel = av.getAnnotationColumnSelectionState()
147 .getCurrentSearchPanel();
148 currentStructureFilterPanel = av.getAnnotationColumnSelectionState()
149 .getCurrentStructureFilterPanel();
150 annotations.setSelectedIndex(av.getAnnotationColumnSelectionState()
151 .getAnnotations().getSelectedIndex());
152 threshold.setSelectedIndex(av.getAnnotationColumnSelectionState()
153 .getThreshold().getSelectedIndex());
154 actionOption = av.getAnnotationColumnSelectionState()
161 } catch (Exception ex)
171 private void jbInit() throws Exception
174 ok.setText(MessageManager.getString("action.ok"));
175 ok.addActionListener(new ActionListener()
178 public void actionPerformed(ActionEvent e)
180 ok_actionPerformed(e);
184 cancel.setOpaque(false);
185 cancel.setText(MessageManager.getString("action.cancel"));
186 cancel.addActionListener(new ActionListener()
189 public void actionPerformed(ActionEvent e)
191 cancel_actionPerformed(e);
195 annotations.addItemListener(this);
196 annotations.setToolTipText(MessageManager
197 .getString("info.select_annotation_row"));
198 threshold.addActionListener(new ActionListener()
201 public void actionPerformed(ActionEvent e)
203 threshold_actionPerformed(e);
207 thresholdValue.setEnabled(false);
208 thresholdValue.setColumns(7);
209 thresholdValue.addActionListener(new ActionListener()
212 public void actionPerformed(ActionEvent e)
214 thresholdValue_actionPerformed(e);
218 slider.setPaintLabels(false);
219 slider.setPaintTicks(true);
220 slider.setBackground(Color.white);
221 slider.setEnabled(false);
222 slider.setOpaque(false);
223 slider.setPreferredSize(new Dimension(100, 32));
225 thresholdPanel.setBorder(new TitledBorder(MessageManager
226 .getString("label.threshold_filter")));
227 thresholdPanel.setBackground(Color.white);
228 thresholdPanel.setFont(JvSwingUtils.getLabelFont());
229 thresholdPanel.setLayout(new MigLayout("", "[left][right]", "[][]"));
231 actionPanel.setBackground(Color.white);
232 actionPanel.setFont(JvSwingUtils.getLabelFont());
234 graphFilterView.setLayout(new MigLayout("", "[left][right]", "[][]"));
235 graphFilterView.setBackground(Color.white);
237 noGraphFilterView.setLayout(new MigLayout("", "[left][right]", "[][]"));
238 noGraphFilterView.setBackground(Color.white);
240 annotationComboBoxPanel.setBackground(Color.white);
241 annotationComboBoxPanel.setFont(JvSwingUtils.getLabelFont());
243 gSearchPanel = new SearchPanel(this);
244 ngSearchPanel = new SearchPanel(this);
245 gFurtherActionPanel = new FurtherActionPanel(this);
246 ngFurtherActionPanel = new FurtherActionPanel(this);
247 gStructureFilterPanel = new StructureFilterPanel(this);
248 ngStructureFilterPanel = new StructureFilterPanel(this);
250 thresholdPanel.add(getThreshold());
251 thresholdPanel.add(thresholdValue, "wrap");
252 thresholdPanel.add(slider, "grow, span, wrap");
255 actionPanel.add(cancel);
257 graphFilterView.add(gSearchPanel, "grow, span, wrap");
258 graphFilterView.add(gStructureFilterPanel, "grow, span, wrap");
259 graphFilterView.add(thresholdPanel, "grow, span, wrap");
260 graphFilterView.add(gFurtherActionPanel);
262 noGraphFilterView.add(ngSearchPanel, "grow, span, wrap");
263 noGraphFilterView.add(ngStructureFilterPanel, "grow, span, wrap");
264 noGraphFilterView.add(ngFurtherActionPanel);
266 annotationComboBoxPanel.add(getAnnotations());
267 switchableViewsPanel.add(noGraphFilterView,
268 AnnotationColumnChooser.NO_GRAPH_VIEW);
269 switchableViewsPanel.add(graphFilterView,
270 AnnotationColumnChooser.GRAPH_VIEW);
272 this.setLayout(borderLayout1);
273 this.add(annotationComboBoxPanel, java.awt.BorderLayout.PAGE_START);
274 this.add(switchableViewsPanel, java.awt.BorderLayout.CENTER);
275 this.add(actionPanel, java.awt.BorderLayout.SOUTH);
277 selectedAnnotationChanged();
278 updateThresholdPanelToolTip();
282 public void updateThresholdPanelToolTip()
284 thresholdValue.setToolTipText("");
285 slider.setToolTipText("");
287 String defaultTtip = MessageManager
288 .getString("info.change_threshold_mode_to_enable");
290 String threshold = getThreshold().getSelectedItem().toString();
291 if (threshold.equalsIgnoreCase("No Threshold"))
293 thresholdValue.setToolTipText(defaultTtip);
294 slider.setToolTipText(defaultTtip);
299 if (this.getOldColumnSelection() != null)
301 av.getColumnSelection().clear();
303 if (av.getAnnotationColumnSelectionState() != null)
305 ColumnSelection oldSelection = av
306 .getAnnotationColumnSelectionState()
307 .getOldColumnSelection();
308 if (oldSelection != null && oldSelection.getHiddenColumns() != null
309 && !oldSelection.getHiddenColumns().isEmpty())
311 for (Iterator<int[]> itr = oldSelection.getHiddenColumns()
312 .iterator(); itr.hasNext();)
314 int positions[] = itr.next();
315 av.hideColumns(positions[0], positions[1]);
318 av.setColumnSelection(oldSelection);
320 ap.paintAlignment(true);
325 public void valueChanged(boolean updateAllAnnotation)
327 if (slider.isEnabled())
329 getCurrentAnnotation().threshold.value = slider.getValue() / 1000f;
331 propagateSeqAssociatedThreshold(updateAllAnnotation,
332 getCurrentAnnotation());
333 ap.paintAlignment(false);
337 public JComboBox<String> getThreshold()
342 public void setThreshold(JComboBox<String> threshold)
344 this.threshold = threshold;
347 public JComboBox<String> getAnnotations()
352 public void setAnnotations(JComboBox<String> annotations)
354 this.annotations = annotations;
358 public void updateView()
360 // Check if combobox is still adjusting
366 AnnotationFilterParameter filterParams = new AnnotationFilterParameter();
368 setCurrentAnnotation(av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
369 .getSelectedIndex()]]);
371 int selectedThresholdItem = getSelectedThresholdItem(getThreshold()
372 .getSelectedIndex());
374 slider.setEnabled(true);
375 thresholdValue.setEnabled(true);
377 if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
379 slider.setEnabled(false);
380 thresholdValue.setEnabled(false);
381 thresholdValue.setText("");
382 // build filter params
384 else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
386 if (getCurrentAnnotation().threshold == null)
388 getCurrentAnnotation()
390 new jalview.datamodel.GraphLine(
391 (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin) / 2f,
392 "Threshold", Color.black));
396 float range = getCurrentAnnotation().graphMax * 1000
397 - getCurrentAnnotation().graphMin * 1000;
399 slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
400 slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
401 slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000));
402 thresholdValue.setText(getCurrentAnnotation().threshold.value + "");
403 slider.setMajorTickSpacing((int) (range / 10f));
404 slider.setEnabled(true);
405 thresholdValue.setEnabled(true);
408 // build filter params
410 .setThresholdType(AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);
411 if (getCurrentAnnotation().graph != AlignmentAnnotation.NO_GRAPH)
414 .setThresholdValue(getCurrentAnnotation().threshold.value);
416 if (selectedThresholdItem == AnnotationColourGradient.ABOVE_THRESHOLD)
419 .setThresholdType(AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD);
421 else if (selectedThresholdItem == AnnotationColourGradient.BELOW_THRESHOLD)
424 .setThresholdType(AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD);
429 updateThresholdPanelToolTip();
430 if (currentStructureFilterPanel != null)
432 if (currentStructureFilterPanel.alphaHelix.isSelected())
434 filterParams.setFilterAlphaHelix(true);
436 if (currentStructureFilterPanel.betaStrand.isSelected())
438 filterParams.setFilterBetaSheet(true);
440 if (currentStructureFilterPanel.turn.isSelected())
442 filterParams.setFilterTurn(true);
446 if (currentSearchPanel != null)
449 if (!currentSearchPanel.searchBox.getText().isEmpty())
451 currentSearchPanel.description.setEnabled(true);
452 currentSearchPanel.displayName.setEnabled(true);
453 filterParams.setRegexString(currentSearchPanel.searchBox.getText());
454 if (currentSearchPanel.displayName.isSelected())
457 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING);
459 if (currentSearchPanel.description.isSelected())
462 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION);
467 currentSearchPanel.description.setEnabled(false);
468 currentSearchPanel.displayName.setEnabled(false);
472 av.getColumnSelection().filterAnnotations(
473 getCurrentAnnotation().annotations, filterParams);
475 av.showAllHiddenColumns();
476 if (getActionOption() == ACTION_OPTION_HIDE)
478 av.hideSelectedColumns();
482 av.setAnnotationColumnSelectionState(this);
483 ap.paintAlignment(true);
486 public ColumnSelection getOldColumnSelection()
488 return oldColumnSelection;
491 public void setOldColumnSelection(ColumnSelection currentColumnSelection)
493 if (currentColumnSelection != null)
495 this.oldColumnSelection = new ColumnSelection(currentColumnSelection);
499 public FurtherActionPanel getCurrentFutherActionPanel()
501 return currentFurtherActionPanel;
504 public void setCurrentFutherActionPanel(
505 FurtherActionPanel currentFutherActionPanel)
507 this.currentFurtherActionPanel = currentFutherActionPanel;
510 public SearchPanel getCurrentSearchPanel()
512 return currentSearchPanel;
515 public void setCurrentSearchPanel(SearchPanel currentSearchPanel)
517 this.currentSearchPanel = currentSearchPanel;
520 public int getActionOption()
525 public void setActionOption(int actionOption)
527 this.actionOption = actionOption;
530 public StructureFilterPanel getCurrentStructureFilterPanel()
532 return currentStructureFilterPanel;
535 public void setCurrentStructureFilterPanel(
536 StructureFilterPanel currentStructureFilterPanel)
538 this.currentStructureFilterPanel = currentStructureFilterPanel;
541 public void select_action(ActionEvent actionEvent)
543 JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
544 if (radioButton.isSelected())
546 setActionOption(ACTION_OPTION_SELECT);
551 public void hide_action(ActionEvent actionEvent)
553 JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
554 if (radioButton.isSelected())
556 setActionOption(ACTION_OPTION_HIDE);
562 public void itemStateChanged(ItemEvent e)
564 selectedAnnotationChanged();
567 public void selectedAnnotationChanged()
569 String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
570 if (av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
571 .getSelectedIndex()]].graph != AlignmentAnnotation.NO_GRAPH)
573 currentView = AnnotationColumnChooser.GRAPH_VIEW;
576 gSearchPanel.syncState();
577 gFurtherActionPanel.syncState();
578 gStructureFilterPanel.syncState();
580 ngSearchPanel.syncState();
581 ngFurtherActionPanel.syncState();
582 ngStructureFilterPanel.syncState();
584 switchableViewsLayout.show(switchableViewsPanel, currentView);
589 public class FurtherActionPanel extends JPanel
591 private AnnotationColumnChooser aColChooser;
593 private JRadioButton hideOption = new JRadioButton();
595 private JRadioButton selectOption = new JRadioButton();
597 private ButtonGroup optionsGroup = new ButtonGroup();
599 public FurtherActionPanel(AnnotationColumnChooser aColChooser)
601 this.aColChooser = aColChooser;
602 JvSwingUtils.jvInitComponent(selectOption, "action.select");
603 selectOption.addActionListener(new ActionListener()
606 public void actionPerformed(ActionEvent actionEvent)
608 selectRadioAction(actionEvent);
612 JvSwingUtils.jvInitComponent(hideOption, "action.hide");
613 hideOption.addActionListener(new ActionListener()
616 public void actionPerformed(ActionEvent actionEvent)
618 hideRadioAction(actionEvent);
622 optionsGroup.add(selectOption);
623 optionsGroup.add(hideOption);
624 optionsGroup.setSelected(selectOption.getModel(), true);
626 JvSwingUtils.jvInitComponent(this);
629 this.add(selectOption);
630 this.add(hideOption);
633 public void selectRadioAction(ActionEvent actionEvent)
635 aColChooser.setCurrentFutherActionPanel(this);
636 aColChooser.select_action(actionEvent);
639 public void hideRadioAction(ActionEvent actionEvent)
641 aColChooser.setCurrentFutherActionPanel(this);
642 aColChooser.hide_action(actionEvent);
645 public void syncState()
647 if (aColChooser.getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
649 this.optionsGroup.setSelected(this.hideOption.getModel(),
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(
820 new DocumentListener()
823 public void insertUpdate(DocumentEvent e)
825 searchStringAction();
829 public void removeUpdate(DocumentEvent e)
831 searchStringAction();
835 public void changedUpdate(DocumentEvent e)
837 searchStringAction();
841 JvSwingUtils.jvInitComponent(displayName, "label.label");
842 displayName.setEnabled(false);
843 displayName.addActionListener(new ActionListener()
846 public void actionPerformed(ActionEvent actionEvent)
848 displayNameCheckboxAction();
852 JvSwingUtils.jvInitComponent(description, "label.description");
853 description.setEnabled(false);
854 description.addActionListener(new ActionListener()
857 public void actionPerformed(ActionEvent actionEvent)
859 discriptionCheckboxAction();
865 this.add(displayName);
866 this.add(description);
869 public void displayNameCheckboxAction()
871 aColChooser.setCurrentSearchPanel(this);
872 aColChooser.updateView();
875 public void discriptionCheckboxAction()
877 aColChooser.setCurrentSearchPanel(this);
878 aColChooser.updateView();
881 public void searchStringAction()
883 aColChooser.setCurrentSearchPanel(this);
884 aColChooser.updateView();
885 updateSearchPanelToolTips();
888 public void syncState()
890 SearchPanel sp = aColChooser.getCurrentSearchPanel();
893 description.setEnabled(sp.description.isEnabled());
894 description.setSelected(sp.description.isSelected());
896 displayName.setEnabled(sp.displayName.isEnabled());
897 displayName.setSelected(sp.displayName.isSelected());
899 searchBox.setText(sp.searchBox.getText());
901 updateSearchPanelToolTips();
904 public void updateSearchPanelToolTips()
906 String defaultTtip = MessageManager
907 .getString("info.enter_search_text_to_enable");
908 String labelTtip = MessageManager
910 "info.search_in_annotation_label", annotations
911 .getSelectedItem().toString());
912 String descTtip = MessageManager
914 "info.search_in_annotation_description", annotations
915 .getSelectedItem().toString());
916 displayName.setToolTipText(displayName.isEnabled() ? labelTtip : defaultTtip);
917 description.setToolTipText(description.isEnabled() ? descTtip