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.

C_MenuListener.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 commands.CommandAdd;
  8. import commands.CommandDelete;
  9. import commands.CommandInvoker;
  10. import commands.CommandOpen;
  11. import commands.CommandSave;
  12. import java.awt.Component;
  13. import java.awt.event.ActionEvent;
  14. import java.awt.event.ActionListener;
  15. import java.util.prefs.Preferences;
  16. import model.model;
  17. import view.gui;
  18. /**
  19. * Command Controller execute
  20. * @author matthias
  21. */
  22. public class C_MenuListener implements ActionListener{
  23. private gui view;
  24. private CommandInvoker invoker;
  25. private String PathID;
  26. private String FildID;
  27. private Preferences prfs;
  28. private model mdl;
  29. public C_MenuListener(gui g, String pid, String fid, Preferences p, model m, CommandInvoker inv)
  30. {
  31. this.view = g;
  32. this.invoker = inv;
  33. this.PathID = pid;
  34. this.FildID = fid;
  35. this.prfs = p;
  36. this.mdl = m;
  37. this.view.getContentTable1().getjTable().setModel(this.mdl);
  38. }
  39. /**
  40. * regestriert alle Events mit dem Command Controller als Listener
  41. */
  42. public void registerEvents()
  43. {
  44. this.view.getBtnSave().addActionListener(this);
  45. this.view.getMiSave().addActionListener(this);
  46. this.view.getMiSave_popup().addActionListener(this);
  47. this.view.getBtnOpen().addActionListener(this);
  48. this.view.getMiOpen().addActionListener(this);
  49. this.view.getMiOpen_popup().addActionListener(this);
  50. this.view.getContentTable1().getBtnAdd().addActionListener(this);
  51. this.view.getContentTable1().getBtnDel().addActionListener(this);
  52. this.view.getContentTable1().getCtmiAdd_popup().addActionListener(this);
  53. this.view.getContentTable1().getCtmiDelRow_popup().addActionListener(this);
  54. }
  55. /**
  56. * fügt alle Commands mit zugehörigem Event dem Invoker zu
  57. */
  58. public void registerCommands()
  59. {
  60. this.invoker.addCommand(this.view.getBtnSave(), new CommandSave(this.view, this.prfs, this.mdl, this.PathID));
  61. this.invoker.addCommand(this.view.getMiSave(), new CommandSave(this.view,this.prfs, this.mdl, this.PathID));
  62. this.invoker.addCommand(this.view.getMiSave_popup(), new CommandSave(this.view, this.prfs, this.mdl, this.PathID));
  63. this.invoker.addCommand(this.view.getBtnOpen(), new CommandOpen(this.view, this.prfs,this.PathID, this.FildID, this.mdl));
  64. this.invoker.addCommand(this.view.getMiOpen(), new CommandOpen(this.view, this.prfs,this.PathID, this.FildID, this.mdl));
  65. this.invoker.addCommand(this.view.getMiOpen_popup(), new CommandOpen(this.view, this.prfs,this.PathID, this.FildID, this.mdl));
  66. this.invoker.addCommand(this.view.getContentTable1().getBtnAdd(), new CommandAdd(this.view, this.prfs, this.mdl, this.PathID));
  67. this.invoker.addCommand(this.view.getContentTable1().getCtmiAdd_popup(), new CommandAdd(this.view, this.prfs, this.mdl, this.PathID));
  68. this.invoker.addCommand(this.view.getContentTable1().getCtmiDelRow_popup(), new CommandDelete(this.view, this.prfs, this.mdl, this.PathID));
  69. this.invoker.addCommand(this.view.getContentTable1().getBtnDel(), new CommandDelete(this.view, this.prfs, this.mdl, this.PathID));
  70. }
  71. /**
  72. * ausführen vom executeCommand aus dem Invoker
  73. * @param ae (AktionEvent)
  74. */
  75. @Override
  76. public void actionPerformed(ActionEvent ae) {
  77. Component key = (Component) ae.getSource();
  78. this.invoker.executeCommand(key);
  79. }
  80. }