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