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.

CommandController.java 3.5KB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 controller;
  7. import command.CommandInterface;
  8. import command.CommandInvoker;
  9. import command.commands.CommandEintragHinzufuegen;
  10. import command.commands.CommandEintragLoeschen;
  11. import java.awt.event.ActionEvent;
  12. import java.awt.event.ActionListener;
  13. import java.awt.event.WindowEvent;
  14. import java.awt.event.WindowListener;
  15. import java.util.prefs.Preferences;
  16. import model.AdressVerwaltungModel;
  17. import view.MainWindow;
  18. /**
  19. *
  20. * @author PC
  21. */
  22. public class CommandController implements ActionListener, WindowListener{
  23. private MainWindow view;
  24. private AdressVerwaltungModel model;
  25. private CommandInvoker invoker;
  26. private Preferences prefs;
  27. public CommandController(MainWindow view, AdressVerwaltungModel model)
  28. {
  29. this.view = view;
  30. this.model = model;
  31. this.invoker = new CommandInvoker();
  32. this.prefs = Preferences.userRoot().node(this.getClass().getName());
  33. view.getjTableAdressen().setModel(model); //Übernehme Model
  34. registerEvents();
  35. registerCommands();
  36. }
  37. public void registerEvents()
  38. {
  39. view.getJpopEintragHinzufuegen().addActionListener(this);
  40. view.getJpopEintragLoeschen().addActionListener(this);
  41. }
  42. public void registerCommands()
  43. {
  44. CommandEintragHinzufuegen cmdHinzufuegen = new CommandEintragHinzufuegen(view, model);
  45. CommandEintragLoeschen cmdLoeschen = new CommandEintragLoeschen(view, model);
  46. invoker.addCommand(view.getJpopEintragHinzufuegen(), cmdHinzufuegen);
  47. invoker.addCommand(view.getJpopEintragLoeschen(), cmdLoeschen);
  48. }
  49. @Override
  50. public void actionPerformed(ActionEvent evt) {
  51. Object key = evt.getSource();
  52. invoker.executeCommand(key);
  53. }
  54. @Override
  55. public void windowOpened(WindowEvent we) {
  56. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  57. }
  58. @Override
  59. public void windowClosing(WindowEvent we) {
  60. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  61. }
  62. @Override
  63. public void windowClosed(WindowEvent we) {
  64. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  65. }
  66. @Override
  67. public void windowIconified(WindowEvent we) {
  68. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  69. }
  70. @Override
  71. public void windowDeiconified(WindowEvent we) {
  72. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  73. }
  74. @Override
  75. public void windowActivated(WindowEvent we) {
  76. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  77. }
  78. @Override
  79. public void windowDeactivated(WindowEvent we) {
  80. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  81. }
  82. }