Package com.jidesoft.swing
Class TristateButtonModel
java.lang.Object
javax.swing.DefaultButtonModel
javax.swing.JToggleButton.ToggleButtonModel
com.jidesoft.swing.TristateButtonModel
- All Implemented Interfaces:
ItemSelectable
,Serializable
,ButtonModel
Model for TristateCheckBox. It introduces a mixed state to represent check box in the mixed selected state.
ActionEvent will be fired when the state is changed.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Identifies the "mixed" bit in the bitmask, which indicates that the button is partial selected.Fields inherited from class javax.swing.DefaultButtonModel
actionCommand, ARMED, changeEvent, ENABLED, group, listenerList, mnemonic, PRESSED, ROLLOVER, SELECTED, stateMask
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected int
getNextState
(int current) We rotate between STATE_UNSELECTED, STATE_SELECTED and STATE_MIXED.int
getState()
boolean
isMixed()
void
setMixed
(boolean b) void
setPressed
(boolean b) void
setSelected
(boolean b) void
setState
(int state) protected void
Updates the state when the mouse is clicked.Methods inherited from class javax.swing.JToggleButton.ToggleButtonModel
isSelected
Methods 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, setRollover
-
Field Details
-
MIXED
public static final int MIXEDIdentifies the "mixed" bit in the bitmask, which indicates that the button is partial selected.- See Also:
-
-
Constructor Details
-
TristateButtonModel
public TristateButtonModel()
-
-
Method Details
-
setState
public void setState(int state) -
getState
public int getState() -
getNextState
protected int getNextState(int current) We rotate between STATE_UNSELECTED, STATE_SELECTED and STATE_MIXED. Subclass can override this method to tell the check box what next state is. Here is the default implementation.if (current == TristateCheckBox.STATE_UNSELECTED) { return TristateCheckBox.STATE_SELECTED; } else if (current == TristateCheckBox.STATE_SELECTED) { return TristateCheckBox.STATE_MIXED; } else if (current == TristateCheckBox.STATE_MIXED) { return TristateCheckBox.STATE_UNSELECTED; }
- Parameters:
current
- the current state- Returns:
- the next state of the current state.
-
setPressed
public void setPressed(boolean b) - Specified by:
setPressed
in interfaceButtonModel
- Overrides:
setPressed
in classJToggleButton.ToggleButtonModel
-
updateState
protected void updateState()Updates the state when the mouse is clicked. The default implementation issetState(getNextState(getState()));
-
setSelected
public void setSelected(boolean b) - Specified by:
setSelected
in interfaceButtonModel
- Overrides:
setSelected
in classJToggleButton.ToggleButtonModel
-
isMixed
public boolean isMixed() -
setMixed
public void setMixed(boolean b)
-