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 javax.swing.JPanel;
35 //import net.miginfocom.swing.MigLayout;
37 public class AnnotationColumnChooser extends AnnotationRowFilter implements
38 ActionListener, AdjustmentListener, ItemListener, MouseListener
41 private Choice annotations = new Choice();
43 private Panel actionPanel = new Panel();
45 private TitledPanel thresholdPanel = new TitledPanel();
47 private Panel switchableViewsPanel = new Panel(new CardLayout());
49 private CardLayout switchableViewsLayout = (CardLayout) (switchableViewsPanel
52 private Panel noGraphFilterView = new Panel();
54 private Panel graphFilterView = new Panel();
56 private Panel annotationComboBoxPanel = new Panel();
58 private BorderLayout borderLayout1 = new BorderLayout();
60 private BorderLayout gBorderLayout = new BorderLayout();
62 private BorderLayout ngBorderLayout = new BorderLayout();
64 private Choice threshold = new Choice();
66 private StructureFilterPanel gStructureFilterPanel;
68 private StructureFilterPanel ngStructureFilterPanel;
70 private StructureFilterPanel currentStructureFilterPanel;
72 private SearchPanel currentSearchPanel;
74 private SearchPanel gSearchPanel;
76 private SearchPanel ngSearchPanel;
78 private FurtherActionPanel currentFurtherActionPanel;
80 private FurtherActionPanel gFurtherActionPanel;
82 private FurtherActionPanel ngFurtherActionPanel;
84 public static final int ACTION_OPTION_SELECT = 1;
86 public static int ACTION_OPTION_HIDE = 2;
88 public static String NO_GRAPH_VIEW = "0";
90 public static String GRAPH_VIEW = "1";
92 private int actionOption = ACTION_OPTION_SELECT;
94 private ColumnSelection oldColumnSelection;
96 public AnnotationColumnChooser()
101 } catch (Exception ex)
103 ex.printStackTrace();
107 public AnnotationColumnChooser(AlignViewport av, final AlignmentPanel ap)
112 jalview.bin.JalviewLite.addFrame(frame,
113 MessageManager.getString("label.select_by_annotation"), 520,
116 slider.addAdjustmentListener(this);
117 slider.addMouseListener(this);
119 if (av.getAlignment().getAlignmentAnnotation() == null)
123 setOldColumnSelection(av.getColumnSelection());
125 Vector list = new Vector();
127 for (int i = 0; i < av.getAlignment().getAlignmentAnnotation().length; i++)
129 String label = av.getAlignment().getAlignmentAnnotation()[i].label;
130 if (!list.contains(label))
132 list.addElement(label);
136 list.addElement(label + "_" + (index++));
140 for (int i = 0; i < list.size(); i++)
142 annotations.addItem(list.elementAt(i).toString());
145 populateThresholdComboBox(threshold);
147 // restore Object state from the previous session if one exists
148 if (av.getAnnotationColumnSelectionState() != null)
150 currentSearchPanel = av.getAnnotationColumnSelectionState()
151 .getCurrentSearchPanel();
152 currentStructureFilterPanel = av.getAnnotationColumnSelectionState()
153 .getCurrentStructureFilterPanel();
154 annotations.select(av.getAnnotationColumnSelectionState()
155 .getAnnotations().getSelectedIndex());
156 threshold.select(av.getAnnotationColumnSelectionState()
157 .getThreshold().getSelectedIndex());
158 actionOption = av.getAnnotationColumnSelectionState()
165 } catch (Exception ex)
175 private void jbInit() throws Exception
177 ok.setLabel(MessageManager.getString("action.ok"));
179 cancel.setLabel(MessageManager.getString("action.cancel"));
181 thresholdValue.setEnabled(false);
182 thresholdValue.setColumns(7);
184 ok.addActionListener(this);
185 cancel.addActionListener(this);
186 annotations.addItemListener(this);
187 thresholdValue.addActionListener(this);
188 threshold.addItemListener(this);
190 slider.setBackground(Color.white);
191 slider.setEnabled(false);
192 slider.setPreferredSize(new Dimension(100, 32));
194 thresholdPanel.setBackground(Color.white);
195 thresholdPanel.setFont(JvSwingUtils.getLabelFont());
196 // thresholdPanel.setLayout(new MigLayout("", "[left][right]", "[][]"));
198 actionPanel.setBackground(Color.white);
199 actionPanel.setFont(JvSwingUtils.getLabelFont());
201 graphFilterView.setLayout(gBorderLayout);
202 graphFilterView.setBackground(Color.white);
204 noGraphFilterView.setLayout(ngBorderLayout);
205 noGraphFilterView.setBackground(Color.white);
207 annotationComboBoxPanel.setBackground(Color.white);
208 annotationComboBoxPanel.setFont(JvSwingUtils.getLabelFont());
210 gSearchPanel = new SearchPanel(this);
211 ngSearchPanel = new SearchPanel(this);
212 gFurtherActionPanel = new FurtherActionPanel(this);
213 ngFurtherActionPanel = new FurtherActionPanel(this);
214 gStructureFilterPanel = new StructureFilterPanel(this);
215 ngStructureFilterPanel = new StructureFilterPanel(this);
217 thresholdPanel.setTitle("Threshold Filter");
218 thresholdPanel.add(getThreshold());
219 thresholdPanel.add(slider);
220 thresholdPanel.add(thresholdValue);
223 actionPanel.add(cancel);
225 JPanel staticPanel = new JPanel();
226 staticPanel.setLayout(new BorderLayout());
227 staticPanel.setBackground(Color.white);
229 staticPanel.add(gSearchPanel, java.awt.BorderLayout.NORTH);
230 staticPanel.add(gStructureFilterPanel, java.awt.BorderLayout.SOUTH);
232 graphFilterView.add(staticPanel, java.awt.BorderLayout.NORTH);
233 graphFilterView.add(thresholdPanel, java.awt.BorderLayout.CENTER);
234 graphFilterView.add(gFurtherActionPanel, java.awt.BorderLayout.SOUTH);
236 noGraphFilterView.add(ngSearchPanel, java.awt.BorderLayout.PAGE_START);
237 noGraphFilterView.add(ngStructureFilterPanel,
238 java.awt.BorderLayout.CENTER);
239 noGraphFilterView.add(ngFurtherActionPanel,
240 java.awt.BorderLayout.CENTER);
242 annotationComboBoxPanel.add(getAnnotations());
243 switchableViewsPanel.add(noGraphFilterView,
244 AnnotationColumnChooser.NO_GRAPH_VIEW);
245 switchableViewsPanel.add(graphFilterView,
246 AnnotationColumnChooser.GRAPH_VIEW);
248 this.setLayout(borderLayout1);
249 this.add(annotationComboBoxPanel, java.awt.BorderLayout.PAGE_START);
250 this.add(switchableViewsPanel, java.awt.BorderLayout.CENTER);
251 this.add(actionPanel, java.awt.BorderLayout.SOUTH);
253 selectedAnnotationChanged();
257 @SuppressWarnings("unchecked")
260 if (this.getOldColumnSelection() != null)
262 av.getColumnSelection().clear();
264 if (av.getAnnotationColumnSelectionState() != null)
266 ColumnSelection oldSelection = av
267 .getAnnotationColumnSelectionState()
268 .getOldColumnSelection();
269 if (oldSelection != null && oldSelection.getHiddenColumns() != null
270 && !oldSelection.getHiddenColumns().isEmpty())
272 for (Iterator<int[]> itr = oldSelection.getHiddenColumns()
273 .iterator(); itr.hasNext();)
275 int positions[] = itr.next();
276 av.hideColumns(positions[0], positions[1]);
279 av.setColumnSelection(oldSelection);
281 ap.paintAlignment(true);
286 public void adjustmentValueChanged(AdjustmentEvent evt)
290 thresholdValue.setText((slider.getValue() / 1000f) + "");
291 valueChanged(!sliderDragging);
295 protected void addSliderMouseListeners()
298 slider.addMouseListener(new MouseAdapter()
301 public void mousePressed(MouseEvent e)
303 sliderDragging = true;
304 super.mousePressed(e);
308 public void mouseDragged(MouseEvent e)
310 sliderDragging = true;
311 super.mouseDragged(e);
315 public void mouseReleased(MouseEvent evt)
319 sliderDragging = false;
322 ap.paintAlignment(true);
327 public void valueChanged(boolean updateAllAnnotation)
329 if (slider.isEnabled())
331 getCurrentAnnotation().threshold.value = slider.getValue() / 1000f;
333 ap.paintAlignment(false);
337 public Choice getThreshold()
342 public void setThreshold(Choice threshold)
344 this.threshold = threshold;
347 public Choice getAnnotations()
352 public void setAnnotations(Choice annotations)
354 this.annotations = annotations;
358 public void updateView()
360 // Check if combobox is still adjusting
366 AnnotationFilterParameter filterParams = new AnnotationFilterParameter();
367 setCurrentAnnotation(av.getAlignment().getAlignmentAnnotation()[getAnnotations()
368 .getSelectedIndex()]);
370 int selectedThresholdItem = getSelectedThresholdItem(getThreshold()
371 .getSelectedIndex());
373 slider.setEnabled(true);
374 thresholdValue.setEnabled(true);
376 if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
378 slider.setEnabled(false);
379 thresholdValue.setEnabled(false);
380 thresholdValue.setText("");
381 // build filter params
383 else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
385 if (getCurrentAnnotation().threshold == null)
387 getCurrentAnnotation()
389 new jalview.datamodel.GraphLine(
390 (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin) / 2f,
391 "Threshold", Color.black));
395 float range = getCurrentAnnotation().graphMax * 1000
396 - getCurrentAnnotation().graphMin * 1000;
398 slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
399 slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
400 slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000));
401 thresholdValue.setText(getCurrentAnnotation().threshold.value + "");
402 // slider.setMajorTickSpacing((int) (range / 10f));
403 slider.setEnabled(true);
404 thresholdValue.setEnabled(true);
407 // build filter params
409 .setThresholdType(AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);
410 if (getCurrentAnnotation().graph != AlignmentAnnotation.NO_GRAPH)
413 .setThresholdValue(getCurrentAnnotation().threshold.value);
415 if (selectedThresholdItem == AnnotationColourGradient.ABOVE_THRESHOLD)
418 .setThresholdType(AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD);
420 else if (selectedThresholdItem == AnnotationColourGradient.BELOW_THRESHOLD)
423 .setThresholdType(AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD);
428 if (currentStructureFilterPanel != null)
430 if (currentStructureFilterPanel.alphaHelix.getState())
432 filterParams.setFilterAlphaHelix(true);
434 if (currentStructureFilterPanel.betaStrand.getState())
436 filterParams.setFilterBetaSheet(true);
438 if (currentStructureFilterPanel.turn.getState())
440 filterParams.setFilterTurn(true);
444 if (currentSearchPanel != null)
447 if (!currentSearchPanel.searchBox.getText().isEmpty())
449 currentSearchPanel.description.setEnabled(true);
450 currentSearchPanel.displayName.setEnabled(true);
451 filterParams.setRegexString(currentSearchPanel.searchBox.getText());
452 if (currentSearchPanel.displayName.getState())
455 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING);
457 if (currentSearchPanel.description.getState())
460 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION);
465 currentSearchPanel.description.setEnabled(false);
466 currentSearchPanel.displayName.setEnabled(false);
470 av.getColumnSelection().filterAnnotations(
471 getCurrentAnnotation().annotations, filterParams);
473 av.showAllHiddenColumns();
474 if (getActionOption() == ACTION_OPTION_HIDE)
476 av.hideSelectedColumns();
480 av.setAnnotationColumnSelectionState(this);
481 ap.paintAlignment(true);
484 public ColumnSelection getOldColumnSelection()
486 return oldColumnSelection;
489 public void setOldColumnSelection(ColumnSelection currentColumnSelection)
491 if (currentColumnSelection != null)
493 this.oldColumnSelection = new ColumnSelection(currentColumnSelection);
497 public FurtherActionPanel getCurrentFutherActionPanel()
499 return currentFurtherActionPanel;
502 public void setCurrentFutherActionPanel(
503 FurtherActionPanel currentFutherActionPanel)
505 this.currentFurtherActionPanel = currentFutherActionPanel;
508 public SearchPanel getCurrentSearchPanel()
510 return currentSearchPanel;
513 public void setCurrentSearchPanel(SearchPanel currentSearchPanel)
515 this.currentSearchPanel = currentSearchPanel;
518 public int getActionOption()
523 public void setActionOption(int actionOption)
525 this.actionOption = actionOption;
528 public StructureFilterPanel getCurrentStructureFilterPanel()
530 return currentStructureFilterPanel;
533 public void setCurrentStructureFilterPanel(
534 StructureFilterPanel currentStructureFilterPanel)
536 this.currentStructureFilterPanel = currentStructureFilterPanel;
540 public void itemStateChanged(ItemEvent e)
542 if (e.getSource() == annotations)
544 selectedAnnotationChanged();
546 else if (e.getSource() == threshold)
548 threshold_actionPerformed(null);
552 public void selectedAnnotationChanged()
554 String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
555 if (av.getAlignment().getAlignmentAnnotation()[getAnnotations()
556 .getSelectedIndex()].graph != AlignmentAnnotation.NO_GRAPH)
558 currentView = AnnotationColumnChooser.GRAPH_VIEW;
561 gSearchPanel.syncState();
562 gFurtherActionPanel.syncState();
563 gStructureFilterPanel.syncState();
565 ngSearchPanel.syncState();
566 ngFurtherActionPanel.syncState();
567 ngStructureFilterPanel.syncState();
569 switchableViewsLayout.show(switchableViewsPanel, currentView);
573 public class FurtherActionPanel extends Panel implements
576 private AnnotationColumnChooser aColChooser;
578 private Choice furtherAction = new Choice();
580 public FurtherActionPanel(AnnotationColumnChooser aColChooser)
582 this.aColChooser = aColChooser;
583 furtherAction.addItem("Select");
584 furtherAction.addItem("Hide");
585 furtherAction.addItemListener(this);
588 // this.setTitle("Filter Actions");
589 // this.setFont(JvSwingUtils.getLabelFont());
591 this.add(furtherAction);
594 public void syncState()
596 if (aColChooser.getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
598 furtherAction.select("Hide");
602 furtherAction.select("Select");
607 public void itemStateChanged(ItemEvent e)
609 aColChooser.setCurrentFutherActionPanel(this);
610 if (furtherAction.getSelectedItem().equalsIgnoreCase("Select"))
612 setActionOption(ACTION_OPTION_SELECT);
617 setActionOption(ACTION_OPTION_HIDE);
624 public class StructureFilterPanel extends TitledPanel implements
627 private AnnotationColumnChooser aColChooser;
629 private Checkbox alphaHelix = new Checkbox();
631 private Checkbox betaStrand = new Checkbox();
633 private Checkbox turn = new Checkbox();
635 private Checkbox all = new Checkbox();
637 public StructureFilterPanel(AnnotationColumnChooser aColChooser)
639 this.aColChooser = aColChooser;
641 alphaHelix.setLabel(MessageManager.getString("label.alpha_helix"));
642 alphaHelix.setBackground(Color.white);
644 alphaHelix.addItemListener(this);
646 betaStrand.setLabel(MessageManager.getString("label.beta_strand"));
647 betaStrand.setBackground(Color.white);
648 betaStrand.addItemListener(this);
650 turn.setLabel(MessageManager.getString("label.turn"));
651 turn.setBackground(Color.white);
652 turn.addItemListener(this);
654 all.setLabel(MessageManager.getString("label.select_all"));
655 all.setBackground(Color.white);
656 all.addItemListener(this);
658 this.setBackground(Color.white);
659 this.setTitle("Structure Filter");
660 this.setFont(JvSwingUtils.getLabelFont());
663 this.add(alphaHelix);
664 this.add(betaStrand);
668 public void alphaHelix_actionPerformed()
670 updateSelectAllState();
671 aColChooser.setCurrentStructureFilterPanel(this);
672 aColChooser.updateView();
675 public void betaStrand_actionPerformed()
677 updateSelectAllState();
678 aColChooser.setCurrentStructureFilterPanel(this);
679 aColChooser.updateView();
682 public void turn_actionPerformed()
684 updateSelectAllState();
685 aColChooser.setCurrentStructureFilterPanel(this);
686 aColChooser.updateView();
689 public void all_actionPerformed()
693 alphaHelix.setState(true);
694 betaStrand.setState(true);
699 alphaHelix.setState(false);
700 betaStrand.setState(false);
701 turn.setState(false);
703 aColChooser.setCurrentStructureFilterPanel(this);
704 aColChooser.updateView();
707 public void updateSelectAllState()
709 if (alphaHelix.getState() && betaStrand.getState() && turn.getState())
719 public void syncState()
721 StructureFilterPanel sfp = aColChooser
722 .getCurrentStructureFilterPanel();
725 alphaHelix.setState(sfp.alphaHelix.getState());
726 betaStrand.setState(sfp.betaStrand.getState());
727 turn.setState(sfp.turn.getState());
728 if (sfp.all.getState())
731 alphaHelix.setState(true);
732 betaStrand.setState(true);
740 public void itemStateChanged(ItemEvent e)
742 if (e.getSource() == alphaHelix)
744 alphaHelix_actionPerformed();
746 else if (e.getSource() == betaStrand)
748 betaStrand_actionPerformed();
750 else if (e.getSource() == turn)
752 turn_actionPerformed();
754 else if (e.getSource() == all)
756 all_actionPerformed();
761 public class SearchPanel extends TitledPanel implements ItemListener
763 private AnnotationColumnChooser aColChooser;
765 private Checkbox displayName = new Checkbox();
767 private Checkbox description = new Checkbox();
769 private TextField searchBox = new TextField(10);
771 public SearchPanel(AnnotationColumnChooser aColChooser)
774 this.aColChooser = aColChooser;
775 searchBox.addTextListener(new TextListener()
779 public void textValueChanged(TextEvent e)
781 searchStringAction();
787 displayName.setLabel(MessageManager.getString("label.display_name"));
788 displayName.setEnabled(false);
789 displayName.addItemListener(this);
791 description.setLabel(MessageManager.getString("label.description"));
792 description.setEnabled(false);
793 description.addItemListener(this);
794 this.setTitle("Search Filter");
795 this.setFont(JvSwingUtils.getLabelFont());
799 this.add(displayName);
800 this.add(description);
803 public void displayNameCheckboxAction()
805 aColChooser.setCurrentSearchPanel(this);
806 aColChooser.updateView();
809 public void discriptionCheckboxAction()
811 aColChooser.setCurrentSearchPanel(this);
812 aColChooser.updateView();
815 public void searchStringAction()
817 aColChooser.setCurrentSearchPanel(this);
818 aColChooser.updateView();
821 public void syncState()
823 SearchPanel sp = aColChooser.getCurrentSearchPanel();
826 description.setEnabled(sp.description.isEnabled());
827 description.setState(sp.description.getState());
829 displayName.setEnabled(sp.displayName.isEnabled());
830 displayName.setState(sp.displayName.getState());
832 searchBox.setText(sp.searchBox.getText());
837 public void itemStateChanged(ItemEvent e)
839 if (e.getSource() == displayName)
841 displayNameCheckboxAction();
843 else if (e.getSource() == description)
845 discriptionCheckboxAction();
851 public void actionPerformed(ActionEvent evt)
853 if (evt.getSource() == thresholdValue)
857 float f = new Float(thresholdValue.getText()).floatValue();
858 slider.setValue((int) (f * 1000));
859 adjustmentValueChanged(null);
860 } catch (NumberFormatException ex)
865 else if (evt.getSource() == ok)
867 ok_actionPerformed(null);
869 else if (evt.getSource() == cancel)
871 cancel_actionPerformed(null);
873 else if (evt.getSource() == thresholdValue)
875 thresholdValue_actionPerformed(null);
884 public void mouseClicked(MouseEvent e)
886 // TODO Auto-generated method stub
891 public void mousePressed(MouseEvent e)
893 if (e.getSource() == slider)
901 public void mouseReleased(MouseEvent e)
903 if (e.getSource() == slider)
910 public void mouseEntered(MouseEvent e)
912 if (e.getSource() == slider)
919 public void mouseExited(MouseEvent e)
921 if (e.getSource() == slider)