Clover icon

Coverage Report

  1. Project Clover database Thu Nov 7 2024 17:01:39 GMT
  2. Package jalview.gui

File AnnotationColumnChooser.java

 

Coverage histogram

../../img/srcFileCovDistChart0.png
0% 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.00%
AnnotationColumnChooser.FurtherActionPanel 519 21 7
0.00%
AnnotationColumnChooser.StructureFilterPanel 589 50 17
0.00%
AnnotationColumnChooser.SearchPanel 728 41 14
0.00%
 

Contributing tests

No tests hitting this source file were found.

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  0 toggle public AnnotationColumnChooser(AlignViewport av, final AlignmentPanel ap)
98    {
99  0 this(av, ap, null);
100    }
101   
 
102  0 toggle public AnnotationColumnChooser(AlignViewport av, final AlignmentPanel ap,
103    AlignmentAnnotation selectedAnnotation)
104    {
105  0 super(av, ap);
106  0 frame = new JInternalFrame();
107  0 frame.setFrameIcon(null);
108  0 frame.setContentPane(this);
109  0 frame.setLayer(JLayeredPane.PALETTE_LAYER);
110  0 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  0 frame.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT));
115   
116  0 addSliderChangeListener();
117  0 addSliderMouseListeners();
118   
119  0 if (av.getAlignment().getAlignmentAnnotation() == null)
120    {
121  0 return;
122    }
123  0 setOldHiddenColumns(av.getAlignment().getHiddenColumns());
124  0 adjusting = true;
125   
126  0 setAnnotations(new JComboBox<>(getAnnotationItems(false)));
127  0 populateThresholdComboBox(threshold);
128  0 AnnotationColumnChooser lastChooser = av
129    .getAnnotationColumnSelectionState();
130    // restore Object state from the previous session if one exists
131  0 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  0 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  0 try
158    {
159  0 jbInit();
160    } catch (Exception ex)
161    {
162    }
163  0 adjusting = false;
164   
165  0 updateView();
166  0 frame.invalidate();
167  0 frame.pack();
168    }
169   
 
170  0 toggle @Override
171    protected void jbInit()
172    {
173  0 super.jbInit();
174   
175  0 JPanel thresholdPanel = new JPanel();
176  0 thresholdPanel.setBorder(new TitledBorder(
177    MessageManager.getString("label.threshold_filter")));
178  0 thresholdPanel.setBackground(Color.white);
179  0 thresholdPanel.setFont(JvSwingUtils.getLabelFont());
180  0 thresholdPanel.setLayout(new MigLayout("", "[left][right]", "[][]"));
181   
182  0 percentThreshold.setBackground(Color.white);
183  0 percentThreshold.setFont(JvSwingUtils.getLabelFont());
184   
185  0 JPanel actionPanel = new JPanel();
186  0 actionPanel.setBackground(Color.white);
187  0 actionPanel.setFont(JvSwingUtils.getLabelFont());
188   
189  0 JPanel graphFilterView = new JPanel();
190  0 graphFilterView.setLayout(new MigLayout("", "[left][right]", "[][]"));
191  0 graphFilterView.setBackground(Color.white);
192   
193  0 JPanel noGraphFilterView = new JPanel();
194  0 noGraphFilterView.setLayout(new MigLayout("", "[left][right]", "[][]"));
195  0 noGraphFilterView.setBackground(Color.white);
196   
197  0 annotationComboBoxPanel.setBackground(Color.white);
198  0 annotationComboBoxPanel.setFont(JvSwingUtils.getLabelFont());
199   
200  0 gSearchPanel = new SearchPanel(this);
201  0 ngSearchPanel = new SearchPanel(this);
202  0 gFurtherActionPanel = new FurtherActionPanel(this);
203  0 ngFurtherActionPanel = new FurtherActionPanel(this);
204  0 gStructureFilterPanel = new StructureFilterPanel(this);
205  0 ngStructureFilterPanel = new StructureFilterPanel(this);
206   
207  0 thresholdPanel.add(getThreshold());
208  0 thresholdPanel.add(percentThreshold, "wrap");
209  0 thresholdPanel.add(slider, "grow");
210  0 thresholdPanel.add(thresholdValue, "span, wrap");
211   
212  0 actionPanel.add(ok);
213  0 actionPanel.add(cancel);
214   
215  0 graphFilterView.add(gSearchPanel, "grow, span, wrap");
216  0 graphFilterView.add(gStructureFilterPanel, "grow, span, wrap");
217  0 graphFilterView.add(thresholdPanel, "grow, span, wrap");
218  0 graphFilterView.add(gFurtherActionPanel);
219   
220  0 noGraphFilterView.add(ngSearchPanel, "grow, span, wrap");
221  0 noGraphFilterView.add(ngStructureFilterPanel, "grow, span, wrap");
222  0 noGraphFilterView.add(ngFurtherActionPanel);
223   
224  0 annotationComboBoxPanel.add(getAnnotations());
225  0 switchableViewsPanel.add(noGraphFilterView,
226    AnnotationColumnChooser.NO_GRAPH_VIEW);
227  0 switchableViewsPanel.add(graphFilterView,
228    AnnotationColumnChooser.GRAPH_VIEW);
229  0 this.setLayout(new BorderLayout());
230  0 this.add(annotationComboBoxPanel, java.awt.BorderLayout.PAGE_START);
231  0 this.add(switchableViewsPanel, java.awt.BorderLayout.CENTER);
232  0 this.add(actionPanel, java.awt.BorderLayout.SOUTH);
233   
234  0 selectedAnnotationChanged();
235  0 updateThresholdPanelToolTip();
236  0 this.validate();
237    }
238   
 
239  0 toggle protected void updateThresholdPanelToolTip()
240    {
241  0 thresholdValue.setToolTipText("");
242  0 slider.setToolTipText("");
243   
244  0 String defaultTtip = MessageManager
245    .getString("info.change_threshold_mode_to_enable");
246   
247  0 String thresh = getThreshold().getSelectedItem().toString();
248  0 if (thresh.equalsIgnoreCase("No Threshold"))
249    {
250  0 thresholdValue.setToolTipText(defaultTtip);
251  0 slider.setToolTipText(defaultTtip);
252    }
253    }
254   
 
255  0 toggle @Override
256    protected void reset()
257    {
258  0 if (this.getOldHiddenColumns() != null)
259    {
260  0 av.getColumnSelection().clear();
261   
262  0 if (av.getAnnotationColumnSelectionState() != null)
263    {
264  0 HiddenColumns oldHidden = av.getAnnotationColumnSelectionState()
265    .getOldHiddenColumns();
266  0 av.getAlignment().setHiddenColumns(oldHidden);
267    }
268  0 av.sendSelection();
269  0 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  0 toggle @Override
287    public void updateView()
288    {
289    // Check if combobox is still adjusting
290  0 if (adjusting)
291    {
292  0 return;
293    }
294   
295  0 AnnotationFilterParameter filterParams = new AnnotationFilterParameter();
296   
297  0 setCurrentAnnotation(av.getAlignment()
298    .getAlignmentAnnotation()[annmap[getAnnotations()
299    .getSelectedIndex()]]);
300   
301  0 int selectedThresholdItem = getSelectedThresholdItem(
302    getThreshold().getSelectedIndex());
303   
304  0 slider.setEnabled(true);
305  0 thresholdValue.setEnabled(true);
306  0 percentThreshold.setEnabled(true);
307   
308  0 final AlignmentAnnotation currentAnnotation = getCurrentAnnotation();
309  0 if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
310    {
311  0 slider.setEnabled(false);
312  0 thresholdValue.setEnabled(false);
313  0 thresholdValue.setText("");
314  0 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  0 updateThresholdPanelToolTip();
359  0 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  0 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  0 av.showAllHiddenColumns();
398  0 av.getColumnSelection().filterAnnotations(currentAnnotation,
399    filterParams);
400   
401  0 boolean hideCols = getActionOption() == ACTION_OPTION_HIDE;
402  0 if (hideCols)
403    {
404  0 av.hideSelectedColumns();
405    }
406  0 av.sendSelection();
407   
408  0 filterParams = null;
409  0 av.setAnnotationColumnSelectionState(this);
410    // only update overview and structures if columns were hidden
411  0 ap.paintAlignment(hideCols, hideCols);
412    }
413   
 
414  0 toggle public HiddenColumns getOldHiddenColumns()
415    {
416  0 return oldHiddenColumns;
417    }
418   
 
419  0 toggle public void setOldHiddenColumns(HiddenColumns currentHiddenColumns)
420    {
421  0 if (currentHiddenColumns != null)
422    {
423  0 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  0 toggle public SearchPanel getCurrentSearchPanel()
439    {
440  0 return currentSearchPanel;
441    }
442   
 
443  0 toggle public void setCurrentSearchPanel(SearchPanel currentSearchPanel)
444    {
445  0 this.currentSearchPanel = currentSearchPanel;
446    }
447   
 
448  0 toggle public int getActionOption()
449    {
450  0 return actionOption;
451    }
452   
 
453  0 toggle public void setActionOption(int actionOption)
454    {
455  0 this.actionOption = actionOption;
456    }
457   
 
458  0 toggle public StructureFilterPanel getCurrentStructureFilterPanel()
459    {
460  0 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  0 toggle @Override
496    public void selectedAnnotationChanged()
497    {
498  0 String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
499  0 if (av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
500    .getSelectedIndex()]].isQuantitative())
501    {
502  0 currentView = AnnotationColumnChooser.GRAPH_VIEW;
503    }
504  0 saveCache();
505  0 gSearchPanel.syncState();
506  0 gFurtherActionPanel.syncState();
507  0 gStructureFilterPanel.syncState();
508   
509  0 ngSearchPanel.syncState();
510  0 ngFurtherActionPanel.syncState();
511  0 ngStructureFilterPanel.syncState();
512   
513  0 CardLayout switchableViewsLayout = (CardLayout) switchableViewsPanel
514    .getLayout();
515  0 switchableViewsLayout.show(switchableViewsPanel, currentView);
516  0 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  0 toggle public FurtherActionPanel(AnnotationColumnChooser aColChooser)
530    {
531  0 this.aColChooser = aColChooser;
532  0 JvSwingUtils.jvInitComponent(selectOption, "action.select");
533  0 selectOption.addActionListener(new ActionListener()
534    {
 
535  0 toggle @Override
536    public void actionPerformed(ActionEvent actionEvent)
537    {
538  0 selectRadioAction(actionEvent);
539    }
540    });
541   
542  0 JvSwingUtils.jvInitComponent(hideOption, "action.hide");
543  0 hideOption.addActionListener(new ActionListener()
544    {
 
545  0 toggle @Override
546    public void actionPerformed(ActionEvent actionEvent)
547    {
548  0 hideRadioAction(actionEvent);
549    }
550    });
551   
552  0 optionsGroup.add(selectOption);
553  0 optionsGroup.add(hideOption);
554  0 optionsGroup.setSelected(selectOption.getModel(), true);
555   
556  0 JvSwingUtils.jvInitComponent(this);
557  0 syncState();
558   
559  0 this.add(selectOption);
560  0 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  0 toggle public void syncState()
576    {
577  0 if (aColChooser
578    .getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
579    {
580  0 this.optionsGroup.setSelected(this.hideOption.getModel(), true);
581    }
582    else
583    {
584  0 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  0 toggle public StructureFilterPanel(AnnotationColumnChooser aColChooser)
602    {
603  0 this.aColChooser = aColChooser;
604   
605  0 JvSwingUtils.jvInitComponent(alphaHelix, "label.alpha_helix");
606  0 alphaHelix.addActionListener(new ActionListener()
607    {
 
608  0 toggle @Override
609    public void actionPerformed(ActionEvent actionEvent)
610    {
611  0 alphaHelix_actionPerformed();
612    }
613    });
614   
615  0 JvSwingUtils.jvInitComponent(betaStrand, "label.beta_strand");
616  0 betaStrand.addActionListener(new ActionListener()
617    {
 
618  0 toggle @Override
619    public void actionPerformed(ActionEvent actionEvent)
620    {
621  0 betaStrand_actionPerformed();
622    }
623    });
624   
625  0 JvSwingUtils.jvInitComponent(turn, "label.turn");
626  0 turn.addActionListener(new ActionListener()
627    {
 
628  0 toggle @Override
629    public void actionPerformed(ActionEvent actionEvent)
630    {
631  0 turn_actionPerformed();
632    }
633    });
634   
635  0 JvSwingUtils.jvInitComponent(all, "label.select_all");
636  0 all.addActionListener(new ActionListener()
637    {
 
638  0 toggle @Override
639    public void actionPerformed(ActionEvent actionEvent)
640    {
641  0 all_actionPerformed();
642    }
643    });
644   
645  0 this.setBorder(new TitledBorder(
646    MessageManager.getString("label.structures_filter")));
647  0 JvSwingUtils.jvInitComponent(this);
648   
649  0 this.add(all);
650  0 this.add(alphaHelix);
651  0 this.add(betaStrand);
652  0 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  0 toggle public void syncState()
708    {
709  0 StructureFilterPanel sfp = aColChooser
710    .getCurrentStructureFilterPanel();
711  0 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  0 toggle public SearchPanel(AnnotationColumnChooser aColChooser)
742    {
743   
744  0 this.aColChooser = aColChooser;
745  0 JvSwingUtils.jvInitComponent(this);
746  0 this.setBorder(new TitledBorder(
747    MessageManager.getString("label.search_filter")));
748   
749  0 searchBox.getComponent().setToolTipText(
750    MessageManager.getString("info.enter_search_text_here"));
751  0 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  0 searchBox.addFocusListener(new FocusAdapter()
764    {
 
765  0 toggle @Override
766    public void focusLost(FocusEvent e)
767    {
768  0 searchStringAction();
769    }
770    });
771   
772  0 JvSwingUtils.jvInitComponent(displayName, "label.label");
773  0 displayName.addActionListener(new ActionListener()
774    {
 
775  0 toggle @Override
776    public void actionPerformed(ActionEvent actionEvent)
777    {
778  0 displayNameCheckboxAction();
779    }
780    });
781   
782  0 JvSwingUtils.jvInitComponent(description, "label.description");
783  0 description.addActionListener(new ActionListener()
784    {
 
785  0 toggle @Override
786    public void actionPerformed(ActionEvent actionEvent)
787    {
788  0 descriptionCheckboxAction();
789    }
790    });
791   
792  0 syncState();
793  0 this.add(searchBox.getComponent());
794  0 this.add(displayName);
795  0 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  0 toggle public void syncState()
819    {
820  0 SearchPanel sp = aColChooser.getCurrentSearchPanel();
821  0 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  0 updateSearchPanelToolTips();
832    }
833   
 
834  0 toggle public void updateSearchPanelToolTips()
835    {
836  0 String defaultTtip = MessageManager
837    .getString("info.enter_search_text_to_enable");
838  0 String labelTtip = MessageManager.formatMessage(
839    "info.search_in_annotation_label",
840    annotations.getSelectedItem().toString());
841  0 String descTtip = MessageManager.formatMessage(
842    "info.search_in_annotation_description",
843    annotations.getSelectedItem().toString());
844  0 displayName.setToolTipText(
845  0 displayName.isEnabled() ? labelTtip : defaultTtip);
846  0 description.setToolTipText(
847  0 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  0 toggle private void saveCache()
866    {
867  0 gSearchPanel.searchBox.persistCache();
868  0 ngSearchPanel.searchBox.persistCache();
869  0 gSearchPanel.searchBox.updateCache();
870  0 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    }