Clover icon

Coverage Report

  1. Project Clover database Thu Aug 13 2020 12:04:21 BST
  2. Package jalview.gui

File JalviewBooleanRadioButtons.java

 

Coverage histogram

../../img/srcFileCovDistChart0.png
56% of files have more coverage

Code metrics

0
23
14
1
127
84
14
0.61
1.64
14
1

Classes

Class Line # Actions
JalviewBooleanRadioButtons 30 23 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    package jalview.gui;
22   
23    import java.awt.Font;
24    import java.awt.event.ActionListener;
25   
26    import javax.swing.AbstractButton;
27    import javax.swing.ButtonGroup;
28    import javax.swing.JRadioButton;
29   
 
30    public class JalviewBooleanRadioButtons extends AbstractButton
31    {
32    private static final Font LABEL_FONT = JvSwingUtils.getLabelFont();
33   
34    private ButtonGroup buttonGroup = new ButtonGroup();
35   
36    private JRadioButton buttonTrue = new JRadioButton();
37   
38    private JRadioButton buttonFalse = new JRadioButton();
39   
 
40  0 toggle public JalviewBooleanRadioButtons(boolean value, String trueLabel,
41    String falseLabel)
42    {
43  0 init();
44  0 this.setLabels(trueLabel, falseLabel);
45    }
46   
 
47  0 toggle public JalviewBooleanRadioButtons(boolean value)
48    {
49  0 init();
50  0 setSelected(value);
51    }
52   
 
53  0 toggle public JalviewBooleanRadioButtons()
54    {
55  0 init();
56    }
57   
 
58  0 toggle protected void init()
59    {
60  0 buttonTrue.setFont(LABEL_FONT);
61  0 buttonFalse.setFont(LABEL_FONT);
62  0 buttonGroup.add(buttonTrue);
63  0 buttonGroup.add(buttonFalse);
64    }
65   
 
66  0 toggle public void setLabels(String trueLabel, String falseLabel)
67    {
68  0 buttonTrue.setText(trueLabel);
69  0 buttonFalse.setText(falseLabel);
70    }
71   
 
72  0 toggle @Override
73    public void setSelected(boolean b)
74    {
75  0 buttonFalse.setSelected(!b);
76    // this should probably happen automatically, no harm in forcing the issue!
77    // setting them this way round so the last setSelected is on buttonTrue
78  0 buttonTrue.setSelected(b);
79    }
80   
 
81  0 toggle @Override
82    public boolean isSelected()
83    {
84    // unambiguous selection
85  0 return buttonTrue.isSelected() && !buttonFalse.isSelected();
86    }
87   
 
88  0 toggle @Override
89    public void setEnabled(boolean b)
90    {
91  0 buttonTrue.setEnabled(b);
92  0 buttonFalse.setEnabled(b);
93    }
94   
 
95  0 toggle @Override
96    public boolean isEnabled()
97    {
98  0 return buttonTrue.isEnabled() && buttonFalse.isEnabled();
99    }
100   
 
101  0 toggle public JRadioButton getTrueButton()
102    {
103  0 return buttonTrue;
104    }
105   
 
106  0 toggle public JRadioButton getFalseButton()
107    {
108  0 return buttonFalse;
109    }
110   
 
111  0 toggle @Override
112    public void addActionListener(ActionListener l)
113    {
114  0 buttonTrue.addActionListener(l);
115  0 buttonFalse.addActionListener(l);
116    }
117   
 
118  0 toggle public void addTrueActionListener(ActionListener l)
119    {
120  0 buttonTrue.addActionListener(l);
121    }
122   
 
123  0 toggle public void addFalseActionListener(ActionListener l)
124    {
125  0 buttonFalse.addActionListener(l);
126    }
127    }