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 actionPanel.setBackground(Color.white);
223 // actionPanel.setFont(JvSwingUtils.getLabelFont());
225 graphFilterView.setLayout(gBorderLayout);
226 graphFilterView.setBackground(Color.white);
228 noGraphFilterView.setLayout(ngBorderLayout);
229 noGraphFilterView.setBackground(Color.white);
231 annotationComboBoxPanel.setBackground(Color.white);
232 // annotationComboBoxPanel.setFont(JvSwingUtils.getLabelFont());
234 gSearchPanel = new SearchPanel(this);
235 ngSearchPanel = new SearchPanel(this);
236 gFurtherActionPanel = new FurtherActionPanel(this);
237 ngFurtherActionPanel = new FurtherActionPanel(this);
238 gStructureFilterPanel = new StructureFilterPanel(this);
239 ngStructureFilterPanel = new StructureFilterPanel(this);
241 thresholdPanel.setTitle("Threshold Filter");
242 thresholdPanel.add(getThreshold());
243 thresholdPanel.add(slider);
244 thresholdPanel.add(thresholdValue);
247 actionPanel.add(cancel);
249 Panel staticPanel = new Panel();
250 staticPanel.setLayout(new BorderLayout());
251 staticPanel.setBackground(Color.white);
253 staticPanel.add(gSearchPanel, java.awt.BorderLayout.NORTH);
254 staticPanel.add(gStructureFilterPanel, java.awt.BorderLayout.SOUTH);
256 graphFilterView.add(staticPanel, java.awt.BorderLayout.NORTH);
257 graphFilterView.add(thresholdPanel, java.awt.BorderLayout.CENTER);
258 graphFilterView.add(gFurtherActionPanel, java.awt.BorderLayout.SOUTH);
260 noGraphFilterView.add(ngSearchPanel, java.awt.BorderLayout.PAGE_START);
261 noGraphFilterView.add(ngStructureFilterPanel,
262 java.awt.BorderLayout.CENTER);
263 noGraphFilterView.add(ngFurtherActionPanel,
264 java.awt.BorderLayout.CENTER);
266 annotationComboBoxPanel.add(getAnnotations());
267 switchableViewsPanel.add(noGraphFilterView,
268 AnnotationColumnChooser.NO_GRAPH_VIEW);
269 switchableViewsPanel.add(graphFilterView,
270 AnnotationColumnChooser.GRAPH_VIEW);
272 this.setLayout(borderLayout1);
273 this.add(annotationComboBoxPanel, java.awt.BorderLayout.PAGE_START);
274 this.add(switchableViewsPanel, java.awt.BorderLayout.CENTER);
275 this.add(actionPanel, java.awt.BorderLayout.SOUTH);
277 selectedAnnotationChanged();
282 @SuppressWarnings("unchecked")
285 if (this.getOldColumnSelection() != null)
287 av.getColumnSelection().clear();
289 if (av.getAnnotationColumnSelectionState() != null)
291 ColumnSelection oldSelection = av
292 .getAnnotationColumnSelectionState()
293 .getOldColumnSelection();
294 if (oldSelection != null && oldSelection.getHiddenColumns() != null
295 && !oldSelection.getHiddenColumns().isEmpty())
297 for (Iterator<int[]> itr = oldSelection.getHiddenColumns()
298 .iterator(); itr.hasNext();)
300 int positions[] = itr.next();
301 av.hideColumns(positions[0], positions[1]);
304 av.setColumnSelection(oldSelection);
306 ap.paintAlignment(true);
312 public void adjustmentValueChanged(AdjustmentEvent evt)
316 thresholdValue.setText((slider.getValue() / 1000f) + "");
317 valueChanged(!sliderDragging);
321 protected void addSliderMouseListeners()
324 slider.addMouseListener(new MouseAdapter()
327 public void mousePressed(MouseEvent e)
329 sliderDragging = true;
330 super.mousePressed(e);
334 public void mouseDragged(MouseEvent e)
336 sliderDragging = true;
337 super.mouseDragged(e);
341 public void mouseReleased(MouseEvent evt)
345 sliderDragging = false;
348 ap.paintAlignment(true);
354 public void valueChanged(boolean updateAllAnnotation)
356 if (slider.isEnabled())
358 getCurrentAnnotation().threshold.value = slider.getValue() / 1000f;
360 ap.paintAlignment(false);
364 public Choice getThreshold()
369 public void setThreshold(Choice threshold)
371 this.threshold = threshold;
374 public Choice getAnnotations()
379 public void setAnnotations(Choice annotations)
381 this.annotations = annotations;
385 public void updateView()
387 // Check if combobox is still adjusting
393 AnnotationFilterParameter filterParams = new AnnotationFilterParameter();
394 setCurrentAnnotation(av.getAlignment().getAlignmentAnnotation()[getAnnotations()
395 .getSelectedIndex()]);
397 int selectedThresholdItem = getSelectedThresholdItem(getThreshold()
398 .getSelectedIndex());
400 slider.setEnabled(true);
401 thresholdValue.setEnabled(true);
403 if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
405 slider.setEnabled(false);
406 thresholdValue.setEnabled(false);
407 thresholdValue.setText("");
408 // build filter params
410 else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
412 if (getCurrentAnnotation().threshold == null)
414 getCurrentAnnotation()
416 new jalview.datamodel.GraphLine(
417 (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin) / 2f,
418 "Threshold", Color.black));
422 float range = getCurrentAnnotation().graphMax * 1000
423 - getCurrentAnnotation().graphMin * 1000;
425 slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
426 slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
427 slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000));
428 thresholdValue.setText(getCurrentAnnotation().threshold.value + "");
429 // slider.setMajorTickSpacing((int) (range / 10f));
430 slider.setEnabled(true);
431 thresholdValue.setEnabled(true);
434 // build filter params
436 .setThresholdType(AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);
437 if (getCurrentAnnotation().graph != AlignmentAnnotation.NO_GRAPH)
440 .setThresholdValue(getCurrentAnnotation().threshold.value);
442 if (selectedThresholdItem == AnnotationColourGradient.ABOVE_THRESHOLD)
445 .setThresholdType(AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD);
447 else if (selectedThresholdItem == AnnotationColourGradient.BELOW_THRESHOLD)
450 .setThresholdType(AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD);
455 if (currentStructureFilterPanel != null)
457 if (currentStructureFilterPanel.alphaHelix.getState())
459 filterParams.setFilterAlphaHelix(true);
461 if (currentStructureFilterPanel.betaStrand.getState())
463 filterParams.setFilterBetaSheet(true);
465 if (currentStructureFilterPanel.turn.getState())
467 filterParams.setFilterTurn(true);
471 if (currentSearchPanel != null)
474 if (!currentSearchPanel.searchBox.getText().isEmpty())
476 currentSearchPanel.description.setEnabled(true);
477 currentSearchPanel.displayName.setEnabled(true);
478 filterParams.setRegexString(currentSearchPanel.searchBox.getText());
479 if (currentSearchPanel.displayName.getState())
482 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING);
484 if (currentSearchPanel.description.getState())
487 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION);
492 currentSearchPanel.description.setEnabled(false);
493 currentSearchPanel.displayName.setEnabled(false);
497 av.getColumnSelection().filterAnnotations(
498 getCurrentAnnotation().annotations, filterParams);
500 av.showAllHiddenColumns();
501 if (getActionOption() == ACTION_OPTION_HIDE)
503 av.hideSelectedColumns();
507 av.setAnnotationColumnSelectionState(this);
508 ap.paintAlignment(true);
511 public ColumnSelection getOldColumnSelection()
513 return oldColumnSelection;
516 public void setOldColumnSelection(ColumnSelection currentColumnSelection)
518 if (currentColumnSelection != null)
520 this.oldColumnSelection = new ColumnSelection(currentColumnSelection);
524 public FurtherActionPanel getCurrentFutherActionPanel()
526 return currentFurtherActionPanel;
529 public void setCurrentFutherActionPanel(
530 FurtherActionPanel currentFutherActionPanel)
532 this.currentFurtherActionPanel = currentFutherActionPanel;
535 public SearchPanel getCurrentSearchPanel()
537 return currentSearchPanel;
540 public void setCurrentSearchPanel(SearchPanel currentSearchPanel)
542 this.currentSearchPanel = currentSearchPanel;
545 public int getActionOption()
550 public void setActionOption(int actionOption)
552 this.actionOption = actionOption;
555 public StructureFilterPanel getCurrentStructureFilterPanel()
557 return currentStructureFilterPanel;
560 public void setCurrentStructureFilterPanel(
561 StructureFilterPanel currentStructureFilterPanel)
563 this.currentStructureFilterPanel = currentStructureFilterPanel;
567 public void itemStateChanged(ItemEvent e)
569 if (e.getSource() == annotations)
571 selectedAnnotationChanged();
573 else if (e.getSource() == threshold)
575 threshold_actionPerformed(null);
579 public void selectedAnnotationChanged()
581 String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
582 if (av.getAlignment().getAlignmentAnnotation()[getAnnotations()
583 .getSelectedIndex()].graph != AlignmentAnnotation.NO_GRAPH)
585 currentView = AnnotationColumnChooser.GRAPH_VIEW;
588 gSearchPanel.syncState();
589 gFurtherActionPanel.syncState();
590 gStructureFilterPanel.syncState();
592 ngSearchPanel.syncState();
593 ngFurtherActionPanel.syncState();
594 ngStructureFilterPanel.syncState();
596 switchableViewsLayout.show(switchableViewsPanel, currentView);
600 public class FurtherActionPanel extends Panel implements ItemListener
602 private AnnotationColumnChooser aColChooser;
604 private Choice furtherAction = new Choice();
606 public FurtherActionPanel(AnnotationColumnChooser aColChooser)
608 this.aColChooser = aColChooser;
609 furtherAction.addItem("Select");
610 furtherAction.addItem("Hide");
611 furtherAction.addItemListener(this);
614 // this.setTitle("Filter Actions");
615 // this.setFont(JvSwingUtils.getLabelFont());
617 this.add(furtherAction);
620 public void syncState()
622 if (aColChooser.getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
624 furtherAction.select("Hide");
628 furtherAction.select("Select");
633 public void itemStateChanged(ItemEvent e)
635 aColChooser.setCurrentFutherActionPanel(this);
636 if (furtherAction.getSelectedItem().equalsIgnoreCase("Select"))
638 setActionOption(ACTION_OPTION_SELECT);
643 setActionOption(ACTION_OPTION_HIDE);
650 public class StructureFilterPanel extends TitledPanel implements
653 private AnnotationColumnChooser aColChooser;
655 private Checkbox alphaHelix = new Checkbox();
657 private Checkbox betaStrand = new Checkbox();
659 private Checkbox turn = new Checkbox();
661 private Checkbox all = new Checkbox();
663 public StructureFilterPanel(AnnotationColumnChooser aColChooser)
665 this.aColChooser = aColChooser;
667 alphaHelix.setLabel(MessageManager.getString("label.alpha_helix"));
668 alphaHelix.setBackground(Color.white);
670 alphaHelix.addItemListener(this);
672 betaStrand.setLabel(MessageManager.getString("label.beta_strand"));
673 betaStrand.setBackground(Color.white);
674 betaStrand.addItemListener(this);
676 turn.setLabel(MessageManager.getString("label.turn"));
677 turn.setBackground(Color.white);
678 turn.addItemListener(this);
680 all.setLabel(MessageManager.getString("label.select_all"));
681 all.setBackground(Color.white);
682 all.addItemListener(this);
684 this.setBackground(Color.white);
685 this.setTitle("Structure Filter");
686 // this.setFont(JvSwingUtils.getLabelFont());
689 this.add(alphaHelix);
690 this.add(betaStrand);
694 public void alphaHelix_actionPerformed()
696 updateSelectAllState();
697 aColChooser.setCurrentStructureFilterPanel(this);
698 aColChooser.updateView();
701 public void betaStrand_actionPerformed()
703 updateSelectAllState();
704 aColChooser.setCurrentStructureFilterPanel(this);
705 aColChooser.updateView();
708 public void turn_actionPerformed()
710 updateSelectAllState();
711 aColChooser.setCurrentStructureFilterPanel(this);
712 aColChooser.updateView();
715 public void all_actionPerformed()
719 alphaHelix.setState(true);
720 betaStrand.setState(true);
725 alphaHelix.setState(false);
726 betaStrand.setState(false);
727 turn.setState(false);
729 aColChooser.setCurrentStructureFilterPanel(this);
730 aColChooser.updateView();
733 public void updateSelectAllState()
735 if (alphaHelix.getState() && betaStrand.getState() && turn.getState())
745 public void syncState()
747 StructureFilterPanel sfp = aColChooser
748 .getCurrentStructureFilterPanel();
751 alphaHelix.setState(sfp.alphaHelix.getState());
752 betaStrand.setState(sfp.betaStrand.getState());
753 turn.setState(sfp.turn.getState());
754 if (sfp.all.getState())
757 alphaHelix.setState(true);
758 betaStrand.setState(true);
766 public void itemStateChanged(ItemEvent e)
768 if (e.getSource() == alphaHelix)
770 alphaHelix_actionPerformed();
772 else if (e.getSource() == betaStrand)
774 betaStrand_actionPerformed();
776 else if (e.getSource() == turn)
778 turn_actionPerformed();
780 else if (e.getSource() == all)
782 all_actionPerformed();
787 public class SearchPanel extends TitledPanel implements ItemListener
789 private AnnotationColumnChooser aColChooser;
791 private Checkbox displayName = new Checkbox();
793 private Checkbox description = new Checkbox();
795 private TextField searchBox = new TextField(10);
797 public SearchPanel(AnnotationColumnChooser aColChooser)
800 this.aColChooser = aColChooser;
801 searchBox.addTextListener(new TextListener()
805 public void textValueChanged(TextEvent e)
807 searchStringAction();
813 displayName.setLabel(MessageManager.getString("label.label"));
814 displayName.setEnabled(false);
815 displayName.addItemListener(this);
817 description.setLabel(MessageManager.getString("label.description"));
818 description.setEnabled(false);
819 description.addItemListener(this);
820 this.setTitle("Search Filter");
821 // this.setFont(JvSwingUtils.getLabelFont());
825 this.add(displayName);
826 this.add(description);
829 public void displayNameCheckboxAction()
831 aColChooser.setCurrentSearchPanel(this);
832 aColChooser.updateView();
835 public void discriptionCheckboxAction()
837 aColChooser.setCurrentSearchPanel(this);
838 aColChooser.updateView();
841 public void searchStringAction()
843 aColChooser.setCurrentSearchPanel(this);
844 aColChooser.updateView();
847 public void syncState()
849 SearchPanel sp = aColChooser.getCurrentSearchPanel();
852 description.setEnabled(sp.description.isEnabled());
853 description.setState(sp.description.getState());
855 displayName.setEnabled(sp.displayName.isEnabled());
856 displayName.setState(sp.displayName.getState());
858 searchBox.setText(sp.searchBox.getText());
863 public void itemStateChanged(ItemEvent e)
865 if (e.getSource() == displayName)
867 displayNameCheckboxAction();
869 else if (e.getSource() == description)
871 discriptionCheckboxAction();
878 public void actionPerformed(ActionEvent evt)
880 if (evt.getSource() == thresholdValue)
884 float f = new Float(thresholdValue.getText()).floatValue();
885 slider.setValue((int) (f * 1000));
886 adjustmentValueChanged(null);
887 } catch (NumberFormatException ex)
892 else if (evt.getSource() == ok)
894 ok_actionPerformed(null);
896 else if (evt.getSource() == cancel)
898 cancel_actionPerformed(null);
900 else if (evt.getSource() == thresholdValue)
902 thresholdValue_actionPerformed(null);
911 public void mouseClicked(MouseEvent e)
913 // TODO Auto-generated method stub
918 public void mousePressed(MouseEvent e)
920 if (e.getSource() == slider)
928 public void mouseReleased(MouseEvent e)
930 if (e.getSource() == slider)
937 public void mouseEntered(MouseEvent e)
939 if (e.getSource() == slider)
946 public void mouseExited(MouseEvent e)
948 if (e.getSource() == slider)