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