1 package jalview.appletgui;
3 import jalview.bin.JalviewLite;
4 import jalview.datamodel.AlignmentAnnotation;
5 import jalview.datamodel.ColumnSelection;
6 import jalview.datamodel.GraphLine;
7 import jalview.schemes.AnnotationColourGradient;
8 import jalview.util.MessageManager;
9 import jalview.viewmodel.annotationfilter.AnnotationFilterParameter;
11 import java.awt.BorderLayout;
12 import java.awt.CardLayout;
13 import awt2swing.Checkbox;
14 import awt2swing.Choice;
15 import java.awt.Color;
16 import java.awt.Dimension;
17 import awt2swing.Frame;
18 import awt2swing.Panel;
19 import awt2swing.TextField;
20 import java.awt.event.ActionEvent;
21 import java.awt.event.ActionListener;
22 import java.awt.event.AdjustmentEvent;
23 import java.awt.event.AdjustmentListener;
24 import java.awt.event.ItemEvent;
25 import java.awt.event.ItemListener;
26 import java.awt.event.MouseAdapter;
27 import java.awt.event.MouseEvent;
28 import java.awt.event.MouseListener;
29 import java.awt.event.TextEvent;
30 import java.awt.event.TextListener;
31 import java.util.Iterator;
32 import java.util.Vector;
34 import javax.swing.JPanel;
36 //import net.miginfocom.swing.MigLayout;
38 public class AnnotationColumnChooser extends AnnotationRowFilter implements
39 ActionListener, AdjustmentListener, ItemListener, MouseListener
42 private Choice annotations = new Choice();
44 private Panel actionPanel = new Panel();
46 private TitledPanel thresholdPanel = new TitledPanel();
48 private Panel switchableViewsPanel = new Panel(new CardLayout());
50 private CardLayout switchableViewsLayout = (CardLayout) (switchableViewsPanel
53 private Panel noGraphFilterView = new Panel();
55 private Panel graphFilterView = new Panel();
57 private Panel annotationComboBoxPanel = new Panel();
59 private BorderLayout borderLayout1 = new BorderLayout();
61 private BorderLayout gBorderLayout = new BorderLayout();
63 private BorderLayout ngBorderLayout = new BorderLayout();
65 private Choice threshold = new Choice();
67 private StructureFilterPanel gStructureFilterPanel;
69 private StructureFilterPanel ngStructureFilterPanel;
71 private StructureFilterPanel currentStructureFilterPanel;
73 private SearchPanel currentSearchPanel;
75 private SearchPanel gSearchPanel;
77 private SearchPanel ngSearchPanel;
79 private FurtherActionPanel currentFurtherActionPanel;
81 private FurtherActionPanel gFurtherActionPanel;
83 private FurtherActionPanel ngFurtherActionPanel;
85 public static final int ACTION_OPTION_SELECT = 1;
87 public static int ACTION_OPTION_HIDE = 2;
89 public static String NO_GRAPH_VIEW = "0";
91 public static String GRAPH_VIEW = "1";
93 private int actionOption = ACTION_OPTION_SELECT;
95 private ColumnSelection oldColumnSelection;
97 public AnnotationColumnChooser()
102 } catch (Exception ex)
104 ex.printStackTrace();
108 public AnnotationColumnChooser(AlignViewport av, final AlignmentPanel ap)
113 JalviewLite.addFrame(frame,
114 MessageManager.getString("label.select_by_annotation"), 520,
117 slider.addAdjustmentListener(this);
118 slider.addMouseListener(this);
120 if (av.getAlignment().getAlignmentAnnotation() == null)
124 setOldColumnSelection(av.getColumnSelection());
126 Vector list = new Vector();
128 for (int i = 0; i < av.getAlignment().getAlignmentAnnotation().length; i++)
130 String label = av.getAlignment().getAlignmentAnnotation()[i].label;
131 if (!list.contains(label))
133 list.addElement(label);
137 list.addElement(label + "_" + (index++));
141 for (int i = 0; i < list.size(); i++)
143 annotations.addItem(list.elementAt(i).toString());
146 populateThresholdComboBox(threshold);
148 // restore Object state from the previous session if one exists
149 if (av.getAnnotationColumnSelectionState() != null)
151 currentSearchPanel = av.getAnnotationColumnSelectionState()
152 .getCurrentSearchPanel();
153 currentStructureFilterPanel = av.getAnnotationColumnSelectionState()
154 .getCurrentStructureFilterPanel();
155 annotations.select(av.getAnnotationColumnSelectionState()
156 .getAnnotations().getSelectedIndex());
157 threshold.select(av.getAnnotationColumnSelectionState()
158 .getThreshold().getSelectedIndex());
159 actionOption = av.getAnnotationColumnSelectionState()
166 } catch (Exception ex)
176 private void jbInit() throws Exception
178 ok.setLabel(MessageManager.getString("action.ok"));
180 cancel.setLabel(MessageManager.getString("action.cancel"));
182 thresholdValue.setEnabled(false);
183 thresholdValue.setColumns(7);
185 ok.addActionListener(this);
186 cancel.addActionListener(this);
187 annotations.addItemListener(this);
188 thresholdValue.addActionListener(this);
189 threshold.addItemListener(this);
191 slider.setBackground(Color.white);
192 slider.setEnabled(false);
193 slider.setPreferredSize(new Dimension(100, 32));
195 thresholdPanel.setBackground(Color.white);
196 // thresholdPanel.setFont(JvSwingUtils.getLabelFont());
197 // thresholdPanel.setLayout(new MigLayout("", "[left][right]", "[][]"));
199 actionPanel.setBackground(Color.white);
200 // actionPanel.setFont(JvSwingUtils.getLabelFont());
202 graphFilterView.setLayout(gBorderLayout);
203 graphFilterView.setBackground(Color.white);
205 noGraphFilterView.setLayout(ngBorderLayout);
206 noGraphFilterView.setBackground(Color.white);
208 annotationComboBoxPanel.setBackground(Color.white);
209 // annotationComboBoxPanel.setFont(JvSwingUtils.getLabelFont());
211 gSearchPanel = new SearchPanel(this);
212 ngSearchPanel = new SearchPanel(this);
213 gFurtherActionPanel = new FurtherActionPanel(this);
214 ngFurtherActionPanel = new FurtherActionPanel(this);
215 gStructureFilterPanel = new StructureFilterPanel(this);
216 ngStructureFilterPanel = new StructureFilterPanel(this);
218 thresholdPanel.setTitle("Threshold Filter");
219 thresholdPanel.add(getThreshold());
220 thresholdPanel.add(slider);
221 thresholdPanel.add(thresholdValue);
224 actionPanel.add(cancel);
226 JPanel staticPanel = new JPanel();
227 staticPanel.setLayout(new BorderLayout());
228 staticPanel.setBackground(Color.white);
230 staticPanel.add(gSearchPanel, java.awt.BorderLayout.NORTH);
231 staticPanel.add(gStructureFilterPanel, java.awt.BorderLayout.SOUTH);
233 graphFilterView.add(staticPanel, java.awt.BorderLayout.NORTH);
234 graphFilterView.add(thresholdPanel, java.awt.BorderLayout.CENTER);
235 graphFilterView.add(gFurtherActionPanel, java.awt.BorderLayout.SOUTH);
237 noGraphFilterView.add(ngSearchPanel, java.awt.BorderLayout.PAGE_START);
238 noGraphFilterView.add(ngStructureFilterPanel,
239 java.awt.BorderLayout.CENTER);
240 noGraphFilterView.add(ngFurtherActionPanel,
241 java.awt.BorderLayout.CENTER);
243 annotationComboBoxPanel.add(getAnnotations());
244 switchableViewsPanel.add(noGraphFilterView,
245 AnnotationColumnChooser.NO_GRAPH_VIEW);
246 switchableViewsPanel.add(graphFilterView,
247 AnnotationColumnChooser.GRAPH_VIEW);
249 this.setLayout(borderLayout1);
250 this.add(annotationComboBoxPanel, java.awt.BorderLayout.PAGE_START);
251 this.add(switchableViewsPanel, java.awt.BorderLayout.CENTER);
252 this.add(actionPanel, java.awt.BorderLayout.SOUTH);
254 selectedAnnotationChanged();
258 @SuppressWarnings("unchecked")
261 if (this.getOldColumnSelection() != null)
263 av.getColumnSelection().clear();
265 if (av.getAnnotationColumnSelectionState() != null)
267 ColumnSelection oldSelection = av
268 .getAnnotationColumnSelectionState()
269 .getOldColumnSelection();
270 if (oldSelection != null && oldSelection.getHiddenColumns() != null
271 && !oldSelection.getHiddenColumns().isEmpty())
273 for (Iterator<int[]> itr = oldSelection.getHiddenColumns()
274 .iterator(); itr.hasNext();)
276 int positions[] = itr.next();
277 av.hideColumns(positions[0], positions[1]);
280 av.setColumnSelection(oldSelection);
282 ap.paintAlignment(true);
287 public void adjustmentValueChanged(AdjustmentEvent evt)
291 thresholdValue.setText((slider.getValue() / 1000f) + "");
292 valueChanged(!sliderDragging);
296 protected void addSliderMouseListeners()
299 slider.addMouseListener(new MouseAdapter()
302 public void mousePressed(MouseEvent e)
304 sliderDragging = true;
305 super.mousePressed(e);
309 public void mouseDragged(MouseEvent e)
311 sliderDragging = true;
312 super.mouseDragged(e);
316 public void mouseReleased(MouseEvent evt)
320 sliderDragging = false;
323 ap.paintAlignment(true);
328 public void valueChanged(boolean updateAllAnnotation)
330 if (slider.isEnabled())
332 getCurrentAnnotation().threshold.value = slider.getValue() / 1000f;
334 ap.paintAlignment(false);
338 public Choice getThreshold()
343 public void setThreshold(Choice threshold)
345 this.threshold = threshold;
348 public Choice getAnnotations()
353 public void setAnnotations(Choice annotations)
355 this.annotations = annotations;
359 public void updateView()
361 // Check if combobox is still adjusting
367 AnnotationFilterParameter filterParams = new AnnotationFilterParameter();
368 setCurrentAnnotation(av.getAlignment().getAlignmentAnnotation()[getAnnotations()
369 .getSelectedIndex()]);
371 int selectedThresholdItem = getSelectedThresholdItem(getThreshold()
372 .getSelectedIndex());
374 slider.setEnabled(true);
375 thresholdValue.setEnabled(true);
377 if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
379 slider.setEnabled(false);
380 thresholdValue.setEnabled(false);
381 thresholdValue.setText("");
382 // build filter params
384 else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
386 if (getCurrentAnnotation().threshold == null)
388 getCurrentAnnotation()
391 (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin) / 2f,
392 "Threshold", Color.black));
396 float range = getCurrentAnnotation().graphMax * 1000
397 - getCurrentAnnotation().graphMin * 1000;
399 slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
400 slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
401 slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000));
402 thresholdValue.setText(getCurrentAnnotation().threshold.value + "");
403 // slider.setMajorTickSpacing((int) (range / 10f));
404 slider.setEnabled(true);
405 thresholdValue.setEnabled(true);
408 // build filter params
410 .setThresholdType(AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);
411 if (getCurrentAnnotation().graph != AlignmentAnnotation.NO_GRAPH)
414 .setThresholdValue(getCurrentAnnotation().threshold.value);
416 if (selectedThresholdItem == AnnotationColourGradient.ABOVE_THRESHOLD)
419 .setThresholdType(AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD);
421 else if (selectedThresholdItem == AnnotationColourGradient.BELOW_THRESHOLD)
424 .setThresholdType(AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD);
429 if (currentStructureFilterPanel != null)
431 if (currentStructureFilterPanel.alphaHelix.getState())
433 filterParams.setFilterAlphaHelix(true);
435 if (currentStructureFilterPanel.betaStrand.getState())
437 filterParams.setFilterBetaSheet(true);
439 if (currentStructureFilterPanel.turn.getState())
441 filterParams.setFilterTurn(true);
445 if (currentSearchPanel != null)
448 if (!currentSearchPanel.searchBox.getText().isEmpty())
450 currentSearchPanel.description.setEnabled(true);
451 currentSearchPanel.displayName.setEnabled(true);
452 filterParams.setRegexString(currentSearchPanel.searchBox.getText());
453 if (currentSearchPanel.displayName.getState())
456 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING);
458 if (currentSearchPanel.description.getState())
461 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION);
466 currentSearchPanel.description.setEnabled(false);
467 currentSearchPanel.displayName.setEnabled(false);
471 av.getColumnSelection().filterAnnotations(
472 getCurrentAnnotation().annotations, filterParams);
474 av.showAllHiddenColumns();
475 if (getActionOption() == ACTION_OPTION_HIDE)
477 av.hideSelectedColumns();
481 av.setAnnotationColumnSelectionState(this);
482 ap.paintAlignment(true);
485 public ColumnSelection getOldColumnSelection()
487 return oldColumnSelection;
490 public void setOldColumnSelection(ColumnSelection currentColumnSelection)
492 if (currentColumnSelection != null)
494 this.oldColumnSelection = new ColumnSelection(currentColumnSelection);
498 public FurtherActionPanel getCurrentFutherActionPanel()
500 return currentFurtherActionPanel;
503 public void setCurrentFutherActionPanel(
504 FurtherActionPanel currentFutherActionPanel)
506 this.currentFurtherActionPanel = currentFutherActionPanel;
509 public SearchPanel getCurrentSearchPanel()
511 return currentSearchPanel;
514 public void setCurrentSearchPanel(SearchPanel currentSearchPanel)
516 this.currentSearchPanel = currentSearchPanel;
519 public int getActionOption()
524 public void setActionOption(int actionOption)
526 this.actionOption = actionOption;
529 public StructureFilterPanel getCurrentStructureFilterPanel()
531 return currentStructureFilterPanel;
534 public void setCurrentStructureFilterPanel(
535 StructureFilterPanel currentStructureFilterPanel)
537 this.currentStructureFilterPanel = currentStructureFilterPanel;
541 public void itemStateChanged(ItemEvent e)
543 if (e.getSource() == annotations)
545 selectedAnnotationChanged();
547 else if (e.getSource() == threshold)
549 threshold_actionPerformed(null);
553 public void selectedAnnotationChanged()
555 String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
556 if (av.getAlignment().getAlignmentAnnotation()[getAnnotations()
557 .getSelectedIndex()].graph != AlignmentAnnotation.NO_GRAPH)
559 currentView = AnnotationColumnChooser.GRAPH_VIEW;
562 gSearchPanel.syncState();
563 gFurtherActionPanel.syncState();
564 gStructureFilterPanel.syncState();
566 ngSearchPanel.syncState();
567 ngFurtherActionPanel.syncState();
568 ngStructureFilterPanel.syncState();
570 switchableViewsLayout.show(switchableViewsPanel, currentView);
574 public class FurtherActionPanel extends Panel implements
577 private AnnotationColumnChooser aColChooser;
579 private Choice furtherAction = new Choice();
581 public FurtherActionPanel(AnnotationColumnChooser aColChooser)
583 this.aColChooser = aColChooser;
584 furtherAction.addItem("Select");
585 furtherAction.addItem("Hide");
586 furtherAction.addItemListener(this);
589 // this.setTitle("Filter Actions");
590 // this.setFont(JvSwingUtils.getLabelFont());
592 this.add(furtherAction);
595 public void syncState()
597 if (aColChooser.getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
599 furtherAction.select("Hide");
603 furtherAction.select("Select");
608 public void itemStateChanged(ItemEvent e)
610 aColChooser.setCurrentFutherActionPanel(this);
611 if (furtherAction.getSelectedItem().toString().equalsIgnoreCase("Select")) // BH added "toString()"
613 setActionOption(ACTION_OPTION_SELECT);
618 setActionOption(ACTION_OPTION_HIDE);
625 public class StructureFilterPanel extends TitledPanel implements
628 private AnnotationColumnChooser aColChooser;
630 private Checkbox alphaHelix = new Checkbox();
632 private Checkbox betaStrand = new Checkbox();
634 private Checkbox turn = new Checkbox();
636 private Checkbox all = new Checkbox();
638 public StructureFilterPanel(AnnotationColumnChooser aColChooser)
640 this.aColChooser = aColChooser;
642 alphaHelix.setLabel(MessageManager.getString("label.alpha_helix"));
643 alphaHelix.setBackground(Color.white);
645 alphaHelix.addItemListener(this);
647 betaStrand.setLabel(MessageManager.getString("label.beta_strand"));
648 betaStrand.setBackground(Color.white);
649 betaStrand.addItemListener(this);
651 turn.setLabel(MessageManager.getString("label.turn"));
652 turn.setBackground(Color.white);
653 turn.addItemListener(this);
655 all.setLabel(MessageManager.getString("label.select_all"));
656 all.setBackground(Color.white);
657 all.addItemListener(this);
659 this.setBackground(Color.white);
660 this.setTitle("Structure Filter");
661 // this.setFont(JvSwingUtils.getLabelFont());
664 this.add(alphaHelix);
665 this.add(betaStrand);
669 public void alphaHelix_actionPerformed()
671 updateSelectAllState();
672 aColChooser.setCurrentStructureFilterPanel(this);
673 aColChooser.updateView();
676 public void betaStrand_actionPerformed()
678 updateSelectAllState();
679 aColChooser.setCurrentStructureFilterPanel(this);
680 aColChooser.updateView();
683 public void turn_actionPerformed()
685 updateSelectAllState();
686 aColChooser.setCurrentStructureFilterPanel(this);
687 aColChooser.updateView();
690 public void all_actionPerformed()
694 alphaHelix.setState(true);
695 betaStrand.setState(true);
700 alphaHelix.setState(false);
701 betaStrand.setState(false);
702 turn.setState(false);
704 aColChooser.setCurrentStructureFilterPanel(this);
705 aColChooser.updateView();
708 public void updateSelectAllState()
710 if (alphaHelix.getState() && betaStrand.getState() && turn.getState())
720 public void syncState()
722 StructureFilterPanel sfp = aColChooser
723 .getCurrentStructureFilterPanel();
726 alphaHelix.setState(sfp.alphaHelix.getState());
727 betaStrand.setState(sfp.betaStrand.getState());
728 turn.setState(sfp.turn.getState());
729 if (sfp.all.getState())
732 alphaHelix.setState(true);
733 betaStrand.setState(true);
741 public void itemStateChanged(ItemEvent e)
743 if (e.getSource() == alphaHelix)
745 alphaHelix_actionPerformed();
747 else if (e.getSource() == betaStrand)
749 betaStrand_actionPerformed();
751 else if (e.getSource() == turn)
753 turn_actionPerformed();
755 else if (e.getSource() == all)
757 all_actionPerformed();
762 public class SearchPanel extends TitledPanel implements ItemListener
764 private AnnotationColumnChooser aColChooser;
766 private Checkbox displayName = new Checkbox();
768 private Checkbox description = new Checkbox();
770 private TextField searchBox = new TextField(10);
772 public SearchPanel(AnnotationColumnChooser aColChooser)
775 this.aColChooser = aColChooser;
776 searchBox.addTextListener(new TextListener()
780 public void textValueChanged(TextEvent e)
782 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)