/* {{{ GPL

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

}}} */

/* {{{ GPL

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

}}} */

var Controller = MockWindow.extend({

  // {{{ init
  init: function( containerName, animation ) {
    
    this._super( containerName );
    this.animation = animation;
    
    this.animationWriter = new AnimationWriter();
    this.animationReader = new AnimationReader();

  },
  // }}}

  // {{{ getHistory
  getHistory: function() {
    return this.animation.history;
  },
  // }}}

  // {{{ onUndo
  onUndo: function() {
    if ( this.getHistory().canUndo() ) {
      this.getHistory().undo();
    }
    return false;
  },
  // }}}

  // {{{ onRedo
  onRedo: function() {
    if ( this.getHistory().canRedo() ) {
      this.getHistory().redo();
    }
    return false;
  },
  // }}}

  // {{{ onKeyPressed
  onKeyPressed: function( event ) {

    this.log.debug( "Controller is considering keypress", event.key );

    if ( (event.key == 'z') || (event.key == 'Z') ) {
      this.log.debug( "undo" );
      this.onUndo();
      return false;
    } else if ( (event.key == 'y') || (event.key == 'Y') ) {
      this.onRedo();
      return false;
    }
    
    return this._super( event );

  },
  // }}}

  // {{{ toString
  toString: function() {
    return "Controller : " + this.frame;
  }
  // }}}
  
});

Controller.prototype.log = new Log( "Controller" );

