Package pt.tecnico.uilib.menus
Class Command<Receiver>
java.lang.Object
pt.tecnico.uilib.menus.Command<Receiver>
- Type Parameters:
Receiver- the entity providing the command's context.
- Direct Known Subclasses:
DoOpenMenu
Command represents an operation that can be carried out by or over an entity.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescription -
Method Summary
Modifier and TypeMethodDescriptionvoidaddBooleanField(String key, String prompt) voidaddIntegerField(String key, String prompt) voidaddOptionField(String key, String prompt, String... options) voidaddRealField(String key, String prompt) voidaddStringField(String key, String prompt) booleanField(String key) protected abstract voidexecute()Executes the command: as defined in the Command pattern, the command's execution should eventually invoke the receiver's action.integerField(String key) booleanisLast()Indicates whether, in a menu, this is the last command.booleanisValid()optionField(String key) final voidstringField(String key) final Stringtitle()
-
Field Details
-
_receiver
The entity providing the command's context. -
_valid
The validity predicate: is the command available/visible? -
_display
This command's display.
-
-
Constructor Details
-
Command
- Parameters:
last- indicates whether, in a menu, this is the last command.title- the command label in a menu.
-
Command
- Parameters:
last- indicates whether, in a menu, this is the last command.title- the command label in a menu.receiver- the entity providing the command's context.
-
Command
- Parameters:
last- indicates whether, in a menu, this is the last command.title- the command label in a menu.receiver- the entity providing the command's context.valid- custom validity predicate
-
Command
- Parameters:
title- the command label in a menu.receiver- the entity providing the command's context.
-
Command
- Parameters:
title- the command label in a menu.receiver- the entity providing the command's context.valid- custom validity predicate
-
-
Method Details
-
title
- Returns:
- the command's title.
-
isLast
public boolean isLast()Indicates whether, in a menu, this is the last command.- Returns:
- true if, in a menu, this is the last command.
-
isValid
public boolean isValid()- Returns:
- whether the command is valid for the given receiver.
-
addBooleanField
-
addRealField
-
addIntegerField
-
addStringField
-
addOptionField
-
booleanField
-
realField
-
integerField
-
stringField
-
optionField
-
performCommand
- Throws:
CommandException
-
execute
Executes the command: as defined in the Command pattern, the command's execution should eventually invoke the receiver's action.- Throws:
CommandException- if something wrong or unexpected occurs.
-