GUI Commands User GuideVersion 2.1 |
||
Creating Toggle CommandsThe following shows a very simple toggle command implementation:
public class LightOnCommand
extends ToggleCommand
{
public LightOnCommand
{
super("light-on");
}
public void handleSelection(boolean selected) throws ToggleVetoException
{
if (selected && isNotDark())
{
throw new ToggleVetoException("Light can only be used when dark");
}
light.setOn(selected)
}
}
Most of the work of the toggle command is managed behind the scenes, but the command specified selection behavior is delegated to the handleSelection method. If selection request can't be honoured, the method should throw a ToggleVetoException. This behavior is respected by exclusive groups and a change in selection state will only be made if the currently selected command relinquishes selection. |
||