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);
208 ok.addActionListener(this);
209 cancel.addActionListener(this);
210 annotations.addItemListener(this);
211 thresholdValue.addActionListener(this);
212 threshold.addItemListener(this);
214 slider.setBackground(Color.white);
215 slider.setEnabled(false);
216 slider.setPreferredSize(new Dimension(100, 32));
218 thresholdPanel.setBackground(Color.white);
219 // thresholdPanel.setFont(JvSwingUtils.getLabelFont());
220 // thresholdPanel.setLayout(new MigLayout("", "[left][right]", "[][]"));
222 percentThreshold.setLabel("As percentage");
223 percentThreshold.addItemListener(this);
225 actionPanel.setBackground(Color.white);
226 // actionPanel.setFont(JvSwingUtils.getLabelFont());
228 graphFilterView.setLayout(gBorderLayout);
229 graphFilterView.setBackground(Color.white);
231 noGraphFilterView.setLayout(ngBorderLayout);
232 noGraphFilterView.setBackground(Color.white);
234 annotationComboBoxPanel.setBackground(Color.white);
235 // annotationComboBoxPanel.setFont(JvSwingUtils.getLabelFont());
237 gSearchPanel = new SearchPanel(this);
238 ngSearchPanel = new SearchPanel(this);
239 gFurtherActionPanel = new FurtherActionPanel(this);
240 ngFurtherActionPanel = new FurtherActionPanel(this);
241 gStructureFilterPanel = new StructureFilterPanel(this);
242 ngStructureFilterPanel = new StructureFilterPanel(this);
244 thresholdPanel.setTitle("Threshold Filter");
245 thresholdPanel.add(percentThreshold);
246 thresholdPanel.add(getThreshold());
247 thresholdPanel.add(slider);
248 thresholdPanel.add(thresholdValue);
251 actionPanel.add(cancel);
253 Panel staticPanel = new Panel();
254 staticPanel.setLayout(new BorderLayout());
255 staticPanel.setBackground(Color.white);
257 staticPanel.add(gSearchPanel, java.awt.BorderLayout.NORTH);
258 staticPanel.add(gStructureFilterPanel, java.awt.BorderLayout.SOUTH);
260 graphFilterView.add(staticPanel, java.awt.BorderLayout.NORTH);
261 graphFilterView.add(thresholdPanel, java.awt.BorderLayout.CENTER);
262 graphFilterView.add(gFurtherActionPanel, java.awt.BorderLayout.SOUTH);
264 noGraphFilterView.add(ngSearchPanel, java.awt.BorderLayout.PAGE_START);
265 noGraphFilterView.add(ngStructureFilterPanel,
266 java.awt.BorderLayout.CENTER);
267 noGraphFilterView.add(ngFurtherActionPanel,
268 java.awt.BorderLayout.CENTER);
270 annotationComboBoxPanel.add(getAnnotations());
271 switchableViewsPanel.add(noGraphFilterView,
272 AnnotationColumnChooser.NO_GRAPH_VIEW);
273 switchableViewsPanel.add(graphFilterView,
274 AnnotationColumnChooser.GRAPH_VIEW);
276 this.setLayout(borderLayout1);
277 this.add(annotationComboBoxPanel, java.awt.BorderLayout.PAGE_START);
278 this.add(switchableViewsPanel, java.awt.BorderLayout.CENTER);
279 this.add(actionPanel, java.awt.BorderLayout.SOUTH);
281 selectedAnnotationChanged();
286 @SuppressWarnings("unchecked")
289 if (this.getOldColumnSelection() != null)
291 av.getColumnSelection().clear();
293 if (av.getAnnotationColumnSelectionState() != null)
295 ColumnSelection oldSelection = av
296 .getAnnotationColumnSelectionState()
297 .getOldColumnSelection();
298 if (oldSelection != null && oldSelection.getHiddenColumns() != null
299 && !oldSelection.getHiddenColumns().isEmpty())
301 for (Iterator<int[]> itr = oldSelection.getHiddenColumns()
302 .iterator(); itr.hasNext();)
304 int positions[] = itr.next();
305 av.hideColumns(positions[0], positions[1]);
308 av.setColumnSelection(oldSelection);
310 ap.paintAlignment(true);
316 public void adjustmentValueChanged(AdjustmentEvent evt)
320 thresholdValue.setText((slider.getValue() / 1000f) + "");
321 valueChanged(!sliderDragging);
325 protected void addSliderMouseListeners()
328 slider.addMouseListener(new MouseAdapter()
331 public void mousePressed(MouseEvent e)
333 sliderDragging = true;
334 super.mousePressed(e);
338 public void mouseDragged(MouseEvent e)
340 sliderDragging = true;
341 super.mouseDragged(e);
345 public void mouseReleased(MouseEvent evt)
349 sliderDragging = false;
352 ap.paintAlignment(true);
358 public void valueChanged(boolean updateAllAnnotation)
360 if (slider.isEnabled())
362 getCurrentAnnotation().threshold.value = slider.getValue() / 1000f;
364 ap.paintAlignment(false);
368 public Choice getThreshold()
373 public void setThreshold(Choice threshold)
375 this.threshold = threshold;
378 public Choice getAnnotations()
383 public void setAnnotations(Choice annotations)
385 this.annotations = annotations;
389 public void updateView()
391 // Check if combobox is still adjusting
397 AnnotationFilterParameter filterParams = new AnnotationFilterParameter();
398 setCurrentAnnotation(av.getAlignment().getAlignmentAnnotation()[getAnnotations()
399 .getSelectedIndex()]);
401 int selectedThresholdItem = getSelectedThresholdItem(getThreshold()
402 .getSelectedIndex());
404 slider.setEnabled(true);
405 thresholdValue.setEnabled(true);
407 if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
409 slider.setEnabled(false);
410 thresholdValue.setEnabled(false);
411 thresholdValue.setText("");
412 // build filter params
414 else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
416 if (getCurrentAnnotation().threshold == null)
418 getCurrentAnnotation()
420 new jalview.datamodel.GraphLine(
421 (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin) / 2f,
422 "Threshold", Color.black));
426 float range = getCurrentAnnotation().graphMax * 1000
427 - getCurrentAnnotation().graphMin * 1000;
429 slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
430 slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
431 slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000));
432 setThresholdValueText();
433 // slider.setMajorTickSpacing((int) (range / 10f));
434 slider.setEnabled(true);
435 thresholdValue.setEnabled(true);
438 // build filter params
440 .setThresholdType(AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);
441 if (getCurrentAnnotation().graph != AlignmentAnnotation.NO_GRAPH)
444 .setThresholdValue(getCurrentAnnotation().threshold.value);
446 if (selectedThresholdItem == AnnotationColourGradient.ABOVE_THRESHOLD)
449 .setThresholdType(AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD);
451 else if (selectedThresholdItem == AnnotationColourGradient.BELOW_THRESHOLD)
454 .setThresholdType(AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD);
459 if (currentStructureFilterPanel != null)
461 if (currentStructureFilterPanel.alphaHelix.getState())
463 filterParams.setFilterAlphaHelix(true);
465 if (currentStructureFilterPanel.betaStrand.getState())
467 filterParams.setFilterBetaSheet(true);
469 if (currentStructureFilterPanel.turn.getState())
471 filterParams.setFilterTurn(true);
475 if (currentSearchPanel != null)
478 if (!currentSearchPanel.searchBox.getText().isEmpty())
480 currentSearchPanel.description.setEnabled(true);
481 currentSearchPanel.displayName.setEnabled(true);
482 filterParams.setRegexString(currentSearchPanel.searchBox.getText());
483 if (currentSearchPanel.displayName.getState())
486 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING);
488 if (currentSearchPanel.description.getState())
491 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION);
496 currentSearchPanel.description.setEnabled(false);
497 currentSearchPanel.displayName.setEnabled(false);
501 av.getColumnSelection().filterAnnotations(
502 getCurrentAnnotation().annotations, filterParams);
504 av.showAllHiddenColumns();
505 if (getActionOption() == ACTION_OPTION_HIDE)
507 av.hideSelectedColumns();
511 av.setAnnotationColumnSelectionState(this);
512 ap.paintAlignment(true);
515 public ColumnSelection getOldColumnSelection()
517 return oldColumnSelection;
520 public void setOldColumnSelection(ColumnSelection currentColumnSelection)
522 if (currentColumnSelection != null)
524 this.oldColumnSelection = new ColumnSelection(currentColumnSelection);
528 public FurtherActionPanel getCurrentFutherActionPanel()
530 return currentFurtherActionPanel;
533 public void setCurrentFutherActionPanel(
534 FurtherActionPanel currentFutherActionPanel)
536 this.currentFurtherActionPanel = currentFutherActionPanel;
539 public SearchPanel getCurrentSearchPanel()
541 return currentSearchPanel;
544 public void setCurrentSearchPanel(SearchPanel currentSearchPanel)
546 this.currentSearchPanel = currentSearchPanel;
549 public int getActionOption()
554 public void setActionOption(int actionOption)
556 this.actionOption = actionOption;
559 public StructureFilterPanel getCurrentStructureFilterPanel()
561 return currentStructureFilterPanel;
564 public void setCurrentStructureFilterPanel(
565 StructureFilterPanel currentStructureFilterPanel)
567 this.currentStructureFilterPanel = currentStructureFilterPanel;
571 public void itemStateChanged(ItemEvent e)
573 if (e.getSource() == annotations)
575 selectedAnnotationChanged();
577 else if (e.getSource() == threshold)
579 threshold_actionPerformed(null);
581 else if (e.getSource() == percentThreshold)
585 percentageValue_actionPerformed();
591 public void selectedAnnotationChanged()
593 String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
594 if (av.getAlignment().getAlignmentAnnotation()[getAnnotations()
595 .getSelectedIndex()].graph != AlignmentAnnotation.NO_GRAPH)
597 currentView = AnnotationColumnChooser.GRAPH_VIEW;
600 gSearchPanel.syncState();
601 gFurtherActionPanel.syncState();
602 gStructureFilterPanel.syncState();
604 ngSearchPanel.syncState();
605 ngFurtherActionPanel.syncState();
606 ngStructureFilterPanel.syncState();
608 switchableViewsLayout.show(switchableViewsPanel, currentView);
612 public class FurtherActionPanel extends Panel implements ItemListener
614 private AnnotationColumnChooser aColChooser;
616 private Choice furtherAction = new Choice();
618 public FurtherActionPanel(AnnotationColumnChooser aColChooser)
620 this.aColChooser = aColChooser;
621 furtherAction.addItem("Select");
622 furtherAction.addItem("Hide");
623 furtherAction.addItemListener(this);
626 // this.setTitle("Filter Actions");
627 // this.setFont(JvSwingUtils.getLabelFont());
629 this.add(furtherAction);
632 public void syncState()
634 if (aColChooser.getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
636 furtherAction.select("Hide");
640 furtherAction.select("Select");
645 public void itemStateChanged(ItemEvent e)
647 aColChooser.setCurrentFutherActionPanel(this);
648 if (furtherAction.getSelectedItem().equalsIgnoreCase("Select"))
650 setActionOption(ACTION_OPTION_SELECT);
655 setActionOption(ACTION_OPTION_HIDE);
662 public class StructureFilterPanel extends TitledPanel implements
665 private AnnotationColumnChooser aColChooser;
667 private Checkbox alphaHelix = new Checkbox();
669 private Checkbox betaStrand = new Checkbox();
671 private Checkbox turn = new Checkbox();
673 private Checkbox all = new Checkbox();
675 public StructureFilterPanel(AnnotationColumnChooser aColChooser)
677 this.aColChooser = aColChooser;
679 alphaHelix.setLabel(MessageManager.getString("label.alpha_helix"));
680 alphaHelix.setBackground(Color.white);
682 alphaHelix.addItemListener(this);
684 betaStrand.setLabel(MessageManager.getString("label.beta_strand"));
685 betaStrand.setBackground(Color.white);
686 betaStrand.addItemListener(this);
688 turn.setLabel(MessageManager.getString("label.turn"));
689 turn.setBackground(Color.white);
690 turn.addItemListener(this);
692 all.setLabel(MessageManager.getString("label.select_all"));
693 all.setBackground(Color.white);
694 all.addItemListener(this);
696 this.setBackground(Color.white);
697 this.setTitle("Structure Filter");
698 // this.setFont(JvSwingUtils.getLabelFont());
701 this.add(alphaHelix);
702 this.add(betaStrand);
706 public void alphaHelix_actionPerformed()
708 updateSelectAllState();
709 aColChooser.setCurrentStructureFilterPanel(this);
710 aColChooser.updateView();
713 public void betaStrand_actionPerformed()
715 updateSelectAllState();
716 aColChooser.setCurrentStructureFilterPanel(this);
717 aColChooser.updateView();
720 public void turn_actionPerformed()
722 updateSelectAllState();
723 aColChooser.setCurrentStructureFilterPanel(this);
724 aColChooser.updateView();
727 public void all_actionPerformed()
731 alphaHelix.setState(true);
732 betaStrand.setState(true);
737 alphaHelix.setState(false);
738 betaStrand.setState(false);
739 turn.setState(false);
741 aColChooser.setCurrentStructureFilterPanel(this);
742 aColChooser.updateView();
745 public void updateSelectAllState()
747 if (alphaHelix.getState() && betaStrand.getState() && turn.getState())
757 public void syncState()
759 StructureFilterPanel sfp = aColChooser
760 .getCurrentStructureFilterPanel();
763 alphaHelix.setState(sfp.alphaHelix.getState());
764 betaStrand.setState(sfp.betaStrand.getState());
765 turn.setState(sfp.turn.getState());
766 if (sfp.all.getState())
769 alphaHelix.setState(true);
770 betaStrand.setState(true);
778 public void itemStateChanged(ItemEvent e)
780 if (e.getSource() == alphaHelix)
782 alphaHelix_actionPerformed();
784 else if (e.getSource() == betaStrand)
786 betaStrand_actionPerformed();
788 else if (e.getSource() == turn)
790 turn_actionPerformed();
792 else if (e.getSource() == all)
794 all_actionPerformed();
799 public class SearchPanel extends TitledPanel implements ItemListener
801 private AnnotationColumnChooser aColChooser;
803 private Checkbox displayName = new Checkbox();
805 private Checkbox description = new Checkbox();
807 private TextField searchBox = new TextField(10);
809 public SearchPanel(AnnotationColumnChooser aColChooser)
812 this.aColChooser = aColChooser;
813 searchBox.addTextListener(new TextListener()
817 public void textValueChanged(TextEvent e)
819 searchStringAction();
825 displayName.setLabel(MessageManager.getString("label.label"));
826 displayName.setEnabled(false);
827 displayName.addItemListener(this);
829 description.setLabel(MessageManager.getString("label.description"));
830 description.setEnabled(false);
831 description.addItemListener(this);
832 this.setTitle("Search Filter");
833 // this.setFont(JvSwingUtils.getLabelFont());
837 this.add(displayName);
838 this.add(description);
841 public void displayNameCheckboxAction()
843 aColChooser.setCurrentSearchPanel(this);
844 aColChooser.updateView();
847 public void discriptionCheckboxAction()
849 aColChooser.setCurrentSearchPanel(this);
850 aColChooser.updateView();
853 public void searchStringAction()
855 aColChooser.setCurrentSearchPanel(this);
856 aColChooser.updateView();
859 public void syncState()
861 SearchPanel sp = aColChooser.getCurrentSearchPanel();
864 description.setEnabled(sp.description.isEnabled());
865 description.setState(sp.description.getState());
867 displayName.setEnabled(sp.displayName.isEnabled());
868 displayName.setState(sp.displayName.getState());
870 searchBox.setText(sp.searchBox.getText());
875 public void itemStateChanged(ItemEvent e)
877 if (e.getSource() == displayName)
879 displayNameCheckboxAction();
881 else if (e.getSource() == description)
883 discriptionCheckboxAction();
890 public void actionPerformed(ActionEvent evt)
892 if (evt.getSource() == thresholdValue)
896 float f = new Float(thresholdValue.getText()).floatValue();
897 slider.setValue((int) (f * 1000));
898 adjustmentValueChanged(null);
899 } catch (NumberFormatException ex)
904 else if (evt.getSource() == ok)
906 ok_actionPerformed(null);
908 else if (evt.getSource() == cancel)
910 cancel_actionPerformed(null);
912 else if (evt.getSource() == thresholdValue)
914 thresholdValue_actionPerformed(null);
923 public void mouseClicked(MouseEvent e)
925 // TODO Auto-generated method stub
930 public void mousePressed(MouseEvent e)
932 if (e.getSource() == slider)
940 public void mouseReleased(MouseEvent e)
942 if (e.getSource() == slider)
949 public void mouseEntered(MouseEvent e)
951 if (e.getSource() == slider)
958 public void mouseExited(MouseEvent e)
960 if (e.getSource() == slider)