|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object be.ugent.caagt.swirl.SelectionGroup
public class SelectionGroup
Acts like a button group with associated single selection model. 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. Buttons are given an internal index as they are added to the group (starting at 0). When the selection model selects a new index, 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, either as an index, an action command or a button object.
A group like this is especially useful when the same set of choices must be available at the same time in different forms: as a set of radio button menu items and a set of toggle buttons in a tool bar, say. Implementing both groups as selection groups with the same model makes both groups automatically synchronized.
In the above example, the group of radio menu items would for instance be created as follows:
SelectionGroup menuGroup = new SelectionGroup (); JRadioButtonMenuItem item0 = new JRadioButtonMenuItem (...); JRadioButtonMenuItem item1 = new JRadioButtonMenuItem (...); JRadioButtonMenuItem item2 = new JRadioButtonMenuItem (...); menuGroup.add (item0); menuGroup.add (item1); menuGroup.add (item2);and the group of toggle buttons
SelectionGroup buttonGroup = new SelectionGroup (menuGroup.getModel(), true); JToggleButton button0 = new JToggleButton (...); JToggleButton button1 = new JToggleButton (...); JToggleButton button2 = new JToggleButton (...); buttonGroup.add(item0); buttonGroup.add(item1); buttonGroup.add(item2);To query which of the three buttons in each group is currently selected, use
menuGroup.getSelectedIndex()
or
buttonGroup.getSelectedIndex()
, which will both yield the same answer.
Alternatively, the selection model can be queried directly, or a change listener
may be registered with the selection model.
GenericSelectionGroup
Constructor Summary | |
---|---|
SelectionGroup()
Create a selection group with a newly created single selection model and no buttons. |
|
SelectionGroup(boolean clearable)
Create a selection group with a newly created single selection model and no buttons. |
|
SelectionGroup(javax.swing.SingleSelectionModel model,
boolean clearable)
Create a selection group with the given model. |
Method Summary | |
---|---|
void |
add(javax.swing.AbstractButton button)
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. |
javax.swing.SingleSelectionModel |
getModel()
The single selection model used by this group. |
javax.swing.AbstractButton |
getSelectedButton()
Return the button which is currently selected. |
int |
getSelectedIndex()
Return the current selection. |
void |
removeChangeListener(javax.swing.event.ChangeListener listener)
Unregister the listener form the model. |
void |
setSelectedIndex(int index)
Set the currently selected index. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SelectionGroup()
Selectiongroup (true)
.
public SelectionGroup(boolean clearable)
clearable
- indicates whether buttons can be cleared by clicking
on them. If false the group behaves like a button group.public SelectionGroup(javax.swing.SingleSelectionModel model, boolean clearable)
clearable
- indicates whether buttons can be cleared by clicking
on them. If false the group behaves like a button group.Method Detail |
---|
public javax.swing.SingleSelectionModel getModel()
public void addChangeListener(javax.swing.event.ChangeListener listener)
public void removeChangeListener(javax.swing.event.ChangeListener listener)
public void add(javax.swing.AbstractButton button)
public javax.swing.AbstractButton getSelectedButton()
public int getSelectedIndex()
public java.lang.String getActionCommand()
public void setSelectedIndex(int index)
index
- Index to be selected, or -1 to clear the selection.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |