12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- /*
- * 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.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import kontakte.model.Model;
- import kontakte.view.View;
-
- /**
- * Diese Klasse leitet Events von der View an den CommandInvoker weiter.
- *
- * @see View
- * @see CommandInvoker
- */
- public class Controller implements ActionListener
- {
- private View view;
- private Model model;
- private CommandInvoker invoker;
-
- public Controller(View view, Model model)
- {
- this.view = view;
- this.model = model;
- invoker = new CommandInvoker();
- }
-
- public void registerEvents()
- {
- view.getBtnOpen().addActionListener(this);
- view.getMenuOpen().addActionListener(this);
- view.getBtnSave().addActionListener(this);
- view.getMenuSave().addActionListener(this);
- view.getBtnNewEntry().addActionListener(this);
- view.getBtnOk().addActionListener(this);
- view.getBtnCancel().addActionListener(this);
- view.getMenuUndo().addActionListener(this);
- }
-
- public void registerCommands()
- {
- CommandOpen cmdOpen = new CommandOpen(view, model);
- invoker.addCommand(view.getBtnOpen(), cmdOpen);
- invoker.addCommand(view.getMenuOpen(), cmdOpen);
- CommandSave cmdSave = new CommandSave(view, model);
- invoker.addCommand(view.getBtnSave(), cmdSave);
- invoker.addCommand(view.getMenuSave(), cmdSave);
- invoker.addCommand(view.getBtnNewEntry(), new CommandNewKontaktVisible(view, model));
- invoker.addCommand(view.getBtnOk(),new CommandNewKontaktOk(view,model));
- invoker.addCommand(view.getBtnCancel(),new CommandNewKontaktCancel(view,model));
- }
-
- @Override
- public void actionPerformed(ActionEvent e)
- {
- Component key = (Component)e.getSource();
- if(key != view.getMenuUndo())
- {
- invoker.executeCommand(key);
- }
- else
- {
- invoker.undoCommand();
- }
- }
-
- }
|