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