org.vectomatic.client.rep.command
Class CommandHistory

java.lang.Object
  extended by org.vectomatic.client.rep.command.CommandHistory

public class CommandHistory
extends Object

Class to represent an undo/redo stack of commands with a fixed depth. The oldest command is automatically removed when the stack capacity is exhausted.

Author:
Lukas Laag

Constructor Summary
CommandHistory(int capacity)
          Constructor
 
Method Summary
 void addCommand(ICommand command)
          Adds a new command to the stack
 void addCommandHistoryListener(ICommandHistoryListener listener)
           
 boolean canRedo()
          Returns true if the command stack contains a command which can be redone false otherwise.
 boolean canUndo()
          Returns true if the command stack contains a command which can be undone false otherwise.
 void fireCommandHistoryChange()
           
 int getCapacity()
          Returns the stack capacity
 ICommand[] getCommands()
          Gets all the commands currently in the stack
 int getCurrentCommand()
          Returns the index of the current command in the array returned by getCommands().
 ICommand getRedoCommand()
          Returns the command which will be redone if undo is invoked
 ICommand getUndoCommand()
          Returns the command which will be undone if undo is invoked
 boolean needsSaving()
           
 void purge()
          Clears the stack
 void redo()
          Redoes the previously undone command
 void removeCommandHistoryListener(ICommandHistoryListener listener)
           
 void setCapacity(int capacity)
          Specifies a new capacity for the stack If the new capacity is smaller than the previous one, a proportional window of commands around the current command will be kept.
 void setSavePoint()
           
 void undo()
          Undoes the current command
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CommandHistory

public CommandHistory(int capacity)
Constructor

Parameters:
capacity - The depth of the undo stack
Method Detail

canUndo

public boolean canUndo()
Returns true if the command stack contains a command which can be undone false otherwise.

Returns:
true if the command stack contains a command which can be undone false otherwise.

canRedo

public boolean canRedo()
Returns true if the command stack contains a command which can be redone false otherwise.

Returns:
true if the command stack contains a command which can be redone false otherwise.

undo

public void undo()
Undoes the current command


redo

public void redo()
Redoes the previously undone command


addCommand

public void addCommand(ICommand command)
Adds a new command to the stack

Parameters:
command - the command to add

getUndoCommand

public ICommand getUndoCommand()
Returns the command which will be undone if undo is invoked

Returns:

getRedoCommand

public ICommand getRedoCommand()
Returns the command which will be redone if undo is invoked

Returns:

getCommands

public ICommand[] getCommands()
Gets all the commands currently in the stack

Returns:

getCurrentCommand

public int getCurrentCommand()
Returns the index of the current command in the array returned by getCommands(). It can vary between 0 and N where N is the number of commands in the stack. 0 means before the least recent command (redo is possible, undo is impossible). N means after the most recent command (redo is impossible, undo is possible)

Returns:

purge

public void purge()
Clears the stack


setCapacity

public void setCapacity(int capacity)
Specifies a new capacity for the stack If the new capacity is smaller than the previous one, a proportional window of commands around the current command will be kept.

Parameters:
capacity -

getCapacity

public int getCapacity()
Returns the stack capacity

Returns:

addCommandHistoryListener

public void addCommandHistoryListener(ICommandHistoryListener listener)

removeCommandHistoryListener

public void removeCommandHistoryListener(ICommandHistoryListener listener)

fireCommandHistoryChange

public void fireCommandHistoryChange()

setSavePoint

public void setSavePoint()

needsSaving

public boolean needsSaving()


Copyright © 2010. All Rights Reserved.