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.ArrayList;
50 import java.util.Vector;
52 //import javax.swing.JPanel;
54 //import net.miginfocom.swing.MigLayout;
56 public class AnnotationColumnChooser extends AnnotationRowFilter implements
57 ActionListener, AdjustmentListener, ItemListener, MouseListener
60 private Choice annotations = new Choice();
62 private Panel actionPanel = new Panel();
64 private TitledPanel thresholdPanel = new TitledPanel();
66 private Panel switchableViewsPanel = new Panel(new CardLayout());
68 private CardLayout switchableViewsLayout = (CardLayout) (switchableViewsPanel
71 private Panel noGraphFilterView = new Panel();
73 private Panel graphFilterView = new Panel();
75 private Panel annotationComboBoxPanel = new Panel();
77 private BorderLayout borderLayout1 = new BorderLayout();
79 private BorderLayout gBorderLayout = new BorderLayout();
81 private BorderLayout ngBorderLayout = new BorderLayout();
83 private Choice threshold = new Choice();
85 private StructureFilterPanel gStructureFilterPanel;
87 private StructureFilterPanel ngStructureFilterPanel;
89 private StructureFilterPanel currentStructureFilterPanel;
91 private SearchPanel currentSearchPanel;
93 private SearchPanel gSearchPanel;
95 private SearchPanel ngSearchPanel;
97 private FurtherActionPanel currentFurtherActionPanel;
99 private FurtherActionPanel gFurtherActionPanel;
101 private FurtherActionPanel ngFurtherActionPanel;
103 public static final int ACTION_OPTION_SELECT = 1;
105 public static int ACTION_OPTION_HIDE = 2;
107 public static String NO_GRAPH_VIEW = "0";
109 public static String GRAPH_VIEW = "1";
111 private int actionOption = ACTION_OPTION_SELECT;
113 private HiddenColumns oldHiddenColumns;
115 public AnnotationColumnChooser()
120 } catch (Exception ex)
122 ex.printStackTrace();
126 public AnnotationColumnChooser(AlignViewport av, final AlignmentPanel ap)
131 jalview.bin.JalviewLite.addFrame(frame,
132 MessageManager.getString("label.select_by_annotation"), 520,
135 slider.addAdjustmentListener(this);
136 slider.addMouseListener(this);
138 AlignmentAnnotation[] anns = av.getAlignment().getAlignmentAnnotation();
143 setOldHiddenColumns(av.getAlignment().getHiddenColumns());
145 Vector<String> list = new Vector<>();
147 for (int i = 0; i < anns.length; i++)
149 String label = anns[i].label;
150 if (anns[i].sequenceRef != null)
152 label = label + "_" + anns[i].sequenceRef.getName();
154 if (!list.contains(label))
156 list.addElement(label);
160 list.addElement(label + "_" + (index++));
164 for (int i = 0; i < list.size(); i++)
166 annotations.addItem(list.elementAt(i).toString());
169 populateThresholdComboBox(threshold);
170 AnnotationColumnChooser lastChooser = av
171 .getAnnotationColumnSelectionState();
172 // restore Object state from the previous session if one exists
173 if (lastChooser != null)
175 currentSearchPanel = lastChooser.getCurrentSearchPanel();
176 currentStructureFilterPanel = lastChooser
177 .getCurrentStructureFilterPanel();
178 annotations.select(lastChooser.getAnnotations().getSelectedIndex());
179 threshold.select(lastChooser.getThreshold().getSelectedIndex());
180 actionOption = lastChooser.getActionOption();
181 percentThreshold.setState(lastChooser.percentThreshold.getState());
187 } catch (Exception ex)
197 private void jbInit() throws Exception
199 ok.setLabel(MessageManager.getString("action.ok"));
201 cancel.setLabel(MessageManager.getString("action.cancel"));
203 thresholdValue.setEnabled(false);
204 thresholdValue.setColumns(7);
205 thresholdValue.setCaretPosition(0);
207 ok.addActionListener(this);
208 cancel.addActionListener(this);
209 annotations.addItemListener(this);
210 thresholdValue.addActionListener(this);
211 threshold.addItemListener(this);
213 slider.setBackground(Color.white);
214 slider.setEnabled(false);
215 slider.setPreferredSize(new Dimension(100, 32));
217 thresholdPanel.setBackground(Color.white);
218 // thresholdPanel.setFont(JvSwingUtils.getLabelFont());
219 // thresholdPanel.setLayout(new MigLayout("", "[left][right]", "[][]"));
221 percentThreshold.setLabel("As percentage");
222 percentThreshold.addItemListener(this);
224 actionPanel.setBackground(Color.white);
225 // actionPanel.setFont(JvSwingUtils.getLabelFont());
227 graphFilterView.setLayout(gBorderLayout);
228 graphFilterView.setBackground(Color.white);
230 noGraphFilterView.setLayout(ngBorderLayout);
231 noGraphFilterView.setBackground(Color.white);
233 annotationComboBoxPanel.setBackground(Color.white);
234 // annotationComboBoxPanel.setFont(JvSwingUtils.getLabelFont());
236 gSearchPanel = new SearchPanel(this);
237 ngSearchPanel = new SearchPanel(this);
238 gFurtherActionPanel = new FurtherActionPanel(this);
239 ngFurtherActionPanel = new FurtherActionPanel(this);
240 gStructureFilterPanel = new StructureFilterPanel(this);
241 ngStructureFilterPanel = new StructureFilterPanel(this);
243 thresholdPanel.setTitle("Threshold Filter");
244 thresholdPanel.add(getThreshold());
245 thresholdPanel.add(slider);
246 thresholdPanel.add(thresholdValue);
247 thresholdPanel.add(percentThreshold);
250 actionPanel.add(cancel);
252 Panel staticPanel = new Panel();
253 staticPanel.setLayout(new BorderLayout());
254 staticPanel.setBackground(Color.white);
256 staticPanel.add(gSearchPanel, java.awt.BorderLayout.NORTH);
257 staticPanel.add(gStructureFilterPanel, java.awt.BorderLayout.SOUTH);
259 graphFilterView.add(staticPanel, java.awt.BorderLayout.NORTH);
260 graphFilterView.add(thresholdPanel, java.awt.BorderLayout.CENTER);
261 graphFilterView.add(gFurtherActionPanel, java.awt.BorderLayout.SOUTH);
263 noGraphFilterView.add(ngSearchPanel, java.awt.BorderLayout.PAGE_START);
264 noGraphFilterView.add(ngStructureFilterPanel,
265 java.awt.BorderLayout.CENTER);
266 noGraphFilterView.add(ngFurtherActionPanel,
267 java.awt.BorderLayout.CENTER);
269 annotationComboBoxPanel.add(getAnnotations());
270 switchableViewsPanel.add(noGraphFilterView,
271 AnnotationColumnChooser.NO_GRAPH_VIEW);
272 switchableViewsPanel.add(graphFilterView,
273 AnnotationColumnChooser.GRAPH_VIEW);
275 this.setLayout(borderLayout1);
276 this.add(annotationComboBoxPanel, java.awt.BorderLayout.PAGE_START);
277 this.add(switchableViewsPanel, java.awt.BorderLayout.CENTER);
278 this.add(actionPanel, java.awt.BorderLayout.SOUTH);
280 selectedAnnotationChanged();
285 @SuppressWarnings("unchecked")
288 if (this.getOldHiddenColumns() != null)
290 av.getColumnSelection().clear();
292 if (av.getAnnotationColumnSelectionState() != null)
294 HiddenColumns oldHidden = av.getAnnotationColumnSelectionState()
295 .getOldHiddenColumns();
296 if (oldHidden != null)
298 ArrayList<int[]> regions = oldHidden.getHiddenColumnsCopy();
299 for (int[] positions : regions)
301 av.hideColumns(positions[0], positions[1]);
304 // TODO not clear why we need to hide all the columns (above) if we are
305 // going to copy the hidden columns over wholesale anyway
306 av.getAlignment().setHiddenColumns(oldHidden);
309 ap.paintAlignment(true, true);
315 public void adjustmentValueChanged(AdjustmentEvent evt)
319 setThresholdValueText();
320 valueChanged(!sliderDragging);
324 protected void addSliderMouseListeners()
327 slider.addMouseListener(new MouseAdapter()
330 public void mousePressed(MouseEvent e)
332 sliderDragging = true;
333 super.mousePressed(e);
337 public void mouseDragged(MouseEvent e)
339 sliderDragging = true;
340 super.mouseDragged(e);
344 public void mouseReleased(MouseEvent evt)
348 sliderDragging = false;
351 ap.paintAlignment(true, true);
357 public void valueChanged(boolean updateAllAnnotation)
359 if (slider.isEnabled())
361 getCurrentAnnotation().threshold.value = slider.getValue() / 1000f;
362 updateView(); // this also calls paintAlignment(true,true)
366 public Choice getThreshold()
371 public void setThreshold(Choice threshold)
373 this.threshold = threshold;
376 public Choice getAnnotations()
381 public void setAnnotations(Choice annotations)
383 this.annotations = annotations;
387 public void updateView()
389 // Check if combobox is still adjusting
395 AnnotationFilterParameter filterParams = new AnnotationFilterParameter();
396 setCurrentAnnotation(av.getAlignment()
397 .getAlignmentAnnotation()[getAnnotations().getSelectedIndex()]);
399 int selectedThresholdItem = getSelectedThresholdItem(
400 getThreshold().getSelectedIndex());
402 slider.setEnabled(true);
403 thresholdValue.setEnabled(true);
404 percentThreshold.setEnabled(true);
406 if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
408 slider.setEnabled(false);
409 thresholdValue.setEnabled(false);
410 thresholdValue.setText("");
411 percentThreshold.setEnabled(false);
412 // build filter params
414 else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
416 if (getCurrentAnnotation().threshold == null)
418 getCurrentAnnotation().setThreshold(new jalview.datamodel.GraphLine(
419 (getCurrentAnnotation().graphMax
420 - getCurrentAnnotation().graphMin) / 2f,
421 "Threshold", Color.black));
425 // float range = getCurrentAnnotation().graphMax * 1000
426 // - getCurrentAnnotation().graphMin * 1000;
428 slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
429 slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
431 (int) (getCurrentAnnotation().threshold.value * 1000));
432 setThresholdValueText();
433 // slider.setMajorTickSpacing((int) (range / 10f));
434 slider.setEnabled(true);
435 thresholdValue.setEnabled(true);
436 percentThreshold.setEnabled(true);
439 // build filter params
440 filterParams.setThresholdType(
441 AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);
442 if (getCurrentAnnotation().isQuantitative())
445 .setThresholdValue(getCurrentAnnotation().threshold.value);
447 if (selectedThresholdItem == AnnotationColourGradient.ABOVE_THRESHOLD)
449 filterParams.setThresholdType(
450 AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD);
452 else if (selectedThresholdItem == AnnotationColourGradient.BELOW_THRESHOLD)
454 filterParams.setThresholdType(
455 AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD);
460 if (currentStructureFilterPanel != null)
462 if (currentStructureFilterPanel.alphaHelix.getState())
464 filterParams.setFilterAlphaHelix(true);
466 if (currentStructureFilterPanel.betaStrand.getState())
468 filterParams.setFilterBetaSheet(true);
470 if (currentStructureFilterPanel.turn.getState())
472 filterParams.setFilterTurn(true);
476 if (currentSearchPanel != null)
479 if (!currentSearchPanel.searchBox.getText().isEmpty())
481 currentSearchPanel.description.setEnabled(true);
482 currentSearchPanel.displayName.setEnabled(true);
483 filterParams.setRegexString(currentSearchPanel.searchBox.getText());
484 if (currentSearchPanel.displayName.getState())
486 filterParams.addRegexSearchField(
487 AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING);
489 if (currentSearchPanel.description.getState())
491 filterParams.addRegexSearchField(
492 AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION);
497 currentSearchPanel.description.setEnabled(false);
498 currentSearchPanel.displayName.setEnabled(false);
502 // show hidden columns here, before changing the column selection in
503 // filterAnnotations, because showing hidden columns has the side effect of
504 // adding them to the selection
505 av.showAllHiddenColumns();
506 av.getColumnSelection().filterAnnotations(
507 getCurrentAnnotation().annotations, filterParams);
509 if (getActionOption() == ACTION_OPTION_HIDE)
511 av.hideSelectedColumns();
515 av.setAnnotationColumnSelectionState(this);
517 ap.paintAlignment(true, true);
520 public HiddenColumns getOldHiddenColumns()
522 return oldHiddenColumns;
525 public void setOldHiddenColumns(HiddenColumns currentHiddenColumns)
527 if (currentHiddenColumns != null)
529 this.oldHiddenColumns = new HiddenColumns(currentHiddenColumns);
533 public FurtherActionPanel getCurrentFutherActionPanel()
535 return currentFurtherActionPanel;
538 public void setCurrentFutherActionPanel(
539 FurtherActionPanel currentFutherActionPanel)
541 this.currentFurtherActionPanel = currentFutherActionPanel;
544 public SearchPanel getCurrentSearchPanel()
546 return currentSearchPanel;
549 public void setCurrentSearchPanel(SearchPanel currentSearchPanel)
551 this.currentSearchPanel = currentSearchPanel;
554 public int getActionOption()
559 public void setActionOption(int actionOption)
561 this.actionOption = actionOption;
564 public StructureFilterPanel getCurrentStructureFilterPanel()
566 return currentStructureFilterPanel;
569 public void setCurrentStructureFilterPanel(
570 StructureFilterPanel currentStructureFilterPanel)
572 this.currentStructureFilterPanel = currentStructureFilterPanel;
576 public void itemStateChanged(ItemEvent e)
578 if (e.getSource() == annotations)
580 selectedAnnotationChanged();
582 else if (e.getSource() == threshold)
584 threshold_actionPerformed(null);
586 else if (e.getSource() == percentThreshold)
590 percentageValue_actionPerformed();
596 public void selectedAnnotationChanged()
598 String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
599 if (av.getAlignment().getAlignmentAnnotation()[getAnnotations()
600 .getSelectedIndex()].isQuantitative())
602 currentView = AnnotationColumnChooser.GRAPH_VIEW;
605 gSearchPanel.syncState();
606 gFurtherActionPanel.syncState();
607 gStructureFilterPanel.syncState();
609 ngSearchPanel.syncState();
610 ngFurtherActionPanel.syncState();
611 ngStructureFilterPanel.syncState();
613 switchableViewsLayout.show(switchableViewsPanel, currentView);
617 public class FurtherActionPanel extends Panel implements ItemListener
619 private AnnotationColumnChooser aColChooser;
621 private Choice furtherAction = new Choice();
623 public FurtherActionPanel(AnnotationColumnChooser aColChooser)
625 this.aColChooser = aColChooser;
626 furtherAction.addItem("Select");
627 furtherAction.addItem("Hide");
628 furtherAction.addItemListener(this);
631 // this.setTitle("Filter Actions");
632 // this.setFont(JvSwingUtils.getLabelFont());
634 this.add(furtherAction);
637 public void syncState()
640 .getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
642 furtherAction.select("Hide");
646 furtherAction.select("Select");
651 public void itemStateChanged(ItemEvent e)
653 aColChooser.setCurrentFutherActionPanel(this);
654 if (furtherAction.getSelectedItem().equalsIgnoreCase("Select"))
656 setActionOption(ACTION_OPTION_SELECT);
661 setActionOption(ACTION_OPTION_HIDE);
668 public class StructureFilterPanel extends TitledPanel
669 implements ItemListener
671 private AnnotationColumnChooser aColChooser;
673 private Checkbox alphaHelix = new Checkbox();
675 private Checkbox betaStrand = new Checkbox();
677 private Checkbox turn = new Checkbox();
679 private Checkbox all = new Checkbox();
681 public StructureFilterPanel(AnnotationColumnChooser aColChooser)
683 this.aColChooser = aColChooser;
685 alphaHelix.setLabel(MessageManager.getString("label.alpha_helix"));
686 alphaHelix.setBackground(Color.white);
688 alphaHelix.addItemListener(this);
690 betaStrand.setLabel(MessageManager.getString("label.beta_strand"));
691 betaStrand.setBackground(Color.white);
692 betaStrand.addItemListener(this);
694 turn.setLabel(MessageManager.getString("label.turn"));
695 turn.setBackground(Color.white);
696 turn.addItemListener(this);
698 all.setLabel(MessageManager.getString("label.select_all"));
699 all.setBackground(Color.white);
700 all.addItemListener(this);
702 this.setBackground(Color.white);
703 this.setTitle("Structure Filter");
704 // this.setFont(JvSwingUtils.getLabelFont());
707 this.add(alphaHelix);
708 this.add(betaStrand);
712 public void alphaHelix_actionPerformed()
714 updateSelectAllState();
715 aColChooser.setCurrentStructureFilterPanel(this);
716 aColChooser.updateView();
719 public void betaStrand_actionPerformed()
721 updateSelectAllState();
722 aColChooser.setCurrentStructureFilterPanel(this);
723 aColChooser.updateView();
726 public void turn_actionPerformed()
728 updateSelectAllState();
729 aColChooser.setCurrentStructureFilterPanel(this);
730 aColChooser.updateView();
733 public void all_actionPerformed()
737 alphaHelix.setState(true);
738 betaStrand.setState(true);
743 alphaHelix.setState(false);
744 betaStrand.setState(false);
745 turn.setState(false);
747 aColChooser.setCurrentStructureFilterPanel(this);
748 aColChooser.updateView();
751 public void updateSelectAllState()
753 if (alphaHelix.getState() && betaStrand.getState() && turn.getState())
763 public void syncState()
765 StructureFilterPanel sfp = aColChooser
766 .getCurrentStructureFilterPanel();
769 alphaHelix.setState(sfp.alphaHelix.getState());
770 betaStrand.setState(sfp.betaStrand.getState());
771 turn.setState(sfp.turn.getState());
772 if (sfp.all.getState())
775 alphaHelix.setState(true);
776 betaStrand.setState(true);
784 public void itemStateChanged(ItemEvent e)
786 if (e.getSource() == alphaHelix)
788 alphaHelix_actionPerformed();
790 else if (e.getSource() == betaStrand)
792 betaStrand_actionPerformed();
794 else if (e.getSource() == turn)
796 turn_actionPerformed();
798 else if (e.getSource() == all)
800 all_actionPerformed();
805 public class SearchPanel extends TitledPanel implements ItemListener
807 private AnnotationColumnChooser aColChooser;
809 private Checkbox displayName = new Checkbox();
811 private Checkbox description = new Checkbox();
813 private TextField searchBox = new TextField(10);
815 public SearchPanel(AnnotationColumnChooser aColChooser)
818 this.aColChooser = aColChooser;
819 searchBox.addTextListener(new TextListener()
823 public void textValueChanged(TextEvent e)
825 searchStringAction();
831 displayName.setLabel(MessageManager.getString("label.label"));
832 displayName.setEnabled(false);
833 displayName.addItemListener(this);
835 description.setLabel(MessageManager.getString("label.description"));
836 description.setEnabled(false);
837 description.addItemListener(this);
838 this.setTitle("Search Filter");
839 // this.setFont(JvSwingUtils.getLabelFont());
843 this.add(displayName);
844 this.add(description);
847 public void displayNameCheckboxAction()
849 aColChooser.setCurrentSearchPanel(this);
850 aColChooser.updateView();
853 public void discriptionCheckboxAction()
855 aColChooser.setCurrentSearchPanel(this);
856 aColChooser.updateView();
859 public void searchStringAction()
861 aColChooser.setCurrentSearchPanel(this);
862 aColChooser.updateView();
865 public void syncState()
867 SearchPanel sp = aColChooser.getCurrentSearchPanel();
870 description.setEnabled(sp.description.isEnabled());
871 description.setState(sp.description.getState());
873 displayName.setEnabled(sp.displayName.isEnabled());
874 displayName.setState(sp.displayName.getState());
876 searchBox.setText(sp.searchBox.getText());
881 public void itemStateChanged(ItemEvent e)
883 if (e.getSource() == displayName)
885 displayNameCheckboxAction();
887 else if (e.getSource() == description)
889 discriptionCheckboxAction();
896 public void actionPerformed(ActionEvent evt)
899 if (evt.getSource() == ok)
901 ok_actionPerformed(null);
903 else if (evt.getSource() == cancel)
905 cancel_actionPerformed(null);
907 else if (evt.getSource() == thresholdValue)
909 thresholdValue_actionPerformed(null);
918 public void mouseClicked(MouseEvent e)
920 // TODO Auto-generated method stub
925 public void mousePressed(MouseEvent e)
927 if (e.getSource() == slider)
935 public void mouseReleased(MouseEvent e)
937 if (e.getSource() == slider)
944 public void mouseEntered(MouseEvent e)
946 if (e.getSource() == slider)
953 public void mouseExited(MouseEvent e)
955 if (e.getSource() == slider)