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
-
-
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
-
-
-
-
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 controlname1
- 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 interfacejavax.swing.ButtonModel
- Overrides:
setSelected
in classjavax.swing.JToggleButton.ToggleButtonModel
- Parameters:
state
- on/off status
-
isSelected
public boolean isSelected()
Returns the state of this model.- Specified by:
isSelected
in interfacejavax.swing.ButtonModel
- Overrides:
isSelected
in classjavax.swing.JToggleButton.ToggleButtonModel
- Returns:
- on/off status
-
fireActionPerformed
public void fireActionPerformed(java.awt.event.ActionEvent evt)
- Overrides:
fireActionPerformed
in classjavax.swing.DefaultButtonModel
-
-