behaviourmanager.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*******************************************************************************
  2. AToMPM - A Tool for Multi-Paradigm Modelling
  3. Copyright (c) 2011 Raphael Mannadiar (raphael.mannadiar@mail.mcgill.ca)
  4. Modified by Conner Hansen (chansen@crimson.ua.edu)
  5. This file is part of AToMPM.
  6. AToMPM is free software: you can redistribute it and/or modify it under the
  7. terms of the GNU Lesser General Public License as published by the Free Software
  8. Foundation, either version 3 of the License, or (at your option) any later
  9. version.
  10. AToMPM is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  12. PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public License along
  14. with AToMPM. If not, see <http://www.gnu.org/licenses/>.
  15. *******************************************************************************/
  16. BehaviorManager = new function(){
  17. var activeBehaviourStatechart = undefined;
  18. /**
  19. * Sends the current event to the currently active state chart, if
  20. * it exists
  21. */
  22. this.handleUserEvent = function( name, event ){
  23. if( activeBehaviourStatechart == undefined ) {
  24. console.warn('There is no active behaviour statechart to process the event. ' +
  25. 'If this event was triggered immediately after a page load, ' +
  26. 'then the statechart may just not be loaded yet.');
  27. } else {
  28. activeBehaviourStatechart.handleUserEvent(name,event);
  29. }
  30. };
  31. /**
  32. * Returns whether or not there is a state chart currently loaded
  33. */
  34. this.isStatechartLoaded = function() {
  35. return activeBehaviourStatechart != undefined;
  36. };
  37. /**
  38. * Sets the currently active state chart
  39. */
  40. this.setActiveBehaviourStatechart = function(sc, init){
  41. if( sc == __SC_DOCK )
  42. throw 'Dock behaviour is not [yet] described by a statechart';
  43. else if( sc == __SC_CANVAS )
  44. activeBehaviourStatechart = __canvasBehaviourStatechart;
  45. else if( sc == __SC_DIALOG )
  46. activeBehaviourStatechart = __dialogBehaviourStatechart;
  47. if( init )
  48. activeBehaviourStatechart.init();
  49. };
  50. return this;
  51. }();