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