Class 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.
      • Fields inherited from class javax.swing.DefaultButtonModel

        actionCommand, ARMED, changeEvent, ENABLED, group, listenerList, mnemonic, PRESSED, ROLLOVER, SELECTED, stateMask
    • 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.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
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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
    • Constructor Detail

      • TristateButtonModel

        public TristateButtonModel()
    • 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 interface javax.swing.ButtonModel
        Overrides:
        setPressed in class javax.swing.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 javax.swing.ButtonModel
        Overrides:
        setSelected in class javax.swing.JToggleButton.ToggleButtonModel
      • isMixed

        public boolean isMixed()
      • setMixed

        public void setMixed​(boolean b)