Module is.codion.swing.common.model
Class NullableToggleButtonModel
java.lang.Object
javax.swing.DefaultButtonModel
is.codion.swing.common.model.component.button.NullableToggleButtonModel
- All Implemented Interfaces:
ItemSelectable
,Serializable
,ButtonModel
A ToggleButtonModel implementation, which allows the null state.
The states are null -> false -> true.
Heavily influenced by TristateCheckBox by Heinz M. Kabutz
http://www.javaspecialists.eu/archive/Issue145.html
Included with permission.
- See Also:
-
Field Summary
FieldsFields inherited from class javax.swing.DefaultButtonModel
actionCommand, ARMED, changeEvent, ENABLED, group, listenerList, mnemonic, PRESSED, ROLLOVER, SELECTED, stateMask
-
Constructor Summary
ConstructorsConstructorDescriptionInstantiates a newNullableToggleButtonModel
with a null initial state.NullableToggleButtonModel
(Boolean initialState) Instantiates a newNullableToggleButtonModel
with the given initial state. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addListener
(Consumer<Boolean> listener) Adds a listener notified each time the state changes.getState()
Returns the underlying valueboolean
void
Iterates between the states: null -> false -> truevoid
removeListener
(Consumer<Boolean> listener) Removes the given listener.void
setSelected
(boolean selected) Sets the underlying state to true or falsevoid
Sets the underlying stateMethods inherited from class javax.swing.DefaultButtonModel
addActionListener, addChangeListener, addItemListener, fireActionPerformed, fireItemStateChanged, fireStateChanged, getActionCommand, getActionListeners, getChangeListeners, getGroup, getItemListeners, getListeners, getMnemonic, getSelectedObjects, isArmed, isEnabled, isPressed, isRollover, removeActionListener, removeChangeListener, removeItemListener, setActionCommand, setArmed, setEnabled, setGroup, setMnemonic, setPressed, setRollover
-
Field Details
-
NULL
public static final int NULLThe item state NULL.
-
-
Constructor Details
-
NullableToggleButtonModel
public NullableToggleButtonModel()Instantiates a newNullableToggleButtonModel
with a null initial state. -
NullableToggleButtonModel
Instantiates a newNullableToggleButtonModel
with the given initial state.- Parameters:
initialState
- the initial state
-
-
Method Details
-
isSelected
public boolean isSelected()- Specified by:
isSelected
in interfaceButtonModel
- Overrides:
isSelected
in classDefaultButtonModel
- Returns:
- true if the underlying state is true
-
setSelected
public void setSelected(boolean selected) Sets the underlying state to true or false- Specified by:
setSelected
in interfaceButtonModel
- Overrides:
setSelected
in classDefaultButtonModel
- Parameters:
selected
- the new state
-
setState
Sets the underlying state- Parameters:
state
- the state
-
getState
Returns the underlying value- Returns:
- the state
-
nextState
public void nextState()Iterates between the states: null -> false -> true -
addListener
Adds a listener notified each time the state changes.- Parameters:
listener
- the listener
-
removeListener
Removes the given listener.- Parameters:
listener
- the listener to remove
-