Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.gui

File AnnotationColumnChooser.java

 

Coverage histogram

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

Code metrics

70
306
50
4
857
693
88
0.29
6.12
12.5
1.76

Classes

Class Line # Actions
AnnotationColumnChooser 54 193 50 113
0.5783582357.8%
AnnotationColumnChooser.FurtherActionPanel 503 21 7 12
0.586206958.6%
AnnotationColumnChooser.StructureFilterPanel 573 50 17 49
0.2898550629%
AnnotationColumnChooser.SearchPanel 712 42 14 31
0.4833333248.3%
 

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