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.ColumnSelection;
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.Iterator;
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 ColumnSelection oldColumnSelection;
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 setOldColumnSelection(av.getColumnSelection());
145 Vector<String> list = new Vector<String>();
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);
171 // restore Object state from the previous session if one exists
172 if (av.getAnnotationColumnSelectionState() != null)
174 currentSearchPanel = av.getAnnotationColumnSelectionState()
175 .getCurrentSearchPanel();
176 currentStructureFilterPanel = av.getAnnotationColumnSelectionState()
177 .getCurrentStructureFilterPanel();
178 annotations.select(av.getAnnotationColumnSelectionState()
179 .getAnnotations().getSelectedIndex());
180 threshold.select(av.getAnnotationColumnSelectionState()
181 .getThreshold().getSelectedIndex());
182 actionOption = av.getAnnotationColumnSelectionState()
189 } catch (Exception ex)
199 private void jbInit() throws Exception
201 ok.setLabel(MessageManager.getString("action.ok"));
203 cancel.setLabel(MessageManager.getString("action.cancel"));
205 thresholdValue.setEnabled(false);
206 thresholdValue.setColumns(7);
207 thresholdValue.setCaretPosition(0);
209 ok.addActionListener(this);
210 cancel.addActionListener(this);
211 annotations.addItemListener(this);
212 thresholdValue.addActionListener(this);
213 threshold.addItemListener(this);
215 slider.setBackground(Color.white);
216 slider.setEnabled(false);
217 slider.setPreferredSize(new Dimension(100, 32));
219 thresholdPanel.setBackground(Color.white);
220 // thresholdPanel.setFont(JvSwingUtils.getLabelFont());
221 // thresholdPanel.setLayout(new MigLayout("", "[left][right]", "[][]"));
223 percentThreshold.setLabel("As percentage");
224 percentThreshold.addItemListener(this);
226 actionPanel.setBackground(Color.white);
227 // actionPanel.setFont(JvSwingUtils.getLabelFont());
229 graphFilterView.setLayout(gBorderLayout);
230 graphFilterView.setBackground(Color.white);
232 noGraphFilterView.setLayout(ngBorderLayout);
233 noGraphFilterView.setBackground(Color.white);
235 annotationComboBoxPanel.setBackground(Color.white);
236 // annotationComboBoxPanel.setFont(JvSwingUtils.getLabelFont());
238 gSearchPanel = new SearchPanel(this);
239 ngSearchPanel = new SearchPanel(this);
240 gFurtherActionPanel = new FurtherActionPanel(this);
241 ngFurtherActionPanel = new FurtherActionPanel(this);
242 gStructureFilterPanel = new StructureFilterPanel(this);
243 ngStructureFilterPanel = new StructureFilterPanel(this);
245 thresholdPanel.setTitle("Threshold Filter");
246 thresholdPanel.add(percentThreshold);
247 thresholdPanel.add(getThreshold());
248 thresholdPanel.add(slider);
249 thresholdPanel.add(thresholdValue);
252 actionPanel.add(cancel);
254 Panel staticPanel = new Panel();
255 staticPanel.setLayout(new BorderLayout());
256 staticPanel.setBackground(Color.white);
258 staticPanel.add(gSearchPanel, java.awt.BorderLayout.NORTH);
259 staticPanel.add(gStructureFilterPanel, java.awt.BorderLayout.SOUTH);
261 graphFilterView.add(staticPanel, java.awt.BorderLayout.NORTH);
262 graphFilterView.add(thresholdPanel, java.awt.BorderLayout.CENTER);
263 graphFilterView.add(gFurtherActionPanel, java.awt.BorderLayout.SOUTH);
265 noGraphFilterView.add(ngSearchPanel, java.awt.BorderLayout.PAGE_START);
266 noGraphFilterView.add(ngStructureFilterPanel,
267 java.awt.BorderLayout.CENTER);
268 noGraphFilterView.add(ngFurtherActionPanel,
269 java.awt.BorderLayout.CENTER);
271 annotationComboBoxPanel.add(getAnnotations());
272 switchableViewsPanel.add(noGraphFilterView,
273 AnnotationColumnChooser.NO_GRAPH_VIEW);
274 switchableViewsPanel.add(graphFilterView,
275 AnnotationColumnChooser.GRAPH_VIEW);
277 this.setLayout(borderLayout1);
278 this.add(annotationComboBoxPanel, java.awt.BorderLayout.PAGE_START);
279 this.add(switchableViewsPanel, java.awt.BorderLayout.CENTER);
280 this.add(actionPanel, java.awt.BorderLayout.SOUTH);
282 selectedAnnotationChanged();
287 @SuppressWarnings("unchecked")
290 if (this.getOldColumnSelection() != null)
292 av.getColumnSelection().clear();
294 if (av.getAnnotationColumnSelectionState() != null)
296 ColumnSelection oldSelection = av
297 .getAnnotationColumnSelectionState()
298 .getOldColumnSelection();
299 if (oldSelection != null && oldSelection.getHiddenColumns() != null
300 && !oldSelection.getHiddenColumns().isEmpty())
302 for (Iterator<int[]> itr = oldSelection.getHiddenColumns()
303 .iterator(); itr.hasNext();)
305 int positions[] = itr.next();
306 av.hideColumns(positions[0], positions[1]);
309 av.setColumnSelection(oldSelection);
311 ap.paintAlignment(true);
317 public void adjustmentValueChanged(AdjustmentEvent evt)
321 thresholdValue.setText((slider.getValue() / 1000f) + "");
322 valueChanged(!sliderDragging);
326 protected void addSliderMouseListeners()
329 slider.addMouseListener(new MouseAdapter()
332 public void mousePressed(MouseEvent e)
334 sliderDragging = true;
335 super.mousePressed(e);
339 public void mouseDragged(MouseEvent e)
341 sliderDragging = true;
342 super.mouseDragged(e);
346 public void mouseReleased(MouseEvent evt)
350 sliderDragging = false;
353 ap.paintAlignment(true);
359 public void valueChanged(boolean updateAllAnnotation)
361 if (slider.isEnabled())
363 getCurrentAnnotation().threshold.value = slider.getValue() / 1000f;
365 ap.paintAlignment(false);
369 public Choice getThreshold()
374 public void setThreshold(Choice threshold)
376 this.threshold = threshold;
379 public Choice getAnnotations()
384 public void setAnnotations(Choice annotations)
386 this.annotations = annotations;
390 public void updateView()
392 // Check if combobox is still adjusting
398 AnnotationFilterParameter filterParams = new AnnotationFilterParameter();
399 setCurrentAnnotation(av.getAlignment().getAlignmentAnnotation()[getAnnotations()
400 .getSelectedIndex()]);
402 int selectedThresholdItem = getSelectedThresholdItem(getThreshold()
403 .getSelectedIndex());
405 slider.setEnabled(true);
406 thresholdValue.setEnabled(true);
408 if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
410 slider.setEnabled(false);
411 thresholdValue.setEnabled(false);
412 thresholdValue.setText("");
413 // build filter params
415 else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
417 if (getCurrentAnnotation().threshold == null)
419 getCurrentAnnotation()
421 new jalview.datamodel.GraphLine(
422 (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin) / 2f,
423 "Threshold", Color.black));
427 float range = getCurrentAnnotation().graphMax * 1000
428 - getCurrentAnnotation().graphMin * 1000;
430 slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
431 slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
432 slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000));
433 setThresholdValueText();
434 // slider.setMajorTickSpacing((int) (range / 10f));
435 slider.setEnabled(true);
436 thresholdValue.setEnabled(true);
439 // build filter params
441 .setThresholdType(AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);
442 if (getCurrentAnnotation().graph != AlignmentAnnotation.NO_GRAPH)
445 .setThresholdValue(getCurrentAnnotation().threshold.value);
447 if (selectedThresholdItem == AnnotationColourGradient.ABOVE_THRESHOLD)
450 .setThresholdType(AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD);
452 else if (selectedThresholdItem == AnnotationColourGradient.BELOW_THRESHOLD)
455 .setThresholdType(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())
487 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING);
489 if (currentSearchPanel.description.getState())
492 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION);
497 currentSearchPanel.description.setEnabled(false);
498 currentSearchPanel.displayName.setEnabled(false);
502 av.getColumnSelection().filterAnnotations(
503 getCurrentAnnotation().annotations, filterParams);
505 av.showAllHiddenColumns();
506 if (getActionOption() == ACTION_OPTION_HIDE)
508 av.hideSelectedColumns();
512 av.setAnnotationColumnSelectionState(this);
513 ap.paintAlignment(true);
516 public ColumnSelection getOldColumnSelection()
518 return oldColumnSelection;
521 public void setOldColumnSelection(ColumnSelection currentColumnSelection)
523 if (currentColumnSelection != null)
525 this.oldColumnSelection = new ColumnSelection(currentColumnSelection);
529 public FurtherActionPanel getCurrentFutherActionPanel()
531 return currentFurtherActionPanel;
534 public void setCurrentFutherActionPanel(
535 FurtherActionPanel currentFutherActionPanel)
537 this.currentFurtherActionPanel = currentFutherActionPanel;
540 public SearchPanel getCurrentSearchPanel()
542 return currentSearchPanel;
545 public void setCurrentSearchPanel(SearchPanel currentSearchPanel)
547 this.currentSearchPanel = currentSearchPanel;
550 public int getActionOption()
555 public void setActionOption(int actionOption)
557 this.actionOption = actionOption;
560 public StructureFilterPanel getCurrentStructureFilterPanel()
562 return currentStructureFilterPanel;
565 public void setCurrentStructureFilterPanel(
566 StructureFilterPanel currentStructureFilterPanel)
568 this.currentStructureFilterPanel = currentStructureFilterPanel;
572 public void itemStateChanged(ItemEvent e)
574 if (e.getSource() == annotations)
576 selectedAnnotationChanged();
578 else if (e.getSource() == threshold)
580 threshold_actionPerformed(null);
582 else if (e.getSource() == percentThreshold)
586 percentageValue_actionPerformed();
592 public void selectedAnnotationChanged()
594 String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
595 if (av.getAlignment().getAlignmentAnnotation()[getAnnotations()
596 .getSelectedIndex()].graph != AlignmentAnnotation.NO_GRAPH)
598 currentView = AnnotationColumnChooser.GRAPH_VIEW;
601 gSearchPanel.syncState();
602 gFurtherActionPanel.syncState();
603 gStructureFilterPanel.syncState();
605 ngSearchPanel.syncState();
606 ngFurtherActionPanel.syncState();
607 ngStructureFilterPanel.syncState();
609 switchableViewsLayout.show(switchableViewsPanel, currentView);
613 public class FurtherActionPanel extends Panel implements ItemListener
615 private AnnotationColumnChooser aColChooser;
617 private Choice furtherAction = new Choice();
619 public FurtherActionPanel(AnnotationColumnChooser aColChooser)
621 this.aColChooser = aColChooser;
622 furtherAction.addItem("Select");
623 furtherAction.addItem("Hide");
624 furtherAction.addItemListener(this);
627 // this.setTitle("Filter Actions");
628 // this.setFont(JvSwingUtils.getLabelFont());
630 this.add(furtherAction);
633 public void syncState()
635 if (aColChooser.getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
637 furtherAction.select("Hide");
641 furtherAction.select("Select");
646 public void itemStateChanged(ItemEvent e)
648 aColChooser.setCurrentFutherActionPanel(this);
649 if (furtherAction.getSelectedItem().equalsIgnoreCase("Select"))
651 setActionOption(ACTION_OPTION_SELECT);
656 setActionOption(ACTION_OPTION_HIDE);
663 public class StructureFilterPanel extends TitledPanel implements
666 private AnnotationColumnChooser aColChooser;
668 private Checkbox alphaHelix = new Checkbox();
670 private Checkbox betaStrand = new Checkbox();
672 private Checkbox turn = new Checkbox();
674 private Checkbox all = new Checkbox();
676 public StructureFilterPanel(AnnotationColumnChooser aColChooser)
678 this.aColChooser = aColChooser;
680 alphaHelix.setLabel(MessageManager.getString("label.alpha_helix"));
681 alphaHelix.setBackground(Color.white);
683 alphaHelix.addItemListener(this);
685 betaStrand.setLabel(MessageManager.getString("label.beta_strand"));
686 betaStrand.setBackground(Color.white);
687 betaStrand.addItemListener(this);
689 turn.setLabel(MessageManager.getString("label.turn"));
690 turn.setBackground(Color.white);
691 turn.addItemListener(this);
693 all.setLabel(MessageManager.getString("label.select_all"));
694 all.setBackground(Color.white);
695 all.addItemListener(this);
697 this.setBackground(Color.white);
698 this.setTitle("Structure Filter");
699 // this.setFont(JvSwingUtils.getLabelFont());
702 this.add(alphaHelix);
703 this.add(betaStrand);
707 public void alphaHelix_actionPerformed()
709 updateSelectAllState();
710 aColChooser.setCurrentStructureFilterPanel(this);
711 aColChooser.updateView();
714 public void betaStrand_actionPerformed()
716 updateSelectAllState();
717 aColChooser.setCurrentStructureFilterPanel(this);
718 aColChooser.updateView();
721 public void turn_actionPerformed()
723 updateSelectAllState();
724 aColChooser.setCurrentStructureFilterPanel(this);
725 aColChooser.updateView();
728 public void all_actionPerformed()
732 alphaHelix.setState(true);
733 betaStrand.setState(true);
738 alphaHelix.setState(false);
739 betaStrand.setState(false);
740 turn.setState(false);
742 aColChooser.setCurrentStructureFilterPanel(this);
743 aColChooser.updateView();
746 public void updateSelectAllState()
748 if (alphaHelix.getState() && betaStrand.getState() && turn.getState())
758 public void syncState()
760 StructureFilterPanel sfp = aColChooser
761 .getCurrentStructureFilterPanel();
764 alphaHelix.setState(sfp.alphaHelix.getState());
765 betaStrand.setState(sfp.betaStrand.getState());
766 turn.setState(sfp.turn.getState());
767 if (sfp.all.getState())
770 alphaHelix.setState(true);
771 betaStrand.setState(true);
779 public void itemStateChanged(ItemEvent e)
781 if (e.getSource() == alphaHelix)
783 alphaHelix_actionPerformed();
785 else if (e.getSource() == betaStrand)
787 betaStrand_actionPerformed();
789 else if (e.getSource() == turn)
791 turn_actionPerformed();
793 else if (e.getSource() == all)
795 all_actionPerformed();
800 public class SearchPanel extends TitledPanel implements ItemListener
802 private AnnotationColumnChooser aColChooser;
804 private Checkbox displayName = new Checkbox();
806 private Checkbox description = new Checkbox();
808 private TextField searchBox = new TextField(10);
810 public SearchPanel(AnnotationColumnChooser aColChooser)
813 this.aColChooser = aColChooser;
814 searchBox.addTextListener(new TextListener()
818 public void textValueChanged(TextEvent e)
820 searchStringAction();
826 displayName.setLabel(MessageManager.getString("label.label"));
827 displayName.setEnabled(false);
828 displayName.addItemListener(this);
830 description.setLabel(MessageManager.getString("label.description"));
831 description.setEnabled(false);
832 description.addItemListener(this);
833 this.setTitle("Search Filter");
834 // this.setFont(JvSwingUtils.getLabelFont());
838 this.add(displayName);
839 this.add(description);
842 public void displayNameCheckboxAction()
844 aColChooser.setCurrentSearchPanel(this);
845 aColChooser.updateView();
848 public void discriptionCheckboxAction()
850 aColChooser.setCurrentSearchPanel(this);
851 aColChooser.updateView();
854 public void searchStringAction()
856 aColChooser.setCurrentSearchPanel(this);
857 aColChooser.updateView();
860 public void syncState()
862 SearchPanel sp = aColChooser.getCurrentSearchPanel();
865 description.setEnabled(sp.description.isEnabled());
866 description.setState(sp.description.getState());
868 displayName.setEnabled(sp.displayName.isEnabled());
869 displayName.setState(sp.displayName.getState());
871 searchBox.setText(sp.searchBox.getText());
876 public void itemStateChanged(ItemEvent e)
878 if (e.getSource() == displayName)
880 displayNameCheckboxAction();
882 else if (e.getSource() == description)
884 discriptionCheckboxAction();
891 public void actionPerformed(ActionEvent evt)
893 if (evt.getSource() == thresholdValue)
897 float f = new Float(thresholdValue.getText()).floatValue();
898 slider.setValue((int) (f * 1000));
899 adjustmentValueChanged(null);
900 } catch (NumberFormatException ex)
905 else if (evt.getSource() == ok)
907 ok_actionPerformed(null);
909 else if (evt.getSource() == cancel)
911 cancel_actionPerformed(null);
913 else if (evt.getSource() == thresholdValue)
915 thresholdValue_actionPerformed(null);
924 public void mouseClicked(MouseEvent e)
926 // TODO Auto-generated method stub
931 public void mousePressed(MouseEvent e)
933 if (e.getSource() == slider)
941 public void mouseReleased(MouseEvent e)
943 if (e.getSource() == slider)
950 public void mouseEntered(MouseEvent e)
952 if (e.getSource() == slider)
959 public void mouseExited(MouseEvent e)
961 if (e.getSource() == slider)