be.ugent.caagt.swirl
Class GenericSelectionGroup<E>

java.lang.Object
  extended by be.ugent.caagt.swirl.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(boolean clearable)
          Create a selection group with a newly created selection model and no buttons.
GenericSelectionGroup(GenericSelectionModel<E> model, boolean clearable)
          Create a selection group with the given model.
 
Method Summary
 void add(javax.swing.AbstractButton button, E element)
          Add the given button to the group.
 void addChangeListener(javax.swing.event.ChangeListener listener)
          Register the listener with the model.
 java.lang.String getActionCommand()
          Return the action command of the currently selected button, or null if none is selected.
 GenericSelectionModel<E> getModel()
          The selection model used by this group.
 javax.swing.AbstractButton getSelectedButton()
          Return the button which is currently selected.
 E getSelection()
          Return the current selection.
 void removeChangeListener(javax.swing.event.ChangeListener listener)
          Unregister the listener from the model.
 void setSelection(E element)
          Set the current selection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericSelectionGroup

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


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.

GenericSelectionGroup

public GenericSelectionGroup(GenericSelectionModel<E> 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.
Method Detail

getModel

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


addChangeListener

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


removeChangeListener

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


add

public void add(javax.swing.AbstractButton button,
                E element)
Add the given button to the group.

Parameters:
button - Button to be added
element - Element which correspond to this button

getSelectedButton

public javax.swing.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.

getActionCommand

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


setSelection

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