Class TristateButtonModel

All Implemented Interfaces:
ItemSelectable, Serializable, ButtonModel

public class TristateButtonModel extends 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:
  • Field Details

    • MIXED

      public static final int MIXED
      Identifies 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 interface ButtonModel
      Overrides:
      setPressed in class JToggleButton.ToggleButtonModel
    • updateState

      protected void updateState()
      Updates the state when the mouse is clicked. The default implementation is
      
       setState(getNextState(getState()));
       
    • setSelected

      public void setSelected(boolean b)
      Specified by:
      setSelected in interface ButtonModel
      Overrides:
      setSelected in class JToggleButton.ToggleButtonModel
    • isMixed

      public boolean isMixed()
    • setMixed

      public void setMixed(boolean b)