behaviourmanager.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* This file is part of AToMPM - A Tool for Multi-Paradigm Modelling
  2. * Copyright 2011 by the AToMPM team and licensed under the LGPL
  3. * See COPYING.lesser and README.md in the root of this project for full details
  4. */
  5. BehaviorManager = new function(){
  6. var activeBehaviourStatechart = undefined;
  7. /**
  8. * Sends the current event to the currently active state chart, if
  9. * it exists
  10. */
  11. this.handleUserEvent = function( name, event ){
  12. if( activeBehaviourStatechart == undefined ) {
  13. console.warn('There is no active behaviour statechart to process the event. ' +
  14. 'If this event was triggered immediately after a page load, ' +
  15. 'then the statechart may just not be loaded yet.');
  16. } else {
  17. activeBehaviourStatechart.handleUserEvent(name,event);
  18. }
  19. };
  20. /**
  21. * Returns whether or not there is a state chart currently loaded
  22. */
  23. this.isStatechartLoaded = function() {
  24. return activeBehaviourStatechart != undefined;
  25. };
  26. /**
  27. * Sets the currently active state chart
  28. */
  29. this.setActiveBehaviourStatechart = function(sc, init){
  30. if( sc == __SC_DOCK )
  31. throw 'Dock behaviour is not [yet] described by a statechart';
  32. else if( sc == __SC_CANVAS )
  33. activeBehaviourStatechart = __canvasBehaviourStatechart;
  34. else if( sc == __SC_DIALOG )
  35. activeBehaviourStatechart = __dialogBehaviourStatechart;
  36. if( init )
  37. activeBehaviourStatechart.init();
  38. };
  39. return this;
  40. }();