--- /dev/null
+package jalview.gui;
+
+import java.awt.Font;
+import java.awt.event.ActionListener;
+
+import javax.swing.AbstractButton;
+import javax.swing.ButtonGroup;
+import javax.swing.JRadioButton;
+
+public class JalviewBooleanRadioButtons extends AbstractButton
+{
+ private static final Font LABEL_FONT = JvSwingUtils.getLabelFont();
+
+ private ButtonGroup buttonGroup = new ButtonGroup();
+
+ private JRadioButton buttonTrue = new JRadioButton();
+
+ private JRadioButton buttonFalse = new JRadioButton();
+
+ public JalviewBooleanRadioButtons(boolean value, String trueLabel,
+ String falseLabel)
+ {
+ init();
+ this.setLabels(trueLabel, falseLabel);
+ }
+
+ public JalviewBooleanRadioButtons(boolean value)
+ {
+ init();
+ setSelected(value);
+ }
+
+ public JalviewBooleanRadioButtons()
+ {
+ init();
+ }
+
+ protected void init()
+ {
+ buttonTrue.setFont(LABEL_FONT);
+ buttonFalse.setFont(LABEL_FONT);
+ buttonGroup.add(buttonTrue);
+ buttonGroup.add(buttonFalse);
+ }
+
+ public void setLabels(String trueLabel, String falseLabel)
+ {
+ buttonTrue.setText(trueLabel);
+ buttonFalse.setText(falseLabel);
+ }
+
+ @Override
+ public void setSelected(boolean b)
+ {
+ buttonFalse.setSelected(!b);
+ // this should probably happen automatically, no harm in forcing the issue!
+ // setting them this way round so the last setSelected is on buttonTrue
+ buttonTrue.setSelected(b);
+ }
+
+ @Override
+ public boolean isSelected()
+ {
+ // unambiguous selection
+ return buttonTrue.isSelected() && !buttonFalse.isSelected();
+ }
+
+ @Override
+ public void setEnabled(boolean b)
+ {
+ buttonTrue.setEnabled(b);
+ buttonFalse.setEnabled(b);
+ }
+
+ @Override
+ public boolean isEnabled()
+ {
+ return buttonTrue.isEnabled() && buttonFalse.isEnabled();
+ }
+
+ public JRadioButton getTrueButton()
+ {
+ return buttonTrue;
+ }
+
+ public JRadioButton getFalseButton()
+ {
+ return buttonFalse;
+ }
+
+ @Override
+ public void addActionListener(ActionListener l)
+ {
+ buttonTrue.addActionListener(l);
+ buttonFalse.addActionListener(l);
+ }
+
+ public void addTrueActionListener(ActionListener l)
+ {
+ buttonTrue.addActionListener(l);
+ }
+
+ public void addFalseActionListener(ActionListener l)
+ {
+ buttonFalse.addActionListener(l);
+ }
+}