1 package jalview.appletgui;
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.Checkbox;
12 import java.awt.Choice;
13 import java.awt.Color;
14 import java.awt.Dimension;
15 import java.awt.Frame;
16 import java.awt.Panel;
17 import java.awt.TextField;
18 import java.awt.event.ActionEvent;
19 import java.awt.event.ActionListener;
20 import java.awt.event.AdjustmentEvent;
21 import java.awt.event.AdjustmentListener;
22 import java.awt.event.ItemEvent;
23 import java.awt.event.ItemListener;
24 import java.awt.event.MouseAdapter;
25 import java.awt.event.MouseEvent;
26 import java.awt.event.MouseListener;
27 import java.awt.event.TextEvent;
28 import java.awt.event.TextListener;
29 import java.util.Iterator;
30 import java.util.Vector;
32 import javax.swing.JPanel;
34 //import net.miginfocom.swing.MigLayout;
36 public class AnnotationColumnChooser extends AnnotationRowFilter implements
37 ActionListener, AdjustmentListener, ItemListener, MouseListener
40 private Choice annotations = new Choice();
42 private Panel actionPanel = new Panel();
44 private TitledPanel thresholdPanel = new TitledPanel();
46 private Panel switchableViewsPanel = new Panel(new CardLayout());
48 private CardLayout switchableViewsLayout = (CardLayout) (switchableViewsPanel
51 private Panel noGraphFilterView = new Panel();
53 private Panel graphFilterView = new Panel();
55 private Panel annotationComboBoxPanel = new Panel();
57 private BorderLayout borderLayout1 = new BorderLayout();
59 private BorderLayout gBorderLayout = new BorderLayout();
61 private BorderLayout ngBorderLayout = new BorderLayout();
63 private Choice threshold = new Choice();
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)
111 jalview.bin.JalviewLite.addFrame(frame,
112 MessageManager.getString("label.select_by_annotation"), 520,
115 slider.addAdjustmentListener(this);
116 slider.addMouseListener(this);
118 if (av.getAlignment().getAlignmentAnnotation() == null)
122 setOldColumnSelection(av.getColumnSelection());
124 Vector list = new Vector();
126 for (int i = 0; i < av.getAlignment().getAlignmentAnnotation().length; i++)
128 String label = av.getAlignment().getAlignmentAnnotation()[i].label;
129 if (!list.contains(label))
131 list.addElement(label);
135 list.addElement(label + "_" + (index++));
139 for (int i = 0; i < list.size(); i++)
141 annotations.addItem(list.elementAt(i).toString());
144 populateThresholdComboBox(threshold);
146 // restore Object state from the previous session if one exists
147 if (av.getAnnotationColumnSelectionState() != null)
149 currentSearchPanel = av.getAnnotationColumnSelectionState()
150 .getCurrentSearchPanel();
151 currentStructureFilterPanel = av.getAnnotationColumnSelectionState()
152 .getCurrentStructureFilterPanel();
153 annotations.select(av.getAnnotationColumnSelectionState()
154 .getAnnotations().getSelectedIndex());
155 threshold.select(av.getAnnotationColumnSelectionState()
156 .getThreshold().getSelectedIndex());
157 actionOption = av.getAnnotationColumnSelectionState()
164 } catch (Exception ex)
174 private void jbInit() throws Exception
176 ok.setLabel(MessageManager.getString("action.ok"));
178 cancel.setLabel(MessageManager.getString("action.cancel"));
180 thresholdValue.setEnabled(false);
181 thresholdValue.setColumns(7);
183 ok.addActionListener(this);
184 cancel.addActionListener(this);
185 annotations.addItemListener(this);
186 thresholdValue.addActionListener(this);
187 threshold.addItemListener(this);
189 slider.setBackground(Color.white);
190 slider.setEnabled(false);
191 slider.setPreferredSize(new Dimension(100, 32));
193 thresholdPanel.setBackground(Color.white);
194 // thresholdPanel.setFont(JvSwingUtils.getLabelFont());
195 // thresholdPanel.setLayout(new MigLayout("", "[left][right]", "[][]"));
197 actionPanel.setBackground(Color.white);
198 // actionPanel.setFont(JvSwingUtils.getLabelFont());
200 graphFilterView.setLayout(gBorderLayout);
201 graphFilterView.setBackground(Color.white);
203 noGraphFilterView.setLayout(ngBorderLayout);
204 noGraphFilterView.setBackground(Color.white);
206 annotationComboBoxPanel.setBackground(Color.white);
207 // annotationComboBoxPanel.setFont(JvSwingUtils.getLabelFont());
209 gSearchPanel = new SearchPanel(this);
210 ngSearchPanel = new SearchPanel(this);
211 gFurtherActionPanel = new FurtherActionPanel(this);
212 ngFurtherActionPanel = new FurtherActionPanel(this);
213 gStructureFilterPanel = new StructureFilterPanel(this);
214 ngStructureFilterPanel = new StructureFilterPanel(this);
216 thresholdPanel.setTitle("Threshold Filter");
217 thresholdPanel.add(getThreshold());
218 thresholdPanel.add(slider);
219 thresholdPanel.add(thresholdValue);
222 actionPanel.add(cancel);
224 JPanel staticPanel = new JPanel();
225 staticPanel.setLayout(new BorderLayout());
226 staticPanel.setBackground(Color.white);
228 staticPanel.add(gSearchPanel, java.awt.BorderLayout.NORTH);
229 staticPanel.add(gStructureFilterPanel, java.awt.BorderLayout.SOUTH);
231 graphFilterView.add(staticPanel, java.awt.BorderLayout.NORTH);
232 graphFilterView.add(thresholdPanel, java.awt.BorderLayout.CENTER);
233 graphFilterView.add(gFurtherActionPanel, java.awt.BorderLayout.SOUTH);
235 noGraphFilterView.add(ngSearchPanel, java.awt.BorderLayout.PAGE_START);
236 noGraphFilterView.add(ngStructureFilterPanel,
237 java.awt.BorderLayout.CENTER);
238 noGraphFilterView.add(ngFurtherActionPanel,
239 java.awt.BorderLayout.CENTER);
241 annotationComboBoxPanel.add(getAnnotations());
242 switchableViewsPanel.add(noGraphFilterView,
243 AnnotationColumnChooser.NO_GRAPH_VIEW);
244 switchableViewsPanel.add(graphFilterView,
245 AnnotationColumnChooser.GRAPH_VIEW);
247 this.setLayout(borderLayout1);
248 this.add(annotationComboBoxPanel, java.awt.BorderLayout.PAGE_START);
249 this.add(switchableViewsPanel, java.awt.BorderLayout.CENTER);
250 this.add(actionPanel, java.awt.BorderLayout.SOUTH);
252 selectedAnnotationChanged();
256 @SuppressWarnings("unchecked")
259 if (this.getOldColumnSelection() != null)
261 av.getColumnSelection().clear();
263 if (av.getAnnotationColumnSelectionState() != null)
265 ColumnSelection oldSelection = av
266 .getAnnotationColumnSelectionState()
267 .getOldColumnSelection();
268 if (oldSelection != null && oldSelection.getHiddenColumns() != null
269 && !oldSelection.getHiddenColumns().isEmpty())
271 for (Iterator<int[]> itr = oldSelection.getHiddenColumns()
272 .iterator(); itr.hasNext();)
274 int positions[] = itr.next();
275 av.hideColumns(positions[0], positions[1]);
278 av.setColumnSelection(oldSelection);
280 ap.paintAlignment(true);
285 public void adjustmentValueChanged(AdjustmentEvent evt)
289 thresholdValue.setText((slider.getValue() / 1000f) + "");
290 valueChanged(!sliderDragging);
294 protected void addSliderMouseListeners()
297 slider.addMouseListener(new MouseAdapter()
300 public void mousePressed(MouseEvent e)
302 sliderDragging = true;
303 super.mousePressed(e);
307 public void mouseDragged(MouseEvent e)
309 sliderDragging = true;
310 super.mouseDragged(e);
314 public void mouseReleased(MouseEvent evt)
318 sliderDragging = false;
321 ap.paintAlignment(true);
326 public void valueChanged(boolean updateAllAnnotation)
328 if (slider.isEnabled())
330 getCurrentAnnotation().threshold.value = slider.getValue() / 1000f;
332 ap.paintAlignment(false);
336 public Choice getThreshold()
341 public void setThreshold(Choice threshold)
343 this.threshold = threshold;
346 public Choice getAnnotations()
351 public void setAnnotations(Choice annotations)
353 this.annotations = annotations;
357 public void updateView()
359 // Check if combobox is still adjusting
365 AnnotationFilterParameter filterParams = new AnnotationFilterParameter();
366 setCurrentAnnotation(av.getAlignment().getAlignmentAnnotation()[getAnnotations()
367 .getSelectedIndex()]);
369 int selectedThresholdItem = getSelectedThresholdItem(getThreshold()
370 .getSelectedIndex());
372 slider.setEnabled(true);
373 thresholdValue.setEnabled(true);
375 if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
377 slider.setEnabled(false);
378 thresholdValue.setEnabled(false);
379 thresholdValue.setText("");
380 // build filter params
382 else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
384 if (getCurrentAnnotation().threshold == null)
386 getCurrentAnnotation()
388 new jalview.datamodel.GraphLine(
389 (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin) / 2f,
390 "Threshold", Color.black));
394 float range = getCurrentAnnotation().graphMax * 1000
395 - getCurrentAnnotation().graphMin * 1000;
397 slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
398 slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
399 slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000));
400 thresholdValue.setText(getCurrentAnnotation().threshold.value + "");
401 // slider.setMajorTickSpacing((int) (range / 10f));
402 slider.setEnabled(true);
403 thresholdValue.setEnabled(true);
406 // build filter params
408 .setThresholdType(AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);
409 if (getCurrentAnnotation().graph != AlignmentAnnotation.NO_GRAPH)
412 .setThresholdValue(getCurrentAnnotation().threshold.value);
414 if (selectedThresholdItem == AnnotationColourGradient.ABOVE_THRESHOLD)
417 .setThresholdType(AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD);
419 else if (selectedThresholdItem == AnnotationColourGradient.BELOW_THRESHOLD)
422 .setThresholdType(AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD);
427 if (currentStructureFilterPanel != null)
429 if (currentStructureFilterPanel.alphaHelix.getState())
431 filterParams.setFilterAlphaHelix(true);
433 if (currentStructureFilterPanel.betaStrand.getState())
435 filterParams.setFilterBetaSheet(true);
437 if (currentStructureFilterPanel.turn.getState())
439 filterParams.setFilterTurn(true);
443 if (currentSearchPanel != null)
446 if (!currentSearchPanel.searchBox.getText().isEmpty())
448 currentSearchPanel.description.setEnabled(true);
449 currentSearchPanel.displayName.setEnabled(true);
450 filterParams.setRegexString(currentSearchPanel.searchBox.getText());
451 if (currentSearchPanel.displayName.getState())
454 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING);
456 if (currentSearchPanel.description.getState())
459 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION);
464 currentSearchPanel.description.setEnabled(false);
465 currentSearchPanel.displayName.setEnabled(false);
469 av.getColumnSelection().filterAnnotations(
470 getCurrentAnnotation().annotations, filterParams);
472 av.showAllHiddenColumns();
473 if (getActionOption() == ACTION_OPTION_HIDE)
475 av.hideSelectedColumns();
479 av.setAnnotationColumnSelectionState(this);
480 ap.paintAlignment(true);
483 public ColumnSelection getOldColumnSelection()
485 return oldColumnSelection;
488 public void setOldColumnSelection(ColumnSelection currentColumnSelection)
490 if (currentColumnSelection != null)
492 this.oldColumnSelection = new ColumnSelection(currentColumnSelection);
496 public FurtherActionPanel getCurrentFutherActionPanel()
498 return currentFurtherActionPanel;
501 public void setCurrentFutherActionPanel(
502 FurtherActionPanel currentFutherActionPanel)
504 this.currentFurtherActionPanel = currentFutherActionPanel;
507 public SearchPanel getCurrentSearchPanel()
509 return currentSearchPanel;
512 public void setCurrentSearchPanel(SearchPanel currentSearchPanel)
514 this.currentSearchPanel = currentSearchPanel;
517 public int getActionOption()
522 public void setActionOption(int actionOption)
524 this.actionOption = actionOption;
527 public StructureFilterPanel getCurrentStructureFilterPanel()
529 return currentStructureFilterPanel;
532 public void setCurrentStructureFilterPanel(
533 StructureFilterPanel currentStructureFilterPanel)
535 this.currentStructureFilterPanel = currentStructureFilterPanel;
539 public void itemStateChanged(ItemEvent e)
541 if (e.getSource() == annotations)
543 selectedAnnotationChanged();
545 else if (e.getSource() == threshold)
547 threshold_actionPerformed(null);
551 public void selectedAnnotationChanged()
553 String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
554 if (av.getAlignment().getAlignmentAnnotation()[getAnnotations()
555 .getSelectedIndex()].graph != AlignmentAnnotation.NO_GRAPH)
557 currentView = AnnotationColumnChooser.GRAPH_VIEW;
560 gSearchPanel.syncState();
561 gFurtherActionPanel.syncState();
562 gStructureFilterPanel.syncState();
564 ngSearchPanel.syncState();
565 ngFurtherActionPanel.syncState();
566 ngStructureFilterPanel.syncState();
568 switchableViewsLayout.show(switchableViewsPanel, currentView);
572 public class FurtherActionPanel extends Panel implements ItemListener
574 private AnnotationColumnChooser aColChooser;
576 private Choice furtherAction = new Choice();
578 public FurtherActionPanel(AnnotationColumnChooser aColChooser)
580 this.aColChooser = aColChooser;
581 furtherAction.addItem("Select");
582 furtherAction.addItem("Hide");
583 furtherAction.addItemListener(this);
586 // this.setTitle("Filter Actions");
587 // this.setFont(JvSwingUtils.getLabelFont());
589 this.add(furtherAction);
592 public void syncState()
594 if (aColChooser.getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
596 furtherAction.select("Hide");
600 furtherAction.select("Select");
605 public void itemStateChanged(ItemEvent e)
607 aColChooser.setCurrentFutherActionPanel(this);
608 if (furtherAction.getSelectedItem().equalsIgnoreCase("Select"))
610 setActionOption(ACTION_OPTION_SELECT);
615 setActionOption(ACTION_OPTION_HIDE);
622 public class StructureFilterPanel extends TitledPanel implements
625 private AnnotationColumnChooser aColChooser;
627 private Checkbox alphaHelix = new Checkbox();
629 private Checkbox betaStrand = new Checkbox();
631 private Checkbox turn = new Checkbox();
633 private Checkbox all = new Checkbox();
635 public StructureFilterPanel(AnnotationColumnChooser aColChooser)
637 this.aColChooser = aColChooser;
639 alphaHelix.setLabel(MessageManager.getString("label.alpha_helix"));
640 alphaHelix.setBackground(Color.white);
642 alphaHelix.addItemListener(this);
644 betaStrand.setLabel(MessageManager.getString("label.beta_strand"));
645 betaStrand.setBackground(Color.white);
646 betaStrand.addItemListener(this);
648 turn.setLabel(MessageManager.getString("label.turn"));
649 turn.setBackground(Color.white);
650 turn.addItemListener(this);
652 all.setLabel(MessageManager.getString("label.select_all"));
653 all.setBackground(Color.white);
654 all.addItemListener(this);
656 this.setBackground(Color.white);
657 this.setTitle("Structure Filter");
658 // this.setFont(JvSwingUtils.getLabelFont());
661 this.add(alphaHelix);
662 this.add(betaStrand);
666 public void alphaHelix_actionPerformed()
668 updateSelectAllState();
669 aColChooser.setCurrentStructureFilterPanel(this);
670 aColChooser.updateView();
673 public void betaStrand_actionPerformed()
675 updateSelectAllState();
676 aColChooser.setCurrentStructureFilterPanel(this);
677 aColChooser.updateView();
680 public void turn_actionPerformed()
682 updateSelectAllState();
683 aColChooser.setCurrentStructureFilterPanel(this);
684 aColChooser.updateView();
687 public void all_actionPerformed()
691 alphaHelix.setState(true);
692 betaStrand.setState(true);
697 alphaHelix.setState(false);
698 betaStrand.setState(false);
699 turn.setState(false);
701 aColChooser.setCurrentStructureFilterPanel(this);
702 aColChooser.updateView();
705 public void updateSelectAllState()
707 if (alphaHelix.getState() && betaStrand.getState() && turn.getState())
717 public void syncState()
719 StructureFilterPanel sfp = aColChooser
720 .getCurrentStructureFilterPanel();
723 alphaHelix.setState(sfp.alphaHelix.getState());
724 betaStrand.setState(sfp.betaStrand.getState());
725 turn.setState(sfp.turn.getState());
726 if (sfp.all.getState())
729 alphaHelix.setState(true);
730 betaStrand.setState(true);
738 public void itemStateChanged(ItemEvent e)
740 if (e.getSource() == alphaHelix)
742 alphaHelix_actionPerformed();
744 else if (e.getSource() == betaStrand)
746 betaStrand_actionPerformed();
748 else if (e.getSource() == turn)
750 turn_actionPerformed();
752 else if (e.getSource() == all)
754 all_actionPerformed();
759 public class SearchPanel extends TitledPanel implements ItemListener
761 private AnnotationColumnChooser aColChooser;
763 private Checkbox displayName = new Checkbox();
765 private Checkbox description = new Checkbox();
767 private TextField searchBox = new TextField(10);
769 public SearchPanel(AnnotationColumnChooser aColChooser)
772 this.aColChooser = aColChooser;
773 searchBox.addTextListener(new TextListener()
777 public void textValueChanged(TextEvent e)
779 searchStringAction();
785 displayName.setLabel(MessageManager.getString("label.label"));
786 displayName.setEnabled(false);
787 displayName.addItemListener(this);
789 description.setLabel(MessageManager.getString("label.description"));
790 description.setEnabled(false);
791 description.addItemListener(this);
792 this.setTitle("Search Filter");
793 // this.setFont(JvSwingUtils.getLabelFont());
797 this.add(displayName);
798 this.add(description);
801 public void displayNameCheckboxAction()
803 aColChooser.setCurrentSearchPanel(this);
804 aColChooser.updateView();
807 public void discriptionCheckboxAction()
809 aColChooser.setCurrentSearchPanel(this);
810 aColChooser.updateView();
813 public void searchStringAction()
815 aColChooser.setCurrentSearchPanel(this);
816 aColChooser.updateView();
819 public void syncState()
821 SearchPanel sp = aColChooser.getCurrentSearchPanel();
824 description.setEnabled(sp.description.isEnabled());
825 description.setState(sp.description.getState());
827 displayName.setEnabled(sp.displayName.isEnabled());
828 displayName.setState(sp.displayName.getState());
830 searchBox.setText(sp.searchBox.getText());
835 public void itemStateChanged(ItemEvent e)
837 if (e.getSource() == displayName)
839 displayNameCheckboxAction();
841 else if (e.getSource() == description)
843 discriptionCheckboxAction();
849 public void actionPerformed(ActionEvent evt)
851 if (evt.getSource() == thresholdValue)
855 float f = new Float(thresholdValue.getText()).floatValue();
856 slider.setValue((int) (f * 1000));
857 adjustmentValueChanged(null);
858 } catch (NumberFormatException ex)
863 else if (evt.getSource() == ok)
865 ok_actionPerformed(null);
867 else if (evt.getSource() == cancel)
869 cancel_actionPerformed(null);
871 else if (evt.getSource() == thresholdValue)
873 thresholdValue_actionPerformed(null);
882 public void mouseClicked(MouseEvent e)
884 // TODO Auto-generated method stub
889 public void mousePressed(MouseEvent e)
891 if (e.getSource() == slider)
899 public void mouseReleased(MouseEvent e)
901 if (e.getSource() == slider)
908 public void mouseEntered(MouseEvent e)
910 if (e.getSource() == slider)
917 public void mouseExited(MouseEvent e)
919 if (e.getSource() == slider)