JAL-1847 superpose checkbox in structure chooser
[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, 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, 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     boolean hideCols = getActionOption() == ACTION_OPTION_HIDE;
384     if (hideCols)
385     {
386       av.hideSelectedColumns();
387     }
388     av.sendSelection();
389
390     filterParams = null;
391     av.setAnnotationColumnSelectionState(this);
392     // only update overview and structures if columns were hidden
393     ap.paintAlignment(hideCols, hideCols);
394   }
395
396   public HiddenColumns getOldHiddenColumns()
397   {
398     return oldHiddenColumns;
399   }
400
401   public void setOldHiddenColumns(HiddenColumns currentHiddenColumns)
402   {
403     if (currentHiddenColumns != null)
404     {
405       this.oldHiddenColumns = new HiddenColumns(currentHiddenColumns);
406     }
407   }
408
409   public FurtherActionPanel getCurrentFutherActionPanel()
410   {
411     return currentFurtherActionPanel;
412   }
413
414   public void setCurrentFutherActionPanel(
415           FurtherActionPanel currentFutherActionPanel)
416   {
417     this.currentFurtherActionPanel = currentFutherActionPanel;
418   }
419
420   public SearchPanel getCurrentSearchPanel()
421   {
422     return currentSearchPanel;
423   }
424
425   public void setCurrentSearchPanel(SearchPanel currentSearchPanel)
426   {
427     this.currentSearchPanel = currentSearchPanel;
428   }
429
430   public int getActionOption()
431   {
432     return actionOption;
433   }
434
435   public void setActionOption(int actionOption)
436   {
437     this.actionOption = actionOption;
438   }
439
440   public StructureFilterPanel getCurrentStructureFilterPanel()
441   {
442     return currentStructureFilterPanel;
443   }
444
445   public void setCurrentStructureFilterPanel(
446           StructureFilterPanel currentStructureFilterPanel)
447   {
448     this.currentStructureFilterPanel = currentStructureFilterPanel;
449   }
450
451   public void select_action(ActionEvent actionEvent)
452   {
453     JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
454     if (radioButton.isSelected())
455     {
456       setActionOption(ACTION_OPTION_SELECT);
457       updateView();
458     }
459   }
460
461   public void hide_action(ActionEvent actionEvent)
462   {
463     JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
464     if (radioButton.isSelected())
465     {
466       setActionOption(ACTION_OPTION_HIDE);
467       updateView();
468     }
469   }
470
471   @Override
472   public void itemStateChanged(ItemEvent e)
473   {
474     selectedAnnotationChanged();
475   }
476
477   @Override
478   public void selectedAnnotationChanged()
479   {
480     String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
481     if (av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
482             .getSelectedIndex()]].isQuantitative())
483     {
484       currentView = AnnotationColumnChooser.GRAPH_VIEW;
485     }
486     saveCache();
487     gSearchPanel.syncState();
488     gFurtherActionPanel.syncState();
489     gStructureFilterPanel.syncState();
490
491     ngSearchPanel.syncState();
492     ngFurtherActionPanel.syncState();
493     ngStructureFilterPanel.syncState();
494
495     CardLayout switchableViewsLayout = (CardLayout) switchableViewsPanel
496             .getLayout();
497     switchableViewsLayout.show(switchableViewsPanel, currentView);
498     updateView();
499   }
500
501   public class FurtherActionPanel extends JPanel
502   {
503     private AnnotationColumnChooser aColChooser;
504
505     private JRadioButton hideOption = new JRadioButton();
506
507     private JRadioButton selectOption = new JRadioButton();
508
509     private ButtonGroup optionsGroup = new ButtonGroup();
510
511     public FurtherActionPanel(AnnotationColumnChooser aColChooser)
512     {
513       this.aColChooser = aColChooser;
514       JvSwingUtils.jvInitComponent(selectOption, "action.select");
515       selectOption.addActionListener(new ActionListener()
516       {
517         @Override
518         public void actionPerformed(ActionEvent actionEvent)
519         {
520           selectRadioAction(actionEvent);
521         }
522       });
523
524       JvSwingUtils.jvInitComponent(hideOption, "action.hide");
525       hideOption.addActionListener(new ActionListener()
526       {
527         @Override
528         public void actionPerformed(ActionEvent actionEvent)
529         {
530           hideRadioAction(actionEvent);
531         }
532       });
533
534       optionsGroup.add(selectOption);
535       optionsGroup.add(hideOption);
536       optionsGroup.setSelected(selectOption.getModel(), true);
537
538       JvSwingUtils.jvInitComponent(this);
539       syncState();
540
541       this.add(selectOption);
542       this.add(hideOption);
543     }
544
545     public void selectRadioAction(ActionEvent actionEvent)
546     {
547       aColChooser.setCurrentFutherActionPanel(this);
548       aColChooser.select_action(actionEvent);
549     }
550
551     public void hideRadioAction(ActionEvent actionEvent)
552     {
553       aColChooser.setCurrentFutherActionPanel(this);
554       aColChooser.hide_action(actionEvent);
555     }
556
557     public void syncState()
558     {
559       if (aColChooser
560               .getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
561       {
562         this.optionsGroup.setSelected(this.hideOption.getModel(), true);
563       }
564       else
565       {
566         this.optionsGroup.setSelected(this.selectOption.getModel(), true);
567       }
568     }
569   }
570
571   public class StructureFilterPanel extends JPanel
572   {
573     private AnnotationColumnChooser aColChooser;
574
575     private JCheckBox alphaHelix = new JCheckBox();
576
577     private JCheckBox betaStrand = new JCheckBox();
578
579     private JCheckBox turn = new JCheckBox();
580
581     private JCheckBox all = new JCheckBox();
582
583     public StructureFilterPanel(AnnotationColumnChooser aColChooser)
584     {
585       this.aColChooser = aColChooser;
586
587       JvSwingUtils.jvInitComponent(alphaHelix, "label.alpha_helix");
588       alphaHelix.addActionListener(new ActionListener()
589       {
590         @Override
591         public void actionPerformed(ActionEvent actionEvent)
592         {
593           alphaHelix_actionPerformed();
594         }
595       });
596
597       JvSwingUtils.jvInitComponent(betaStrand, "label.beta_strand");
598       betaStrand.addActionListener(new ActionListener()
599       {
600         @Override
601         public void actionPerformed(ActionEvent actionEvent)
602         {
603           betaStrand_actionPerformed();
604         }
605       });
606
607       JvSwingUtils.jvInitComponent(turn, "label.turn");
608       turn.addActionListener(new ActionListener()
609       {
610         @Override
611         public void actionPerformed(ActionEvent actionEvent)
612         {
613           turn_actionPerformed();
614         }
615       });
616
617       JvSwingUtils.jvInitComponent(all, "label.select_all");
618       all.addActionListener(new ActionListener()
619       {
620         @Override
621         public void actionPerformed(ActionEvent actionEvent)
622         {
623           all_actionPerformed();
624         }
625       });
626
627       this.setBorder(new TitledBorder(
628               MessageManager.getString("label.structures_filter")));
629       JvSwingUtils.jvInitComponent(this);
630
631       this.add(all);
632       this.add(alphaHelix);
633       this.add(betaStrand);
634       this.add(turn);
635     }
636
637     public void alphaHelix_actionPerformed()
638     {
639       updateSelectAllState();
640       aColChooser.setCurrentStructureFilterPanel(this);
641       aColChooser.updateView();
642     }
643
644     public void betaStrand_actionPerformed()
645     {
646       updateSelectAllState();
647       aColChooser.setCurrentStructureFilterPanel(this);
648       aColChooser.updateView();
649     }
650
651     public void turn_actionPerformed()
652     {
653       updateSelectAllState();
654       aColChooser.setCurrentStructureFilterPanel(this);
655       aColChooser.updateView();
656     }
657
658     public void all_actionPerformed()
659     {
660       if (all.isSelected())
661       {
662         alphaHelix.setSelected(true);
663         betaStrand.setSelected(true);
664         turn.setSelected(true);
665       }
666       else
667       {
668         alphaHelix.setSelected(false);
669         betaStrand.setSelected(false);
670         turn.setSelected(false);
671       }
672       aColChooser.setCurrentStructureFilterPanel(this);
673       aColChooser.updateView();
674     }
675
676     public void updateSelectAllState()
677     {
678       if (alphaHelix.isSelected() && betaStrand.isSelected()
679               && turn.isSelected())
680       {
681         all.setSelected(true);
682       }
683       else
684       {
685         all.setSelected(false);
686       }
687     }
688
689     public void syncState()
690     {
691       StructureFilterPanel sfp = aColChooser
692               .getCurrentStructureFilterPanel();
693       if (sfp != null)
694       {
695         alphaHelix.setSelected(sfp.alphaHelix.isSelected());
696         betaStrand.setSelected(sfp.betaStrand.isSelected());
697         turn.setSelected(sfp.turn.isSelected());
698         if (sfp.all.isSelected())
699         {
700           all.setSelected(true);
701           alphaHelix.setSelected(true);
702           betaStrand.setSelected(true);
703           turn.setSelected(true);
704         }
705       }
706
707     }
708   }
709
710   public class SearchPanel extends JPanel
711   {
712     private AnnotationColumnChooser aColChooser;
713
714     private JCheckBox displayName = new JCheckBox();
715
716     private JCheckBox description = new JCheckBox();
717
718     private static final String FILTER_BY_ANN_CACHE_KEY = "CACHE.SELECT_FILTER_BY_ANNOT";
719
720     public JvCacheableInputBox<String> searchBox = new JvCacheableInputBox<>(
721             FILTER_BY_ANN_CACHE_KEY);
722
723     public SearchPanel(AnnotationColumnChooser aColChooser)
724     {
725
726       this.aColChooser = aColChooser;
727       JvSwingUtils.jvInitComponent(this);
728       this.setBorder(new TitledBorder(
729               MessageManager.getString("label.search_filter")));
730
731       searchBox.setPrototypeDisplayValue("XXXXXXXXXXXXXXXXXXXXXXX");
732       searchBox.setToolTipText(
733               MessageManager.getString("info.enter_search_text_here"));
734       searchBox.getEditor().getEditorComponent()
735               .addKeyListener(new java.awt.event.KeyAdapter()
736               {
737                 @Override
738                 public void keyPressed(KeyEvent e)
739                 {
740                   if (e.getKeyCode() == KeyEvent.VK_ENTER)
741                   {
742                     e.consume();
743                     searchStringAction();
744                   }
745                 }
746               });
747
748       JvSwingUtils.jvInitComponent(displayName, "label.label");
749       displayName.addActionListener(new ActionListener()
750       {
751         @Override
752         public void actionPerformed(ActionEvent actionEvent)
753         {
754           displayNameCheckboxAction();
755         }
756       });
757
758       JvSwingUtils.jvInitComponent(description, "label.description");
759       description.addActionListener(new ActionListener()
760       {
761         @Override
762         public void actionPerformed(ActionEvent actionEvent)
763         {
764           discriptionCheckboxAction();
765         }
766       });
767
768       syncState();
769       this.add(searchBox);
770       this.add(displayName);
771       this.add(description);
772     }
773
774     public void displayNameCheckboxAction()
775     {
776       aColChooser.setCurrentSearchPanel(this);
777       aColChooser.updateView();
778     }
779
780     public void discriptionCheckboxAction()
781     {
782       aColChooser.setCurrentSearchPanel(this);
783       aColChooser.updateView();
784     }
785
786     public void searchStringAction()
787     {
788       aColChooser.setCurrentSearchPanel(this);
789       aColChooser.updateView();
790       updateSearchPanelToolTips();
791       searchBox.updateCache();
792     }
793
794     public void syncState()
795     {
796       SearchPanel sp = aColChooser.getCurrentSearchPanel();
797       if (sp != null)
798       {
799         description.setEnabled(sp.description.isEnabled());
800         description.setSelected(sp.description.isSelected());
801
802         displayName.setEnabled(sp.displayName.isEnabled());
803         displayName.setSelected(sp.displayName.isSelected());
804
805         searchBox.setSelectedItem(sp.searchBox.getUserInput());
806       }
807       updateSearchPanelToolTips();
808     }
809
810     public void updateSearchPanelToolTips()
811     {
812       String defaultTtip = MessageManager
813               .getString("info.enter_search_text_to_enable");
814       String labelTtip = MessageManager.formatMessage(
815               "info.search_in_annotation_label",
816               annotations.getSelectedItem().toString());
817       String descTtip = MessageManager.formatMessage(
818               "info.search_in_annotation_description",
819               annotations.getSelectedItem().toString());
820       displayName.setToolTipText(
821               displayName.isEnabled() ? labelTtip : defaultTtip);
822       description.setToolTipText(
823               description.isEnabled() ? descTtip : defaultTtip);
824     }
825   }
826
827   @Override
828   public void ok_actionPerformed()
829   {
830     saveCache();
831     super.ok_actionPerformed();
832   }
833
834   @Override
835   public void cancel_actionPerformed()
836   {
837     saveCache();
838     super.cancel_actionPerformed();
839   }
840
841   private void saveCache()
842   {
843     gSearchPanel.searchBox.persistCache();
844     ngSearchPanel.searchBox.persistCache();
845     gSearchPanel.searchBox.updateCache();
846     ngSearchPanel.searchBox.updateCache();
847   }
848 }