Controller.java 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package de.tu_darmstadt.tk.SmartHomeNetworkSim.control;
  2. import java.util.Observer;
  3. import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Model;
  4. /**
  5. * Controller which allows interaction with the Model and Simulation
  6. *
  7. * @author Andreas T. Meyer-Berg
  8. */
  9. public class Controller {
  10. /**
  11. * {@link Model} which stores the smart home model
  12. */
  13. private Model model;
  14. /**
  15. * Controller for Import of user defined java classes
  16. */
  17. private ImportController importController;
  18. /**
  19. * Controller which allows configuration of the program e.g. settings
  20. */
  21. private SettingsController settingsController;
  22. /**
  23. * NetworkController for manipulation of the network model
  24. */
  25. private NetworkController networkController;
  26. /**
  27. * SimulationController which controls the simulation
  28. */
  29. private SimulationController simulationController;
  30. /**
  31. * Create a new Controller, which controls the given model and allows
  32. * manipulation of this model
  33. *
  34. * @param model
  35. * model, that should be controlled
  36. */
  37. public Controller(Model model) {
  38. this.model = model;
  39. settingsController = new SettingsController(this.model, this);
  40. importController = new ImportController(this.model, this);
  41. simulationController = new SimulationController(this.model, this);
  42. networkController = new NetworkController(this.model, this);
  43. }
  44. /**
  45. * Returns the main model of the simulation, use with precaution. Calls via the controller are preferred
  46. * @return Main Model for full access to the model
  47. * @deprecated use the corresponding controller
  48. */
  49. public Model getModel(){
  50. return model;
  51. }
  52. /**
  53. * Returns the ImportController, which manages the user imported classes,
  54. * which can be used in the framework
  55. * @return {@link ImportController}
  56. */
  57. public ImportController getImportController(){
  58. return importController;
  59. }
  60. /**
  61. * Returns the controller responsible for configuration of the program, e.g. changing the settings
  62. * @return {@link SettingsController}
  63. */
  64. public SettingsController getSettingsController(){
  65. return settingsController;
  66. }
  67. /**
  68. * Return the controller, which manages the network Model
  69. * @return {@link NetworkController}
  70. */
  71. public NetworkController getNetworkController(){
  72. return networkController;
  73. }
  74. /**
  75. * Return the simulation controller, to manage the simulation
  76. * @return {@link SimulationController}
  77. */
  78. public SimulationController getSimulationController(){
  79. return simulationController;
  80. }
  81. /**
  82. * Notifies Observer, which may update their visualization/state
  83. */
  84. public void notifyObservers(){
  85. model.setChanged();
  86. model.notifyObservers();
  87. }
  88. /**
  89. * Adds Observer to the model, which will be notified, when the model changes
  90. *
  91. * @param observer observer to be to notified on changes
  92. */
  93. public void addObserver(Observer observer){
  94. model.addObserver(observer);
  95. }
  96. /**
  97. * Removes Observer from the model. The Observer will no longer be notified on changes
  98. *
  99. * @param observer observer to be removed
  100. */
  101. public void removeObserver(Observer observer){
  102. model.deleteObserver(observer);
  103. }
  104. }