|
Using Command Hints
Hints are the basic mechanism by which you can parameterize the execution of a command. Hints are configured by the invoker by calling Command.putHint(...) or by provided by a Map to the execute method. Hints are retrieved during command execution by calling getHint(...). All hints are cleared automatically after the command has finished execution.
I've used hints in dialog commands to control the initial state of the dialog. This has been particularly useful with application settings where I've been able to include command hyperlinks help information that takes users directly to the configuration page of interest.
Predefined Hints
There are a number of predefined hints. These will be present when ever the command is triggered by a button or menu.
ActionCommand.HINT_ACTION_EVENT
This hint is the ActionEvent associated with the button press the triggered the command.
ActionCommand.HINT_MODIFIERS This hint is the modifiers of the previously mentioned ActionEvent.
ActionCommand.HINT_INVOKER
This hint is the component that triggered the command. In the case of buttons and menus it's the button or menu itself. In the case of HTML links it is the JEditorPane that contained the link.
Convenience Methods
There are a number of convenience methods for accessing hints.
int getModifiers()
Gets the modifiers as specified by ActionCommand.HINT_MODIFIERS.
Object getInvoker()
Gets the invoker of the command as specified by ActionCommand.HINT_INVOKER.
Window getInvokerWindow()
This method attempts to find a Window ancestor for the invoker.
|