2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9.0b2)
3 * Copyright (C) 2015 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 if (av.getAlignment().getAlignmentAnnotation() == null)
142 setOldColumnSelection(av.getColumnSelection());
144 Vector list = new Vector();
146 for (int i = 0; i < av.getAlignment().getAlignmentAnnotation().length; i++)
148 String label = av.getAlignment().getAlignmentAnnotation()[i].label;
149 if (!list.contains(label))
151 list.addElement(label);
155 list.addElement(label + "_" + (index++));
159 for (int i = 0; i < list.size(); i++)
161 annotations.addItem(list.elementAt(i).toString());
164 populateThresholdComboBox(threshold);
166 // restore Object state from the previous session if one exists
167 if (av.getAnnotationColumnSelectionState() != null)
169 currentSearchPanel = av.getAnnotationColumnSelectionState()
170 .getCurrentSearchPanel();
171 currentStructureFilterPanel = av.getAnnotationColumnSelectionState()
172 .getCurrentStructureFilterPanel();
173 annotations.select(av.getAnnotationColumnSelectionState()
174 .getAnnotations().getSelectedIndex());
175 threshold.select(av.getAnnotationColumnSelectionState()
176 .getThreshold().getSelectedIndex());
177 actionOption = av.getAnnotationColumnSelectionState()
184 } catch (Exception ex)
194 private void jbInit() throws Exception
196 ok.setLabel(MessageManager.getString("action.ok"));
198 cancel.setLabel(MessageManager.getString("action.cancel"));
200 thresholdValue.setEnabled(false);
201 thresholdValue.setColumns(7);
203 ok.addActionListener(this);
204 cancel.addActionListener(this);
205 annotations.addItemListener(this);
206 thresholdValue.addActionListener(this);
207 threshold.addItemListener(this);
209 slider.setBackground(Color.white);
210 slider.setEnabled(false);
211 slider.setPreferredSize(new Dimension(100, 32));
213 thresholdPanel.setBackground(Color.white);
214 // thresholdPanel.setFont(JvSwingUtils.getLabelFont());
215 // thresholdPanel.setLayout(new MigLayout("", "[left][right]", "[][]"));
217 actionPanel.setBackground(Color.white);
218 // actionPanel.setFont(JvSwingUtils.getLabelFont());
220 graphFilterView.setLayout(gBorderLayout);
221 graphFilterView.setBackground(Color.white);
223 noGraphFilterView.setLayout(ngBorderLayout);
224 noGraphFilterView.setBackground(Color.white);
226 annotationComboBoxPanel.setBackground(Color.white);
227 // annotationComboBoxPanel.setFont(JvSwingUtils.getLabelFont());
229 gSearchPanel = new SearchPanel(this);
230 ngSearchPanel = new SearchPanel(this);
231 gFurtherActionPanel = new FurtherActionPanel(this);
232 ngFurtherActionPanel = new FurtherActionPanel(this);
233 gStructureFilterPanel = new StructureFilterPanel(this);
234 ngStructureFilterPanel = new StructureFilterPanel(this);
236 thresholdPanel.setTitle("Threshold Filter");
237 thresholdPanel.add(getThreshold());
238 thresholdPanel.add(slider);
239 thresholdPanel.add(thresholdValue);
242 actionPanel.add(cancel);
244 Panel staticPanel = new Panel();
245 staticPanel.setLayout(new BorderLayout());
246 staticPanel.setBackground(Color.white);
248 staticPanel.add(gSearchPanel, java.awt.BorderLayout.NORTH);
249 staticPanel.add(gStructureFilterPanel, java.awt.BorderLayout.SOUTH);
251 graphFilterView.add(staticPanel, java.awt.BorderLayout.NORTH);
252 graphFilterView.add(thresholdPanel, java.awt.BorderLayout.CENTER);
253 graphFilterView.add(gFurtherActionPanel, java.awt.BorderLayout.SOUTH);
255 noGraphFilterView.add(ngSearchPanel, java.awt.BorderLayout.PAGE_START);
256 noGraphFilterView.add(ngStructureFilterPanel,
257 java.awt.BorderLayout.CENTER);
258 noGraphFilterView.add(ngFurtherActionPanel,
259 java.awt.BorderLayout.CENTER);
261 annotationComboBoxPanel.add(getAnnotations());
262 switchableViewsPanel.add(noGraphFilterView,
263 AnnotationColumnChooser.NO_GRAPH_VIEW);
264 switchableViewsPanel.add(graphFilterView,
265 AnnotationColumnChooser.GRAPH_VIEW);
267 this.setLayout(borderLayout1);
268 this.add(annotationComboBoxPanel, java.awt.BorderLayout.PAGE_START);
269 this.add(switchableViewsPanel, java.awt.BorderLayout.CENTER);
270 this.add(actionPanel, java.awt.BorderLayout.SOUTH);
272 selectedAnnotationChanged();
276 @SuppressWarnings("unchecked")
279 if (this.getOldColumnSelection() != null)
281 av.getColumnSelection().clear();
283 if (av.getAnnotationColumnSelectionState() != null)
285 ColumnSelection oldSelection = av
286 .getAnnotationColumnSelectionState()
287 .getOldColumnSelection();
288 if (oldSelection != null && oldSelection.getHiddenColumns() != null
289 && !oldSelection.getHiddenColumns().isEmpty())
291 for (Iterator<int[]> itr = oldSelection.getHiddenColumns()
292 .iterator(); itr.hasNext();)
294 int positions[] = itr.next();
295 av.hideColumns(positions[0], positions[1]);
298 av.setColumnSelection(oldSelection);
300 ap.paintAlignment(true);
305 public void adjustmentValueChanged(AdjustmentEvent evt)
309 thresholdValue.setText((slider.getValue() / 1000f) + "");
310 valueChanged(!sliderDragging);
314 protected void addSliderMouseListeners()
317 slider.addMouseListener(new MouseAdapter()
320 public void mousePressed(MouseEvent e)
322 sliderDragging = true;
323 super.mousePressed(e);
327 public void mouseDragged(MouseEvent e)
329 sliderDragging = true;
330 super.mouseDragged(e);
334 public void mouseReleased(MouseEvent evt)
338 sliderDragging = false;
341 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().getAlignmentAnnotation()[getAnnotations()
387 .getSelectedIndex()]);
389 int selectedThresholdItem = getSelectedThresholdItem(getThreshold()
390 .getSelectedIndex());
392 slider.setEnabled(true);
393 thresholdValue.setEnabled(true);
395 if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
397 slider.setEnabled(false);
398 thresholdValue.setEnabled(false);
399 thresholdValue.setText("");
400 // build filter params
402 else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
404 if (getCurrentAnnotation().threshold == null)
406 getCurrentAnnotation()
408 new jalview.datamodel.GraphLine(
409 (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin) / 2f,
410 "Threshold", Color.black));
414 float range = getCurrentAnnotation().graphMax * 1000
415 - getCurrentAnnotation().graphMin * 1000;
417 slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
418 slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
419 slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000));
420 thresholdValue.setText(getCurrentAnnotation().threshold.value + "");
421 // slider.setMajorTickSpacing((int) (range / 10f));
422 slider.setEnabled(true);
423 thresholdValue.setEnabled(true);
426 // build filter params
428 .setThresholdType(AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);
429 if (getCurrentAnnotation().graph != AlignmentAnnotation.NO_GRAPH)
432 .setThresholdValue(getCurrentAnnotation().threshold.value);
434 if (selectedThresholdItem == AnnotationColourGradient.ABOVE_THRESHOLD)
437 .setThresholdType(AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD);
439 else if (selectedThresholdItem == AnnotationColourGradient.BELOW_THRESHOLD)
442 .setThresholdType(AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD);
447 if (currentStructureFilterPanel != null)
449 if (currentStructureFilterPanel.alphaHelix.getState())
451 filterParams.setFilterAlphaHelix(true);
453 if (currentStructureFilterPanel.betaStrand.getState())
455 filterParams.setFilterBetaSheet(true);
457 if (currentStructureFilterPanel.turn.getState())
459 filterParams.setFilterTurn(true);
463 if (currentSearchPanel != null)
466 if (!currentSearchPanel.searchBox.getText().isEmpty())
468 currentSearchPanel.description.setEnabled(true);
469 currentSearchPanel.displayName.setEnabled(true);
470 filterParams.setRegexString(currentSearchPanel.searchBox.getText());
471 if (currentSearchPanel.displayName.getState())
474 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING);
476 if (currentSearchPanel.description.getState())
479 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION);
484 currentSearchPanel.description.setEnabled(false);
485 currentSearchPanel.displayName.setEnabled(false);
489 av.getColumnSelection().filterAnnotations(
490 getCurrentAnnotation().annotations, filterParams);
492 av.showAllHiddenColumns();
493 if (getActionOption() == ACTION_OPTION_HIDE)
495 av.hideSelectedColumns();
499 av.setAnnotationColumnSelectionState(this);
500 ap.paintAlignment(true);
503 public ColumnSelection getOldColumnSelection()
505 return oldColumnSelection;
508 public void setOldColumnSelection(ColumnSelection currentColumnSelection)
510 if (currentColumnSelection != null)
512 this.oldColumnSelection = new ColumnSelection(currentColumnSelection);
516 public FurtherActionPanel getCurrentFutherActionPanel()
518 return currentFurtherActionPanel;
521 public void setCurrentFutherActionPanel(
522 FurtherActionPanel currentFutherActionPanel)
524 this.currentFurtherActionPanel = currentFutherActionPanel;
527 public SearchPanel getCurrentSearchPanel()
529 return currentSearchPanel;
532 public void setCurrentSearchPanel(SearchPanel currentSearchPanel)
534 this.currentSearchPanel = currentSearchPanel;
537 public int getActionOption()
542 public void setActionOption(int actionOption)
544 this.actionOption = actionOption;
547 public StructureFilterPanel getCurrentStructureFilterPanel()
549 return currentStructureFilterPanel;
552 public void setCurrentStructureFilterPanel(
553 StructureFilterPanel currentStructureFilterPanel)
555 this.currentStructureFilterPanel = currentStructureFilterPanel;
559 public void itemStateChanged(ItemEvent e)
561 if (e.getSource() == annotations)
563 selectedAnnotationChanged();
565 else if (e.getSource() == threshold)
567 threshold_actionPerformed(null);
571 public void selectedAnnotationChanged()
573 String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
574 if (av.getAlignment().getAlignmentAnnotation()[getAnnotations()
575 .getSelectedIndex()].graph != AlignmentAnnotation.NO_GRAPH)
577 currentView = AnnotationColumnChooser.GRAPH_VIEW;
580 gSearchPanel.syncState();
581 gFurtherActionPanel.syncState();
582 gStructureFilterPanel.syncState();
584 ngSearchPanel.syncState();
585 ngFurtherActionPanel.syncState();
586 ngStructureFilterPanel.syncState();
588 switchableViewsLayout.show(switchableViewsPanel, currentView);
592 public class FurtherActionPanel extends Panel implements ItemListener
594 private AnnotationColumnChooser aColChooser;
596 private Choice furtherAction = new Choice();
598 public FurtherActionPanel(AnnotationColumnChooser aColChooser)
600 this.aColChooser = aColChooser;
601 furtherAction.addItem("Select");
602 furtherAction.addItem("Hide");
603 furtherAction.addItemListener(this);
606 // this.setTitle("Filter Actions");
607 // this.setFont(JvSwingUtils.getLabelFont());
609 this.add(furtherAction);
612 public void syncState()
614 if (aColChooser.getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
616 furtherAction.select("Hide");
620 furtherAction.select("Select");
625 public void itemStateChanged(ItemEvent e)
627 aColChooser.setCurrentFutherActionPanel(this);
628 if (furtherAction.getSelectedItem().equalsIgnoreCase("Select"))
630 setActionOption(ACTION_OPTION_SELECT);
635 setActionOption(ACTION_OPTION_HIDE);
642 public class StructureFilterPanel extends TitledPanel implements
645 private AnnotationColumnChooser aColChooser;
647 private Checkbox alphaHelix = new Checkbox();
649 private Checkbox betaStrand = new Checkbox();
651 private Checkbox turn = new Checkbox();
653 private Checkbox all = new Checkbox();
655 public StructureFilterPanel(AnnotationColumnChooser aColChooser)
657 this.aColChooser = aColChooser;
659 alphaHelix.setLabel(MessageManager.getString("label.alpha_helix"));
660 alphaHelix.setBackground(Color.white);
662 alphaHelix.addItemListener(this);
664 betaStrand.setLabel(MessageManager.getString("label.beta_strand"));
665 betaStrand.setBackground(Color.white);
666 betaStrand.addItemListener(this);
668 turn.setLabel(MessageManager.getString("label.turn"));
669 turn.setBackground(Color.white);
670 turn.addItemListener(this);
672 all.setLabel(MessageManager.getString("label.select_all"));
673 all.setBackground(Color.white);
674 all.addItemListener(this);
676 this.setBackground(Color.white);
677 this.setTitle("Structure Filter");
678 // this.setFont(JvSwingUtils.getLabelFont());
681 this.add(alphaHelix);
682 this.add(betaStrand);
686 public void alphaHelix_actionPerformed()
688 updateSelectAllState();
689 aColChooser.setCurrentStructureFilterPanel(this);
690 aColChooser.updateView();
693 public void betaStrand_actionPerformed()
695 updateSelectAllState();
696 aColChooser.setCurrentStructureFilterPanel(this);
697 aColChooser.updateView();
700 public void turn_actionPerformed()
702 updateSelectAllState();
703 aColChooser.setCurrentStructureFilterPanel(this);
704 aColChooser.updateView();
707 public void all_actionPerformed()
711 alphaHelix.setState(true);
712 betaStrand.setState(true);
717 alphaHelix.setState(false);
718 betaStrand.setState(false);
719 turn.setState(false);
721 aColChooser.setCurrentStructureFilterPanel(this);
722 aColChooser.updateView();
725 public void updateSelectAllState()
727 if (alphaHelix.getState() && betaStrand.getState() && turn.getState())
737 public void syncState()
739 StructureFilterPanel sfp = aColChooser
740 .getCurrentStructureFilterPanel();
743 alphaHelix.setState(sfp.alphaHelix.getState());
744 betaStrand.setState(sfp.betaStrand.getState());
745 turn.setState(sfp.turn.getState());
746 if (sfp.all.getState())
749 alphaHelix.setState(true);
750 betaStrand.setState(true);
758 public void itemStateChanged(ItemEvent e)
760 if (e.getSource() == alphaHelix)
762 alphaHelix_actionPerformed();
764 else if (e.getSource() == betaStrand)
766 betaStrand_actionPerformed();
768 else if (e.getSource() == turn)
770 turn_actionPerformed();
772 else if (e.getSource() == all)
774 all_actionPerformed();
779 public class SearchPanel extends TitledPanel implements ItemListener
781 private AnnotationColumnChooser aColChooser;
783 private Checkbox displayName = new Checkbox();
785 private Checkbox description = new Checkbox();
787 private TextField searchBox = new TextField(10);
789 public SearchPanel(AnnotationColumnChooser aColChooser)
792 this.aColChooser = aColChooser;
793 searchBox.addTextListener(new TextListener()
797 public void textValueChanged(TextEvent e)
799 searchStringAction();
805 displayName.setLabel(MessageManager.getString("label.label"));
806 displayName.setEnabled(false);
807 displayName.addItemListener(this);
809 description.setLabel(MessageManager.getString("label.description"));
810 description.setEnabled(false);
811 description.addItemListener(this);
812 this.setTitle("Search Filter");
813 // this.setFont(JvSwingUtils.getLabelFont());
817 this.add(displayName);
818 this.add(description);
821 public void displayNameCheckboxAction()
823 aColChooser.setCurrentSearchPanel(this);
824 aColChooser.updateView();
827 public void discriptionCheckboxAction()
829 aColChooser.setCurrentSearchPanel(this);
830 aColChooser.updateView();
833 public void searchStringAction()
835 aColChooser.setCurrentSearchPanel(this);
836 aColChooser.updateView();
839 public void syncState()
841 SearchPanel sp = aColChooser.getCurrentSearchPanel();
844 description.setEnabled(sp.description.isEnabled());
845 description.setState(sp.description.getState());
847 displayName.setEnabled(sp.displayName.isEnabled());
848 displayName.setState(sp.displayName.getState());
850 searchBox.setText(sp.searchBox.getText());
855 public void itemStateChanged(ItemEvent e)
857 if (e.getSource() == displayName)
859 displayNameCheckboxAction();
861 else if (e.getSource() == description)
863 discriptionCheckboxAction();
869 public void actionPerformed(ActionEvent evt)
871 if (evt.getSource() == thresholdValue)
875 float f = new Float(thresholdValue.getText()).floatValue();
876 slider.setValue((int) (f * 1000));
877 adjustmentValueChanged(null);
878 } catch (NumberFormatException ex)
883 else if (evt.getSource() == ok)
885 ok_actionPerformed(null);
887 else if (evt.getSource() == cancel)
889 cancel_actionPerformed(null);
891 else if (evt.getSource() == thresholdValue)
893 thresholdValue_actionPerformed(null);
902 public void mouseClicked(MouseEvent e)
904 // TODO Auto-generated method stub
909 public void mousePressed(MouseEvent e)
911 if (e.getSource() == slider)
919 public void mouseReleased(MouseEvent e)
921 if (e.getSource() == slider)
928 public void mouseEntered(MouseEvent e)
930 if (e.getSource() == slider)
937 public void mouseExited(MouseEvent e)
939 if (e.getSource() == slider)