public class ToggleModel
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected boolean |
checked
The state after the last change.
|
Constructor and Description |
---|
ToggleModel()
Creates an unchecked toggle.
|
ToggleModel(boolean checked)
Creates a toggle with the given initial state.
|
Modifier and Type | Method and Description |
---|---|
void |
addOnStateChangeListener(OnStateChangeListener listener)
Adds a listener on the state change event of the toggle.
|
protected void |
changeState(boolean checked)
Internal method that sets the state of the toggle without check and notify the group and notify the listener.
|
ToggleGroup |
getGroup()
Gets the group which contains the toggle button.
|
boolean |
isChecked()
Gets whether or not the toggle button is checked.
|
protected void |
notifyOnStateChangeListener(boolean newState)
Notifies the listeners that a state change event happened.
|
void |
removeOnStateChangeListener(OnStateChangeListener listener)
Removes a listener on the state change event of the toggle.
|
void |
setChecked(boolean checked)
Sets the state of the toggle.
|
void |
toggle()
Changes the state of the toggle to the inverse of the current state.
|
public ToggleModel()
public ToggleModel(boolean checked)
checked
- if true
, the toggle is initially checked, otherwise the toggle is initially unchecked.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 already in the given state, nothing change.
checked
- the new state of the toggle.public void toggle()
public boolean isChecked()
true
if the toggle button is checked otherwise false
.protected void changeState(boolean checked)
checked
- the new state of the toggle button.protected void notifyOnStateChangeListener(boolean newState)
newState
- the new state of the toggle.@Nullable public ToggleGroup getGroup()
null
if the toggle button has no group.