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