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 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 command.commands.CommandOpenFile;
  12. import command.commands.CommandSaveFile;
  13. import java.awt.event.ActionEvent;
  14. import java.awt.event.ActionListener;
  15. import java.awt.event.WindowEvent;
  16. import java.awt.event.WindowListener;
  17. import java.util.prefs.Preferences;
  18. import model.AdressVerwaltungModel;
  19. import view.MainWindow;
  20. /**
  21. *
  22. * @author PC
  23. */
  24. public class CommandController implements ActionListener, WindowListener{
  25. private MainWindow view;
  26. private AdressVerwaltungModel model;
  27. private CommandInvoker invoker;
  28. //private Preferences prefs;
  29. public CommandController(MainWindow view, AdressVerwaltungModel model)
  30. {
  31. this.view = view;
  32. this.model = model;
  33. this.invoker = new CommandInvoker();
  34. //this.prefs = Preferences.userRoot().node(this.getClass().getName());
  35. registerEvents();
  36. registerCommands();
  37. }
  38. public void registerEvents()
  39. {
  40. view.getJpopEintragHinzufuegen().addActionListener(this);
  41. view.getJpopEintragLoeschen().addActionListener(this);
  42. view.getJbOpen().addActionListener(this);
  43. view.getJbSave().addActionListener(this);
  44. view.getFileOpen().addActionListener(this);
  45. view.getFileSave().addActionListener(this);
  46. view.getMiUndo().addActionListener(this);
  47. }
  48. public void registerCommands()
  49. {
  50. CommandEintragHinzufuegen cmdHinzufuegen = new CommandEintragHinzufuegen(view, model);
  51. CommandEintragLoeschen cmdLoeschen = new CommandEintragLoeschen(view, model);
  52. CommandSaveFile cmdSaveFile = new CommandSaveFile(view, model);
  53. CommandOpenFile cmdOpenFile = new CommandOpenFile(view, model);
  54. invoker.addCommand(view.getJpopEintragHinzufuegen(), cmdHinzufuegen);
  55. invoker.addCommand(view.getJpopEintragLoeschen(), cmdLoeschen);
  56. invoker.addCommand(view.getJbOpen(), cmdOpenFile);
  57. invoker.addCommand(view.getJbSave(), cmdSaveFile);
  58. invoker.addCommand(view.getFileOpen(), cmdOpenFile);
  59. invoker.addCommand(view.getFileSave(), cmdSaveFile);
  60. }
  61. /**
  62. * actionPerformed Funktion wird aufgerufen
  63. * @param evt
  64. * <br>
  65. * Hallo Guten Tag
  66. */
  67. @Override
  68. public void actionPerformed(ActionEvent evt) {
  69. Object key = evt.getSource();
  70. if(key == view.getMiUndo())
  71. {
  72. invoker.undoCommand();
  73. }
  74. else
  75. {
  76. invoker.executeCommand(key);
  77. }
  78. }
  79. @Override
  80. public void windowOpened(WindowEvent we) {
  81. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  82. }
  83. @Override
  84. public void windowClosing(WindowEvent we) {
  85. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  86. }
  87. @Override
  88. public void windowClosed(WindowEvent we) {
  89. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  90. }
  91. @Override
  92. public void windowIconified(WindowEvent we) {
  93. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  94. }
  95. @Override
  96. public void windowDeiconified(WindowEvent we) {
  97. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  98. }
  99. @Override
  100. public void windowActivated(WindowEvent we) {
  101. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  102. }
  103. @Override
  104. public void windowDeactivated(WindowEvent we) {
  105. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  106. }
  107. }