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);
119 AnnotationColumnChooser lastChooser = av
120 .getAnnotationColumnSelectionState();
121 // restore Object state from the previous session if one exists
122 if (lastChooser != null)
124 currentSearchPanel = lastChooser
125 .getCurrentSearchPanel();
126 currentStructureFilterPanel = lastChooser
127 .getCurrentStructureFilterPanel();
128 annotations.setSelectedIndex(lastChooser
129 .getAnnotations().getSelectedIndex());
130 threshold.setSelectedIndex(lastChooser
131 .getThreshold().getSelectedIndex());
132 actionOption = lastChooser
134 percentThreshold.setSelected(lastChooser.percentThreshold
141 } catch (Exception ex)
152 protected void jbInit()
156 JPanel thresholdPanel = new JPanel();
157 thresholdPanel.setBorder(new TitledBorder(MessageManager
158 .getString("label.threshold_filter")));
159 thresholdPanel.setBackground(Color.white);
160 thresholdPanel.setFont(JvSwingUtils.getLabelFont());
161 thresholdPanel.setLayout(new MigLayout("", "[left][right]", "[][]"));
163 percentThreshold.setBackground(Color.white);
164 percentThreshold.setFont(JvSwingUtils.getLabelFont());
166 JPanel actionPanel = new JPanel();
167 actionPanel.setBackground(Color.white);
168 actionPanel.setFont(JvSwingUtils.getLabelFont());
170 JPanel graphFilterView = new JPanel();
171 graphFilterView.setLayout(new MigLayout("", "[left][right]", "[][]"));
172 graphFilterView.setBackground(Color.white);
174 JPanel noGraphFilterView = new JPanel();
175 noGraphFilterView.setLayout(new MigLayout("", "[left][right]", "[][]"));
176 noGraphFilterView.setBackground(Color.white);
178 annotationComboBoxPanel.setBackground(Color.white);
179 annotationComboBoxPanel.setFont(JvSwingUtils.getLabelFont());
181 gSearchPanel = new SearchPanel(this);
182 ngSearchPanel = new SearchPanel(this);
183 gFurtherActionPanel = new FurtherActionPanel(this);
184 ngFurtherActionPanel = new FurtherActionPanel(this);
185 gStructureFilterPanel = new StructureFilterPanel(this);
186 ngStructureFilterPanel = new StructureFilterPanel(this);
188 thresholdPanel.add(getThreshold());
189 thresholdPanel.add(percentThreshold, "wrap");
190 thresholdPanel.add(slider, "grow");
191 thresholdPanel.add(thresholdValue, "span, wrap");
194 actionPanel.add(cancel);
196 graphFilterView.add(gSearchPanel, "grow, span, wrap");
197 graphFilterView.add(gStructureFilterPanel, "grow, span, wrap");
198 graphFilterView.add(thresholdPanel, "grow, span, wrap");
199 graphFilterView.add(gFurtherActionPanel);
201 noGraphFilterView.add(ngSearchPanel, "grow, span, wrap");
202 noGraphFilterView.add(ngStructureFilterPanel, "grow, span, wrap");
203 noGraphFilterView.add(ngFurtherActionPanel);
205 annotationComboBoxPanel.add(getAnnotations());
206 switchableViewsPanel.add(noGraphFilterView,
207 AnnotationColumnChooser.NO_GRAPH_VIEW);
208 switchableViewsPanel.add(graphFilterView,
209 AnnotationColumnChooser.GRAPH_VIEW);
211 this.setLayout(new BorderLayout());
212 this.add(annotationComboBoxPanel, java.awt.BorderLayout.PAGE_START);
213 this.add(switchableViewsPanel, java.awt.BorderLayout.CENTER);
214 this.add(actionPanel, java.awt.BorderLayout.SOUTH);
216 selectedAnnotationChanged();
217 updateThresholdPanelToolTip();
221 protected void updateThresholdPanelToolTip()
223 thresholdValue.setToolTipText("");
224 slider.setToolTipText("");
226 String defaultTtip = MessageManager
227 .getString("info.change_threshold_mode_to_enable");
229 String thresh = getThreshold().getSelectedItem().toString();
230 if (thresh.equalsIgnoreCase("No Threshold"))
232 thresholdValue.setToolTipText(defaultTtip);
233 slider.setToolTipText(defaultTtip);
238 protected void reset()
240 if (this.getOldColumnSelection() != null)
242 av.getColumnSelection().clear();
244 if (av.getAnnotationColumnSelectionState() != null)
246 ColumnSelection oldSelection = av
247 .getAnnotationColumnSelectionState()
248 .getOldColumnSelection();
249 if (oldSelection != null && oldSelection.getHiddenColumns() != null
250 && !oldSelection.getHiddenColumns().isEmpty())
252 for (Iterator<int[]> itr = oldSelection.getHiddenColumns()
253 .iterator(); itr.hasNext();)
255 int positions[] = itr.next();
256 av.hideColumns(positions[0], positions[1]);
259 av.setColumnSelection(oldSelection);
261 ap.paintAlignment(true);
267 public void valueChanged(boolean updateAllAnnotation)
269 if (slider.isEnabled())
271 getCurrentAnnotation().threshold.value = slider.getValue() / 1000f;
273 propagateSeqAssociatedThreshold(updateAllAnnotation,
274 getCurrentAnnotation());
275 ap.paintAlignment(false);
280 public void updateView()
282 // Check if combobox is still adjusting
288 AnnotationFilterParameter filterParams = new AnnotationFilterParameter();
290 setCurrentAnnotation(av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
291 .getSelectedIndex()]]);
293 int selectedThresholdItem = getSelectedThresholdItem(getThreshold()
294 .getSelectedIndex());
296 slider.setEnabled(true);
297 thresholdValue.setEnabled(true);
298 percentThreshold.setEnabled(true);
300 if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
302 slider.setEnabled(false);
303 thresholdValue.setEnabled(false);
304 thresholdValue.setText("");
305 percentThreshold.setEnabled(false);
306 // build filter params
308 else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
310 if (getCurrentAnnotation().threshold == null)
312 getCurrentAnnotation()
314 new jalview.datamodel.GraphLine(
315 (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin) / 2f,
316 "Threshold", Color.black));
320 float range = getCurrentAnnotation().graphMax * 1000
321 - getCurrentAnnotation().graphMin * 1000;
323 slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
324 slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
325 slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000));
327 setThresholdValueText();
329 slider.setMajorTickSpacing((int) (range / 10f));
330 slider.setEnabled(true);
331 thresholdValue.setEnabled(true);
334 // build filter params
336 .setThresholdType(AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);
337 if (getCurrentAnnotation().graph != AlignmentAnnotation.NO_GRAPH)
340 .setThresholdValue(getCurrentAnnotation().threshold.value);
342 if (selectedThresholdItem == AnnotationColourGradient.ABOVE_THRESHOLD)
345 .setThresholdType(AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD);
347 else if (selectedThresholdItem == AnnotationColourGradient.BELOW_THRESHOLD)
350 .setThresholdType(AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD);
355 updateThresholdPanelToolTip();
356 if (currentStructureFilterPanel != null)
358 if (currentStructureFilterPanel.alphaHelix.isSelected())
360 filterParams.setFilterAlphaHelix(true);
362 if (currentStructureFilterPanel.betaStrand.isSelected())
364 filterParams.setFilterBetaSheet(true);
366 if (currentStructureFilterPanel.turn.isSelected())
368 filterParams.setFilterTurn(true);
372 if (currentSearchPanel != null)
375 if (!currentSearchPanel.searchBox.getText().isEmpty())
377 currentSearchPanel.description.setEnabled(true);
378 currentSearchPanel.displayName.setEnabled(true);
379 filterParams.setRegexString(currentSearchPanel.searchBox.getText());
380 if (currentSearchPanel.displayName.isSelected())
383 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING);
385 if (currentSearchPanel.description.isSelected())
388 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION);
393 currentSearchPanel.description.setEnabled(false);
394 currentSearchPanel.displayName.setEnabled(false);
398 av.getColumnSelection().filterAnnotations(
399 getCurrentAnnotation().annotations, filterParams);
401 av.showAllHiddenColumns();
402 if (getActionOption() == ACTION_OPTION_HIDE)
404 av.hideSelectedColumns();
408 av.setAnnotationColumnSelectionState(this);
409 ap.paintAlignment(true);
413 public ColumnSelection getOldColumnSelection()
415 return oldColumnSelection;
418 public void setOldColumnSelection(ColumnSelection currentColumnSelection)
420 if (currentColumnSelection != null)
422 this.oldColumnSelection = new ColumnSelection(currentColumnSelection);
426 public FurtherActionPanel getCurrentFutherActionPanel()
428 return currentFurtherActionPanel;
431 public void setCurrentFutherActionPanel(
432 FurtherActionPanel currentFutherActionPanel)
434 this.currentFurtherActionPanel = currentFutherActionPanel;
437 public SearchPanel getCurrentSearchPanel()
439 return currentSearchPanel;
442 public void setCurrentSearchPanel(SearchPanel currentSearchPanel)
444 this.currentSearchPanel = currentSearchPanel;
447 public int getActionOption()
452 public void setActionOption(int actionOption)
454 this.actionOption = actionOption;
457 public StructureFilterPanel getCurrentStructureFilterPanel()
459 return currentStructureFilterPanel;
462 public void setCurrentStructureFilterPanel(
463 StructureFilterPanel currentStructureFilterPanel)
465 this.currentStructureFilterPanel = currentStructureFilterPanel;
468 public void select_action(ActionEvent actionEvent)
470 JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
471 if (radioButton.isSelected())
473 setActionOption(ACTION_OPTION_SELECT);
478 public void hide_action(ActionEvent actionEvent)
480 JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
481 if (radioButton.isSelected())
483 setActionOption(ACTION_OPTION_HIDE);
489 public void itemStateChanged(ItemEvent e)
491 selectedAnnotationChanged();
495 public void selectedAnnotationChanged()
497 String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
498 if (av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
499 .getSelectedIndex()]].graph != AlignmentAnnotation.NO_GRAPH)
501 currentView = AnnotationColumnChooser.GRAPH_VIEW;
504 gSearchPanel.syncState();
505 gFurtherActionPanel.syncState();
506 gStructureFilterPanel.syncState();
508 ngSearchPanel.syncState();
509 ngFurtherActionPanel.syncState();
510 ngStructureFilterPanel.syncState();
512 CardLayout switchableViewsLayout = (CardLayout) switchableViewsPanel
514 switchableViewsLayout.show(switchableViewsPanel, currentView);
518 public class FurtherActionPanel extends JPanel
520 private AnnotationColumnChooser aColChooser;
522 private JRadioButton hideOption = new JRadioButton();
524 private JRadioButton selectOption = new JRadioButton();
526 private ButtonGroup optionsGroup = new ButtonGroup();
528 public FurtherActionPanel(AnnotationColumnChooser aColChooser)
530 this.aColChooser = aColChooser;
531 JvSwingUtils.jvInitComponent(selectOption, "action.select");
532 selectOption.addActionListener(new ActionListener()
535 public void actionPerformed(ActionEvent actionEvent)
537 selectRadioAction(actionEvent);
541 JvSwingUtils.jvInitComponent(hideOption, "action.hide");
542 hideOption.addActionListener(new ActionListener()
545 public void actionPerformed(ActionEvent actionEvent)
547 hideRadioAction(actionEvent);
551 optionsGroup.add(selectOption);
552 optionsGroup.add(hideOption);
553 optionsGroup.setSelected(selectOption.getModel(), true);
555 JvSwingUtils.jvInitComponent(this);
558 this.add(selectOption);
559 this.add(hideOption);
562 public void selectRadioAction(ActionEvent actionEvent)
564 aColChooser.setCurrentFutherActionPanel(this);
565 aColChooser.select_action(actionEvent);
568 public void hideRadioAction(ActionEvent actionEvent)
570 aColChooser.setCurrentFutherActionPanel(this);
571 aColChooser.hide_action(actionEvent);
574 public void syncState()
576 if (aColChooser.getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
578 this.optionsGroup.setSelected(this.hideOption.getModel(), true);
582 this.optionsGroup.setSelected(this.selectOption.getModel(), true);
587 public class StructureFilterPanel extends JPanel
589 private AnnotationColumnChooser aColChooser;
591 private JCheckBox alphaHelix = new JCheckBox();
593 private JCheckBox betaStrand = new JCheckBox();
595 private JCheckBox turn = new JCheckBox();
597 private JCheckBox all = new JCheckBox();
599 public StructureFilterPanel(AnnotationColumnChooser aColChooser)
601 this.aColChooser = aColChooser;
603 JvSwingUtils.jvInitComponent(alphaHelix, "label.alpha_helix");
604 alphaHelix.addActionListener(new ActionListener()
607 public void actionPerformed(ActionEvent actionEvent)
609 alphaHelix_actionPerformed();
613 JvSwingUtils.jvInitComponent(betaStrand, "label.beta_strand");
614 betaStrand.addActionListener(new ActionListener()
617 public void actionPerformed(ActionEvent actionEvent)
619 betaStrand_actionPerformed();
623 JvSwingUtils.jvInitComponent(turn, "label.turn");
624 turn.addActionListener(new ActionListener()
627 public void actionPerformed(ActionEvent actionEvent)
629 turn_actionPerformed();
633 JvSwingUtils.jvInitComponent(all, "label.select_all");
634 all.addActionListener(new ActionListener()
637 public void actionPerformed(ActionEvent actionEvent)
639 all_actionPerformed();
643 this.setBorder(new TitledBorder(MessageManager
644 .getString("label.structures_filter")));
645 JvSwingUtils.jvInitComponent(this);
648 this.add(alphaHelix);
649 this.add(betaStrand);
653 public void alphaHelix_actionPerformed()
655 updateSelectAllState();
656 aColChooser.setCurrentStructureFilterPanel(this);
657 aColChooser.updateView();
660 public void betaStrand_actionPerformed()
662 updateSelectAllState();
663 aColChooser.setCurrentStructureFilterPanel(this);
664 aColChooser.updateView();
667 public void turn_actionPerformed()
669 updateSelectAllState();
670 aColChooser.setCurrentStructureFilterPanel(this);
671 aColChooser.updateView();
674 public void all_actionPerformed()
676 if (all.isSelected())
678 alphaHelix.setSelected(true);
679 betaStrand.setSelected(true);
680 turn.setSelected(true);
684 alphaHelix.setSelected(false);
685 betaStrand.setSelected(false);
686 turn.setSelected(false);
688 aColChooser.setCurrentStructureFilterPanel(this);
689 aColChooser.updateView();
692 public void updateSelectAllState()
694 if (alphaHelix.isSelected() && betaStrand.isSelected()
695 && turn.isSelected())
697 all.setSelected(true);
701 all.setSelected(false);
705 public void syncState()
707 StructureFilterPanel sfp = aColChooser
708 .getCurrentStructureFilterPanel();
711 alphaHelix.setSelected(sfp.alphaHelix.isSelected());
712 betaStrand.setSelected(sfp.betaStrand.isSelected());
713 turn.setSelected(sfp.turn.isSelected());
714 if (sfp.all.isSelected())
716 all.setSelected(true);
717 alphaHelix.setSelected(true);
718 betaStrand.setSelected(true);
719 turn.setSelected(true);
726 public class SearchPanel extends JPanel
728 private AnnotationColumnChooser aColChooser;
730 private JCheckBox displayName = new JCheckBox();
732 private JCheckBox description = new JCheckBox();
734 private JTextField searchBox = new JTextField(10);
736 public SearchPanel(AnnotationColumnChooser aColChooser)
739 this.aColChooser = aColChooser;
740 JvSwingUtils.jvInitComponent(this);
741 this.setBorder(new TitledBorder(MessageManager
742 .getString("label.search_filter")));
744 JvSwingUtils.jvInitComponent(searchBox);
745 searchBox.setToolTipText(MessageManager
746 .getString("info.enter_search_text_here"));
747 searchBox.getDocument().addDocumentListener(new DocumentListener()
750 public void insertUpdate(DocumentEvent e)
752 searchStringAction();
756 public void removeUpdate(DocumentEvent e)
758 searchStringAction();
762 public void changedUpdate(DocumentEvent e)
764 searchStringAction();
768 JvSwingUtils.jvInitComponent(displayName, "label.label");
769 displayName.setEnabled(false);
770 displayName.addActionListener(new ActionListener()
773 public void actionPerformed(ActionEvent actionEvent)
775 displayNameCheckboxAction();
779 JvSwingUtils.jvInitComponent(description, "label.description");
780 description.setEnabled(false);
781 description.addActionListener(new ActionListener()
784 public void actionPerformed(ActionEvent actionEvent)
786 discriptionCheckboxAction();
792 this.add(displayName);
793 this.add(description);
796 public void displayNameCheckboxAction()
798 aColChooser.setCurrentSearchPanel(this);
799 aColChooser.updateView();
802 public void discriptionCheckboxAction()
804 aColChooser.setCurrentSearchPanel(this);
805 aColChooser.updateView();
808 public void searchStringAction()
810 aColChooser.setCurrentSearchPanel(this);
811 aColChooser.updateView();
812 updateSearchPanelToolTips();
815 public void syncState()
817 SearchPanel sp = aColChooser.getCurrentSearchPanel();
820 description.setEnabled(sp.description.isEnabled());
821 description.setSelected(sp.description.isSelected());
823 displayName.setEnabled(sp.displayName.isEnabled());
824 displayName.setSelected(sp.displayName.isSelected());
826 searchBox.setText(sp.searchBox.getText());
828 updateSearchPanelToolTips();
831 public void updateSearchPanelToolTips()
833 String defaultTtip = MessageManager
834 .getString("info.enter_search_text_to_enable");
835 String labelTtip = MessageManager.formatMessage(
836 "info.search_in_annotation_label", annotations
837 .getSelectedItem().toString());
838 String descTtip = MessageManager.formatMessage(
839 "info.search_in_annotation_description", annotations
840 .getSelectedItem().toString());
841 displayName.setToolTipText(displayName.isEnabled() ? labelTtip
843 description.setToolTipText(description.isEnabled() ? descTtip