Package uk.ac.starlink.topcat

## Class ToggleButtonModel

- java.lang.Object
- - javax.swing.DefaultButtonModel
  - - javax.swing.JToggleButton.ToggleButtonModel
    - - uk.ac.starlink.topcat.ToggleButtonModel

- All Implemented Interfaces:
    `java.awt.ItemSelectable`, `java.io.Serializable`, `javax.swing.ButtonModel`
  Direct Known Subclasses:
    `WindowToggle`

      public class ToggleButtonModel
      extends javax.swing.JToggleButton.ToggleButtonModel

  Provides all information about a toggle button. This is not only it's current on/off status (selection state in swing talk), but also the button's name, tooltip etc. Swing doesn't provide a model/action for this, so this class does it instead. Factory methods are provided to create Swing components that use this as their model.
  Since:
    3 Nov 2005
  Author:
    Mark Taylor
  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
    --- | ---
    `ToggleButtonModel​(java.lang.String text, javax.swing.Icon icon, java.lang.String shortdesc)` | Constructor.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `javax.swing.JToggleButton` | `createButton()` | Creates and returns a normal button using this model.
    `javax.swing.JCheckBox` | `createCheckBox()` | Creates and returns a check box using this model.
    `javax.swing.JCheckBoxMenuItem` | `createMenuItem()` | Creates and returns a menu item using this model.
    `javax.swing.JRadioButton[]` | `createRadioButtons​(java.lang.String name0, java.lang.String name1)` | Creates and returns a pair of radio buttons using this model.
    `javax.swing.JToggleButton` | `createToolbarButton()` | Creates and returns a button suitable for use in a toolbar using this model.
    `void` | `fireActionPerformed​(java.awt.event.ActionEvent evt)` |
    `java.lang.String` | `getDescription()` | Returns the description (for tooltips etc) associated with this model.
    `javax.swing.Icon` | `getIcon()` | Returns the icon associated with this model.
    `java.lang.String` | `getText()` | Returns the text label associated with this model.
    `boolean` | `isSelected()` | Returns the state of this model.
    `void` | `setDescription​(java.lang.String shortdesc)` | Sets the description (for tooltips etc) associated with this model.
    `void` | `setIcon​(javax.swing.Icon icon)` | Sets the icon associated with this model.
    `void` | `setSelected​(boolean state)` | Sets the state of this model.
    `void` | `setText​(java.lang.String text)` | Sets the text label associated with this model.

    - ### Methods inherited from class javax.swing.DefaultButtonModel

      `addActionListener, addChangeListener, addItemListener, 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 javax.swing.JToggleButton.ToggleButtonModel

      `setPressed`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ToggleButtonModel

          public ToggleButtonModel​(java.lang.String text,
                                   javax.swing.Icon icon,
                                   java.lang.String shortdesc)

      Constructor.
      Parameters:
        `text` - text to be used on buttons etc
        `icon` - icon to be used on buttons etc
        `shortdesc` - short description to be used for tool tips etc

  - ### Method Detail

    - #### setText

          public void setText​(java.lang.String text)

      Sets the text label associated with this model.
      Parameters:
        `text` - button name

    - #### getText

          public java.lang.String getText()

      Returns the text label associated with this model.
      Returns:
        button name

    - #### setIcon

          public void setIcon​(javax.swing.Icon icon)

      Sets the icon associated with this model.
      Parameters:
        `icon` - button icon

    - #### getIcon

          public javax.swing.Icon getIcon()

      Returns the icon associated with this model.
      Returns:
        button icon

    - #### setDescription

          public void setDescription​(java.lang.String shortdesc)

      Sets the description (for tooltips etc) associated with this model.
      Parameters:
        `shortdesc` - description

    - #### getDescription

          public java.lang.String getDescription()

      Returns the description (for tooltips etc) associated with this model.
      Returns:
        description

    - #### createButton

          public javax.swing.JToggleButton createButton()

      Creates and returns a normal button using this model.
      Returns:
        button

    - #### createToolbarButton

          public javax.swing.JToggleButton createToolbarButton()

      Creates and returns a button suitable for use in a toolbar using this model. The button has no text.
      Returns:
        button

    - #### createMenuItem

          public javax.swing.JCheckBoxMenuItem createMenuItem()

      Creates and returns a menu item using this model.
      Returns:
        checkbox menu item

    - #### createCheckBox

          public javax.swing.JCheckBox createCheckBox()

      Creates and returns a check box using this model.
      Returns:
        checkbox

    - #### createRadioButtons

          public javax.swing.JRadioButton[] createRadioButtons​(java.lang.String name0,
                                                               java.lang.String name1)

      Creates and returns a pair of radio buttons using this model. One unselects it, and the other selects it.
      Parameters:
        `name0` - name of the Off control
        `name1` - name of the On control
      Returns:
        array of (Off, On) controls

    - #### setSelected

          public void setSelected​(boolean state)

      Sets the state of this model.
      Specified by:
        `setSelected` in interface `javax.swing.ButtonModel`
      Overrides:
        `setSelected` in class `javax.swing.JToggleButton.ToggleButtonModel`
      Parameters:
        `state` - on/off status

    - #### isSelected

          public boolean isSelected()

      Returns the state of this model.
      Specified by:
        `isSelected` in interface `javax.swing.ButtonModel`
      Overrides:
        `isSelected` in class `javax.swing.JToggleButton.ToggleButtonModel`
      Returns:
        on/off status

    - #### fireActionPerformed

          public void fireActionPerformed​(java.awt.event.ActionEvent evt)

      Overrides:
        `fireActionPerformed` in class `javax.swing.DefaultButtonModel`

Copyright © 2003-2018 CCLRC: Council for the Central Laboratory of the Research Councils. All Rights Reserved.