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);
170 AnnotationColumnChooser lastChooser = av
171 .getAnnotationColumnSelectionState();
172 // restore Object state from the previous session if one exists
173 if (lastChooser != null)
175 currentSearchPanel = lastChooser
176 .getCurrentSearchPanel();
177 currentStructureFilterPanel = lastChooser
178 .getCurrentStructureFilterPanel();
179 annotations.select(lastChooser
180 .getAnnotations().getSelectedIndex());
181 threshold.select(lastChooser
182 .getThreshold().getSelectedIndex());
183 actionOption = lastChooser
190 } catch (Exception ex)
200 private void jbInit() throws Exception
202 ok.setLabel(MessageManager.getString("action.ok"));
204 cancel.setLabel(MessageManager.getString("action.cancel"));
206 thresholdValue.setEnabled(false);
207 thresholdValue.setColumns(7);
208 thresholdValue.setCaretPosition(0);
210 ok.addActionListener(this);
211 cancel.addActionListener(this);
212 annotations.addItemListener(this);
213 thresholdValue.addActionListener(this);
214 threshold.addItemListener(this);
216 slider.setBackground(Color.white);
217 slider.setEnabled(false);
218 slider.setPreferredSize(new Dimension(100, 32));
220 thresholdPanel.setBackground(Color.white);
221 // thresholdPanel.setFont(JvSwingUtils.getLabelFont());
222 // thresholdPanel.setLayout(new MigLayout("", "[left][right]", "[][]"));
224 percentThreshold.setLabel("As percentage");
225 percentThreshold.addItemListener(this);
227 actionPanel.setBackground(Color.white);
228 // actionPanel.setFont(JvSwingUtils.getLabelFont());
230 graphFilterView.setLayout(gBorderLayout);
231 graphFilterView.setBackground(Color.white);
233 noGraphFilterView.setLayout(ngBorderLayout);
234 noGraphFilterView.setBackground(Color.white);
236 annotationComboBoxPanel.setBackground(Color.white);
237 // annotationComboBoxPanel.setFont(JvSwingUtils.getLabelFont());
239 gSearchPanel = new SearchPanel(this);
240 ngSearchPanel = new SearchPanel(this);
241 gFurtherActionPanel = new FurtherActionPanel(this);
242 ngFurtherActionPanel = new FurtherActionPanel(this);
243 gStructureFilterPanel = new StructureFilterPanel(this);
244 ngStructureFilterPanel = new StructureFilterPanel(this);
246 thresholdPanel.setTitle("Threshold Filter");
247 thresholdPanel.add(percentThreshold);
248 thresholdPanel.add(getThreshold());
249 thresholdPanel.add(slider);
250 thresholdPanel.add(thresholdValue);
253 actionPanel.add(cancel);
255 Panel staticPanel = new Panel();
256 staticPanel.setLayout(new BorderLayout());
257 staticPanel.setBackground(Color.white);
259 staticPanel.add(gSearchPanel, java.awt.BorderLayout.NORTH);
260 staticPanel.add(gStructureFilterPanel, java.awt.BorderLayout.SOUTH);
262 graphFilterView.add(staticPanel, java.awt.BorderLayout.NORTH);
263 graphFilterView.add(thresholdPanel, java.awt.BorderLayout.CENTER);
264 graphFilterView.add(gFurtherActionPanel, java.awt.BorderLayout.SOUTH);
266 noGraphFilterView.add(ngSearchPanel, java.awt.BorderLayout.PAGE_START);
267 noGraphFilterView.add(ngStructureFilterPanel,
268 java.awt.BorderLayout.CENTER);
269 noGraphFilterView.add(ngFurtherActionPanel,
270 java.awt.BorderLayout.CENTER);
272 annotationComboBoxPanel.add(getAnnotations());
273 switchableViewsPanel.add(noGraphFilterView,
274 AnnotationColumnChooser.NO_GRAPH_VIEW);
275 switchableViewsPanel.add(graphFilterView,
276 AnnotationColumnChooser.GRAPH_VIEW);
278 this.setLayout(borderLayout1);
279 this.add(annotationComboBoxPanel, java.awt.BorderLayout.PAGE_START);
280 this.add(switchableViewsPanel, java.awt.BorderLayout.CENTER);
281 this.add(actionPanel, java.awt.BorderLayout.SOUTH);
283 selectedAnnotationChanged();
288 @SuppressWarnings("unchecked")
291 if (this.getOldColumnSelection() != null)
293 av.getColumnSelection().clear();
295 if (av.getAnnotationColumnSelectionState() != null)
297 ColumnSelection oldSelection = av
298 .getAnnotationColumnSelectionState()
299 .getOldColumnSelection();
300 if (oldSelection != null && oldSelection.getHiddenColumns() != null
301 && !oldSelection.getHiddenColumns().isEmpty())
303 for (Iterator<int[]> itr = oldSelection.getHiddenColumns()
304 .iterator(); itr.hasNext();)
306 int positions[] = itr.next();
307 av.hideColumns(positions[0], positions[1]);
310 av.setColumnSelection(oldSelection);
312 ap.paintAlignment(true);
318 public void adjustmentValueChanged(AdjustmentEvent evt)
322 thresholdValue.setText((slider.getValue() / 1000f) + "");
323 valueChanged(!sliderDragging);
327 protected void addSliderMouseListeners()
330 slider.addMouseListener(new MouseAdapter()
333 public void mousePressed(MouseEvent e)
335 sliderDragging = true;
336 super.mousePressed(e);
340 public void mouseDragged(MouseEvent e)
342 sliderDragging = true;
343 super.mouseDragged(e);
347 public void mouseReleased(MouseEvent evt)
351 sliderDragging = false;
354 ap.paintAlignment(true);
360 public void valueChanged(boolean updateAllAnnotation)
362 if (slider.isEnabled())
364 getCurrentAnnotation().threshold.value = slider.getValue() / 1000f;
366 ap.paintAlignment(false);
370 public Choice getThreshold()
375 public void setThreshold(Choice threshold)
377 this.threshold = threshold;
380 public Choice getAnnotations()
385 public void setAnnotations(Choice annotations)
387 this.annotations = annotations;
391 public void updateView()
393 // Check if combobox is still adjusting
399 AnnotationFilterParameter filterParams = new AnnotationFilterParameter();
400 setCurrentAnnotation(av.getAlignment().getAlignmentAnnotation()[getAnnotations()
401 .getSelectedIndex()]);
403 int selectedThresholdItem = getSelectedThresholdItem(getThreshold()
404 .getSelectedIndex());
406 slider.setEnabled(true);
407 thresholdValue.setEnabled(true);
409 if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
411 slider.setEnabled(false);
412 thresholdValue.setEnabled(false);
413 thresholdValue.setText("");
414 // build filter params
416 else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
418 if (getCurrentAnnotation().threshold == null)
420 getCurrentAnnotation()
422 new jalview.datamodel.GraphLine(
423 (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin) / 2f,
424 "Threshold", Color.black));
428 float range = getCurrentAnnotation().graphMax * 1000
429 - getCurrentAnnotation().graphMin * 1000;
431 slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
432 slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
433 slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000));
434 setThresholdValueText();
435 // slider.setMajorTickSpacing((int) (range / 10f));
436 slider.setEnabled(true);
437 thresholdValue.setEnabled(true);
440 // build filter params
442 .setThresholdType(AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);
443 if (getCurrentAnnotation().graph != AlignmentAnnotation.NO_GRAPH)
446 .setThresholdValue(getCurrentAnnotation().threshold.value);
448 if (selectedThresholdItem == AnnotationColourGradient.ABOVE_THRESHOLD)
451 .setThresholdType(AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD);
453 else if (selectedThresholdItem == AnnotationColourGradient.BELOW_THRESHOLD)
456 .setThresholdType(AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD);
461 if (currentStructureFilterPanel != null)
463 if (currentStructureFilterPanel.alphaHelix.getState())
465 filterParams.setFilterAlphaHelix(true);
467 if (currentStructureFilterPanel.betaStrand.getState())
469 filterParams.setFilterBetaSheet(true);
471 if (currentStructureFilterPanel.turn.getState())
473 filterParams.setFilterTurn(true);
477 if (currentSearchPanel != null)
480 if (!currentSearchPanel.searchBox.getText().isEmpty())
482 currentSearchPanel.description.setEnabled(true);
483 currentSearchPanel.displayName.setEnabled(true);
484 filterParams.setRegexString(currentSearchPanel.searchBox.getText());
485 if (currentSearchPanel.displayName.getState())
488 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING);
490 if (currentSearchPanel.description.getState())
493 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION);
498 currentSearchPanel.description.setEnabled(false);
499 currentSearchPanel.displayName.setEnabled(false);
503 av.getColumnSelection().filterAnnotations(
504 getCurrentAnnotation().annotations, filterParams);
506 av.showAllHiddenColumns();
507 if (getActionOption() == ACTION_OPTION_HIDE)
509 av.hideSelectedColumns();
513 av.setAnnotationColumnSelectionState(this);
514 ap.paintAlignment(true);
517 public ColumnSelection getOldColumnSelection()
519 return oldColumnSelection;
522 public void setOldColumnSelection(ColumnSelection currentColumnSelection)
524 if (currentColumnSelection != null)
526 this.oldColumnSelection = new ColumnSelection(currentColumnSelection);
530 public FurtherActionPanel getCurrentFutherActionPanel()
532 return currentFurtherActionPanel;
535 public void setCurrentFutherActionPanel(
536 FurtherActionPanel currentFutherActionPanel)
538 this.currentFurtherActionPanel = currentFutherActionPanel;
541 public SearchPanel getCurrentSearchPanel()
543 return currentSearchPanel;
546 public void setCurrentSearchPanel(SearchPanel currentSearchPanel)
548 this.currentSearchPanel = currentSearchPanel;
551 public int getActionOption()
556 public void setActionOption(int actionOption)
558 this.actionOption = actionOption;
561 public StructureFilterPanel getCurrentStructureFilterPanel()
563 return currentStructureFilterPanel;
566 public void setCurrentStructureFilterPanel(
567 StructureFilterPanel currentStructureFilterPanel)
569 this.currentStructureFilterPanel = currentStructureFilterPanel;
573 public void itemStateChanged(ItemEvent e)
575 if (e.getSource() == annotations)
577 selectedAnnotationChanged();
579 else if (e.getSource() == threshold)
581 threshold_actionPerformed(null);
583 else if (e.getSource() == percentThreshold)
587 percentageValue_actionPerformed();
593 public void selectedAnnotationChanged()
595 String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
596 if (av.getAlignment().getAlignmentAnnotation()[getAnnotations()
597 .getSelectedIndex()].graph != AlignmentAnnotation.NO_GRAPH)
599 currentView = AnnotationColumnChooser.GRAPH_VIEW;
602 gSearchPanel.syncState();
603 gFurtherActionPanel.syncState();
604 gStructureFilterPanel.syncState();
606 ngSearchPanel.syncState();
607 ngFurtherActionPanel.syncState();
608 ngStructureFilterPanel.syncState();
610 switchableViewsLayout.show(switchableViewsPanel, currentView);
614 public class FurtherActionPanel extends Panel implements ItemListener
616 private AnnotationColumnChooser aColChooser;
618 private Choice furtherAction = new Choice();
620 public FurtherActionPanel(AnnotationColumnChooser aColChooser)
622 this.aColChooser = aColChooser;
623 furtherAction.addItem("Select");
624 furtherAction.addItem("Hide");
625 furtherAction.addItemListener(this);
628 // this.setTitle("Filter Actions");
629 // this.setFont(JvSwingUtils.getLabelFont());
631 this.add(furtherAction);
634 public void syncState()
636 if (aColChooser.getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
638 furtherAction.select("Hide");
642 furtherAction.select("Select");
647 public void itemStateChanged(ItemEvent e)
649 aColChooser.setCurrentFutherActionPanel(this);
650 if (furtherAction.getSelectedItem().equalsIgnoreCase("Select"))
652 setActionOption(ACTION_OPTION_SELECT);
657 setActionOption(ACTION_OPTION_HIDE);
664 public class StructureFilterPanel extends TitledPanel implements
667 private AnnotationColumnChooser aColChooser;
669 private Checkbox alphaHelix = new Checkbox();
671 private Checkbox betaStrand = new Checkbox();
673 private Checkbox turn = new Checkbox();
675 private Checkbox all = new Checkbox();
677 public StructureFilterPanel(AnnotationColumnChooser aColChooser)
679 this.aColChooser = aColChooser;
681 alphaHelix.setLabel(MessageManager.getString("label.alpha_helix"));
682 alphaHelix.setBackground(Color.white);
684 alphaHelix.addItemListener(this);
686 betaStrand.setLabel(MessageManager.getString("label.beta_strand"));
687 betaStrand.setBackground(Color.white);
688 betaStrand.addItemListener(this);
690 turn.setLabel(MessageManager.getString("label.turn"));
691 turn.setBackground(Color.white);
692 turn.addItemListener(this);
694 all.setLabel(MessageManager.getString("label.select_all"));
695 all.setBackground(Color.white);
696 all.addItemListener(this);
698 this.setBackground(Color.white);
699 this.setTitle("Structure Filter");
700 // this.setFont(JvSwingUtils.getLabelFont());
703 this.add(alphaHelix);
704 this.add(betaStrand);
708 public void alphaHelix_actionPerformed()
710 updateSelectAllState();
711 aColChooser.setCurrentStructureFilterPanel(this);
712 aColChooser.updateView();
715 public void betaStrand_actionPerformed()
717 updateSelectAllState();
718 aColChooser.setCurrentStructureFilterPanel(this);
719 aColChooser.updateView();
722 public void turn_actionPerformed()
724 updateSelectAllState();
725 aColChooser.setCurrentStructureFilterPanel(this);
726 aColChooser.updateView();
729 public void all_actionPerformed()
733 alphaHelix.setState(true);
734 betaStrand.setState(true);
739 alphaHelix.setState(false);
740 betaStrand.setState(false);
741 turn.setState(false);
743 aColChooser.setCurrentStructureFilterPanel(this);
744 aColChooser.updateView();
747 public void updateSelectAllState()
749 if (alphaHelix.getState() && betaStrand.getState() && turn.getState())
759 public void syncState()
761 StructureFilterPanel sfp = aColChooser
762 .getCurrentStructureFilterPanel();
765 alphaHelix.setState(sfp.alphaHelix.getState());
766 betaStrand.setState(sfp.betaStrand.getState());
767 turn.setState(sfp.turn.getState());
768 if (sfp.all.getState())
771 alphaHelix.setState(true);
772 betaStrand.setState(true);
780 public void itemStateChanged(ItemEvent e)
782 if (e.getSource() == alphaHelix)
784 alphaHelix_actionPerformed();
786 else if (e.getSource() == betaStrand)
788 betaStrand_actionPerformed();
790 else if (e.getSource() == turn)
792 turn_actionPerformed();
794 else if (e.getSource() == all)
796 all_actionPerformed();
801 public class SearchPanel extends TitledPanel implements ItemListener
803 private AnnotationColumnChooser aColChooser;
805 private Checkbox displayName = new Checkbox();
807 private Checkbox description = new Checkbox();
809 private TextField searchBox = new TextField(10);
811 public SearchPanel(AnnotationColumnChooser aColChooser)
814 this.aColChooser = aColChooser;
815 searchBox.addTextListener(new TextListener()
819 public void textValueChanged(TextEvent e)
821 searchStringAction();
827 displayName.setLabel(MessageManager.getString("label.label"));
828 displayName.setEnabled(false);
829 displayName.addItemListener(this);
831 description.setLabel(MessageManager.getString("label.description"));
832 description.setEnabled(false);
833 description.addItemListener(this);
834 this.setTitle("Search Filter");
835 // this.setFont(JvSwingUtils.getLabelFont());
839 this.add(displayName);
840 this.add(description);
843 public void displayNameCheckboxAction()
845 aColChooser.setCurrentSearchPanel(this);
846 aColChooser.updateView();
849 public void discriptionCheckboxAction()
851 aColChooser.setCurrentSearchPanel(this);
852 aColChooser.updateView();
855 public void searchStringAction()
857 aColChooser.setCurrentSearchPanel(this);
858 aColChooser.updateView();
861 public void syncState()
863 SearchPanel sp = aColChooser.getCurrentSearchPanel();
866 description.setEnabled(sp.description.isEnabled());
867 description.setState(sp.description.getState());
869 displayName.setEnabled(sp.displayName.isEnabled());
870 displayName.setState(sp.displayName.getState());
872 searchBox.setText(sp.searchBox.getText());
877 public void itemStateChanged(ItemEvent e)
879 if (e.getSource() == displayName)
881 displayNameCheckboxAction();
883 else if (e.getSource() == description)
885 discriptionCheckboxAction();
892 public void actionPerformed(ActionEvent evt)
894 if (evt.getSource() == thresholdValue)
898 float f = new Float(thresholdValue.getText()).floatValue();
899 slider.setValue((int) (f * 1000));
900 adjustmentValueChanged(null);
901 } catch (NumberFormatException ex)
906 else if (evt.getSource() == ok)
908 ok_actionPerformed(null);
910 else if (evt.getSource() == cancel)
912 cancel_actionPerformed(null);
914 else if (evt.getSource() == thresholdValue)
916 thresholdValue_actionPerformed(null);
925 public void mouseClicked(MouseEvent e)
927 // TODO Auto-generated method stub
932 public void mousePressed(MouseEvent e)
934 if (e.getSource() == slider)
942 public void mouseReleased(MouseEvent e)
944 if (e.getSource() == slider)
951 public void mouseEntered(MouseEvent e)
953 if (e.getSource() == slider)
960 public void mouseExited(MouseEvent e)
962 if (e.getSource() == slider)