/* * 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 command.commands.CommandOpenFile; import command.commands.CommandSaveFile; 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()); registerEvents(); registerCommands(); } public void registerEvents() { view.getJpopEintragHinzufuegen().addActionListener(this); view.getJpopEintragLoeschen().addActionListener(this); view.getJbOpen().addActionListener(this); view.getJbSave().addActionListener(this); view.getFileOpen().addActionListener(this); view.getFileSave().addActionListener(this); view.getMiUndo().addActionListener(this); } public void registerCommands() { CommandEintragHinzufuegen cmdHinzufuegen = new CommandEintragHinzufuegen(view, model); CommandEintragLoeschen cmdLoeschen = new CommandEintragLoeschen(view, model); CommandSaveFile cmdSaveFile = new CommandSaveFile(view, model); CommandOpenFile cmdOpenFile = new CommandOpenFile(view, model); invoker.addCommand(view.getJpopEintragHinzufuegen(), cmdHinzufuegen); invoker.addCommand(view.getJpopEintragLoeschen(), cmdLoeschen); invoker.addCommand(view.getJbOpen(), cmdOpenFile); invoker.addCommand(view.getJbSave(), cmdSaveFile); invoker.addCommand(view.getFileOpen(), cmdOpenFile); invoker.addCommand(view.getFileSave(), cmdSaveFile); } /** * actionPerformed Funktion wird aufgerufen * @param evt *
* Hallo Guten Tag */ @Override public void actionPerformed(ActionEvent evt) { Object key = evt.getSource(); if(key == view.getMiUndo()) { invoker.undoCommand(); } else { 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. } }