javax.swing
Class DefaultButtonModel
- ButtonModel, ItemSelectable, Serializable
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.
static int | ARMED - Indicates that the button is partially committed to being
pressed, but not entirely.
|
static int | ENABLED - State constant indicating that the button is enabled.
|
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 String | actionCommand - The string used as the "command" property of any ActionEvent this model
sends.
|
protected ChangeEvent | changeEvent - The single ChangeEvent this model (re)uses to call its ChangeListeners.
|
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.
|
protected int | stateMask - Represents the "state properties" (armed, enabled, pressed, rollover and
selected) by a bitwise combination of integer constants.
|
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
ARMED
public static final int ARMED
Indicates that the button is partially committed to being
pressed, but not entirely. This usually happens when a user has pressed
but not yet released the mouse button.
ENABLED
public static final int ENABLED
State constant indicating that the button is enabled. Buttons cannot be
pressed or selected unless they are enabled.
PRESSED
public static final int PRESSED
State constant indicating that the user is holding down the button. When
this transitions from true to false, an ActionEvent may be fired,
depending on the value of the "armed" property.
ROLLOVER
public static final int ROLLOVER
State constant indicating that the mouse is currently positioned over the
button.
SELECTED
public static final int SELECTED
State constant indicating that the button is selected. This constant is
only meaningful for toggle-type buttons (radio buttons, checkboxes).
actionCommand
protected String actionCommand
The string used as the "command" property of any ActionEvent this model
sends.
changeEvent
protected ChangeEvent changeEvent
The single ChangeEvent this model (re)uses to call its ChangeListeners.
group
protected ButtonGroup group
The group this model belongs to. Only one button in a group may be
selected at any given time.
mnemonic
protected int mnemonic
The key code (one of
KeyEvent
VK_) used to press
this button via a keyboard interface.
stateMask
protected int stateMask
Represents the "state properties" (armed, enabled, pressed, rollover and
selected) by a bitwise combination of integer constants.
extends EventListener> T[] getListeners
public extends EventListener> T[] getListeners(Class listenerType)
Returns a specified class of listeners.
listenerType
- the type of listener to return
fireActionPerformed
protected void fireActionPerformed(ActionEvent e)
Inform each ActionListener in the
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 fire
fireStateChanged
protected void fireStateChanged()
Inform each ChangeListener in the
listenerList
that a ChangeEvent
has occurred. This happens in response to the any change to a property
of the model.
getGroup
public ButtonGroup getGroup()
Returns the current value of the model's "group" property.
- The value of the "group" property
isArmed
public boolean isArmed()
Get the value of the model's "armed" property.
- isArmed in interface ButtonModel
- The current "armed" property
isEnabled
public boolean isEnabled()
Get the value of the model's "enabled" property.
- isEnabled in interface ButtonModel
- The current "enabled" property.
isPressed
public boolean isPressed()
Get the value of the model's "pressed" property.
- isPressed in interface ButtonModel
- The current "pressed" property
setArmed
public void setArmed(boolean a)
Set the value of the model's "armed" property.
- setArmed in interface ButtonModel
a
- The new "armed" property
setEnabled
public void setEnabled(boolean e)
Set the value of the model's "enabled" property.
- setEnabled in interface ButtonModel
e
- The new "enabled" property
setGroup
public void setGroup(ButtonGroup g)
Set the value of the model's "group" property. The model is said to be a
member of the
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 ButtonModel
g
- The new "group" property (null
permitted).
setPressed
public void setPressed(boolean p)
Set the value of the model's "pressed" property.
- setPressed in interface ButtonModel
p
- The new "pressed" property
DefaultButtonModel.java --
Copyright (C) 2002, 2004, 2006, Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version.