Package uk.ac.starlink.util.gui
Class ValueButtonGroup<T>
- java.lang.Object
-
- javax.swing.ButtonGroup
-
- uk.ac.starlink.util.gui.ValueButtonGroup<T>
-
- All Implemented Interfaces:
java.io.Serializable
public class ValueButtonGroup<T> extends javax.swing.ButtonGroupExtends ButtonGroup by associating a value with each button.- Since:
- 11 Jan 2005
- Author:
- Mark Taylor
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description ValueButtonGroup()Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(javax.swing.AbstractButton button, T value)Adds a button and associates a value with it.voidaddChangeListener(javax.swing.event.ChangeListener listener)Adds a listener which will be notified whenever this group's selected value changes.TgetValue()Returns the currently selected value, that is the value associated with the currently selected button.voidremove(javax.swing.AbstractButton button)voidremoveChangeListener(javax.swing.event.ChangeListener listener)Removes a listener previously added byaddChangeListener.voidsetValue(T value)Sets the currently selected value.
-
-
-
Method Detail
-
add
public void add(javax.swing.AbstractButton button, T value)Adds a button and associates a value with it. Whenbuttonis selected,getValue()will returnvalue. You can usenullfor a value, but don't have two buttons with associated values which are equal.- Parameters:
button- buttonvalue- associated value
-
remove
public void remove(javax.swing.AbstractButton button)
- Overrides:
removein classjavax.swing.ButtonGroup
-
getValue
public T getValue()
Returns the currently selected value, that is the value associated with the currently selected button.- Returns:
- selected value
-
setValue
public void setValue(T value)
Sets the currently selected value. The associated button will be selected (and others deselected).valuemust be one of the values associated with a button in this group.- Parameters:
value- new value
-
addChangeListener
public void addChangeListener(javax.swing.event.ChangeListener listener)
Adds a listener which will be notified whenever this group's selected value changes.- Parameters:
listener- listener to add
-
removeChangeListener
public void removeChangeListener(javax.swing.event.ChangeListener listener)
Removes a listener previously added byaddChangeListener.- Parameters:
listener- listener to remove
-
-