2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
24 import java.awt.event.ActionListener;
26 import javax.swing.AbstractButton;
27 import javax.swing.ButtonGroup;
28 import javax.swing.JRadioButton;
30 public class JalviewBooleanRadioButtons extends AbstractButton
32 private static final Font LABEL_FONT = JvSwingUtils.getLabelFont();
34 private ButtonGroup buttonGroup = new ButtonGroup();
36 private JRadioButton buttonTrue = new JRadioButton();
38 private JRadioButton buttonFalse = new JRadioButton();
40 public JalviewBooleanRadioButtons(boolean value, String trueLabel,
44 this.setLabels(trueLabel, falseLabel);
47 public JalviewBooleanRadioButtons(boolean value)
53 public JalviewBooleanRadioButtons()
60 buttonTrue.setFont(LABEL_FONT);
61 buttonFalse.setFont(LABEL_FONT);
62 buttonGroup.add(buttonTrue);
63 buttonGroup.add(buttonFalse);
66 public void setLabels(String trueLabel, String falseLabel)
68 buttonTrue.setText(trueLabel);
69 buttonFalse.setText(falseLabel);
73 public void setSelected(boolean b)
75 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 buttonTrue.setSelected(b);
82 public boolean isSelected()
84 // unambiguous selection
85 return buttonTrue.isSelected() && !buttonFalse.isSelected();
89 public void setEnabled(boolean b)
91 buttonTrue.setEnabled(b);
92 buttonFalse.setEnabled(b);
96 public boolean isEnabled()
98 return buttonTrue.isEnabled() && buttonFalse.isEnabled();
101 public JRadioButton getTrueButton()
106 public JRadioButton getFalseButton()
112 public void addActionListener(ActionListener l)
114 buttonTrue.addActionListener(l);
115 buttonFalse.addActionListener(l);
118 public void addTrueActionListener(ActionListener l)
120 buttonTrue.addActionListener(l);
123 public void addFalseActionListener(ActionListener l)
125 buttonFalse.addActionListener(l);