be.ugent.caagt.swirl

Class GenericSelectionGroup<E>


public class GenericSelectionGroup<E>
extends java.lang.Object

Acts like a button group with associated generic selection model for type E. Similar to SelectionGroup but backed by a GenericSelectionModel instead of a SingleSelectionModel.

Of all toggle buttons added to a group of this kind, at most one can be selected at the same time. Every time a new selection is made, this is reported to the selection model. Each button added to the group is given an associated object of type E. When a new object is selected in the model, the corresponding button will be selected and the old button will be deselected.

Provides convenience methods to add listeners to the associated selection model and to determine what is the currently selected button.

Note: In typical applications of this class E will denote an enumeration type. It is always required that E has implementations of hashCode and equals that are compatible.

See Also:
SelectionGroup

Constructor Summary

GenericSelectionGroup()
Create a selection group with a newly created selection model and no buttons.
GenericSelectionGroup(GenericSelectionModel model, boolean clearable)
Create a selection group with the given model.
GenericSelectionGroup(boolean clearable)
Create a selection group with a newly created selection model and no buttons.

Method Summary

void
add(AbstractButton button, E element)
Add the given button to the group.
void
addChangeListener(ChangeListener listener)
Register the listener with the model.
String
getActionCommand()
Return the action command of the currently selected button, or null if none is selected.
GenericSelectionModel
getModel()
The selection model used by this group.
AbstractButton
getSelectedButton()
Return the button which is currently selected.
E
getSelection()
Return the current selection.
void
removeChangeListener(ChangeListener listener)
Unregister the listener from the model.
void
setSelection(E element)
Set the current selection.

Constructor Details

GenericSelectionGroup

public GenericSelectionGroup()
Create a selection group with a newly created selection model and no buttons. Short for GenericSelectiongroup(true).

GenericSelectionGroup

public GenericSelectionGroup(GenericSelectionModel model,
                             boolean clearable)
Create a selection group with the given model.
Parameters:
clearable - indicates whether buttons can be cleared by clicking on them. If false the group behaves like a button group.

GenericSelectionGroup

public GenericSelectionGroup(boolean clearable)
Create a selection group with a newly created selection model and no buttons.
Parameters:
clearable - indicates whether buttons can be cleared by clicking on them. If false the group behaves like a button group.

Method Details

add

public void add(AbstractButton button,
                E element)
Add the given button to the group.
Parameters:
button - Button to be added
element - Element which correspond to this button

addChangeListener

public void addChangeListener(ChangeListener listener)
Register the listener with the model.

getActionCommand

public String getActionCommand()
Return the action command of the currently selected button, or null if none is selected.

getModel

public GenericSelectionModel getModel()
The selection model used by this group.

getSelectedButton

public AbstractButton getSelectedButton()
Return the button which is currently selected.
Returns:
the currently selected button or null if none is selected

getSelection

public E getSelection()
Return the current selection.
Returns:
the current selection index or -1 if none.

removeChangeListener

public void removeChangeListener(ChangeListener listener)
Unregister the listener from the model.

setSelection

public void setSelection(E element)
Set the current selection.