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