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

goog.provide('org.apache.royale.html.beads.controllers.ListSingleSelectionMouseController');

goog.require('org.apache.royale.core.IItemRendererParent');
goog.require('org.apache.royale.core.IRollOverModel');
goog.require('org.apache.royale.core.ISelectableItemRenderer');
goog.require('org.apache.royale.core.ISelectionModel');
goog.require('org.apache.royale.core.IStrand');
goog.require('org.apache.royale.events.Event');
goog.require('org.apache.royale.events.IEventDispatcher');
goog.require('org.apache.royale.events.ItemAddedEvent');
goog.require('org.apache.royale.events.ItemClickedEvent');
goog.require('org.apache.royale.events.ItemRemovedEvent');
goog.require('org.apache.royale.html.beads.IListView');
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
 * @constructor
 * @implements {org.apache.royale.core.IBeadController}
 */
org.apache.royale.html.beads.controllers.ListSingleSelectionMouseController = function() {
};


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


/**
 * @protected
 * @type {org.apache.royale.core.ISelectionModel}
 */
org.apache.royale.html.beads.controllers.ListSingleSelectionMouseController.prototype.listModel;


/**
 * @protected
 * @type {org.apache.royale.html.beads.IListView}
 */
org.apache.royale.html.beads.controllers.ListSingleSelectionMouseController.prototype.listView;


/**
 * @protected
 * @type {org.apache.royale.core.IItemRendererParent}
 */
org.apache.royale.html.beads.controllers.ListSingleSelectionMouseController.prototype.dataGroup;


/**
 * @private
 * @type {org.apache.royale.core.IStrand}
 */
org.apache.royale.html.beads.controllers.ListSingleSelectionMouseController.prototype.org_apache_royale_html_beads_controllers_ListSingleSelectionMouseController__strand;


/**
 * @royaleignorecoercion org.apache.royale.events.IEventDispatcher
 * @protected
 * @param {org.apache.royale.events.ItemAddedEvent} event
 */
org.apache.royale.html.beads.controllers.ListSingleSelectionMouseController.prototype.handleItemAdded = function(event) {
  event.item.addEventListener("itemClicked", org.apache.royale.utils.Language.closure(this.selectedHandler, this, 'selectedHandler'));
  event.item.addEventListener("itemRollOver", org.apache.royale.utils.Language.closure(this.rolloverHandler, this, 'rolloverHandler'));
  event.item.addEventListener("itemRollOut", org.apache.royale.utils.Language.closure(this.rolloutHandler, this, 'rolloutHandler'));
};


/**
 * @royaleignorecoercion org.apache.royale.events.IEventDispatcher
 * @protected
 * @param {org.apache.royale.events.ItemRemovedEvent} event
 */
org.apache.royale.html.beads.controllers.ListSingleSelectionMouseController.prototype.handleItemRemoved = function(event) {
  event.item.removeEventListener("itemClicked", org.apache.royale.utils.Language.closure(this.selectedHandler, this, 'selectedHandler'));
  event.item.removeEventListener("itemRollOver", org.apache.royale.utils.Language.closure(this.rolloverHandler, this, 'rolloverHandler'));
  event.item.removeEventListener("itemRollOut", org.apache.royale.utils.Language.closure(this.rolloutHandler, this, 'rolloutHandler'));
};


/**
 * @protected
 * @param {org.apache.royale.events.ItemClickedEvent} event
 */
org.apache.royale.html.beads.controllers.ListSingleSelectionMouseController.prototype.selectedHandler = function(event) {
  this.listModel.selectedIndex = event.index;
  this.listModel.selectedItem = event.data;
  this.listView.host.dispatchEvent(new org.apache.royale.events.Event("change"));
};


/**
 * @royaleemitcoercion org.apache.royale.core.ISelectableItemRenderer
 * @royaleignorecoercion org.apache.royale.core.IRollOverModel
 * @protected
 * @param {Object} event
 */
org.apache.royale.html.beads.controllers.ListSingleSelectionMouseController.prototype.rolloverHandler = function(event) {
  var /** @type {org.apache.royale.core.ISelectableItemRenderer} */ renderer = org.apache.royale.utils.Language.as(event.currentTarget, org.apache.royale.core.ISelectableItemRenderer);
  if (renderer) {
    this.listModel.rollOverIndex = renderer.index;
  }
};


/**
 * @royaleemitcoercion org.apache.royale.core.ISelectableItemRenderer
 * @royaleignorecoercion org.apache.royale.core.IRollOverModel
 * @protected
 * @param {Object} event
 */
org.apache.royale.html.beads.controllers.ListSingleSelectionMouseController.prototype.rolloutHandler = function(event) {
  var /** @type {org.apache.royale.core.ISelectableItemRenderer} */ renderer = org.apache.royale.utils.Language.as(event.currentTarget, org.apache.royale.core.ISelectableItemRenderer);
  if (renderer) {
    renderer.hovered = false;
    renderer.down = false;
    this.listModel.rollOverIndex = -1;
  }
};


org.apache.royale.html.beads.controllers.ListSingleSelectionMouseController.prototype.set__strand = function(value) {
  this.org_apache_royale_html_beads_controllers_ListSingleSelectionMouseController__strand = value;
  this.listModel = value.getBeadByType(org.apache.royale.core.ISelectionModel);
  this.listView = value.getBeadByType(org.apache.royale.html.beads.IListView);
  this.org_apache_royale_html_beads_controllers_ListSingleSelectionMouseController__strand.addEventListener("itemAdded", org.apache.royale.utils.Language.closure(this.handleItemAdded, this, 'handleItemAdded'));
  this.org_apache_royale_html_beads_controllers_ListSingleSelectionMouseController__strand.addEventListener("itemRemoved", org.apache.royale.utils.Language.closure(this.handleItemRemoved, this, 'handleItemRemoved'));
};


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


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



/**
 * Reflection
 *
 * @return {Object.<string, Function>}
 */
org.apache.royale.html.beads.controllers.ListSingleSelectionMouseController.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.html.beads.controllers.ListSingleSelectionMouseController'}
      };
    },
    methods: function () {
      return {
        'ListSingleSelectionMouseController': { type: '', declaredBy: 'org.apache.royale.html.beads.controllers.ListSingleSelectionMouseController'}
      };
    }
  };
};