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