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