Class InsertTextCommand
java.lang.Object
fr.istic.aco.editor.commands.InsertTextCommand
- All Implemented Interfaces:
Command
,CommandOriginator
,Originator
The
InsertTextCommand
class implements the functionality for inserting a string in the buffer,
which replaces the contents of the selection-
Constructor Summary
ConstructorsConstructorDescriptionInsertTextCommand
(Engine engine, Invoker invoker, Recorder recorder, UndoManager undoManager) Constructs aCopyTextCommand
with the specified dependencies. -
Method Summary
Modifier and TypeMethodDescriptionvoid
execute()
Executes the command by inserting a string in the bufferCreates and returns a memento representing the current state of the insert command.void
setMemento
(Memento memento) Restores the state of the command from the provided memento.
-
Constructor Details
-
InsertTextCommand
public InsertTextCommand(Engine engine, Invoker invoker, Recorder recorder, UndoManager undoManager) Constructs aCopyTextCommand
with the specified dependencies.- Parameters:
engine
- the text editing engine responsible for text editing actionsinvoker
- the invoker object that provides the text to be insertedrecorder
- the command recorder for saving and replaying the commandundoManager
- the undo manager for handling undo and redo functionality
-
-
Method Details
-
getMemento
Creates and returns a memento representing the current state of the insert command.The memento stores the text to be inserted, which is retrieved from the
Invoker
.- Specified by:
getMemento
in interfaceOriginator
- Returns:
- a memento containing the text to be inserted
-
setMemento
Restores the state of the command from the provided memento.The text stored in the memento is set back to the
Invoker
.- Specified by:
setMemento
in interfaceOriginator
- Parameters:
memento
- the memento object containing the state to restore
-
execute
public void execute()Executes the command by inserting a string in the bufferBefore executing, the current state of the
Engine
is stored in theUndoManager
as a memento. The command is also saved in theRecorder
for replay functionality.
-