JAL-2432 percentage checkbox follows threshold value field
[jalview.git] / src / jalview / appletgui / 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 package jalview.appletgui;
22
23 import jalview.datamodel.AlignmentAnnotation;
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.Checkbox;
32 import java.awt.Choice;
33 import java.awt.Color;
34 import java.awt.Dimension;
35 import java.awt.Frame;
36 import java.awt.Panel;
37 import java.awt.TextField;
38 import java.awt.event.ActionEvent;
39 import java.awt.event.ActionListener;
40 import java.awt.event.AdjustmentEvent;
41 import java.awt.event.AdjustmentListener;
42 import java.awt.event.ItemEvent;
43 import java.awt.event.ItemListener;
44 import java.awt.event.MouseAdapter;
45 import java.awt.event.MouseEvent;
46 import java.awt.event.MouseListener;
47 import java.awt.event.TextEvent;
48 import java.awt.event.TextListener;
49 import java.util.Iterator;
50 import java.util.Vector;
51
52 //import javax.swing.JPanel;
53
54 //import net.miginfocom.swing.MigLayout;
55
56 public class AnnotationColumnChooser extends AnnotationRowFilter implements
57         ActionListener, AdjustmentListener, ItemListener, MouseListener
58 {
59
60   private Choice annotations = new Choice();
61
62   private Panel actionPanel = new Panel();
63
64   private TitledPanel thresholdPanel = new TitledPanel();
65
66   private Panel switchableViewsPanel = new Panel(new CardLayout());
67
68   private CardLayout switchableViewsLayout = (CardLayout) (switchableViewsPanel
69           .getLayout());
70
71   private Panel noGraphFilterView = new Panel();
72
73   private Panel graphFilterView = new Panel();
74
75   private Panel annotationComboBoxPanel = new Panel();
76
77   private BorderLayout borderLayout1 = new BorderLayout();
78
79   private BorderLayout gBorderLayout = new BorderLayout();
80
81   private BorderLayout ngBorderLayout = new BorderLayout();
82
83   private Choice threshold = new Choice();
84
85   private StructureFilterPanel gStructureFilterPanel;
86
87   private StructureFilterPanel ngStructureFilterPanel;
88
89   private StructureFilterPanel currentStructureFilterPanel;
90
91   private SearchPanel currentSearchPanel;
92
93   private SearchPanel gSearchPanel;
94
95   private SearchPanel ngSearchPanel;
96
97   private FurtherActionPanel currentFurtherActionPanel;
98
99   private FurtherActionPanel gFurtherActionPanel;
100
101   private FurtherActionPanel ngFurtherActionPanel;
102
103   public static final int ACTION_OPTION_SELECT = 1;
104
105   public static int ACTION_OPTION_HIDE = 2;
106
107   public static String NO_GRAPH_VIEW = "0";
108
109   public static String GRAPH_VIEW = "1";
110
111   private int actionOption = ACTION_OPTION_SELECT;
112
113   private ColumnSelection oldColumnSelection;
114
115   public AnnotationColumnChooser()
116   {
117     try
118     {
119       jbInit();
120     } catch (Exception ex)
121     {
122       ex.printStackTrace();
123     }
124   }
125
126   public AnnotationColumnChooser(AlignViewport av, final AlignmentPanel ap)
127   {
128     super(av, ap);
129     frame = new Frame();
130     frame.add(this);
131     jalview.bin.JalviewLite.addFrame(frame,
132             MessageManager.getString("label.select_by_annotation"), 520,
133             215);
134
135     slider.addAdjustmentListener(this);
136     slider.addMouseListener(this);
137
138     AlignmentAnnotation[] anns = av.getAlignment().getAlignmentAnnotation();
139     if (anns == null)
140     {
141       return;
142     }
143     setOldColumnSelection(av.getColumnSelection());
144     adjusting = true;
145     Vector<String> list = new Vector<String>();
146     int index = 1;
147     for (int i = 0; i < anns.length; i++)
148     {
149       String label = anns[i].label;
150       if (anns[i].sequenceRef != null)
151       {
152         label = label + "_" + anns[i].sequenceRef.getName();
153       }
154       if (!list.contains(label))
155       {
156         list.addElement(label);
157       }
158       else
159       {
160         list.addElement(label + "_" + (index++));
161       }
162     }
163
164     for (int i = 0; i < list.size(); i++)
165     {
166       annotations.addItem(list.elementAt(i).toString());
167     }
168
169     populateThresholdComboBox(threshold);
170     AnnotationColumnChooser lastChooser = av
171             .getAnnotationColumnSelectionState();
172     // restore Object state from the previous session if one exists
173     if (lastChooser != null)
174     {
175       currentSearchPanel = lastChooser
176               .getCurrentSearchPanel();
177       currentStructureFilterPanel = lastChooser
178               .getCurrentStructureFilterPanel();
179       annotations.select(lastChooser
180               .getAnnotations().getSelectedIndex());
181       threshold.select(lastChooser
182               .getThreshold().getSelectedIndex());
183       actionOption = lastChooser
184               .getActionOption();
185       percentThreshold.setState(lastChooser.percentThreshold.getState());
186     }
187
188     try
189     {
190       jbInit();
191     } catch (Exception ex)
192     {
193     }
194     adjusting = false;
195
196     updateView();
197     frame.invalidate();
198     frame.pack();
199   }
200
201   private void jbInit() throws Exception
202   {
203     ok.setLabel(MessageManager.getString("action.ok"));
204
205     cancel.setLabel(MessageManager.getString("action.cancel"));
206
207     thresholdValue.setEnabled(false);
208     thresholdValue.setColumns(7);
209     thresholdValue.setCaretPosition(0);
210
211     ok.addActionListener(this);
212     cancel.addActionListener(this);
213     annotations.addItemListener(this);
214     thresholdValue.addActionListener(this);
215     threshold.addItemListener(this);
216
217     slider.setBackground(Color.white);
218     slider.setEnabled(false);
219     slider.setPreferredSize(new Dimension(100, 32));
220
221     thresholdPanel.setBackground(Color.white);
222     // thresholdPanel.setFont(JvSwingUtils.getLabelFont());
223     // thresholdPanel.setLayout(new MigLayout("", "[left][right]", "[][]"));
224
225     percentThreshold.setLabel("As percentage");
226     percentThreshold.addItemListener(this);
227
228     actionPanel.setBackground(Color.white);
229     // actionPanel.setFont(JvSwingUtils.getLabelFont());
230
231     graphFilterView.setLayout(gBorderLayout);
232     graphFilterView.setBackground(Color.white);
233
234     noGraphFilterView.setLayout(ngBorderLayout);
235     noGraphFilterView.setBackground(Color.white);
236
237     annotationComboBoxPanel.setBackground(Color.white);
238     // annotationComboBoxPanel.setFont(JvSwingUtils.getLabelFont());
239
240     gSearchPanel = new SearchPanel(this);
241     ngSearchPanel = new SearchPanel(this);
242     gFurtherActionPanel = new FurtherActionPanel(this);
243     ngFurtherActionPanel = new FurtherActionPanel(this);
244     gStructureFilterPanel = new StructureFilterPanel(this);
245     ngStructureFilterPanel = new StructureFilterPanel(this);
246
247     thresholdPanel.setTitle("Threshold Filter");
248     thresholdPanel.add(getThreshold());
249     thresholdPanel.add(slider);
250     thresholdPanel.add(thresholdValue);
251     thresholdPanel.add(percentThreshold);
252
253     actionPanel.add(ok);
254     actionPanel.add(cancel);
255
256     Panel staticPanel = new Panel();
257     staticPanel.setLayout(new BorderLayout());
258     staticPanel.setBackground(Color.white);
259
260     staticPanel.add(gSearchPanel, java.awt.BorderLayout.NORTH);
261     staticPanel.add(gStructureFilterPanel, java.awt.BorderLayout.SOUTH);
262
263     graphFilterView.add(staticPanel, java.awt.BorderLayout.NORTH);
264     graphFilterView.add(thresholdPanel, java.awt.BorderLayout.CENTER);
265     graphFilterView.add(gFurtherActionPanel, java.awt.BorderLayout.SOUTH);
266
267     noGraphFilterView.add(ngSearchPanel, java.awt.BorderLayout.PAGE_START);
268     noGraphFilterView.add(ngStructureFilterPanel,
269             java.awt.BorderLayout.CENTER);
270     noGraphFilterView.add(ngFurtherActionPanel,
271             java.awt.BorderLayout.CENTER);
272
273     annotationComboBoxPanel.add(getAnnotations());
274     switchableViewsPanel.add(noGraphFilterView,
275             AnnotationColumnChooser.NO_GRAPH_VIEW);
276     switchableViewsPanel.add(graphFilterView,
277             AnnotationColumnChooser.GRAPH_VIEW);
278
279     this.setLayout(borderLayout1);
280     this.add(annotationComboBoxPanel, java.awt.BorderLayout.PAGE_START);
281     this.add(switchableViewsPanel, java.awt.BorderLayout.CENTER);
282     this.add(actionPanel, java.awt.BorderLayout.SOUTH);
283
284     selectedAnnotationChanged();
285     this.validate();
286   }
287
288   @Override
289   @SuppressWarnings("unchecked")
290   public void reset()
291   {
292     if (this.getOldColumnSelection() != null)
293     {
294       av.getColumnSelection().clear();
295
296       if (av.getAnnotationColumnSelectionState() != null)
297       {
298         ColumnSelection oldSelection = av
299                 .getAnnotationColumnSelectionState()
300                 .getOldColumnSelection();
301         if (oldSelection != null && oldSelection.getHiddenColumns() != null
302                 && !oldSelection.getHiddenColumns().isEmpty())
303         {
304           for (Iterator<int[]> itr = oldSelection.getHiddenColumns()
305                   .iterator(); itr.hasNext();)
306           {
307             int positions[] = itr.next();
308             av.hideColumns(positions[0], positions[1]);
309           }
310         }
311         av.setColumnSelection(oldSelection);
312       }
313       ap.paintAlignment(true);
314     }
315
316   }
317
318   @Override
319   public void adjustmentValueChanged(AdjustmentEvent evt)
320   {
321     if (!adjusting)
322     {
323       thresholdValue.setText((slider.getValue() / 1000f) + "");
324       valueChanged(!sliderDragging);
325     }
326   }
327
328   protected void addSliderMouseListeners()
329   {
330
331     slider.addMouseListener(new MouseAdapter()
332     {
333       @Override
334       public void mousePressed(MouseEvent e)
335       {
336         sliderDragging = true;
337         super.mousePressed(e);
338       }
339
340       @Override
341       public void mouseDragged(MouseEvent e)
342       {
343         sliderDragging = true;
344         super.mouseDragged(e);
345       }
346
347       @Override
348       public void mouseReleased(MouseEvent evt)
349       {
350         if (sliderDragging)
351         {
352           sliderDragging = false;
353           valueChanged(true);
354         }
355         ap.paintAlignment(true);
356       }
357     });
358   }
359
360   @Override
361   public void valueChanged(boolean updateAllAnnotation)
362   {
363     if (slider.isEnabled())
364     {
365       getCurrentAnnotation().threshold.value = slider.getValue() / 1000f;
366       updateView();
367       ap.paintAlignment(false);
368     }
369   }
370
371   public Choice getThreshold()
372   {
373     return threshold;
374   }
375
376   public void setThreshold(Choice threshold)
377   {
378     this.threshold = threshold;
379   }
380
381   public Choice getAnnotations()
382   {
383     return annotations;
384   }
385
386   public void setAnnotations(Choice annotations)
387   {
388     this.annotations = annotations;
389   }
390
391   @Override
392   public void updateView()
393   {
394     // Check if combobox is still adjusting
395     if (adjusting)
396     {
397       return;
398     }
399
400     AnnotationFilterParameter filterParams = new AnnotationFilterParameter();
401     setCurrentAnnotation(av.getAlignment().getAlignmentAnnotation()[getAnnotations()
402             .getSelectedIndex()]);
403
404     int selectedThresholdItem = getSelectedThresholdItem(getThreshold()
405             .getSelectedIndex());
406
407     slider.setEnabled(true);
408     thresholdValue.setEnabled(true);
409
410     if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
411     {
412       slider.setEnabled(false);
413       thresholdValue.setEnabled(false);
414       thresholdValue.setText("");
415       // build filter params
416     }
417     else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
418     {
419       if (getCurrentAnnotation().threshold == null)
420       {
421         getCurrentAnnotation()
422                 .setThreshold(
423                         new jalview.datamodel.GraphLine(
424                                 (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin) / 2f,
425                                 "Threshold", Color.black));
426       }
427
428       adjusting = true;
429       float range = getCurrentAnnotation().graphMax * 1000
430               - getCurrentAnnotation().graphMin * 1000;
431
432       slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
433       slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
434       slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000));
435       setThresholdValueText();
436       // slider.setMajorTickSpacing((int) (range / 10f));
437       slider.setEnabled(true);
438       thresholdValue.setEnabled(true);
439       adjusting = false;
440
441       // build filter params
442       filterParams
443               .setThresholdType(AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);
444       if (getCurrentAnnotation().graph != AlignmentAnnotation.NO_GRAPH)
445       {
446         filterParams
447                 .setThresholdValue(getCurrentAnnotation().threshold.value);
448
449         if (selectedThresholdItem == AnnotationColourGradient.ABOVE_THRESHOLD)
450         {
451           filterParams
452                   .setThresholdType(AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD);
453         }
454         else if (selectedThresholdItem == AnnotationColourGradient.BELOW_THRESHOLD)
455         {
456           filterParams
457                   .setThresholdType(AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD);
458         }
459       }
460     }
461
462     if (currentStructureFilterPanel != null)
463     {
464       if (currentStructureFilterPanel.alphaHelix.getState())
465       {
466         filterParams.setFilterAlphaHelix(true);
467       }
468       if (currentStructureFilterPanel.betaStrand.getState())
469       {
470         filterParams.setFilterBetaSheet(true);
471       }
472       if (currentStructureFilterPanel.turn.getState())
473       {
474         filterParams.setFilterTurn(true);
475       }
476     }
477
478     if (currentSearchPanel != null)
479     {
480
481       if (!currentSearchPanel.searchBox.getText().isEmpty())
482       {
483         currentSearchPanel.description.setEnabled(true);
484         currentSearchPanel.displayName.setEnabled(true);
485         filterParams.setRegexString(currentSearchPanel.searchBox.getText());
486         if (currentSearchPanel.displayName.getState())
487         {
488           filterParams
489                   .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING);
490         }
491         if (currentSearchPanel.description.getState())
492         {
493           filterParams
494                   .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION);
495         }
496       }
497       else
498       {
499         currentSearchPanel.description.setEnabled(false);
500         currentSearchPanel.displayName.setEnabled(false);
501       }
502     }
503
504     av.getColumnSelection().filterAnnotations(
505             getCurrentAnnotation().annotations, filterParams);
506
507     av.showAllHiddenColumns();
508     if (getActionOption() == ACTION_OPTION_HIDE)
509     {
510       av.hideSelectedColumns();
511     }
512
513     filterParams = null;
514     av.setAnnotationColumnSelectionState(this);
515     ap.paintAlignment(true);
516   }
517
518   public ColumnSelection getOldColumnSelection()
519   {
520     return oldColumnSelection;
521   }
522
523   public void setOldColumnSelection(ColumnSelection currentColumnSelection)
524   {
525     if (currentColumnSelection != null)
526     {
527       this.oldColumnSelection = new ColumnSelection(currentColumnSelection);
528     }
529   }
530
531   public FurtherActionPanel getCurrentFutherActionPanel()
532   {
533     return currentFurtherActionPanel;
534   }
535
536   public void setCurrentFutherActionPanel(
537           FurtherActionPanel currentFutherActionPanel)
538   {
539     this.currentFurtherActionPanel = currentFutherActionPanel;
540   }
541
542   public SearchPanel getCurrentSearchPanel()
543   {
544     return currentSearchPanel;
545   }
546
547   public void setCurrentSearchPanel(SearchPanel currentSearchPanel)
548   {
549     this.currentSearchPanel = currentSearchPanel;
550   }
551
552   public int getActionOption()
553   {
554     return actionOption;
555   }
556
557   public void setActionOption(int actionOption)
558   {
559     this.actionOption = actionOption;
560   }
561
562   public StructureFilterPanel getCurrentStructureFilterPanel()
563   {
564     return currentStructureFilterPanel;
565   }
566
567   public void setCurrentStructureFilterPanel(
568           StructureFilterPanel currentStructureFilterPanel)
569   {
570     this.currentStructureFilterPanel = currentStructureFilterPanel;
571   }
572
573   @Override
574   public void itemStateChanged(ItemEvent e)
575   {
576     if (e.getSource() == annotations)
577     {
578       selectedAnnotationChanged();
579     }
580     else if (e.getSource() == threshold)
581     {
582       threshold_actionPerformed(null);
583     }
584     else if (e.getSource() == percentThreshold)
585     {
586       if (!adjusting)
587       {
588         percentageValue_actionPerformed();
589       }
590
591     }
592   }
593
594   public void selectedAnnotationChanged()
595   {
596     String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
597     if (av.getAlignment().getAlignmentAnnotation()[getAnnotations()
598             .getSelectedIndex()].graph != AlignmentAnnotation.NO_GRAPH)
599     {
600       currentView = AnnotationColumnChooser.GRAPH_VIEW;
601     }
602
603     gSearchPanel.syncState();
604     gFurtherActionPanel.syncState();
605     gStructureFilterPanel.syncState();
606
607     ngSearchPanel.syncState();
608     ngFurtherActionPanel.syncState();
609     ngStructureFilterPanel.syncState();
610
611     switchableViewsLayout.show(switchableViewsPanel, currentView);
612     updateView();
613   }
614
615   public class FurtherActionPanel extends Panel implements ItemListener
616   {
617     private AnnotationColumnChooser aColChooser;
618
619     private Choice furtherAction = new Choice();
620
621     public FurtherActionPanel(AnnotationColumnChooser aColChooser)
622     {
623       this.aColChooser = aColChooser;
624       furtherAction.addItem("Select");
625       furtherAction.addItem("Hide");
626       furtherAction.addItemListener(this);
627       syncState();
628
629       // this.setTitle("Filter Actions");
630       // this.setFont(JvSwingUtils.getLabelFont());
631
632       this.add(furtherAction);
633     }
634
635     public void syncState()
636     {
637       if (aColChooser.getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
638       {
639         furtherAction.select("Hide");
640       }
641       else
642       {
643         furtherAction.select("Select");
644       }
645     }
646
647     @Override
648     public void itemStateChanged(ItemEvent e)
649     {
650       aColChooser.setCurrentFutherActionPanel(this);
651       if (furtherAction.getSelectedItem().equalsIgnoreCase("Select"))
652       {
653         setActionOption(ACTION_OPTION_SELECT);
654         updateView();
655       }
656       else
657       {
658         setActionOption(ACTION_OPTION_HIDE);
659         updateView();
660       }
661
662     }
663   }
664
665   public class StructureFilterPanel extends TitledPanel implements
666           ItemListener
667   {
668     private AnnotationColumnChooser aColChooser;
669
670     private Checkbox alphaHelix = new Checkbox();
671
672     private Checkbox betaStrand = new Checkbox();
673
674     private Checkbox turn = new Checkbox();
675
676     private Checkbox all = new Checkbox();
677
678     public StructureFilterPanel(AnnotationColumnChooser aColChooser)
679     {
680       this.aColChooser = aColChooser;
681
682       alphaHelix.setLabel(MessageManager.getString("label.alpha_helix"));
683       alphaHelix.setBackground(Color.white);
684
685       alphaHelix.addItemListener(this);
686
687       betaStrand.setLabel(MessageManager.getString("label.beta_strand"));
688       betaStrand.setBackground(Color.white);
689       betaStrand.addItemListener(this);
690
691       turn.setLabel(MessageManager.getString("label.turn"));
692       turn.setBackground(Color.white);
693       turn.addItemListener(this);
694
695       all.setLabel(MessageManager.getString("label.select_all"));
696       all.setBackground(Color.white);
697       all.addItemListener(this);
698
699       this.setBackground(Color.white);
700       this.setTitle("Structure Filter");
701       // this.setFont(JvSwingUtils.getLabelFont());
702
703       this.add(all);
704       this.add(alphaHelix);
705       this.add(betaStrand);
706       this.add(turn);
707     }
708
709     public void alphaHelix_actionPerformed()
710     {
711       updateSelectAllState();
712       aColChooser.setCurrentStructureFilterPanel(this);
713       aColChooser.updateView();
714     }
715
716     public void betaStrand_actionPerformed()
717     {
718       updateSelectAllState();
719       aColChooser.setCurrentStructureFilterPanel(this);
720       aColChooser.updateView();
721     }
722
723     public void turn_actionPerformed()
724     {
725       updateSelectAllState();
726       aColChooser.setCurrentStructureFilterPanel(this);
727       aColChooser.updateView();
728     }
729
730     public void all_actionPerformed()
731     {
732       if (all.getState())
733       {
734         alphaHelix.setState(true);
735         betaStrand.setState(true);
736         turn.setState(true);
737       }
738       else
739       {
740         alphaHelix.setState(false);
741         betaStrand.setState(false);
742         turn.setState(false);
743       }
744       aColChooser.setCurrentStructureFilterPanel(this);
745       aColChooser.updateView();
746     }
747
748     public void updateSelectAllState()
749     {
750       if (alphaHelix.getState() && betaStrand.getState() && turn.getState())
751       {
752         all.setState(true);
753       }
754       else
755       {
756         all.setState(false);
757       }
758     }
759
760     public void syncState()
761     {
762       StructureFilterPanel sfp = aColChooser
763               .getCurrentStructureFilterPanel();
764       if (sfp != null)
765       {
766         alphaHelix.setState(sfp.alphaHelix.getState());
767         betaStrand.setState(sfp.betaStrand.getState());
768         turn.setState(sfp.turn.getState());
769         if (sfp.all.getState())
770         {
771           all.setState(true);
772           alphaHelix.setState(true);
773           betaStrand.setState(true);
774           turn.setState(true);
775         }
776       }
777
778     }
779
780     @Override
781     public void itemStateChanged(ItemEvent e)
782     {
783       if (e.getSource() == alphaHelix)
784       {
785         alphaHelix_actionPerformed();
786       }
787       else if (e.getSource() == betaStrand)
788       {
789         betaStrand_actionPerformed();
790       }
791       else if (e.getSource() == turn)
792       {
793         turn_actionPerformed();
794       }
795       else if (e.getSource() == all)
796       {
797         all_actionPerformed();
798       }
799     }
800   }
801
802   public class SearchPanel extends TitledPanel implements ItemListener
803   {
804     private AnnotationColumnChooser aColChooser;
805
806     private Checkbox displayName = new Checkbox();
807
808     private Checkbox description = new Checkbox();
809
810     private TextField searchBox = new TextField(10);
811
812     public SearchPanel(AnnotationColumnChooser aColChooser)
813     {
814
815       this.aColChooser = aColChooser;
816       searchBox.addTextListener(new TextListener()
817       {
818
819         @Override
820         public void textValueChanged(TextEvent e)
821         {
822           searchStringAction();
823
824         }
825
826       });
827
828       displayName.setLabel(MessageManager.getString("label.label"));
829       displayName.setEnabled(false);
830       displayName.addItemListener(this);
831
832       description.setLabel(MessageManager.getString("label.description"));
833       description.setEnabled(false);
834       description.addItemListener(this);
835       this.setTitle("Search Filter");
836       // this.setFont(JvSwingUtils.getLabelFont());
837
838       syncState();
839       this.add(searchBox);
840       this.add(displayName);
841       this.add(description);
842     }
843
844     public void displayNameCheckboxAction()
845     {
846       aColChooser.setCurrentSearchPanel(this);
847       aColChooser.updateView();
848     }
849
850     public void discriptionCheckboxAction()
851     {
852       aColChooser.setCurrentSearchPanel(this);
853       aColChooser.updateView();
854     }
855
856     public void searchStringAction()
857     {
858       aColChooser.setCurrentSearchPanel(this);
859       aColChooser.updateView();
860     }
861
862     public void syncState()
863     {
864       SearchPanel sp = aColChooser.getCurrentSearchPanel();
865       if (sp != null)
866       {
867         description.setEnabled(sp.description.isEnabled());
868         description.setState(sp.description.getState());
869
870         displayName.setEnabled(sp.displayName.isEnabled());
871         displayName.setState(sp.displayName.getState());
872
873         searchBox.setText(sp.searchBox.getText());
874       }
875     }
876
877     @Override
878     public void itemStateChanged(ItemEvent e)
879     {
880       if (e.getSource() == displayName)
881       {
882         displayNameCheckboxAction();
883       }
884       else if (e.getSource() == description)
885       {
886         discriptionCheckboxAction();
887       }
888
889     }
890   }
891
892   @Override
893   public void actionPerformed(ActionEvent evt)
894   {
895     if (evt.getSource() == thresholdValue)
896     {
897       try
898       {
899         float f = new Float(thresholdValue.getText()).floatValue();
900         slider.setValue((int) (f * 1000));
901         adjustmentValueChanged(null);
902       } catch (NumberFormatException ex)
903       {
904       }
905     }
906
907     else if (evt.getSource() == ok)
908     {
909       ok_actionPerformed(null);
910     }
911     else if (evt.getSource() == cancel)
912     {
913       cancel_actionPerformed(null);
914     }
915     else if (evt.getSource() == thresholdValue)
916     {
917       thresholdValue_actionPerformed(null);
918     }
919     else
920     {
921       updateView();
922     }
923   }
924
925   @Override
926   public void mouseClicked(MouseEvent e)
927   {
928     // TODO Auto-generated method stub
929
930   }
931
932   @Override
933   public void mousePressed(MouseEvent e)
934   {
935     if (e.getSource() == slider)
936     {
937       updateView();
938     }
939
940   }
941
942   @Override
943   public void mouseReleased(MouseEvent e)
944   {
945     if (e.getSource() == slider)
946     {
947       updateView();
948     }
949   }
950
951   @Override
952   public void mouseEntered(MouseEvent e)
953   {
954     if (e.getSource() == slider)
955     {
956       updateView();
957     }
958   }
959
960   @Override
961   public void mouseExited(MouseEvent e)
962   {
963     if (e.getSource() == slider)
964     {
965       updateView();
966     }
967   }
968
969 }