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
133 } catch (Exception ex)
144 protected void jbInit()
148 JPanel thresholdPanel = new JPanel();
149 thresholdPanel.setBorder(new TitledBorder(MessageManager
150 .getString("label.threshold_filter")));
151 thresholdPanel.setBackground(Color.white);
152 thresholdPanel.setFont(JvSwingUtils.getLabelFont());
153 thresholdPanel.setLayout(new MigLayout("", "[left][right]", "[][]"));
155 percentThreshold.setBackground(Color.white);
156 percentThreshold.setFont(JvSwingUtils.getLabelFont());
158 JPanel actionPanel = new JPanel();
159 actionPanel.setBackground(Color.white);
160 actionPanel.setFont(JvSwingUtils.getLabelFont());
162 JPanel graphFilterView = new JPanel();
163 graphFilterView.setLayout(new MigLayout("", "[left][right]", "[][]"));
164 graphFilterView.setBackground(Color.white);
166 JPanel noGraphFilterView = new JPanel();
167 noGraphFilterView.setLayout(new MigLayout("", "[left][right]", "[][]"));
168 noGraphFilterView.setBackground(Color.white);
170 annotationComboBoxPanel.setBackground(Color.white);
171 annotationComboBoxPanel.setFont(JvSwingUtils.getLabelFont());
173 gSearchPanel = new SearchPanel(this);
174 ngSearchPanel = new SearchPanel(this);
175 gFurtherActionPanel = new FurtherActionPanel(this);
176 ngFurtherActionPanel = new FurtherActionPanel(this);
177 gStructureFilterPanel = new StructureFilterPanel(this);
178 ngStructureFilterPanel = new StructureFilterPanel(this);
180 thresholdPanel.add(getThreshold());
181 thresholdPanel.add(percentThreshold, "wrap");
182 thresholdPanel.add(slider, "grow");
183 thresholdPanel.add(thresholdValue, "span, wrap");
186 actionPanel.add(cancel);
188 graphFilterView.add(gSearchPanel, "grow, span, wrap");
189 graphFilterView.add(gStructureFilterPanel, "grow, span, wrap");
190 graphFilterView.add(thresholdPanel, "grow, span, wrap");
191 graphFilterView.add(gFurtherActionPanel);
193 noGraphFilterView.add(ngSearchPanel, "grow, span, wrap");
194 noGraphFilterView.add(ngStructureFilterPanel, "grow, span, wrap");
195 noGraphFilterView.add(ngFurtherActionPanel);
197 annotationComboBoxPanel.add(getAnnotations());
198 switchableViewsPanel.add(noGraphFilterView,
199 AnnotationColumnChooser.NO_GRAPH_VIEW);
200 switchableViewsPanel.add(graphFilterView,
201 AnnotationColumnChooser.GRAPH_VIEW);
203 this.setLayout(new BorderLayout());
204 this.add(annotationComboBoxPanel, java.awt.BorderLayout.PAGE_START);
205 this.add(switchableViewsPanel, java.awt.BorderLayout.CENTER);
206 this.add(actionPanel, java.awt.BorderLayout.SOUTH);
208 selectedAnnotationChanged();
209 updateThresholdPanelToolTip();
213 protected void updateThresholdPanelToolTip()
215 thresholdValue.setToolTipText("");
216 slider.setToolTipText("");
218 String defaultTtip = MessageManager
219 .getString("info.change_threshold_mode_to_enable");
221 String thresh = getThreshold().getSelectedItem().toString();
222 if (thresh.equalsIgnoreCase("No Threshold"))
224 thresholdValue.setToolTipText(defaultTtip);
225 slider.setToolTipText(defaultTtip);
230 protected void reset()
232 if (this.getOldColumnSelection() != null)
234 av.getColumnSelection().clear();
236 if (av.getAnnotationColumnSelectionState() != null)
238 ColumnSelection oldSelection = av
239 .getAnnotationColumnSelectionState()
240 .getOldColumnSelection();
241 if (oldSelection != null && oldSelection.getHiddenColumns() != null
242 && !oldSelection.getHiddenColumns().isEmpty())
244 for (Iterator<int[]> itr = oldSelection.getHiddenColumns()
245 .iterator(); itr.hasNext();)
247 int positions[] = itr.next();
248 av.hideColumns(positions[0], positions[1]);
251 av.setColumnSelection(oldSelection);
253 ap.paintAlignment(true);
259 public void valueChanged(boolean updateAllAnnotation)
261 if (slider.isEnabled())
263 getCurrentAnnotation().threshold.value = slider.getValue() / 1000f;
265 propagateSeqAssociatedThreshold(updateAllAnnotation,
266 getCurrentAnnotation());
267 ap.paintAlignment(false);
272 public void updateView()
274 // Check if combobox is still adjusting
280 AnnotationFilterParameter filterParams = new AnnotationFilterParameter();
282 setCurrentAnnotation(av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
283 .getSelectedIndex()]]);
285 int selectedThresholdItem = getSelectedThresholdItem(getThreshold()
286 .getSelectedIndex());
288 slider.setEnabled(true);
289 thresholdValue.setEnabled(true);
290 percentThreshold.setEnabled(true);
292 if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
294 slider.setEnabled(false);
295 thresholdValue.setEnabled(false);
296 thresholdValue.setText("");
297 percentThreshold.setEnabled(false);
298 // build filter params
300 else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
302 if (getCurrentAnnotation().threshold == null)
304 getCurrentAnnotation()
306 new jalview.datamodel.GraphLine(
307 (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin) / 2f,
308 "Threshold", Color.black));
312 float range = getCurrentAnnotation().graphMax * 1000
313 - getCurrentAnnotation().graphMin * 1000;
315 slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
316 slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
317 slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000));
319 if (percentThreshold.isSelected())
323 + ((getCurrentAnnotation().threshold.value - getCurrentAnnotation().graphMin) * 100f / (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin)));
327 thresholdValue.setText(getCurrentAnnotation().threshold.value + "");
330 slider.setMajorTickSpacing((int) (range / 10f));
331 slider.setEnabled(true);
332 thresholdValue.setEnabled(true);
335 // build filter params
337 .setThresholdType(AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);
338 if (getCurrentAnnotation().graph != AlignmentAnnotation.NO_GRAPH)
341 .setThresholdValue(getCurrentAnnotation().threshold.value);
343 if (selectedThresholdItem == AnnotationColourGradient.ABOVE_THRESHOLD)
346 .setThresholdType(AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD);
348 else if (selectedThresholdItem == AnnotationColourGradient.BELOW_THRESHOLD)
351 .setThresholdType(AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD);
356 updateThresholdPanelToolTip();
357 if (currentStructureFilterPanel != null)
359 if (currentStructureFilterPanel.alphaHelix.isSelected())
361 filterParams.setFilterAlphaHelix(true);
363 if (currentStructureFilterPanel.betaStrand.isSelected())
365 filterParams.setFilterBetaSheet(true);
367 if (currentStructureFilterPanel.turn.isSelected())
369 filterParams.setFilterTurn(true);
373 if (currentSearchPanel != null)
376 if (!currentSearchPanel.searchBox.getText().isEmpty())
378 currentSearchPanel.description.setEnabled(true);
379 currentSearchPanel.displayName.setEnabled(true);
380 filterParams.setRegexString(currentSearchPanel.searchBox.getText());
381 if (currentSearchPanel.displayName.isSelected())
384 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING);
386 if (currentSearchPanel.description.isSelected())
389 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION);
394 currentSearchPanel.description.setEnabled(false);
395 currentSearchPanel.displayName.setEnabled(false);
399 av.getColumnSelection().filterAnnotations(
400 getCurrentAnnotation().annotations, filterParams);
402 av.showAllHiddenColumns();
403 if (getActionOption() == ACTION_OPTION_HIDE)
405 av.hideSelectedColumns();
409 av.setAnnotationColumnSelectionState(this);
410 ap.paintAlignment(true);
414 public ColumnSelection getOldColumnSelection()
416 return oldColumnSelection;
419 public void setOldColumnSelection(ColumnSelection currentColumnSelection)
421 if (currentColumnSelection != null)
423 this.oldColumnSelection = new ColumnSelection(currentColumnSelection);
427 public FurtherActionPanel getCurrentFutherActionPanel()
429 return currentFurtherActionPanel;
432 public void setCurrentFutherActionPanel(
433 FurtherActionPanel currentFutherActionPanel)
435 this.currentFurtherActionPanel = currentFutherActionPanel;
438 public SearchPanel getCurrentSearchPanel()
440 return currentSearchPanel;
443 public void setCurrentSearchPanel(SearchPanel currentSearchPanel)
445 this.currentSearchPanel = currentSearchPanel;
448 public int getActionOption()
453 public void setActionOption(int actionOption)
455 this.actionOption = actionOption;
458 public StructureFilterPanel getCurrentStructureFilterPanel()
460 return currentStructureFilterPanel;
463 public void setCurrentStructureFilterPanel(
464 StructureFilterPanel currentStructureFilterPanel)
466 this.currentStructureFilterPanel = currentStructureFilterPanel;
469 public void select_action(ActionEvent actionEvent)
471 JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
472 if (radioButton.isSelected())
474 setActionOption(ACTION_OPTION_SELECT);
479 public void hide_action(ActionEvent actionEvent)
481 JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
482 if (radioButton.isSelected())
484 setActionOption(ACTION_OPTION_HIDE);
490 public void itemStateChanged(ItemEvent e)
492 selectedAnnotationChanged();
496 public void selectedAnnotationChanged()
498 String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
499 if (av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
500 .getSelectedIndex()]].graph != AlignmentAnnotation.NO_GRAPH)
502 currentView = AnnotationColumnChooser.GRAPH_VIEW;
505 gSearchPanel.syncState();
506 gFurtherActionPanel.syncState();
507 gStructureFilterPanel.syncState();
509 ngSearchPanel.syncState();
510 ngFurtherActionPanel.syncState();
511 ngStructureFilterPanel.syncState();
513 CardLayout switchableViewsLayout = (CardLayout) switchableViewsPanel
515 switchableViewsLayout.show(switchableViewsPanel, currentView);
519 public class FurtherActionPanel extends JPanel
521 private AnnotationColumnChooser aColChooser;
523 private JRadioButton hideOption = new JRadioButton();
525 private JRadioButton selectOption = new JRadioButton();
527 private ButtonGroup optionsGroup = new ButtonGroup();
529 public FurtherActionPanel(AnnotationColumnChooser aColChooser)
531 this.aColChooser = aColChooser;
532 JvSwingUtils.jvInitComponent(selectOption, "action.select");
533 selectOption.addActionListener(new ActionListener()
536 public void actionPerformed(ActionEvent actionEvent)
538 selectRadioAction(actionEvent);
542 JvSwingUtils.jvInitComponent(hideOption, "action.hide");
543 hideOption.addActionListener(new ActionListener()
546 public void actionPerformed(ActionEvent actionEvent)
548 hideRadioAction(actionEvent);
552 optionsGroup.add(selectOption);
553 optionsGroup.add(hideOption);
554 optionsGroup.setSelected(selectOption.getModel(), true);
556 JvSwingUtils.jvInitComponent(this);
559 this.add(selectOption);
560 this.add(hideOption);
563 public void selectRadioAction(ActionEvent actionEvent)
565 aColChooser.setCurrentFutherActionPanel(this);
566 aColChooser.select_action(actionEvent);
569 public void hideRadioAction(ActionEvent actionEvent)
571 aColChooser.setCurrentFutherActionPanel(this);
572 aColChooser.hide_action(actionEvent);
575 public void syncState()
577 if (aColChooser.getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
579 this.optionsGroup.setSelected(this.hideOption.getModel(), true);
583 this.optionsGroup.setSelected(this.selectOption.getModel(), true);
588 public class StructureFilterPanel extends JPanel
590 private AnnotationColumnChooser aColChooser;
592 private JCheckBox alphaHelix = new JCheckBox();
594 private JCheckBox betaStrand = new JCheckBox();
596 private JCheckBox turn = new JCheckBox();
598 private JCheckBox all = new JCheckBox();
600 public StructureFilterPanel(AnnotationColumnChooser aColChooser)
602 this.aColChooser = aColChooser;
604 JvSwingUtils.jvInitComponent(alphaHelix, "label.alpha_helix");
605 alphaHelix.addActionListener(new ActionListener()
608 public void actionPerformed(ActionEvent actionEvent)
610 alphaHelix_actionPerformed();
614 JvSwingUtils.jvInitComponent(betaStrand, "label.beta_strand");
615 betaStrand.addActionListener(new ActionListener()
618 public void actionPerformed(ActionEvent actionEvent)
620 betaStrand_actionPerformed();
624 JvSwingUtils.jvInitComponent(turn, "label.turn");
625 turn.addActionListener(new ActionListener()
628 public void actionPerformed(ActionEvent actionEvent)
630 turn_actionPerformed();
634 JvSwingUtils.jvInitComponent(all, "label.select_all");
635 all.addActionListener(new ActionListener()
638 public void actionPerformed(ActionEvent actionEvent)
640 all_actionPerformed();
644 this.setBorder(new TitledBorder(MessageManager
645 .getString("label.structures_filter")));
646 JvSwingUtils.jvInitComponent(this);
649 this.add(alphaHelix);
650 this.add(betaStrand);
654 public void alphaHelix_actionPerformed()
656 updateSelectAllState();
657 aColChooser.setCurrentStructureFilterPanel(this);
658 aColChooser.updateView();
661 public void betaStrand_actionPerformed()
663 updateSelectAllState();
664 aColChooser.setCurrentStructureFilterPanel(this);
665 aColChooser.updateView();
668 public void turn_actionPerformed()
670 updateSelectAllState();
671 aColChooser.setCurrentStructureFilterPanel(this);
672 aColChooser.updateView();
675 public void all_actionPerformed()
677 if (all.isSelected())
679 alphaHelix.setSelected(true);
680 betaStrand.setSelected(true);
681 turn.setSelected(true);
685 alphaHelix.setSelected(false);
686 betaStrand.setSelected(false);
687 turn.setSelected(false);
689 aColChooser.setCurrentStructureFilterPanel(this);
690 aColChooser.updateView();
693 public void updateSelectAllState()
695 if (alphaHelix.isSelected() && betaStrand.isSelected()
696 && turn.isSelected())
698 all.setSelected(true);
702 all.setSelected(false);
706 public void syncState()
708 StructureFilterPanel sfp = aColChooser
709 .getCurrentStructureFilterPanel();
712 alphaHelix.setSelected(sfp.alphaHelix.isSelected());
713 betaStrand.setSelected(sfp.betaStrand.isSelected());
714 turn.setSelected(sfp.turn.isSelected());
715 if (sfp.all.isSelected())
717 all.setSelected(true);
718 alphaHelix.setSelected(true);
719 betaStrand.setSelected(true);
720 turn.setSelected(true);
727 public class SearchPanel extends JPanel
729 private AnnotationColumnChooser aColChooser;
731 private JCheckBox displayName = new JCheckBox();
733 private JCheckBox description = new JCheckBox();
735 private JTextField searchBox = new JTextField(10);
737 public SearchPanel(AnnotationColumnChooser aColChooser)
740 this.aColChooser = aColChooser;
741 JvSwingUtils.jvInitComponent(this);
742 this.setBorder(new TitledBorder(MessageManager
743 .getString("label.search_filter")));
745 JvSwingUtils.jvInitComponent(searchBox);
746 searchBox.setToolTipText(MessageManager
747 .getString("info.enter_search_text_here"));
748 searchBox.getDocument().addDocumentListener(new DocumentListener()
751 public void insertUpdate(DocumentEvent e)
753 searchStringAction();
757 public void removeUpdate(DocumentEvent e)
759 searchStringAction();
763 public void changedUpdate(DocumentEvent e)
765 searchStringAction();
769 JvSwingUtils.jvInitComponent(displayName, "label.label");
770 displayName.setEnabled(false);
771 displayName.addActionListener(new ActionListener()
774 public void actionPerformed(ActionEvent actionEvent)
776 displayNameCheckboxAction();
780 JvSwingUtils.jvInitComponent(description, "label.description");
781 description.setEnabled(false);
782 description.addActionListener(new ActionListener()
785 public void actionPerformed(ActionEvent actionEvent)
787 discriptionCheckboxAction();
793 this.add(displayName);
794 this.add(description);
797 public void displayNameCheckboxAction()
799 aColChooser.setCurrentSearchPanel(this);
800 aColChooser.updateView();
803 public void discriptionCheckboxAction()
805 aColChooser.setCurrentSearchPanel(this);
806 aColChooser.updateView();
809 public void searchStringAction()
811 aColChooser.setCurrentSearchPanel(this);
812 aColChooser.updateView();
813 updateSearchPanelToolTips();
816 public void syncState()
818 SearchPanel sp = aColChooser.getCurrentSearchPanel();
821 description.setEnabled(sp.description.isEnabled());
822 description.setSelected(sp.description.isSelected());
824 displayName.setEnabled(sp.displayName.isEnabled());
825 displayName.setSelected(sp.displayName.isSelected());
827 searchBox.setText(sp.searchBox.getText());
829 updateSearchPanelToolTips();
832 public void updateSearchPanelToolTips()
834 String defaultTtip = MessageManager
835 .getString("info.enter_search_text_to_enable");
836 String labelTtip = MessageManager.formatMessage(
837 "info.search_in_annotation_label", annotations
838 .getSelectedItem().toString());
839 String descTtip = MessageManager.formatMessage(
840 "info.search_in_annotation_description", annotations
841 .getSelectedItem().toString());
842 displayName.setToolTipText(displayName.isEnabled() ? labelTtip
844 description.setToolTipText(description.isEnabled() ? descTtip