JAL-1645 Version-Rel Version 2.9 Year-Rel 2015 Licensing glob
[jalview.git] / src / jalview / gui / AnnotationColumnChooser.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9)
3  * Copyright (C) 2015 The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21
22 package jalview.gui;
23
24 import jalview.datamodel.AlignmentAnnotation;
25 import jalview.datamodel.ColumnSelection;
26 import jalview.schemes.AnnotationColourGradient;
27 import jalview.util.MessageManager;
28 import jalview.viewmodel.annotationfilter.AnnotationFilterParameter;
29
30 import java.awt.BorderLayout;
31 import java.awt.CardLayout;
32 import java.awt.Color;
33 import java.awt.Dimension;
34 import java.awt.event.ActionEvent;
35 import java.awt.event.ActionListener;
36 import java.awt.event.ItemEvent;
37 import java.awt.event.ItemListener;
38 import java.util.Iterator;
39
40 import javax.swing.ButtonGroup;
41 import javax.swing.JCheckBox;
42 import javax.swing.JComboBox;
43 import javax.swing.JInternalFrame;
44 import javax.swing.JLayeredPane;
45 import javax.swing.JPanel;
46 import javax.swing.JRadioButton;
47 import javax.swing.JTextField;
48 import javax.swing.border.TitledBorder;
49 import javax.swing.event.DocumentEvent;
50 import javax.swing.event.DocumentListener;
51
52 import net.miginfocom.swing.MigLayout;
53
54 @SuppressWarnings("serial")
55 public class AnnotationColumnChooser extends AnnotationRowFilter implements
56         ItemListener
57 {
58
59   private JComboBox<String> annotations;
60
61   private JPanel actionPanel = new JPanel();
62
63   private JPanel thresholdPanel = new JPanel();
64
65   private JPanel switchableViewsPanel = new JPanel(new CardLayout());
66
67   private CardLayout switchableViewsLayout = (CardLayout) (switchableViewsPanel
68           .getLayout());
69
70   private JPanel noGraphFilterView = new JPanel();
71
72   private JPanel graphFilterView = new JPanel();
73
74   private JPanel annotationComboBoxPanel = new JPanel();
75
76   private BorderLayout borderLayout1 = new BorderLayout();
77
78   private JComboBox<String> threshold = new JComboBox<String>();
79
80   private StructureFilterPanel gStructureFilterPanel;
81
82   private StructureFilterPanel ngStructureFilterPanel;
83
84   private StructureFilterPanel currentStructureFilterPanel;
85
86   private SearchPanel currentSearchPanel;
87
88   private SearchPanel gSearchPanel;
89
90   private SearchPanel ngSearchPanel;
91
92   private FurtherActionPanel currentFurtherActionPanel;
93
94   private FurtherActionPanel gFurtherActionPanel;
95
96   private FurtherActionPanel ngFurtherActionPanel;
97
98   public static final int ACTION_OPTION_SELECT = 1;
99
100   public static int ACTION_OPTION_HIDE = 2;
101
102   public static String NO_GRAPH_VIEW = "0";
103
104   public static String GRAPH_VIEW = "1";
105
106   private int actionOption = ACTION_OPTION_SELECT;
107
108   private ColumnSelection oldColumnSelection;
109
110   public AnnotationColumnChooser()
111   {
112     try
113     {
114       jbInit();
115     } catch (Exception ex)
116     {
117       ex.printStackTrace();
118     }
119   }
120
121   public AnnotationColumnChooser(AlignViewport av, final AlignmentPanel ap)
122   {
123     super(av, ap);
124     frame = new JInternalFrame();
125     frame.setContentPane(this);
126     frame.setLayer(JLayeredPane.PALETTE_LAYER);
127     Desktop.addInternalFrame(frame,
128             MessageManager.getString("label.select_by_annotation"), 520,
129             215);
130
131     addSliderChangeListener();
132     addSliderMouseListeners();
133
134     if (av.getAlignment().getAlignmentAnnotation() == null)
135     {
136       return;
137     }
138     setOldColumnSelection(av.getColumnSelection());
139     adjusting = true;
140
141     setAnnotations(new JComboBox<String>(getAnnotationItems(false)));
142     populateThresholdComboBox(threshold);
143
144     // restore Object state from the previous session if one exists
145     if (av.getAnnotationColumnSelectionState() != null)
146     {
147       currentSearchPanel = av.getAnnotationColumnSelectionState()
148               .getCurrentSearchPanel();
149       currentStructureFilterPanel = av.getAnnotationColumnSelectionState()
150               .getCurrentStructureFilterPanel();
151       annotations.setSelectedIndex(av.getAnnotationColumnSelectionState()
152               .getAnnotations().getSelectedIndex());
153       threshold.setSelectedIndex(av.getAnnotationColumnSelectionState()
154               .getThreshold().getSelectedIndex());
155       actionOption = av.getAnnotationColumnSelectionState()
156               .getActionOption();
157     }
158
159     try
160     {
161       jbInit();
162     } catch (Exception ex)
163     {
164     }
165     adjusting = false;
166
167     updateView();
168     frame.invalidate();
169     frame.pack();
170   }
171
172   private void jbInit() throws Exception
173   {
174     ok.setOpaque(false);
175     ok.setText(MessageManager.getString("action.ok"));
176     ok.addActionListener(new ActionListener()
177     {
178       @Override
179       public void actionPerformed(ActionEvent e)
180       {
181         ok_actionPerformed(e);
182       }
183     });
184
185     cancel.setOpaque(false);
186     cancel.setText(MessageManager.getString("action.cancel"));
187     cancel.addActionListener(new ActionListener()
188     {
189       @Override
190       public void actionPerformed(ActionEvent e)
191       {
192         cancel_actionPerformed(e);
193       }
194     });
195
196     annotations.addItemListener(this);
197     annotations.setToolTipText(MessageManager
198             .getString("info.select_annotation_row"));
199     threshold.addActionListener(new ActionListener()
200     {
201       @Override
202       public void actionPerformed(ActionEvent e)
203       {
204         threshold_actionPerformed(e);
205       }
206     });
207
208     thresholdValue.setEnabled(false);
209     thresholdValue.setColumns(7);
210     thresholdValue.addActionListener(new ActionListener()
211     {
212       @Override
213       public void actionPerformed(ActionEvent e)
214       {
215         thresholdValue_actionPerformed(e);
216       }
217     });
218
219     slider.setPaintLabels(false);
220     slider.setPaintTicks(true);
221     slider.setBackground(Color.white);
222     slider.setEnabled(false);
223     slider.setOpaque(false);
224     slider.setPreferredSize(new Dimension(100, 32));
225
226     thresholdPanel.setBorder(new TitledBorder(MessageManager
227             .getString("label.threshold_filter")));
228     thresholdPanel.setBackground(Color.white);
229     thresholdPanel.setFont(JvSwingUtils.getLabelFont());
230     thresholdPanel.setLayout(new MigLayout("", "[left][right]", "[][]"));
231
232     actionPanel.setBackground(Color.white);
233     actionPanel.setFont(JvSwingUtils.getLabelFont());
234
235     graphFilterView.setLayout(new MigLayout("", "[left][right]", "[][]"));
236     graphFilterView.setBackground(Color.white);
237
238     noGraphFilterView.setLayout(new MigLayout("", "[left][right]", "[][]"));
239     noGraphFilterView.setBackground(Color.white);
240
241     annotationComboBoxPanel.setBackground(Color.white);
242     annotationComboBoxPanel.setFont(JvSwingUtils.getLabelFont());
243
244     gSearchPanel = new SearchPanel(this);
245     ngSearchPanel = new SearchPanel(this);
246     gFurtherActionPanel = new FurtherActionPanel(this);
247     ngFurtherActionPanel = new FurtherActionPanel(this);
248     gStructureFilterPanel = new StructureFilterPanel(this);
249     ngStructureFilterPanel = new StructureFilterPanel(this);
250
251     thresholdPanel.add(getThreshold());
252     thresholdPanel.add(thresholdValue, "wrap");
253     thresholdPanel.add(slider, "grow, span, wrap");
254
255     actionPanel.add(ok);
256     actionPanel.add(cancel);
257
258     graphFilterView.add(gSearchPanel, "grow, span, wrap");
259     graphFilterView.add(gStructureFilterPanel, "grow, span, wrap");
260     graphFilterView.add(thresholdPanel, "grow, span, wrap");
261     graphFilterView.add(gFurtherActionPanel);
262
263     noGraphFilterView.add(ngSearchPanel, "grow, span, wrap");
264     noGraphFilterView.add(ngStructureFilterPanel, "grow, span, wrap");
265     noGraphFilterView.add(ngFurtherActionPanel);
266
267     annotationComboBoxPanel.add(getAnnotations());
268     switchableViewsPanel.add(noGraphFilterView,
269             AnnotationColumnChooser.NO_GRAPH_VIEW);
270     switchableViewsPanel.add(graphFilterView,
271             AnnotationColumnChooser.GRAPH_VIEW);
272
273     this.setLayout(borderLayout1);
274     this.add(annotationComboBoxPanel, java.awt.BorderLayout.PAGE_START);
275     this.add(switchableViewsPanel, java.awt.BorderLayout.CENTER);
276     this.add(actionPanel, java.awt.BorderLayout.SOUTH);
277
278     selectedAnnotationChanged();
279     updateThresholdPanelToolTip();
280     this.validate();
281   }
282
283   public void updateThresholdPanelToolTip()
284   {
285     thresholdValue.setToolTipText("");
286     slider.setToolTipText("");
287
288     String defaultTtip = MessageManager
289             .getString("info.change_threshold_mode_to_enable");
290
291     String threshold = getThreshold().getSelectedItem().toString();
292     if (threshold.equalsIgnoreCase("No Threshold"))
293     {
294       thresholdValue.setToolTipText(defaultTtip);
295       slider.setToolTipText(defaultTtip);
296     }
297   }
298
299   public void reset()
300   {
301     if (this.getOldColumnSelection() != null)
302     {
303       av.getColumnSelection().clear();
304
305       if (av.getAnnotationColumnSelectionState() != null)
306       {
307         ColumnSelection oldSelection = av
308                 .getAnnotationColumnSelectionState()
309                 .getOldColumnSelection();
310         if (oldSelection != null && oldSelection.getHiddenColumns() != null
311                 && !oldSelection.getHiddenColumns().isEmpty())
312         {
313           for (Iterator<int[]> itr = oldSelection.getHiddenColumns()
314                   .iterator(); itr.hasNext();)
315           {
316             int positions[] = itr.next();
317             av.hideColumns(positions[0], positions[1]);
318           }
319         }
320         av.setColumnSelection(oldSelection);
321       }
322       ap.paintAlignment(true);
323     }
324
325   }
326
327   public void valueChanged(boolean updateAllAnnotation)
328   {
329     if (slider.isEnabled())
330     {
331       getCurrentAnnotation().threshold.value = slider.getValue() / 1000f;
332       updateView();
333       propagateSeqAssociatedThreshold(updateAllAnnotation,
334               getCurrentAnnotation());
335       ap.paintAlignment(false);
336     }
337   }
338
339   public JComboBox<String> getThreshold()
340   {
341     return threshold;
342   }
343
344   public void setThreshold(JComboBox<String> threshold)
345   {
346     this.threshold = threshold;
347   }
348
349   public JComboBox<String> getAnnotations()
350   {
351     return annotations;
352   }
353
354   public void setAnnotations(JComboBox<String> annotations)
355   {
356     this.annotations = annotations;
357   }
358
359   @Override
360   public void updateView()
361   {
362     // Check if combobox is still adjusting
363     if (adjusting)
364     {
365       return;
366     }
367
368     AnnotationFilterParameter filterParams = new AnnotationFilterParameter();
369
370     setCurrentAnnotation(av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
371             .getSelectedIndex()]]);
372
373     int selectedThresholdItem = getSelectedThresholdItem(getThreshold()
374             .getSelectedIndex());
375
376     slider.setEnabled(true);
377     thresholdValue.setEnabled(true);
378
379     if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
380     {
381       slider.setEnabled(false);
382       thresholdValue.setEnabled(false);
383       thresholdValue.setText("");
384       // build filter params
385     }
386     else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
387     {
388       if (getCurrentAnnotation().threshold == null)
389       {
390         getCurrentAnnotation()
391                 .setThreshold(
392                         new jalview.datamodel.GraphLine(
393                                 (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin) / 2f,
394                                 "Threshold", Color.black));
395       }
396
397       adjusting = true;
398       float range = getCurrentAnnotation().graphMax * 1000
399               - getCurrentAnnotation().graphMin * 1000;
400
401       slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
402       slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
403       slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000));
404       thresholdValue.setText(getCurrentAnnotation().threshold.value + "");
405       slider.setMajorTickSpacing((int) (range / 10f));
406       slider.setEnabled(true);
407       thresholdValue.setEnabled(true);
408       adjusting = false;
409
410       // build filter params
411       filterParams
412               .setThresholdType(AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);
413       if (getCurrentAnnotation().graph != AlignmentAnnotation.NO_GRAPH)
414       {
415         filterParams
416                 .setThresholdValue(getCurrentAnnotation().threshold.value);
417
418         if (selectedThresholdItem == AnnotationColourGradient.ABOVE_THRESHOLD)
419         {
420           filterParams
421                   .setThresholdType(AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD);
422         }
423         else if (selectedThresholdItem == AnnotationColourGradient.BELOW_THRESHOLD)
424         {
425           filterParams
426                   .setThresholdType(AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD);
427         }
428       }
429     }
430
431     updateThresholdPanelToolTip();
432     if (currentStructureFilterPanel != null)
433     {
434       if (currentStructureFilterPanel.alphaHelix.isSelected())
435       {
436         filterParams.setFilterAlphaHelix(true);
437       }
438       if (currentStructureFilterPanel.betaStrand.isSelected())
439       {
440         filterParams.setFilterBetaSheet(true);
441       }
442       if (currentStructureFilterPanel.turn.isSelected())
443       {
444         filterParams.setFilterTurn(true);
445       }
446     }
447
448     if (currentSearchPanel != null)
449     {
450
451       if (!currentSearchPanel.searchBox.getText().isEmpty())
452       {
453         currentSearchPanel.description.setEnabled(true);
454         currentSearchPanel.displayName.setEnabled(true);
455         filterParams.setRegexString(currentSearchPanel.searchBox.getText());
456         if (currentSearchPanel.displayName.isSelected())
457         {
458           filterParams
459                   .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING);
460         }
461         if (currentSearchPanel.description.isSelected())
462         {
463           filterParams
464                   .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION);
465         }
466       }
467       else
468       {
469         currentSearchPanel.description.setEnabled(false);
470         currentSearchPanel.displayName.setEnabled(false);
471       }
472     }
473
474     av.getColumnSelection().filterAnnotations(
475             getCurrentAnnotation().annotations, filterParams);
476
477     av.showAllHiddenColumns();
478     if (getActionOption() == ACTION_OPTION_HIDE)
479     {
480       av.hideSelectedColumns();
481     }
482
483     filterParams = null;
484     av.setAnnotationColumnSelectionState(this);
485     ap.paintAlignment(true);
486   }
487
488   public ColumnSelection getOldColumnSelection()
489   {
490     return oldColumnSelection;
491   }
492
493   public void setOldColumnSelection(ColumnSelection currentColumnSelection)
494   {
495     if (currentColumnSelection != null)
496     {
497       this.oldColumnSelection = new ColumnSelection(currentColumnSelection);
498     }
499   }
500
501   public FurtherActionPanel getCurrentFutherActionPanel()
502   {
503     return currentFurtherActionPanel;
504   }
505
506   public void setCurrentFutherActionPanel(
507           FurtherActionPanel currentFutherActionPanel)
508   {
509     this.currentFurtherActionPanel = currentFutherActionPanel;
510   }
511
512   public SearchPanel getCurrentSearchPanel()
513   {
514     return currentSearchPanel;
515   }
516
517   public void setCurrentSearchPanel(SearchPanel currentSearchPanel)
518   {
519     this.currentSearchPanel = currentSearchPanel;
520   }
521
522   public int getActionOption()
523   {
524     return actionOption;
525   }
526
527   public void setActionOption(int actionOption)
528   {
529     this.actionOption = actionOption;
530   }
531
532   public StructureFilterPanel getCurrentStructureFilterPanel()
533   {
534     return currentStructureFilterPanel;
535   }
536
537   public void setCurrentStructureFilterPanel(
538           StructureFilterPanel currentStructureFilterPanel)
539   {
540     this.currentStructureFilterPanel = currentStructureFilterPanel;
541   }
542
543   public void select_action(ActionEvent actionEvent)
544   {
545     JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
546     if (radioButton.isSelected())
547     {
548       setActionOption(ACTION_OPTION_SELECT);
549       updateView();
550     }
551   }
552
553   public void hide_action(ActionEvent actionEvent)
554   {
555     JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
556     if (radioButton.isSelected())
557     {
558       setActionOption(ACTION_OPTION_HIDE);
559       updateView();
560     }
561   }
562
563   @Override
564   public void itemStateChanged(ItemEvent e)
565   {
566     selectedAnnotationChanged();
567   }
568
569   public void selectedAnnotationChanged()
570   {
571     String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
572     if (av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
573             .getSelectedIndex()]].graph != AlignmentAnnotation.NO_GRAPH)
574     {
575       currentView = AnnotationColumnChooser.GRAPH_VIEW;
576     }
577
578     gSearchPanel.syncState();
579     gFurtherActionPanel.syncState();
580     gStructureFilterPanel.syncState();
581
582     ngSearchPanel.syncState();
583     ngFurtherActionPanel.syncState();
584     ngStructureFilterPanel.syncState();
585
586     switchableViewsLayout.show(switchableViewsPanel, currentView);
587     updateView();
588   }
589
590   public class FurtherActionPanel extends JPanel
591   {
592     private AnnotationColumnChooser aColChooser;
593
594     private JRadioButton hideOption = new JRadioButton();
595
596     private JRadioButton selectOption = new JRadioButton();
597
598     private ButtonGroup optionsGroup = new ButtonGroup();
599
600     public FurtherActionPanel(AnnotationColumnChooser aColChooser)
601     {
602       this.aColChooser = aColChooser;
603       JvSwingUtils.jvInitComponent(selectOption, "action.select");
604       selectOption.addActionListener(new ActionListener()
605       {
606         @Override
607         public void actionPerformed(ActionEvent actionEvent)
608         {
609           selectRadioAction(actionEvent);
610         }
611       });
612
613       JvSwingUtils.jvInitComponent(hideOption, "action.hide");
614       hideOption.addActionListener(new ActionListener()
615       {
616         @Override
617         public void actionPerformed(ActionEvent actionEvent)
618         {
619           hideRadioAction(actionEvent);
620         }
621       });
622
623       optionsGroup.add(selectOption);
624       optionsGroup.add(hideOption);
625       optionsGroup.setSelected(selectOption.getModel(), true);
626
627       JvSwingUtils.jvInitComponent(this);
628       syncState();
629
630       this.add(selectOption);
631       this.add(hideOption);
632     }
633
634     public void selectRadioAction(ActionEvent actionEvent)
635     {
636       aColChooser.setCurrentFutherActionPanel(this);
637       aColChooser.select_action(actionEvent);
638     }
639
640     public void hideRadioAction(ActionEvent actionEvent)
641     {
642       aColChooser.setCurrentFutherActionPanel(this);
643       aColChooser.hide_action(actionEvent);
644     }
645
646     public void syncState()
647     {
648       if (aColChooser.getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
649       {
650         this.optionsGroup.setSelected(this.hideOption.getModel(), true);
651       }
652       else
653       {
654         this.optionsGroup.setSelected(this.selectOption.getModel(), true);
655       }
656     }
657   }
658
659   public class StructureFilterPanel extends JPanel
660   {
661     private AnnotationColumnChooser aColChooser;
662
663     private JCheckBox alphaHelix = new JCheckBox();
664
665     private JCheckBox betaStrand = new JCheckBox();
666
667     private JCheckBox turn = new JCheckBox();
668
669     private JCheckBox all = new JCheckBox();
670
671     public StructureFilterPanel(AnnotationColumnChooser aColChooser)
672     {
673       this.aColChooser = aColChooser;
674
675       JvSwingUtils.jvInitComponent(alphaHelix, "label.alpha_helix");
676       alphaHelix.addActionListener(new ActionListener()
677       {
678         @Override
679         public void actionPerformed(ActionEvent actionEvent)
680         {
681           alphaHelix_actionPerformed();
682         }
683       });
684
685       JvSwingUtils.jvInitComponent(betaStrand, "label.beta_strand");
686       betaStrand.addActionListener(new ActionListener()
687       {
688         @Override
689         public void actionPerformed(ActionEvent actionEvent)
690         {
691           betaStrand_actionPerformed();
692         }
693       });
694
695       JvSwingUtils.jvInitComponent(turn, "label.turn");
696       turn.addActionListener(new ActionListener()
697       {
698         @Override
699         public void actionPerformed(ActionEvent actionEvent)
700         {
701           turn_actionPerformed();
702         }
703       });
704
705       JvSwingUtils.jvInitComponent(all, "label.select_all");
706       all.addActionListener(new ActionListener()
707       {
708         @Override
709         public void actionPerformed(ActionEvent actionEvent)
710         {
711           all_actionPerformed();
712         }
713       });
714
715       this.setBorder(new TitledBorder(MessageManager
716               .getString("label.structures_filter")));
717       JvSwingUtils.jvInitComponent(this);
718
719       this.add(all);
720       this.add(alphaHelix);
721       this.add(betaStrand);
722       this.add(turn);
723     }
724
725     public void alphaHelix_actionPerformed()
726     {
727       updateSelectAllState();
728       aColChooser.setCurrentStructureFilterPanel(this);
729       aColChooser.updateView();
730     }
731
732     public void betaStrand_actionPerformed()
733     {
734       updateSelectAllState();
735       aColChooser.setCurrentStructureFilterPanel(this);
736       aColChooser.updateView();
737     }
738
739     public void turn_actionPerformed()
740     {
741       updateSelectAllState();
742       aColChooser.setCurrentStructureFilterPanel(this);
743       aColChooser.updateView();
744     }
745
746     public void all_actionPerformed()
747     {
748       if (all.isSelected())
749       {
750         alphaHelix.setSelected(true);
751         betaStrand.setSelected(true);
752         turn.setSelected(true);
753       }
754       else
755       {
756         alphaHelix.setSelected(false);
757         betaStrand.setSelected(false);
758         turn.setSelected(false);
759       }
760       aColChooser.setCurrentStructureFilterPanel(this);
761       aColChooser.updateView();
762     }
763
764     public void updateSelectAllState()
765     {
766       if (alphaHelix.isSelected() && betaStrand.isSelected()
767               && turn.isSelected())
768       {
769         all.setSelected(true);
770       }
771       else
772       {
773         all.setSelected(false);
774       }
775     }
776
777     public void syncState()
778     {
779       StructureFilterPanel sfp = aColChooser
780               .getCurrentStructureFilterPanel();
781       if (sfp != null)
782       {
783         alphaHelix.setSelected(sfp.alphaHelix.isSelected());
784         betaStrand.setSelected(sfp.betaStrand.isSelected());
785         turn.setSelected(sfp.turn.isSelected());
786         if (sfp.all.isSelected())
787         {
788           all.setSelected(true);
789           alphaHelix.setSelected(true);
790           betaStrand.setSelected(true);
791           turn.setSelected(true);
792         }
793       }
794
795     }
796   }
797
798   public class SearchPanel extends JPanel
799   {
800     private AnnotationColumnChooser aColChooser;
801
802     private JCheckBox displayName = new JCheckBox();
803
804     private JCheckBox description = new JCheckBox();
805
806     private JTextField searchBox = new JTextField(10);
807
808     public SearchPanel(AnnotationColumnChooser aColChooser)
809     {
810
811       this.aColChooser = aColChooser;
812       JvSwingUtils.jvInitComponent(this);
813       this.setBorder(new TitledBorder(MessageManager
814               .getString("label.search_filter")));
815
816       JvSwingUtils.jvInitComponent(searchBox);
817       searchBox.setToolTipText(MessageManager
818               .getString("info.enter_search_text_here"));
819       searchBox.getDocument().addDocumentListener(new DocumentListener()
820       {
821         @Override
822         public void insertUpdate(DocumentEvent e)
823         {
824           searchStringAction();
825         }
826
827         @Override
828         public void removeUpdate(DocumentEvent e)
829         {
830           searchStringAction();
831         }
832
833         @Override
834         public void changedUpdate(DocumentEvent e)
835         {
836           searchStringAction();
837         }
838       });
839
840       JvSwingUtils.jvInitComponent(displayName, "label.label");
841       displayName.setEnabled(false);
842       displayName.addActionListener(new ActionListener()
843       {
844         @Override
845         public void actionPerformed(ActionEvent actionEvent)
846         {
847           displayNameCheckboxAction();
848         }
849       });
850
851       JvSwingUtils.jvInitComponent(description, "label.description");
852       description.setEnabled(false);
853       description.addActionListener(new ActionListener()
854       {
855         @Override
856         public void actionPerformed(ActionEvent actionEvent)
857         {
858           discriptionCheckboxAction();
859         }
860       });
861
862       syncState();
863       this.add(searchBox);
864       this.add(displayName);
865       this.add(description);
866     }
867
868     public void displayNameCheckboxAction()
869     {
870       aColChooser.setCurrentSearchPanel(this);
871       aColChooser.updateView();
872     }
873
874     public void discriptionCheckboxAction()
875     {
876       aColChooser.setCurrentSearchPanel(this);
877       aColChooser.updateView();
878     }
879
880     public void searchStringAction()
881     {
882       aColChooser.setCurrentSearchPanel(this);
883       aColChooser.updateView();
884       updateSearchPanelToolTips();
885     }
886
887     public void syncState()
888     {
889       SearchPanel sp = aColChooser.getCurrentSearchPanel();
890       if (sp != null)
891       {
892         description.setEnabled(sp.description.isEnabled());
893         description.setSelected(sp.description.isSelected());
894
895         displayName.setEnabled(sp.displayName.isEnabled());
896         displayName.setSelected(sp.displayName.isSelected());
897
898         searchBox.setText(sp.searchBox.getText());
899       }
900       updateSearchPanelToolTips();
901     }
902
903     public void updateSearchPanelToolTips()
904     {
905       String defaultTtip = MessageManager
906               .getString("info.enter_search_text_to_enable");
907       String labelTtip = MessageManager.formatMessage(
908               "info.search_in_annotation_label", annotations
909                       .getSelectedItem().toString());
910       String descTtip = MessageManager.formatMessage(
911               "info.search_in_annotation_description", annotations
912                       .getSelectedItem().toString());
913       displayName.setToolTipText(displayName.isEnabled() ? labelTtip
914               : defaultTtip);
915       description.setToolTipText(description.isEnabled() ? descTtip
916               : defaultTtip);
917     }
918   }
919
920 }