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.HiddenColumns;
25 import jalview.io.cache.JvCacheableInputBox;
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.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 HiddenColumns oldHiddenColumns;
90 protected int MIN_WIDTH = 420;
92 protected int MIN_HEIGHT = 430;
94 public AnnotationColumnChooser(AlignViewport av, final AlignmentPanel ap)
97 frame = new JInternalFrame();
98 frame.setContentPane(this);
99 frame.setLayer(JLayeredPane.PALETTE_LAYER);
100 Desktop.addInternalFrame(frame,
101 MessageManager.getString("label.select_by_annotation"), 520,
103 frame.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT));
105 addSliderChangeListener();
106 addSliderMouseListeners();
108 if (av.getAlignment().getAlignmentAnnotation() == null)
112 setOldHiddenColumns(av.getAlignment().getHiddenColumns());
115 setAnnotations(new JComboBox<String>(getAnnotationItems(false)));
116 populateThresholdComboBox(threshold);
117 AnnotationColumnChooser lastChooser = av
118 .getAnnotationColumnSelectionState();
119 // restore Object state from the previous session if one exists
120 if (lastChooser != null)
122 currentSearchPanel = lastChooser
123 .getCurrentSearchPanel();
124 currentStructureFilterPanel = lastChooser
125 .getCurrentStructureFilterPanel();
126 annotations.setSelectedIndex(lastChooser
127 .getAnnotations().getSelectedIndex());
128 threshold.setSelectedIndex(lastChooser
129 .getThreshold().getSelectedIndex());
130 actionOption = lastChooser
132 percentThreshold.setSelected(lastChooser.percentThreshold
139 } catch (Exception ex)
150 protected void jbInit()
154 JPanel thresholdPanel = new JPanel();
155 thresholdPanel.setBorder(new TitledBorder(MessageManager
156 .getString("label.threshold_filter")));
157 thresholdPanel.setBackground(Color.white);
158 thresholdPanel.setFont(JvSwingUtils.getLabelFont());
159 thresholdPanel.setLayout(new MigLayout("", "[left][right]", "[][]"));
161 percentThreshold.setBackground(Color.white);
162 percentThreshold.setFont(JvSwingUtils.getLabelFont());
164 JPanel actionPanel = new JPanel();
165 actionPanel.setBackground(Color.white);
166 actionPanel.setFont(JvSwingUtils.getLabelFont());
168 JPanel graphFilterView = new JPanel();
169 graphFilterView.setLayout(new MigLayout("", "[left][right]", "[][]"));
170 graphFilterView.setBackground(Color.white);
172 JPanel noGraphFilterView = new JPanel();
173 noGraphFilterView.setLayout(new MigLayout("", "[left][right]", "[][]"));
174 noGraphFilterView.setBackground(Color.white);
176 annotationComboBoxPanel.setBackground(Color.white);
177 annotationComboBoxPanel.setFont(JvSwingUtils.getLabelFont());
179 gSearchPanel = new SearchPanel(this);
180 ngSearchPanel = new SearchPanel(this);
181 gFurtherActionPanel = new FurtherActionPanel(this);
182 ngFurtherActionPanel = new FurtherActionPanel(this);
183 gStructureFilterPanel = new StructureFilterPanel(this);
184 ngStructureFilterPanel = new StructureFilterPanel(this);
186 thresholdPanel.add(getThreshold());
187 thresholdPanel.add(percentThreshold, "wrap");
188 thresholdPanel.add(slider, "grow");
189 thresholdPanel.add(thresholdValue, "span, wrap");
192 actionPanel.add(cancel);
194 graphFilterView.add(gSearchPanel, "grow, span, wrap");
195 graphFilterView.add(gStructureFilterPanel, "grow, span, wrap");
196 graphFilterView.add(thresholdPanel, "grow, span, wrap");
197 graphFilterView.add(gFurtherActionPanel);
199 noGraphFilterView.add(ngSearchPanel, "grow, span, wrap");
200 noGraphFilterView.add(ngStructureFilterPanel, "grow, span, wrap");
201 noGraphFilterView.add(ngFurtherActionPanel);
203 annotationComboBoxPanel.add(getAnnotations());
204 switchableViewsPanel.add(noGraphFilterView,
205 AnnotationColumnChooser.NO_GRAPH_VIEW);
206 switchableViewsPanel.add(graphFilterView,
207 AnnotationColumnChooser.GRAPH_VIEW);
209 this.setLayout(new BorderLayout());
210 this.add(annotationComboBoxPanel, java.awt.BorderLayout.PAGE_START);
211 this.add(switchableViewsPanel, java.awt.BorderLayout.CENTER);
212 this.add(actionPanel, java.awt.BorderLayout.SOUTH);
214 selectedAnnotationChanged();
215 updateThresholdPanelToolTip();
219 protected void updateThresholdPanelToolTip()
221 thresholdValue.setToolTipText("");
222 slider.setToolTipText("");
224 String defaultTtip = MessageManager
225 .getString("info.change_threshold_mode_to_enable");
227 String thresh = getThreshold().getSelectedItem().toString();
228 if (thresh.equalsIgnoreCase("No Threshold"))
230 thresholdValue.setToolTipText(defaultTtip);
231 slider.setToolTipText(defaultTtip);
236 protected void reset()
238 if (this.getOldHiddenColumns() != null)
240 av.getColumnSelection().clear();
242 if (av.getAnnotationColumnSelectionState() != null)
244 HiddenColumns oldHidden = av
245 .getAnnotationColumnSelectionState()
246 .getOldHiddenColumns();
247 if (oldHidden != null && oldHidden.getHiddenRegions() != null
248 && !oldHidden.getHiddenRegions().isEmpty())
250 for (Iterator<int[]> itr = oldHidden.getHiddenRegions()
251 .iterator(); itr.hasNext();)
253 int positions[] = itr.next();
254 av.hideColumns(positions[0], positions[1]);
257 av.getAlignment().setHiddenColumns(oldHidden);
259 ap.paintAlignment(true);
265 public void valueChanged(boolean updateAllAnnotation)
267 if (slider.isEnabled())
269 getCurrentAnnotation().threshold.value = slider.getValue() / 1000f;
271 propagateSeqAssociatedThreshold(updateAllAnnotation,
272 getCurrentAnnotation());
273 ap.paintAlignment(false);
278 public void updateView()
280 // Check if combobox is still adjusting
286 AnnotationFilterParameter filterParams = new AnnotationFilterParameter();
288 setCurrentAnnotation(av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
289 .getSelectedIndex()]]);
291 int selectedThresholdItem = getSelectedThresholdItem(getThreshold()
292 .getSelectedIndex());
294 slider.setEnabled(true);
295 thresholdValue.setEnabled(true);
296 percentThreshold.setEnabled(true);
298 if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
300 slider.setEnabled(false);
301 thresholdValue.setEnabled(false);
302 thresholdValue.setText("");
303 percentThreshold.setEnabled(false);
304 // build filter params
306 else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
308 if (getCurrentAnnotation().threshold == null)
310 getCurrentAnnotation()
312 new jalview.datamodel.GraphLine(
313 (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin) / 2f,
314 "Threshold", Color.black));
318 float range = getCurrentAnnotation().graphMax * 1000
319 - getCurrentAnnotation().graphMin * 1000;
321 slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
322 slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
323 slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000));
325 setThresholdValueText();
327 slider.setMajorTickSpacing((int) (range / 10f));
328 slider.setEnabled(true);
329 thresholdValue.setEnabled(true);
332 // build filter params
334 .setThresholdType(AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);
335 if (getCurrentAnnotation().isQuantitative())
338 .setThresholdValue(getCurrentAnnotation().threshold.value);
340 if (selectedThresholdItem == AnnotationColourGradient.ABOVE_THRESHOLD)
343 .setThresholdType(AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD);
345 else if (selectedThresholdItem == AnnotationColourGradient.BELOW_THRESHOLD)
348 .setThresholdType(AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD);
353 updateThresholdPanelToolTip();
354 if (currentStructureFilterPanel != null)
356 if (currentStructureFilterPanel.alphaHelix.isSelected())
358 filterParams.setFilterAlphaHelix(true);
360 if (currentStructureFilterPanel.betaStrand.isSelected())
362 filterParams.setFilterBetaSheet(true);
364 if (currentStructureFilterPanel.turn.isSelected())
366 filterParams.setFilterTurn(true);
370 if (currentSearchPanel != null)
372 if (!currentSearchPanel.searchBox.getUserInput().isEmpty())
374 filterParams.setRegexString(currentSearchPanel.searchBox
376 if (currentSearchPanel.displayName.isSelected())
379 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING);
381 if (currentSearchPanel.description.isSelected())
384 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION);
389 av.getColumnSelection().filterAnnotations(
390 getCurrentAnnotation().annotations, filterParams);
392 av.showAllHiddenColumns();
393 if (getActionOption() == ACTION_OPTION_HIDE)
395 av.hideSelectedColumns();
399 av.setAnnotationColumnSelectionState(this);
400 ap.paintAlignment(true);
403 public HiddenColumns getOldHiddenColumns()
405 return oldHiddenColumns;
408 public void setOldHiddenColumns(HiddenColumns currentHiddenColumns)
410 if (currentHiddenColumns != null)
412 this.oldHiddenColumns = new HiddenColumns(currentHiddenColumns);
416 public FurtherActionPanel getCurrentFutherActionPanel()
418 return currentFurtherActionPanel;
421 public void setCurrentFutherActionPanel(
422 FurtherActionPanel currentFutherActionPanel)
424 this.currentFurtherActionPanel = currentFutherActionPanel;
427 public SearchPanel getCurrentSearchPanel()
429 return currentSearchPanel;
432 public void setCurrentSearchPanel(SearchPanel currentSearchPanel)
434 this.currentSearchPanel = currentSearchPanel;
437 public int getActionOption()
442 public void setActionOption(int actionOption)
444 this.actionOption = actionOption;
447 public StructureFilterPanel getCurrentStructureFilterPanel()
449 return currentStructureFilterPanel;
452 public void setCurrentStructureFilterPanel(
453 StructureFilterPanel currentStructureFilterPanel)
455 this.currentStructureFilterPanel = currentStructureFilterPanel;
458 public void select_action(ActionEvent actionEvent)
460 JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
461 if (radioButton.isSelected())
463 setActionOption(ACTION_OPTION_SELECT);
468 public void hide_action(ActionEvent actionEvent)
470 JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
471 if (radioButton.isSelected())
473 setActionOption(ACTION_OPTION_HIDE);
479 public void itemStateChanged(ItemEvent e)
481 selectedAnnotationChanged();
485 public void selectedAnnotationChanged()
487 String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
488 if (av.getAlignment()
489 .getAlignmentAnnotation()[annmap[getAnnotations()
490 .getSelectedIndex()]].isQuantitative())
492 currentView = AnnotationColumnChooser.GRAPH_VIEW;
495 gSearchPanel.syncState();
496 gFurtherActionPanel.syncState();
497 gStructureFilterPanel.syncState();
499 ngSearchPanel.syncState();
500 ngFurtherActionPanel.syncState();
501 ngStructureFilterPanel.syncState();
503 CardLayout switchableViewsLayout = (CardLayout) switchableViewsPanel
505 switchableViewsLayout.show(switchableViewsPanel, currentView);
509 public class FurtherActionPanel extends JPanel
511 private AnnotationColumnChooser aColChooser;
513 private JRadioButton hideOption = new JRadioButton();
515 private JRadioButton selectOption = new JRadioButton();
517 private ButtonGroup optionsGroup = new ButtonGroup();
519 public FurtherActionPanel(AnnotationColumnChooser aColChooser)
521 this.aColChooser = aColChooser;
522 JvSwingUtils.jvInitComponent(selectOption, "action.select");
523 selectOption.addActionListener(new ActionListener()
526 public void actionPerformed(ActionEvent actionEvent)
528 selectRadioAction(actionEvent);
532 JvSwingUtils.jvInitComponent(hideOption, "action.hide");
533 hideOption.addActionListener(new ActionListener()
536 public void actionPerformed(ActionEvent actionEvent)
538 hideRadioAction(actionEvent);
542 optionsGroup.add(selectOption);
543 optionsGroup.add(hideOption);
544 optionsGroup.setSelected(selectOption.getModel(), true);
546 JvSwingUtils.jvInitComponent(this);
549 this.add(selectOption);
550 this.add(hideOption);
553 public void selectRadioAction(ActionEvent actionEvent)
555 aColChooser.setCurrentFutherActionPanel(this);
556 aColChooser.select_action(actionEvent);
559 public void hideRadioAction(ActionEvent actionEvent)
561 aColChooser.setCurrentFutherActionPanel(this);
562 aColChooser.hide_action(actionEvent);
565 public void syncState()
567 if (aColChooser.getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
569 this.optionsGroup.setSelected(this.hideOption.getModel(), true);
573 this.optionsGroup.setSelected(this.selectOption.getModel(), true);
578 public class StructureFilterPanel extends JPanel
580 private AnnotationColumnChooser aColChooser;
582 private JCheckBox alphaHelix = new JCheckBox();
584 private JCheckBox betaStrand = new JCheckBox();
586 private JCheckBox turn = new JCheckBox();
588 private JCheckBox all = new JCheckBox();
590 public StructureFilterPanel(AnnotationColumnChooser aColChooser)
592 this.aColChooser = aColChooser;
594 JvSwingUtils.jvInitComponent(alphaHelix, "label.alpha_helix");
595 alphaHelix.addActionListener(new ActionListener()
598 public void actionPerformed(ActionEvent actionEvent)
600 alphaHelix_actionPerformed();
604 JvSwingUtils.jvInitComponent(betaStrand, "label.beta_strand");
605 betaStrand.addActionListener(new ActionListener()
608 public void actionPerformed(ActionEvent actionEvent)
610 betaStrand_actionPerformed();
614 JvSwingUtils.jvInitComponent(turn, "label.turn");
615 turn.addActionListener(new ActionListener()
618 public void actionPerformed(ActionEvent actionEvent)
620 turn_actionPerformed();
624 JvSwingUtils.jvInitComponent(all, "label.select_all");
625 all.addActionListener(new ActionListener()
628 public void actionPerformed(ActionEvent actionEvent)
630 all_actionPerformed();
634 this.setBorder(new TitledBorder(MessageManager
635 .getString("label.structures_filter")));
636 JvSwingUtils.jvInitComponent(this);
639 this.add(alphaHelix);
640 this.add(betaStrand);
644 public void alphaHelix_actionPerformed()
646 updateSelectAllState();
647 aColChooser.setCurrentStructureFilterPanel(this);
648 aColChooser.updateView();
651 public void betaStrand_actionPerformed()
653 updateSelectAllState();
654 aColChooser.setCurrentStructureFilterPanel(this);
655 aColChooser.updateView();
658 public void turn_actionPerformed()
660 updateSelectAllState();
661 aColChooser.setCurrentStructureFilterPanel(this);
662 aColChooser.updateView();
665 public void all_actionPerformed()
667 if (all.isSelected())
669 alphaHelix.setSelected(true);
670 betaStrand.setSelected(true);
671 turn.setSelected(true);
675 alphaHelix.setSelected(false);
676 betaStrand.setSelected(false);
677 turn.setSelected(false);
679 aColChooser.setCurrentStructureFilterPanel(this);
680 aColChooser.updateView();
683 public void updateSelectAllState()
685 if (alphaHelix.isSelected() && betaStrand.isSelected()
686 && turn.isSelected())
688 all.setSelected(true);
692 all.setSelected(false);
696 public void syncState()
698 StructureFilterPanel sfp = aColChooser
699 .getCurrentStructureFilterPanel();
702 alphaHelix.setSelected(sfp.alphaHelix.isSelected());
703 betaStrand.setSelected(sfp.betaStrand.isSelected());
704 turn.setSelected(sfp.turn.isSelected());
705 if (sfp.all.isSelected())
707 all.setSelected(true);
708 alphaHelix.setSelected(true);
709 betaStrand.setSelected(true);
710 turn.setSelected(true);
717 public class SearchPanel extends JPanel
719 private AnnotationColumnChooser aColChooser;
721 private JCheckBox displayName = new JCheckBox();
723 private JCheckBox description = new JCheckBox();
725 private static final String FILTER_BY_ANN_CACHE_KEY = "CACHE.SELECT_FILTER_BY_ANNOT";
727 public JvCacheableInputBox<String> searchBox = new JvCacheableInputBox<String>(
728 FILTER_BY_ANN_CACHE_KEY);
730 public SearchPanel(AnnotationColumnChooser aColChooser)
733 this.aColChooser = aColChooser;
734 JvSwingUtils.jvInitComponent(this);
735 this.setBorder(new TitledBorder(MessageManager
736 .getString("label.search_filter")));
738 searchBox.setPrototypeDisplayValue("XXXXXXXXXXXXXXXXXXXXXXX");
739 searchBox.setToolTipText(MessageManager
740 .getString("info.enter_search_text_here"));
741 searchBox.getEditor().getEditorComponent()
742 .addKeyListener(new java.awt.event.KeyAdapter()
745 public void keyPressed(KeyEvent e)
747 if (e.getKeyCode() == KeyEvent.VK_ENTER)
750 searchStringAction();
757 JvSwingUtils.jvInitComponent(displayName, "label.label");
758 displayName.addActionListener(new ActionListener()
761 public void actionPerformed(ActionEvent actionEvent)
763 displayNameCheckboxAction();
767 JvSwingUtils.jvInitComponent(description, "label.description");
768 description.addActionListener(new ActionListener()
771 public void actionPerformed(ActionEvent actionEvent)
773 discriptionCheckboxAction();
779 this.add(displayName);
780 this.add(description);
783 public void displayNameCheckboxAction()
785 aColChooser.setCurrentSearchPanel(this);
786 aColChooser.updateView();
789 public void discriptionCheckboxAction()
791 aColChooser.setCurrentSearchPanel(this);
792 aColChooser.updateView();
795 public void searchStringAction()
797 aColChooser.setCurrentSearchPanel(this);
798 aColChooser.updateView();
799 updateSearchPanelToolTips();
800 searchBox.updateCache();
803 public void syncState()
805 SearchPanel sp = aColChooser.getCurrentSearchPanel();
808 description.setEnabled(sp.description.isEnabled());
809 description.setSelected(sp.description.isSelected());
811 displayName.setEnabled(sp.displayName.isEnabled());
812 displayName.setSelected(sp.displayName.isSelected());
814 searchBox.setSelectedItem(sp.searchBox.getUserInput());
816 updateSearchPanelToolTips();
819 public void updateSearchPanelToolTips()
821 String defaultTtip = MessageManager
822 .getString("info.enter_search_text_to_enable");
823 String labelTtip = MessageManager.formatMessage(
824 "info.search_in_annotation_label", annotations
825 .getSelectedItem().toString());
826 String descTtip = MessageManager.formatMessage(
827 "info.search_in_annotation_description", annotations
828 .getSelectedItem().toString());
829 displayName.setToolTipText(displayName.isEnabled() ? labelTtip
831 description.setToolTipText(description.isEnabled() ? descTtip
837 public void ok_actionPerformed()
840 super.ok_actionPerformed();
844 public void cancel_actionPerformed()
847 super.cancel_actionPerformed();
850 private void saveCache()
852 gSearchPanel.searchBox.persistCache();
853 ngSearchPanel.searchBox.persistCache();
854 gSearchPanel.searchBox.updateCache();
855 ngSearchPanel.searchBox.updateCache();