public abstract class Mode
extends javax.swing.AbstractAction
A mode can be activated or deactivated, by setting its active state. An active mode responds to input events in some mode-specific manner. An inactive mode ignores all input events.
A mode is an action, so it can be used to construct toggle buttons and menu items. A mode, like any action, may be enabled or disabled. While enabled, a mode may be active or inactive. While disabled, a mode is inactive, and cannot be activated.
A mode has a manager, which coordinates the activation of modes that may be mutually exclusive. When an exclusive mode is activated, the mode's manager first deactivates any other exclusive modes, thereby ensuring that no more than one exclusive mode is active at any time. By default, modes are exclusive, but this property may be overridden.
Modifier | Constructor and Description |
---|---|
protected |
Mode(ModeManager manager)
Constructs a mode with specified manager, name, and icon.
|
Modifier and Type | Method and Description |
---|---|
void |
actionPerformed(java.awt.event.ActionEvent event)
Toggles the active state of this mode.
|
java.awt.Cursor |
getCursor()
Gets the cursor for this mode.
|
boolean |
isActive()
Determines whether this mode is active.
|
boolean |
isExclusive()
Determines whether or not this mode is exclusive.
|
protected static java.awt.Cursor |
loadCursor(java.lang.Class<?> cls,
java.lang.String res,
int x,
int y)
Loads a cursor from the specified resource name.
|
protected static javax.swing.Icon |
loadIcon(java.lang.Class<?> cls,
java.lang.String res)
Loads an icon from the specified resource name.
|
void |
setAcceleratorKey(javax.swing.KeyStroke ak)
Sets the accelerator key stroke for this mode.
|
void |
setActive(boolean active)
Activates or deactivates this mode.
|
protected abstract void |
setActive(java.awt.Component component,
boolean active)
Activates or deactivates this mode for the specified component.
|
void |
setCursor(java.awt.Cursor cursor)
Sets the cursor for this mode.
|
void |
setEnabled(boolean enabled) |
void |
setIcon(javax.swing.Icon icon)
Sets the icon for this mode.
|
void |
setLongDescription(java.lang.String ld)
Sets the long description for this mode.
|
void |
setMnemonicKey(int mk)
Sets the mnemonic key for this mode.
|
void |
setName(java.lang.String name)
Sets the name (text) for this mode.
|
void |
setShortDescription(java.lang.String sd)
Sets the short description for this mode.
|
protected Mode(ModeManager manager)
manager
- the manager.public void setActive(boolean active)
active
- true, to activate; false, to deactivate.public boolean isActive()
public boolean isExclusive()
public void actionPerformed(java.awt.event.ActionEvent event)
event
- the action event (ignored).public void setEnabled(boolean enabled)
setEnabled
in interface javax.swing.Action
setEnabled
in class javax.swing.AbstractAction
public void setName(java.lang.String name)
Typically, this method is called by constructors in classes that extend this abstract base class.
name
- the name.public void setIcon(javax.swing.Icon icon)
Typically, this method is called by constructors in classes that extend this abstract base class.
icon
- the icon.public void setMnemonicKey(int mk)
Typically, this method is called by constructors in classes that extend this abstract base class.
mk
- the mnemonic key; e.g., KeyEvent.VK_K.public void setAcceleratorKey(javax.swing.KeyStroke ak)
Typically, this method is called by constructors in classes that extend this abstract base class.
ak
- the accelerator key stroke.public void setShortDescription(java.lang.String sd)
Typically, this method is called by constructors in classes that extend this abstract base class.
sd
- the short description.public void setLongDescription(java.lang.String ld)
Typically, this method is called by constructors in classes that extend this abstract base class.
ld
- the long description.public void setCursor(java.awt.Cursor cursor)
cursor
- the cursor; null, if the default cursor should be used.public java.awt.Cursor getCursor()
protected static javax.swing.Icon loadIcon(java.lang.Class<?> cls, java.lang.String res)
cls
- the class used to find the resource.res
- the name of the resource that contains the icon.protected static java.awt.Cursor loadCursor(java.lang.Class<?> cls, java.lang.String res, int x, int y)
cls
- the class used to find the resource.res
- the name of the resource that contains the cursor image.x
- the x coordinate of the cursor hot spoty
- the y coordinate of the cursor hot spotprotected abstract void setActive(java.awt.Component component, boolean active)
This method should not be called directly. The mode's manager calls this method for all of its components. Implementations of this method should do nothing for components for which the mode is inapplicable.
component
- the component for which to enable the mode.active
- true, to activate; false, to deactivate.