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