Class History

All Implemented Interfaces:
Serializable, Cloneable, Iterable<Action<?>>, Collection<Action<?>>, List<Action<?>>, RandomAccess, SequencedCollection<Action<?>>

public class History extends ArrayList<Action<?>>
Manages a history of actions, allowing for undo and redo functionality. It extends ArrayList to store Action objects.
Author:
Lehlogonolo Poole
See Also:
  • Field Details

    • backup

      private final Backup backup
      Where actions that are undone are stored for redo functionality.
    • logHead

      public static final String logHead
      See Also:
    • panel

      public static HistoryPanel panel
    • serialVersionUID

      private static final long serialVersionUID
      Serial version UID for serialization.
      See Also:
    • MAX_HISTORY_SIZE

      private static final int MAX_HISTORY_SIZE
      See Also:
  • Constructor Details

    • History

      public History()
  • Method Details

    • undo

      public void undo()
      Undoes the last action in the history.
    • redo

      public void redo()
      Removes and returns the last action in the history.
    • repaint

      private static void repaint()
    • bypassAdd

      private void bypassAdd(Action<?> action)
      Adds an action to the history, bypassing the size limit and backup clearing. This is used for redoing actions.
      Parameters:
      action - The action to add.
    • add

      public boolean add(Action<?> action)
      Specified by:
      add in interface Collection<Action<?>>
      Specified by:
      add in interface List<Action<?>>
      Overrides:
      add in class ArrayList<Action<?>>
    • clear

      public void clear()
      Specified by:
      clear in interface Collection<Action<?>>
      Specified by:
      clear in interface List<Action<?>>
      Overrides:
      clear in class ArrayList<Action<?>>
    • clearLocators

      private static void clearLocators()
    • updateHistory

      private void updateHistory()
      Updates the history panel with the current actions in the history and backup. This method clears the existing panels and repopulates them.
    • apply

      public void apply(Action<?> action)
      Applies a given action by either redoing it from the backup or undoing actions from the history until the target action is reached.
      Parameters:
      action - The action to apply.