Java Reference
In-Depth Information
A
long description
of the action —a
String
object that is intended to be used as context
sensitive help.
❑
A
mnemonic
key
for the action - this is a key code of type
int
.
❑
An
action command key
- defined by an entry in a
KeyMap
object associated with a
component.
❑
Just so you are aware of them I have included the complete set here, but we will concentrate on just using the
first three. We haven't met
Icon
objects before, but we will get to them a little later in this chapter.
You are not obliged to provide for all of these properties in your action classes, but the interface
provides the framework for it. These properties are stored internally in a map collection in your action
class, so the
Action
interface defines constants that you use as keys for each of the standard properties.
These constants are all of type
String
, and the ones we are interested in are
NAME
,
SMALL
_
ICON
, and
SHORT
_
DESCRIPTION
. The others are
ACCELERATOR
_
KEY
,
LONG
_
DESCRIPTION
,
MNEMONIC
_
KEY
,
and
ACTION
_
COMMAND
_
KEY
. There is another constant of type
String
defined in the interface with
the name
DEFAULT
. This is for you to use to store a default property for the action.
The
Action
interface also declares the following methods:
Method
Description
void putValue(String key,
Object value)
Stores the
value
with the key
key
in the map
supported by the action class. To store the name of
an action within a class method you might write:
putValue(NAME, theName);
This uses the standard key,
NAME
to store the
object
theName
.
Object
getValue(String key)
This retrieves the object from the map
corresponding to the key
key
. To retrieve a small
icon within an action class method you might
write:
Icon lineIcon =
(Icon)getValue(SMALL
_
ICON);
boolean
isEnabled()
Returns
true
if the action object is enabled and
false
otherwise.
void
setEnabled(boolean state)
Sets the action object as enabled if the argument
state is
true
and disabled if it is
false
. This
operates on both the toolbar button and the menu
item if they have been created using the same
object.
Table continued on following page