Merge remote-tracking branch 'origin/bug/JAL-2740' into feature/JAL-2674take2
[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.HiddenColumns;
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.Vector;
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);
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);
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();
352       ap.paintAlignment(false);
353     }
354   }
355
356   public Choice getThreshold()
357   {
358     return threshold;
359   }
360
361   public void setThreshold(Choice threshold)
362   {
363     this.threshold = threshold;
364   }
365
366   public Choice getAnnotations()
367   {
368     return annotations;
369   }
370
371   public void setAnnotations(Choice annotations)
372   {
373     this.annotations = annotations;
374   }
375
376   @Override
377   public void updateView()
378   {
379     // Check if combobox is still adjusting
380     if (adjusting)
381     {
382       return;
383     }
384
385     AnnotationFilterParameter filterParams = new AnnotationFilterParameter();
386     setCurrentAnnotation(av.getAlignment()
387             .getAlignmentAnnotation()[getAnnotations().getSelectedIndex()]);
388
389     int selectedThresholdItem = getSelectedThresholdItem(
390             getThreshold().getSelectedIndex());
391
392     slider.setEnabled(true);
393     thresholdValue.setEnabled(true);
394     percentThreshold.setEnabled(true);
395
396     if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
397     {
398       slider.setEnabled(false);
399       thresholdValue.setEnabled(false);
400       thresholdValue.setText("");
401       percentThreshold.setEnabled(false);
402       // build filter params
403     }
404     else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
405     {
406       if (getCurrentAnnotation().threshold == null)
407       {
408         getCurrentAnnotation().setThreshold(new jalview.datamodel.GraphLine(
409                 (getCurrentAnnotation().graphMax
410                         - getCurrentAnnotation().graphMin) / 2f,
411                 "Threshold", Color.black));
412       }
413
414       adjusting = true;
415       // float range = getCurrentAnnotation().graphMax * 1000
416       // - getCurrentAnnotation().graphMin * 1000;
417
418       slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
419       slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
420       slider.setValue(
421               (int) (getCurrentAnnotation().threshold.value * 1000));
422       setThresholdValueText();
423       // slider.setMajorTickSpacing((int) (range / 10f));
424       slider.setEnabled(true);
425       thresholdValue.setEnabled(true);
426       percentThreshold.setEnabled(true);
427       adjusting = false;
428
429       // build filter params
430       filterParams.setThresholdType(
431               AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);
432       if (getCurrentAnnotation().isQuantitative())
433       {
434         filterParams
435                 .setThresholdValue(getCurrentAnnotation().threshold.value);
436
437         if (selectedThresholdItem == AnnotationColourGradient.ABOVE_THRESHOLD)
438         {
439           filterParams.setThresholdType(
440                   AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD);
441         }
442         else if (selectedThresholdItem == AnnotationColourGradient.BELOW_THRESHOLD)
443         {
444           filterParams.setThresholdType(
445                   AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD);
446         }
447       }
448     }
449
450     if (currentStructureFilterPanel != null)
451     {
452       if (currentStructureFilterPanel.alphaHelix.getState())
453       {
454         filterParams.setFilterAlphaHelix(true);
455       }
456       if (currentStructureFilterPanel.betaStrand.getState())
457       {
458         filterParams.setFilterBetaSheet(true);
459       }
460       if (currentStructureFilterPanel.turn.getState())
461       {
462         filterParams.setFilterTurn(true);
463       }
464     }
465
466     if (currentSearchPanel != null)
467     {
468
469       if (!currentSearchPanel.searchBox.getText().isEmpty())
470       {
471         currentSearchPanel.description.setEnabled(true);
472         currentSearchPanel.displayName.setEnabled(true);
473         filterParams.setRegexString(currentSearchPanel.searchBox.getText());
474         if (currentSearchPanel.displayName.getState())
475         {
476           filterParams.addRegexSearchField(
477                   AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING);
478         }
479         if (currentSearchPanel.description.getState())
480         {
481           filterParams.addRegexSearchField(
482                   AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION);
483         }
484       }
485       else
486       {
487         currentSearchPanel.description.setEnabled(false);
488         currentSearchPanel.displayName.setEnabled(false);
489       }
490     }
491
492     // show hidden columns here, before changing the column selection in
493     // filterAnnotations, because showing hidden columns has the side effect of
494     // adding them to the selection
495     av.showAllHiddenColumns();
496     av.getColumnSelection().filterAnnotations(
497             getCurrentAnnotation().annotations, filterParams);
498
499     if (getActionOption() == ACTION_OPTION_HIDE)
500     {
501       av.hideSelectedColumns();
502     }
503
504     filterParams = null;
505     av.setAnnotationColumnSelectionState(this);
506     av.sendSelection();
507     ap.paintAlignment(true);
508   }
509
510   public HiddenColumns getOldHiddenColumns()
511   {
512     return oldHiddenColumns;
513   }
514
515   public void setOldHiddenColumns(HiddenColumns currentHiddenColumns)
516   {
517     if (currentHiddenColumns != null)
518     {
519       this.oldHiddenColumns = new HiddenColumns(currentHiddenColumns);
520     }
521   }
522
523   public FurtherActionPanel getCurrentFutherActionPanel()
524   {
525     return currentFurtherActionPanel;
526   }
527
528   public void setCurrentFutherActionPanel(
529           FurtherActionPanel currentFutherActionPanel)
530   {
531     this.currentFurtherActionPanel = currentFutherActionPanel;
532   }
533
534   public SearchPanel getCurrentSearchPanel()
535   {
536     return currentSearchPanel;
537   }
538
539   public void setCurrentSearchPanel(SearchPanel currentSearchPanel)
540   {
541     this.currentSearchPanel = currentSearchPanel;
542   }
543
544   public int getActionOption()
545   {
546     return actionOption;
547   }
548
549   public void setActionOption(int actionOption)
550   {
551     this.actionOption = actionOption;
552   }
553
554   public StructureFilterPanel getCurrentStructureFilterPanel()
555   {
556     return currentStructureFilterPanel;
557   }
558
559   public void setCurrentStructureFilterPanel(
560           StructureFilterPanel currentStructureFilterPanel)
561   {
562     this.currentStructureFilterPanel = currentStructureFilterPanel;
563   }
564
565   @Override
566   public void itemStateChanged(ItemEvent e)
567   {
568     if (e.getSource() == annotations)
569     {
570       selectedAnnotationChanged();
571     }
572     else if (e.getSource() == threshold)
573     {
574       threshold_actionPerformed(null);
575     }
576     else if (e.getSource() == percentThreshold)
577     {
578       if (!adjusting)
579       {
580         percentageValue_actionPerformed();
581       }
582
583     }
584   }
585
586   public void selectedAnnotationChanged()
587   {
588     String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
589     if (av.getAlignment().getAlignmentAnnotation()[getAnnotations()
590             .getSelectedIndex()].isQuantitative())
591     {
592       currentView = AnnotationColumnChooser.GRAPH_VIEW;
593     }
594
595     gSearchPanel.syncState();
596     gFurtherActionPanel.syncState();
597     gStructureFilterPanel.syncState();
598
599     ngSearchPanel.syncState();
600     ngFurtherActionPanel.syncState();
601     ngStructureFilterPanel.syncState();
602
603     switchableViewsLayout.show(switchableViewsPanel, currentView);
604     updateView();
605   }
606
607   public class FurtherActionPanel extends Panel implements ItemListener
608   {
609     private AnnotationColumnChooser aColChooser;
610
611     private Choice furtherAction = new Choice();
612
613     public FurtherActionPanel(AnnotationColumnChooser aColChooser)
614     {
615       this.aColChooser = aColChooser;
616       furtherAction.addItem("Select");
617       furtherAction.addItem("Hide");
618       furtherAction.addItemListener(this);
619       syncState();
620
621       // this.setTitle("Filter Actions");
622       // this.setFont(JvSwingUtils.getLabelFont());
623
624       this.add(furtherAction);
625     }
626
627     public void syncState()
628     {
629       if (aColChooser
630               .getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
631       {
632         furtherAction.select("Hide");
633       }
634       else
635       {
636         furtherAction.select("Select");
637       }
638     }
639
640     @Override
641     public void itemStateChanged(ItemEvent e)
642     {
643       aColChooser.setCurrentFutherActionPanel(this);
644       if (furtherAction.getSelectedItem().equalsIgnoreCase("Select"))
645       {
646         setActionOption(ACTION_OPTION_SELECT);
647         updateView();
648       }
649       else
650       {
651         setActionOption(ACTION_OPTION_HIDE);
652         updateView();
653       }
654
655     }
656   }
657
658   public class StructureFilterPanel extends TitledPanel
659           implements ItemListener
660   {
661     private AnnotationColumnChooser aColChooser;
662
663     private Checkbox alphaHelix = new Checkbox();
664
665     private Checkbox betaStrand = new Checkbox();
666
667     private Checkbox turn = new Checkbox();
668
669     private Checkbox all = new Checkbox();
670
671     public StructureFilterPanel(AnnotationColumnChooser aColChooser)
672     {
673       this.aColChooser = aColChooser;
674
675       alphaHelix.setLabel(MessageManager.getString("label.alpha_helix"));
676       alphaHelix.setBackground(Color.white);
677
678       alphaHelix.addItemListener(this);
679
680       betaStrand.setLabel(MessageManager.getString("label.beta_strand"));
681       betaStrand.setBackground(Color.white);
682       betaStrand.addItemListener(this);
683
684       turn.setLabel(MessageManager.getString("label.turn"));
685       turn.setBackground(Color.white);
686       turn.addItemListener(this);
687
688       all.setLabel(MessageManager.getString("label.select_all"));
689       all.setBackground(Color.white);
690       all.addItemListener(this);
691
692       this.setBackground(Color.white);
693       this.setTitle("Structure Filter");
694       // this.setFont(JvSwingUtils.getLabelFont());
695
696       this.add(all);
697       this.add(alphaHelix);
698       this.add(betaStrand);
699       this.add(turn);
700     }
701
702     public void alphaHelix_actionPerformed()
703     {
704       updateSelectAllState();
705       aColChooser.setCurrentStructureFilterPanel(this);
706       aColChooser.updateView();
707     }
708
709     public void betaStrand_actionPerformed()
710     {
711       updateSelectAllState();
712       aColChooser.setCurrentStructureFilterPanel(this);
713       aColChooser.updateView();
714     }
715
716     public void turn_actionPerformed()
717     {
718       updateSelectAllState();
719       aColChooser.setCurrentStructureFilterPanel(this);
720       aColChooser.updateView();
721     }
722
723     public void all_actionPerformed()
724     {
725       if (all.getState())
726       {
727         alphaHelix.setState(true);
728         betaStrand.setState(true);
729         turn.setState(true);
730       }
731       else
732       {
733         alphaHelix.setState(false);
734         betaStrand.setState(false);
735         turn.setState(false);
736       }
737       aColChooser.setCurrentStructureFilterPanel(this);
738       aColChooser.updateView();
739     }
740
741     public void updateSelectAllState()
742     {
743       if (alphaHelix.getState() && betaStrand.getState() && turn.getState())
744       {
745         all.setState(true);
746       }
747       else
748       {
749         all.setState(false);
750       }
751     }
752
753     public void syncState()
754     {
755       StructureFilterPanel sfp = aColChooser
756               .getCurrentStructureFilterPanel();
757       if (sfp != null)
758       {
759         alphaHelix.setState(sfp.alphaHelix.getState());
760         betaStrand.setState(sfp.betaStrand.getState());
761         turn.setState(sfp.turn.getState());
762         if (sfp.all.getState())
763         {
764           all.setState(true);
765           alphaHelix.setState(true);
766           betaStrand.setState(true);
767           turn.setState(true);
768         }
769       }
770
771     }
772
773     @Override
774     public void itemStateChanged(ItemEvent e)
775     {
776       if (e.getSource() == alphaHelix)
777       {
778         alphaHelix_actionPerformed();
779       }
780       else if (e.getSource() == betaStrand)
781       {
782         betaStrand_actionPerformed();
783       }
784       else if (e.getSource() == turn)
785       {
786         turn_actionPerformed();
787       }
788       else if (e.getSource() == all)
789       {
790         all_actionPerformed();
791       }
792     }
793   }
794
795   public class SearchPanel extends TitledPanel implements ItemListener
796   {
797     private AnnotationColumnChooser aColChooser;
798
799     private Checkbox displayName = new Checkbox();
800
801     private Checkbox description = new Checkbox();
802
803     private TextField searchBox = new TextField(10);
804
805     public SearchPanel(AnnotationColumnChooser aColChooser)
806     {
807
808       this.aColChooser = aColChooser;
809       searchBox.addTextListener(new TextListener()
810       {
811
812         @Override
813         public void textValueChanged(TextEvent e)
814         {
815           searchStringAction();
816
817         }
818
819       });
820
821       displayName.setLabel(MessageManager.getString("label.label"));
822       displayName.setEnabled(false);
823       displayName.addItemListener(this);
824
825       description.setLabel(MessageManager.getString("label.description"));
826       description.setEnabled(false);
827       description.addItemListener(this);
828       this.setTitle("Search Filter");
829       // this.setFont(JvSwingUtils.getLabelFont());
830
831       syncState();
832       this.add(searchBox);
833       this.add(displayName);
834       this.add(description);
835     }
836
837     public void displayNameCheckboxAction()
838     {
839       aColChooser.setCurrentSearchPanel(this);
840       aColChooser.updateView();
841     }
842
843     public void discriptionCheckboxAction()
844     {
845       aColChooser.setCurrentSearchPanel(this);
846       aColChooser.updateView();
847     }
848
849     public void searchStringAction()
850     {
851       aColChooser.setCurrentSearchPanel(this);
852       aColChooser.updateView();
853     }
854
855     public void syncState()
856     {
857       SearchPanel sp = aColChooser.getCurrentSearchPanel();
858       if (sp != null)
859       {
860         description.setEnabled(sp.description.isEnabled());
861         description.setState(sp.description.getState());
862
863         displayName.setEnabled(sp.displayName.isEnabled());
864         displayName.setState(sp.displayName.getState());
865
866         searchBox.setText(sp.searchBox.getText());
867       }
868     }
869
870     @Override
871     public void itemStateChanged(ItemEvent e)
872     {
873       if (e.getSource() == displayName)
874       {
875         displayNameCheckboxAction();
876       }
877       else if (e.getSource() == description)
878       {
879         discriptionCheckboxAction();
880       }
881
882     }
883   }
884
885   @Override
886   public void actionPerformed(ActionEvent evt)
887   {
888
889     if (evt.getSource() == ok)
890     {
891       ok_actionPerformed(null);
892     }
893     else if (evt.getSource() == cancel)
894     {
895       cancel_actionPerformed(null);
896     }
897     else if (evt.getSource() == thresholdValue)
898     {
899       thresholdValue_actionPerformed(null);
900     }
901     else
902     {
903       updateView();
904     }
905   }
906
907   @Override
908   public void mouseClicked(MouseEvent e)
909   {
910     // TODO Auto-generated method stub
911
912   }
913
914   @Override
915   public void mousePressed(MouseEvent e)
916   {
917     if (e.getSource() == slider)
918     {
919       updateView();
920     }
921
922   }
923
924   @Override
925   public void mouseReleased(MouseEvent e)
926   {
927     if (e.getSource() == slider)
928     {
929       updateView();
930     }
931   }
932
933   @Override
934   public void mouseEntered(MouseEvent e)
935   {
936     if (e.getSource() == slider)
937     {
938       updateView();
939     }
940   }
941
942   @Override
943   public void mouseExited(MouseEvent e)
944   {
945     if (e.getSource() == slider)
946     {
947       updateView();
948     }
949   }
950
951 }