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