1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- /*
- * 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;
-
- /**
- *
- * @author nobody
- */
- 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();
- }
- }
-
- }
|