Package com.jidesoft.swing
Class TristateButtonModel
- java.lang.Object
-
- javax.swing.DefaultButtonModel
-
- javax.swing.JToggleButton.ToggleButtonModel
-
- com.jidesoft.swing.TristateButtonModel
-
- All Implemented Interfaces:
java.awt.ItemSelectable
,java.io.Serializable
,javax.swing.ButtonModel
public class TristateButtonModel extends javax.swing.JToggleButton.ToggleButtonModel
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:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static int
MIXED
Identifies the "mixed" bit in the bitmask, which indicates that the button is partial selected.
-
Constructor Summary
Constructors Constructor Description TristateButtonModel()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected 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
updateState()
Updates the state when the mouse is clicked.-
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 Detail
-
MIXED
public static final int MIXED
Identifies the "mixed" bit in the bitmask, which indicates that the button is partial selected.- See Also:
- Constant Field Values
-
-
Method Detail
-
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 interfacejavax.swing.ButtonModel
- Overrides:
setPressed
in classjavax.swing.JToggleButton.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 interfacejavax.swing.ButtonModel
- Overrides:
setSelected
in classjavax.swing.JToggleButton.ToggleButtonModel
-
isMixed
public boolean isMixed()
-
setMixed
public void setMixed(boolean b)
-
-