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.HiddenColumns;
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.Vector;
51 //import javax.swing.JPanel;
53 //import net.miginfocom.swing.MigLayout;
55 public class AnnotationColumnChooser extends AnnotationRowFilter implements
56 ActionListener, AdjustmentListener, ItemListener, MouseListener
59 private Choice annotations = new Choice();
61 private Panel actionPanel = new Panel();
63 private TitledPanel thresholdPanel = new TitledPanel();
65 private Panel switchableViewsPanel = new Panel(new CardLayout());
67 private CardLayout switchableViewsLayout = (CardLayout) (switchableViewsPanel
70 private Panel noGraphFilterView = new Panel();
72 private Panel graphFilterView = new Panel();
74 private Panel annotationComboBoxPanel = new Panel();
76 private BorderLayout borderLayout1 = new BorderLayout();
78 private BorderLayout gBorderLayout = new BorderLayout();
80 private BorderLayout ngBorderLayout = new BorderLayout();
82 private Choice threshold = new Choice();
84 private StructureFilterPanel gStructureFilterPanel;
86 private StructureFilterPanel ngStructureFilterPanel;
88 private StructureFilterPanel currentStructureFilterPanel;
90 private SearchPanel currentSearchPanel;
92 private SearchPanel gSearchPanel;
94 private SearchPanel ngSearchPanel;
96 private FurtherActionPanel currentFurtherActionPanel;
98 private FurtherActionPanel gFurtherActionPanel;
100 private FurtherActionPanel ngFurtherActionPanel;
102 public static final int ACTION_OPTION_SELECT = 1;
104 public static int ACTION_OPTION_HIDE = 2;
106 public static String NO_GRAPH_VIEW = "0";
108 public static String GRAPH_VIEW = "1";
110 private int actionOption = ACTION_OPTION_SELECT;
112 private HiddenColumns oldHiddenColumns;
114 public AnnotationColumnChooser()
119 } catch (Exception ex)
121 ex.printStackTrace();
125 public AnnotationColumnChooser(AlignViewport av, final AlignmentPanel ap)
130 jalview.bin.JalviewLite.addFrame(frame,
131 MessageManager.getString("label.select_by_annotation"), 520,
134 slider.addAdjustmentListener(this);
135 slider.addMouseListener(this);
137 AlignmentAnnotation[] anns = av.getAlignment().getAlignmentAnnotation();
142 setOldHiddenColumns(av.getAlignment().getHiddenColumns());
144 Vector<String> list = new Vector<>();
146 for (int i = 0; i < anns.length; i++)
148 String label = anns[i].label;
149 if (anns[i].sequenceRef != null)
151 label = label + "_" + anns[i].sequenceRef.getName();
153 if (!list.contains(label))
155 list.addElement(label);
159 list.addElement(label + "_" + (index++));
163 for (int i = 0; i < list.size(); i++)
165 annotations.addItem(list.elementAt(i).toString());
168 populateThresholdComboBox(threshold);
169 AnnotationColumnChooser lastChooser = av
170 .getAnnotationColumnSelectionState();
171 // restore Object state from the previous session if one exists
172 if (lastChooser != null)
174 currentSearchPanel = lastChooser.getCurrentSearchPanel();
175 currentStructureFilterPanel = lastChooser
176 .getCurrentStructureFilterPanel();
177 annotations.select(lastChooser.getAnnotations().getSelectedIndex());
178 threshold.select(lastChooser.getThreshold().getSelectedIndex());
179 actionOption = lastChooser.getActionOption();
180 percentThreshold.setState(lastChooser.percentThreshold.getState());
186 } catch (Exception ex)
196 private void jbInit() throws Exception
198 ok.setLabel(MessageManager.getString("action.ok"));
200 cancel.setLabel(MessageManager.getString("action.cancel"));
202 thresholdValue.setEnabled(false);
203 thresholdValue.setColumns(7);
204 thresholdValue.setCaretPosition(0);
206 ok.addActionListener(this);
207 cancel.addActionListener(this);
208 annotations.addItemListener(this);
209 thresholdValue.addActionListener(this);
210 threshold.addItemListener(this);
212 slider.setBackground(Color.white);
213 slider.setEnabled(false);
214 slider.setPreferredSize(new Dimension(100, 32));
216 thresholdPanel.setBackground(Color.white);
217 // thresholdPanel.setFont(JvSwingUtils.getLabelFont());
218 // thresholdPanel.setLayout(new MigLayout("", "[left][right]", "[][]"));
220 percentThreshold.setLabel("As percentage");
221 percentThreshold.addItemListener(this);
223 actionPanel.setBackground(Color.white);
224 // actionPanel.setFont(JvSwingUtils.getLabelFont());
226 graphFilterView.setLayout(gBorderLayout);
227 graphFilterView.setBackground(Color.white);
229 noGraphFilterView.setLayout(ngBorderLayout);
230 noGraphFilterView.setBackground(Color.white);
232 annotationComboBoxPanel.setBackground(Color.white);
233 // annotationComboBoxPanel.setFont(JvSwingUtils.getLabelFont());
235 gSearchPanel = new SearchPanel(this);
236 ngSearchPanel = new SearchPanel(this);
237 gFurtherActionPanel = new FurtherActionPanel(this);
238 ngFurtherActionPanel = new FurtherActionPanel(this);
239 gStructureFilterPanel = new StructureFilterPanel(this);
240 ngStructureFilterPanel = new StructureFilterPanel(this);
242 thresholdPanel.setTitle("Threshold Filter");
243 thresholdPanel.add(getThreshold());
244 thresholdPanel.add(slider);
245 thresholdPanel.add(thresholdValue);
246 thresholdPanel.add(percentThreshold);
249 actionPanel.add(cancel);
251 Panel staticPanel = new Panel();
252 staticPanel.setLayout(new BorderLayout());
253 staticPanel.setBackground(Color.white);
255 staticPanel.add(gSearchPanel, java.awt.BorderLayout.NORTH);
256 staticPanel.add(gStructureFilterPanel, java.awt.BorderLayout.SOUTH);
258 graphFilterView.add(staticPanel, java.awt.BorderLayout.NORTH);
259 graphFilterView.add(thresholdPanel, java.awt.BorderLayout.CENTER);
260 graphFilterView.add(gFurtherActionPanel, java.awt.BorderLayout.SOUTH);
262 noGraphFilterView.add(ngSearchPanel, java.awt.BorderLayout.PAGE_START);
263 noGraphFilterView.add(ngStructureFilterPanel,
264 java.awt.BorderLayout.CENTER);
265 noGraphFilterView.add(ngFurtherActionPanel,
266 java.awt.BorderLayout.CENTER);
268 annotationComboBoxPanel.add(getAnnotations());
269 switchableViewsPanel.add(noGraphFilterView,
270 AnnotationColumnChooser.NO_GRAPH_VIEW);
271 switchableViewsPanel.add(graphFilterView,
272 AnnotationColumnChooser.GRAPH_VIEW);
274 this.setLayout(borderLayout1);
275 this.add(annotationComboBoxPanel, java.awt.BorderLayout.PAGE_START);
276 this.add(switchableViewsPanel, java.awt.BorderLayout.CENTER);
277 this.add(actionPanel, java.awt.BorderLayout.SOUTH);
279 selectedAnnotationChanged();
284 @SuppressWarnings("unchecked")
287 if (this.getOldHiddenColumns() != null)
289 av.getColumnSelection().clear();
291 if (av.getAnnotationColumnSelectionState() != null)
293 HiddenColumns oldHidden = av.getAnnotationColumnSelectionState()
294 .getOldHiddenColumns();
295 av.getAlignment().setHiddenColumns(oldHidden);
298 ap.paintAlignment(true, true);
304 public void adjustmentValueChanged(AdjustmentEvent evt)
308 setThresholdValueText();
309 valueChanged(!sliderDragging);
313 protected void addSliderMouseListeners()
316 slider.addMouseListener(new MouseAdapter()
319 public void mousePressed(MouseEvent e)
321 sliderDragging = true;
322 super.mousePressed(e);
326 public void mouseDragged(MouseEvent e)
328 sliderDragging = true;
329 super.mouseDragged(e);
333 public void mouseReleased(MouseEvent evt)
337 sliderDragging = false;
340 ap.paintAlignment(true, true);
346 public void valueChanged(boolean updateAllAnnotation)
348 if (slider.isEnabled())
350 getCurrentAnnotation().threshold.value = slider.getValue() / 1000f;
351 updateView(); // this also calls paintAlignment(true,true)
355 public Choice getThreshold()
360 public void setThreshold(Choice threshold)
362 this.threshold = threshold;
365 public Choice getAnnotations()
370 public void setAnnotations(Choice annotations)
372 this.annotations = annotations;
376 public void updateView()
378 // Check if combobox is still adjusting
384 AnnotationFilterParameter filterParams = new AnnotationFilterParameter();
385 setCurrentAnnotation(av.getAlignment()
386 .getAlignmentAnnotation()[getAnnotations().getSelectedIndex()]);
388 int selectedThresholdItem = getSelectedThresholdItem(
389 getThreshold().getSelectedIndex());
391 slider.setEnabled(true);
392 thresholdValue.setEnabled(true);
393 percentThreshold.setEnabled(true);
395 if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
397 slider.setEnabled(false);
398 thresholdValue.setEnabled(false);
399 thresholdValue.setText("");
400 percentThreshold.setEnabled(false);
401 // build filter params
403 else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
405 if (getCurrentAnnotation().threshold == null)
407 getCurrentAnnotation().setThreshold(new jalview.datamodel.GraphLine(
408 (getCurrentAnnotation().graphMax
409 - 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));
420 (int) (getCurrentAnnotation().threshold.value * 1000));
421 setThresholdValueText();
422 // slider.setMajorTickSpacing((int) (range / 10f));
423 slider.setEnabled(true);
424 thresholdValue.setEnabled(true);
425 percentThreshold.setEnabled(true);
428 // build filter params
429 filterParams.setThresholdType(
430 AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);
431 if (getCurrentAnnotation().isQuantitative())
434 .setThresholdValue(getCurrentAnnotation().threshold.value);
436 if (selectedThresholdItem == AnnotationColourGradient.ABOVE_THRESHOLD)
438 filterParams.setThresholdType(
439 AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD);
441 else if (selectedThresholdItem == AnnotationColourGradient.BELOW_THRESHOLD)
443 filterParams.setThresholdType(
444 AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD);
449 if (currentStructureFilterPanel != null)
451 if (currentStructureFilterPanel.alphaHelix.getState())
453 filterParams.setFilterAlphaHelix(true);
455 if (currentStructureFilterPanel.betaStrand.getState())
457 filterParams.setFilterBetaSheet(true);
459 if (currentStructureFilterPanel.turn.getState())
461 filterParams.setFilterTurn(true);
465 if (currentSearchPanel != null)
468 if (!currentSearchPanel.searchBox.getText().isEmpty())
470 currentSearchPanel.description.setEnabled(true);
471 currentSearchPanel.displayName.setEnabled(true);
472 filterParams.setRegexString(currentSearchPanel.searchBox.getText());
473 if (currentSearchPanel.displayName.getState())
475 filterParams.addRegexSearchField(
476 AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING);
478 if (currentSearchPanel.description.getState())
480 filterParams.addRegexSearchField(
481 AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION);
486 currentSearchPanel.description.setEnabled(false);
487 currentSearchPanel.displayName.setEnabled(false);
491 // show hidden columns here, before changing the column selection in
492 // filterAnnotations, because showing hidden columns has the side effect of
493 // adding them to the selection
494 av.showAllHiddenColumns();
495 av.getColumnSelection().filterAnnotations(
496 getCurrentAnnotation().annotations, filterParams);
498 if (getActionOption() == ACTION_OPTION_HIDE)
500 av.hideSelectedColumns();
504 av.setAnnotationColumnSelectionState(this);
506 ap.paintAlignment(true, true);
509 public HiddenColumns getOldHiddenColumns()
511 return oldHiddenColumns;
514 public void setOldHiddenColumns(HiddenColumns currentHiddenColumns)
516 if (currentHiddenColumns != null)
518 this.oldHiddenColumns = new HiddenColumns(currentHiddenColumns);
522 public FurtherActionPanel getCurrentFutherActionPanel()
524 return currentFurtherActionPanel;
527 public void setCurrentFutherActionPanel(
528 FurtherActionPanel currentFutherActionPanel)
530 this.currentFurtherActionPanel = currentFutherActionPanel;
533 public SearchPanel getCurrentSearchPanel()
535 return currentSearchPanel;
538 public void setCurrentSearchPanel(SearchPanel currentSearchPanel)
540 this.currentSearchPanel = currentSearchPanel;
543 public int getActionOption()
548 public void setActionOption(int actionOption)
550 this.actionOption = actionOption;
553 public StructureFilterPanel getCurrentStructureFilterPanel()
555 return currentStructureFilterPanel;
558 public void setCurrentStructureFilterPanel(
559 StructureFilterPanel currentStructureFilterPanel)
561 this.currentStructureFilterPanel = currentStructureFilterPanel;
565 public void itemStateChanged(ItemEvent e)
567 if (e.getSource() == annotations)
569 selectedAnnotationChanged();
571 else if (e.getSource() == threshold)
573 threshold_actionPerformed(null);
575 else if (e.getSource() == percentThreshold)
579 percentageValue_actionPerformed();
585 public void selectedAnnotationChanged()
587 String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
588 if (av.getAlignment().getAlignmentAnnotation()[getAnnotations()
589 .getSelectedIndex()].isQuantitative())
591 currentView = AnnotationColumnChooser.GRAPH_VIEW;
594 gSearchPanel.syncState();
595 gFurtherActionPanel.syncState();
596 gStructureFilterPanel.syncState();
598 ngSearchPanel.syncState();
599 ngFurtherActionPanel.syncState();
600 ngStructureFilterPanel.syncState();
602 switchableViewsLayout.show(switchableViewsPanel, currentView);
606 public class FurtherActionPanel extends Panel implements ItemListener
608 private AnnotationColumnChooser aColChooser;
610 private Choice furtherAction = new Choice();
612 public FurtherActionPanel(AnnotationColumnChooser aColChooser)
614 this.aColChooser = aColChooser;
615 furtherAction.addItem("Select");
616 furtherAction.addItem("Hide");
617 furtherAction.addItemListener(this);
620 // this.setTitle("Filter Actions");
621 // this.setFont(JvSwingUtils.getLabelFont());
623 this.add(furtherAction);
626 public void syncState()
629 .getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
631 furtherAction.select("Hide");
635 furtherAction.select("Select");
640 public void itemStateChanged(ItemEvent e)
642 aColChooser.setCurrentFutherActionPanel(this);
643 if (furtherAction.getSelectedItem().equalsIgnoreCase("Select"))
645 setActionOption(ACTION_OPTION_SELECT);
650 setActionOption(ACTION_OPTION_HIDE);
657 public class StructureFilterPanel extends TitledPanel
658 implements ItemListener
660 private AnnotationColumnChooser aColChooser;
662 private Checkbox alphaHelix = new Checkbox();
664 private Checkbox betaStrand = new Checkbox();
666 private Checkbox turn = new Checkbox();
668 private Checkbox all = new Checkbox();
670 public StructureFilterPanel(AnnotationColumnChooser aColChooser)
672 this.aColChooser = aColChooser;
674 alphaHelix.setLabel(MessageManager.getString("label.alpha_helix"));
675 alphaHelix.setBackground(Color.white);
677 alphaHelix.addItemListener(this);
679 betaStrand.setLabel(MessageManager.getString("label.beta_strand"));
680 betaStrand.setBackground(Color.white);
681 betaStrand.addItemListener(this);
683 turn.setLabel(MessageManager.getString("label.turn"));
684 turn.setBackground(Color.white);
685 turn.addItemListener(this);
687 all.setLabel(MessageManager.getString("label.select_all"));
688 all.setBackground(Color.white);
689 all.addItemListener(this);
691 this.setBackground(Color.white);
692 this.setTitle("Structure Filter");
693 // this.setFont(JvSwingUtils.getLabelFont());
696 this.add(alphaHelix);
697 this.add(betaStrand);
701 public void alphaHelix_actionPerformed()
703 updateSelectAllState();
704 aColChooser.setCurrentStructureFilterPanel(this);
705 aColChooser.updateView();
708 public void betaStrand_actionPerformed()
710 updateSelectAllState();
711 aColChooser.setCurrentStructureFilterPanel(this);
712 aColChooser.updateView();
715 public void turn_actionPerformed()
717 updateSelectAllState();
718 aColChooser.setCurrentStructureFilterPanel(this);
719 aColChooser.updateView();
722 public void all_actionPerformed()
726 alphaHelix.setState(true);
727 betaStrand.setState(true);
732 alphaHelix.setState(false);
733 betaStrand.setState(false);
734 turn.setState(false);
736 aColChooser.setCurrentStructureFilterPanel(this);
737 aColChooser.updateView();
740 public void updateSelectAllState()
742 if (alphaHelix.getState() && betaStrand.getState() && turn.getState())
752 public void syncState()
754 StructureFilterPanel sfp = aColChooser
755 .getCurrentStructureFilterPanel();
758 alphaHelix.setState(sfp.alphaHelix.getState());
759 betaStrand.setState(sfp.betaStrand.getState());
760 turn.setState(sfp.turn.getState());
761 if (sfp.all.getState())
764 alphaHelix.setState(true);
765 betaStrand.setState(true);
773 public void itemStateChanged(ItemEvent e)
775 if (e.getSource() == alphaHelix)
777 alphaHelix_actionPerformed();
779 else if (e.getSource() == betaStrand)
781 betaStrand_actionPerformed();
783 else if (e.getSource() == turn)
785 turn_actionPerformed();
787 else if (e.getSource() == all)
789 all_actionPerformed();
794 public class SearchPanel extends TitledPanel implements ItemListener
796 private AnnotationColumnChooser aColChooser;
798 private Checkbox displayName = new Checkbox();
800 private Checkbox description = new Checkbox();
802 private TextField searchBox = new TextField(10);
804 public SearchPanel(AnnotationColumnChooser aColChooser)
807 this.aColChooser = aColChooser;
808 searchBox.addTextListener(new TextListener()
812 public void textValueChanged(TextEvent e)
814 searchStringAction();
820 displayName.setLabel(MessageManager.getString("label.label"));
821 displayName.setEnabled(false);
822 displayName.addItemListener(this);
824 description.setLabel(MessageManager.getString("label.description"));
825 description.setEnabled(false);
826 description.addItemListener(this);
827 this.setTitle("Search Filter");
828 // this.setFont(JvSwingUtils.getLabelFont());
832 this.add(displayName);
833 this.add(description);
836 public void displayNameCheckboxAction()
838 aColChooser.setCurrentSearchPanel(this);
839 aColChooser.updateView();
842 public void discriptionCheckboxAction()
844 aColChooser.setCurrentSearchPanel(this);
845 aColChooser.updateView();
848 public void searchStringAction()
850 aColChooser.setCurrentSearchPanel(this);
851 aColChooser.updateView();
854 public void syncState()
856 SearchPanel sp = aColChooser.getCurrentSearchPanel();
859 description.setEnabled(sp.description.isEnabled());
860 description.setState(sp.description.getState());
862 displayName.setEnabled(sp.displayName.isEnabled());
863 displayName.setState(sp.displayName.getState());
865 searchBox.setText(sp.searchBox.getText());
870 public void itemStateChanged(ItemEvent e)
872 if (e.getSource() == displayName)
874 displayNameCheckboxAction();
876 else if (e.getSource() == description)
878 discriptionCheckboxAction();
885 public void actionPerformed(ActionEvent evt)
888 if (evt.getSource() == ok)
890 ok_actionPerformed(null);
892 else if (evt.getSource() == cancel)
894 cancel_actionPerformed(null);
896 else if (evt.getSource() == thresholdValue)
898 thresholdValue_actionPerformed(null);
907 public void mouseClicked(MouseEvent e)
909 // TODO Auto-generated method stub
914 public void mousePressed(MouseEvent e)
916 if (e.getSource() == slider)
924 public void mouseReleased(MouseEvent e)
926 if (e.getSource() == slider)
933 public void mouseEntered(MouseEvent e)
935 if (e.getSource() == slider)
942 public void mouseExited(MouseEvent e)
944 if (e.getSource() == slider)