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