/* * 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 command.CommandInterface; import command.CommandInvoker; import command.commands.CommandEintragHinzufuegen; import command.commands.CommandEintragLoeschen; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; import java.util.prefs.Preferences; import model.AdressVerwaltungModel; import view.MainWindow; /** * * @author PC */ public class CommandController implements ActionListener, WindowListener{ private MainWindow view; private AdressVerwaltungModel model; private CommandInvoker invoker; private Preferences prefs; public CommandController(MainWindow view, AdressVerwaltungModel model) { this.view = view; this.model = model; this.invoker = new CommandInvoker(); this.prefs = Preferences.userRoot().node(this.getClass().getName()); view.getjTableAdressen().setModel(model); //Übernehme Model registerEvents(); registerCommands(); } public void registerEvents() { view.getJpopEintragHinzufuegen().addActionListener(this); view.getJpopEintragLoeschen().addActionListener(this); } public void registerCommands() { CommandEintragHinzufuegen cmdHinzufuegen = new CommandEintragHinzufuegen(view, model); CommandEintragLoeschen cmdLoeschen = new CommandEintragLoeschen(view, model); invoker.addCommand(view.getJpopEintragHinzufuegen(), cmdHinzufuegen); invoker.addCommand(view.getJpopEintragLoeschen(), cmdLoeschen); } @Override public void actionPerformed(ActionEvent evt) { Object key = evt.getSource(); invoker.executeCommand(key); } @Override public void windowOpened(WindowEvent we) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void windowClosing(WindowEvent we) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void windowClosed(WindowEvent we) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void windowIconified(WindowEvent we) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void windowDeiconified(WindowEvent we) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void windowActivated(WindowEvent we) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void windowDeactivated(WindowEvent we) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }