1. Project Clover database Fri Dec 6 2024 13:47:14 GMT
  2. Package jalview.gui

File AnnotationColumnChooser.java

 

Coverage histogram

../../img/srcFileCovDistChart6.png
37% of files have more coverage

Code metrics

72
310
52
4
879
713
92
0.3
5.96
13
1.77

Classes

Class
Line #
Actions
AnnotationColumnChooser 56 198 54
0.581227458.1%
AnnotationColumnChooser.FurtherActionPanel 519 21 7
0.586206958.6%
AnnotationColumnChooser.StructureFilterPanel 589 50 17
0.2898550629%
AnnotationColumnChooser.SearchPanel 728 41 14
0.4745762647.5%
 

Contributing tests

This file is covered by 1 test. .

Source view

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