public class ToggleWrapper extends Wrapper implements GenericListener
EMPTY_ELEMENT_ARRAY
Constructor and Description |
---|
ToggleWrapper()
Creates a toggle button with a default toggle model.
|
ToggleWrapper(ToggleModel toggle)
Creates a toggle button with a referent toggle model.
|
ToggleWrapper(ToggleModel toggle,
java.lang.String group)
Creates a toggle button with a referent toggle model and a group.
|
Modifier and Type | Method and Description |
---|---|
void |
addOnStateChangeListener(OnStateChangeListener listener)
Adds a listener on the state change event of the toggle.
|
void |
gainFocus()
Notifies the widget that it is now the focus owner of its panel.
|
ToggleModel |
getToggle()
Gets the toggle.
|
boolean |
handleEvent(int event)
Called by the system if a child of this composite is the owner of the focus of the active panel (recursively) and
have not consumed the specified event.
|
boolean |
isChecked()
Gets whether or not the toggle button is checked.
|
boolean |
isInState(State state)
Gets whether or not the element is in the given state.
|
void |
lostFocus()
Notifies the widget that it is no longer the focus owner of its panel.
|
void |
removeOnStateChangeListener(OnStateChangeListener listener)
Removes a listener on the state change event of the toggle.
|
void |
requestFocus()
Requests that the first child of this composite be set as the focus owner of its panel.
|
boolean |
requestFocus(int direction)
Sets a widget in this composite as the focus owner of its panel, if it is enabled, following the direction.
|
void |
setChecked(boolean checked)
Sets the state of the toggle.
|
void |
setGroup(java.lang.String groupName)
Sets the group of this toggle.
|
protected void |
setPressed(boolean pressed)
Sets the pressed state of the toggle.
|
void |
toggle()
Changes the state of the toggle to the inverse of the current state.
|
void |
update()
Something has changed.
|
contains, isAdjustedToChild, setAdjustedToChild, setBoundsContent, setWidget, validateContent
add, addClassSelector, getAttribute, getChild, getChildrenCount, getChildrenElements, getParentElement, getStyle, hasClassSelector, isTransparent, mergeStyle, removeAllClassSelectors, removeClassSelector, removeInstanceStyle, render, renderContent, setBounds, setClassSelectors, setEnabled, updateStyle, updateStyleOnly, validate
getFocus, getFocusIndex, getNext, getWidget, getWidgetAt, getWidgets, getWidgetsCount, hideNotify, iterator, remove, removeAllWidgets, requestFocusFrom, showNotify
getAbsoluteX, getAbsoluteX, getAbsoluteY, getAbsoluteY, getEventHandler, getHeight, getPanel, getParent, getPreferredHeight, getPreferredWidth, getRelativeX, getRelativeY, getWidth, getX, getY, hasFocus, invalidate, isEnabled, isShown, isValid, isVisible, repaint, repaint, revalidate, revalidateSubTree, setEventHandler, setLocation, setPreferredSize, setSize, setVisible
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getEventHandler, getHeight, getWidth, getX, getY, hideNotify, isShown, repaint, repaint, setEventHandler, showNotify
public ToggleWrapper()
Events received by the toggle button are forwarded to the referent toggle.
public ToggleWrapper(ToggleModel toggle)
Events received by the toggle button are forwarded to the referent toggle.
toggle
- the referent toggle.java.lang.NullPointerException
- if the toggle is null
.public ToggleWrapper(ToggleModel toggle, java.lang.String group)
Events received by the toggle button are forwarded to the referent toggle.
The toggle is registered in the group with the given name.
toggle
- the referent toggle.group
- the name of the toggle group.java.lang.NullPointerException
- if a parameter is null
.public ToggleModel getToggle()
public void setGroup(@Nullable java.lang.String groupName)
For each name, a toggle group is created to group the toggles (only one toggle selected at a time).
groupName
- the name of the toggle group.ToggleGroup
public void addOnStateChangeListener(OnStateChangeListener listener)
listener
- the listener to add.java.lang.NullPointerException
- if the given listener is null
.public void removeOnStateChangeListener(OnStateChangeListener listener)
listener
- the listener to add.public void setChecked(boolean checked)
If the toggle is not enabled or is already in the given state, nothing change.
checked
- the new state of the toggle.public void toggle()
If the toggle is not enabled, nothing change.
public boolean isChecked()
true
if the toggle button is checked otherwise false
.public void gainFocus()
Widget
The subclasses can override this method to add behavior.
gainFocus
in class StyledComposite
public void lostFocus()
Widget
The subclasses can override this method to add behavior.
lostFocus
in class StyledComposite
public boolean isInState(State state)
Element
isInState
in interface Element
isInState
in class StyledComposite
state
- the state to check.true
if the element is in the given state, false
otherwise.protected void setPressed(boolean pressed)
pressed
- the new pressed state of the toggle.public void update()
GenericListener
update
in interface GenericListener
public boolean handleEvent(int event)
Composite
Command#UP
, Command#DOWN
,
Command#LEFT
, and Command#RIGHT
commands to manage navigation in its children.handleEvent
in interface Renderable
handleEvent
in class Composite
event
- the event to handletrue
if the composite consume the event, false
otherwiseWidget.setEventHandler(EventHandler)
public void requestFocus()
Composite
If the composite does not contain any widgets, nothing is done.
If the composite is not in a panel hierarchy, nothing is done.
Identical to calling Composite.requestFocusFrom(int, int)
with MWT.RIGHT
as direction and 0
as from.
requestFocus
in class Composite
public boolean requestFocus(int direction) throws java.lang.IllegalArgumentException
Composite
The given direction must be one of MWT.UP
, MWT.DOWN
, MWT.LEFT
, MWT.RIGHT
.
If the widget is not in a panel hierarchy, nothing is done.
Identical to calling Composite.requestFocusFrom(int, int)
with one of MWT.DOWN
or MWT.RIGHT
as
direction and 0
as from, or one of MWT.LEFT
or MWT.UP
and
(getWidgetsCount() - 1)
as from.
requestFocus
in class Composite
direction
- the direction followed by the focustrue
if the composite take the focus, false
otherwisejava.lang.IllegalArgumentException
- if direction
is not a valid direction