You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Controller.java 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package kontakte.controller ;
  7. import java.awt.Component;
  8. import java.awt.event.ActionEvent;
  9. import java.awt.event.ActionListener;
  10. import kontakte.model.Model;
  11. import kontakte.view.View;
  12. /**
  13. *
  14. * @author nobody
  15. */
  16. public class Controller implements ActionListener
  17. {
  18. private View view;
  19. private Model model;
  20. private CommandInvoker invoker;
  21. public Controller(View view, Model model)
  22. {
  23. this.view = view;
  24. this.model = model;
  25. invoker = new CommandInvoker();
  26. }
  27. public void registerEvents()
  28. {
  29. view.getBtnOpen().addActionListener(this);
  30. view.getMenuOpen().addActionListener(this);
  31. view.getBtnSave().addActionListener(this);
  32. view.getMenuSave().addActionListener(this);
  33. view.getBtnNewEntry().addActionListener(this);
  34. view.getBtnOk().addActionListener(this);
  35. view.getBtnCancel().addActionListener(this);
  36. view.getMenuUndo().addActionListener(this);
  37. }
  38. public void registerCommands()
  39. {
  40. CommandOpen cmdOpen = new CommandOpen(view, model);
  41. invoker.addCommand(view.getBtnOpen(), cmdOpen);
  42. invoker.addCommand(view.getMenuOpen(), cmdOpen);
  43. CommandSave cmdSave = new CommandSave(view, model);
  44. invoker.addCommand(view.getBtnSave(), cmdSave);
  45. invoker.addCommand(view.getMenuSave(), cmdSave);
  46. invoker.addCommand(view.getBtnNewEntry(), new CommandNewKontaktVisible(view, model));
  47. invoker.addCommand(view.getBtnOk(),new CommandNewKontaktOk(view,model));
  48. invoker.addCommand(view.getBtnCancel(),new CommandNewKontaktCancel(view,model));
  49. }
  50. @Override
  51. public void actionPerformed(ActionEvent e)
  52. {
  53. Component key = (Component)e.getSource();
  54. if(key != view.getMenuUndo())
  55. {
  56. invoker.executeCommand(key);
  57. }
  58. else
  59. {
  60. invoker.undoCommand();
  61. }
  62. }
  63. }