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