3 import jalview.controller.AlignViewController;
4 import jalview.datamodel.AlignmentAnnotation;
5 import jalview.datamodel.ColumnSelection;
6 import jalview.schemes.AnnotationColourGradient;
7 import jalview.util.MessageManager;
8 import jalview.viewmodel.annotationfilter.AnnotationFilterParameter;
10 import java.awt.BorderLayout;
11 import java.awt.CardLayout;
12 import java.awt.Color;
13 import java.awt.Dimension;
14 import java.awt.event.ActionEvent;
15 import java.awt.event.ActionListener;
16 import java.awt.event.ItemEvent;
17 import java.awt.event.ItemListener;
18 import java.util.Iterator;
20 import javax.swing.ButtonGroup;
21 import javax.swing.JButton;
22 import javax.swing.JCheckBox;
23 import javax.swing.JComboBox;
24 import javax.swing.JInternalFrame;
25 import javax.swing.JLayeredPane;
26 import javax.swing.JPanel;
27 import javax.swing.JRadioButton;
28 import javax.swing.JTextField;
29 import javax.swing.border.TitledBorder;
30 import javax.swing.event.DocumentEvent;
31 import javax.swing.event.DocumentListener;
33 import net.miginfocom.swing.MigLayout;
35 @SuppressWarnings("serial")
36 public class AnnotationColumnChooser extends AnnotationRowFilter implements
40 private JComboBox<String> annotations;
42 private JButton ok = new JButton();
44 private JButton cancel = new JButton();
46 private JPanel actionPanel = new JPanel();
48 private JPanel thresholdPanel = new JPanel();
50 private JPanel switchableViewsPanel = new JPanel(new CardLayout());
52 private CardLayout switchableViewsLayout = (CardLayout) (switchableViewsPanel
55 private JPanel noGraphFilterView = new JPanel();
57 private JPanel graphFilterView = new JPanel();
59 private JPanel annotationComboBoxPanel = new JPanel();
61 private BorderLayout borderLayout1 = new BorderLayout();
63 private JComboBox<String> threshold = new JComboBox<String>();
65 private StructureFilterPanel gStructureFilterPanel;
67 private StructureFilterPanel ngStructureFilterPanel;
69 private StructureFilterPanel currentStructureFilterPanel;
71 private SearchPanel currentSearchPanel;
73 private SearchPanel gSearchPanel;
75 private SearchPanel ngSearchPanel;
77 private FurtherActionPanel currentFurtherActionPanel;
79 private FurtherActionPanel gFurtherActionPanel;
81 private FurtherActionPanel ngFurtherActionPanel;
83 public static final int ACTION_OPTION_SELECT = 1;
85 public static int ACTION_OPTION_HIDE = 2;
87 public static String NO_GRAPH_VIEW = "0";
89 public static String GRAPH_VIEW = "1";
91 private int actionOption = ACTION_OPTION_SELECT;
93 private ColumnSelection oldColumnSelection;
95 public AnnotationColumnChooser()
100 } catch (Exception ex)
102 ex.printStackTrace();
106 public AnnotationColumnChooser(AlignViewport av, final AlignmentPanel ap)
109 frame = new JInternalFrame();
110 frame.setContentPane(this);
111 frame.setLayer(JLayeredPane.PALETTE_LAYER);
112 Desktop.addInternalFrame(frame,
113 MessageManager.getString("label.select_by_annotation"), 520,
116 addSliderChangeListener();
117 addSliderMouseListeners();
119 if (av.getAlignment().getAlignmentAnnotation() == null)
123 setOldColumnSelection(av.getColumnSelection());
126 setAnnotations(new JComboBox<String>(getAnnotationItems(false)));
127 populateThresholdComboBox(threshold);
129 // restore Object state from the previous session if one exists
130 if (av.getAnnotationColumnSelectionState() != null)
132 currentSearchPanel = av.getAnnotationColumnSelectionState()
133 .getCurrentSearchPanel();
134 currentStructureFilterPanel = av.getAnnotationColumnSelectionState()
135 .getCurrentStructureFilterPanel();
136 annotations.setSelectedIndex(av.getAnnotationColumnSelectionState()
137 .getAnnotations().getSelectedIndex());
138 threshold.setSelectedIndex(av.getAnnotationColumnSelectionState()
139 .getThreshold().getSelectedIndex());
140 actionOption = av.getAnnotationColumnSelectionState()
147 } catch (Exception ex)
157 private void jbInit() throws Exception
160 ok.setText(MessageManager.getString("action.ok"));
161 ok.addActionListener(new ActionListener()
164 public void actionPerformed(ActionEvent e)
166 ok_actionPerformed(e);
170 cancel.setOpaque(false);
171 cancel.setText(MessageManager.getString("action.cancel"));
172 cancel.addActionListener(new ActionListener()
175 public void actionPerformed(ActionEvent e)
177 cancel_actionPerformed(e);
181 annotations.addItemListener(this);
182 threshold.addActionListener(new ActionListener()
185 public void actionPerformed(ActionEvent e)
187 threshold_actionPerformed(e);
191 thresholdValue.setEnabled(false);
192 thresholdValue.setColumns(7);
193 thresholdValue.addActionListener(new ActionListener()
196 public void actionPerformed(ActionEvent e)
198 thresholdValue_actionPerformed(e);
202 slider.setPaintLabels(false);
203 slider.setPaintTicks(true);
204 slider.setBackground(Color.white);
205 slider.setEnabled(false);
206 slider.setOpaque(false);
207 slider.setPreferredSize(new Dimension(100, 32));
209 thresholdPanel.setBorder(new TitledBorder(MessageManager
210 .getString("label.threshold_filter")));
211 thresholdPanel.setBackground(Color.white);
212 thresholdPanel.setFont(JvSwingUtils.getLabelFont());
213 thresholdPanel.setLayout(new MigLayout("", "[left][right]", "[][]"));
215 actionPanel.setBackground(Color.white);
216 actionPanel.setFont(JvSwingUtils.getLabelFont());
218 graphFilterView.setLayout(new MigLayout("", "[left][right]", "[][]"));
219 graphFilterView.setBackground(Color.white);
221 noGraphFilterView.setLayout(new MigLayout("", "[left][right]", "[][]"));
222 noGraphFilterView.setBackground(Color.white);
224 annotationComboBoxPanel.setBackground(Color.white);
225 annotationComboBoxPanel.setFont(JvSwingUtils.getLabelFont());
227 gSearchPanel = new SearchPanel(this);
228 ngSearchPanel = new SearchPanel(this);
229 gFurtherActionPanel = new FurtherActionPanel(this);
230 ngFurtherActionPanel = new FurtherActionPanel(this);
231 gStructureFilterPanel = new StructureFilterPanel(this);
232 ngStructureFilterPanel = new StructureFilterPanel(this);
234 thresholdPanel.add(getThreshold());
235 thresholdPanel.add(thresholdValue, "wrap");
236 thresholdPanel.add(slider, "grow, span, wrap");
239 actionPanel.add(cancel);
241 graphFilterView.add(gSearchPanel, "grow, span, wrap");
242 graphFilterView.add(gStructureFilterPanel, "grow, span, wrap");
243 graphFilterView.add(thresholdPanel, "grow, span, wrap");
244 graphFilterView.add(gFurtherActionPanel);
246 noGraphFilterView.add(ngSearchPanel, "grow, span, wrap");
247 noGraphFilterView.add(ngStructureFilterPanel, "grow, span, wrap");
248 noGraphFilterView.add(ngFurtherActionPanel);
250 annotationComboBoxPanel.add(getAnnotations());
251 switchableViewsPanel.add(noGraphFilterView,
252 AnnotationColumnChooser.NO_GRAPH_VIEW);
253 switchableViewsPanel.add(graphFilterView,
254 AnnotationColumnChooser.GRAPH_VIEW);
256 this.setLayout(borderLayout1);
257 this.add(annotationComboBoxPanel, java.awt.BorderLayout.PAGE_START);
258 this.add(switchableViewsPanel, java.awt.BorderLayout.CENTER);
259 this.add(actionPanel, java.awt.BorderLayout.SOUTH);
261 selectedAnnotationChanged();
265 @SuppressWarnings("unchecked")
268 if (this.getOldColumnSelection() != null)
270 av.getColumnSelection().clear();
272 if (av.getAnnotationColumnSelectionState() != null)
274 ColumnSelection oldSelection = av
275 .getAnnotationColumnSelectionState()
276 .getOldColumnSelection();
277 if (oldSelection != null && oldSelection.getHiddenColumns() != null
278 && !oldSelection.getHiddenColumns().isEmpty())
280 for (Iterator<int[]> itr = oldSelection.getHiddenColumns()
281 .iterator(); itr.hasNext();)
283 int positions[] = itr.next();
284 av.hideColumns(positions[0], positions[1]);
287 av.setColumnSelection(oldSelection);
289 ap.paintAlignment(true);
294 public void valueChanged(boolean updateAllAnnotation)
296 if (slider.isEnabled())
298 getCurrentAnnotation().threshold.value = slider.getValue() / 1000f;
300 propagateSeqAssociatedThreshold(updateAllAnnotation,
301 getCurrentAnnotation());
302 ap.paintAlignment(false);
306 public JComboBox<String> getThreshold()
311 public void setThreshold(JComboBox<String> threshold)
313 this.threshold = threshold;
316 public JComboBox<String> getAnnotations()
321 public void setAnnotations(JComboBox<String> annotations)
323 this.annotations = annotations;
327 public void updateView()
329 // Check if combobox is still adjusting
335 AnnotationFilterParameter filterParams = new AnnotationFilterParameter();
337 setCurrentAnnotation(av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
338 .getSelectedIndex()]]);
340 int selectedThresholdItem = getSelectedThresholdItem(getThreshold()
341 .getSelectedIndex());
343 slider.setEnabled(true);
344 thresholdValue.setEnabled(true);
346 if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
348 slider.setEnabled(false);
349 thresholdValue.setEnabled(false);
350 thresholdValue.setText("");
351 // build filter params
353 else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
355 if (getCurrentAnnotation().threshold == null)
357 getCurrentAnnotation()
359 new jalview.datamodel.GraphLine(
360 (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin) / 2f,
361 "Threshold", Color.black));
365 float range = getCurrentAnnotation().graphMax * 1000
366 - getCurrentAnnotation().graphMin * 1000;
368 slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
369 slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
370 slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000));
371 thresholdValue.setText(getCurrentAnnotation().threshold.value + "");
372 slider.setMajorTickSpacing((int) (range / 10f));
373 slider.setEnabled(true);
374 thresholdValue.setEnabled(true);
377 // build filter params
379 .setThresholdType(AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);
380 if (getCurrentAnnotation().graph != AlignmentAnnotation.NO_GRAPH)
383 .setThresholdValue(getCurrentAnnotation().threshold.value);
385 if (selectedThresholdItem == AnnotationColourGradient.ABOVE_THRESHOLD)
388 .setThresholdType(AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD);
390 else if (selectedThresholdItem == AnnotationColourGradient.BELOW_THRESHOLD)
393 .setThresholdType(AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD);
398 if (currentStructureFilterPanel != null)
400 if (currentStructureFilterPanel.alphaHelix.isSelected())
402 filterParams.setFilterAlphaHelix(true);
404 if (currentStructureFilterPanel.betaStrand.isSelected())
406 filterParams.setFilterBetaSheet(true);
408 if (currentStructureFilterPanel.turn.isSelected())
410 filterParams.setFilterTurn(true);
414 if (currentSearchPanel != null)
417 if (!currentSearchPanel.searchBox.getText().isEmpty())
419 currentSearchPanel.description.setEnabled(true);
420 currentSearchPanel.displayName.setEnabled(true);
421 filterParams.setRegexString(currentSearchPanel.searchBox.getText());
422 if (currentSearchPanel.displayName.isSelected())
425 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING);
427 if (currentSearchPanel.description.isSelected())
430 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION);
435 currentSearchPanel.description.setEnabled(false);
436 currentSearchPanel.displayName.setEnabled(false);
440 AlignViewController.filterAnnotations(
441 getCurrentAnnotation().annotations, filterParams,
442 av.getColumnSelection());
444 av.showAllHiddenColumns();
445 if (getActionOption() == ACTION_OPTION_HIDE)
447 av.hideSelectedColumns();
451 av.setAnnotationColumnSelectionState(this);
452 ap.paintAlignment(true);
455 public ColumnSelection getOldColumnSelection()
457 return oldColumnSelection;
460 public void setOldColumnSelection(ColumnSelection currentColumnSelection)
462 if (currentColumnSelection != null)
464 this.oldColumnSelection = new ColumnSelection(currentColumnSelection);
468 public FurtherActionPanel getCurrentFutherActionPanel()
470 return currentFurtherActionPanel;
473 public void setCurrentFutherActionPanel(
474 FurtherActionPanel currentFutherActionPanel)
476 this.currentFurtherActionPanel = currentFutherActionPanel;
479 public SearchPanel getCurrentSearchPanel()
481 return currentSearchPanel;
484 public void setCurrentSearchPanel(SearchPanel currentSearchPanel)
486 this.currentSearchPanel = currentSearchPanel;
489 public int getActionOption()
494 public void setActionOption(int actionOption)
496 this.actionOption = actionOption;
499 public StructureFilterPanel getCurrentStructureFilterPanel()
501 return currentStructureFilterPanel;
504 public void setCurrentStructureFilterPanel(
505 StructureFilterPanel currentStructureFilterPanel)
507 this.currentStructureFilterPanel = currentStructureFilterPanel;
510 public void select_action(ActionEvent actionEvent)
512 JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
513 if (radioButton.isSelected())
515 setActionOption(ACTION_OPTION_SELECT);
520 public void hide_action(ActionEvent actionEvent)
522 JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
523 if (radioButton.isSelected())
525 setActionOption(ACTION_OPTION_HIDE);
531 public void itemStateChanged(ItemEvent e)
533 selectedAnnotationChanged();
536 public void selectedAnnotationChanged()
538 String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
539 if (av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
540 .getSelectedIndex()]].graph != AlignmentAnnotation.NO_GRAPH)
542 currentView = AnnotationColumnChooser.GRAPH_VIEW;
545 gSearchPanel.syncState();
546 gFurtherActionPanel.syncState();
547 gStructureFilterPanel.syncState();
549 ngSearchPanel.syncState();
550 ngFurtherActionPanel.syncState();
551 ngStructureFilterPanel.syncState();
553 switchableViewsLayout.show(switchableViewsPanel, currentView);
558 public class FurtherActionPanel extends JPanel
560 private AnnotationColumnChooser aColChooser;
562 private JRadioButton hideOption = new JRadioButton();
564 private JRadioButton selectOption = new JRadioButton();
566 private ButtonGroup optionsGroup = new ButtonGroup();
568 public FurtherActionPanel(AnnotationColumnChooser aColChooser)
570 this.aColChooser = aColChooser;
571 JvSwingUtils.jvInitComponent(selectOption, "action.select");
572 selectOption.addActionListener(new ActionListener()
575 public void actionPerformed(ActionEvent actionEvent)
577 selectRadioAction(actionEvent);
581 JvSwingUtils.jvInitComponent(hideOption, "action.hide");
582 hideOption.addActionListener(new ActionListener()
585 public void actionPerformed(ActionEvent actionEvent)
587 hideRadioAction(actionEvent);
591 optionsGroup.add(selectOption);
592 optionsGroup.add(hideOption);
593 optionsGroup.setSelected(selectOption.getModel(), true);
595 JvSwingUtils.jvInitComponent(this);
598 this.add(selectOption);
599 this.add(hideOption);
602 public void selectRadioAction(ActionEvent actionEvent)
604 aColChooser.setCurrentFutherActionPanel(this);
605 aColChooser.select_action(actionEvent);
608 public void hideRadioAction(ActionEvent actionEvent)
610 aColChooser.setCurrentFutherActionPanel(this);
611 aColChooser.hide_action(actionEvent);
614 public void syncState()
616 if (aColChooser.getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
618 this.optionsGroup.setSelected(this.hideOption.getModel(),
623 this.optionsGroup.setSelected(this.selectOption.getModel(), true);
628 public class StructureFilterPanel extends JPanel
630 private AnnotationColumnChooser aColChooser;
632 private JCheckBox alphaHelix = new JCheckBox();
634 private JCheckBox betaStrand = new JCheckBox();
636 private JCheckBox turn = new JCheckBox();
638 private JCheckBox all = new JCheckBox();
640 public StructureFilterPanel(AnnotationColumnChooser aColChooser)
642 this.aColChooser = aColChooser;
644 JvSwingUtils.jvInitComponent(alphaHelix, "label.alpha_helix");
645 alphaHelix.addActionListener(new ActionListener()
648 public void actionPerformed(ActionEvent actionEvent)
650 alphaHelix_actionPerformed();
654 JvSwingUtils.jvInitComponent(betaStrand, "label.beta_strand");
655 betaStrand.addActionListener(new ActionListener()
658 public void actionPerformed(ActionEvent actionEvent)
660 betaStrand_actionPerformed();
664 JvSwingUtils.jvInitComponent(turn, "label.turn");
665 turn.addActionListener(new ActionListener()
668 public void actionPerformed(ActionEvent actionEvent)
670 turn_actionPerformed();
674 JvSwingUtils.jvInitComponent(all, "label.select_all");
675 all.addActionListener(new ActionListener()
678 public void actionPerformed(ActionEvent actionEvent)
680 all_actionPerformed();
684 this.setBorder(new TitledBorder(MessageManager
685 .getString("label.structures_filter")));
686 JvSwingUtils.jvInitComponent(this);
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()
717 if (all.isSelected())
719 alphaHelix.setSelected(true);
720 betaStrand.setSelected(true);
721 turn.setSelected(true);
725 alphaHelix.setSelected(false);
726 betaStrand.setSelected(false);
727 turn.setSelected(false);
729 aColChooser.setCurrentStructureFilterPanel(this);
730 aColChooser.updateView();
733 public void updateSelectAllState()
735 if (alphaHelix.isSelected() && betaStrand.isSelected()
736 && turn.isSelected())
738 all.setSelected(true);
742 all.setSelected(false);
746 public void syncState()
748 StructureFilterPanel sfp = aColChooser
749 .getCurrentStructureFilterPanel();
752 alphaHelix.setSelected(sfp.alphaHelix.isSelected());
753 betaStrand.setSelected(sfp.betaStrand.isSelected());
754 turn.setSelected(sfp.turn.isSelected());
755 if (sfp.all.isSelected())
757 all.setSelected(true);
758 alphaHelix.setSelected(true);
759 betaStrand.setSelected(true);
760 turn.setSelected(true);
767 public class SearchPanel extends JPanel
769 private AnnotationColumnChooser aColChooser;
771 private JCheckBox displayName = new JCheckBox();
773 private JCheckBox description = new JCheckBox();
775 private JTextField searchBox = new JTextField(10);
777 public SearchPanel(AnnotationColumnChooser aColChooser)
780 this.aColChooser = aColChooser;
781 JvSwingUtils.jvInitComponent(this);
782 this.setBorder(new TitledBorder(MessageManager
783 .getString("label.search_filter")));
785 JvSwingUtils.jvInitComponent(searchBox);
786 searchBox.getDocument().addDocumentListener(
787 new DocumentListener()
790 public void insertUpdate(DocumentEvent e)
792 searchStringAction();
796 public void removeUpdate(DocumentEvent e)
798 searchStringAction();
802 public void changedUpdate(DocumentEvent e)
804 searchStringAction();
808 JvSwingUtils.jvInitComponent(displayName, "label.display_name");
809 displayName.setEnabled(false);
810 displayName.addActionListener(new ActionListener()
813 public void actionPerformed(ActionEvent actionEvent)
815 displayNameCheckboxAction();
819 JvSwingUtils.jvInitComponent(description, "label.description");
820 description.setEnabled(false);
821 description.addActionListener(new ActionListener()
824 public void actionPerformed(ActionEvent actionEvent)
826 discriptionCheckboxAction();
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.setSelected(sp.description.isSelected());
862 displayName.setEnabled(sp.displayName.isEnabled());
863 displayName.setSelected(sp.displayName.isSelected());
865 searchBox.setText(sp.searchBox.getText());