com.dlsc.flexgantt.command

## Class DefaultCommandStack

- java.lang.Object
- - com.dlsc.flexgantt.command.DefaultCommandStack

- All Implemented Interfaces:
    ICommandStack

      public class DefaultCommandStack
      extends Object
      implements ICommandStack

  The default command stack implementation manages a list of executed and undone commands. The stack has a default size of 20, which means that the last 20 commands can be undone. The stack size can be passed to the stack's constructor. Commands will be removed from the stack once the stack's limit is reached.
  Since:
    1.0
  Version:
    $Revision: 1.22 $
  Author:
    Dirk Lemmermann
  See Also:
    `ICommand`, `ICommandStackListener`

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `DefaultCommandStack()` Creates a new command stack with a default size (number of undoable commands).
    `DefaultCommandStack(int size)` Creates a new command stack.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addCommandStackListener(ICommandStackListener l)` Adds a listener to the command stack.
    `void` | `clear()` Clears the command stack, which means that the list of executed and undone commands will be cleared and no further commands can be undone or redone.
    `void` | `execute(ICommand cmd, IProgressMonitor monitor)` Executes the given command.
    `protected void` | `fireCommandStackChanged(CommandStackEvent event)` Used internally to inform stack listeners about executed, undone or redone commands.
    `ICommandStackListener[]` | `getCommandStackListeners()` Returns all command stack listeners.
    `List<ICommand>` | `getExecutedCommands()` Returns a copy of the list of executed commands.
    `ICommand` | `getRedoableCommand()` Returns the command, which would be redone if the application called the redo operation on the stack.
    `int` | `getSize()` Returns the stack size as defined via the constructor or default stack size value.
    `ICommand` | `getUndoableCommand()` Returns the command, which would be undone if the application called the undo operation on the stack.
    `List<ICommand>` | `getUndoneCommands()` Returns a copy of the list of undone commands.
    `boolean` | `isRedoable()` Determines whether the command stack currently supports the redo operation.
    `boolean` | `isUndoable()` Determines whether the command stack currently supports the undo operation.
    `void` | `redo(IProgressMonitor monitor)` If it is redoable then the last undone command can be redone by calling this method.
    `void` | `removeCommandStackListener(ICommandStackListener l)` Removes a listener from the command stack.
    `void` | `undo(IProgressMonitor monitor)` If it is undoable then the last executed command can be undone by calling this method.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### DefaultCommandStack

          public DefaultCommandStack(int size)

      Creates a new command stack.
      Parameters:
        `size` - the maximum stack size and number of undoable commands
      Since:
        1.0

    - #### DefaultCommandStack

          public DefaultCommandStack()

      Creates a new command stack with a default size (number of undoable commands).
      Since:
        1.0

  - ### Method Detail

    - #### getSize

          public int getSize()

      Returns the stack size as defined via the constructor or default stack size value.
      Returns:
        the command stack's size
      Since:
        1.0

    - #### execute

          public void execute(ICommand cmd,
                              IProgressMonitor monitor)

      Executes the given command. If undoable the command will be added to the list of undoable commands. This list will be cleared if the command is not undoable. If the number of undoable commands exceeds the stack size then the oldest undoable command will be removed from the stack. A command stack event will be fired upon completion of the command execution.
      Specified by:
        `execute` in interface `ICommandStack`
      Parameters:
        `cmd` - the command to execute
        `monitor` - a monitor to report the command's progress to
      Since:
        1.0
      See Also:
        `CommandStackEvent`

    - #### undo

          public void undo(IProgressMonitor monitor)

      If it is undoable then the last executed command can be undone by calling this method. The command will be stored in the list of undone commands and an event will be fired, which informs the listeners of the stack that the command was undone.
      Specified by:
        `undo` in interface `ICommandStack`
      Parameters:
        `monitor` - a monitor for reporting progress of the undo operation
      Since:
        1.0
      See Also:
        `ICommandStack.undo(IProgressMonitor)`, `CommandStackEvent`

    - #### redo

          public void redo(IProgressMonitor monitor)

      If it is redoable then the last undone command can be redone by calling this method. The command will be put back on the list of executed commands and an event will be fired, which informs the listeners of the stack that the command was redone.
      Specified by:
        `redo` in interface `ICommandStack`
      Parameters:
        `monitor` - a monitor for reporting the progress of the redo operation
      Since:
        1.0
      See Also:
        `ICommandStack.redo(IProgressMonitor)`, `CommandStackEvent`

    - #### clear

          public void clear()

      Clears the command stack, which means that the list of executed and undone commands will be cleared and no further commands can be undone or redone.
      Specified by:
        `clear` in interface `ICommandStack`
      Since:
        1.0
      See Also:
        `ICommandStack.clear()`

    - #### isUndoable

          public boolean isUndoable()

      Determines whether the command stack currently supports the undo operation. This depends on the last executed command. If the command can be undone then the stack can be undone.
      Specified by:
        `isUndoable` in interface `ICommandStack`
      Returns:
        boolean
      Since:
        1.0
      See Also:
        `ICommandStack.isUndoable()`

    - #### isRedoable

          public boolean isRedoable()

      Determines whether the command stack currently supports the redo operation. This depends on the last undone command. If the command can be redone then the stack can be redone.
      Specified by:
        `isRedoable` in interface `ICommandStack`
      Returns:
        boolean
      Since:
        1.0
      See Also:
        `ICommandStack.isRedoable()`

    - #### addCommandStackListener

          public void addCommandStackListener(ICommandStackListener l)

      Adds a listener to the command stack. The listener will receive command stack events informing it which command was executed, undone or redone.
      Specified by:
        `addCommandStackListener` in interface `ICommandStack`
      Parameters:
        `l` - the listener to add
      Since:
        1.0
      See Also:
        `ICommandStack.addCommandStackListener(ICommandStackListener)`

    - #### removeCommandStackListener

          public void removeCommandStackListener(ICommandStackListener l)

      Removes a listener from the command stack.
      Specified by:
        `removeCommandStackListener` in interface `ICommandStack`
      Parameters:
        `l` - the listener to remove
      Since:
        1.0
      See Also:
        `ICommandStack.removeCommandStackListener(ICommandStackListener)`

    - #### getCommandStackListeners

          public ICommandStackListener[] getCommandStackListeners()

      Returns all command stack listeners.
      Returns:
        an array of all command stack listeners
      Since:
        1.0

    - #### fireCommandStackChanged

          protected void fireCommandStackChanged(CommandStackEvent event)

      Used internally to inform stack listeners about executed, undone or redone commands.
      Parameters:
        `event` - the event to send to the listeners
      Since:
        1.0

    - #### getUndoableCommand

          public ICommand getUndoableCommand()

      Returns the command, which would be undone if the application called the undo operation on the stack. This method is useful for displaying the command's name in an undo button or menu item.
      Specified by:
        `getUndoableCommand` in interface `ICommandStack`
      Returns:
        the next undoable command or NULL if the last command that was executed can not be undone
      Since:
        1.0
      See Also:
        `ICommandStack.getUndoableCommand()`

    - #### getRedoableCommand

          public ICommand getRedoableCommand()

      Returns the command, which would be redone if the application called the redo operation on the stack. This method is useful for displaying the command's name in a redo button or menu item.
      Specified by:
        `getRedoableCommand` in interface `ICommandStack`
      Returns:
        the next redoable command or NULL if the last command that was undone can not be redone
      Since:
        1.0
      See Also:
        `ICommandStack.getRedoableCommand()`

    - #### getExecutedCommands

          public List<ICommand> getExecutedCommands()

      Returns a copy of the list of executed commands. The next undo operation will be performed on the last command in this list.
      Returns:
        a list of executed commands that can be undone
      Since:
        1.0

    - #### getUndoneCommands

          public List<ICommand> getUndoneCommands()

      Returns a copy of the list of undone commands. The next redo operation will be performed on the last command in this list.
      Returns:
        a list of undone commands that can be redone
      Since:
        1.0

Copyright © 2006–2020 Dirk Lemmermann Software & Consulting. All rights reserved.