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