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
-
Constructor Summary
ConstructorDescription -
Method Summary
Modifier and TypeMethodDescriptionvoid
addBooleanField
(String key, String prompt) void
addIntegerField
(String key, String prompt) void
addOptionField
(String key, String prompt, String... options) void
addRealField
(String key, String prompt) void
addStringField
(String key, String prompt) booleanField
(String key) protected abstract void
execute()
Executes the command: as defined in the Command pattern, the command's execution should eventually invoke the receiver's action.integerField
(String key) boolean
isLast()
Indicates whether, in a menu, this is the last command.boolean
isValid()
optionField
(String key) final void
stringField
(String key) final String
title()
-
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.
-