public class IlvAction extends AbstractAction
IlvAction
also enriches predefined
Swing action properties with new properties that it allows for,
for example, checking menu items or toolbar buttons associated with the
action.
IlvAction
properties can be accessed through
static methods of the IlvAction
class, so that those properties
can be applied to actions that are not IlvAction
actions.
You can find task-oriented documentation and examples of using
IlvAction
in the Perforce JViews Application Framework User's Manual, in the chapter on
How to Use Swing Actions in JAppFrame.
Modifier and Type | Field and Description |
---|---|
static String |
ACTION_ACCELERATOR_LIST
The key used for storing the list of accelerators that trigger an
action event for the action.
|
static String |
ACTION_APPLICATION
The key used for storing the application of the action.
|
static String |
ACTION_AUTOMATIC
Determines whether the action events for the action should be processed
by the application or by the
actionPerformed method
of the action. |
static String |
ACTION_CHECK_GROUP
The key used for storing the name of the group of checkable
actions that the action belongs to.
|
static String |
ACTION_CHECK_LOOK
Action property read only for checkable actions.
|
static String |
ACTION_CHECK_ONE_SHOT
Action property read only for checkable actions.
|
static String |
ACTION_CHECK_STATE
The key of the property that determines whether the action is checked.
|
static String |
ACTION_CHECKABLE
The key of the property that determines whether the action is checkable.
|
static String |
ACTION_CHECKED_ICON
Action property read only for checkable actions with the
ACTION_CHECK_LOOK property set to "new" . |
static String |
ACTION_DEPENDING_ACTIONS
The key for storing the actions with state that must change when an action
event for the action is being processed.
|
static String |
ACTION_LIST
Determines whether the action is a list action.
|
static String |
ACTION_LIST_CHECK_SELECTION
Boolean list action property that determines whether the selected menu item
of the list should be marked with a check.
|
static String |
ACTION_LIST_DYNAMIC_CONTENT
Property accessed only for list actions where
ACTION_LIST_IN_SUBMENU
property has been set. |
static String |
ACTION_LIST_IN_SUBMENU
Property accessed only for list actions.
|
static String |
ACTION_LIST_ITEMS
The key used for storing the list items of a list action.
|
static String |
ACTION_LIST_MENU_EMPTYSTRING
Property accessed only for list actions.
|
static String |
ACTION_LIST_MENU_FIRSTNUMBER
Property accessed only for list actions that have the
property
ACTION_LIST_MENU_USENUMBERING set to
Boolean.TRUE . |
static String |
ACTION_LIST_MENU_MAXLENGTH
Property accessed only for list actions.
|
static String |
ACTION_LIST_MENU_USENUMBERING
Property accessed only for list actions.
|
static String |
ACTION_LIST_SELECTION
Property accessed only for list actions.
|
static String |
ACTION_LOCK_ON_DOUBLECLICK
Action property read only for checkable actions that are "one shot".
|
static String |
ACTION_PROCESSED_IN_NEW_THREAD
Determines whether the process of the action should be performed in a
separate thread.
|
static String |
ACTION_UNCHECKED_ICON
Action property read only for checkable actions with the
ACTION_CHECK_LOOK property set to "new" . |
static String |
ACTION_UPDATE_AFTER_PROCESSING
Determines whether the action state should be updated after an event
for this action has been processed.
|
static int |
BIG_ICONS
Constant value that specifies the use of big icons (32x32).
|
static String |
DOUBLE_CLICK_ACTION
The key used for storing the command of the action that is used for notifying
that a button built with the action parameters has been double-clicked.
|
static int |
SMALL_ICONS
Constant value that specifies the use of small icons (16x16).
|
changeSupport, enabled
ACCELERATOR_KEY, ACTION_COMMAND_KEY, DEFAULT, DISPLAYED_MNEMONIC_INDEX_KEY, LARGE_ICON_KEY, LONG_DESCRIPTION, MNEMONIC_KEY, NAME, SELECTED_KEY, SHORT_DESCRIPTION, SMALL_ICON
Constructor and Description |
---|
IlvAction()
Constructs a new
IlvAction . |
Modifier and Type | Method and Description |
---|---|
static KeyStroke |
AcceleratorFromString(String s)
Returns an accelerator from its specified string representation.
|
static String |
AcceleratorToString(KeyStroke accelerator)
Returns a string representation of the specified
accelerator . |
void |
actionPerformed(ActionEvent e)
Invoked when an action occurs.
|
static void |
ActionProcessTerminated(Action action)
Must be invoked after the process of the action event for the
specified
action has been terminated. |
IlvApplication |
getApplication()
Returns the application associated with this action.
|
static String[] |
GetCategories(Action action)
Returns the categories the specified
action belongs to. |
static String |
GetGroup(Action action)
Returns the check group that the specified
action belongs to. |
static Object[] |
GetListItems(Action action)
Returns the array of items stored by the specified list
action
in the ACTION_LIST_ITEMS property. |
static char |
GetMnemonic(Action action,
IlvApplication application)
Returns the mnemonic character that should be set to the menu items
associated with the specified
action . |
static Action |
GetSelectedGroupAction(IlvApplication application,
String group)
Returns the action currently selected in the specified
group
of actions. |
static Object |
GetSelectedItem(Action action)
Returns the item currently selected among the items stored in the specified
list
action . |
static int |
GetSelectionIndex(Action action)
Returns the index of the item currently selected among the items stored
in the specified list
action . |
static boolean |
HasCategory(Action action,
String category)
Determines whether the specified
action has the specified
category . |
static boolean |
IsActionList(Action action)
Determines whether the specified action is a list action.
|
static boolean |
IsActionLocked(Action action)
Determines whether the specified
action has been locked. |
static boolean |
IsAutomatic(Action action)
Determines whether the action events of the specified action are handled
by the action handlers registered with the application.
|
static boolean |
IsChecked(Action action)
Determines whether the specified action is checked.
|
static boolean |
IsListMenuNumbering(Action action)
Determines whether the specified
action is a list action and whether
the stored items in it appear with a prefix number in menu items created
for those items. |
static void |
LockAction(Action action)
Locks the specified
action . |
void |
readSettings(IlvSettingsElement element,
IlvApplication application)
Reads the settings of the action from the specified settings element.
|
static void |
RegisterActionInGroup(Action action,
Component child)
Register the component that represents the given action in the
action group, if this is in the action configuration.
|
static void |
SetAction(AbstractButton button,
Action action,
IlvApplication application,
int iconsSize)
Sets the action to a specified button, taking care of internationalization
issues.
|
static void |
SetAction(Component component,
Action action,
IlvApplication application)
Sets the action to a specified component, taking care of internationalization
issues.
|
static boolean |
SetAutomatic(Action action,
boolean automatic)
Sets the specified
action as automatic or not, depending on the
value of the specified automatic parameter. |
static void |
SetChecked(Action action,
boolean state)
Changes the check state of the specified
action by
setting its ACTION_CHECK_STATE property. |
static void |
SetChecked(Component component,
Action action,
boolean state)
Sets the specified component checked or unchecked, depending on the
specified check state.
|
static void |
SetListItems(Action action,
Object[] items)
Sets the array of items to the specified list
action . |
static void |
SetSelectedItem(Action action,
Object item)
Selects one item among the items stored in the specified list
action . |
static void |
SetSelectionIndex(Action action,
int index)
Selects one item among the items stored in the specified list
action . |
static void |
UnlockAction(Action action)
Unlocks the specified
action , previously locked with
the method LockAction(javax.swing.Action) . |
static void |
UnregisterActionInGroup(Component child)
Removes the given component from the action group.
|
static void |
UpdateButtonProperties(AbstractButton button,
IlvApplication application)
Updates the
button properties according to the parameters
of its associated action. |
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
public static final int SMALL_ICONS
public static final int BIG_ICONS
public static final String ACTION_APPLICATION
public static final String ACTION_PROCESSED_IN_NEW_THREAD
Boolean.TRUE
, the processing of action events will be performed in
a separate thread. Otherwise, the action is performed in the current thread.public static final String ACTION_AUTOMATIC
actionPerformed
method
of the action.
If the value of the property is equal to Boolean.TRUE
, the
action will be automatic and its events will be handled by the application that
fires them to its registered action handlers. Otherwise,
the actionPerformed
method of the action is called.
By default, any IlvAction
instantiated by the application
when initializing its actions from the settings is set to automatic.
public static final String ACTION_UPDATE_AFTER_PROCESSING
Boolean.TRUE
, the action
state will be updated by a call to IlvApplication.updateAction(Action)
.
Otherwise, the state of the action is updated using the standard
JAppFrame action update mechanism.public static final String DOUBLE_CLICK_ACTION
public static final String ACTION_LIST
Boolean.TRUE
, the
action will be a list action. Otherwise, it is not a list action.public static final String ACTION_LIST_ITEMS
public static final String ACTION_LIST_IN_SUBMENU
Boolean.TRUE
, list items
will appear in a sub pop-up menu. Otherwise, menu items appear below the menu
item associated with the list action.public static final String ACTION_LIST_MENU_MAXLENGTH
Integer
value for the maximum length of the text of menu items that are generated
for the list items of the action.public static final String ACTION_LIST_SELECTION
public static final String ACTION_LIST_MENU_USENUMBERING
true
, the
text of generated menu items will be prefixed as specified with the
ACTION_LIST_MENU_FIRSTNUMBER
property. Otherwise, the text
is not prefixed.public static final String ACTION_LIST_MENU_FIRSTNUMBER
ACTION_LIST_MENU_USENUMBERING
set to
Boolean.TRUE
. It stores the text used as the prefix for
the text of the menu item corresponding to the item given by
GetListItems(Action)
[0]
.
This text should only contain one character. The prefix string that
corresponds to the item of index n
in the list is then
determined as follows:
String prefix = (String)action.getProperty(IlvAction.ACTION_LIST_MENU_FIRSTNUMBER); prefix = new String(new char[]{prefix.charAt(0) + n)});For example, if the property contains the string
"A"
, menu
items generated for list items will be prefixed with the strings
"A"
, "B"
,... for the list items of
index 0
, 1
, ... respectively.public static final String ACTION_LIST_MENU_EMPTYSTRING
public static final String ACTION_LIST_CHECK_SELECTION
Boolean.TRUE
, the selected menu item will be marked with a checkbox;
if the value is Boolean.FALSE
, the selected item will not be
marked.public static final String ACTION_LIST_DYNAMIC_CONTENT
ACTION_LIST_IN_SUBMENU
property has been set. It determines whether the list items of the action
should be calculated dynamically. If the value of the property is equal to
Boolean.TRUE
, the method IlvApplication.updateAction(Action)
will be invoked before the pop-up menu listing the action list items is displayed.
An action handler registered with the application can then set the new list
items of the action in its method ActionHandler.updateAction(Action)
.
Otherwise, it is the responsibility of the JAppFrame user to determine when
the list items should be set to the action.public static final String ACTION_CHECKABLE
Boolean.TRUE
, it will be a checkable action.
Otherwise, the action cannot be checked.public static final String ACTION_CHECK_STATE
Boolean.TRUE
, the action will be checked.
Otherwise, the action is not checked.public static final String ACTION_CHECK_GROUP
public static final String ACTION_CHECK_ONE_SHOT
Boolean.TRUE
, the
action will be unchecked after the action process terminates. Otherwise,
the action remains checked.public static final String ACTION_LOCK_ON_DOUBLECLICK
Boolean.TRUE
,
the action will be locked after the application user double-clicks a button
associated with the action. Otherwise, the button is unchecked and the
action is not locked.ACTION_CHECK_ONE_SHOT
,
Constant Field Valuespublic static final String ACTION_CHECK_LOOK
"new"
, the menu item
will be set a check icon if the action is checked and an unchecked icon if the
action is unchecked. The check icons are specified with the
ACTION_CHECKED_ICON
and ACTION_UNCHECKED_ICON
properties.
Otherwise, if the value of the property is not equal to Boolean.TRUE
,
a JCheckBoxMenuItem
will be instantiated to represent
the action. The check state of this JCheckBoxMenuItem
is associated with the
check state of the action.
ACTION_CHECKABLE
,
Constant Field Valuespublic static final String ACTION_CHECKED_ICON
ACTION_CHECK_LOOK
property set to "new"
.
It specifies the check icon to be set to a menu item associated with
the action, if the action is checked. If the property is not defined
from the settings, it will be set to a default icon.public static final String ACTION_UNCHECKED_ICON
ACTION_CHECK_LOOK
property set to "new"
.
It specifies the uncheck icon to be set to a menu item associated with
the action, if the action is unchecked. If the property is not defined
from the settings, it will be set to a default icon.public static final String ACTION_DEPENDING_ACTIONS
The value of the property is a HashMap
instance with
keys that are the action command of the dependent actions and values that
indicate the state the dependent action must have while the action is
being processed: Boolean.TRUE
to enable the dependent action and Boolean.FALSE
to
set it disabled.
Consider as an example a "Compile" action that compiles the currently
active Java document in the application. We may have three dependent actions
for this action: cut
, copy
, and stopCompilation
.
If we set the variable dependentActions
to:
HashMap dependentActions = (HashMap)application.getAction("Compile").getValue(IlvAction.ACTION_DEPENDING_ACTIONS);we may have:
dependentActions.get("cut") == Boolean.FALSE
and
dependentActions.get("copy") == Boolean.FALSE
to
indicate that the cut
and copy
modification actions
should be disabled while compiling the Java document and we may have:
dependentActions.get("stopCompilation") == Boolean.TRUE
to
indicate that the stopCompilation
action is enabled when
compiling a Java document.public static final String ACTION_ACCELERATOR_LIST
KeyStroke
instances.public void actionPerformed(ActionEvent e)
public void readSettings(IlvSettingsElement element, IlvApplication application)
element
- The settings element to read the settings of the action from.application
- The application of the action.public static boolean HasCategory(Action action, String category)
action
has the specified
category
.action
- The action for testing whether it belongs to the specified category.category
- The category.true
if the action has the category;
false
otherwise.GetCategories(javax.swing.Action)
public static String[] GetCategories(Action action)
action
belongs to.action
- The action to retrieve categories from.public static void SetSelectionIndex(Action action, int index)
action
.
The specified action must be a list action, with the property
ACTION_LIST
set.action
- The action to set the selected item to.index
- The index of the item to select.SetSelectedItem(Action, Object)
,
GetSelectionIndex(javax.swing.Action)
public static void SetSelectedItem(Action action, Object item)
action
.
The specified action must be a list action, with the property
ACTION_LIST
set.action
- The action to set the selected item to.item
- The new item to select.GetSelectedItem(Action)
,
SetSelectionIndex(Action, int)
public static int GetSelectionIndex(Action action)
action
.
The specified action must be a list action, with the property
ACTION_LIST
set.action
- The action to get the selection index from.-1
if no item has been
previously selected.GetSelectedItem(Action)
,
SetSelectionIndex(Action, int)
,
SetSelectedItem(Action, Object)
public static Object GetSelectedItem(Action action)
action
.
The specified action must be a list action, with the property
ACTION_LIST
set.action
- The action to get the selected item from.null
if no item has been previously
selected.SetSelectionIndex(Action, int)
,
SetSelectedItem(Action, Object)
,
GetSelectionIndex(Action)
public static Object[] GetListItems(Action action)
action
in the ACTION_LIST_ITEMS
property.public static void SetListItems(Action action, Object[] items)
action
.
The ACTION_LIST_ITEMS
property is set to the new array of items.GetListItems(javax.swing.Action)
public static boolean IsListMenuNumbering(Action action)
action
is a list action and whether
the stored items in it appear with a prefix number in menu items created
for those items.action
- The action to test the list menu numbering property of.true
if the menu items associated with the stored
objects of the list action are numbered; false
otherwise.public static boolean IsAutomatic(Action action)
ACTION_AUTOMATIC
for a more detailed description of
automatic actions.true
if action events of the specified action are
handled by the application; false
otherwise.ACTION_AUTOMATIC
,
SetAutomatic(javax.swing.Action, boolean)
public static boolean SetAutomatic(Action action, boolean automatic)
action
as automatic or not, depending on the
value of the specified automatic
parameter.action
- The action to set the automatic mode to.automatic
- If true
, the action will be set automatic;
if false
, the action will not be automatic.true
if the specified action was previously
automatic. Otherwise, this method returns false
.ACTION_AUTOMATIC
,
IsAutomatic(javax.swing.Action)
public static boolean IsActionList(Action action)
true
if the specified action is a list action;
false
otherwise.public IlvApplication getApplication()
public static void SetAction(Component component, Action action, IlvApplication application)
component
- The component to set the action to.action
- The action to set to the button.application
- The application to retrieve locale and icons from.public static void SetAction(AbstractButton button, Action action, IlvApplication application, int iconsSize)
button
- The button to set the action to.action
- The action to set to the button.application
- The application associated with the button.iconsSize
- The size of icons to set to the button. It can have one
of these values:SMALL_ICONS
for 16x16 icons.BIG_ICONS
for 32x32
icons.public static void UpdateButtonProperties(AbstractButton button, IlvApplication application)
button
properties according to the parameters
of its associated action. For example, after some locale parameters
have changed, this method can be invoked to update the button display
parameters accordingly.button
- The button to update the properties from.application
- The application of the button.public static void SetChecked(Action action, boolean state)
action
by
setting its ACTION_CHECK_STATE
property.
The action must have the ACTION_CHECKABLE
property set to
Boolean.TRUE
.action
- The action to change the check state of.state
- The new check state of the action.IsChecked(javax.swing.Action)
public static boolean IsChecked(Action action)
ACTION_CHECKABLE
property set to Boolean.TRUE
.action
- The action to get the check state from.true
if the action is checked; false
otherwise.SetChecked(Action, boolean)
public static void ActionProcessTerminated(Action action)
action
has been terminated.
ACTION_CHECK_ONE_SHOT
property set to Boolean.TRUE
, it will be unchecked.action
- The action with the process that has terminated.ACTION_CHECK_ONE_SHOT
,
GetGroup(javax.swing.Action)
public static String GetGroup(Action action)
action
belongs to.null
if the action
does not belong to any check group.public static Action GetSelectedGroupAction(IlvApplication application, String group)
group
of actions.application
- The application.group
- The name of the group to return the selected action from.null
if no action is currently
selected.public static void LockAction(Action action)
action
.
This method should only be invoked for checkable actions with the
ACTION_CHECK_ONE_SHOT
property set. It forces the action to
remain checked after an event for this action has been processed.
The action is unlocked using the method UnlockAction(javax.swing.Action)
. If the
action belongs to an action group, it can also be unlocked when another
action of this group has been selected.action
- The action to lock.UnlockAction(javax.swing.Action)
,
IsActionLocked(javax.swing.Action)
public static void UnlockAction(Action action)
action
, previously locked with
the method LockAction(javax.swing.Action)
.public static boolean IsActionLocked(Action action)
action
has been locked.action
- The action to determine the lock state of.true
if the action has been locked; false
otherwise.LockAction(javax.swing.Action)
,
UnlockAction(javax.swing.Action)
public static void SetChecked(Component component, Action action, boolean state)
component
- The component to set a check icon to.action
- The action associated with the component. It provides
the check display attributes for checking the component.state
- The check state of the component.public static void RegisterActionInGroup(Action action, Component child)
action
- Actionchild
- Component to be registered in the action grouppublic static void UnregisterActionInGroup(Component child)
public static char GetMnemonic(Action action, IlvApplication application)
action
.action
- The action to retrieve the mnemonic from.application
- The current application.null
if
not specified in the settings of the action.public static KeyStroke AcceleratorFromString(String s)
s
- The string representation of the accelerator to return.null
if the string representation has an invalid format.AcceleratorToString(javax.swing.KeyStroke)
public static String AcceleratorToString(KeyStroke accelerator)
accelerator
.accelerator
- The accelerator to provide a string representation from.accelerator
.AcceleratorFromString(java.lang.String)
© Copyright 2024 Rogue Wave Software, Inc., a Perforce company.. All Rights Reserved.