JAL-1834 removed quotes around truncated strings with ellipsis
[jalview.git] / src / jalview / gui / 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
22 package jalview.gui;
23
24 import jalview.datamodel.AlignmentAnnotation;
25 import jalview.datamodel.ColumnSelection;
26 import jalview.schemes.AnnotationColourGradient;
27 import jalview.util.MessageManager;
28 import jalview.viewmodel.annotationfilter.AnnotationFilterParameter;
29
30 import java.awt.BorderLayout;
31 import java.awt.CardLayout;
32 import java.awt.Color;
33 import java.awt.Dimension;
34 import java.awt.event.ActionEvent;
35 import java.awt.event.ActionListener;
36 import java.awt.event.ItemEvent;
37 import java.awt.event.ItemListener;
38 import java.util.Iterator;
39
40 import javax.swing.ButtonGroup;
41 import javax.swing.JCheckBox;
42 import javax.swing.JComboBox;
43 import javax.swing.JInternalFrame;
44 import javax.swing.JLayeredPane;
45 import javax.swing.JPanel;
46 import javax.swing.JRadioButton;
47 import javax.swing.JTextField;
48 import javax.swing.border.TitledBorder;
49 import javax.swing.event.DocumentEvent;
50 import javax.swing.event.DocumentListener;
51
52 import net.miginfocom.swing.MigLayout;
53
54 @SuppressWarnings("serial")
55 public class AnnotationColumnChooser extends AnnotationRowFilter implements
56         ItemListener
57 {
58
59   private JComboBox<String> annotations;
60
61   private JPanel actionPanel = new JPanel();
62
63   private JPanel thresholdPanel = new JPanel();
64
65   private JPanel switchableViewsPanel = new JPanel(new CardLayout());
66
67   private CardLayout switchableViewsLayout = (CardLayout) (switchableViewsPanel
68           .getLayout());
69   private JPanel noGraphFilterView = new JPanel();
70
71   private JPanel graphFilterView = new JPanel();
72
73   private JPanel annotationComboBoxPanel = new JPanel();
74
75   private BorderLayout borderLayout1 = new BorderLayout();
76
77   private JComboBox<String> threshold = new JComboBox<String>();
78
79   private StructureFilterPanel gStructureFilterPanel;
80
81   private StructureFilterPanel ngStructureFilterPanel;
82
83   private StructureFilterPanel currentStructureFilterPanel;
84
85   private SearchPanel currentSearchPanel;
86
87   private SearchPanel gSearchPanel;
88
89   private SearchPanel ngSearchPanel;
90
91   private FurtherActionPanel currentFurtherActionPanel;
92
93   private FurtherActionPanel gFurtherActionPanel;
94
95   private FurtherActionPanel ngFurtherActionPanel;
96
97   public static final int ACTION_OPTION_SELECT = 1;
98
99   public static int ACTION_OPTION_HIDE = 2;
100
101   public static String NO_GRAPH_VIEW = "0";
102
103   public static String GRAPH_VIEW = "1";
104
105   private int actionOption = ACTION_OPTION_SELECT;
106
107   private ColumnSelection oldColumnSelection;
108
109   public AnnotationColumnChooser()
110   {
111     try
112     {
113       jbInit();
114     } catch (Exception ex)
115     {
116       ex.printStackTrace();
117     }
118   }
119
120   public AnnotationColumnChooser(AlignViewport av, final AlignmentPanel ap)
121   {
122     super(av, ap);
123     frame = new JInternalFrame();
124     frame.setContentPane(this);
125     frame.setLayer(JLayeredPane.PALETTE_LAYER);
126     Desktop.addInternalFrame(frame,
127             MessageManager.getString("label.select_by_annotation"), 520,
128             215);
129
130     addSliderChangeListener();
131     addSliderMouseListeners();
132
133     if (av.getAlignment().getAlignmentAnnotation() == null)
134     {
135       return;
136     }
137     setOldColumnSelection(av.getColumnSelection());
138     adjusting = true;
139
140     setAnnotations(new JComboBox<String>(getAnnotationItems(false)));
141     populateThresholdComboBox(threshold);
142
143     // restore Object state from the previous session if one exists
144     if (av.getAnnotationColumnSelectionState() != null)
145     {
146       currentSearchPanel = av.getAnnotationColumnSelectionState()
147               .getCurrentSearchPanel();
148       currentStructureFilterPanel = av.getAnnotationColumnSelectionState()
149               .getCurrentStructureFilterPanel();
150       annotations.setSelectedIndex(av.getAnnotationColumnSelectionState()
151               .getAnnotations().getSelectedIndex());
152       threshold.setSelectedIndex(av.getAnnotationColumnSelectionState()
153               .getThreshold().getSelectedIndex());
154       actionOption = av.getAnnotationColumnSelectionState()
155               .getActionOption();
156     }
157
158     try
159     {
160       jbInit();
161     } catch (Exception ex)
162     {
163     }
164     adjusting = false;
165
166     updateView();
167     frame.invalidate();
168     frame.pack();
169   }
170
171   private void jbInit() throws Exception
172   {
173     ok.setOpaque(false);
174     ok.setText(MessageManager.getString("action.ok"));
175     ok.addActionListener(new ActionListener()
176     {
177       @Override
178       public void actionPerformed(ActionEvent e)
179       {
180         ok_actionPerformed(e);
181       }
182     });
183
184     cancel.setOpaque(false);
185     cancel.setText(MessageManager.getString("action.cancel"));
186     cancel.addActionListener(new ActionListener()
187     {
188       @Override
189       public void actionPerformed(ActionEvent e)
190       {
191         cancel_actionPerformed(e);
192       }
193     });
194
195     annotations.addItemListener(this);
196     annotations.setToolTipText(MessageManager
197             .getString("info.select_annotation_row"));
198     threshold.addActionListener(new ActionListener()
199     {
200       @Override
201       public void actionPerformed(ActionEvent e)
202       {
203         threshold_actionPerformed(e);
204       }
205     });
206
207     thresholdValue.setEnabled(false);
208     thresholdValue.setColumns(7);
209     thresholdValue.addActionListener(new ActionListener()
210     {
211       @Override
212       public void actionPerformed(ActionEvent e)
213       {
214         thresholdValue_actionPerformed(e);
215       }
216     });
217
218     slider.setPaintLabels(false);
219     slider.setPaintTicks(true);
220     slider.setBackground(Color.white);
221     slider.setEnabled(false);
222     slider.setOpaque(false);
223     slider.setPreferredSize(new Dimension(100, 32));
224
225     thresholdPanel.setBorder(new TitledBorder(MessageManager
226             .getString("label.threshold_filter")));
227     thresholdPanel.setBackground(Color.white);
228     thresholdPanel.setFont(JvSwingUtils.getLabelFont());
229     thresholdPanel.setLayout(new MigLayout("", "[left][right]", "[][]"));
230
231     actionPanel.setBackground(Color.white);
232     actionPanel.setFont(JvSwingUtils.getLabelFont());
233
234     graphFilterView.setLayout(new MigLayout("", "[left][right]", "[][]"));
235     graphFilterView.setBackground(Color.white);
236
237     noGraphFilterView.setLayout(new MigLayout("", "[left][right]", "[][]"));
238     noGraphFilterView.setBackground(Color.white);
239
240     annotationComboBoxPanel.setBackground(Color.white);
241     annotationComboBoxPanel.setFont(JvSwingUtils.getLabelFont());
242
243     gSearchPanel = new SearchPanel(this);
244     ngSearchPanel = new SearchPanel(this);
245     gFurtherActionPanel = new FurtherActionPanel(this);
246     ngFurtherActionPanel = new FurtherActionPanel(this);
247     gStructureFilterPanel = new StructureFilterPanel(this);
248     ngStructureFilterPanel = new StructureFilterPanel(this);
249
250     thresholdPanel.add(getThreshold());
251     thresholdPanel.add(thresholdValue, "wrap");
252     thresholdPanel.add(slider, "grow, span, wrap");
253
254     actionPanel.add(ok);
255     actionPanel.add(cancel);
256
257     graphFilterView.add(gSearchPanel, "grow, span, wrap");
258     graphFilterView.add(gStructureFilterPanel, "grow, span, wrap");
259     graphFilterView.add(thresholdPanel, "grow, span, wrap");
260     graphFilterView.add(gFurtherActionPanel);
261
262     noGraphFilterView.add(ngSearchPanel, "grow, span, wrap");
263     noGraphFilterView.add(ngStructureFilterPanel, "grow, span, wrap");
264     noGraphFilterView.add(ngFurtherActionPanel);
265
266     annotationComboBoxPanel.add(getAnnotations());
267     switchableViewsPanel.add(noGraphFilterView,
268             AnnotationColumnChooser.NO_GRAPH_VIEW);
269     switchableViewsPanel.add(graphFilterView,
270             AnnotationColumnChooser.GRAPH_VIEW);
271
272     this.setLayout(borderLayout1);
273     this.add(annotationComboBoxPanel, java.awt.BorderLayout.PAGE_START);
274     this.add(switchableViewsPanel, java.awt.BorderLayout.CENTER);
275     this.add(actionPanel, java.awt.BorderLayout.SOUTH);
276
277     selectedAnnotationChanged();
278     updateThresholdPanelToolTip();
279     this.validate();
280   }
281
282   public void updateThresholdPanelToolTip()
283   {
284     thresholdValue.setToolTipText("");
285     slider.setToolTipText("");
286
287     String defaultTtip = MessageManager
288             .getString("info.change_threshold_mode_to_enable");
289
290     String threshold = getThreshold().getSelectedItem().toString();
291     if (threshold.equalsIgnoreCase("No Threshold"))
292     {
293       thresholdValue.setToolTipText(defaultTtip);
294       slider.setToolTipText(defaultTtip);
295     }
296   }
297   public void reset()
298   {
299     if (this.getOldColumnSelection() != null)
300     {
301       av.getColumnSelection().clear();
302
303       if (av.getAnnotationColumnSelectionState() != null)
304       {
305         ColumnSelection oldSelection = av
306                 .getAnnotationColumnSelectionState()
307                 .getOldColumnSelection();
308         if (oldSelection != null && oldSelection.getHiddenColumns() != null
309                 && !oldSelection.getHiddenColumns().isEmpty())
310         {
311           for (Iterator<int[]> itr = oldSelection.getHiddenColumns()
312                   .iterator(); itr.hasNext();)
313           {
314             int positions[] = itr.next();
315             av.hideColumns(positions[0], positions[1]);
316           }
317         }
318         av.setColumnSelection(oldSelection);
319       }
320       ap.paintAlignment(true);
321     }
322
323   }
324
325   public void valueChanged(boolean updateAllAnnotation)
326   {
327     if (slider.isEnabled())
328     {
329       getCurrentAnnotation().threshold.value = slider.getValue() / 1000f;
330       updateView();
331       propagateSeqAssociatedThreshold(updateAllAnnotation,
332               getCurrentAnnotation());
333       ap.paintAlignment(false);
334     }
335   }
336
337   public JComboBox<String> getThreshold()
338   {
339     return threshold;
340   }
341
342   public void setThreshold(JComboBox<String> threshold)
343   {
344     this.threshold = threshold;
345   }
346
347   public JComboBox<String> getAnnotations()
348   {
349     return annotations;
350   }
351
352   public void setAnnotations(JComboBox<String> annotations)
353   {
354     this.annotations = annotations;
355   }
356
357   @Override
358   public void updateView()
359   {
360     // Check if combobox is still adjusting
361     if (adjusting)
362     {
363       return;
364     }
365
366     AnnotationFilterParameter filterParams = new AnnotationFilterParameter();
367
368     setCurrentAnnotation(av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
369             .getSelectedIndex()]]);
370
371     int selectedThresholdItem = getSelectedThresholdItem(getThreshold()
372             .getSelectedIndex());
373
374     slider.setEnabled(true);
375     thresholdValue.setEnabled(true);
376
377     if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
378     {
379       slider.setEnabled(false);
380       thresholdValue.setEnabled(false);
381       thresholdValue.setText("");
382       // build filter params
383     }
384     else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
385     {
386       if (getCurrentAnnotation().threshold == null)
387       {
388         getCurrentAnnotation()
389                 .setThreshold(
390                         new jalview.datamodel.GraphLine(
391                                 (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin) / 2f,
392                                 "Threshold", Color.black));
393       }
394
395       adjusting = true;
396       float range = getCurrentAnnotation().graphMax * 1000
397               - getCurrentAnnotation().graphMin * 1000;
398
399       slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
400       slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
401       slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000));
402       thresholdValue.setText(getCurrentAnnotation().threshold.value + "");
403       slider.setMajorTickSpacing((int) (range / 10f));
404       slider.setEnabled(true);
405       thresholdValue.setEnabled(true);
406       adjusting = false;
407
408       // build filter params
409       filterParams
410               .setThresholdType(AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);
411       if (getCurrentAnnotation().graph != AlignmentAnnotation.NO_GRAPH)
412       {
413         filterParams
414                 .setThresholdValue(getCurrentAnnotation().threshold.value);
415
416         if (selectedThresholdItem == AnnotationColourGradient.ABOVE_THRESHOLD)
417         {
418           filterParams
419                   .setThresholdType(AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD);
420         }
421         else if (selectedThresholdItem == AnnotationColourGradient.BELOW_THRESHOLD)
422         {
423           filterParams
424                   .setThresholdType(AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD);
425         }
426       }
427     }
428
429     updateThresholdPanelToolTip();
430     if (currentStructureFilterPanel != null)
431     {
432       if (currentStructureFilterPanel.alphaHelix.isSelected())
433       {
434         filterParams.setFilterAlphaHelix(true);
435       }
436       if (currentStructureFilterPanel.betaStrand.isSelected())
437       {
438         filterParams.setFilterBetaSheet(true);
439       }
440       if (currentStructureFilterPanel.turn.isSelected())
441       {
442         filterParams.setFilterTurn(true);
443       }
444     }
445
446     if (currentSearchPanel != null)
447     {
448
449       if (!currentSearchPanel.searchBox.getText().isEmpty())
450       {
451         currentSearchPanel.description.setEnabled(true);
452         currentSearchPanel.displayName.setEnabled(true);
453         filterParams.setRegexString(currentSearchPanel.searchBox.getText());
454         if (currentSearchPanel.displayName.isSelected())
455         {
456           filterParams
457                   .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING);
458         }
459         if (currentSearchPanel.description.isSelected())
460         {
461           filterParams
462                   .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION);
463         }
464       }
465       else
466       {
467         currentSearchPanel.description.setEnabled(false);
468         currentSearchPanel.displayName.setEnabled(false);
469       }
470     }
471
472     av.getColumnSelection().filterAnnotations(
473             getCurrentAnnotation().annotations, filterParams);
474
475     av.showAllHiddenColumns();
476     if (getActionOption() == ACTION_OPTION_HIDE)
477     {
478       av.hideSelectedColumns();
479     }
480
481     filterParams = null;
482     av.setAnnotationColumnSelectionState(this);
483     ap.paintAlignment(true);
484   }
485
486   public ColumnSelection getOldColumnSelection()
487   {
488     return oldColumnSelection;
489   }
490
491   public void setOldColumnSelection(ColumnSelection currentColumnSelection)
492   {
493     if (currentColumnSelection != null)
494     {
495       this.oldColumnSelection = new ColumnSelection(currentColumnSelection);
496     }
497   }
498
499   public FurtherActionPanel getCurrentFutherActionPanel()
500   {
501     return currentFurtherActionPanel;
502   }
503
504   public void setCurrentFutherActionPanel(
505           FurtherActionPanel currentFutherActionPanel)
506   {
507     this.currentFurtherActionPanel = currentFutherActionPanel;
508   }
509
510   public SearchPanel getCurrentSearchPanel()
511   {
512     return currentSearchPanel;
513   }
514
515   public void setCurrentSearchPanel(SearchPanel currentSearchPanel)
516   {
517     this.currentSearchPanel = currentSearchPanel;
518   }
519
520   public int getActionOption()
521   {
522     return actionOption;
523   }
524
525   public void setActionOption(int actionOption)
526   {
527     this.actionOption = actionOption;
528   }
529
530   public StructureFilterPanel getCurrentStructureFilterPanel()
531   {
532     return currentStructureFilterPanel;
533   }
534
535   public void setCurrentStructureFilterPanel(
536           StructureFilterPanel currentStructureFilterPanel)
537   {
538     this.currentStructureFilterPanel = currentStructureFilterPanel;
539   }
540
541   public void select_action(ActionEvent actionEvent)
542   {
543     JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
544     if (radioButton.isSelected())
545     {
546       setActionOption(ACTION_OPTION_SELECT);
547       updateView();
548     }
549   }
550
551   public void hide_action(ActionEvent actionEvent)
552   {
553     JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
554     if (radioButton.isSelected())
555     {
556       setActionOption(ACTION_OPTION_HIDE);
557       updateView();
558     }
559   }
560
561   @Override
562   public void itemStateChanged(ItemEvent e)
563   {
564     selectedAnnotationChanged();
565   }
566
567   public void selectedAnnotationChanged()
568   {
569     String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
570     if (av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
571             .getSelectedIndex()]].graph != AlignmentAnnotation.NO_GRAPH)
572     {
573       currentView = AnnotationColumnChooser.GRAPH_VIEW;
574     }
575
576     gSearchPanel.syncState();
577     gFurtherActionPanel.syncState();
578     gStructureFilterPanel.syncState();
579
580     ngSearchPanel.syncState();
581     ngFurtherActionPanel.syncState();
582     ngStructureFilterPanel.syncState();
583
584     switchableViewsLayout.show(switchableViewsPanel, currentView);
585     updateView();
586   }
587
588
589   public class FurtherActionPanel extends JPanel
590   {
591     private AnnotationColumnChooser aColChooser;
592
593     private JRadioButton hideOption = new JRadioButton();
594
595     private JRadioButton selectOption = new JRadioButton();
596
597     private ButtonGroup optionsGroup = new ButtonGroup();
598
599     public FurtherActionPanel(AnnotationColumnChooser aColChooser)
600     {
601       this.aColChooser = aColChooser;
602       JvSwingUtils.jvInitComponent(selectOption, "action.select");
603       selectOption.addActionListener(new ActionListener()
604       {
605         @Override
606         public void actionPerformed(ActionEvent actionEvent)
607         {
608           selectRadioAction(actionEvent);
609         }
610       });
611
612       JvSwingUtils.jvInitComponent(hideOption, "action.hide");
613       hideOption.addActionListener(new ActionListener()
614       {
615         @Override
616         public void actionPerformed(ActionEvent actionEvent)
617         {
618           hideRadioAction(actionEvent);
619         }
620       });
621
622       optionsGroup.add(selectOption);
623       optionsGroup.add(hideOption);
624       optionsGroup.setSelected(selectOption.getModel(), true);
625
626       JvSwingUtils.jvInitComponent(this);
627       syncState();
628
629       this.add(selectOption);
630       this.add(hideOption);
631     }
632
633     public void selectRadioAction(ActionEvent actionEvent)
634     {
635       aColChooser.setCurrentFutherActionPanel(this);
636       aColChooser.select_action(actionEvent);
637     }
638
639     public void hideRadioAction(ActionEvent actionEvent)
640     {
641       aColChooser.setCurrentFutherActionPanel(this);
642       aColChooser.hide_action(actionEvent);
643     }
644
645     public void syncState()
646     {
647       if (aColChooser.getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
648       {
649         this.optionsGroup.setSelected(this.hideOption.getModel(),
650                 true);
651       }
652       else
653       {
654         this.optionsGroup.setSelected(this.selectOption.getModel(), true);
655       }
656     }
657   }
658
659   public class StructureFilterPanel extends JPanel
660   {
661     private AnnotationColumnChooser aColChooser;
662
663     private JCheckBox alphaHelix = new JCheckBox();
664
665     private JCheckBox betaStrand = new JCheckBox();
666
667     private JCheckBox turn = new JCheckBox();
668
669     private JCheckBox all = new JCheckBox();
670
671     public StructureFilterPanel(AnnotationColumnChooser aColChooser)
672     {
673       this.aColChooser = aColChooser;
674
675       JvSwingUtils.jvInitComponent(alphaHelix, "label.alpha_helix");
676       alphaHelix.addActionListener(new ActionListener()
677       {
678         @Override
679         public void actionPerformed(ActionEvent actionEvent)
680         {
681           alphaHelix_actionPerformed();
682         }
683       });
684
685       JvSwingUtils.jvInitComponent(betaStrand, "label.beta_strand");
686       betaStrand.addActionListener(new ActionListener()
687       {
688         @Override
689         public void actionPerformed(ActionEvent actionEvent)
690         {
691           betaStrand_actionPerformed();
692         }
693       });
694
695       JvSwingUtils.jvInitComponent(turn, "label.turn");
696       turn.addActionListener(new ActionListener()
697       {
698         @Override
699         public void actionPerformed(ActionEvent actionEvent)
700         {
701           turn_actionPerformed();
702         }
703       });
704
705       JvSwingUtils.jvInitComponent(all, "label.select_all");
706       all.addActionListener(new ActionListener()
707       {
708         @Override
709         public void actionPerformed(ActionEvent actionEvent)
710         {
711           all_actionPerformed();
712         }
713       });
714
715       this.setBorder(new TitledBorder(MessageManager
716               .getString("label.structures_filter")));
717       JvSwingUtils.jvInitComponent(this);
718
719       this.add(all);
720       this.add(alphaHelix);
721       this.add(betaStrand);
722       this.add(turn);
723     }
724
725     public void alphaHelix_actionPerformed()
726     {
727       updateSelectAllState();
728       aColChooser.setCurrentStructureFilterPanel(this);
729       aColChooser.updateView();
730     }
731
732     public void betaStrand_actionPerformed()
733     {
734       updateSelectAllState();
735       aColChooser.setCurrentStructureFilterPanel(this);
736       aColChooser.updateView();
737     }
738
739     public void turn_actionPerformed()
740     {
741       updateSelectAllState();
742       aColChooser.setCurrentStructureFilterPanel(this);
743       aColChooser.updateView();
744     }
745
746     public void all_actionPerformed()
747     {
748       if (all.isSelected())
749       {
750         alphaHelix.setSelected(true);
751         betaStrand.setSelected(true);
752         turn.setSelected(true);
753       }
754       else
755       {
756         alphaHelix.setSelected(false);
757         betaStrand.setSelected(false);
758         turn.setSelected(false);
759       }
760       aColChooser.setCurrentStructureFilterPanel(this);
761       aColChooser.updateView();
762     }
763
764     public void updateSelectAllState()
765     {
766       if (alphaHelix.isSelected() && betaStrand.isSelected()
767               && turn.isSelected())
768       {
769         all.setSelected(true);
770       }
771       else
772       {
773         all.setSelected(false);
774       }
775     }
776
777     public void syncState()
778     {
779       StructureFilterPanel sfp = aColChooser
780               .getCurrentStructureFilterPanel();
781       if (sfp != null)
782       {
783         alphaHelix.setSelected(sfp.alphaHelix.isSelected());
784         betaStrand.setSelected(sfp.betaStrand.isSelected());
785         turn.setSelected(sfp.turn.isSelected());
786         if (sfp.all.isSelected())
787         {
788           all.setSelected(true);
789           alphaHelix.setSelected(true);
790           betaStrand.setSelected(true);
791           turn.setSelected(true);
792         }
793       }
794
795     }
796   }
797
798   public class SearchPanel extends JPanel
799   {
800     private AnnotationColumnChooser aColChooser;
801
802     private JCheckBox displayName = new JCheckBox();
803
804     private JCheckBox description = new JCheckBox();
805
806     private JTextField searchBox = new JTextField(10);
807
808     public SearchPanel(AnnotationColumnChooser aColChooser)
809     {
810
811       this.aColChooser = aColChooser;
812       JvSwingUtils.jvInitComponent(this);
813       this.setBorder(new TitledBorder(MessageManager
814               .getString("label.search_filter")));
815
816       JvSwingUtils.jvInitComponent(searchBox);
817       searchBox.setToolTipText(MessageManager
818               .getString("info.enter_search_text_here"));
819       searchBox.getDocument().addDocumentListener(
820               new DocumentListener()
821               {
822                 @Override
823                 public void insertUpdate(DocumentEvent e)
824                 {
825                   searchStringAction();
826                 }
827
828                 @Override
829                 public void removeUpdate(DocumentEvent e)
830                 {
831                   searchStringAction();
832                 }
833
834                 @Override
835                 public void changedUpdate(DocumentEvent e)
836                 {
837                   searchStringAction();
838                 }
839               });
840
841       JvSwingUtils.jvInitComponent(displayName, "label.label");
842       displayName.setEnabled(false);
843       displayName.addActionListener(new ActionListener()
844       {
845         @Override
846         public void actionPerformed(ActionEvent actionEvent)
847         {
848           displayNameCheckboxAction();
849         }
850       });
851
852       JvSwingUtils.jvInitComponent(description, "label.description");
853       description.setEnabled(false);
854       description.addActionListener(new ActionListener()
855       {
856         @Override
857         public void actionPerformed(ActionEvent actionEvent)
858         {
859           discriptionCheckboxAction();
860         }
861       });
862
863       syncState();
864       this.add(searchBox);
865       this.add(displayName);
866       this.add(description);
867     }
868
869     public void displayNameCheckboxAction()
870     {
871       aColChooser.setCurrentSearchPanel(this);
872       aColChooser.updateView();
873     }
874
875     public void discriptionCheckboxAction()
876     {
877       aColChooser.setCurrentSearchPanel(this);
878       aColChooser.updateView();
879     }
880
881     public void searchStringAction()
882     {
883       aColChooser.setCurrentSearchPanel(this);
884       aColChooser.updateView();
885       updateSearchPanelToolTips();
886     }
887
888     public void syncState()
889     {
890       SearchPanel sp = aColChooser.getCurrentSearchPanel();
891       if (sp != null)
892       {
893         description.setEnabled(sp.description.isEnabled());
894         description.setSelected(sp.description.isSelected());
895
896         displayName.setEnabled(sp.displayName.isEnabled());
897         displayName.setSelected(sp.displayName.isSelected());
898
899         searchBox.setText(sp.searchBox.getText());
900       }
901       updateSearchPanelToolTips();
902     }
903
904     public void updateSearchPanelToolTips()
905     {
906       String defaultTtip = MessageManager
907               .getString("info.enter_search_text_to_enable");
908       String labelTtip = MessageManager
909 .formatMessage(
910               "info.search_in_annotation_label", annotations
911                       .getSelectedItem().toString());
912       String descTtip = MessageManager
913 .formatMessage(
914               "info.search_in_annotation_description", annotations
915                       .getSelectedItem().toString());
916       displayName.setToolTipText(displayName.isEnabled() ? labelTtip : defaultTtip);
917       description.setToolTipText(description.isEnabled() ? descTtip
918               : defaultTtip);
919     }
920   }
921
922 }