12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package commands;
-
- import java.awt.Component;
- import java.util.HashMap;
- import java.util.Stack;
-
- /**
- * Command Invoker
- * ordnet den verschiedenen Events die Kommandos zu
- * speichert die letzten Kommandos im Stack
- * @author matthias
- */
- public class CommandInvoker {
- private HashMap<Component, CommandInterface> commands;
- private Stack<CommandInterface> undoStack;
-
- public CommandInvoker()
- {
- this.commands = new HashMap<>();
- this.undoStack = new Stack<>();
- }
-
- public void addCommand(Component key, CommandInterface val)
- {
- this.commands.put(key, val);
- }
-
- /**
- * führt das zugehörige Kommand zum Key(Object) aus
- * @param key (Objekt)
- */
- public void executeCommand(Component key)
- {
- this.commands.get(key).execute();
- this.undoStack.push(this.commands.get(key));
- }
- /**
- * führt das zugehörige undo vom letzten Kommand aus
- */
- public void undoCommand()
- {
- if (!this.undoStack.isEmpty())
- {
- this.undoStack.pop().undo();
- }
- }
- }
|