1 package jalview.appletgui;
3 import jalview.datamodel.AlignmentAnnotation;
4 import jalview.datamodel.ColumnSelection;
5 import jalview.gui.JvSwingUtils;
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.Checkbox;
13 import java.awt.Choice;
14 import java.awt.Color;
15 import java.awt.Dimension;
16 import java.awt.Frame;
17 import java.awt.Panel;
18 import java.awt.TextField;
19 import java.awt.event.ActionEvent;
20 import java.awt.event.ActionListener;
21 import java.awt.event.AdjustmentEvent;
22 import java.awt.event.AdjustmentListener;
23 import java.awt.event.ItemEvent;
24 import java.awt.event.ItemListener;
25 import java.awt.event.MouseAdapter;
26 import java.awt.event.MouseEvent;
27 import java.awt.event.MouseListener;
28 import java.awt.event.TextEvent;
29 import java.awt.event.TextListener;
30 import java.util.Iterator;
31 import java.util.Vector;
33 import net.miginfocom.swing.MigLayout;
35 public class AnnotationColumnChooser extends AnnotationRowFilter implements
36 ActionListener, AdjustmentListener, ItemListener, MouseListener
39 private Choice annotations = new Choice();
41 private Panel actionPanel = new Panel();
43 private TitledPanel thresholdPanel = new TitledPanel();
45 private Panel switchableViewsPanel = new Panel(new CardLayout());
47 private CardLayout switchableViewsLayout = (CardLayout) (switchableViewsPanel
50 private Panel noGraphFilterView = new Panel();
52 private Panel graphFilterView = new Panel();
54 private Panel annotationComboBoxPanel = new Panel();
56 private BorderLayout borderLayout1 = new BorderLayout();
58 private Choice threshold = new Choice();
60 private StructureFilterPanel gStructureFilterPanel;
62 private StructureFilterPanel ngStructureFilterPanel;
64 private StructureFilterPanel currentStructureFilterPanel;
66 private SearchPanel currentSearchPanel;
68 private SearchPanel gSearchPanel;
70 private SearchPanel ngSearchPanel;
72 private FurtherActionPanel currentFurtherActionPanel;
74 private FurtherActionPanel gFurtherActionPanel;
76 private FurtherActionPanel ngFurtherActionPanel;
78 public static final int ACTION_OPTION_SELECT = 1;
80 public static int ACTION_OPTION_HIDE = 2;
82 public static String NO_GRAPH_VIEW = "0";
84 public static String GRAPH_VIEW = "1";
86 private int actionOption = ACTION_OPTION_SELECT;
88 private ColumnSelection oldColumnSelection;
90 public AnnotationColumnChooser()
95 } catch (Exception ex)
101 public AnnotationColumnChooser(AlignViewport av, final AlignmentPanel ap)
106 jalview.bin.JalviewLite.addFrame(frame,
107 MessageManager.getString("label.select_by_annotation"), 520,
110 slider.addAdjustmentListener(this);
111 slider.addMouseListener(this);
113 if (av.getAlignment().getAlignmentAnnotation() == null)
117 setOldColumnSelection(av.getColumnSelection());
119 Vector list = new Vector();
121 for (int i = 0; i < av.getAlignment().getAlignmentAnnotation().length; i++)
123 String label = av.getAlignment().getAlignmentAnnotation()[i].label;
124 if (!list.contains(label))
126 list.addElement(label);
130 list.addElement(label + "_" + (index++));
134 for (int i = 0; i < list.size(); i++)
136 annotations.addItem(list.elementAt(i).toString());
139 populateThresholdComboBox(threshold);
141 // restore Object state from the previous session if one exists
142 if (av.getAnnotationColumnSelectionState() != null)
144 currentSearchPanel = av.getAnnotationColumnSelectionState()
145 .getCurrentSearchPanel();
146 currentStructureFilterPanel = av.getAnnotationColumnSelectionState()
147 .getCurrentStructureFilterPanel();
148 annotations.select(av.getAnnotationColumnSelectionState()
149 .getAnnotations().getSelectedIndex());
150 threshold.select(av.getAnnotationColumnSelectionState()
151 .getThreshold().getSelectedIndex());
152 actionOption = av.getAnnotationColumnSelectionState()
159 } catch (Exception ex)
169 private void jbInit() throws Exception
171 ok.setLabel(MessageManager.getString("action.ok"));
173 cancel.setLabel(MessageManager.getString("action.cancel"));
175 thresholdValue.setEnabled(false);
176 thresholdValue.setColumns(7);
178 ok.addActionListener(this);
179 cancel.addActionListener(this);
180 annotations.addItemListener(this);
181 thresholdValue.addActionListener(this);
182 threshold.addItemListener(this);
184 slider.setBackground(Color.white);
185 slider.setEnabled(false);
186 slider.setPreferredSize(new Dimension(100, 32));
188 thresholdPanel.setBackground(Color.white);
189 thresholdPanel.setFont(JvSwingUtils.getLabelFont());
190 thresholdPanel.setLayout(new MigLayout("", "[left][right]", "[][]"));
192 actionPanel.setBackground(Color.white);
193 actionPanel.setFont(JvSwingUtils.getLabelFont());
195 graphFilterView.setLayout(new MigLayout("", "[left][right]", "[][]"));
196 graphFilterView.setBackground(Color.white);
198 noGraphFilterView.setLayout(new MigLayout("", "[left][right]", "[][]"));
199 noGraphFilterView.setBackground(Color.white);
201 annotationComboBoxPanel.setBackground(Color.white);
202 annotationComboBoxPanel.setFont(JvSwingUtils.getLabelFont());
204 gSearchPanel = new SearchPanel(this);
205 ngSearchPanel = new SearchPanel(this);
206 gFurtherActionPanel = new FurtherActionPanel(this);
207 ngFurtherActionPanel = new FurtherActionPanel(this);
208 gStructureFilterPanel = new StructureFilterPanel(this);
209 ngStructureFilterPanel = new StructureFilterPanel(this);
211 thresholdPanel.setTitle("Threshold Filter");
212 thresholdPanel.add(getThreshold(), "grow");
213 thresholdPanel.add(thresholdValue, "grow, wrap");
214 thresholdPanel.add(slider, "grow, span, wrap");
217 actionPanel.add(cancel);
219 graphFilterView.add(gSearchPanel, "grow, span, wrap");
220 graphFilterView.add(gStructureFilterPanel, "grow, span, wrap");
221 graphFilterView.add(thresholdPanel, "grow, span, wrap");
222 graphFilterView.add(gFurtherActionPanel);
224 noGraphFilterView.add(ngSearchPanel, "grow, span, wrap");
225 noGraphFilterView.add(ngStructureFilterPanel, "grow, span, wrap");
226 noGraphFilterView.add(ngFurtherActionPanel);
228 annotationComboBoxPanel.add(getAnnotations());
229 switchableViewsPanel.add(noGraphFilterView,
230 AnnotationColumnChooser.NO_GRAPH_VIEW);
231 switchableViewsPanel.add(graphFilterView,
232 AnnotationColumnChooser.GRAPH_VIEW);
234 this.setLayout(borderLayout1);
235 this.add(annotationComboBoxPanel, java.awt.BorderLayout.PAGE_START);
236 this.add(switchableViewsPanel, java.awt.BorderLayout.CENTER);
237 this.add(actionPanel, java.awt.BorderLayout.SOUTH);
239 selectedAnnotationChanged();
243 @SuppressWarnings("unchecked")
246 if (this.getOldColumnSelection() != null)
248 av.getColumnSelection().clear();
250 if (av.getAnnotationColumnSelectionState() != null)
252 ColumnSelection oldSelection = av
253 .getAnnotationColumnSelectionState()
254 .getOldColumnSelection();
255 if (oldSelection != null && oldSelection.getHiddenColumns() != null
256 && !oldSelection.getHiddenColumns().isEmpty())
258 for (Iterator<int[]> itr = oldSelection.getHiddenColumns()
259 .iterator(); itr.hasNext();)
261 int positions[] = itr.next();
262 av.hideColumns(positions[0], positions[1]);
265 av.setColumnSelection(oldSelection);
267 ap.paintAlignment(true);
272 public void adjustmentValueChanged(AdjustmentEvent evt)
276 thresholdValue.setText((slider.getValue() / 1000f) + "");
277 valueChanged(!sliderDragging);
281 protected void addSliderMouseListeners()
284 slider.addMouseListener(new MouseAdapter()
287 public void mousePressed(MouseEvent e)
289 sliderDragging = true;
290 super.mousePressed(e);
294 public void mouseDragged(MouseEvent e)
296 sliderDragging = true;
297 super.mouseDragged(e);
301 public void mouseReleased(MouseEvent evt)
305 sliderDragging = false;
308 ap.paintAlignment(true);
313 public void valueChanged(boolean updateAllAnnotation)
315 if (slider.isEnabled())
317 getCurrentAnnotation().threshold.value = slider.getValue() / 1000f;
319 ap.paintAlignment(false);
323 public Choice getThreshold()
328 public void setThreshold(Choice threshold)
330 this.threshold = threshold;
333 public Choice getAnnotations()
338 public void setAnnotations(Choice annotations)
340 this.annotations = annotations;
344 public void updateView()
346 // Check if combobox is still adjusting
352 AnnotationFilterParameter filterParams = new AnnotationFilterParameter();
353 setCurrentAnnotation(av.getAlignment().getAlignmentAnnotation()[getAnnotations()
354 .getSelectedIndex()]);
356 int selectedThresholdItem = getSelectedThresholdItem(getThreshold()
357 .getSelectedIndex());
359 slider.setEnabled(true);
360 thresholdValue.setEnabled(true);
362 if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
364 slider.setEnabled(false);
365 thresholdValue.setEnabled(false);
366 thresholdValue.setText("");
367 // build filter params
369 else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
371 if (getCurrentAnnotation().threshold == null)
373 getCurrentAnnotation()
375 new jalview.datamodel.GraphLine(
376 (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin) / 2f,
377 "Threshold", Color.black));
381 float range = getCurrentAnnotation().graphMax * 1000
382 - getCurrentAnnotation().graphMin * 1000;
384 slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
385 slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
386 slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000));
387 thresholdValue.setText(getCurrentAnnotation().threshold.value + "");
388 // slider.setMajorTickSpacing((int) (range / 10f));
389 slider.setEnabled(true);
390 thresholdValue.setEnabled(true);
393 // build filter params
395 .setThresholdType(AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);
396 if (getCurrentAnnotation().graph != AlignmentAnnotation.NO_GRAPH)
399 .setThresholdValue(getCurrentAnnotation().threshold.value);
401 if (selectedThresholdItem == AnnotationColourGradient.ABOVE_THRESHOLD)
404 .setThresholdType(AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD);
406 else if (selectedThresholdItem == AnnotationColourGradient.BELOW_THRESHOLD)
409 .setThresholdType(AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD);
414 if (currentStructureFilterPanel != null)
416 if (currentStructureFilterPanel.alphaHelix.getState())
418 filterParams.setFilterAlphaHelix(true);
420 if (currentStructureFilterPanel.betaStrand.getState())
422 filterParams.setFilterBetaSheet(true);
424 if (currentStructureFilterPanel.turn.getState())
426 filterParams.setFilterTurn(true);
430 if (currentSearchPanel != null)
433 if (!currentSearchPanel.searchBox.getText().isEmpty())
435 currentSearchPanel.description.setEnabled(true);
436 currentSearchPanel.displayName.setEnabled(true);
437 filterParams.setRegexString(currentSearchPanel.searchBox.getText());
438 if (currentSearchPanel.displayName.getState())
441 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING);
443 if (currentSearchPanel.description.getState())
446 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION);
451 currentSearchPanel.description.setEnabled(false);
452 currentSearchPanel.displayName.setEnabled(false);
456 av.getColumnSelection().filterAnnotations(
457 getCurrentAnnotation().annotations, filterParams);
459 av.showAllHiddenColumns();
460 if (getActionOption() == ACTION_OPTION_HIDE)
462 av.hideSelectedColumns();
466 av.setAnnotationColumnSelectionState(this);
467 ap.paintAlignment(true);
470 public ColumnSelection getOldColumnSelection()
472 return oldColumnSelection;
475 public void setOldColumnSelection(ColumnSelection currentColumnSelection)
477 if (currentColumnSelection != null)
479 this.oldColumnSelection = new ColumnSelection(currentColumnSelection);
483 public FurtherActionPanel getCurrentFutherActionPanel()
485 return currentFurtherActionPanel;
488 public void setCurrentFutherActionPanel(
489 FurtherActionPanel currentFutherActionPanel)
491 this.currentFurtherActionPanel = currentFutherActionPanel;
494 public SearchPanel getCurrentSearchPanel()
496 return currentSearchPanel;
499 public void setCurrentSearchPanel(SearchPanel currentSearchPanel)
501 this.currentSearchPanel = currentSearchPanel;
504 public int getActionOption()
509 public void setActionOption(int actionOption)
511 this.actionOption = actionOption;
514 public StructureFilterPanel getCurrentStructureFilterPanel()
516 return currentStructureFilterPanel;
519 public void setCurrentStructureFilterPanel(
520 StructureFilterPanel currentStructureFilterPanel)
522 this.currentStructureFilterPanel = currentStructureFilterPanel;
526 public void itemStateChanged(ItemEvent e)
528 if (e.getSource() == annotations)
530 selectedAnnotationChanged();
532 else if (e.getSource() == threshold)
534 threshold_actionPerformed(null);
538 public void selectedAnnotationChanged()
540 String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
541 if (av.getAlignment().getAlignmentAnnotation()[getAnnotations()
542 .getSelectedIndex()].graph != AlignmentAnnotation.NO_GRAPH)
544 currentView = AnnotationColumnChooser.GRAPH_VIEW;
547 gSearchPanel.syncState();
548 gFurtherActionPanel.syncState();
549 gStructureFilterPanel.syncState();
551 ngSearchPanel.syncState();
552 ngFurtherActionPanel.syncState();
553 ngStructureFilterPanel.syncState();
555 switchableViewsLayout.show(switchableViewsPanel, currentView);
559 public class FurtherActionPanel extends Panel implements
562 private AnnotationColumnChooser aColChooser;
564 private Choice furtherAction = new Choice();
566 public FurtherActionPanel(AnnotationColumnChooser aColChooser)
568 this.aColChooser = aColChooser;
569 furtherAction.addItem("Select");
570 furtherAction.addItem("Hide");
571 furtherAction.addItemListener(this);
574 // this.setTitle("Filter Actions");
575 // this.setFont(JvSwingUtils.getLabelFont());
577 this.add(furtherAction);
580 public void syncState()
582 if (aColChooser.getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
584 furtherAction.select("Hide");
588 furtherAction.select("Select");
593 public void itemStateChanged(ItemEvent e)
595 aColChooser.setCurrentFutherActionPanel(this);
596 if (furtherAction.getSelectedItem().equalsIgnoreCase("Select"))
598 setActionOption(ACTION_OPTION_SELECT);
603 setActionOption(ACTION_OPTION_HIDE);
610 public class StructureFilterPanel extends TitledPanel implements
613 private AnnotationColumnChooser aColChooser;
615 private Checkbox alphaHelix = new Checkbox();
617 private Checkbox betaStrand = new Checkbox();
619 private Checkbox turn = new Checkbox();
621 private Checkbox all = new Checkbox();
623 public StructureFilterPanel(AnnotationColumnChooser aColChooser)
625 this.aColChooser = aColChooser;
627 alphaHelix.setLabel(MessageManager.getString("label.alpha_helix"));
628 alphaHelix.setBackground(Color.white);
630 alphaHelix.addItemListener(this);
632 betaStrand.setLabel(MessageManager.getString("label.beta_strand"));
633 betaStrand.setBackground(Color.white);
634 betaStrand.addItemListener(this);
636 turn.setLabel(MessageManager.getString("label.turn"));
637 turn.setBackground(Color.white);
638 turn.addItemListener(this);
640 all.setLabel(MessageManager.getString("label.select_all"));
641 all.setBackground(Color.white);
642 all.addItemListener(this);
644 this.setBackground(Color.white);
645 this.setTitle("Structure Filter");
646 this.setFont(JvSwingUtils.getLabelFont());
649 this.add(alphaHelix);
650 this.add(betaStrand);
654 public void alphaHelix_actionPerformed()
656 updateSelectAllState();
657 aColChooser.setCurrentStructureFilterPanel(this);
658 aColChooser.updateView();
661 public void betaStrand_actionPerformed()
663 updateSelectAllState();
664 aColChooser.setCurrentStructureFilterPanel(this);
665 aColChooser.updateView();
668 public void turn_actionPerformed()
670 updateSelectAllState();
671 aColChooser.setCurrentStructureFilterPanel(this);
672 aColChooser.updateView();
675 public void all_actionPerformed()
679 alphaHelix.setState(true);
680 betaStrand.setState(true);
685 alphaHelix.setState(false);
686 betaStrand.setState(false);
687 turn.setState(false);
689 aColChooser.setCurrentStructureFilterPanel(this);
690 aColChooser.updateView();
693 public void updateSelectAllState()
695 if (alphaHelix.getState() && betaStrand.getState() && turn.getState())
705 public void syncState()
707 StructureFilterPanel sfp = aColChooser
708 .getCurrentStructureFilterPanel();
711 alphaHelix.setState(sfp.alphaHelix.getState());
712 betaStrand.setState(sfp.betaStrand.getState());
713 turn.setState(sfp.turn.getState());
714 if (sfp.all.getState())
717 alphaHelix.setState(true);
718 betaStrand.setState(true);
726 public void itemStateChanged(ItemEvent e)
728 if (e.getSource() == alphaHelix)
730 alphaHelix_actionPerformed();
732 else if (e.getSource() == betaStrand)
734 betaStrand_actionPerformed();
736 else if (e.getSource() == turn)
738 turn_actionPerformed();
740 else if (e.getSource() == all)
742 all_actionPerformed();
747 public class SearchPanel extends TitledPanel implements ItemListener
749 private AnnotationColumnChooser aColChooser;
751 private Checkbox displayName = new Checkbox();
753 private Checkbox description = new Checkbox();
755 private TextField searchBox = new TextField(10);
757 public SearchPanel(AnnotationColumnChooser aColChooser)
760 this.aColChooser = aColChooser;
761 searchBox.addTextListener(new TextListener()
765 public void textValueChanged(TextEvent e)
767 searchStringAction();
773 displayName.setLabel(MessageManager.getString("label.display_name"));
774 displayName.setEnabled(false);
775 displayName.addItemListener(this);
777 description.setLabel(MessageManager.getString("label.description"));
778 description.setEnabled(false);
779 description.addItemListener(this);
780 this.setTitle("Search Filter");
781 this.setFont(JvSwingUtils.getLabelFont());
785 this.add(displayName);
786 this.add(description);
789 public void displayNameCheckboxAction()
791 aColChooser.setCurrentSearchPanel(this);
792 aColChooser.updateView();
795 public void discriptionCheckboxAction()
797 aColChooser.setCurrentSearchPanel(this);
798 aColChooser.updateView();
801 public void searchStringAction()
803 aColChooser.setCurrentSearchPanel(this);
804 aColChooser.updateView();
807 public void syncState()
809 SearchPanel sp = aColChooser.getCurrentSearchPanel();
812 description.setEnabled(sp.description.isEnabled());
813 description.setState(sp.description.getState());
815 displayName.setEnabled(sp.displayName.isEnabled());
816 displayName.setState(sp.displayName.getState());
818 searchBox.setText(sp.searchBox.getText());
823 public void itemStateChanged(ItemEvent e)
825 if (e.getSource() == displayName)
827 displayNameCheckboxAction();
829 else if (e.getSource() == description)
831 discriptionCheckboxAction();
837 public void actionPerformed(ActionEvent evt)
839 if (evt.getSource() == thresholdValue)
843 float f = new Float(thresholdValue.getText()).floatValue();
844 slider.setValue((int) (f * 1000));
845 adjustmentValueChanged(null);
846 } catch (NumberFormatException ex)
851 else if (evt.getSource() == ok)
853 ok_actionPerformed(null);
855 else if (evt.getSource() == cancel)
857 cancel_actionPerformed(null);
859 else if (evt.getSource() == thresholdValue)
861 thresholdValue_actionPerformed(null);
870 public void mouseClicked(MouseEvent e)
872 // TODO Auto-generated method stub
877 public void mousePressed(MouseEvent e)
879 if (e.getSource() == slider)
887 public void mouseReleased(MouseEvent e)
889 if (e.getSource() == slider)
896 public void mouseEntered(MouseEvent e)
898 if (e.getSource() == slider)
905 public void mouseExited(MouseEvent e)
907 if (e.getSource() == slider)