|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjavax.swing.DefaultButtonModel
public class DefaultButtonModel
The default implementation of ButtonModel.
The purpose of this class is to model the dynamic state of an abstract
button. The concrete button type holding this state may be a a "toggle"
button (checkbox, radio button) or a "push" button (menu button, button).
If the model is disabled, only the "selected" property can be changed. An
attempt to change the "armed", "rollover" or "pressed" properties while
the model is disabled will be blocked. Any successful (non-blocked) change
to the model's properties will trigger the firing of a ChangeEvent. Any
change to the "selected" property will trigger the firing of an ItemEvent
in addition to ChangeEvent. This is true whether the model is enabled or
not. One other state change is special: the transition from "enabled,
armed and pressed" to "enabled, armed and not-pressed". This is considered
the "trailing edge" of a successful mouse click, and therefore fires an
ActionEvent in addition to a ChangeEvent. In all other respects this class
is just a container of boolean flags.
| Field Summary | |
|---|---|
protected String |
actionCommand
The string used as the "command" property of any ActionEvent this model sends. |
static int |
ARMED
Indicates that the button is partially committed to being pressed, but not entirely. |
protected ChangeEvent |
changeEvent
The single ChangeEvent this model (re)uses to call its ChangeListeners. |
static int |
ENABLED
State constant indicating that the button is enabled. |
protected ButtonGroup |
group
The group this model belongs to. |
protected EventListenerList |
listenerList
List of ItemListeners, ChangeListeners, and ActionListeners registered on this model. |
protected int |
mnemonic
The key code (one of KeyEvent VK_) used to press
this button via a keyboard interface. |
static int |
PRESSED
State constant indicating that the user is holding down the button. |
static int |
ROLLOVER
State constant indicating that the mouse is currently positioned over the button. |
static int |
SELECTED
State constant indicating that the button is selected. |
protected int |
stateMask
Represents the "state properties" (armed, enabled, pressed, rollover and selected) by a bitwise combination of integer constants. |
| Constructor Summary | |
|---|---|
DefaultButtonModel()
Creates a new DefaultButtonModel object. |
|
| Method Summary | ||
|---|---|---|
void |
addActionListener(ActionListener l)
Add an ActionListener to the model. |
|
void |
addChangeListener(ChangeListener l)
Add a ChangeListener to the model. |
|
void |
addItemListener(ItemListener l)
Add an ItemListener to the model. |
|
protected void |
fireActionPerformed(ActionEvent e)
Inform each ActionListener in the listenerList that an
ActionEvent has occurred. |
|
protected void |
fireItemStateChanged(ItemEvent e)
Inform each ItemListener in the listenerList that an ItemEvent
has occurred. |
|
protected void |
fireStateChanged()
Inform each ChangeListener in the listenerList that a ChangeEvent
has occurred. |
|
String |
getActionCommand()
Returns the current value of the model's "actionCommand" property. |
|
ActionListener[] |
getActionListeners()
Returns all registered ActionListener objects. |
|
ChangeListener[] |
getChangeListeners()
Returns all registered ChangeListener objects. |
|
ButtonGroup |
getGroup()
Returns the current value of the model's "group" property. |
|
ItemListener[] |
getItemListeners()
Returns all registered ItemListener objects. |
|
|
getListeners(Class<T> listenerType)
Returns a specified class of listeners. |
|
int |
getMnemonic()
Get the value of the model's "mnemonic" property. |
|
Object[] |
getSelectedObjects()
Return null. |
|
boolean |
isArmed()
Get the value of the model's "armed" property. |
|
boolean |
isEnabled()
Get the value of the model's "enabled" property. |
|
boolean |
isPressed()
Get the value of the model's "pressed" property. |
|
boolean |
isRollover()
Get the value of the model's "rollover" property. |
|
boolean |
isSelected()
Get the value of the model's "selected" property. |
|
void |
removeActionListener(ActionListener l)
Remove an ActionListener to the model. |
|
void |
removeChangeListener(ChangeListener l)
Remove a ChangeListener to the model. |
|
void |
removeItemListener(ItemListener l)
Remove an ItemListener to the model. |
|
void |
setActionCommand(String s)
Set the value of the model's "actionCommand" property. |
|
void |
setArmed(boolean a)
Set the value of the model's "armed" property. |
|
void |
setEnabled(boolean e)
Set the value of the model's "enabled" property. |
|
void |
setGroup(ButtonGroup g)
Set the value of the model's "group" property. |
|
void |
setMnemonic(int key)
Set the value of the model's "mnemonic" property. |
|
void |
setPressed(boolean p)
Set the value of the model's "pressed" property. |
|
void |
setRollover(boolean r)
Set the value of the model's "rollover" property. |
|
void |
setSelected(boolean s)
Set the value of the model's "selected" property. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int ARMED
public static final int ENABLED
public static final int PRESSED
public static final int ROLLOVER
public static final int SELECTED
protected int stateMask
protected EventListenerList listenerList
protected ChangeEvent changeEvent
protected ButtonGroup group
protected int mnemonic
KeyEvent VK_) used to press
this button via a keyboard interface.
protected String actionCommand
| Constructor Detail |
|---|
public DefaultButtonModel()
| Method Detail |
|---|
public Object[] getSelectedObjects()
null. Use AbstractButton if you wish to
interface with a button via an ItemSelectable interface.
getSelectedObjects in interface ItemSelectablenullpublic <T extends EventListener> T[] getListeners(Class<T> listenerType)
listenerType - the type of listener to return
public void addActionListener(ActionListener l)
addActionListener in interface ButtonModell - The listener to addButtonModel.removeActionListener(ActionListener)public void removeActionListener(ActionListener l)
removeActionListener in interface ButtonModell - The listener to removeButtonModel.addActionListener(ActionListener)public ActionListener[] getActionListeners()
ActionListener objects.
ActionListener objectspublic void addItemListener(ItemListener l)
addItemListener in interface ItemSelectableaddItemListener in interface ButtonModell - The listener to addButtonModel.removeItemListener(ItemListener)public void removeItemListener(ItemListener l)
removeItemListener in interface ItemSelectableremoveItemListener in interface ButtonModell - The listener to removeButtonModel.removeItemListener(ItemListener)public ItemListener[] getItemListeners()
ItemListener objects.
ItemListener objectspublic void addChangeListener(ChangeListener l)
addChangeListener in interface ButtonModell - The listener to addButtonModel.removeChangeListener(ChangeListener)public void removeChangeListener(ChangeListener l)
removeChangeListener in interface ButtonModell - The listener to removeButtonModel.removeChangeListener(ChangeListener)public ChangeListener[] getChangeListeners()
ChangeListener objects.
ChangeListener objectsprotected void fireItemStateChanged(ItemEvent e)
listenerList that an ItemEvent
has occurred. This happens in response to any change to the stateMask field.
e - The ItemEvent to fireprotected void fireActionPerformed(ActionEvent e)
listenerList that an
ActionEvent has occurred. This happens in response to the any change to
the stateMask field which makes the enabled, armed and pressed
properties all simultaneously true.
e - The ActionEvent to fireprotected void fireStateChanged()
listenerList that a ChangeEvent
has occurred. This happens in response to the any change to a property
of the model.
public boolean isArmed()
isArmed in interface ButtonModelButtonModel.setArmed(boolean)public void setArmed(boolean a)
setArmed in interface ButtonModela - The new "armed" propertyButtonModel.isArmed()public boolean isEnabled()
isEnabled in interface ButtonModelButtonModel.setEnabled(boolean)public void setEnabled(boolean e)
setEnabled in interface ButtonModele - The new "enabled" propertyButtonModel.isEnabled()public void setPressed(boolean p)
setPressed in interface ButtonModelp - The new "pressed" propertyButtonModel.isPressed()public boolean isPressed()
isPressed in interface ButtonModelButtonModel.setPressed(boolean)public void setRollover(boolean r)
setRollover in interface ButtonModelr - The new "rollover" propertyButtonModel.isRollover()public void setSelected(boolean s)
setSelected in interface ButtonModels - The new "selected" propertyButtonModel.isSelected()public boolean isSelected()
isSelected in interface ButtonModelButtonModel.setSelected(boolean)public boolean isRollover()
isRollover in interface ButtonModelButtonModel.setRollover(boolean)public int getMnemonic()
getMnemonic in interface ButtonModelButtonModel.setMnemonic(int)public void setMnemonic(int key)
setMnemonic in interface ButtonModelkey - The new "mnemonic" propertyButtonModel.getMnemonic()public void setActionCommand(String s)
ActionEvent fired from the
model.
setActionCommand in interface ButtonModels - The new "actionCommand" property.ButtonModel.getActionCommand()public String getActionCommand()
getActionCommand in interface ButtonModelButtonModel.setActionCommand(String)public void setGroup(ButtonGroup g)
ButtonGroup held in its "group" property, and only
one model in a given group can have their "selected" property be
true at a time.
setGroup in interface ButtonModelg - The new "group" property (null permitted).getGroup()public ButtonGroup getGroup()
setGroup(ButtonGroup)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||