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 newNullableToggleButtonModelwith a null initial state.NullableToggleButtonModel(Boolean initialState) Instantiates a newNullableToggleButtonModelwith the given initial state. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(Consumer<Boolean> listener) Adds a listener notified each time the state changes.getState()Returns the underlying valuebooleanvoidIterates between the states: null -> false -> truevoidremoveListener(Consumer<Boolean> listener) Removes the given listener.voidsetSelected(boolean selected) Sets the underlying state to true or falsevoidSets 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 newNullableToggleButtonModelwith a null initial state. -
NullableToggleButtonModel
Instantiates a newNullableToggleButtonModelwith the given initial state.- Parameters:
initialState- the initial state
-
-
Method Details
-
isSelected
public boolean isSelected()- Specified by:
isSelectedin interfaceButtonModel- Overrides:
isSelectedin 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:
setSelectedin interfaceButtonModel- Overrides:
setSelectedin 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
-