/**
 * Generated by Apache Royale Compiler from org\apache\royale\jewel\beads\controllers\DateFieldMouseController.as
 * org.apache.royale.jewel.beads.controllers.DateFieldMouseController
 *
 * @fileoverview
 *
 * @suppress {checkTypes|accessControls}
 */

goog.provide('org.apache.royale.jewel.beads.controllers.DateFieldMouseController');

goog.require('org.apache.royale.core.IDateChooserModel');
goog.require('org.apache.royale.core.IStrand');
goog.require('org.apache.royale.core.IUIBase');
goog.require('org.apache.royale.events.Event');
goog.require('org.apache.royale.events.IEventDispatcher');
goog.require('org.apache.royale.events.MouseEvent');
goog.require('org.apache.royale.jewel.Table');
goog.require('org.apache.royale.jewel.beads.views.DateChooserView');
goog.require('org.apache.royale.jewel.beads.views.DateFieldView');
goog.require('org.apache.royale.core.IBeadController');
goog.require('org.apache.royale.utils.Language');



/**
 *  constructor.
 *  
 *  @langversion 3.0
 *  @playerversion Flash 10.2
 *  @playerversion AIR 2.6
 *  @productversion Royale 0.9.4
 * @constructor
 * @implements {org.apache.royale.core.IBeadController}
 */
org.apache.royale.jewel.beads.controllers.DateFieldMouseController = function() {
};


/**
 * Prevent renaming of class. Needed for reflection.
 */
goog.exportSymbol('org.apache.royale.jewel.beads.controllers.DateFieldMouseController', org.apache.royale.jewel.beads.controllers.DateFieldMouseController);


/**
 * @private
 * @type {org.apache.royale.jewel.beads.views.DateFieldView}
 */
org.apache.royale.jewel.beads.controllers.DateFieldMouseController.prototype.org_apache_royale_jewel_beads_controllers_DateFieldMouseController_viewBead;


/**
 * @private
 * @type {org.apache.royale.jewel.Table}
 */
org.apache.royale.jewel.beads.controllers.DateFieldMouseController.prototype.org_apache_royale_jewel_beads_controllers_DateFieldMouseController_daysTable;


/**
 * @private
 * @type {org.apache.royale.core.IDateChooserModel}
 */
org.apache.royale.jewel.beads.controllers.DateFieldMouseController.prototype.org_apache_royale_jewel_beads_controllers_DateFieldMouseController_model;


/**
 * @private
 * @type {org.apache.royale.core.IStrand}
 */
org.apache.royale.jewel.beads.controllers.DateFieldMouseController.prototype.org_apache_royale_jewel_beads_controllers_DateFieldMouseController__strand;


/**
 * @asprivate
 * @private
 * @param {org.apache.royale.events.MouseEvent} event
 */
org.apache.royale.jewel.beads.controllers.DateFieldMouseController.prototype.org_apache_royale_jewel_beads_controllers_DateFieldMouseController_clickHandler = function(event) {
  event.stopImmediatePropagation();
  this.org_apache_royale_jewel_beads_controllers_DateFieldMouseController_viewBead.popUpVisible = true;
  org.apache.royale.utils.Language.as(this.org_apache_royale_jewel_beads_controllers_DateFieldMouseController_viewBead.popUp, org.apache.royale.events.IEventDispatcher, true).addEventListener(org.apache.royale.events.Event.CHANGE, org.apache.royale.utils.Language.closure(this.org_apache_royale_jewel_beads_controllers_DateFieldMouseController_changeHandler, this, 'changeHandler'));
  this.org_apache_royale_jewel_beads_controllers_DateFieldMouseController_daysTable = org.apache.royale.utils.Language.as(this.org_apache_royale_jewel_beads_controllers_DateFieldMouseController_viewBead.popUp.getBeadByType(org.apache.royale.jewel.beads.views.DateChooserView), org.apache.royale.jewel.beads.views.DateChooserView).daysTable;
  org.apache.royale.utils.Language.as(this.org_apache_royale_jewel_beads_controllers_DateFieldMouseController_daysTable, org.apache.royale.events.IEventDispatcher, true).addEventListener(org.apache.royale.events.MouseEvent.MOUSE_DOWN, org.apache.royale.utils.Language.closure(this.handleControlMouseDown, this, 'handleControlMouseDown'));
  org.apache.royale.utils.Language.as(this.org_apache_royale_jewel_beads_controllers_DateFieldMouseController_viewBead.popUp, org.apache.royale.core.IUIBase, true).addEventListener(org.apache.royale.events.MouseEvent.MOUSE_DOWN, org.apache.royale.utils.Language.closure(this.removePopUpWhenClickOutside, this, 'removePopUpWhenClickOutside'));
};


/**
 * @protected
 * @param {org.apache.royale.events.MouseEvent} event
 */
org.apache.royale.jewel.beads.controllers.DateFieldMouseController.prototype.handleControlMouseDown = function(event) {
  event.stopImmediatePropagation();
};


/**
 * @protected
 * @param {org.apache.royale.events.MouseEvent=} event
 */
org.apache.royale.jewel.beads.controllers.DateFieldMouseController.prototype.removePopUpWhenClickOutside = function(event) {
  event = typeof event !== 'undefined' ? event : null;
  org.apache.royale.utils.Language.as(this.org_apache_royale_jewel_beads_controllers_DateFieldMouseController_daysTable, org.apache.royale.events.IEventDispatcher, true).removeEventListener(org.apache.royale.events.MouseEvent.MOUSE_DOWN, org.apache.royale.utils.Language.closure(this.handleControlMouseDown, this, 'handleControlMouseDown'));
  org.apache.royale.utils.Language.as(this.org_apache_royale_jewel_beads_controllers_DateFieldMouseController_viewBead.popUp, org.apache.royale.core.IUIBase, true).removeEventListener(org.apache.royale.events.MouseEvent.MOUSE_DOWN, org.apache.royale.utils.Language.closure(this.removePopUpWhenClickOutside, this, 'removePopUpWhenClickOutside'));
  org.apache.royale.utils.Language.as(this.org_apache_royale_jewel_beads_controllers_DateFieldMouseController_viewBead.popUp, org.apache.royale.events.IEventDispatcher, true).removeEventListener(org.apache.royale.events.Event.CHANGE, org.apache.royale.utils.Language.closure(this.org_apache_royale_jewel_beads_controllers_DateFieldMouseController_changeHandler, this, 'changeHandler'));
  this.org_apache_royale_jewel_beads_controllers_DateFieldMouseController_viewBead.popUpVisible = false;
};


/**
 * @asprivate
 * @private
 * @param {org.apache.royale.events.Event} event
 */
org.apache.royale.jewel.beads.controllers.DateFieldMouseController.prototype.org_apache_royale_jewel_beads_controllers_DateFieldMouseController_changeHandler = function(event) {
  event.stopImmediatePropagation();
  org.apache.royale.utils.Language.as(this.org_apache_royale_jewel_beads_controllers_DateFieldMouseController_daysTable, org.apache.royale.events.IEventDispatcher, true).removeEventListener(org.apache.royale.events.MouseEvent.MOUSE_DOWN, org.apache.royale.utils.Language.closure(this.handleControlMouseDown, this, 'handleControlMouseDown'));
  org.apache.royale.utils.Language.as(this.org_apache_royale_jewel_beads_controllers_DateFieldMouseController_viewBead.popUp, org.apache.royale.core.IUIBase, true).removeEventListener(org.apache.royale.events.MouseEvent.MOUSE_DOWN, org.apache.royale.utils.Language.closure(this.removePopUpWhenClickOutside, this, 'removePopUpWhenClickOutside'));
  org.apache.royale.utils.Language.as(this.org_apache_royale_jewel_beads_controllers_DateFieldMouseController_viewBead.popUp, org.apache.royale.events.IEventDispatcher, true).removeEventListener(org.apache.royale.events.Event.CHANGE, org.apache.royale.utils.Language.closure(this.org_apache_royale_jewel_beads_controllers_DateFieldMouseController_changeHandler, this, 'changeHandler'));
  this.org_apache_royale_jewel_beads_controllers_DateFieldMouseController_model.selectedDate = org.apache.royale.utils.Language.as(this.org_apache_royale_jewel_beads_controllers_DateFieldMouseController_viewBead.popUp.getBeadByType(org.apache.royale.core.IDateChooserModel), org.apache.royale.core.IDateChooserModel, true).selectedDate;
  this.org_apache_royale_jewel_beads_controllers_DateFieldMouseController_viewBead.popUpVisible = false;
  org.apache.royale.utils.Language.as(this.org_apache_royale_jewel_beads_controllers_DateFieldMouseController__strand, org.apache.royale.events.IEventDispatcher, true).dispatchEvent(new org.apache.royale.events.Event(org.apache.royale.events.Event.CHANGE));
};


/**
 * @private
 * @param {*} d
 * @return {boolean}
 */
org.apache.royale.jewel.beads.controllers.DateFieldMouseController.prototype.org_apache_royale_jewel_beads_controllers_DateFieldMouseController_isValidDate = function(d) {
  return org.apache.royale.utils.Language.is(d, Date) && !isNaN(d);
};


/**
 * @asprivate
 * @private
 * @param {org.apache.royale.events.Event} event
 */
org.apache.royale.jewel.beads.controllers.DateFieldMouseController.prototype.org_apache_royale_jewel_beads_controllers_DateFieldMouseController_inputSelectionChangeHandler = function(event) {
  var /** @type {number} */ len = this.org_apache_royale_jewel_beads_controllers_DateFieldMouseController_viewBead.textInput.text.length;
  if (len == 10) {
    var /** @type {Date} */ date = new Date(this.org_apache_royale_jewel_beads_controllers_DateFieldMouseController_viewBead.textInput.text);
    this.org_apache_royale_jewel_beads_controllers_DateFieldMouseController_model.selectedDate = this.org_apache_royale_jewel_beads_controllers_DateFieldMouseController_isValidDate(date) ? date : null;
  }
};


org.apache.royale.jewel.beads.controllers.DateFieldMouseController.prototype.set__strand = function(value) {
  this.org_apache_royale_jewel_beads_controllers_DateFieldMouseController__strand = value;
  this.org_apache_royale_jewel_beads_controllers_DateFieldMouseController_model = org.apache.royale.utils.Language.as(this.org_apache_royale_jewel_beads_controllers_DateFieldMouseController__strand.getBeadByType(org.apache.royale.core.IDateChooserModel), org.apache.royale.core.IDateChooserModel);
  this.org_apache_royale_jewel_beads_controllers_DateFieldMouseController_viewBead = org.apache.royale.utils.Language.as(this.org_apache_royale_jewel_beads_controllers_DateFieldMouseController__strand.getBeadByType(org.apache.royale.jewel.beads.views.DateFieldView), org.apache.royale.jewel.beads.views.DateFieldView);
  org.apache.royale.utils.Language.as(this.org_apache_royale_jewel_beads_controllers_DateFieldMouseController_viewBead.menuButton, org.apache.royale.events.IEventDispatcher, true).addEventListener(org.apache.royale.events.MouseEvent.CLICK, org.apache.royale.utils.Language.closure(this.org_apache_royale_jewel_beads_controllers_DateFieldMouseController_clickHandler, this, 'clickHandler'));
  this.org_apache_royale_jewel_beads_controllers_DateFieldMouseController_viewBead.textInput.addEventListener(org.apache.royale.events.Event.CHANGE, org.apache.royale.utils.Language.closure(this.org_apache_royale_jewel_beads_controllers_DateFieldMouseController_inputSelectionChangeHandler, this, 'inputSelectionChangeHandler'));
};


Object.defineProperties(org.apache.royale.jewel.beads.controllers.DateFieldMouseController.prototype, /** @lends {org.apache.royale.jewel.beads.controllers.DateFieldMouseController.prototype} */ {
/**
  * @export
  * @type {org.apache.royale.core.IStrand} */
strand: {
set: org.apache.royale.jewel.beads.controllers.DateFieldMouseController.prototype.set__strand}}
);


/**
 * Metadata
 *
 * @type {Object.<string, Array.<Object>>}
 */
org.apache.royale.jewel.beads.controllers.DateFieldMouseController.prototype.ROYALE_CLASS_INFO = { names: [{ name: 'DateFieldMouseController', qName: 'org.apache.royale.jewel.beads.controllers.DateFieldMouseController', kind: 'class' }], interfaces: [org.apache.royale.core.IBeadController] };



/**
 * Reflection
 *
 * @return {Object.<string, Function>}
 */
org.apache.royale.jewel.beads.controllers.DateFieldMouseController.prototype.ROYALE_REFLECTION_INFO = function () {
  return {
    variables: function () {return {};},
    accessors: function () {
      return {
        'strand': { type: 'org.apache.royale.core.IStrand', access: 'writeonly', declaredBy: 'org.apache.royale.jewel.beads.controllers.DateFieldMouseController'}
      };
    },
    methods: function () {
      return {
        'DateFieldMouseController': { type: '', declaredBy: 'org.apache.royale.jewel.beads.controllers.DateFieldMouseController'}
      };
    }
  };
};