JAL-2349 JAL-3855 experimenting with filtering columns based on mean of contact map...
[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 java.awt.BorderLayout;
25 import java.awt.CardLayout;
26 import java.awt.Color;
27 import java.awt.Dimension;
28 import java.awt.event.ActionEvent;
29 import java.awt.event.ActionListener;
30 import java.awt.event.FocusAdapter;
31 import java.awt.event.FocusEvent;
32 import java.awt.event.ItemEvent;
33 import java.awt.event.ItemListener;
34 import java.awt.event.KeyEvent;
35
36 import javax.swing.ButtonGroup;
37 import javax.swing.JCheckBox;
38 import javax.swing.JComboBox;
39 import javax.swing.JInternalFrame;
40 import javax.swing.JLayeredPane;
41 import javax.swing.JPanel;
42 import javax.swing.JRadioButton;
43 import javax.swing.border.TitledBorder;
44
45 import jalview.datamodel.AlignmentAnnotation;
46 import jalview.datamodel.HiddenColumns;
47 import jalview.io.cache.JvCacheableInputBox;
48 import jalview.schemes.AnnotationColourGradient;
49 import jalview.util.MessageManager;
50 import jalview.util.Platform;
51 import jalview.viewmodel.annotationfilter.AnnotationFilterParameter;
52 import net.miginfocom.swing.MigLayout;
53
54 @SuppressWarnings("serial")
55 public class AnnotationColumnChooser extends AnnotationRowFilter
56         implements ItemListener
57 {
58   private JPanel switchableViewsPanel = new JPanel(new CardLayout());
59
60   private JPanel annotationComboBoxPanel = new JPanel();
61
62   private StructureFilterPanel gStructureFilterPanel;
63
64   private StructureFilterPanel ngStructureFilterPanel;
65
66   private StructureFilterPanel currentStructureFilterPanel;
67
68   private SearchPanel currentSearchPanel;
69
70   private SearchPanel gSearchPanel;
71
72   private SearchPanel ngSearchPanel;
73
74   private FurtherActionPanel currentFurtherActionPanel;
75
76   private FurtherActionPanel gFurtherActionPanel;
77
78   private FurtherActionPanel ngFurtherActionPanel;
79
80   public static final int ACTION_OPTION_SELECT = 1;
81
82   public static int ACTION_OPTION_HIDE = 2;
83
84   public static String NO_GRAPH_VIEW = "0";
85
86   public static String GRAPH_VIEW = "1";
87
88   private int actionOption = ACTION_OPTION_SELECT;
89
90   private HiddenColumns oldHiddenColumns;
91
92   protected static int MIN_WIDTH = (Platform.isJS() ? 370 : 420);
93
94   protected static int MIN_HEIGHT = (Platform.isJS() ? 370 : 430);
95
96   public AnnotationColumnChooser(AlignViewport av, final AlignmentPanel ap)
97   {
98     super(av, ap);
99     frame = new JInternalFrame();
100     frame.setContentPane(this);
101     frame.setLayer(JLayeredPane.PALETTE_LAYER);
102     Desktop.addInternalFrame(frame,
103             MessageManager.getString("label.select_by_annotation"), 0, 0);
104     // BH note: MIGLayout ignores this completely,
105     // possibly creating a frame smaller than specified:
106     frame.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT));
107
108     addSliderChangeListener();
109     addSliderMouseListeners();
110
111     if (av.getAlignment().getAlignmentAnnotation() == null)
112     {
113       return;
114     }
115     setOldHiddenColumns(av.getAlignment().getHiddenColumns());
116     adjusting = true;
117
118     setAnnotations(new JComboBox<>(getAnnotationItems(false)));
119     populateThresholdComboBox(threshold);
120     AnnotationColumnChooser lastChooser = av
121             .getAnnotationColumnSelectionState();
122     // restore Object state from the previous session if one exists
123     if (lastChooser != null)
124     {
125       currentSearchPanel = lastChooser.getCurrentSearchPanel();
126       currentStructureFilterPanel = lastChooser
127               .getCurrentStructureFilterPanel();
128       annotations.setSelectedIndex(
129               lastChooser.getAnnotations().getSelectedIndex());
130       threshold.setSelectedIndex(
131               lastChooser.getThreshold().getSelectedIndex());
132       actionOption = lastChooser.getActionOption();
133       percentThreshold
134               .setSelected(lastChooser.percentThreshold.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(
157             MessageManager.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     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.getAnnotationColumnSelectionState()
245                 .getOldHiddenColumns();
246         av.getAlignment().setHiddenColumns(oldHidden);
247       }
248       av.sendSelection();
249       ap.paintAlignment(true, true);
250     }
251   }
252
253   @Override
254   public void valueChanged(boolean updateAllAnnotation)
255   {
256     if (slider.isEnabled())
257     {
258       getCurrentAnnotation().threshold.value = getSliderValue();
259       updateView();
260       propagateSeqAssociatedThreshold(updateAllAnnotation,
261               getCurrentAnnotation());
262       ap.paintAlignment(false, false);
263     }
264   }
265
266   @Override
267   public void updateView()
268   {
269     // Check if combobox is still adjusting
270     if (adjusting)
271     {
272       return;
273     }
274
275     AnnotationFilterParameter filterParams = new AnnotationFilterParameter();
276
277     setCurrentAnnotation(av.getAlignment()
278             .getAlignmentAnnotation()[annmap[getAnnotations()
279                     .getSelectedIndex()]]);
280
281     int selectedThresholdItem = getSelectedThresholdItem(
282             getThreshold().getSelectedIndex());
283
284     slider.setEnabled(true);
285     thresholdValue.setEnabled(true);
286     percentThreshold.setEnabled(true);
287
288     final AlignmentAnnotation currentAnnotation = getCurrentAnnotation();
289     if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
290     {
291       slider.setEnabled(false);
292       thresholdValue.setEnabled(false);
293       thresholdValue.setText("");
294       percentThreshold.setEnabled(false);
295       // build filter params
296     }
297     else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
298     {
299       if (currentAnnotation.threshold == null)
300       {
301         currentAnnotation.setThreshold(new jalview.datamodel.GraphLine(
302                 (currentAnnotation.graphMax - currentAnnotation.graphMin)
303                         / 2f,
304                 "Threshold", Color.black));
305       }
306
307       adjusting = true;
308
309       setSliderModel(currentAnnotation.graphMin, currentAnnotation.graphMax,
310               currentAnnotation.threshold.value);
311
312       setThresholdValueText();
313
314       slider.setEnabled(true);
315       thresholdValue.setEnabled(true);
316       adjusting = false;
317
318       // build filter params
319       filterParams.setThresholdType(
320               AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);
321       if (currentAnnotation.isQuantitative())
322       {
323         filterParams.setThresholdValue(currentAnnotation.threshold.value);
324
325         if (selectedThresholdItem == AnnotationColourGradient.ABOVE_THRESHOLD)
326         {
327           filterParams.setThresholdType(
328                   AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD);
329         }
330         else if (selectedThresholdItem == AnnotationColourGradient.BELOW_THRESHOLD)
331         {
332           filterParams.setThresholdType(
333                   AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD);
334         }
335       }
336     }
337
338     updateThresholdPanelToolTip();
339     if (currentStructureFilterPanel != null)
340     {
341       if (currentStructureFilterPanel.alphaHelix.isSelected())
342       {
343         filterParams.setFilterAlphaHelix(true);
344       }
345       if (currentStructureFilterPanel.betaStrand.isSelected())
346       {
347         filterParams.setFilterBetaSheet(true);
348       }
349       if (currentStructureFilterPanel.turn.isSelected())
350       {
351         filterParams.setFilterTurn(true);
352       }
353     }
354
355     if (currentSearchPanel != null)
356     {
357       if (!currentSearchPanel.searchBox.getUserInput().isEmpty())
358       {
359         filterParams.setRegexString(
360                 currentSearchPanel.searchBox.getUserInput());
361         if (currentSearchPanel.displayName.isSelected())
362         {
363           filterParams.addRegexSearchField(
364                   AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING);
365         }
366         if (currentSearchPanel.description.isSelected())
367         {
368           filterParams.addRegexSearchField(
369                   AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION);
370         }
371       }
372     }
373
374     // show hidden columns here, before changing the column selection in
375     // filterAnnotations, because showing hidden columns has the side effect of
376     // adding them to the selection
377     av.showAllHiddenColumns();
378     av.getColumnSelection().filterAnnotations(currentAnnotation,
379             filterParams);
380
381     boolean hideCols = getActionOption() == ACTION_OPTION_HIDE;
382     if (hideCols)
383     {
384       av.hideSelectedColumns();
385     }
386     av.sendSelection();
387
388     filterParams = null;
389     av.setAnnotationColumnSelectionState(this);
390     // only update overview and structures if columns were hidden
391     ap.paintAlignment(hideCols, hideCols);
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, 23);
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.getComponent().setToolTipText(
730               MessageManager.getString("info.enter_search_text_here"));
731       searchBox.addKeyListener(new java.awt.event.KeyAdapter()
732       {
733         @Override
734         public void keyPressed(KeyEvent e)
735         {
736           if (e.getKeyCode() == KeyEvent.VK_ENTER)
737           {
738             e.consume();
739             searchStringAction();
740           }
741         }
742       });
743       searchBox.addFocusListener(new FocusAdapter()
744       {
745         @Override
746         public void focusLost(FocusEvent e)
747         {
748           searchStringAction();
749         }
750       });
751
752       JvSwingUtils.jvInitComponent(displayName, "label.label");
753       displayName.addActionListener(new ActionListener()
754       {
755         @Override
756         public void actionPerformed(ActionEvent actionEvent)
757         {
758           displayNameCheckboxAction();
759         }
760       });
761
762       JvSwingUtils.jvInitComponent(description, "label.description");
763       description.addActionListener(new ActionListener()
764       {
765         @Override
766         public void actionPerformed(ActionEvent actionEvent)
767         {
768           descriptionCheckboxAction();
769         }
770       });
771
772       syncState();
773       this.add(searchBox.getComponent());
774       this.add(displayName);
775       this.add(description);
776     }
777
778     public void displayNameCheckboxAction()
779     {
780       aColChooser.setCurrentSearchPanel(this);
781       aColChooser.updateView();
782     }
783
784     public void descriptionCheckboxAction()
785     {
786       aColChooser.setCurrentSearchPanel(this);
787       aColChooser.updateView();
788     }
789
790     public void searchStringAction()
791     {
792       aColChooser.setCurrentSearchPanel(this);
793       aColChooser.updateView();
794       updateSearchPanelToolTips();
795       searchBox.updateCache();
796     }
797
798     public void syncState()
799     {
800       SearchPanel sp = aColChooser.getCurrentSearchPanel();
801       if (sp != null)
802       {
803         description.setEnabled(sp.description.isEnabled());
804         description.setSelected(sp.description.isSelected());
805
806         displayName.setEnabled(sp.displayName.isEnabled());
807         displayName.setSelected(sp.displayName.isSelected());
808
809         searchBox.setSelectedItem(sp.searchBox.getUserInput());
810       }
811       updateSearchPanelToolTips();
812     }
813
814     public void updateSearchPanelToolTips()
815     {
816       String defaultTtip = MessageManager
817               .getString("info.enter_search_text_to_enable");
818       String labelTtip = MessageManager.formatMessage(
819               "info.search_in_annotation_label",
820               annotations.getSelectedItem().toString());
821       String descTtip = MessageManager.formatMessage(
822               "info.search_in_annotation_description",
823               annotations.getSelectedItem().toString());
824       displayName.setToolTipText(
825               displayName.isEnabled() ? labelTtip : defaultTtip);
826       description.setToolTipText(
827               description.isEnabled() ? descTtip : defaultTtip);
828     }
829   }
830
831   @Override
832   public void ok_actionPerformed()
833   {
834     saveCache();
835     super.ok_actionPerformed();
836   }
837
838   @Override
839   public void cancel_actionPerformed()
840   {
841     saveCache();
842     super.cancel_actionPerformed();
843   }
844
845   private void saveCache()
846   {
847     gSearchPanel.searchBox.persistCache();
848     ngSearchPanel.searchBox.persistCache();
849     gSearchPanel.searchBox.updateCache();
850     ngSearchPanel.searchBox.updateCache();
851   }
852 }