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
185 percentThreshold.setState(lastChooser.percentThreshold.getState());
191 } catch (Exception ex)
201 private void jbInit() throws Exception
203 ok.setLabel(MessageManager.getString("action.ok"));
205 cancel.setLabel(MessageManager.getString("action.cancel"));
207 thresholdValue.setEnabled(false);
208 thresholdValue.setColumns(7);
209 thresholdValue.setCaretPosition(0);
211 ok.addActionListener(this);
212 cancel.addActionListener(this);
213 annotations.addItemListener(this);
214 thresholdValue.addActionListener(this);
215 threshold.addItemListener(this);
217 slider.setBackground(Color.white);
218 slider.setEnabled(false);
219 slider.setPreferredSize(new Dimension(100, 32));
221 thresholdPanel.setBackground(Color.white);
222 // thresholdPanel.setFont(JvSwingUtils.getLabelFont());
223 // thresholdPanel.setLayout(new MigLayout("", "[left][right]", "[][]"));
225 percentThreshold.setLabel("As percentage");
226 percentThreshold.addItemListener(this);
228 actionPanel.setBackground(Color.white);
229 // actionPanel.setFont(JvSwingUtils.getLabelFont());
231 graphFilterView.setLayout(gBorderLayout);
232 graphFilterView.setBackground(Color.white);
234 noGraphFilterView.setLayout(ngBorderLayout);
235 noGraphFilterView.setBackground(Color.white);
237 annotationComboBoxPanel.setBackground(Color.white);
238 // annotationComboBoxPanel.setFont(JvSwingUtils.getLabelFont());
240 gSearchPanel = new SearchPanel(this);
241 ngSearchPanel = new SearchPanel(this);
242 gFurtherActionPanel = new FurtherActionPanel(this);
243 ngFurtherActionPanel = new FurtherActionPanel(this);
244 gStructureFilterPanel = new StructureFilterPanel(this);
245 ngStructureFilterPanel = new StructureFilterPanel(this);
247 thresholdPanel.setTitle("Threshold Filter");
248 thresholdPanel.add(percentThreshold);
249 thresholdPanel.add(getThreshold());
250 thresholdPanel.add(slider);
251 thresholdPanel.add(thresholdValue);
254 actionPanel.add(cancel);
256 Panel staticPanel = new Panel();
257 staticPanel.setLayout(new BorderLayout());
258 staticPanel.setBackground(Color.white);
260 staticPanel.add(gSearchPanel, java.awt.BorderLayout.NORTH);
261 staticPanel.add(gStructureFilterPanel, java.awt.BorderLayout.SOUTH);
263 graphFilterView.add(staticPanel, java.awt.BorderLayout.NORTH);
264 graphFilterView.add(thresholdPanel, java.awt.BorderLayout.CENTER);
265 graphFilterView.add(gFurtherActionPanel, java.awt.BorderLayout.SOUTH);
267 noGraphFilterView.add(ngSearchPanel, java.awt.BorderLayout.PAGE_START);
268 noGraphFilterView.add(ngStructureFilterPanel,
269 java.awt.BorderLayout.CENTER);
270 noGraphFilterView.add(ngFurtherActionPanel,
271 java.awt.BorderLayout.CENTER);
273 annotationComboBoxPanel.add(getAnnotations());
274 switchableViewsPanel.add(noGraphFilterView,
275 AnnotationColumnChooser.NO_GRAPH_VIEW);
276 switchableViewsPanel.add(graphFilterView,
277 AnnotationColumnChooser.GRAPH_VIEW);
279 this.setLayout(borderLayout1);
280 this.add(annotationComboBoxPanel, java.awt.BorderLayout.PAGE_START);
281 this.add(switchableViewsPanel, java.awt.BorderLayout.CENTER);
282 this.add(actionPanel, java.awt.BorderLayout.SOUTH);
284 selectedAnnotationChanged();
289 @SuppressWarnings("unchecked")
292 if (this.getOldColumnSelection() != null)
294 av.getColumnSelection().clear();
296 if (av.getAnnotationColumnSelectionState() != null)
298 ColumnSelection oldSelection = av
299 .getAnnotationColumnSelectionState()
300 .getOldColumnSelection();
301 if (oldSelection != null && oldSelection.getHiddenColumns() != null
302 && !oldSelection.getHiddenColumns().isEmpty())
304 for (Iterator<int[]> itr = oldSelection.getHiddenColumns()
305 .iterator(); itr.hasNext();)
307 int positions[] = itr.next();
308 av.hideColumns(positions[0], positions[1]);
311 av.setColumnSelection(oldSelection);
313 ap.paintAlignment(true);
319 public void adjustmentValueChanged(AdjustmentEvent evt)
323 thresholdValue.setText((slider.getValue() / 1000f) + "");
324 valueChanged(!sliderDragging);
328 protected void addSliderMouseListeners()
331 slider.addMouseListener(new MouseAdapter()
334 public void mousePressed(MouseEvent e)
336 sliderDragging = true;
337 super.mousePressed(e);
341 public void mouseDragged(MouseEvent e)
343 sliderDragging = true;
344 super.mouseDragged(e);
348 public void mouseReleased(MouseEvent evt)
352 sliderDragging = false;
355 ap.paintAlignment(true);
361 public void valueChanged(boolean updateAllAnnotation)
363 if (slider.isEnabled())
365 getCurrentAnnotation().threshold.value = slider.getValue() / 1000f;
367 ap.paintAlignment(false);
371 public Choice getThreshold()
376 public void setThreshold(Choice threshold)
378 this.threshold = threshold;
381 public Choice getAnnotations()
386 public void setAnnotations(Choice annotations)
388 this.annotations = annotations;
392 public void updateView()
394 // Check if combobox is still adjusting
400 AnnotationFilterParameter filterParams = new AnnotationFilterParameter();
401 setCurrentAnnotation(av.getAlignment().getAlignmentAnnotation()[getAnnotations()
402 .getSelectedIndex()]);
404 int selectedThresholdItem = getSelectedThresholdItem(getThreshold()
405 .getSelectedIndex());
407 slider.setEnabled(true);
408 thresholdValue.setEnabled(true);
410 if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
412 slider.setEnabled(false);
413 thresholdValue.setEnabled(false);
414 thresholdValue.setText("");
415 // build filter params
417 else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
419 if (getCurrentAnnotation().threshold == null)
421 getCurrentAnnotation()
423 new jalview.datamodel.GraphLine(
424 (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin) / 2f,
425 "Threshold", Color.black));
429 float range = getCurrentAnnotation().graphMax * 1000
430 - getCurrentAnnotation().graphMin * 1000;
432 slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
433 slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
434 slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000));
435 setThresholdValueText();
436 // slider.setMajorTickSpacing((int) (range / 10f));
437 slider.setEnabled(true);
438 thresholdValue.setEnabled(true);
441 // build filter params
443 .setThresholdType(AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);
444 if (getCurrentAnnotation().graph != AlignmentAnnotation.NO_GRAPH)
447 .setThresholdValue(getCurrentAnnotation().threshold.value);
449 if (selectedThresholdItem == AnnotationColourGradient.ABOVE_THRESHOLD)
452 .setThresholdType(AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD);
454 else if (selectedThresholdItem == AnnotationColourGradient.BELOW_THRESHOLD)
457 .setThresholdType(AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD);
462 if (currentStructureFilterPanel != null)
464 if (currentStructureFilterPanel.alphaHelix.getState())
466 filterParams.setFilterAlphaHelix(true);
468 if (currentStructureFilterPanel.betaStrand.getState())
470 filterParams.setFilterBetaSheet(true);
472 if (currentStructureFilterPanel.turn.getState())
474 filterParams.setFilterTurn(true);
478 if (currentSearchPanel != null)
481 if (!currentSearchPanel.searchBox.getText().isEmpty())
483 currentSearchPanel.description.setEnabled(true);
484 currentSearchPanel.displayName.setEnabled(true);
485 filterParams.setRegexString(currentSearchPanel.searchBox.getText());
486 if (currentSearchPanel.displayName.getState())
489 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING);
491 if (currentSearchPanel.description.getState())
494 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION);
499 currentSearchPanel.description.setEnabled(false);
500 currentSearchPanel.displayName.setEnabled(false);
504 av.getColumnSelection().filterAnnotations(
505 getCurrentAnnotation().annotations, filterParams);
507 av.showAllHiddenColumns();
508 if (getActionOption() == ACTION_OPTION_HIDE)
510 av.hideSelectedColumns();
514 av.setAnnotationColumnSelectionState(this);
515 ap.paintAlignment(true);
518 public ColumnSelection getOldColumnSelection()
520 return oldColumnSelection;
523 public void setOldColumnSelection(ColumnSelection currentColumnSelection)
525 if (currentColumnSelection != null)
527 this.oldColumnSelection = new ColumnSelection(currentColumnSelection);
531 public FurtherActionPanel getCurrentFutherActionPanel()
533 return currentFurtherActionPanel;
536 public void setCurrentFutherActionPanel(
537 FurtherActionPanel currentFutherActionPanel)
539 this.currentFurtherActionPanel = currentFutherActionPanel;
542 public SearchPanel getCurrentSearchPanel()
544 return currentSearchPanel;
547 public void setCurrentSearchPanel(SearchPanel currentSearchPanel)
549 this.currentSearchPanel = currentSearchPanel;
552 public int getActionOption()
557 public void setActionOption(int actionOption)
559 this.actionOption = actionOption;
562 public StructureFilterPanel getCurrentStructureFilterPanel()
564 return currentStructureFilterPanel;
567 public void setCurrentStructureFilterPanel(
568 StructureFilterPanel currentStructureFilterPanel)
570 this.currentStructureFilterPanel = currentStructureFilterPanel;
574 public void itemStateChanged(ItemEvent e)
576 if (e.getSource() == annotations)
578 selectedAnnotationChanged();
580 else if (e.getSource() == threshold)
582 threshold_actionPerformed(null);
584 else if (e.getSource() == percentThreshold)
588 percentageValue_actionPerformed();
594 public void selectedAnnotationChanged()
596 String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
597 if (av.getAlignment().getAlignmentAnnotation()[getAnnotations()
598 .getSelectedIndex()].graph != AlignmentAnnotation.NO_GRAPH)
600 currentView = AnnotationColumnChooser.GRAPH_VIEW;
603 gSearchPanel.syncState();
604 gFurtherActionPanel.syncState();
605 gStructureFilterPanel.syncState();
607 ngSearchPanel.syncState();
608 ngFurtherActionPanel.syncState();
609 ngStructureFilterPanel.syncState();
611 switchableViewsLayout.show(switchableViewsPanel, currentView);
615 public class FurtherActionPanel extends Panel implements ItemListener
617 private AnnotationColumnChooser aColChooser;
619 private Choice furtherAction = new Choice();
621 public FurtherActionPanel(AnnotationColumnChooser aColChooser)
623 this.aColChooser = aColChooser;
624 furtherAction.addItem("Select");
625 furtherAction.addItem("Hide");
626 furtherAction.addItemListener(this);
629 // this.setTitle("Filter Actions");
630 // this.setFont(JvSwingUtils.getLabelFont());
632 this.add(furtherAction);
635 public void syncState()
637 if (aColChooser.getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
639 furtherAction.select("Hide");
643 furtherAction.select("Select");
648 public void itemStateChanged(ItemEvent e)
650 aColChooser.setCurrentFutherActionPanel(this);
651 if (furtherAction.getSelectedItem().equalsIgnoreCase("Select"))
653 setActionOption(ACTION_OPTION_SELECT);
658 setActionOption(ACTION_OPTION_HIDE);
665 public class StructureFilterPanel extends TitledPanel implements
668 private AnnotationColumnChooser aColChooser;
670 private Checkbox alphaHelix = new Checkbox();
672 private Checkbox betaStrand = new Checkbox();
674 private Checkbox turn = new Checkbox();
676 private Checkbox all = new Checkbox();
678 public StructureFilterPanel(AnnotationColumnChooser aColChooser)
680 this.aColChooser = aColChooser;
682 alphaHelix.setLabel(MessageManager.getString("label.alpha_helix"));
683 alphaHelix.setBackground(Color.white);
685 alphaHelix.addItemListener(this);
687 betaStrand.setLabel(MessageManager.getString("label.beta_strand"));
688 betaStrand.setBackground(Color.white);
689 betaStrand.addItemListener(this);
691 turn.setLabel(MessageManager.getString("label.turn"));
692 turn.setBackground(Color.white);
693 turn.addItemListener(this);
695 all.setLabel(MessageManager.getString("label.select_all"));
696 all.setBackground(Color.white);
697 all.addItemListener(this);
699 this.setBackground(Color.white);
700 this.setTitle("Structure Filter");
701 // this.setFont(JvSwingUtils.getLabelFont());
704 this.add(alphaHelix);
705 this.add(betaStrand);
709 public void alphaHelix_actionPerformed()
711 updateSelectAllState();
712 aColChooser.setCurrentStructureFilterPanel(this);
713 aColChooser.updateView();
716 public void betaStrand_actionPerformed()
718 updateSelectAllState();
719 aColChooser.setCurrentStructureFilterPanel(this);
720 aColChooser.updateView();
723 public void turn_actionPerformed()
725 updateSelectAllState();
726 aColChooser.setCurrentStructureFilterPanel(this);
727 aColChooser.updateView();
730 public void all_actionPerformed()
734 alphaHelix.setState(true);
735 betaStrand.setState(true);
740 alphaHelix.setState(false);
741 betaStrand.setState(false);
742 turn.setState(false);
744 aColChooser.setCurrentStructureFilterPanel(this);
745 aColChooser.updateView();
748 public void updateSelectAllState()
750 if (alphaHelix.getState() && betaStrand.getState() && turn.getState())
760 public void syncState()
762 StructureFilterPanel sfp = aColChooser
763 .getCurrentStructureFilterPanel();
766 alphaHelix.setState(sfp.alphaHelix.getState());
767 betaStrand.setState(sfp.betaStrand.getState());
768 turn.setState(sfp.turn.getState());
769 if (sfp.all.getState())
772 alphaHelix.setState(true);
773 betaStrand.setState(true);
781 public void itemStateChanged(ItemEvent e)
783 if (e.getSource() == alphaHelix)
785 alphaHelix_actionPerformed();
787 else if (e.getSource() == betaStrand)
789 betaStrand_actionPerformed();
791 else if (e.getSource() == turn)
793 turn_actionPerformed();
795 else if (e.getSource() == all)
797 all_actionPerformed();
802 public class SearchPanel extends TitledPanel implements ItemListener
804 private AnnotationColumnChooser aColChooser;
806 private Checkbox displayName = new Checkbox();
808 private Checkbox description = new Checkbox();
810 private TextField searchBox = new TextField(10);
812 public SearchPanel(AnnotationColumnChooser aColChooser)
815 this.aColChooser = aColChooser;
816 searchBox.addTextListener(new TextListener()
820 public void textValueChanged(TextEvent e)
822 searchStringAction();
828 displayName.setLabel(MessageManager.getString("label.label"));
829 displayName.setEnabled(false);
830 displayName.addItemListener(this);
832 description.setLabel(MessageManager.getString("label.description"));
833 description.setEnabled(false);
834 description.addItemListener(this);
835 this.setTitle("Search Filter");
836 // this.setFont(JvSwingUtils.getLabelFont());
840 this.add(displayName);
841 this.add(description);
844 public void displayNameCheckboxAction()
846 aColChooser.setCurrentSearchPanel(this);
847 aColChooser.updateView();
850 public void discriptionCheckboxAction()
852 aColChooser.setCurrentSearchPanel(this);
853 aColChooser.updateView();
856 public void searchStringAction()
858 aColChooser.setCurrentSearchPanel(this);
859 aColChooser.updateView();
862 public void syncState()
864 SearchPanel sp = aColChooser.getCurrentSearchPanel();
867 description.setEnabled(sp.description.isEnabled());
868 description.setState(sp.description.getState());
870 displayName.setEnabled(sp.displayName.isEnabled());
871 displayName.setState(sp.displayName.getState());
873 searchBox.setText(sp.searchBox.getText());
878 public void itemStateChanged(ItemEvent e)
880 if (e.getSource() == displayName)
882 displayNameCheckboxAction();
884 else if (e.getSource() == description)
886 discriptionCheckboxAction();
893 public void actionPerformed(ActionEvent evt)
895 if (evt.getSource() == thresholdValue)
899 float f = new Float(thresholdValue.getText()).floatValue();
900 slider.setValue((int) (f * 1000));
901 adjustmentValueChanged(null);
902 } catch (NumberFormatException ex)
907 else if (evt.getSource() == ok)
909 ok_actionPerformed(null);
911 else if (evt.getSource() == cancel)
913 cancel_actionPerformed(null);
915 else if (evt.getSource() == thresholdValue)
917 thresholdValue_actionPerformed(null);
926 public void mouseClicked(MouseEvent e)
928 // TODO Auto-generated method stub
933 public void mousePressed(MouseEvent e)
935 if (e.getSource() == slider)
943 public void mouseReleased(MouseEvent e)
945 if (e.getSource() == slider)
952 public void mouseEntered(MouseEvent e)
954 if (e.getSource() == slider)
961 public void mouseExited(MouseEvent e)
963 if (e.getSource() == slider)