target.js 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818
  1. /* Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
  2. Date: Mon Aug 08 16:30:17 2016
  3. Model author: Joeri Exelmans+Raphael Mannadiar+Simon Van Mierlo
  4. Model name: Bouncing_Balls_JavaScript_Version
  5. Model description:
  6. SVG canvas with bouncing balls in it.*/
  7. // package "Bouncing_Balls_JavaScript_Version"
  8. var Bouncing_Balls_JavaScript_Version = {};
  9. (function() {
  10. var MainApp = function(controller) {
  11. RuntimeClassBase.call(this, controller);
  12. this.semantics.big_step_maximality = StatechartSemantics.TakeMany;
  13. this.semantics.internal_event_lifeline = StatechartSemantics.Queue;
  14. this.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep;
  15. this.semantics.priority = StatechartSemantics.SourceParent;
  16. this.semantics.concurrency = StatechartSemantics.Single;
  17. // build Statechart structure
  18. this.build_statechart_structure();
  19. // call user defined constructor
  20. MainApp.prototype.user_defined_constructor.call(this);
  21. };
  22. MainApp.prototype = new Object();
  23. (function() {
  24. var proto = new RuntimeClassBase();
  25. for (prop in proto) {
  26. MainApp.prototype[prop] = proto[prop];
  27. }
  28. })();
  29. MainApp.prototype.user_defined_constructor = function() {
  30. this.nr_of_fields = 0;
  31. };
  32. MainApp.prototype.user_defined_destructor = function() {
  33. };
  34. // builds Statechart structure
  35. MainApp.prototype.build_statechart_structure = function() {
  36. // state <root>
  37. this.states[""] = new State(0, this);
  38. // state /running
  39. this.states["/running"] = new State(1, this);
  40. // state /running/root
  41. this.states["/running/root"] = new ParallelState(2, this);
  42. // state /running/root/main_behaviour
  43. this.states["/running/root/main_behaviour"] = new State(3, this);
  44. // state /running/root/main_behaviour/initializing
  45. this.states["/running/root/main_behaviour/initializing"] = new State(4, this);
  46. // state /running/root/main_behaviour/running
  47. this.states["/running/root/main_behaviour/running"] = new State(5, this);
  48. // state /running/root/cd_behaviour
  49. this.states["/running/root/cd_behaviour"] = new State(6, this);
  50. // state /running/root/cd_behaviour/waiting
  51. this.states["/running/root/cd_behaviour/waiting"] = new State(7, this);
  52. // state /running/root/cd_behaviour/creating
  53. this.states["/running/root/cd_behaviour/creating"] = new State(8, this);
  54. // state /running/root/cd_behaviour/check_nr_of_fields
  55. this.states["/running/root/cd_behaviour/check_nr_of_fields"] = new State(9, this);
  56. // state /running/stopped
  57. this.states["/running/stopped"] = new State(10, this);
  58. // add children
  59. this.states[""].addChild(this.states["/running"]);
  60. this.states["/running"].addChild(this.states["/running/root"]);
  61. this.states["/running"].addChild(this.states["/running/stopped"]);
  62. this.states["/running/root"].addChild(this.states["/running/root/main_behaviour"]);
  63. this.states["/running/root"].addChild(this.states["/running/root/cd_behaviour"]);
  64. this.states["/running/root/main_behaviour"].addChild(this.states["/running/root/main_behaviour/initializing"]);
  65. this.states["/running/root/main_behaviour"].addChild(this.states["/running/root/main_behaviour/running"]);
  66. this.states["/running/root/cd_behaviour"].addChild(this.states["/running/root/cd_behaviour/waiting"]);
  67. this.states["/running/root/cd_behaviour"].addChild(this.states["/running/root/cd_behaviour/creating"]);
  68. this.states["/running/root/cd_behaviour"].addChild(this.states["/running/root/cd_behaviour/check_nr_of_fields"]);
  69. this.states[""].fixTree();
  70. this.states[""].default_state = this.states["/running"];
  71. this.states["/running"].default_state = this.states["/running/root"];
  72. this.states["/running/root/main_behaviour"].default_state = this.states["/running/root/main_behaviour/initializing"];
  73. this.states["/running/root/cd_behaviour"].default_state = this.states["/running/root/cd_behaviour/waiting"];
  74. // transition /running/root/main_behaviour/initializing
  75. var _running_root_main_behaviour_initializing_0 = new Transition(this, this.states["/running/root/main_behaviour/initializing"], [this.states["/running/root/main_behaviour/running"]]);
  76. _running_root_main_behaviour_initializing_0.setAction(this._running_root_main_behaviour_initializing_0_exec);
  77. _running_root_main_behaviour_initializing_0.setTrigger(null);
  78. this.states["/running/root/main_behaviour/initializing"].addTransition(_running_root_main_behaviour_initializing_0);
  79. // transition /running/root/main_behaviour/running
  80. var _running_root_main_behaviour_running_0 = new Transition(this, this.states["/running/root/main_behaviour/running"], [this.states["/running/root/main_behaviour/running"]]);
  81. _running_root_main_behaviour_running_0.setAction(this._running_root_main_behaviour_running_0_exec);
  82. _running_root_main_behaviour_running_0.setTrigger(new Event("button_pressed", null));
  83. _running_root_main_behaviour_running_0.setGuard(this._running_root_main_behaviour_running_0_guard);
  84. this.states["/running/root/main_behaviour/running"].addTransition(_running_root_main_behaviour_running_0);
  85. // transition /running/root/cd_behaviour/waiting
  86. var _running_root_cd_behaviour_waiting_0 = new Transition(this, this.states["/running/root/cd_behaviour/waiting"], [this.states["/running/root/cd_behaviour/creating"]]);
  87. _running_root_cd_behaviour_waiting_0.setAction(this._running_root_cd_behaviour_waiting_0_exec);
  88. _running_root_cd_behaviour_waiting_0.setTrigger(new Event("create_field", null));
  89. this.states["/running/root/cd_behaviour/waiting"].addTransition(_running_root_cd_behaviour_waiting_0);
  90. var _running_root_cd_behaviour_waiting_1 = new Transition(this, this.states["/running/root/cd_behaviour/waiting"], [this.states["/running/root/cd_behaviour/check_nr_of_fields"]]);
  91. _running_root_cd_behaviour_waiting_1.setAction(this._running_root_cd_behaviour_waiting_1_exec);
  92. _running_root_cd_behaviour_waiting_1.setTrigger(new Event("delete_field", null));
  93. this.states["/running/root/cd_behaviour/waiting"].addTransition(_running_root_cd_behaviour_waiting_1);
  94. // transition /running/root/cd_behaviour/creating
  95. var _running_root_cd_behaviour_creating_0 = new Transition(this, this.states["/running/root/cd_behaviour/creating"], [this.states["/running/root/cd_behaviour/waiting"]]);
  96. _running_root_cd_behaviour_creating_0.setAction(this._running_root_cd_behaviour_creating_0_exec);
  97. _running_root_cd_behaviour_creating_0.setTrigger(new Event("instance_created", null));
  98. this.states["/running/root/cd_behaviour/creating"].addTransition(_running_root_cd_behaviour_creating_0);
  99. // transition /running/root/cd_behaviour/check_nr_of_fields
  100. var _running_root_cd_behaviour_check_nr_of_fields_0 = new Transition(this, this.states["/running/root/cd_behaviour/check_nr_of_fields"], [this.states["/running/stopped"]]);
  101. _running_root_cd_behaviour_check_nr_of_fields_0.setAction(this._running_root_cd_behaviour_check_nr_of_fields_0_exec);
  102. _running_root_cd_behaviour_check_nr_of_fields_0.setTrigger(null);
  103. _running_root_cd_behaviour_check_nr_of_fields_0.setGuard(this._running_root_cd_behaviour_check_nr_of_fields_0_guard);
  104. this.states["/running/root/cd_behaviour/check_nr_of_fields"].addTransition(_running_root_cd_behaviour_check_nr_of_fields_0);
  105. var _running_root_cd_behaviour_check_nr_of_fields_1 = new Transition(this, this.states["/running/root/cd_behaviour/check_nr_of_fields"], [this.states["/running/root/cd_behaviour/waiting"]]);
  106. _running_root_cd_behaviour_check_nr_of_fields_1.setTrigger(null);
  107. _running_root_cd_behaviour_check_nr_of_fields_1.setGuard(this._running_root_cd_behaviour_check_nr_of_fields_1_guard);
  108. this.states["/running/root/cd_behaviour/check_nr_of_fields"].addTransition(_running_root_cd_behaviour_check_nr_of_fields_1);
  109. };
  110. MainApp.prototype._running_root_main_behaviour_initializing_0_exec = function(parameters) {
  111. this.raiseInternalEvent(new Event("create_field", null, new Array()));
  112. };
  113. MainApp.prototype._running_root_main_behaviour_running_0_exec = function(parameters) {
  114. var event_name = parameters[0];
  115. this.raiseInternalEvent(new Event("create_field", null, new Array()));
  116. };
  117. MainApp.prototype._running_root_main_behaviour_running_0_guard = function(parameters) {
  118. var event_name = parameters[0];
  119. return event_name == "create_new_field";
  120. };
  121. MainApp.prototype._running_root_cd_behaviour_waiting_0_exec = function(parameters) {
  122. this.big_step.outputEventOM(new Event("create_instance", null, [this, "fields"]));
  123. };
  124. MainApp.prototype._running_root_cd_behaviour_waiting_1_exec = function(parameters) {
  125. var association_name = parameters[0];
  126. this.big_step.outputEventOM(new Event("delete_instance", null, [this, association_name]));
  127. this.nr_of_fields -= 1
  128. };
  129. MainApp.prototype._running_root_cd_behaviour_creating_0_exec = function(parameters) {
  130. var association_name = parameters[0];
  131. this.big_step.outputEventOM(new Event("start_instance", null, [this, association_name]));
  132. this.big_step.outputEventOM(new Event("narrow_cast", null, [this, association_name, new Event("set_association_name", null, [association_name])]));
  133. this.nr_of_fields += 1
  134. };
  135. MainApp.prototype._running_root_cd_behaviour_check_nr_of_fields_0_exec = function(parameters) {
  136. //NOTE: ideally, this should be ui.close_window(ui.window). we can't do this though
  137. // due to a security measure preventing scripts from closing pages they didn't
  138. // open themselves
  139. ui.println('refresh to play again');
  140. };
  141. MainApp.prototype._running_root_cd_behaviour_check_nr_of_fields_0_guard = function(parameters) {
  142. return this.nr_of_fields == 0;
  143. };
  144. MainApp.prototype._running_root_cd_behaviour_check_nr_of_fields_1_guard = function(parameters) {
  145. return this.nr_of_fields != 0;
  146. };
  147. MainApp.prototype.initializeStatechart = function() {
  148. // enter default state
  149. this.default_targets = this.states["/running"].getEffectiveTargetStates();
  150. RuntimeClassBase.prototype.initializeStatechart.call(this);
  151. };
  152. // add symbol 'MainApp' to package 'Bouncing_Balls_JavaScript_Version'
  153. Bouncing_Balls_JavaScript_Version.MainApp = MainApp;
  154. var Field = function(controller) {
  155. RuntimeClassBase.call(this, controller);
  156. this.semantics.big_step_maximality = StatechartSemantics.TakeMany;
  157. this.semantics.internal_event_lifeline = StatechartSemantics.Queue;
  158. this.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep;
  159. this.semantics.priority = StatechartSemantics.SourceParent;
  160. this.semantics.concurrency = StatechartSemantics.Single;
  161. // build Statechart structure
  162. this.build_statechart_structure();
  163. this.inports["field_ui"] = controller.addInputPort("field_ui", this);
  164. // user defined attributes
  165. this.canvas = null;
  166. this.field_window = null;
  167. // call user defined constructor
  168. Field.prototype.user_defined_constructor.call(this);
  169. };
  170. Field.prototype = new Object();
  171. (function() {
  172. var proto = new RuntimeClassBase();
  173. for (prop in proto) {
  174. Field.prototype[prop] = proto[prop];
  175. }
  176. })();
  177. Field.prototype.user_defined_constructor = function() {
  178. this.field_window = ui.new_window(400,450);
  179. this.canvas = ui.append_canvas(this.field_window,400,400,{'background':'#eee'});
  180. ui.bind_event(this.field_window, ui.EVENTS.WINDOW_CLOSE, this.controller, 'window_close', this.inports['field_ui']);
  181. ui.bind_event(this.field_window, ui.EVENTS.KEY_PRESS, this.controller, 'key_press', this.inports['field_ui']);
  182. ui.bind_event(this.canvas.element, ui.EVENTS.MOUSE_RIGHT_CLICK, this.controller, 'right_click', this.inports['field_ui']);
  183. ui.bind_event(this.canvas.element, ui.EVENTS.MOUSE_MOVE, this.controller, 'mouse_move');
  184. ui.bind_event(this.canvas.element, ui.EVENTS.MOUSE_RELEASE, this.controller, 'mouse_release');
  185. };
  186. Field.prototype.user_defined_destructor = function() {
  187. ui.close_window(this.field_window);
  188. };
  189. // builds Statechart structure
  190. Field.prototype.build_statechart_structure = function() {
  191. // state <root>
  192. this.states[""] = new State(0, this);
  193. // state /root
  194. this.states["/root"] = new State(1, this);
  195. // state /root/waiting
  196. this.states["/root/waiting"] = new State(2, this);
  197. // state /root/initializing
  198. this.states["/root/initializing"] = new State(3, this);
  199. // state /root/creating
  200. this.states["/root/creating"] = new State(4, this);
  201. // state /root/packing
  202. this.states["/root/packing"] = new State(5, this);
  203. // state /root/running
  204. this.states["/root/running"] = new ParallelState(6, this);
  205. // state /root/running/main_behaviour
  206. this.states["/root/running/main_behaviour"] = new State(7, this);
  207. // state /root/running/main_behaviour/running
  208. this.states["/root/running/main_behaviour/running"] = new State(8, this);
  209. // state /root/running/main_behaviour/creating
  210. this.states["/root/running/main_behaviour/creating"] = new State(9, this);
  211. // state /root/running/deleting_behaviour
  212. this.states["/root/running/deleting_behaviour"] = new State(10, this);
  213. // state /root/running/deleting_behaviour/running
  214. this.states["/root/running/deleting_behaviour/running"] = new State(11, this);
  215. // state /root/running/child_behaviour
  216. this.states["/root/running/child_behaviour"] = new State(12, this);
  217. // state /root/running/child_behaviour/listening
  218. this.states["/root/running/child_behaviour/listening"] = new State(13, this);
  219. // state /root/running/deleting_balls_behaviour
  220. this.states["/root/running/deleting_balls_behaviour"] = new State(14, this);
  221. // state /root/running/deleting_balls_behaviour/listening
  222. this.states["/root/running/deleting_balls_behaviour/listening"] = new State(15, this);
  223. // state /root/deleting
  224. this.states["/root/deleting"] = new State(16, this);
  225. // state /root/deleted
  226. this.states["/root/deleted"] = new State(17, this);
  227. // add children
  228. this.states[""].addChild(this.states["/root"]);
  229. this.states["/root"].addChild(this.states["/root/waiting"]);
  230. this.states["/root"].addChild(this.states["/root/initializing"]);
  231. this.states["/root"].addChild(this.states["/root/creating"]);
  232. this.states["/root"].addChild(this.states["/root/packing"]);
  233. this.states["/root"].addChild(this.states["/root/running"]);
  234. this.states["/root"].addChild(this.states["/root/deleting"]);
  235. this.states["/root"].addChild(this.states["/root/deleted"]);
  236. this.states["/root/running"].addChild(this.states["/root/running/main_behaviour"]);
  237. this.states["/root/running"].addChild(this.states["/root/running/deleting_behaviour"]);
  238. this.states["/root/running"].addChild(this.states["/root/running/child_behaviour"]);
  239. this.states["/root/running"].addChild(this.states["/root/running/deleting_balls_behaviour"]);
  240. this.states["/root/running/main_behaviour"].addChild(this.states["/root/running/main_behaviour/running"]);
  241. this.states["/root/running/main_behaviour"].addChild(this.states["/root/running/main_behaviour/creating"]);
  242. this.states["/root/running/deleting_behaviour"].addChild(this.states["/root/running/deleting_behaviour/running"]);
  243. this.states["/root/running/child_behaviour"].addChild(this.states["/root/running/child_behaviour/listening"]);
  244. this.states["/root/running/deleting_balls_behaviour"].addChild(this.states["/root/running/deleting_balls_behaviour/listening"]);
  245. this.states[""].fixTree();
  246. this.states[""].default_state = this.states["/root"];
  247. this.states["/root"].default_state = this.states["/root/waiting"];
  248. this.states["/root/running/main_behaviour"].default_state = this.states["/root/running/main_behaviour/running"];
  249. this.states["/root/running/deleting_behaviour"].default_state = this.states["/root/running/deleting_behaviour/running"];
  250. this.states["/root/running/child_behaviour"].default_state = this.states["/root/running/child_behaviour/listening"];
  251. this.states["/root/running/deleting_balls_behaviour"].default_state = this.states["/root/running/deleting_balls_behaviour/listening"];
  252. // transition /root/waiting
  253. var _root_waiting_0 = new Transition(this, this.states["/root/waiting"], [this.states["/root/initializing"]]);
  254. _root_waiting_0.setAction(this._root_waiting_0_exec);
  255. _root_waiting_0.setTrigger(new Event("set_association_name", null));
  256. this.states["/root/waiting"].addTransition(_root_waiting_0);
  257. // transition /root/initializing
  258. var _root_initializing_0 = new Transition(this, this.states["/root/initializing"], [this.states["/root/creating"]]);
  259. _root_initializing_0.setAction(this._root_initializing_0_exec);
  260. _root_initializing_0.setTrigger(null);
  261. this.states["/root/initializing"].addTransition(_root_initializing_0);
  262. // transition /root/creating
  263. var _root_creating_0 = new Transition(this, this.states["/root/creating"], [this.states["/root/packing"]]);
  264. _root_creating_0.setAction(this._root_creating_0_exec);
  265. _root_creating_0.setTrigger(new Event("instance_created", null));
  266. this.states["/root/creating"].addTransition(_root_creating_0);
  267. // transition /root/packing
  268. var _root_packing_0 = new Transition(this, this.states["/root/packing"], [this.states["/root/running"]]);
  269. _root_packing_0.setTrigger(new Event("button_created", null));
  270. this.states["/root/packing"].addTransition(_root_packing_0);
  271. // transition /root/running/main_behaviour/running
  272. var _root_running_main_behaviour_running_0 = new Transition(this, this.states["/root/running/main_behaviour/running"], [this.states["/root/running/main_behaviour/creating"]]);
  273. _root_running_main_behaviour_running_0.setAction(this._root_running_main_behaviour_running_0_exec);
  274. _root_running_main_behaviour_running_0.setTrigger(new Event("right_click", "field_ui"));
  275. this.states["/root/running/main_behaviour/running"].addTransition(_root_running_main_behaviour_running_0);
  276. // transition /root/running/main_behaviour/creating
  277. var _root_running_main_behaviour_creating_0 = new Transition(this, this.states["/root/running/main_behaviour/creating"], [this.states["/root/running/main_behaviour/running"]]);
  278. _root_running_main_behaviour_creating_0.setAction(this._root_running_main_behaviour_creating_0_exec);
  279. _root_running_main_behaviour_creating_0.setTrigger(new Event("instance_created", null));
  280. this.states["/root/running/main_behaviour/creating"].addTransition(_root_running_main_behaviour_creating_0);
  281. // transition /root/running/deleting_behaviour/running
  282. var _root_running_deleting_behaviour_running_0 = new Transition(this, this.states["/root/running/deleting_behaviour/running"], [this.states["/root/running/deleting_behaviour/running"]]);
  283. _root_running_deleting_behaviour_running_0.setAction(this._root_running_deleting_behaviour_running_0_exec);
  284. _root_running_deleting_behaviour_running_0.setTrigger(new Event("delete_ball", null));
  285. this.states["/root/running/deleting_behaviour/running"].addTransition(_root_running_deleting_behaviour_running_0);
  286. // transition /root/running/child_behaviour/listening
  287. var _root_running_child_behaviour_listening_0 = new Transition(this, this.states["/root/running/child_behaviour/listening"], [this.states["/root/running/child_behaviour/listening"]]);
  288. _root_running_child_behaviour_listening_0.setAction(this._root_running_child_behaviour_listening_0_exec);
  289. _root_running_child_behaviour_listening_0.setTrigger(new Event("button_pressed", null));
  290. this.states["/root/running/child_behaviour/listening"].addTransition(_root_running_child_behaviour_listening_0);
  291. // transition /root/running/deleting_balls_behaviour/listening
  292. var _root_running_deleting_balls_behaviour_listening_0 = new Transition(this, this.states["/root/running/deleting_balls_behaviour/listening"], [this.states["/root/running/deleting_balls_behaviour/listening"]]);
  293. _root_running_deleting_balls_behaviour_listening_0.setAction(this._root_running_deleting_balls_behaviour_listening_0_exec);
  294. _root_running_deleting_balls_behaviour_listening_0.setTrigger(new Event("key_press", "field_ui"));
  295. _root_running_deleting_balls_behaviour_listening_0.setGuard(this._root_running_deleting_balls_behaviour_listening_0_guard);
  296. this.states["/root/running/deleting_balls_behaviour/listening"].addTransition(_root_running_deleting_balls_behaviour_listening_0);
  297. // transition /root/deleting
  298. var _root_deleting_0 = new Transition(this, this.states["/root/deleting"], [this.states["/root/deleted"]]);
  299. _root_deleting_0.setAction(this._root_deleting_0_exec);
  300. _root_deleting_0.setTrigger(null);
  301. this.states["/root/deleting"].addTransition(_root_deleting_0);
  302. // transition /root/running
  303. var _root_running_0 = new Transition(this, this.states["/root/running"], [this.states["/root/deleting"]]);
  304. _root_running_0.setAction(this._root_running_0_exec);
  305. _root_running_0.setTrigger(new Event("window_close", "field_ui"));
  306. this.states["/root/running"].addTransition(_root_running_0);
  307. };
  308. Field.prototype._root_running_0_exec = function(parameters) {
  309. this.big_step.outputEventOM(new Event("delete_instance", null, [this, "buttons"]));
  310. this.big_step.outputEventOM(new Event("delete_instance", null, [this, "balls"]));
  311. };
  312. Field.prototype._root_waiting_0_exec = function(parameters) {
  313. var association_name = parameters[0];
  314. this.association_name = association_name
  315. };
  316. Field.prototype._root_initializing_0_exec = function(parameters) {
  317. this.big_step.outputEventOM(new Event("create_instance", null, [this, "buttons", "Button", this, 'create_new_field', 'Spawn New Window']));
  318. };
  319. Field.prototype._root_creating_0_exec = function(parameters) {
  320. var association_name = parameters[0];
  321. this.big_step.outputEventOM(new Event("start_instance", null, [this, association_name]));
  322. };
  323. Field.prototype._root_running_main_behaviour_running_0_exec = function(parameters) {
  324. var x = parameters[0];
  325. var y = parameters[1];
  326. var button = parameters[2];
  327. this.big_step.outputEventOM(new Event("create_instance", null, [this, "balls", "Ball", this.canvas, x, y]));
  328. };
  329. Field.prototype._root_running_main_behaviour_creating_0_exec = function(parameters) {
  330. var association_name = parameters[0];
  331. this.big_step.outputEventOM(new Event("start_instance", null, [this, association_name]));
  332. this.big_step.outputEventOM(new Event("narrow_cast", null, [this, association_name, new Event("set_association_name", null, [association_name])]));
  333. };
  334. Field.prototype._root_running_deleting_behaviour_running_0_exec = function(parameters) {
  335. var association_name = parameters[0];
  336. this.big_step.outputEventOM(new Event("delete_instance", null, [this, association_name]));
  337. };
  338. Field.prototype._root_running_child_behaviour_listening_0_exec = function(parameters) {
  339. var event_name = parameters[0];
  340. this.big_step.outputEventOM(new Event("narrow_cast", null, [this, 'parent', new Event("button_pressed", null, [event_name])]));
  341. };
  342. Field.prototype._root_running_deleting_balls_behaviour_listening_0_exec = function(parameters) {
  343. var key = parameters[0];
  344. this.big_step.outputEventOM(new Event("narrow_cast", null, [this, 'balls', new Event("delete_self", null, new Array())]));
  345. };
  346. Field.prototype._root_running_deleting_balls_behaviour_listening_0_guard = function(parameters) {
  347. var key = parameters[0];
  348. return key == ui.KEYCODES.DELETE;
  349. };
  350. Field.prototype._root_deleting_0_exec = function(parameters) {
  351. this.big_step.outputEventOM(new Event("narrow_cast", null, [this, 'parent', new Event("delete_field", null, [this.association_name])]));
  352. };
  353. Field.prototype.initializeStatechart = function() {
  354. // enter default state
  355. this.default_targets = this.states["/root"].getEffectiveTargetStates();
  356. RuntimeClassBase.prototype.initializeStatechart.call(this);
  357. };
  358. // add symbol 'Field' to package 'Bouncing_Balls_JavaScript_Version'
  359. Bouncing_Balls_JavaScript_Version.Field = Field;
  360. var Button = function(controller, parent, event_name, button_text) {
  361. RuntimeClassBase.call(this, controller);
  362. this.semantics.big_step_maximality = StatechartSemantics.TakeMany;
  363. this.semantics.internal_event_lifeline = StatechartSemantics.Queue;
  364. this.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep;
  365. this.semantics.priority = StatechartSemantics.SourceParent;
  366. this.semantics.concurrency = StatechartSemantics.Single;
  367. // build Statechart structure
  368. this.build_statechart_structure();
  369. this.inports["button_ui"] = controller.addInputPort("button_ui", this);
  370. // call user defined constructor
  371. Button.prototype.user_defined_constructor.call(this, parent, event_name, button_text);
  372. };
  373. Button.prototype = new Object();
  374. (function() {
  375. var proto = new RuntimeClassBase();
  376. for (prop in proto) {
  377. Button.prototype[prop] = proto[prop];
  378. }
  379. })();
  380. Button.prototype.user_defined_constructor = function(parent, event_name, button_text) {
  381. this.event_name = event_name;
  382. var button = ui.append_button(parent.field_window, event_name);
  383. ui.bind_event(button.element, ui.EVENTS.MOUSE_CLICK, this.controller, 'mouse_click', this.inports["button_ui"]);
  384. };
  385. Button.prototype.user_defined_destructor = function() {
  386. };
  387. // builds Statechart structure
  388. Button.prototype.build_statechart_structure = function() {
  389. // state <root>
  390. this.states[""] = new State(0, this);
  391. // state /initializing
  392. this.states["/initializing"] = new State(1, this);
  393. // state /running
  394. this.states["/running"] = new State(2, this);
  395. // add children
  396. this.states[""].addChild(this.states["/initializing"]);
  397. this.states[""].addChild(this.states["/running"]);
  398. this.states[""].fixTree();
  399. this.states[""].default_state = this.states["/initializing"];
  400. // transition /initializing
  401. var _initializing_0 = new Transition(this, this.states["/initializing"], [this.states["/running"]]);
  402. _initializing_0.setAction(this._initializing_0_exec);
  403. _initializing_0.setTrigger(null);
  404. this.states["/initializing"].addTransition(_initializing_0);
  405. // transition /running
  406. var _running_0 = new Transition(this, this.states["/running"], [this.states["/running"]]);
  407. _running_0.setAction(this._running_0_exec);
  408. _running_0.setTrigger(new Event("mouse_click", "button_ui"));
  409. _running_0.setGuard(this._running_0_guard);
  410. this.states["/running"].addTransition(_running_0);
  411. };
  412. Button.prototype._initializing_0_exec = function(parameters) {
  413. this.big_step.outputEventOM(new Event("narrow_cast", null, [this, 'parent', new Event("button_created", null, new Array())]));
  414. };
  415. Button.prototype._running_0_exec = function(parameters) {
  416. var x = parameters[0];
  417. var y = parameters[1];
  418. var button = parameters[2];
  419. this.big_step.outputEventOM(new Event("narrow_cast", null, [this, 'parent', new Event("button_pressed", null, [this.event_name])]));
  420. };
  421. Button.prototype._running_0_guard = function(parameters) {
  422. var x = parameters[0];
  423. var y = parameters[1];
  424. var button = parameters[2];
  425. return button == ui.MOUSE_BUTTONS.LEFT;
  426. };
  427. Button.prototype.initializeStatechart = function() {
  428. // enter default state
  429. this.default_targets = this.states["/initializing"].getEffectiveTargetStates();
  430. RuntimeClassBase.prototype.initializeStatechart.call(this);
  431. };
  432. // add symbol 'Button' to package 'Bouncing_Balls_JavaScript_Version'
  433. Bouncing_Balls_JavaScript_Version.Button = Button;
  434. var Ball = function(controller, canvas, x, y) {
  435. RuntimeClassBase.call(this, controller);
  436. this.semantics.big_step_maximality = StatechartSemantics.TakeMany;
  437. this.semantics.internal_event_lifeline = StatechartSemantics.Queue;
  438. this.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep;
  439. this.semantics.priority = StatechartSemantics.SourceParent;
  440. this.semantics.concurrency = StatechartSemantics.Single;
  441. // build Statechart structure
  442. this.build_statechart_structure();
  443. this.inports["ball_ui"] = controller.addInputPort("ball_ui", this);
  444. // user defined attributes
  445. this.canvas = null;
  446. // call user defined constructor
  447. Ball.prototype.user_defined_constructor.call(this, canvas, x, y);
  448. };
  449. Ball.prototype = new Object();
  450. (function() {
  451. var proto = new RuntimeClassBase();
  452. for (prop in proto) {
  453. Ball.prototype[prop] = proto[prop];
  454. }
  455. })();
  456. Ball.prototype.user_defined_constructor = function(canvas, x, y) {
  457. this.canvas = canvas;
  458. this.r = 20.0;
  459. this.vel = {'x': utils.random() * 3.0, 'y': utils.random() * 3.0};
  460. this.mouse_pos = {};
  461. this.smooth = 0.4; // value between 0 and 1
  462. var circle = this.canvas.add_circle(x, y, this.r, {'fill':'#000'});
  463. ui.bind_event(circle, ui.EVENTS.MOUSE_PRESS, this.controller, 'mouse_press', this.inports["ball_ui"]);
  464. this.element = circle;
  465. };
  466. Ball.prototype.user_defined_destructor = function() {
  467. this.canvas.remove_element(this.element);
  468. };
  469. // builds Statechart structure
  470. Ball.prototype.build_statechart_structure = function() {
  471. // state <root>
  472. this.states[""] = new State(0, this);
  473. // state /main_behaviour
  474. this.states["/main_behaviour"] = new State(1, this);
  475. // state /main_behaviour/initializing
  476. this.states["/main_behaviour/initializing"] = new State(2, this);
  477. // state /main_behaviour/bouncing
  478. this.states["/main_behaviour/bouncing"] = new State(3, this);
  479. this.states["/main_behaviour/bouncing"].setEnter(this._main_behaviour_bouncing_enter);
  480. this.states["/main_behaviour/bouncing"].setExit(this._main_behaviour_bouncing_exit);
  481. // state /main_behaviour/dragging
  482. this.states["/main_behaviour/dragging"] = new State(4, this);
  483. // state /main_behaviour/selected
  484. this.states["/main_behaviour/selected"] = new State(5, this);
  485. // state /deleted
  486. this.states["/deleted"] = new State(6, this);
  487. // add children
  488. this.states[""].addChild(this.states["/main_behaviour"]);
  489. this.states[""].addChild(this.states["/deleted"]);
  490. this.states["/main_behaviour"].addChild(this.states["/main_behaviour/initializing"]);
  491. this.states["/main_behaviour"].addChild(this.states["/main_behaviour/bouncing"]);
  492. this.states["/main_behaviour"].addChild(this.states["/main_behaviour/dragging"]);
  493. this.states["/main_behaviour"].addChild(this.states["/main_behaviour/selected"]);
  494. this.states[""].fixTree();
  495. this.states[""].default_state = this.states["/main_behaviour"];
  496. this.states["/main_behaviour"].default_state = this.states["/main_behaviour/initializing"];
  497. // transition /main_behaviour/initializing
  498. var _main_behaviour_initializing_0 = new Transition(this, this.states["/main_behaviour/initializing"], [this.states["/main_behaviour/bouncing"]]);
  499. _main_behaviour_initializing_0.setAction(this._main_behaviour_initializing_0_exec);
  500. _main_behaviour_initializing_0.setTrigger(new Event("set_association_name", null));
  501. this.states["/main_behaviour/initializing"].addTransition(_main_behaviour_initializing_0);
  502. // transition /main_behaviour/bouncing
  503. var _main_behaviour_bouncing_0 = new Transition(this, this.states["/main_behaviour/bouncing"], [this.states["/main_behaviour/bouncing"]]);
  504. _main_behaviour_bouncing_0.setAction(this._main_behaviour_bouncing_0_exec);
  505. _main_behaviour_bouncing_0.setTrigger(new Event("_0after"));
  506. this.states["/main_behaviour/bouncing"].addTransition(_main_behaviour_bouncing_0);
  507. var _main_behaviour_bouncing_1 = new Transition(this, this.states["/main_behaviour/bouncing"], [this.states["/main_behaviour/selected"]]);
  508. _main_behaviour_bouncing_1.setAction(this._main_behaviour_bouncing_1_exec);
  509. _main_behaviour_bouncing_1.setTrigger(new Event("mouse_press", "ball_ui"));
  510. _main_behaviour_bouncing_1.setGuard(this._main_behaviour_bouncing_1_guard);
  511. this.states["/main_behaviour/bouncing"].addTransition(_main_behaviour_bouncing_1);
  512. // transition /main_behaviour/dragging
  513. var _main_behaviour_dragging_0 = new Transition(this, this.states["/main_behaviour/dragging"], [this.states["/main_behaviour/dragging"]]);
  514. _main_behaviour_dragging_0.setAction(this._main_behaviour_dragging_0_exec);
  515. _main_behaviour_dragging_0.setTrigger(new Event("mouse_move", "ui"));
  516. this.states["/main_behaviour/dragging"].addTransition(_main_behaviour_dragging_0);
  517. var _main_behaviour_dragging_1 = new Transition(this, this.states["/main_behaviour/dragging"], [this.states["/main_behaviour/bouncing"]]);
  518. _main_behaviour_dragging_1.setAction(this._main_behaviour_dragging_1_exec);
  519. _main_behaviour_dragging_1.setTrigger(new Event("mouse_release", "ui"));
  520. this.states["/main_behaviour/dragging"].addTransition(_main_behaviour_dragging_1);
  521. // transition /main_behaviour/selected
  522. var _main_behaviour_selected_0 = new Transition(this, this.states["/main_behaviour/selected"], [this.states["/main_behaviour/dragging"]]);
  523. _main_behaviour_selected_0.setAction(this._main_behaviour_selected_0_exec);
  524. _main_behaviour_selected_0.setTrigger(new Event("mouse_press", "ball_ui"));
  525. _main_behaviour_selected_0.setGuard(this._main_behaviour_selected_0_guard);
  526. this.states["/main_behaviour/selected"].addTransition(_main_behaviour_selected_0);
  527. var _main_behaviour_selected_1 = new Transition(this, this.states["/main_behaviour/selected"], [this.states["/deleted"]]);
  528. _main_behaviour_selected_1.setAction(this._main_behaviour_selected_1_exec);
  529. _main_behaviour_selected_1.setTrigger(new Event("delete_self", null));
  530. this.states["/main_behaviour/selected"].addTransition(_main_behaviour_selected_1);
  531. };
  532. Ball.prototype._main_behaviour_bouncing_enter = function() {
  533. this.addTimer(0, 0.05);
  534. };
  535. Ball.prototype._main_behaviour_bouncing_exit = function() {
  536. this.removeTimer(0);
  537. };
  538. Ball.prototype._main_behaviour_initializing_0_exec = function(parameters) {
  539. var association_name = parameters[0];
  540. this.association_name = association_name;
  541. };
  542. Ball.prototype._main_behaviour_bouncing_0_exec = function(parameters) {
  543. var pos = this.element.get_position();
  544. if (pos.x-this.r <= 0 || pos.x+this.r >= this.canvas.width)
  545. this.vel.x = -this.vel.x;
  546. if (pos.y-this.r <= 0 || pos.y+this.r >= this.canvas.height)
  547. this.vel.y = -this.vel.y;
  548. this.element.move(this.vel.x, this.vel.y);
  549. };
  550. Ball.prototype._main_behaviour_bouncing_1_exec = function(parameters) {
  551. var x = parameters[0];
  552. var y = parameters[1];
  553. var button = parameters[2];
  554. this.element.set_color("#ff0");
  555. };
  556. Ball.prototype._main_behaviour_bouncing_1_guard = function(parameters) {
  557. var x = parameters[0];
  558. var y = parameters[1];
  559. var button = parameters[2];
  560. return button == ui.MOUSE_BUTTONS.LEFT;
  561. };
  562. Ball.prototype._main_behaviour_dragging_0_exec = function(parameters) {
  563. var x = parameters[0];
  564. var y = parameters[1];
  565. var button = parameters[2];
  566. var dx = x - this.mouse_pos.x;
  567. var dy = y - this.mouse_pos.y;
  568. this.element.move(dx, dy);
  569. // keep ball within boundaries
  570. var pos = this.element.get_position();
  571. if (pos.x-this.r <= 0)
  572. pos.x = this.r + 1;
  573. else if (pos.x+this.r >= this.canvas.width)
  574. pos.x = this.canvas.width-this.r-1;
  575. if (pos.y-this.r <= 0)
  576. pos.y = this.r + 1;
  577. else if (pos.y+this.r >= this.canvas.height)
  578. pos.y = this.canvas.height-this.r-1;
  579. this.element.set_position(pos.x, pos.y);
  580. this.mouse_pos = {'x':x, 'y':y};
  581. this.vel = {
  582. 'x': (1-this.smooth)*dx + this.smooth*this.vel.x,
  583. 'y': (1-this.smooth)*dy + this.smooth*this.vel.y
  584. };
  585. };
  586. Ball.prototype._main_behaviour_dragging_1_exec = function(parameters) {
  587. var x = parameters[0];
  588. var y = parameters[1];
  589. this.element.set_color("#f00");
  590. };
  591. Ball.prototype._main_behaviour_selected_0_exec = function(parameters) {
  592. var x = parameters[0];
  593. var y = parameters[1];
  594. var button = parameters[2];
  595. this.mouse_pos = {'x':x, 'y':y};
  596. };
  597. Ball.prototype._main_behaviour_selected_0_guard = function(parameters) {
  598. var x = parameters[0];
  599. var y = parameters[1];
  600. var button = parameters[2];
  601. return button == ui.MOUSE_BUTTONS.LEFT;
  602. };
  603. Ball.prototype._main_behaviour_selected_1_exec = function(parameters) {
  604. this.big_step.outputEventOM(new Event("narrow_cast", null, [this, 'parent', new Event("delete_ball", null, [this.association_name])]));
  605. };
  606. Ball.prototype.initializeStatechart = function() {
  607. // enter default state
  608. this.default_targets = this.states["/main_behaviour"].getEffectiveTargetStates();
  609. RuntimeClassBase.prototype.initializeStatechart.call(this);
  610. };
  611. // add symbol 'Ball' to package 'Bouncing_Balls_JavaScript_Version'
  612. Bouncing_Balls_JavaScript_Version.Ball = Ball;
  613. var ObjectManager = function(controller) {
  614. ObjectManagerBase.call(this, controller);
  615. };
  616. ObjectManager.prototype = new Object();
  617. (function() {
  618. var proto = new ObjectManagerBase();
  619. for (prop in proto) {
  620. ObjectManager.prototype[prop] = proto[prop];
  621. }
  622. })();
  623. ObjectManager.prototype.instantiate = function(class_name, construct_params) {
  624. if (class_name === "MainApp") {
  625. var instance = new MainApp(this.controller);
  626. instance.associations = new Object();
  627. instance.associations["fields"] = new Association("Field", 0, -1);
  628. } else if (class_name === "Field") {
  629. var instance = new Field(this.controller);
  630. instance.associations = new Object();
  631. instance.associations["balls"] = new Association("Ball", 0, -1);
  632. instance.associations["buttons"] = new Association("Button", 0, -1);
  633. instance.associations["parent"] = new Association("MainApp", 1, 1);
  634. } else if (class_name === "Button") {
  635. var instance = new Button(this.controller, construct_params[0], construct_params[1], construct_params[2]);
  636. instance.associations = new Object();
  637. instance.associations["parent"] = new Association("Field", 1, 1);
  638. } else if (class_name === "Ball") {
  639. var instance = new Ball(this.controller, construct_params[0], construct_params[1], construct_params[2]);
  640. instance.associations = new Object();
  641. instance.associations["parent"] = new Association("Field", 1, 1);
  642. } else {
  643. throw new Error("Cannot instantiate class " + class_name);
  644. }
  645. return instance;
  646. };
  647. // add symbol 'ObjectManager' to package 'Bouncing_Balls_JavaScript_Version'
  648. Bouncing_Balls_JavaScript_Version.ObjectManager = ObjectManager;
  649. var Controller = function(event_loop_callbacks, finished_callback, behind_schedule_callback) {
  650. if (finished_callback === undefined) finished_callback = null;
  651. if (behind_schedule_callback === undefined) behind_schedule_callback = null;
  652. EventLoopControllerBase.call(this, new ObjectManager(this), event_loop_callbacks, finished_callback, behind_schedule_callback);
  653. this.addInputPort("ui");
  654. this.object_manager.createInstance("MainApp", new Array());
  655. };
  656. Controller.prototype = new Object();
  657. (function() {
  658. var proto = new EventLoopControllerBase();
  659. for (prop in proto) {
  660. Controller.prototype[prop] = proto[prop];
  661. }
  662. })();
  663. // add symbol 'Controller' to package 'Bouncing_Balls_JavaScript_Version'
  664. Bouncing_Balls_JavaScript_Version.Controller = Controller;
  665. })();