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

goog.provide('org.apache.royale.html.supportClasses.ButtonBarButtonItemRenderer');

goog.require('org.apache.royale.events.ItemClickedEvent');
goog.require('org.apache.royale.events.MouseEvent');
goog.require('org.apache.royale.html.TextButton');
goog.require('org.apache.royale.html.supportClasses.UIItemRendererBase');
goog.require('org.apache.royale.html.beads.ITextItemRenderer');
goog.require('org.apache.royale.utils.Language');



/**
 *  constructor.
 *
 *  @langversion 3.0
 *  @playerversion Flash 10.2
 *  @playerversion AIR 2.6
 *  @productversion Royale 0.0
 * @constructor
 * @extends {org.apache.royale.html.supportClasses.UIItemRendererBase}
 * @implements {org.apache.royale.html.beads.ITextItemRenderer}
 */
org.apache.royale.html.supportClasses.ButtonBarButtonItemRenderer = function() {
  org.apache.royale.html.supportClasses.ButtonBarButtonItemRenderer.base(this, 'constructor');
};
goog.inherits(org.apache.royale.html.supportClasses.ButtonBarButtonItemRenderer, org.apache.royale.html.supportClasses.UIItemRendererBase);


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


/**
 * @protected
 * @type {org.apache.royale.html.TextButton}
 */
org.apache.royale.html.supportClasses.ButtonBarButtonItemRenderer.prototype.textButton;


/**
 * @asprivate
 * @export
 * @override
 */
org.apache.royale.html.supportClasses.ButtonBarButtonItemRenderer.prototype.addedToParent = function() {
  org.apache.royale.html.supportClasses.ButtonBarButtonItemRenderer.superClass_.addedToParent.apply(this);
};


/**
 * @asprivate
 * @protected
 * @param {org.apache.royale.events.MouseEvent} event
 */
org.apache.royale.html.supportClasses.ButtonBarButtonItemRenderer.prototype.handleClickEvent = function(event) {
  var /** @type {org.apache.royale.events.ItemClickedEvent} */ newEvent = new org.apache.royale.events.ItemClickedEvent("itemClicked");
  newEvent.multipleSelection = event.shiftKey;
  newEvent.index = this.index;
  newEvent.data = this.data;
  this.dispatchEvent(newEvent);
};


/**
 * @asprivate
 * @export
 * @override
 */
org.apache.royale.html.supportClasses.ButtonBarButtonItemRenderer.prototype.setWidth = function(value, noEvent) {
  noEvent = typeof noEvent !== 'undefined' ? noEvent : false;
  org.apache.royale.html.supportClasses.ButtonBarButtonItemRenderer.superClass_.setWidth.apply(this, [ value, noEvent] );
  this.textButton.width = value;
};


/**
 * @asprivate
 * @export
 * @override
 */
org.apache.royale.html.supportClasses.ButtonBarButtonItemRenderer.prototype.setHeight = function(value, noEvent) {
  noEvent = typeof noEvent !== 'undefined' ? noEvent : false;
  org.apache.royale.html.supportClasses.ButtonBarButtonItemRenderer.superClass_.setHeight.apply(this, [ value, noEvent] );
  this.textButton.height = value;
};


/**
 * @asprivate
 * @export
 * @override
 */
org.apache.royale.html.supportClasses.ButtonBarButtonItemRenderer.prototype.adjustSize = function() {
  this.textButton.width = this.width;
  this.textButton.height = this.height;
  this.updateRenderer();
};


org.apache.royale.html.supportClasses.ButtonBarButtonItemRenderer.prototype.get__text = function() {
  return org.apache.royale.utils.Language.as(this.data, String);
};


org.apache.royale.html.supportClasses.ButtonBarButtonItemRenderer.prototype.set__text = function(value) {
  this.data = value;
};


org.apache.royale.html.supportClasses.ButtonBarButtonItemRenderer.prototype.set__data = function(value) {
  org.apache.royale.html.supportClasses.ButtonBarButtonItemRenderer.superClass_.set__data.apply(this, [ value] );
  var /** @type {boolean} */ added = false;
  if (this.textButton == null) {
    this.textButton = new org.apache.royale.html.TextButton();
    this.textButton.percentWidth = 100;
    this.textButton.addEventListener('click', org.apache.royale.utils.Language.closure(this.handleClickEvent, this, 'handleClickEvent'));
    added = true;
  }
  var /** @type {string} */ valueAsString;
  if (org.apache.royale.utils.Language.is(value, String)) {
    valueAsString = org.apache.royale.utils.Language.as(value, String);
  } else if (value.hasOwnProperty("label")) {
    valueAsString = String(value["label"]);
  } else if (value.hasOwnProperty("title")) {
    valueAsString = String(value["title"]);
  }
  if (valueAsString)
    this.textButton.text = valueAsString;
  if (added)
    this.addElement(this.textButton);
};


Object.defineProperties(org.apache.royale.html.supportClasses.ButtonBarButtonItemRenderer.prototype, /** @lends {org.apache.royale.html.supportClasses.ButtonBarButtonItemRenderer.prototype} */ {
/**
  * @export
  * @type {string} */
text: {
get: org.apache.royale.html.supportClasses.ButtonBarButtonItemRenderer.prototype.get__text,
set: org.apache.royale.html.supportClasses.ButtonBarButtonItemRenderer.prototype.set__text},
/**
  * @export
  * @type {Object} */
data: {
get: org.apache.royale.html.supportClasses.UIItemRendererBase.prototype.get__data,
set: org.apache.royale.html.supportClasses.ButtonBarButtonItemRenderer.prototype.set__data}}
);


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



/**
 * Reflection
 *
 * @return {Object.<string, Function>}
 */
org.apache.royale.html.supportClasses.ButtonBarButtonItemRenderer.prototype.ROYALE_REFLECTION_INFO = function () {
  return {
    variables: function () {return {};},
    accessors: function () {
      return {
        'text': { type: 'String', access: 'readwrite', declaredBy: 'org.apache.royale.html.supportClasses.ButtonBarButtonItemRenderer'},
        'data': { type: 'Object', access: 'writeonly', declaredBy: 'org.apache.royale.html.supportClasses.ButtonBarButtonItemRenderer'}
      };
    },
    methods: function () {
      return {
        'ButtonBarButtonItemRenderer': { type: '', declaredBy: 'org.apache.royale.html.supportClasses.ButtonBarButtonItemRenderer'},
        'addedToParent': { type: 'void', declaredBy: 'org.apache.royale.html.supportClasses.ButtonBarButtonItemRenderer'},
        'setWidth': { type: 'void', declaredBy: 'org.apache.royale.html.supportClasses.ButtonBarButtonItemRenderer', parameters: function () { return [  { index: 1, type: 'Number', optional: false },{ index: 2, type: 'Boolean', optional: true } ]; }},
        'setHeight': { type: 'void', declaredBy: 'org.apache.royale.html.supportClasses.ButtonBarButtonItemRenderer', parameters: function () { return [  { index: 1, type: 'Number', optional: false },{ index: 2, type: 'Boolean', optional: true } ]; }},
        'adjustSize': { type: 'void', declaredBy: 'org.apache.royale.html.supportClasses.ButtonBarButtonItemRenderer'}
      };
    }
  };
};