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.
21 package jalview.appletgui;
23 import jalview.datamodel.AlignmentAnnotation;
24 import jalview.datamodel.HiddenColumns;
25 import jalview.schemes.AnnotationColourGradient;
26 import jalview.util.MessageManager;
27 import jalview.viewmodel.annotationfilter.AnnotationFilterParameter;
29 import java.awt.BorderLayout;
30 import java.awt.CardLayout;
31 import java.awt.Checkbox;
32 import java.awt.Choice;
33 import java.awt.Color;
34 import java.awt.Dimension;
35 import java.awt.Frame;
36 import java.awt.Panel;
37 import java.awt.TextField;
38 import java.awt.event.ActionEvent;
39 import java.awt.event.ActionListener;
40 import java.awt.event.AdjustmentEvent;
41 import java.awt.event.AdjustmentListener;
42 import java.awt.event.ItemEvent;
43 import java.awt.event.ItemListener;
44 import java.awt.event.MouseAdapter;
45 import java.awt.event.MouseEvent;
46 import java.awt.event.MouseListener;
47 import java.awt.event.TextEvent;
48 import java.awt.event.TextListener;
49 import java.util.Vector;
51 //import javax.swing.JPanel;
53 //import net.miginfocom.swing.MigLayout;
55 public class AnnotationColumnChooser extends AnnotationRowFilter implements
56 ActionListener, AdjustmentListener, ItemListener, MouseListener
59 private Choice annotations = new Choice();
61 private Panel actionPanel = new Panel();
63 private TitledPanel thresholdPanel = new TitledPanel();
65 private Panel switchableViewsPanel = new Panel(new CardLayout());
67 private CardLayout switchableViewsLayout = (CardLayout) (switchableViewsPanel
70 private Panel noGraphFilterView = new Panel();
72 private Panel graphFilterView = new Panel();
74 private Panel annotationComboBoxPanel = new Panel();
76 private BorderLayout borderLayout1 = new BorderLayout();
78 private BorderLayout gBorderLayout = new BorderLayout();
80 private BorderLayout ngBorderLayout = new BorderLayout();
82 private Choice threshold = new Choice();
84 private StructureFilterPanel gStructureFilterPanel;
86 private StructureFilterPanel ngStructureFilterPanel;
88 private StructureFilterPanel currentStructureFilterPanel;
90 private SearchPanel currentSearchPanel;
92 private SearchPanel gSearchPanel;
94 private SearchPanel ngSearchPanel;
96 private FurtherActionPanel currentFurtherActionPanel;
98 private FurtherActionPanel gFurtherActionPanel;
100 private FurtherActionPanel ngFurtherActionPanel;
102 public static final int ACTION_OPTION_SELECT = 1;
104 public static int ACTION_OPTION_HIDE = 2;
106 public static String NO_GRAPH_VIEW = "0";
108 public static String GRAPH_VIEW = "1";
110 private int actionOption = ACTION_OPTION_SELECT;
112 private HiddenColumns oldHiddenColumns;
114 public AnnotationColumnChooser()
119 } catch (Exception ex)
121 ex.printStackTrace();
125 public AnnotationColumnChooser(AlignViewport av, final AlignmentPanel ap)
130 jalview.bin.JalviewLite.addFrame(frame,
131 MessageManager.getString("label.select_by_annotation"), 520,
134 slider.addAdjustmentListener(this);
135 slider.addMouseListener(this);
137 AlignmentAnnotation[] anns = av.getAlignment().getAlignmentAnnotation();
142 setOldHiddenColumns(av.getAlignment().getHiddenColumns());
144 Vector<String> list = new Vector<>();
146 for (int i = 0; i < anns.length; i++)
148 String label = anns[i].label;
149 if (anns[i].sequenceRef != null)
151 label = label + "_" + anns[i].sequenceRef.getName();
153 if (!list.contains(label))
155 list.addElement(label);
159 list.addElement(label + "_" + (index++));
163 for (int i = 0; i < list.size(); i++)
165 annotations.addItem(list.elementAt(i).toString());
168 populateThresholdComboBox(threshold);
169 AnnotationColumnChooser lastChooser = av
170 .getAnnotationColumnSelectionState();
171 // restore Object state from the previous session if one exists
172 if (lastChooser != null)
174 currentSearchPanel = lastChooser.getCurrentSearchPanel();
175 currentStructureFilterPanel = lastChooser
176 .getCurrentStructureFilterPanel();
177 annotations.select(lastChooser.getAnnotations().getSelectedIndex());
178 threshold.select(lastChooser.getThreshold().getSelectedIndex());
179 actionOption = lastChooser.getActionOption();
180 percentThreshold.setState(lastChooser.percentThreshold.getState());
186 } catch (Exception ex)
196 private void jbInit() throws Exception
198 ok.setLabel(MessageManager.getString("action.ok"));
200 cancel.setLabel(MessageManager.getString("action.cancel"));
202 thresholdValue.setEnabled(false);
203 thresholdValue.setColumns(7);
204 thresholdValue.setCaretPosition(0);
206 ok.addActionListener(this);
207 cancel.addActionListener(this);
208 annotations.addItemListener(this);
209 thresholdValue.addActionListener(this);
210 threshold.addItemListener(this);
212 slider.setBackground(Color.white);
213 slider.setEnabled(false);
214 slider.setPreferredSize(new Dimension(100, 32));
216 thresholdPanel.setBackground(Color.white);
217 // thresholdPanel.setFont(JvSwingUtils.getLabelFont());
218 // thresholdPanel.setLayout(new MigLayout("", "[left][right]", "[][]"));
220 percentThreshold.setLabel("As percentage");
221 percentThreshold.addItemListener(this);
223 actionPanel.setBackground(Color.white);
224 // actionPanel.setFont(JvSwingUtils.getLabelFont());
226 graphFilterView.setLayout(gBorderLayout);
227 graphFilterView.setBackground(Color.white);
229 noGraphFilterView.setLayout(ngBorderLayout);
230 noGraphFilterView.setBackground(Color.white);
232 annotationComboBoxPanel.setBackground(Color.white);
233 // annotationComboBoxPanel.setFont(JvSwingUtils.getLabelFont());
235 gSearchPanel = new SearchPanel(this);
236 ngSearchPanel = new SearchPanel(this);
237 gFurtherActionPanel = new FurtherActionPanel(this);
238 ngFurtherActionPanel = new FurtherActionPanel(this);
239 gStructureFilterPanel = new StructureFilterPanel(this);
240 ngStructureFilterPanel = new StructureFilterPanel(this);
242 thresholdPanel.setTitle("Threshold Filter");
243 thresholdPanel.add(getThreshold());
244 thresholdPanel.add(slider);
245 thresholdPanel.add(thresholdValue);
246 thresholdPanel.add(percentThreshold);
249 actionPanel.add(cancel);
251 Panel staticPanel = new Panel();
252 staticPanel.setLayout(new BorderLayout());
253 staticPanel.setBackground(Color.white);
255 staticPanel.add(gSearchPanel, java.awt.BorderLayout.NORTH);
256 staticPanel.add(gStructureFilterPanel, java.awt.BorderLayout.SOUTH);
258 graphFilterView.add(staticPanel, java.awt.BorderLayout.NORTH);
259 graphFilterView.add(thresholdPanel, java.awt.BorderLayout.CENTER);
260 graphFilterView.add(gFurtherActionPanel, java.awt.BorderLayout.SOUTH);
262 noGraphFilterView.add(ngSearchPanel, java.awt.BorderLayout.PAGE_START);
263 noGraphFilterView.add(ngStructureFilterPanel,
264 java.awt.BorderLayout.CENTER);
265 noGraphFilterView.add(ngFurtherActionPanel,
266 java.awt.BorderLayout.CENTER);
268 annotationComboBoxPanel.add(getAnnotations());
269 switchableViewsPanel.add(noGraphFilterView,
270 AnnotationColumnChooser.NO_GRAPH_VIEW);
271 switchableViewsPanel.add(graphFilterView,
272 AnnotationColumnChooser.GRAPH_VIEW);
274 this.setLayout(borderLayout1);
275 this.add(annotationComboBoxPanel, java.awt.BorderLayout.PAGE_START);
276 this.add(switchableViewsPanel, java.awt.BorderLayout.CENTER);
277 this.add(actionPanel, java.awt.BorderLayout.SOUTH);
279 selectedAnnotationChanged();
284 @SuppressWarnings("unchecked")
287 if (this.getOldHiddenColumns() != null)
289 av.getColumnSelection().clear();
291 if (av.getAnnotationColumnSelectionState() != null)
293 HiddenColumns oldHidden = av.getAnnotationColumnSelectionState()
294 .getOldHiddenColumns();
295 av.getAlignment().setHiddenColumns(oldHidden);
298 ap.paintAlignment(true);
304 public void adjustmentValueChanged(AdjustmentEvent evt)
308 setThresholdValueText();
309 valueChanged(!sliderDragging);
313 protected void addSliderMouseListeners()
316 slider.addMouseListener(new MouseAdapter()
319 public void mousePressed(MouseEvent e)
321 sliderDragging = true;
322 super.mousePressed(e);
326 public void mouseDragged(MouseEvent e)
328 sliderDragging = true;
329 super.mouseDragged(e);
333 public void mouseReleased(MouseEvent evt)
337 sliderDragging = false;
340 ap.paintAlignment(true);
346 public void valueChanged(boolean updateAllAnnotation)
348 if (slider.isEnabled())
350 getCurrentAnnotation().threshold.value = slider.getValue() / 1000f;
352 ap.paintAlignment(false);
356 public Choice getThreshold()
361 public void setThreshold(Choice threshold)
363 this.threshold = threshold;
366 public Choice getAnnotations()
371 public void setAnnotations(Choice annotations)
373 this.annotations = annotations;
377 public void updateView()
379 // Check if combobox is still adjusting
385 AnnotationFilterParameter filterParams = new AnnotationFilterParameter();
386 setCurrentAnnotation(av.getAlignment()
387 .getAlignmentAnnotation()[getAnnotations().getSelectedIndex()]);
389 int selectedThresholdItem = getSelectedThresholdItem(
390 getThreshold().getSelectedIndex());
392 slider.setEnabled(true);
393 thresholdValue.setEnabled(true);
394 percentThreshold.setEnabled(true);
396 if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
398 slider.setEnabled(false);
399 thresholdValue.setEnabled(false);
400 thresholdValue.setText("");
401 percentThreshold.setEnabled(false);
402 // build filter params
404 else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
406 if (getCurrentAnnotation().threshold == null)
408 getCurrentAnnotation().setThreshold(new jalview.datamodel.GraphLine(
409 (getCurrentAnnotation().graphMax
410 - getCurrentAnnotation().graphMin) / 2f,
411 "Threshold", Color.black));
415 // float range = getCurrentAnnotation().graphMax * 1000
416 // - getCurrentAnnotation().graphMin * 1000;
418 slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
419 slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
421 (int) (getCurrentAnnotation().threshold.value * 1000));
422 setThresholdValueText();
423 // slider.setMajorTickSpacing((int) (range / 10f));
424 slider.setEnabled(true);
425 thresholdValue.setEnabled(true);
426 percentThreshold.setEnabled(true);
429 // build filter params
430 filterParams.setThresholdType(
431 AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);
432 if (getCurrentAnnotation().isQuantitative())
435 .setThresholdValue(getCurrentAnnotation().threshold.value);
437 if (selectedThresholdItem == AnnotationColourGradient.ABOVE_THRESHOLD)
439 filterParams.setThresholdType(
440 AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD);
442 else if (selectedThresholdItem == AnnotationColourGradient.BELOW_THRESHOLD)
444 filterParams.setThresholdType(
445 AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD);
450 if (currentStructureFilterPanel != null)
452 if (currentStructureFilterPanel.alphaHelix.getState())
454 filterParams.setFilterAlphaHelix(true);
456 if (currentStructureFilterPanel.betaStrand.getState())
458 filterParams.setFilterBetaSheet(true);
460 if (currentStructureFilterPanel.turn.getState())
462 filterParams.setFilterTurn(true);
466 if (currentSearchPanel != null)
469 if (!currentSearchPanel.searchBox.getText().isEmpty())
471 currentSearchPanel.description.setEnabled(true);
472 currentSearchPanel.displayName.setEnabled(true);
473 filterParams.setRegexString(currentSearchPanel.searchBox.getText());
474 if (currentSearchPanel.displayName.getState())
476 filterParams.addRegexSearchField(
477 AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING);
479 if (currentSearchPanel.description.getState())
481 filterParams.addRegexSearchField(
482 AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION);
487 currentSearchPanel.description.setEnabled(false);
488 currentSearchPanel.displayName.setEnabled(false);
492 // show hidden columns here, before changing the column selection in
493 // filterAnnotations, because showing hidden columns has the side effect of
494 // adding them to the selection
495 av.showAllHiddenColumns();
496 av.getColumnSelection().filterAnnotations(
497 getCurrentAnnotation().annotations, filterParams);
499 if (getActionOption() == ACTION_OPTION_HIDE)
501 av.hideSelectedColumns();
505 av.setAnnotationColumnSelectionState(this);
507 ap.paintAlignment(true);
510 public HiddenColumns getOldHiddenColumns()
512 return oldHiddenColumns;
515 public void setOldHiddenColumns(HiddenColumns currentHiddenColumns)
517 if (currentHiddenColumns != null)
519 this.oldHiddenColumns = new HiddenColumns(currentHiddenColumns);
523 public FurtherActionPanel getCurrentFutherActionPanel()
525 return currentFurtherActionPanel;
528 public void setCurrentFutherActionPanel(
529 FurtherActionPanel currentFutherActionPanel)
531 this.currentFurtherActionPanel = currentFutherActionPanel;
534 public SearchPanel getCurrentSearchPanel()
536 return currentSearchPanel;
539 public void setCurrentSearchPanel(SearchPanel currentSearchPanel)
541 this.currentSearchPanel = currentSearchPanel;
544 public int getActionOption()
549 public void setActionOption(int actionOption)
551 this.actionOption = actionOption;
554 public StructureFilterPanel getCurrentStructureFilterPanel()
556 return currentStructureFilterPanel;
559 public void setCurrentStructureFilterPanel(
560 StructureFilterPanel currentStructureFilterPanel)
562 this.currentStructureFilterPanel = currentStructureFilterPanel;
566 public void itemStateChanged(ItemEvent e)
568 if (e.getSource() == annotations)
570 selectedAnnotationChanged();
572 else if (e.getSource() == threshold)
574 threshold_actionPerformed(null);
576 else if (e.getSource() == percentThreshold)
580 percentageValue_actionPerformed();
586 public void selectedAnnotationChanged()
588 String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
589 if (av.getAlignment().getAlignmentAnnotation()[getAnnotations()
590 .getSelectedIndex()].isQuantitative())
592 currentView = AnnotationColumnChooser.GRAPH_VIEW;
595 gSearchPanel.syncState();
596 gFurtherActionPanel.syncState();
597 gStructureFilterPanel.syncState();
599 ngSearchPanel.syncState();
600 ngFurtherActionPanel.syncState();
601 ngStructureFilterPanel.syncState();
603 switchableViewsLayout.show(switchableViewsPanel, currentView);
607 public class FurtherActionPanel extends Panel implements ItemListener
609 private AnnotationColumnChooser aColChooser;
611 private Choice furtherAction = new Choice();
613 public FurtherActionPanel(AnnotationColumnChooser aColChooser)
615 this.aColChooser = aColChooser;
616 furtherAction.addItem("Select");
617 furtherAction.addItem("Hide");
618 furtherAction.addItemListener(this);
621 // this.setTitle("Filter Actions");
622 // this.setFont(JvSwingUtils.getLabelFont());
624 this.add(furtherAction);
627 public void syncState()
630 .getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
632 furtherAction.select("Hide");
636 furtherAction.select("Select");
641 public void itemStateChanged(ItemEvent e)
643 aColChooser.setCurrentFutherActionPanel(this);
644 if (furtherAction.getSelectedItem().equalsIgnoreCase("Select"))
646 setActionOption(ACTION_OPTION_SELECT);
651 setActionOption(ACTION_OPTION_HIDE);
658 public class StructureFilterPanel extends TitledPanel
659 implements ItemListener
661 private AnnotationColumnChooser aColChooser;
663 private Checkbox alphaHelix = new Checkbox();
665 private Checkbox betaStrand = new Checkbox();
667 private Checkbox turn = new Checkbox();
669 private Checkbox all = new Checkbox();
671 public StructureFilterPanel(AnnotationColumnChooser aColChooser)
673 this.aColChooser = aColChooser;
675 alphaHelix.setLabel(MessageManager.getString("label.alpha_helix"));
676 alphaHelix.setBackground(Color.white);
678 alphaHelix.addItemListener(this);
680 betaStrand.setLabel(MessageManager.getString("label.beta_strand"));
681 betaStrand.setBackground(Color.white);
682 betaStrand.addItemListener(this);
684 turn.setLabel(MessageManager.getString("label.turn"));
685 turn.setBackground(Color.white);
686 turn.addItemListener(this);
688 all.setLabel(MessageManager.getString("label.select_all"));
689 all.setBackground(Color.white);
690 all.addItemListener(this);
692 this.setBackground(Color.white);
693 this.setTitle("Structure Filter");
694 // this.setFont(JvSwingUtils.getLabelFont());
697 this.add(alphaHelix);
698 this.add(betaStrand);
702 public void alphaHelix_actionPerformed()
704 updateSelectAllState();
705 aColChooser.setCurrentStructureFilterPanel(this);
706 aColChooser.updateView();
709 public void betaStrand_actionPerformed()
711 updateSelectAllState();
712 aColChooser.setCurrentStructureFilterPanel(this);
713 aColChooser.updateView();
716 public void turn_actionPerformed()
718 updateSelectAllState();
719 aColChooser.setCurrentStructureFilterPanel(this);
720 aColChooser.updateView();
723 public void all_actionPerformed()
727 alphaHelix.setState(true);
728 betaStrand.setState(true);
733 alphaHelix.setState(false);
734 betaStrand.setState(false);
735 turn.setState(false);
737 aColChooser.setCurrentStructureFilterPanel(this);
738 aColChooser.updateView();
741 public void updateSelectAllState()
743 if (alphaHelix.getState() && betaStrand.getState() && turn.getState())
753 public void syncState()
755 StructureFilterPanel sfp = aColChooser
756 .getCurrentStructureFilterPanel();
759 alphaHelix.setState(sfp.alphaHelix.getState());
760 betaStrand.setState(sfp.betaStrand.getState());
761 turn.setState(sfp.turn.getState());
762 if (sfp.all.getState())
765 alphaHelix.setState(true);
766 betaStrand.setState(true);
774 public void itemStateChanged(ItemEvent e)
776 if (e.getSource() == alphaHelix)
778 alphaHelix_actionPerformed();
780 else if (e.getSource() == betaStrand)
782 betaStrand_actionPerformed();
784 else if (e.getSource() == turn)
786 turn_actionPerformed();
788 else if (e.getSource() == all)
790 all_actionPerformed();
795 public class SearchPanel extends TitledPanel implements ItemListener
797 private AnnotationColumnChooser aColChooser;
799 private Checkbox displayName = new Checkbox();
801 private Checkbox description = new Checkbox();
803 private TextField searchBox = new TextField(10);
805 public SearchPanel(AnnotationColumnChooser aColChooser)
808 this.aColChooser = aColChooser;
809 searchBox.addTextListener(new TextListener()
813 public void textValueChanged(TextEvent e)
815 searchStringAction();
821 displayName.setLabel(MessageManager.getString("label.label"));
822 displayName.setEnabled(false);
823 displayName.addItemListener(this);
825 description.setLabel(MessageManager.getString("label.description"));
826 description.setEnabled(false);
827 description.addItemListener(this);
828 this.setTitle("Search Filter");
829 // this.setFont(JvSwingUtils.getLabelFont());
833 this.add(displayName);
834 this.add(description);
837 public void displayNameCheckboxAction()
839 aColChooser.setCurrentSearchPanel(this);
840 aColChooser.updateView();
843 public void discriptionCheckboxAction()
845 aColChooser.setCurrentSearchPanel(this);
846 aColChooser.updateView();
849 public void searchStringAction()
851 aColChooser.setCurrentSearchPanel(this);
852 aColChooser.updateView();
855 public void syncState()
857 SearchPanel sp = aColChooser.getCurrentSearchPanel();
860 description.setEnabled(sp.description.isEnabled());
861 description.setState(sp.description.getState());
863 displayName.setEnabled(sp.displayName.isEnabled());
864 displayName.setState(sp.displayName.getState());
866 searchBox.setText(sp.searchBox.getText());
871 public void itemStateChanged(ItemEvent e)
873 if (e.getSource() == displayName)
875 displayNameCheckboxAction();
877 else if (e.getSource() == description)
879 discriptionCheckboxAction();
886 public void actionPerformed(ActionEvent evt)
889 if (evt.getSource() == ok)
891 ok_actionPerformed(null);
893 else if (evt.getSource() == cancel)
895 cancel_actionPerformed(null);
897 else if (evt.getSource() == thresholdValue)
899 thresholdValue_actionPerformed(null);
908 public void mouseClicked(MouseEvent e)
910 // TODO Auto-generated method stub
915 public void mousePressed(MouseEvent e)
917 if (e.getSource() == slider)
925 public void mouseReleased(MouseEvent e)
927 if (e.getSource() == slider)
934 public void mouseEntered(MouseEvent e)
936 if (e.getSource() == slider)
943 public void mouseExited(MouseEvent e)
945 if (e.getSource() == slider)