Clover icon

Coverage Report

  1. Project Clover database Fri Jul 3 2026 13:27:51 BST
  2. Package jalview.gui

File SliderPanel.java

 

Coverage histogram

../../img/srcFileCovDistChart7.png
30% of files have more coverage

Code metrics

64
165
29
1
624
429
72
0.44
5.69
29
2.48

Classes

Class Line # Actions
SliderPanel 47 165 72
0.635658963.6%
 

Contributing tests

This file is covered by 20 tests. .

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    package jalview.gui;
22   
23    import java.awt.event.MouseAdapter;
24    import java.awt.event.MouseEvent;
25    import java.beans.PropertyVetoException;
26    import java.util.List;
27   
28    import javax.swing.JInternalFrame;
29    import javax.swing.JLayeredPane;
30    import javax.swing.event.ChangeEvent;
31    import javax.swing.event.ChangeListener;
32    import javax.swing.event.InternalFrameAdapter;
33    import javax.swing.event.InternalFrameEvent;
34   
35    import jalview.analysis.Conservation;
36    import jalview.datamodel.SequenceGroup;
37    import jalview.jbgui.GSliderPanel;
38    import jalview.renderer.ResidueShaderI;
39    import jalview.util.MessageManager;
40   
41    /**
42    * DOCUMENT ME!
43    *
44    * @author $author$
45    * @version $Revision$
46    */
 
47    public class SliderPanel extends GSliderPanel
48    {
49    private static final String BACKGROUND = "Background";
50   
51    static JInternalFrame conservationSlider;
52   
53    static JInternalFrame consensusSecondaryStructureSlider;
54   
55    static JInternalFrame PIDSlider;
56   
57    AlignmentPanel ap;
58   
59    boolean forConservation = true;
60   
61    boolean forConsensusSecondaryStructure = false;
62   
63    ResidueShaderI cs;
64   
65    /**
66    * Returns the currently displayed slider panel (or null if none).
67    *
68    * @return
69    */
 
70  19 toggle public static SliderPanel getSliderPanel()
71    {
72  19 if (conservationSlider != null && conservationSlider.isVisible())
73    {
74  10 return (SliderPanel) conservationSlider.getContentPane();
75    }
76  9 if (PIDSlider != null && PIDSlider.isVisible())
77    {
78  9 return (SliderPanel) PIDSlider.getContentPane();
79    }
80  0 if (consensusSecondaryStructureSlider != null
81    && consensusSecondaryStructureSlider.isVisible())
82    {
83  0 return (SliderPanel) consensusSecondaryStructureSlider
84    .getContentPane();
85    }
86  0 return null;
87    }
88   
89    /**
90    * Creates a new SliderPanel object.
91    *
92    * @param ap
93    * DOCUMENT ME!
94    * @param value
95    * DOCUMENT ME!
96    * @param forConserve
97    * DOCUMENT ME!
98    * @param scheme
99    * DOCUMENT ME!
100    */
 
101  17 toggle public SliderPanel(final AlignmentPanel ap, int value,
102    boolean forConserve, boolean forConsensusSS,
103    ResidueShaderI scheme)
104    {
105  17 this.ap = ap;
106  17 this.cs = scheme;
107  17 forConservation = forConserve;
108  17 forConsensusSecondaryStructure = forConsensusSS;
109   
110  17 undoButton.setVisible(false);
111  17 applyButton.setVisible(false);
112   
113  17 if (forConservation)
114    {
115  7 label.setText(MessageManager.getString(
116    "label.enter_value_increase_conservation_visibility"));
117  7 slider.setMinimum(0);
118  7 slider.setMaximum(100);
119  10 } else if (forConsensusSS)
120    {
121  0 label.setText(MessageManager.getString(
122    "label.enter_value_increase_conservation_visibility"));
123  0 slider.setMinimum(0);
124  0 slider.setMaximum(100);
125    }
126    else
127    {
128  10 label.setText(MessageManager.getString(
129    "label.enter_percentage_identity_above_which_colour_residues"));
130  10 slider.setMinimum(0);
131  10 slider.setMaximum(100);
132    }
133   
134  17 slider.addChangeListener(new ChangeListener()
135    {
 
136  17 toggle @Override
137    public void stateChanged(ChangeEvent evt)
138    {
139  17 valueField.setText(String.valueOf(slider.getValue()));
140  17 valueChanged(slider.getValue());
141    }
142    });
143   
144  17 slider.addMouseListener(new MouseAdapter()
145    {
 
146  0 toggle @Override
147    public void mouseReleased(MouseEvent evt)
148    {
149  0 ap.paintAlignment(true, true);
150    }
151    });
152   
153  17 slider.setValue(value);
154  17 valueField.setText(String.valueOf(value));
155    }
156   
157    /**
158    * Method to 'set focus' of the Conservation slider panel
159    *
160    * @param ap
161    * the panel to repaint on change of slider
162    * @param rs
163    * the colour scheme to update on change of slider
164    * @param source
165    * a text description for the panel's title
166    *
167    * @return
168    */
 
169  11 toggle public static int setConservationSlider(AlignmentPanel ap,
170    ResidueShaderI rs, String source)
171    {
172  11 SliderPanel sliderPanel = null;
173   
174  11 if (conservationSlider == null)
175    {
176  7 sliderPanel = new SliderPanel(ap, rs.getConservationInc(), true,
177    false, rs);
178  7 conservationSlider = new JInternalFrame();
179  7 conservationSlider.setFrameIcon(null);
180  7 conservationSlider.setContentPane(sliderPanel);
181  7 conservationSlider.setLayer(JLayeredPane.PALETTE_LAYER);
182    }
183    else
184    {
185  4 sliderPanel = (SliderPanel) conservationSlider.getContentPane();
186  4 sliderPanel.valueField
187    .setText(String.valueOf(rs.getConservationInc()));
188  4 sliderPanel.cs = rs;
189  4 sliderPanel.ap = ap;
190  4 sliderPanel.slider.setValue(rs.getConservationInc());
191    }
192   
193  11 conservationSlider.setTitle(MessageManager.formatMessage(
194    "label.conservation_colour_increment", new String[]
195  11 { source == null ? BACKGROUND : source }));
196   
197  11 List<SequenceGroup> groups = ap.av.getAlignment().getGroups();
198  11 if (groups != null && !groups.isEmpty())
199    {
200  6 sliderPanel.setAllGroupsCheckEnabled(true);
201  6 sliderPanel.allGroupsCheck
202    .setSelected(ap.av.getColourAppliesToAllGroups());
203    }
204    else
205    {
206  5 sliderPanel.setAllGroupsCheckEnabled(false);
207    }
208   
209  11 return sliderPanel.getValue();
210    }
211   
212    /**
213    * Hides the PID slider panel if it is shown
214    */
 
215  170 toggle public static void hidePIDSlider()
216    {
217  170 if (PIDSlider != null)
218    {
219  8 try
220    {
221  8 PIDSlider.setClosed(true);
222  8 PIDSlider = null;
223    } catch (PropertyVetoException ex)
224    {
225    }
226    }
227    }
228   
229    /**
230    * Hides the conservation slider panel if it is shown
231    */
 
232  169 toggle public static void hideConservationSlider()
233    {
234  169 if (conservationSlider != null)
235    {
236  6 try
237    {
238  6 conservationSlider.setClosed(true);
239  6 conservationSlider = null;
240    } catch (PropertyVetoException ex)
241    {
242    }
243    }
244    }
245   
246    /**
247    * DOCUMENT ME!
248    */
 
249  9 toggle public static void showConservationSlider()
250    {
251  9 hidePIDSlider();
252   
253  9 if (!conservationSlider.isVisible())
254    {
255  7 Desktop.addInternalFrame(conservationSlider,
256    conservationSlider.getTitle(), true, FRAME_WIDTH,
257    FRAME_HEIGHT, false, true);
258  7 conservationSlider.addInternalFrameListener(new InternalFrameAdapter()
259    {
 
260  7 toggle @Override
261    public void internalFrameClosed(InternalFrameEvent e)
262    {
263  7 conservationSlider = null;
264    }
265    });
266  7 conservationSlider.setLayer(JLayeredPane.PALETTE_LAYER);
267    }
268    }
269   
 
270  0 toggle public static int setConsensusSecondaryStructureSlider(AlignmentPanel ap,
271    ResidueShaderI rs, String source)
272    {
273  0 SliderPanel sliderPanel = null;
274   
275  0 if (consensusSecondaryStructureSlider == null)
276    {
277  0 sliderPanel = new SliderPanel(ap,
278    rs.getConsensusSecondaryStructureThreshold(), false, true,
279    rs);
280  0 consensusSecondaryStructureSlider = new JInternalFrame();
281  0 consensusSecondaryStructureSlider.setFrameIcon(null);
282  0 consensusSecondaryStructureSlider.setContentPane(sliderPanel);
283  0 consensusSecondaryStructureSlider
284    .setLayer(JLayeredPane.PALETTE_LAYER);
285    }
286    else
287    {
288  0 sliderPanel = (SliderPanel) consensusSecondaryStructureSlider
289    .getContentPane();
290  0 sliderPanel.valueField.setText(
291    String.valueOf(rs.getConsensusSecondaryStructureThreshold()));
292  0 sliderPanel.cs = rs;
293  0 sliderPanel.ap = ap;
294  0 sliderPanel.slider
295    .setValue(rs.getConsensusSecondaryStructureThreshold());
296    }
297   
298  0 consensusSecondaryStructureSlider.setTitle(MessageManager.formatMessage(
299    "label.secondary_structure_conservation_threshold", new String[]
300  0 { source == null ? BACKGROUND : source }));
301   
302  0 List<SequenceGroup> groups = ap.av.getAlignment().getGroups();
303  0 if (groups != null && !groups.isEmpty())
304    {
305  0 sliderPanel.setAllGroupsCheckEnabled(true);
306  0 sliderPanel.allGroupsCheck
307    .setSelected(ap.av.getColourAppliesToAllGroups());
308    }
309    else
310    {
311  0 sliderPanel.setAllGroupsCheckEnabled(false);
312    }
313   
314  0 return sliderPanel.getValue();
315    }
316   
 
317  160 toggle public static void hideConsensusSecondaryStructureSlider()
318    {
319  160 if (consensusSecondaryStructureSlider != null)
320    {
321  0 try
322    {
323  0 consensusSecondaryStructureSlider.setClosed(true);
324  0 consensusSecondaryStructureSlider = null;
325    } catch (PropertyVetoException ex)
326    {
327    }
328    }
329    }
330   
 
331  0 toggle public static void showConsensusSecondaryStructureSlider()
332    {
333  0 hidePIDSlider();
334  0 hideConservationSlider();
335   
336  0 if (!consensusSecondaryStructureSlider.isVisible())
337    {
338  0 Desktop.addInternalFrame(consensusSecondaryStructureSlider,
339    consensusSecondaryStructureSlider.getTitle(), true,
340    FRAME_WIDTH, FRAME_HEIGHT, false, true);
341  0 consensusSecondaryStructureSlider
342    .addInternalFrameListener(new InternalFrameAdapter()
343    {
 
344  0 toggle @Override
345    public void internalFrameClosed(InternalFrameEvent e)
346    {
347  0 consensusSecondaryStructureSlider = null;
348    }
349    });
350  0 consensusSecondaryStructureSlider
351    .setLayer(JLayeredPane.PALETTE_LAYER);
352    }
353    }
354   
355    /**
356    * Method to 'set focus' of the PID slider panel
357    *
358    * @param ap
359    * the panel to repaint on change of slider
360    * @param rs
361    * the colour scheme to update on change of slider
362    * @param source
363    * a text description for the panel's title
364    *
365    * @return
366    */
 
367  11 toggle public static int setPIDSliderSource(AlignmentPanel ap, ResidueShaderI rs,
368    String source)
369    {
370  11 int threshold = rs.getThreshold();
371   
372  11 SliderPanel sliderPanel = null;
373   
374  11 if (PIDSlider == null)
375    {
376  10 sliderPanel = new SliderPanel(ap, threshold, false, false, rs);
377  10 PIDSlider = new JInternalFrame();
378  10 PIDSlider.setFrameIcon(null);
379  10 PIDSlider.setContentPane(sliderPanel);
380  10 PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER);
381    }
382    else
383    {
384  1 sliderPanel = (SliderPanel) PIDSlider.getContentPane();
385  1 sliderPanel.cs = rs;
386  1 sliderPanel.ap = ap;
387  1 sliderPanel.valueField.setText(String.valueOf(rs.getThreshold()));
388  1 sliderPanel.slider.setValue(rs.getThreshold());
389    }
390   
391  11 PIDSlider.setTitle(MessageManager.formatMessage(
392    "label.percentage_identity_threshold", new String[]
393  11 { source == null ? BACKGROUND : source }));
394   
395  11 if (ap.av.getAlignment().getGroups() != null)
396    {
397  11 sliderPanel.setAllGroupsCheckEnabled(true);
398    }
399    else
400    {
401  0 sliderPanel.setAllGroupsCheckEnabled(false);
402    }
403   
404  11 return sliderPanel.getValue();
405    }
406   
407    /**
408    * DOCUMENT ME!
409    *
410    * @return
411    */
 
412  9 toggle public static JInternalFrame showPIDSlider()
413    {
414  9 hideConservationSlider();
415   
416  9 if (!PIDSlider.isVisible())
417    {
418  9 Desktop.addInternalFrame(PIDSlider, PIDSlider.getTitle(), true,
419    FRAME_WIDTH, FRAME_HEIGHT, false, true);
420  9 PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER);
421  9 PIDSlider.addInternalFrameListener(new InternalFrameAdapter()
422    {
 
423  9 toggle @Override
424    public void internalFrameClosed(InternalFrameEvent e)
425    {
426  9 PIDSlider = null;
427    }
428    });
429  9 PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER);
430    }
431  9 return PIDSlider;
432    }
433   
434    /**
435    * Updates the colour scheme with the current (identity threshold or
436    * conservation) percentage value. Also updates all groups if 'apply to all
437    * groups' is selected.
438    *
439    * @param percent
440    */
 
441  37 toggle public void valueChanged(int percent)
442    {
443  37 if (!forConservation && !forConsensusSecondaryStructure)
444    {
445  21 ap.av.setThreshold(percent);
446    }
447  37 updateColourScheme(percent, cs, null);
448   
449  37 if (allGroupsCheck.isSelected())
450    {
451  2 List<SequenceGroup> groups = ap.av.getAlignment().getGroups();
452  2 for (SequenceGroup sg : groups)
453    {
454  2 updateColourScheme(percent, sg.getGroupColourScheme(), sg);
455    }
456    }
457   
458  37 ap.getSeqPanel().seqCanvas.repaint();
459    }
460   
461    /**
462    * Updates the colour scheme (if not null) with the current (identity
463    * threshold or conservation) percentage value
464    *
465    * @param percent
466    * @param scheme
467    * @param sg
468    */
 
469  39 toggle protected void updateColourScheme(int percent, ResidueShaderI scheme,
470    SequenceGroup sg)
471    {
472  39 if (scheme == null)
473    {
474  0 return;
475    }
476  39 if (forConservation)
477    {
478  18 if (!scheme.conservationApplied() && sg != null)
479    {
480    /*
481    * first time the colour scheme has had Conservation shading applied
482    * - compute conservation
483    */
484  0 Conservation c = new Conservation("Group", sg.getSequences(null),
485    sg.getStartRes(), sg.getEndRes());
486  0 c.calculate();
487  0 c.verdict(false, ap.av.getConsPercGaps());
488  0 sg.cs.setConservation(c);
489   
490    }
491  18 scheme.setConservationApplied(true);
492  18 scheme.setConservationInc(percent);
493    }
494  21 else if(forConsensusSecondaryStructure)
495    {
496  0 scheme.setConsensusSecondaryStructureColouring(true);
497  0 scheme.setConsensusSecondaryStructureThreshold(percent);
498    }
499    else
500    {
501  21 scheme.setThreshold(percent, ap.av.isIgnoreGapsConsensus());
502   
503    }
504    }
505   
506    /**
507    * DOCUMENT ME!
508    *
509    * @param b
510    * DOCUMENT ME!
511    */
 
512  22 toggle public void setAllGroupsCheckEnabled(boolean b)
513    {
514  22 allGroupsCheck.setEnabled(b);
515    }
516   
517    /**
518    * DOCUMENT ME!
519    *
520    * @param e
521    * DOCUMENT ME!
522    */
 
523  0 toggle @Override
524    public void valueField_actionPerformed()
525    {
526  0 try
527    {
528  0 int i = Integer.parseInt(valueField.getText());
529  0 slider.setValue(i);
530    } catch (NumberFormatException ex)
531    {
532  0 valueField.setText(slider.getValue() + "");
533    }
534    }
535   
536    /**
537    * DOCUMENT ME!
538    *
539    * @param value
540    * DOCUMENT ME!
541    */
 
542  0 toggle public void setValue(int value)
543    {
544  0 slider.setValue(value);
545    }
546   
547    /**
548    * DOCUMENT ME!
549    *
550    * @return DOCUMENT ME!
551    */
 
552  24 toggle public int getValue()
553    {
554  24 return Integer.parseInt(valueField.getText());
555    }
556   
 
557  0 toggle @Override
558    public void slider_mouseReleased(MouseEvent e)
559    {
560  0 if (ap.overviewPanel != null)
561    {
562  0 ap.overviewPanel.updateOverviewImage();
563    }
564    }
565   
 
566  0 toggle public static int getConservationValue()
567    {
568  0 return getValue(conservationSlider);
569    }
570   
 
571  0 toggle static int getValue(JInternalFrame slider)
572    {
573  0 return slider == null ? 0
574    : ((SliderPanel) slider.getContentPane()).getValue();
575    }
576   
 
577  0 toggle public static int getPIDValue()
578    {
579  0 return getValue(PIDSlider);
580    }
581   
 
582  0 toggle public static int getConsensusSecondaryStructureSliderValue()
583    {
584  0 return getValue(consensusSecondaryStructureSlider);
585    }
586   
587    /**
588    * Answers true if the SliderPanel is for Conservation, false if it is for PID
589    * threshold
590    *
591    * @return
592    */
 
593  24 toggle public boolean isForConservation()
594    {
595  24 return forConservation;
596    }
597   
598    /**
599    * Answers the title for the slider panel; this may include 'Background' if
600    * for the alignment, or the group id if for a group
601    *
602    * @return
603    */
 
604  6 toggle public String getTitle()
605    {
606  6 String title = null;
607  6 if (isForConservation())
608    {
609  4 if (conservationSlider != null)
610    {
611  4 title = conservationSlider.getTitle();
612    }
613    }
614  2 else if (PIDSlider != null)
615    {
616  2 title = PIDSlider.getTitle();
617    }
618  0 else if (consensusSecondaryStructureSlider != null)
619    {
620  0 title = consensusSecondaryStructureSlider.getTitle();
621    }
622  6 return title;
623    }
624    }