3 import jalview.datamodel.AlignmentAnnotation;
4 import jalview.datamodel.ColumnSelection;
5 import jalview.schemes.AnnotationColourGradient;
6 import jalview.util.MessageManager;
7 import jalview.viewmodel.annotationfilter.AnnotationFilterParameter;
9 import java.awt.BorderLayout;
10 import java.awt.CardLayout;
11 import java.awt.Color;
12 import java.awt.Dimension;
13 import java.awt.event.ActionEvent;
14 import java.awt.event.ActionListener;
15 import java.awt.event.ItemEvent;
16 import java.awt.event.ItemListener;
17 import java.util.Iterator;
19 import javax.swing.ButtonGroup;
20 import javax.swing.JCheckBox;
21 import javax.swing.JComboBox;
22 import javax.swing.JInternalFrame;
23 import javax.swing.JLayeredPane;
24 import javax.swing.JPanel;
25 import javax.swing.JRadioButton;
26 import javax.swing.JTextField;
27 import javax.swing.border.TitledBorder;
28 import javax.swing.event.DocumentEvent;
29 import javax.swing.event.DocumentListener;
31 import net.miginfocom.swing.MigLayout;
33 @SuppressWarnings("serial")
34 public class AnnotationColumnChooser extends AnnotationRowFilter implements
38 private JComboBox<String> annotations;
40 // private JButton ok = new JButton();
42 // private JButton cancel = new JButton();
44 private JPanel actionPanel = new JPanel();
46 private JPanel thresholdPanel = new JPanel();
48 private JPanel switchableViewsPanel = new JPanel(new CardLayout());
50 private CardLayout switchableViewsLayout = (CardLayout) (switchableViewsPanel
52 private JPanel noGraphFilterView = new JPanel();
54 private JPanel graphFilterView = new JPanel();
56 private JPanel annotationComboBoxPanel = new JPanel();
58 private BorderLayout borderLayout1 = new BorderLayout();
60 private JComboBox<String> threshold = new JComboBox<String>();
62 private StructureFilterPanel gStructureFilterPanel;
64 private StructureFilterPanel ngStructureFilterPanel;
66 private StructureFilterPanel currentStructureFilterPanel;
68 private SearchPanel currentSearchPanel;
70 private SearchPanel gSearchPanel;
72 private SearchPanel ngSearchPanel;
74 private FurtherActionPanel currentFurtherActionPanel;
76 private FurtherActionPanel gFurtherActionPanel;
78 private FurtherActionPanel ngFurtherActionPanel;
80 public static final int ACTION_OPTION_SELECT = 1;
82 public static int ACTION_OPTION_HIDE = 2;
84 public static String NO_GRAPH_VIEW = "0";
86 public static String GRAPH_VIEW = "1";
88 private int actionOption = ACTION_OPTION_SELECT;
90 private ColumnSelection oldColumnSelection;
92 public AnnotationColumnChooser()
97 } catch (Exception ex)
103 public AnnotationColumnChooser(AlignViewport av, final AlignmentPanel ap)
106 frame = new JInternalFrame();
107 frame.setContentPane(this);
108 frame.setLayer(JLayeredPane.PALETTE_LAYER);
109 Desktop.addInternalFrame(frame,
110 MessageManager.getString("label.select_by_annotation"), 520,
113 addSliderChangeListener();
114 addSliderMouseListeners();
116 if (av.getAlignment().getAlignmentAnnotation() == null)
120 setOldColumnSelection(av.getColumnSelection());
123 setAnnotations(new JComboBox<String>(getAnnotationItems(false)));
124 populateThresholdComboBox(threshold);
126 // restore Object state from the previous session if one exists
127 if (av.getAnnotationColumnSelectionState() != null)
129 currentSearchPanel = av.getAnnotationColumnSelectionState()
130 .getCurrentSearchPanel();
131 currentStructureFilterPanel = av.getAnnotationColumnSelectionState()
132 .getCurrentStructureFilterPanel();
133 annotations.setSelectedIndex(av.getAnnotationColumnSelectionState()
134 .getAnnotations().getSelectedIndex());
135 threshold.setSelectedIndex(av.getAnnotationColumnSelectionState()
136 .getThreshold().getSelectedIndex());
137 actionOption = av.getAnnotationColumnSelectionState()
144 } catch (Exception ex)
154 private void jbInit() throws Exception
157 ok.setText(MessageManager.getString("action.ok"));
158 ok.addActionListener(new ActionListener()
161 public void actionPerformed(ActionEvent e)
163 ok_actionPerformed(e);
167 cancel.setOpaque(false);
168 cancel.setText(MessageManager.getString("action.cancel"));
169 cancel.addActionListener(new ActionListener()
172 public void actionPerformed(ActionEvent e)
174 cancel_actionPerformed(e);
178 annotations.addItemListener(this);
179 threshold.addActionListener(new ActionListener()
182 public void actionPerformed(ActionEvent e)
184 threshold_actionPerformed(e);
188 thresholdValue.setEnabled(false);
189 thresholdValue.setColumns(7);
190 thresholdValue.addActionListener(new ActionListener()
193 public void actionPerformed(ActionEvent e)
195 thresholdValue_actionPerformed(e);
199 slider.setPaintLabels(false);
200 slider.setPaintTicks(true);
201 slider.setBackground(Color.white);
202 slider.setEnabled(false);
203 slider.setOpaque(false);
204 slider.setPreferredSize(new Dimension(100, 32));
206 thresholdPanel.setBorder(new TitledBorder(MessageManager
207 .getString("label.threshold_filter")));
208 thresholdPanel.setBackground(Color.white);
209 thresholdPanel.setFont(JvSwingUtils.getLabelFont());
210 thresholdPanel.setLayout(new MigLayout("", "[left][right]", "[][]"));
212 actionPanel.setBackground(Color.white);
213 actionPanel.setFont(JvSwingUtils.getLabelFont());
215 graphFilterView.setLayout(new MigLayout("", "[left][right]", "[][]"));
216 graphFilterView.setBackground(Color.white);
218 noGraphFilterView.setLayout(new MigLayout("", "[left][right]", "[][]"));
219 noGraphFilterView.setBackground(Color.white);
221 annotationComboBoxPanel.setBackground(Color.white);
222 annotationComboBoxPanel.setFont(JvSwingUtils.getLabelFont());
224 gSearchPanel = new SearchPanel(this);
225 ngSearchPanel = new SearchPanel(this);
226 gFurtherActionPanel = new FurtherActionPanel(this);
227 ngFurtherActionPanel = new FurtherActionPanel(this);
228 gStructureFilterPanel = new StructureFilterPanel(this);
229 ngStructureFilterPanel = new StructureFilterPanel(this);
231 thresholdPanel.add(getThreshold());
232 thresholdPanel.add(thresholdValue, "wrap");
233 thresholdPanel.add(slider, "grow, span, wrap");
236 actionPanel.add(cancel);
238 graphFilterView.add(gSearchPanel, "grow, span, wrap");
239 graphFilterView.add(gStructureFilterPanel, "grow, span, wrap");
240 graphFilterView.add(thresholdPanel, "grow, span, wrap");
241 graphFilterView.add(gFurtherActionPanel);
243 noGraphFilterView.add(ngSearchPanel, "grow, span, wrap");
244 noGraphFilterView.add(ngStructureFilterPanel, "grow, span, wrap");
245 noGraphFilterView.add(ngFurtherActionPanel);
247 annotationComboBoxPanel.add(getAnnotations());
248 switchableViewsPanel.add(noGraphFilterView,
249 AnnotationColumnChooser.NO_GRAPH_VIEW);
250 switchableViewsPanel.add(graphFilterView,
251 AnnotationColumnChooser.GRAPH_VIEW);
253 this.setLayout(borderLayout1);
254 this.add(annotationComboBoxPanel, java.awt.BorderLayout.PAGE_START);
255 this.add(switchableViewsPanel, java.awt.BorderLayout.CENTER);
256 this.add(actionPanel, java.awt.BorderLayout.SOUTH);
258 selectedAnnotationChanged();
262 @SuppressWarnings("unchecked")
265 if (this.getOldColumnSelection() != null)
267 av.getColumnSelection().clear();
269 if (av.getAnnotationColumnSelectionState() != null)
271 ColumnSelection oldSelection = av
272 .getAnnotationColumnSelectionState()
273 .getOldColumnSelection();
274 if (oldSelection != null && oldSelection.getHiddenColumns() != null
275 && !oldSelection.getHiddenColumns().isEmpty())
277 for (Iterator<int[]> itr = oldSelection.getHiddenColumns()
278 .iterator(); itr.hasNext();)
280 int positions[] = itr.next();
281 av.hideColumns(positions[0], positions[1]);
284 av.setColumnSelection(oldSelection);
286 ap.paintAlignment(true);
291 public void valueChanged(boolean updateAllAnnotation)
293 if (slider.isEnabled())
295 getCurrentAnnotation().threshold.value = slider.getValue() / 1000f;
297 propagateSeqAssociatedThreshold(updateAllAnnotation,
298 getCurrentAnnotation());
299 ap.paintAlignment(false);
303 public JComboBox<String> getThreshold()
308 public void setThreshold(JComboBox<String> threshold)
310 this.threshold = threshold;
313 public JComboBox<String> getAnnotations()
318 public void setAnnotations(JComboBox<String> annotations)
320 this.annotations = annotations;
324 public void updateView()
326 // Check if combobox is still adjusting
332 AnnotationFilterParameter filterParams = new AnnotationFilterParameter();
334 setCurrentAnnotation(av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
335 .getSelectedIndex()]]);
337 int selectedThresholdItem = getSelectedThresholdItem(getThreshold()
338 .getSelectedIndex());
340 slider.setEnabled(true);
341 thresholdValue.setEnabled(true);
343 if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
345 slider.setEnabled(false);
346 thresholdValue.setEnabled(false);
347 thresholdValue.setText("");
348 // build filter params
350 else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
352 if (getCurrentAnnotation().threshold == null)
354 getCurrentAnnotation()
356 new jalview.datamodel.GraphLine(
357 (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin) / 2f,
358 "Threshold", Color.black));
362 float range = getCurrentAnnotation().graphMax * 1000
363 - getCurrentAnnotation().graphMin * 1000;
365 slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
366 slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
367 slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000));
368 thresholdValue.setText(getCurrentAnnotation().threshold.value + "");
369 slider.setMajorTickSpacing((int) (range / 10f));
370 slider.setEnabled(true);
371 thresholdValue.setEnabled(true);
374 // build filter params
376 .setThresholdType(AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);
377 if (getCurrentAnnotation().graph != AlignmentAnnotation.NO_GRAPH)
380 .setThresholdValue(getCurrentAnnotation().threshold.value);
382 if (selectedThresholdItem == AnnotationColourGradient.ABOVE_THRESHOLD)
385 .setThresholdType(AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD);
387 else if (selectedThresholdItem == AnnotationColourGradient.BELOW_THRESHOLD)
390 .setThresholdType(AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD);
395 if (currentStructureFilterPanel != null)
397 if (currentStructureFilterPanel.alphaHelix.isSelected())
399 filterParams.setFilterAlphaHelix(true);
401 if (currentStructureFilterPanel.betaStrand.isSelected())
403 filterParams.setFilterBetaSheet(true);
405 if (currentStructureFilterPanel.turn.isSelected())
407 filterParams.setFilterTurn(true);
411 if (currentSearchPanel != null)
414 if (!currentSearchPanel.searchBox.getText().isEmpty())
416 currentSearchPanel.description.setEnabled(true);
417 currentSearchPanel.displayName.setEnabled(true);
418 filterParams.setRegexString(currentSearchPanel.searchBox.getText());
419 if (currentSearchPanel.displayName.isSelected())
422 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING);
424 if (currentSearchPanel.description.isSelected())
427 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION);
432 currentSearchPanel.description.setEnabled(false);
433 currentSearchPanel.displayName.setEnabled(false);
437 av.getColumnSelection().filterAnnotations(
438 getCurrentAnnotation().annotations, filterParams);
440 av.showAllHiddenColumns();
441 if (getActionOption() == ACTION_OPTION_HIDE)
443 av.hideSelectedColumns();
447 av.setAnnotationColumnSelectionState(this);
448 ap.paintAlignment(true);
451 public ColumnSelection getOldColumnSelection()
453 return oldColumnSelection;
456 public void setOldColumnSelection(ColumnSelection currentColumnSelection)
458 if (currentColumnSelection != null)
460 this.oldColumnSelection = new ColumnSelection(currentColumnSelection);
464 public FurtherActionPanel getCurrentFutherActionPanel()
466 return currentFurtherActionPanel;
469 public void setCurrentFutherActionPanel(
470 FurtherActionPanel currentFutherActionPanel)
472 this.currentFurtherActionPanel = currentFutherActionPanel;
475 public SearchPanel getCurrentSearchPanel()
477 return currentSearchPanel;
480 public void setCurrentSearchPanel(SearchPanel currentSearchPanel)
482 this.currentSearchPanel = currentSearchPanel;
485 public int getActionOption()
490 public void setActionOption(int actionOption)
492 this.actionOption = actionOption;
495 public StructureFilterPanel getCurrentStructureFilterPanel()
497 return currentStructureFilterPanel;
500 public void setCurrentStructureFilterPanel(
501 StructureFilterPanel currentStructureFilterPanel)
503 this.currentStructureFilterPanel = currentStructureFilterPanel;
506 public void select_action(ActionEvent actionEvent)
508 JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
509 if (radioButton.isSelected())
511 setActionOption(ACTION_OPTION_SELECT);
516 public void hide_action(ActionEvent actionEvent)
518 JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
519 if (radioButton.isSelected())
521 setActionOption(ACTION_OPTION_HIDE);
527 public void itemStateChanged(ItemEvent e)
529 selectedAnnotationChanged();
532 public void selectedAnnotationChanged()
534 String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
535 if (av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
536 .getSelectedIndex()]].graph != AlignmentAnnotation.NO_GRAPH)
538 currentView = AnnotationColumnChooser.GRAPH_VIEW;
541 gSearchPanel.syncState();
542 gFurtherActionPanel.syncState();
543 gStructureFilterPanel.syncState();
545 ngSearchPanel.syncState();
546 ngFurtherActionPanel.syncState();
547 ngStructureFilterPanel.syncState();
549 switchableViewsLayout.show(switchableViewsPanel, currentView);
554 public class FurtherActionPanel extends JPanel
556 private AnnotationColumnChooser aColChooser;
558 private JRadioButton hideOption = new JRadioButton();
560 private JRadioButton selectOption = new JRadioButton();
562 private ButtonGroup optionsGroup = new ButtonGroup();
564 public FurtherActionPanel(AnnotationColumnChooser aColChooser)
566 this.aColChooser = aColChooser;
567 JvSwingUtils.jvInitComponent(selectOption, "action.select");
568 selectOption.addActionListener(new ActionListener()
571 public void actionPerformed(ActionEvent actionEvent)
573 selectRadioAction(actionEvent);
577 JvSwingUtils.jvInitComponent(hideOption, "action.hide");
578 hideOption.addActionListener(new ActionListener()
581 public void actionPerformed(ActionEvent actionEvent)
583 hideRadioAction(actionEvent);
587 optionsGroup.add(selectOption);
588 optionsGroup.add(hideOption);
589 optionsGroup.setSelected(selectOption.getModel(), true);
591 JvSwingUtils.jvInitComponent(this);
594 this.add(selectOption);
595 this.add(hideOption);
598 public void selectRadioAction(ActionEvent actionEvent)
600 aColChooser.setCurrentFutherActionPanel(this);
601 aColChooser.select_action(actionEvent);
604 public void hideRadioAction(ActionEvent actionEvent)
606 aColChooser.setCurrentFutherActionPanel(this);
607 aColChooser.hide_action(actionEvent);
610 public void syncState()
612 if (aColChooser.getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
614 this.optionsGroup.setSelected(this.hideOption.getModel(),
619 this.optionsGroup.setSelected(this.selectOption.getModel(), true);
624 public class StructureFilterPanel extends JPanel
626 private AnnotationColumnChooser aColChooser;
628 private JCheckBox alphaHelix = new JCheckBox();
630 private JCheckBox betaStrand = new JCheckBox();
632 private JCheckBox turn = new JCheckBox();
634 private JCheckBox all = new JCheckBox();
636 public StructureFilterPanel(AnnotationColumnChooser aColChooser)
638 this.aColChooser = aColChooser;
640 JvSwingUtils.jvInitComponent(alphaHelix, "label.alpha_helix");
641 alphaHelix.addActionListener(new ActionListener()
644 public void actionPerformed(ActionEvent actionEvent)
646 alphaHelix_actionPerformed();
650 JvSwingUtils.jvInitComponent(betaStrand, "label.beta_strand");
651 betaStrand.addActionListener(new ActionListener()
654 public void actionPerformed(ActionEvent actionEvent)
656 betaStrand_actionPerformed();
660 JvSwingUtils.jvInitComponent(turn, "label.turn");
661 turn.addActionListener(new ActionListener()
664 public void actionPerformed(ActionEvent actionEvent)
666 turn_actionPerformed();
670 JvSwingUtils.jvInitComponent(all, "label.select_all");
671 all.addActionListener(new ActionListener()
674 public void actionPerformed(ActionEvent actionEvent)
676 all_actionPerformed();
680 this.setBorder(new TitledBorder(MessageManager
681 .getString("label.structures_filter")));
682 JvSwingUtils.jvInitComponent(this);
685 this.add(alphaHelix);
686 this.add(betaStrand);
690 public void alphaHelix_actionPerformed()
692 updateSelectAllState();
693 aColChooser.setCurrentStructureFilterPanel(this);
694 aColChooser.updateView();
697 public void betaStrand_actionPerformed()
699 updateSelectAllState();
700 aColChooser.setCurrentStructureFilterPanel(this);
701 aColChooser.updateView();
704 public void turn_actionPerformed()
706 updateSelectAllState();
707 aColChooser.setCurrentStructureFilterPanel(this);
708 aColChooser.updateView();
711 public void all_actionPerformed()
713 if (all.isSelected())
715 alphaHelix.setSelected(true);
716 betaStrand.setSelected(true);
717 turn.setSelected(true);
721 alphaHelix.setSelected(false);
722 betaStrand.setSelected(false);
723 turn.setSelected(false);
725 aColChooser.setCurrentStructureFilterPanel(this);
726 aColChooser.updateView();
729 public void updateSelectAllState()
731 if (alphaHelix.isSelected() && betaStrand.isSelected()
732 && turn.isSelected())
734 all.setSelected(true);
738 all.setSelected(false);
742 public void syncState()
744 StructureFilterPanel sfp = aColChooser
745 .getCurrentStructureFilterPanel();
748 alphaHelix.setSelected(sfp.alphaHelix.isSelected());
749 betaStrand.setSelected(sfp.betaStrand.isSelected());
750 turn.setSelected(sfp.turn.isSelected());
751 if (sfp.all.isSelected())
753 all.setSelected(true);
754 alphaHelix.setSelected(true);
755 betaStrand.setSelected(true);
756 turn.setSelected(true);
763 public class SearchPanel extends JPanel
765 private AnnotationColumnChooser aColChooser;
767 private JCheckBox displayName = new JCheckBox();
769 private JCheckBox description = new JCheckBox();
771 private JTextField searchBox = new JTextField(10);
773 public SearchPanel(AnnotationColumnChooser aColChooser)
776 this.aColChooser = aColChooser;
777 JvSwingUtils.jvInitComponent(this);
778 this.setBorder(new TitledBorder(MessageManager
779 .getString("label.search_filter")));
781 JvSwingUtils.jvInitComponent(searchBox);
782 searchBox.getDocument().addDocumentListener(
783 new DocumentListener()
786 public void insertUpdate(DocumentEvent e)
788 searchStringAction();
792 public void removeUpdate(DocumentEvent e)
794 searchStringAction();
798 public void changedUpdate(DocumentEvent e)
800 searchStringAction();
804 JvSwingUtils.jvInitComponent(displayName, "label.display_name");
805 displayName.setEnabled(false);
806 displayName.addActionListener(new ActionListener()
809 public void actionPerformed(ActionEvent actionEvent)
811 displayNameCheckboxAction();
815 JvSwingUtils.jvInitComponent(description, "label.description");
816 description.setEnabled(false);
817 description.addActionListener(new ActionListener()
820 public void actionPerformed(ActionEvent actionEvent)
822 discriptionCheckboxAction();
828 this.add(displayName);
829 this.add(description);
832 public void displayNameCheckboxAction()
834 aColChooser.setCurrentSearchPanel(this);
835 aColChooser.updateView();
838 public void discriptionCheckboxAction()
840 aColChooser.setCurrentSearchPanel(this);
841 aColChooser.updateView();
844 public void searchStringAction()
846 aColChooser.setCurrentSearchPanel(this);
847 aColChooser.updateView();
850 public void syncState()
852 SearchPanel sp = aColChooser.getCurrentSearchPanel();
855 description.setEnabled(sp.description.isEnabled());
856 description.setSelected(sp.description.isSelected());
858 displayName.setEnabled(sp.displayName.isEnabled());
859 displayName.setSelected(sp.displayName.isSelected());
861 searchBox.setText(sp.searchBox.getText());