Class ToggleOrPressButtonModel

  • All Implemented Interfaces:
    java.awt.ItemSelectable, java.io.Serializable, javax.swing.ButtonModel

    public class ToggleOrPressButtonModel
    extends javax.swing.JToggleButton.ToggleButtonModel
    ToggleOrPressButtonModel handles the storage and maintenance of the state of the button.

    Changes the state of the function depending on the locking state of the button.

    Modified from http://developer.classpath.org/doc/javax/swing/JToggleButton-source.html

    Updates the button state depending if is lockable.

    Since:
    4.19.6
    See Also:
    Serialized Form
    • Field Summary

      • Fields inherited from class javax.swing.DefaultButtonModel

        actionCommand, ARMED, changeEvent, ENABLED, group, listenerList, mnemonic, PRESSED, ROLLOVER, SELECTED, stateMask
    • Constructor Summary

      Constructors 
      Constructor Description
      ToggleOrPressButtonModel​(javax.swing.JToggleButton button, boolean startLockable)
      Create a new ToggleOrPressButtonModel.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean getLockable()
      Get if Button is Lockable.
      void setLockable​(boolean lockable)
      Set button lockable state.
      void setPressed​(boolean p)
      Sets the pressed state of the button.
      void updateSelected​(boolean p)
      An external change has happened so we update.
      • Methods inherited from class javax.swing.JToggleButton.ToggleButtonModel

        isSelected, setSelected
      • 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
    • Constructor Detail

      • ToggleOrPressButtonModel

        public ToggleOrPressButtonModel​(javax.swing.JToggleButton button,
                                        boolean startLockable)
        Create a new ToggleOrPressButtonModel.
        Parameters:
        button - the button being controlled.
        startLockable - true to start as a toggle button, false to start as a click on / release off button.
    • Method Detail

      • setLockable

        public void setLockable​(boolean lockable)
        Set button lockable state.

        Lockable on - Normal Toggle button. Lockable off - push on, release off.

        If button is set unlocked when pressed, is de-pressed.

        Parameters:
        lockable - true for lockable, else false.
      • getLockable

        public boolean getLockable()
        Get if Button is Lockable.
        Returns:
        true if normal toggle button, false if push on release off.
      • updateSelected

        public void updateSelected​(boolean p)
        An external change has happened so we update.
        Parameters:
        p - new Selected state.
      • setPressed

        public void setPressed​(boolean p)
        Sets the pressed state of the button.

        The selected state of the button also changes following the button being pressed.

        Specified by:
        setPressed in interface javax.swing.ButtonModel
        Overrides:
        setPressed in class javax.swing.JToggleButton.ToggleButtonModel
        Parameters:
        p - true if the button is pressed down.