/* * 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 controller.commands.CommandLoescheDaten; import controller.commands.CommandNeueDaten; import controller.commands.CommandOpen; import controller.commands.CommandSave; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import model.AdressverwaltungModel; import view.Adressverwaltung; /** * * @author nobody */ public class CommandController implements ActionListener { private Adressverwaltung view; private AdressverwaltungModel model; private CommandInvoker invoker; public CommandController(Adressverwaltung view,AdressverwaltungModel model) { this.view = view; this.model = model; invoker = new CommandInvoker(); } public void registerEvents() { view.getMnuioeffnen().addActionListener(this); view.getMnuispeichern().addActionListener(this); view.getMnuineueadresse().addActionListener(this); view.getMnuiloescheadresse().addActionListener(this); view.getBtnoeffnen().addActionListener(this); view.getBtnspeichern().addActionListener(this); view.getBtnneueadresse().addActionListener(this); view.getBtnloescheadresse().addActionListener(this); } public void registerCommands() { invoker.addCommand(view.getMnuioeffnen(), new CommandOpen(view, model)); invoker.addCommand(view.getMnuispeichern(), new CommandSave(view,model)); invoker.addCommand(view.getMnuineueadresse(),new CommandNeueDaten(view,model)); invoker.addCommand(view.getMnuiloescheadresse(),new CommandLoescheDaten(view,model)); } @Override public void actionPerformed(ActionEvent e) { Object key = e.getSource(); invoker.executeCommand(key); } }