/* * 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 kontakte.controller; import java.awt.Component; import java.util.HashMap; import java.util.Stack; /** * Diese Klasse verknüpft Eventquellen mit ihren entsprechenden Kommandos. * * @see CommandInterface */ public class CommandInvoker { private HashMap commands; private Stack undoStack; public CommandInvoker() { commands = new HashMap<>(); undoStack = new Stack(); } public void addCommand(Component key, CommandInterface value) { commands.put(key, value); } public void executeCommand(Component key) { commands.get(key).execute(); undoStack.add(commands.get(key)); } public void undoCommand() { if (!undoStack.empty()) { undoStack.pop().undo(); } } }