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