fbc93b54e5b02fa7016dbcc3d2395333f27b690d
[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.util.Platform;
29 import jalview.viewmodel.annotationfilter.AnnotationFilterParameter;
30
31 import java.awt.BorderLayout;
32 import java.awt.CardLayout;
33 import java.awt.Color;
34 import java.awt.Dimension;
35 import java.awt.event.ActionEvent;
36 import java.awt.event.ActionListener;
37 import java.awt.event.FocusAdapter;
38 import java.awt.event.FocusEvent;
39 import java.awt.event.ItemEvent;
40 import java.awt.event.ItemListener;
41 import java.awt.event.KeyEvent;
42
43 import javax.swing.ButtonGroup;
44 import javax.swing.JCheckBox;
45 import javax.swing.JComboBox;
46 import javax.swing.JInternalFrame;
47 import javax.swing.JLayeredPane;
48 import javax.swing.JPanel;
49 import javax.swing.JRadioButton;
50 import javax.swing.border.TitledBorder;
51
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   protected static int MIN_HEIGHT = (Platform.isJS() ? 370 : 430);
94
95   public AnnotationColumnChooser(AlignViewport av, final AlignmentPanel ap)
96   {
97     super(av, ap);
98     frame = new JInternalFrame();
99     frame.setContentPane(this);
100     frame.setLayer(JLayeredPane.PALETTE_LAYER);
101     Desktop.addInternalFrame(frame,
102             MessageManager.getString("label.select_by_annotation"), 0,
103             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 = slider.getValue() / 1000f;
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     if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
289     {
290       slider.setEnabled(false);
291       thresholdValue.setEnabled(false);
292       thresholdValue.setText("");
293       percentThreshold.setEnabled(false);
294       // build filter params
295     }
296     else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
297     {
298       if (getCurrentAnnotation().threshold == null)
299       {
300         getCurrentAnnotation().setThreshold(new jalview.datamodel.GraphLine(
301                 (getCurrentAnnotation().graphMax
302                         - getCurrentAnnotation().graphMin) / 2f,
303                 "Threshold", Color.black));
304       }
305
306       adjusting = true;
307       float range = getCurrentAnnotation().graphMax * 1000
308               - getCurrentAnnotation().graphMin * 1000;
309
310       slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
311       slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
312       slider.setValue(
313               (int) (getCurrentAnnotation().threshold.value * 1000));
314
315       setThresholdValueText();
316
317       slider.setMajorTickSpacing((int) (range / 10f));
318       slider.setEnabled(true);
319       thresholdValue.setEnabled(true);
320       adjusting = false;
321
322       // build filter params
323       filterParams.setThresholdType(
324               AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);
325       if (getCurrentAnnotation().isQuantitative())
326       {
327         filterParams
328                 .setThresholdValue(getCurrentAnnotation().threshold.value);
329
330         if (selectedThresholdItem == AnnotationColourGradient.ABOVE_THRESHOLD)
331         {
332           filterParams.setThresholdType(
333                   AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD);
334         }
335         else if (selectedThresholdItem == AnnotationColourGradient.BELOW_THRESHOLD)
336         {
337           filterParams.setThresholdType(
338                   AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD);
339         }
340       }
341     }
342
343     updateThresholdPanelToolTip();
344     if (currentStructureFilterPanel != null)
345     {
346       if (currentStructureFilterPanel.alphaHelix.isSelected())
347       {
348         filterParams.setFilterAlphaHelix(true);
349       }
350       if (currentStructureFilterPanel.betaStrand.isSelected())
351       {
352         filterParams.setFilterBetaSheet(true);
353       }
354       if (currentStructureFilterPanel.turn.isSelected())
355       {
356         filterParams.setFilterTurn(true);
357       }
358     }
359
360     if (currentSearchPanel != null)
361     {
362       if (!currentSearchPanel.searchBox.getUserInput().isEmpty())
363       {
364         filterParams.setRegexString(
365                 currentSearchPanel.searchBox.getUserInput());
366         if (currentSearchPanel.displayName.isSelected())
367         {
368           filterParams.addRegexSearchField(
369                   AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING);
370         }
371         if (currentSearchPanel.description.isSelected())
372         {
373           filterParams.addRegexSearchField(
374                   AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION);
375         }
376       }
377     }
378
379     // show hidden columns here, before changing the column selection in
380     // filterAnnotations, because showing hidden columns has the side effect of
381     // adding them to the selection
382     av.showAllHiddenColumns();
383     av.getColumnSelection().filterAnnotations(
384             getCurrentAnnotation().annotations, filterParams);
385
386     boolean hideCols = getActionOption() == ACTION_OPTION_HIDE;
387     if (hideCols)
388     {
389       av.hideSelectedColumns();
390     }
391     av.sendSelection();
392
393     filterParams = null;
394     av.setAnnotationColumnSelectionState(this);
395     // only update overview and structures if columns were hidden
396     ap.paintAlignment(hideCols, hideCols);
397   }
398
399   public HiddenColumns getOldHiddenColumns()
400   {
401     return oldHiddenColumns;
402   }
403
404   public void setOldHiddenColumns(HiddenColumns currentHiddenColumns)
405   {
406     if (currentHiddenColumns != null)
407     {
408       this.oldHiddenColumns = new HiddenColumns(currentHiddenColumns);
409     }
410   }
411
412   public FurtherActionPanel getCurrentFutherActionPanel()
413   {
414     return currentFurtherActionPanel;
415   }
416
417   public void setCurrentFutherActionPanel(
418           FurtherActionPanel currentFutherActionPanel)
419   {
420     this.currentFurtherActionPanel = currentFutherActionPanel;
421   }
422
423   public SearchPanel getCurrentSearchPanel()
424   {
425     return currentSearchPanel;
426   }
427
428   public void setCurrentSearchPanel(SearchPanel currentSearchPanel)
429   {
430     this.currentSearchPanel = currentSearchPanel;
431   }
432
433   public int getActionOption()
434   {
435     return actionOption;
436   }
437
438   public void setActionOption(int actionOption)
439   {
440     this.actionOption = actionOption;
441   }
442
443   public StructureFilterPanel getCurrentStructureFilterPanel()
444   {
445     return currentStructureFilterPanel;
446   }
447
448   public void setCurrentStructureFilterPanel(
449           StructureFilterPanel currentStructureFilterPanel)
450   {
451     this.currentStructureFilterPanel = currentStructureFilterPanel;
452   }
453
454   public void select_action(ActionEvent actionEvent)
455   {
456     JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
457     if (radioButton.isSelected())
458     {
459       setActionOption(ACTION_OPTION_SELECT);
460       updateView();
461     }
462   }
463
464   public void hide_action(ActionEvent actionEvent)
465   {
466     JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
467     if (radioButton.isSelected())
468     {
469       setActionOption(ACTION_OPTION_HIDE);
470       updateView();
471     }
472   }
473
474   @Override
475   public void itemStateChanged(ItemEvent e)
476   {
477     selectedAnnotationChanged();
478   }
479
480   @Override
481   public void selectedAnnotationChanged()
482   {
483     String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
484     if (av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
485             .getSelectedIndex()]].isQuantitative())
486     {
487       currentView = AnnotationColumnChooser.GRAPH_VIEW;
488     }
489     saveCache();
490     gSearchPanel.syncState();
491     gFurtherActionPanel.syncState();
492     gStructureFilterPanel.syncState();
493
494     ngSearchPanel.syncState();
495     ngFurtherActionPanel.syncState();
496     ngStructureFilterPanel.syncState();
497
498     CardLayout switchableViewsLayout = (CardLayout) switchableViewsPanel
499             .getLayout();
500         switchableViewsLayout.show(switchableViewsPanel, currentView);
501     updateView();
502   }
503
504   public class FurtherActionPanel extends JPanel
505   {
506     private AnnotationColumnChooser aColChooser;
507
508     private JRadioButton hideOption = new JRadioButton();
509
510     private JRadioButton selectOption = new JRadioButton();
511
512     private ButtonGroup optionsGroup = new ButtonGroup();
513
514     public FurtherActionPanel(AnnotationColumnChooser aColChooser)
515     {
516       this.aColChooser = aColChooser;
517       JvSwingUtils.jvInitComponent(selectOption, "action.select");
518       selectOption.addActionListener(new ActionListener()
519       {
520         @Override
521         public void actionPerformed(ActionEvent actionEvent)
522         {
523           selectRadioAction(actionEvent);
524         }
525       });
526
527       JvSwingUtils.jvInitComponent(hideOption, "action.hide");
528       hideOption.addActionListener(new ActionListener()
529       {
530         @Override
531         public void actionPerformed(ActionEvent actionEvent)
532         {
533           hideRadioAction(actionEvent);
534         }
535       });
536
537       optionsGroup.add(selectOption);
538       optionsGroup.add(hideOption);
539       optionsGroup.setSelected(selectOption.getModel(), true);
540
541       JvSwingUtils.jvInitComponent(this);
542       syncState();
543
544       this.add(selectOption);
545       this.add(hideOption);
546     }
547
548     public void selectRadioAction(ActionEvent actionEvent)
549     {
550       aColChooser.setCurrentFutherActionPanel(this);
551       aColChooser.select_action(actionEvent);
552     }
553
554     public void hideRadioAction(ActionEvent actionEvent)
555     {
556       aColChooser.setCurrentFutherActionPanel(this);
557       aColChooser.hide_action(actionEvent);
558     }
559
560     public void syncState()
561     {
562       if (aColChooser
563               .getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
564       {
565         this.optionsGroup.setSelected(this.hideOption.getModel(), true);
566       }
567       else
568       {
569         this.optionsGroup.setSelected(this.selectOption.getModel(), true);
570       }
571     }
572   }
573
574   public class StructureFilterPanel extends JPanel
575   {
576     private AnnotationColumnChooser aColChooser;
577
578     private JCheckBox alphaHelix = new JCheckBox();
579
580     private JCheckBox betaStrand = new JCheckBox();
581
582     private JCheckBox turn = new JCheckBox();
583
584     private JCheckBox all = new JCheckBox();
585
586     public StructureFilterPanel(AnnotationColumnChooser aColChooser)
587     {
588       this.aColChooser = aColChooser;
589
590       JvSwingUtils.jvInitComponent(alphaHelix, "label.alpha_helix");
591       alphaHelix.addActionListener(new ActionListener()
592       {
593         @Override
594         public void actionPerformed(ActionEvent actionEvent)
595         {
596           alphaHelix_actionPerformed();
597         }
598       });
599
600       JvSwingUtils.jvInitComponent(betaStrand, "label.beta_strand");
601       betaStrand.addActionListener(new ActionListener()
602       {
603         @Override
604         public void actionPerformed(ActionEvent actionEvent)
605         {
606           betaStrand_actionPerformed();
607         }
608       });
609
610       JvSwingUtils.jvInitComponent(turn, "label.turn");
611       turn.addActionListener(new ActionListener()
612       {
613         @Override
614         public void actionPerformed(ActionEvent actionEvent)
615         {
616           turn_actionPerformed();
617         }
618       });
619
620       JvSwingUtils.jvInitComponent(all, "label.select_all");
621       all.addActionListener(new ActionListener()
622       {
623         @Override
624         public void actionPerformed(ActionEvent actionEvent)
625         {
626           all_actionPerformed();
627         }
628       });
629
630       this.setBorder(new TitledBorder(
631               MessageManager.getString("label.structures_filter")));
632       JvSwingUtils.jvInitComponent(this);
633
634       this.add(all);
635       this.add(alphaHelix);
636       this.add(betaStrand);
637       this.add(turn);
638     }
639
640     public void alphaHelix_actionPerformed()
641     {
642       updateSelectAllState();
643       aColChooser.setCurrentStructureFilterPanel(this);
644       aColChooser.updateView();
645     }
646
647     public void betaStrand_actionPerformed()
648     {
649       updateSelectAllState();
650       aColChooser.setCurrentStructureFilterPanel(this);
651       aColChooser.updateView();
652     }
653
654     public void turn_actionPerformed()
655     {
656       updateSelectAllState();
657       aColChooser.setCurrentStructureFilterPanel(this);
658       aColChooser.updateView();
659     }
660
661     public void all_actionPerformed()
662     {
663       if (all.isSelected())
664       {
665         alphaHelix.setSelected(true);
666         betaStrand.setSelected(true);
667         turn.setSelected(true);
668       }
669       else
670       {
671         alphaHelix.setSelected(false);
672         betaStrand.setSelected(false);
673         turn.setSelected(false);
674       }
675       aColChooser.setCurrentStructureFilterPanel(this);
676       aColChooser.updateView();
677     }
678
679     public void updateSelectAllState()
680     {
681       if (alphaHelix.isSelected() && betaStrand.isSelected()
682               && turn.isSelected())
683       {
684         all.setSelected(true);
685       }
686       else
687       {
688         all.setSelected(false);
689       }
690     }
691
692     public void syncState()
693     {
694       StructureFilterPanel sfp = aColChooser
695               .getCurrentStructureFilterPanel();
696       if (sfp != null)
697       {
698         alphaHelix.setSelected(sfp.alphaHelix.isSelected());
699         betaStrand.setSelected(sfp.betaStrand.isSelected());
700         turn.setSelected(sfp.turn.isSelected());
701         if (sfp.all.isSelected())
702         {
703           all.setSelected(true);
704           alphaHelix.setSelected(true);
705           betaStrand.setSelected(true);
706           turn.setSelected(true);
707         }
708       }
709
710     }
711   }
712
713   public class SearchPanel extends JPanel
714   {
715     private AnnotationColumnChooser aColChooser;
716
717     private JCheckBox displayName = new JCheckBox();
718
719     private JCheckBox description = new JCheckBox();
720
721     private static final String FILTER_BY_ANN_CACHE_KEY = "CACHE.SELECT_FILTER_BY_ANNOT";
722
723     public JvCacheableInputBox<String> searchBox = new JvCacheableInputBox<>(
724             FILTER_BY_ANN_CACHE_KEY);
725
726     public SearchPanel(AnnotationColumnChooser aColChooser)
727     {
728
729       this.aColChooser = aColChooser;
730       JvSwingUtils.jvInitComponent(this);
731       this.setBorder(new TitledBorder(
732               MessageManager.getString("label.search_filter")));
733
734       searchBox.setPrototypeDisplayValue("XXXXXXXXXXXXXXXXXXXXXXX");
735       searchBox.getComponent().setToolTipText(
736               MessageManager.getString("info.enter_search_text_here"));
737       searchBox.addKeyListener(new java.awt.event.KeyAdapter()
738               {
739                 @Override
740                 public void keyPressed(KeyEvent e)
741                 {
742                   if (e.getKeyCode() == KeyEvent.VK_ENTER)
743                   {
744                     e.consume();
745                     searchStringAction();
746                   }
747                 }
748               });
749       searchBox.addFocusListener(new FocusAdapter()
750       {
751         @Override
752         public void focusLost(FocusEvent e)
753         {
754           searchStringAction();
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           descriptionCheckboxAction();
775         }
776       });
777
778       syncState();
779       this.add(searchBox.getComponent());
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 descriptionCheckboxAction()
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",
826               annotations.getSelectedItem().toString());
827       String descTtip = MessageManager.formatMessage(
828               "info.search_in_annotation_description",
829               annotations.getSelectedItem().toString());
830       displayName.setToolTipText(
831               displayName.isEnabled() ? labelTtip : defaultTtip);
832       description.setToolTipText(
833               description.isEnabled() ? descTtip : 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 }