Package org.apache.pivot.wtk
Class RadioButtonGroup
- java.lang.Object
-
- org.apache.pivot.wtk.ButtonGroup
-
- org.apache.pivot.wtk.RadioButtonGroup
-
public class RadioButtonGroup extends ButtonGroup
Extension ofButtonGroupproviding keyboard navigation within the group and modified focus navigation that treats the group as a single focusable entity.
UPandLEFTSelect the previous button
DOWNandRIGHTSelect the next button
HOMESelect the first button
ENDSelect the last button
(Note that onlyfocusablebuttons are considered when searching for a Button to select)
When a button within the group is focused and key is typed, an attempt is made to find the next button (default) or previous button (when the SHIFT modifier is pressed) whose renderer text starts with the typed character. This search will always behave as if thecircularproperty were set.
By default,TABandSHIFT+TABkey presses will transfer focus out of the group (forwards or backwards respectively). This is managed by theintraGroupFocusTransferEnabledproperty.
Thecircularproperty can be enabled to allow the selection to transfer seamlessly from one end of the group to the other. (i.e. holding down an arrow key will cycle through all focusable buttons)
Note that due to the conflicting return types of theadd(T)andremove(T)methods in theGroupandSequenceinterfaces, this class cannot actually implementSequence<Button>, although most of the same methods are implemented.
-
-
Constructor Summary
Constructors Constructor Description RadioButtonGroup()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(Button button)Add a button to the group.Buttonget(int index)intgetLength()intindexOf(Button button)Return the index (order) of the button within the group.voidinsert(Button button, int index)Insert a button at the specified index.booleanisCircular()booleanisIntraGroupFocusTransferEnabled()When true, TAB and SHIFT+TAB transfer focus out of the RadioButtonGroup.java.util.Iterator<Button>iterator()Sequence<Button>remove(int index, int count)Removecountbuttons from the group starting atindex.booleanremove(Button button)Remove the button from the group.voidselectFirstButton()Select the first focusable button in the group.voidselectLastButton()Select the last focusable button in the group.voidselectNextButton(Button button)Working forwards from the specified button, select the first focusable button.voidselectPreviousButton(Button button)Working backwards from the specified button, select the first focusable button.voidsetCircular(boolean circular)voidsetIntraGroupFocusTransferEnabled(boolean intraGroupFocusTransferEnabled)Controls whether TAB and SHIFT+TAB will transfer focus out of the RadioButtonGroup, or simply maintain their default behaviour.voidsetSelection(int index)Select and focus the button at the specified index, unless the index is NOT_FOUND_INDEX.voidsetSelection(Button button)Select and focus the specified button.-
Methods inherited from class org.apache.pivot.wtk.ButtonGroup
clearSelection, contains, getButtonGroupListeners, getSelection
-
-
-
-
Method Detail
-
isCircular
public boolean isCircular()
When enabled, a search for thepreviousornextfocusable button will not stop when the group's lower or upper bounds (respectively) are reached.
Instead, the search will 'wrap' and continue from the opposite bound until each button in the entire group has been tested for inclusion.
Defaults tofalse- Returns:
- Whether the group is circular.
-
setCircular
public void setCircular(boolean circular)
When enabled, a search for thepreviousornextfocusable button will not stop when the group's lower or upper bounds (respectively) are reached.
Instead, the search will 'wrap' and continue from the opposite bound until each button in the entire group has been tested for inclusion.- Parameters:
circular- New setting for the group.
-
isIntraGroupFocusTransferEnabled
public boolean isIntraGroupFocusTransferEnabled()
When true, TAB and SHIFT+TAB transfer focus out of the RadioButtonGroup.
Defaults tofalse- Returns:
- Whether focus transfers out of the group on TAB.
-
setIntraGroupFocusTransferEnabled
public void setIntraGroupFocusTransferEnabled(boolean intraGroupFocusTransferEnabled)
Controls whether TAB and SHIFT+TAB will transfer focus out of the RadioButtonGroup, or simply maintain their default behaviour.- Parameters:
intraGroupFocusTransferEnabled- New setting for this group.
-
add
public boolean add(Button button)
Add a button to the group.- Specified by:
addin interfaceGroup<Button>- Overrides:
addin classButtonGroup- Parameters:
button- The button to add.- Returns:
trueif the element was added to the group;false, otherwise.- Throws:
java.lang.IllegalArgumentException- if the button parameter isnull.- See Also:
Group.add(Object),Sequence.add(Object)
-
get
public Button get(int index)
- Parameters:
index- The location to retrieve the button from.- Returns:
- The button at the specified index.
- See Also:
Sequence.get(int)
-
getLength
public int getLength()
- Returns:
- The number of buttons in the group.
- See Also:
Sequence.getLength()
-
indexOf
public int indexOf(Button button)
Return the index (order) of the button within the group.- Parameters:
button- The button to search for in this group.- Returns:
- The index or
NOT_FOUND_INDEXif the button does not belong to this RadioButtonGroup. - See Also:
Sequence.indexOf(Object)
-
insert
public void insert(Button button, int index)
Insert a button at the specified index.- Parameters:
button- The button to be inserted.index- Where to insert the button.- Throws:
java.lang.IllegalArgumentException- if the button parameter isnull.- See Also:
Sequence.insert(Object, int)
-
remove
public boolean remove(Button button)
Remove the button from the group.- Specified by:
removein interfaceGroup<Button>- Overrides:
removein classButtonGroup- Parameters:
button- The button to remove from this group.- Returns:
- Success indicator.
- See Also:
Group.remove(Object),Sequence.remove(Object)
-
remove
public Sequence<Button> remove(int index, int count)
Removecountbuttons from the group starting atindex.- Parameters:
index- Starting point for the removal.count- Number of buttons to remove.- Returns:
- The sequence of buttons actually removed (will not be
null, but could be an empty sequence). - See Also:
Sequence.remove(int, int)
-
iterator
public java.util.Iterator<Button> iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<Button>- Overrides:
iteratorin classButtonGroup- Returns:
- An iterator for the ordered list of buttons
-
setSelection
public void setSelection(Button button)
Select and focus the specified button.- Overrides:
setSelectionin classButtonGroup- See Also:
ButtonGroup.setSelection(Button)
-
setSelection
public void setSelection(int index)
Select and focus the button at the specified index, unless the index is NOT_FOUND_INDEX.- Parameters:
index- The new selection index for the group.
-
selectFirstButton
public void selectFirstButton()
Select the first focusable button in the group.
-
selectLastButton
public void selectLastButton()
Select the last focusable button in the group.
-
selectNextButton
public void selectNextButton(Button button)
Working forwards from the specified button, select the first focusable button.- Parameters:
button- If null, the first available button will be selected, unless the group contains a selected or focused button, in which case that button will be used as the starting point for the search.
-
selectPreviousButton
public void selectPreviousButton(Button button)
Working backwards from the specified button, select the first focusable button.- Parameters:
button- If null, the last available button will be selected, unless the group contains a selected or focused button, in which case that button will be used as the starting point for the search.
-
-