You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CommandInvoker.java 997B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package kontakte.controller;
  7. import java.awt.Component;
  8. import java.util.HashMap;
  9. import java.util.Stack;
  10. /**
  11. * Diese Klasse verknüpft Eventquellen mit ihren entsprechenden Kommandos.
  12. *
  13. * @see CommandInterface
  14. */
  15. public class CommandInvoker
  16. {
  17. private HashMap<Component, CommandInterface> commands;
  18. private Stack<CommandInterface> undoStack;
  19. public CommandInvoker()
  20. {
  21. commands = new HashMap<>();
  22. undoStack = new Stack<CommandInterface>();
  23. }
  24. public void addCommand(Component key, CommandInterface value)
  25. {
  26. commands.put(key, value);
  27. }
  28. public void executeCommand(Component key)
  29. {
  30. commands.get(key).execute();
  31. undoStack.add(commands.get(key));
  32. }
  33. public void undoCommand()
  34. {
  35. if (!undoStack.empty())
  36. {
  37. undoStack.pop().undo();
  38. }
  39. }
  40. }