Class MoveSelection

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

public class MoveSelection extends Object implements CommandOriginator
The MoveSelection class implements the functionality for selecting the text within the interval
  • Constructor Details

    • MoveSelection

      public MoveSelection(Engine engine, Invoker invoker, Recorder recorder, UndoManager undoManager)
      Constructs a MoveSelection 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 selection command.

      The memento stores the beginning and ending indices of the selection range, which are retrieved from the Invoker.

      Specified by:
      getMemento in interface Originator
      Returns:
      a memento containing the selection range (beginning and ending indices)
    • setMemento

      public void setMemento(Memento memento)
      Restores the state of the command from the provided memento.

      The beginning and ending indices stored in the memento are restored 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 to update the text selection range.

      This method performs the following steps:

      • Saves the current state of the Engine in the UndoManager to enable undo functionality.
      • Updates the selection range using the beginning and ending indices provided by the Invoker.
      • Records the command in the Recorder for replay functionality.
      Specified by:
      execute in interface Command