123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- /*
- * 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 controller;
-
- import java.util.HashMap;
- import java.util.Stack;
-
- /**
- *
- * @author Jan
- * Invoker für alle Commands zur übersichtlichkeit, evtl. undo anruf?
- */
- public class CommandInvoker
- {
-
- private HashMap<Object, CommandInterface> commands;
- private Stack<CommandInterface> undoStack;
-
- public CommandInvoker()
- {
- commands = new HashMap<>();
- undoStack = new Stack<>();
- }
-
- public void addCommand(Object key,CommandInterface value)
- {
- commands.put(key,value);
- }
-
- public void executeCommand(Object key)
- {
- commands.get(key).execute();
- if(commands.get(key).isundoable()==true)
- {
- undoStack.push(commands.get(key));
- }
- }
-
- public void undoCommand(Object key)
- {
- try
- {
- undoStack.pop().undo();
- }
- catch (Exception e)
- {
-
- }
- }
- }
|