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
575 private AnnotationColumnChooser aColChooser;
577 private Choice furtherAction = new Choice();
579 public FurtherActionPanel(AnnotationColumnChooser aColChooser)
581 this.aColChooser = aColChooser;
582 furtherAction.addItem("Select");
583 furtherAction.addItem("Hide");
584 furtherAction.addItemListener(this);
587 // this.setTitle("Filter Actions");
588 // this.setFont(JvSwingUtils.getLabelFont());
590 this.add(furtherAction);
593 public void syncState()
595 if (aColChooser.getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
597 furtherAction.select("Hide");
601 furtherAction.select("Select");
606 public void itemStateChanged(ItemEvent e)
608 aColChooser.setCurrentFutherActionPanel(this);
609 if (furtherAction.getSelectedItem().equalsIgnoreCase("Select"))
611 setActionOption(ACTION_OPTION_SELECT);
616 setActionOption(ACTION_OPTION_HIDE);
623 public class StructureFilterPanel extends TitledPanel implements
626 private AnnotationColumnChooser aColChooser;
628 private Checkbox alphaHelix = new Checkbox();
630 private Checkbox betaStrand = new Checkbox();
632 private Checkbox turn = new Checkbox();
634 private Checkbox all = new Checkbox();
636 public StructureFilterPanel(AnnotationColumnChooser aColChooser)
638 this.aColChooser = aColChooser;
640 alphaHelix.setLabel(MessageManager.getString("label.alpha_helix"));
641 alphaHelix.setBackground(Color.white);
643 alphaHelix.addItemListener(this);
645 betaStrand.setLabel(MessageManager.getString("label.beta_strand"));
646 betaStrand.setBackground(Color.white);
647 betaStrand.addItemListener(this);
649 turn.setLabel(MessageManager.getString("label.turn"));
650 turn.setBackground(Color.white);
651 turn.addItemListener(this);
653 all.setLabel(MessageManager.getString("label.select_all"));
654 all.setBackground(Color.white);
655 all.addItemListener(this);
657 this.setBackground(Color.white);
658 this.setTitle("Structure Filter");
659 // this.setFont(JvSwingUtils.getLabelFont());
662 this.add(alphaHelix);
663 this.add(betaStrand);
667 public void alphaHelix_actionPerformed()
669 updateSelectAllState();
670 aColChooser.setCurrentStructureFilterPanel(this);
671 aColChooser.updateView();
674 public void betaStrand_actionPerformed()
676 updateSelectAllState();
677 aColChooser.setCurrentStructureFilterPanel(this);
678 aColChooser.updateView();
681 public void turn_actionPerformed()
683 updateSelectAllState();
684 aColChooser.setCurrentStructureFilterPanel(this);
685 aColChooser.updateView();
688 public void all_actionPerformed()
692 alphaHelix.setState(true);
693 betaStrand.setState(true);
698 alphaHelix.setState(false);
699 betaStrand.setState(false);
700 turn.setState(false);
702 aColChooser.setCurrentStructureFilterPanel(this);
703 aColChooser.updateView();
706 public void updateSelectAllState()
708 if (alphaHelix.getState() && betaStrand.getState() && turn.getState())
718 public void syncState()
720 StructureFilterPanel sfp = aColChooser
721 .getCurrentStructureFilterPanel();
724 alphaHelix.setState(sfp.alphaHelix.getState());
725 betaStrand.setState(sfp.betaStrand.getState());
726 turn.setState(sfp.turn.getState());
727 if (sfp.all.getState())
730 alphaHelix.setState(true);
731 betaStrand.setState(true);
739 public void itemStateChanged(ItemEvent e)
741 if (e.getSource() == alphaHelix)
743 alphaHelix_actionPerformed();
745 else if (e.getSource() == betaStrand)
747 betaStrand_actionPerformed();
749 else if (e.getSource() == turn)
751 turn_actionPerformed();
753 else if (e.getSource() == all)
755 all_actionPerformed();
760 public class SearchPanel extends TitledPanel implements ItemListener
762 private AnnotationColumnChooser aColChooser;
764 private Checkbox displayName = new Checkbox();
766 private Checkbox description = new Checkbox();
768 private TextField searchBox = new TextField(10);
770 public SearchPanel(AnnotationColumnChooser aColChooser)
773 this.aColChooser = aColChooser;
774 searchBox.addTextListener(new TextListener()
778 public void textValueChanged(TextEvent e)
780 searchStringAction();
786 displayName.setLabel(MessageManager.getString("label.display_name"));
787 displayName.setEnabled(false);
788 displayName.addItemListener(this);
790 description.setLabel(MessageManager.getString("label.description"));
791 description.setEnabled(false);
792 description.addItemListener(this);
793 this.setTitle("Search Filter");
794 // this.setFont(JvSwingUtils.getLabelFont());
798 this.add(displayName);
799 this.add(description);
802 public void displayNameCheckboxAction()
804 aColChooser.setCurrentSearchPanel(this);
805 aColChooser.updateView();
808 public void discriptionCheckboxAction()
810 aColChooser.setCurrentSearchPanel(this);
811 aColChooser.updateView();
814 public void searchStringAction()
816 aColChooser.setCurrentSearchPanel(this);
817 aColChooser.updateView();
820 public void syncState()
822 SearchPanel sp = aColChooser.getCurrentSearchPanel();
825 description.setEnabled(sp.description.isEnabled());
826 description.setState(sp.description.getState());
828 displayName.setEnabled(sp.displayName.isEnabled());
829 displayName.setState(sp.displayName.getState());
831 searchBox.setText(sp.searchBox.getText());
836 public void itemStateChanged(ItemEvent e)
838 if (e.getSource() == displayName)
840 displayNameCheckboxAction();
842 else if (e.getSource() == description)
844 discriptionCheckboxAction();
850 public void actionPerformed(ActionEvent evt)
852 if (evt.getSource() == thresholdValue)
856 float f = new Float(thresholdValue.getText()).floatValue();
857 slider.setValue((int) (f * 1000));
858 adjustmentValueChanged(null);
859 } catch (NumberFormatException ex)
864 else if (evt.getSource() == ok)
866 ok_actionPerformed(null);
868 else if (evt.getSource() == cancel)
870 cancel_actionPerformed(null);
872 else if (evt.getSource() == thresholdValue)
874 thresholdValue_actionPerformed(null);
883 public void mouseClicked(MouseEvent e)
885 // TODO Auto-generated method stub
890 public void mousePressed(MouseEvent e)
892 if (e.getSource() == slider)
900 public void mouseReleased(MouseEvent e)
902 if (e.getSource() == slider)
909 public void mouseEntered(MouseEvent e)
911 if (e.getSource() == slider)
918 public void mouseExited(MouseEvent e)
920 if (e.getSource() == slider)