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.io.cache.JvCacheableInputBox;
27 import jalview.schemes.AnnotationColourGradient;
28 import jalview.util.MessageManager;
29 import jalview.viewmodel.annotationfilter.AnnotationFilterParameter;
31 import java.awt.BorderLayout;
32 import java.awt.CardLayout;
33 import java.awt.Color;
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.awt.event.KeyEvent;
39 import java.util.Iterator;
41 import javax.swing.ButtonGroup;
42 import javax.swing.JCheckBox;
43 import javax.swing.JComboBox;
44 import javax.swing.JInternalFrame;
45 import javax.swing.JLayeredPane;
46 import javax.swing.JPanel;
47 import javax.swing.JRadioButton;
48 import javax.swing.border.TitledBorder;
50 import net.miginfocom.swing.MigLayout;
52 @SuppressWarnings("serial")
53 public class AnnotationColumnChooser extends AnnotationRowFilter implements
56 private JPanel switchableViewsPanel = new JPanel(new CardLayout());
58 private JPanel annotationComboBoxPanel = new JPanel();
60 private StructureFilterPanel gStructureFilterPanel;
62 private StructureFilterPanel ngStructureFilterPanel;
64 private StructureFilterPanel currentStructureFilterPanel;
66 private SearchPanel currentSearchPanel;
68 private SearchPanel gSearchPanel;
70 private SearchPanel ngSearchPanel;
72 private FurtherActionPanel currentFurtherActionPanel;
74 private FurtherActionPanel gFurtherActionPanel;
76 private FurtherActionPanel ngFurtherActionPanel;
78 public static final int ACTION_OPTION_SELECT = 1;
80 public static int ACTION_OPTION_HIDE = 2;
82 public static String NO_GRAPH_VIEW = "0";
84 public static String GRAPH_VIEW = "1";
86 private int actionOption = ACTION_OPTION_SELECT;
88 private ColumnSelection oldColumnSelection;
90 public AnnotationColumnChooser(AlignViewport av, final AlignmentPanel ap)
93 frame = new JInternalFrame();
94 frame.setContentPane(this);
95 frame.setLayer(JLayeredPane.PALETTE_LAYER);
96 Desktop.addInternalFrame(frame,
97 MessageManager.getString("label.select_by_annotation"), 520,
100 addSliderChangeListener();
101 addSliderMouseListeners();
103 if (av.getAlignment().getAlignmentAnnotation() == null)
107 setOldColumnSelection(av.getColumnSelection());
110 setAnnotations(new JComboBox<String>(getAnnotationItems(false)));
111 populateThresholdComboBox(threshold);
113 // restore Object state from the previous session if one exists
114 if (av.getAnnotationColumnSelectionState() != null)
116 currentSearchPanel = av.getAnnotationColumnSelectionState()
117 .getCurrentSearchPanel();
118 currentStructureFilterPanel = av.getAnnotationColumnSelectionState()
119 .getCurrentStructureFilterPanel();
120 annotations.setSelectedIndex(av.getAnnotationColumnSelectionState()
121 .getAnnotations().getSelectedIndex());
122 threshold.setSelectedIndex(av.getAnnotationColumnSelectionState()
123 .getThreshold().getSelectedIndex());
124 actionOption = av.getAnnotationColumnSelectionState()
131 } catch (Exception ex)
142 protected void jbInit()
146 JPanel thresholdPanel = new JPanel();
147 thresholdPanel.setBorder(new TitledBorder(MessageManager
148 .getString("label.threshold_filter")));
149 thresholdPanel.setBackground(Color.white);
150 thresholdPanel.setFont(JvSwingUtils.getLabelFont());
151 thresholdPanel.setLayout(new MigLayout("", "[left][right]", "[][]"));
153 JPanel actionPanel = new JPanel();
154 actionPanel.setBackground(Color.white);
155 actionPanel.setFont(JvSwingUtils.getLabelFont());
157 JPanel graphFilterView = new JPanel();
158 graphFilterView.setLayout(new MigLayout("", "[left][right]", "[][]"));
159 graphFilterView.setBackground(Color.white);
161 JPanel noGraphFilterView = new JPanel();
162 noGraphFilterView.setLayout(new MigLayout("", "[left][right]", "[][]"));
163 noGraphFilterView.setBackground(Color.white);
165 annotationComboBoxPanel.setBackground(Color.white);
166 annotationComboBoxPanel.setFont(JvSwingUtils.getLabelFont());
168 gSearchPanel = new SearchPanel(this);
169 ngSearchPanel = new SearchPanel(this);
170 gFurtherActionPanel = new FurtherActionPanel(this);
171 ngFurtherActionPanel = new FurtherActionPanel(this);
172 gStructureFilterPanel = new StructureFilterPanel(this);
173 ngStructureFilterPanel = new StructureFilterPanel(this);
175 thresholdPanel.add(getThreshold());
176 thresholdPanel.add(thresholdValue, "wrap");
177 thresholdPanel.add(slider, "grow, span, wrap");
180 actionPanel.add(cancel);
182 graphFilterView.add(gSearchPanel, "grow, span, wrap");
183 graphFilterView.add(gStructureFilterPanel, "grow, span, wrap");
184 graphFilterView.add(thresholdPanel, "grow, span, wrap");
185 graphFilterView.add(gFurtherActionPanel);
187 noGraphFilterView.add(ngSearchPanel, "grow, span, wrap");
188 noGraphFilterView.add(ngStructureFilterPanel, "grow, span, wrap");
189 noGraphFilterView.add(ngFurtherActionPanel);
191 annotationComboBoxPanel.add(getAnnotations());
192 switchableViewsPanel.add(noGraphFilterView,
193 AnnotationColumnChooser.NO_GRAPH_VIEW);
194 switchableViewsPanel.add(graphFilterView,
195 AnnotationColumnChooser.GRAPH_VIEW);
197 this.setLayout(new BorderLayout());
198 this.add(annotationComboBoxPanel, java.awt.BorderLayout.PAGE_START);
199 this.add(switchableViewsPanel, java.awt.BorderLayout.CENTER);
200 this.add(actionPanel, java.awt.BorderLayout.SOUTH);
202 selectedAnnotationChanged();
203 updateThresholdPanelToolTip();
207 protected void updateThresholdPanelToolTip()
209 thresholdValue.setToolTipText("");
210 slider.setToolTipText("");
212 String defaultTtip = MessageManager
213 .getString("info.change_threshold_mode_to_enable");
215 String thresh = getThreshold().getSelectedItem().toString();
216 if (thresh.equalsIgnoreCase("No Threshold"))
218 thresholdValue.setToolTipText(defaultTtip);
219 slider.setToolTipText(defaultTtip);
224 protected void reset()
226 if (this.getOldColumnSelection() != null)
228 av.getColumnSelection().clear();
230 if (av.getAnnotationColumnSelectionState() != null)
232 ColumnSelection oldSelection = av
233 .getAnnotationColumnSelectionState()
234 .getOldColumnSelection();
235 if (oldSelection != null && oldSelection.getHiddenColumns() != null
236 && !oldSelection.getHiddenColumns().isEmpty())
238 for (Iterator<int[]> itr = oldSelection.getHiddenColumns()
239 .iterator(); itr.hasNext();)
241 int positions[] = itr.next();
242 av.hideColumns(positions[0], positions[1]);
245 av.setColumnSelection(oldSelection);
247 ap.paintAlignment(true);
253 public void valueChanged(boolean updateAllAnnotation)
255 if (slider.isEnabled())
257 getCurrentAnnotation().threshold.value = slider.getValue() / 1000f;
259 propagateSeqAssociatedThreshold(updateAllAnnotation,
260 getCurrentAnnotation());
261 ap.paintAlignment(false);
266 public void updateView()
268 // Check if combobox is still adjusting
274 AnnotationFilterParameter filterParams = new AnnotationFilterParameter();
276 setCurrentAnnotation(av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
277 .getSelectedIndex()]]);
279 int selectedThresholdItem = getSelectedThresholdItem(getThreshold()
280 .getSelectedIndex());
282 slider.setEnabled(true);
283 thresholdValue.setEnabled(true);
285 if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
287 slider.setEnabled(false);
288 thresholdValue.setEnabled(false);
289 thresholdValue.setText("");
290 // build filter params
292 else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
294 if (getCurrentAnnotation().threshold == null)
296 getCurrentAnnotation()
298 new jalview.datamodel.GraphLine(
299 (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin) / 2f,
300 "Threshold", Color.black));
304 float range = getCurrentAnnotation().graphMax * 1000
305 - getCurrentAnnotation().graphMin * 1000;
307 slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
308 slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
309 slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000));
310 thresholdValue.setText(getCurrentAnnotation().threshold.value + "");
311 slider.setMajorTickSpacing((int) (range / 10f));
312 slider.setEnabled(true);
313 thresholdValue.setEnabled(true);
316 // build filter params
318 .setThresholdType(AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);
319 if (getCurrentAnnotation().graph != AlignmentAnnotation.NO_GRAPH)
322 .setThresholdValue(getCurrentAnnotation().threshold.value);
324 if (selectedThresholdItem == AnnotationColourGradient.ABOVE_THRESHOLD)
327 .setThresholdType(AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD);
329 else if (selectedThresholdItem == AnnotationColourGradient.BELOW_THRESHOLD)
332 .setThresholdType(AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD);
337 updateThresholdPanelToolTip();
338 if (currentStructureFilterPanel != null)
340 if (currentStructureFilterPanel.alphaHelix.isSelected())
342 filterParams.setFilterAlphaHelix(true);
344 if (currentStructureFilterPanel.betaStrand.isSelected())
346 filterParams.setFilterBetaSheet(true);
348 if (currentStructureFilterPanel.turn.isSelected())
350 filterParams.setFilterTurn(true);
354 if (currentSearchPanel != null)
356 if (!currentSearchPanel.searchBox.getUserInput().isEmpty())
358 filterParams.setRegexString(currentSearchPanel.searchBox
360 if (currentSearchPanel.displayName.isSelected())
363 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING);
365 if (currentSearchPanel.description.isSelected())
368 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION);
373 av.getColumnSelection().filterAnnotations(
374 getCurrentAnnotation().annotations, filterParams);
376 av.showAllHiddenColumns();
377 if (getActionOption() == ACTION_OPTION_HIDE)
379 av.hideSelectedColumns();
383 av.setAnnotationColumnSelectionState(this);
384 ap.paintAlignment(true);
387 public ColumnSelection getOldColumnSelection()
389 return oldColumnSelection;
392 public void setOldColumnSelection(ColumnSelection currentColumnSelection)
394 if (currentColumnSelection != null)
396 this.oldColumnSelection = new ColumnSelection(currentColumnSelection);
400 public FurtherActionPanel getCurrentFutherActionPanel()
402 return currentFurtherActionPanel;
405 public void setCurrentFutherActionPanel(
406 FurtherActionPanel currentFutherActionPanel)
408 this.currentFurtherActionPanel = currentFutherActionPanel;
411 public SearchPanel getCurrentSearchPanel()
413 return currentSearchPanel;
416 public void setCurrentSearchPanel(SearchPanel currentSearchPanel)
418 this.currentSearchPanel = currentSearchPanel;
421 public int getActionOption()
426 public void setActionOption(int actionOption)
428 this.actionOption = actionOption;
431 public StructureFilterPanel getCurrentStructureFilterPanel()
433 return currentStructureFilterPanel;
436 public void setCurrentStructureFilterPanel(
437 StructureFilterPanel currentStructureFilterPanel)
439 this.currentStructureFilterPanel = currentStructureFilterPanel;
442 public void select_action(ActionEvent actionEvent)
444 JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
445 if (radioButton.isSelected())
447 setActionOption(ACTION_OPTION_SELECT);
452 public void hide_action(ActionEvent actionEvent)
454 JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
455 if (radioButton.isSelected())
457 setActionOption(ACTION_OPTION_HIDE);
463 public void itemStateChanged(ItemEvent e)
465 selectedAnnotationChanged();
469 public void selectedAnnotationChanged()
471 String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
472 if (av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
473 .getSelectedIndex()]].graph != AlignmentAnnotation.NO_GRAPH)
475 currentView = AnnotationColumnChooser.GRAPH_VIEW;
478 gSearchPanel.syncState();
479 gFurtherActionPanel.syncState();
480 gStructureFilterPanel.syncState();
482 ngSearchPanel.syncState();
483 ngFurtherActionPanel.syncState();
484 ngStructureFilterPanel.syncState();
486 CardLayout switchableViewsLayout = (CardLayout) switchableViewsPanel
488 switchableViewsLayout.show(switchableViewsPanel, currentView);
492 public class FurtherActionPanel extends JPanel
494 private AnnotationColumnChooser aColChooser;
496 private JRadioButton hideOption = new JRadioButton();
498 private JRadioButton selectOption = new JRadioButton();
500 private ButtonGroup optionsGroup = new ButtonGroup();
502 public FurtherActionPanel(AnnotationColumnChooser aColChooser)
504 this.aColChooser = aColChooser;
505 JvSwingUtils.jvInitComponent(selectOption, "action.select");
506 selectOption.addActionListener(new ActionListener()
509 public void actionPerformed(ActionEvent actionEvent)
511 selectRadioAction(actionEvent);
515 JvSwingUtils.jvInitComponent(hideOption, "action.hide");
516 hideOption.addActionListener(new ActionListener()
519 public void actionPerformed(ActionEvent actionEvent)
521 hideRadioAction(actionEvent);
525 optionsGroup.add(selectOption);
526 optionsGroup.add(hideOption);
527 optionsGroup.setSelected(selectOption.getModel(), true);
529 JvSwingUtils.jvInitComponent(this);
532 this.add(selectOption);
533 this.add(hideOption);
536 public void selectRadioAction(ActionEvent actionEvent)
538 aColChooser.setCurrentFutherActionPanel(this);
539 aColChooser.select_action(actionEvent);
542 public void hideRadioAction(ActionEvent actionEvent)
544 aColChooser.setCurrentFutherActionPanel(this);
545 aColChooser.hide_action(actionEvent);
548 public void syncState()
550 if (aColChooser.getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
552 this.optionsGroup.setSelected(this.hideOption.getModel(), true);
556 this.optionsGroup.setSelected(this.selectOption.getModel(), true);
561 public class StructureFilterPanel extends JPanel
563 private AnnotationColumnChooser aColChooser;
565 private JCheckBox alphaHelix = new JCheckBox();
567 private JCheckBox betaStrand = new JCheckBox();
569 private JCheckBox turn = new JCheckBox();
571 private JCheckBox all = new JCheckBox();
573 public StructureFilterPanel(AnnotationColumnChooser aColChooser)
575 this.aColChooser = aColChooser;
577 JvSwingUtils.jvInitComponent(alphaHelix, "label.alpha_helix");
578 alphaHelix.addActionListener(new ActionListener()
581 public void actionPerformed(ActionEvent actionEvent)
583 alphaHelix_actionPerformed();
587 JvSwingUtils.jvInitComponent(betaStrand, "label.beta_strand");
588 betaStrand.addActionListener(new ActionListener()
591 public void actionPerformed(ActionEvent actionEvent)
593 betaStrand_actionPerformed();
597 JvSwingUtils.jvInitComponent(turn, "label.turn");
598 turn.addActionListener(new ActionListener()
601 public void actionPerformed(ActionEvent actionEvent)
603 turn_actionPerformed();
607 JvSwingUtils.jvInitComponent(all, "label.select_all");
608 all.addActionListener(new ActionListener()
611 public void actionPerformed(ActionEvent actionEvent)
613 all_actionPerformed();
617 this.setBorder(new TitledBorder(MessageManager
618 .getString("label.structures_filter")));
619 JvSwingUtils.jvInitComponent(this);
622 this.add(alphaHelix);
623 this.add(betaStrand);
627 public void alphaHelix_actionPerformed()
629 updateSelectAllState();
630 aColChooser.setCurrentStructureFilterPanel(this);
631 aColChooser.updateView();
634 public void betaStrand_actionPerformed()
636 updateSelectAllState();
637 aColChooser.setCurrentStructureFilterPanel(this);
638 aColChooser.updateView();
641 public void turn_actionPerformed()
643 updateSelectAllState();
644 aColChooser.setCurrentStructureFilterPanel(this);
645 aColChooser.updateView();
648 public void all_actionPerformed()
650 if (all.isSelected())
652 alphaHelix.setSelected(true);
653 betaStrand.setSelected(true);
654 turn.setSelected(true);
658 alphaHelix.setSelected(false);
659 betaStrand.setSelected(false);
660 turn.setSelected(false);
662 aColChooser.setCurrentStructureFilterPanel(this);
663 aColChooser.updateView();
666 public void updateSelectAllState()
668 if (alphaHelix.isSelected() && betaStrand.isSelected()
669 && turn.isSelected())
671 all.setSelected(true);
675 all.setSelected(false);
679 public void syncState()
681 StructureFilterPanel sfp = aColChooser
682 .getCurrentStructureFilterPanel();
685 alphaHelix.setSelected(sfp.alphaHelix.isSelected());
686 betaStrand.setSelected(sfp.betaStrand.isSelected());
687 turn.setSelected(sfp.turn.isSelected());
688 if (sfp.all.isSelected())
690 all.setSelected(true);
691 alphaHelix.setSelected(true);
692 betaStrand.setSelected(true);
693 turn.setSelected(true);
700 public class SearchPanel extends JPanel
702 private AnnotationColumnChooser aColChooser;
704 private JCheckBox displayName = new JCheckBox();
706 private JCheckBox description = new JCheckBox();
708 private static final String FILTER_BY_ANN_CACHE_KEY = "CACHE.SELECT_FILTER_BY_ANNOT";
710 public JvCacheableInputBox<String> searchBox = new JvCacheableInputBox<String>(
711 FILTER_BY_ANN_CACHE_KEY);
713 public SearchPanel(AnnotationColumnChooser aColChooser)
716 this.aColChooser = aColChooser;
717 JvSwingUtils.jvInitComponent(this);
718 this.setBorder(new TitledBorder(MessageManager
719 .getString("label.search_filter")));
721 searchBox.setPrototypeDisplayValue("XXXXXXXXXXXXXXXXXXXXXXX");
722 searchBox.setToolTipText(MessageManager
723 .getString("info.enter_search_text_here"));
724 searchBox.getEditor().getEditorComponent()
725 .addKeyListener(new java.awt.event.KeyAdapter()
728 public void keyPressed(KeyEvent e)
730 if (e.getKeyCode() == KeyEvent.VK_ENTER)
733 searchStringAction();
740 JvSwingUtils.jvInitComponent(displayName, "label.label");
741 displayName.addActionListener(new ActionListener()
744 public void actionPerformed(ActionEvent actionEvent)
746 displayNameCheckboxAction();
750 JvSwingUtils.jvInitComponent(description, "label.description");
751 description.addActionListener(new ActionListener()
754 public void actionPerformed(ActionEvent actionEvent)
756 discriptionCheckboxAction();
762 this.add(displayName);
763 this.add(description);
766 public void displayNameCheckboxAction()
768 aColChooser.setCurrentSearchPanel(this);
769 aColChooser.updateView();
772 public void discriptionCheckboxAction()
774 aColChooser.setCurrentSearchPanel(this);
775 aColChooser.updateView();
778 public void searchStringAction()
780 aColChooser.setCurrentSearchPanel(this);
781 aColChooser.updateView();
782 updateSearchPanelToolTips();
783 searchBox.updateCache();
786 public void syncState()
788 SearchPanel sp = aColChooser.getCurrentSearchPanel();
791 description.setEnabled(sp.description.isEnabled());
792 description.setSelected(sp.description.isSelected());
794 displayName.setEnabled(sp.displayName.isEnabled());
795 displayName.setSelected(sp.displayName.isSelected());
797 searchBox.setSelectedItem(sp.searchBox.getUserInput());
799 updateSearchPanelToolTips();
802 public void updateSearchPanelToolTips()
804 String defaultTtip = MessageManager
805 .getString("info.enter_search_text_to_enable");
806 String labelTtip = MessageManager.formatMessage(
807 "info.search_in_annotation_label", annotations
808 .getSelectedItem().toString());
809 String descTtip = MessageManager.formatMessage(
810 "info.search_in_annotation_description", annotations
811 .getSelectedItem().toString());
812 displayName.setToolTipText(displayName.isEnabled() ? labelTtip
814 description.setToolTipText(description.isEnabled() ? descTtip
820 public void ok_actionPerformed()
823 super.ok_actionPerformed();
827 public void cancel_actionPerformed()
830 super.cancel_actionPerformed();
833 private void saveCache()
835 gSearchPanel.searchBox.persistCache();
836 ngSearchPanel.searchBox.persistCache();
837 gSearchPanel.searchBox.updateCache();
838 ngSearchPanel.searchBox.updateCache();