Advertisement
Lauda

undo/redo

Jun 14th, 2014
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  1.    /** @param command */
  2.    public void executeCommand(Command command) {
  3.       // TODO: implement
  4.        for(int i = commands.size() -1; i > currentCommandIndex; i--){
  5.            commands.remove(i); // praznjenje redo liste
  6.        }
  7.        commands.add(command);
  8.        command.execute();
  9.        currentCommandIndex++;
  10.    }
  11.    
  12.    public void undo() {
  13.       // TODO: implement
  14.        if(currentCommandIndex > -1){
  15.            Command currentCommandToUndo = commands.get(currentCommandIndex);
  16.            currentCommandToUndo.undo();
  17.            currentCommandIndex--;
  18.        }
  19.    }
  20.    
  21.    public void redo() {
  22.       // TODO: implement
  23.        if(currentCommandIndex < commands.size() -1){
  24.            Command currentCommandToRedo = commands.get(currentCommandIndex + 1);
  25.            currentCommandToRedo.execute();
  26.            currentCommandIndex++;
  27.        }
  28.    }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement