|
Programatic Creation
The new programatic face creation behaviour makes it easy to implement on the fly commands
and faces. Commands and Groups can now also be anonymous in that they don't required an Id.
Such commands can't be configured using XML or exported. There are intended to be used only
in a programatic manner.
ActionCommand c = new ActionCommand()
{
public void handleExecute() {}
}
c.addNewFace("default").setText("My Anonymous Command");
Do I need a Command Id?
Commands only require an Id if you want their faces configured using the XML templates or you wish to make them dynamically available via the command.export() mechanism. It is perfectly legal to omit XML configuration data for commands even when Ids are specified. In this case, the CommandManager simply ignores the automatic configuration request, but you will be required to add at least one face programatically before using the command.
For example.
// there is no XML config defined for 'my-programatic-group'
CommandGroup group = new CommandGroup("my-programatic-group", CommangManager.defaultInstance());
// so now I must add at least one face before I use it
group.addNewFace("default").setText("Programatic Group");
// now lets add a command without an Id
ActionCommand anonymousCommand = new ActionCommand()
{
public void handleExecute()
{
Toolkit.getDefaultToolkit().beep()
}
}
anonymousCommand.addNewFace("default").setText("Anonymous Command");
// and add it to my group
group.add(anonymousCommand);
In the above case, other Groups can include 'my-programatic-group' in their member lists even though it has no XML defininition. The ActionCommand
defined above can't be included and must be manually added to any group that requires it.
What Command types can I create?
The four basic classes that can be created or extended are:
- ActionCommand
- ToggleCommand
- CommandGroup
- ToggleCommandGroup
|