# Class ToggleButtonModel

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

All Implemented Interfaces:
  `ItemSelectable, Serializable, ButtonModel`

Direct Known Subclasses:
  `WindowToggle`

public class ToggleButtonModel extends 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 DefaultButtonModel

`actionCommand, ARMED, changeEvent, ENABLED, group, listenerList, mnemonic, PRESSED, ROLLOVER, SELECTED, stateMask`

## Constructor Summary

Constructors
Constructor
Description
`ToggleButtonModel(String text, Icon icon, String shortdesc)`
Constructor.

## Method Summary

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

### Methods inherited from class JToggleButton.ToggleButtonModel

`setPressed`

### Methods inherited from class 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 Object

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

## Constructor Details

### ToggleButtonModel

public ToggleButtonModel(String text, Icon icon, 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 Details

### setText

public void setText(String text)
Sets the text label associated with this model.

Parameters:
  `text` - button name

### getText

public String getText()
Returns the text label associated with this model.

Returns:
  button name

### setIcon

public void setIcon(Icon icon)
Sets the icon associated with this model.

Parameters:
  `icon` - button icon

### getIcon

public Icon getIcon()
Returns the icon associated with this model.

Returns:
  button icon

### setDescription

public void setDescription(String shortdesc)
Sets the description (for tooltips etc) associated with this model.

Parameters:
  `shortdesc` - description

### getDescription

public String getDescription()
Returns the description (for tooltips etc) associated with this model.

Returns:
  description

### createButton

public JToggleButton createButton()
Creates and returns a normal button using this model.

Returns:
  button

### createToolbarButton

public 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 JCheckBoxMenuItem createMenuItem()
Creates and returns a menu item using this model.

Returns:
  checkbox menu item

### createCheckBox

public JCheckBox createCheckBox()
Creates and returns a check box using this model.

Returns:
  checkbox

### createRadioButtons

public JRadioButton[] createRadioButtons(String name0, 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 `ButtonModel`
Overrides:
  `setSelected` in class `JToggleButton.ToggleButtonModel`
Parameters:
  `state` - on/off status

### isSelected

public boolean isSelected()
Returns the state of this model.

Specified by:
  `isSelected` in interface `ButtonModel`
Overrides:
  `isSelected` in class `JToggleButton.ToggleButtonModel`
Returns:
  on/off status

### fireActionPerformed

public void fireActionPerformed(ActionEvent evt)

Overrides:
  `fireActionPerformed` in class `DefaultButtonModel`