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