diff --git a/projects/samskivert/src/java/com/samskivert/swing/util/ButtonUtil.java b/projects/samskivert/src/java/com/samskivert/swing/util/ButtonUtil.java new file mode 100644 index 00000000..c2d461e7 --- /dev/null +++ b/projects/samskivert/src/java/com/samskivert/swing/util/ButtonUtil.java @@ -0,0 +1,37 @@ +// +// $Id: ButtonUtil.java,v 1.1 2002/12/04 23:58:22 ray Exp $ + +package com.samskivert.swing.util; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.AbstractButton; + +/** + * Utilities for buttons. + */ +public class ButtonUtil +{ + /** + * Set the specified button such that it alternates between being + * selected and not whenever it is pushed. + */ + public static synchronized void setToggling (AbstractButton b) + { + if (_toggler == null) { + _toggler = new ActionListener () { + public void actionPerformed (ActionEvent event) + { + AbstractButton but = (AbstractButton) event.getSource(); + but.setSelected(!but.isSelected()); + } + }; + } + + b.addActionListener(_toggler); + } + + /** Our lazily-initialized toggling action listener. */ + protected static ActionListener _toggler; +}