Class InsertTextCommand

java.lang.Object
fr.istic.aco.editor.commands.InsertTextCommand
All Implemented Interfaces:
Command, CommandOriginator, Originator

public class InsertTextCommand extends Object implements CommandOriginator
The InsertTextCommand class implements the functionality for inserting a string in the buffer, which replaces the contents of the selection
  • Constructor Details

    • InsertTextCommand

      public InsertTextCommand(Engine engine, Invoker invoker, Recorder recorder, UndoManager undoManager)
      Constructs a CopyTextCommand with the specified dependencies.
      Parameters:
      engine - the text editing engine responsible for text editing actions
      invoker - the invoker object that provides the text to be inserted
      recorder - the command recorder for saving and replaying the command
      undoManager - the undo manager for handling undo and redo functionality
  • Method Details

    • getMemento

      public Memento 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 interface Originator
      Returns:
      a memento containing the text to be inserted
    • setMemento

      public void setMemento(Memento memento)
      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 interface Originator
      Parameters:
      memento - the memento object containing the state to restore
    • execute

      public void execute()
      Executes the command by inserting a string in the buffer

      Before executing, the current state of the Engine is stored in the UndoManager as a memento. The command is also saved in the Recorder for replay functionality.

      Specified by:
      execute in interface Command