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

goog.provide('org.apache.royale.jewel.ToggleButton');

goog.require('org.apache.royale.core.IIcon');
goog.require('org.apache.royale.core.ISelectable');
goog.require('org.apache.royale.core.WrappedHTMLElement');
goog.require('org.apache.royale.events.Event');
goog.require('org.apache.royale.events.MouseEvent');
goog.require('org.apache.royale.jewel.IconButton');
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
 * @extends {org.apache.royale.jewel.IconButton}
 * @implements {org.apache.royale.core.ISelectable}
 */
org.apache.royale.jewel.ToggleButton = function() {
  org.apache.royale.jewel.ToggleButton.base(this, 'constructor');
  this.typeNames = "jewel togglebutton";
  
};
goog.inherits(org.apache.royale.jewel.ToggleButton, org.apache.royale.jewel.IconButton);


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


/**
 * @private
 * @type {boolean}
 */
org.apache.royale.jewel.ToggleButton.prototype.org_apache_royale_jewel_ToggleButton__selected = false;


/**
 * @protected
 * @override
 */
org.apache.royale.jewel.ToggleButton.prototype.createElement = function() {
  org.apache.royale.jewel.ToggleButton.superClass_.createElement.apply(this);
  this.element.addEventListener(org.apache.royale.events.MouseEvent.CLICK, org.apache.royale.utils.Language.closure(this.org_apache_royale_jewel_ToggleButton_clickHandler, this, 'clickHandler'), false);
  this.org_apache_royale_jewel_ToggleButton_internalSelected();
  return this.element;
};


/**
 * @private
 * @param {org.apache.royale.events.Event} event
 */
org.apache.royale.jewel.ToggleButton.prototype.org_apache_royale_jewel_ToggleButton_clickHandler = function(event) {
  this.selected = !this.selected;
};


/**
 * @private
 */
org.apache.royale.jewel.ToggleButton.prototype.org_apache_royale_jewel_ToggleButton_internalSelected = function() {
  
  var /** @type {boolean} */ isToggleTextButtonSelected = this.containsClass("selected");
  if (isToggleTextButtonSelected != this.org_apache_royale_jewel_ToggleButton__selected)
    this.toggleClass("selected", this.org_apache_royale_jewel_ToggleButton__selected);
  if (this.icon && org.apache.royale.utils.Language.is(this.icon, org.apache.royale.core.ISelectable)) {
    var /** @type {org.apache.royale.core.ISelectable} */ selectableIcon = org.apache.royale.utils.Language.as(this.icon, org.apache.royale.core.ISelectable);
    selectableIcon.selected = this.org_apache_royale_jewel_ToggleButton__selected;
  }
};


org.apache.royale.jewel.ToggleButton.prototype.get__selected = function() {
  
  return this.org_apache_royale_jewel_ToggleButton__selected;
};


org.apache.royale.jewel.ToggleButton.prototype.set__selected = function(value) {
  
  if (this.org_apache_royale_jewel_ToggleButton__selected != value) {
    this.org_apache_royale_jewel_ToggleButton__selected = value;
    this.org_apache_royale_jewel_ToggleButton_internalSelected();
    this.dispatchEvent(new org.apache.royale.events.Event(org.apache.royale.events.Event.CHANGE));
  }
};


org.apache.royale.jewel.ToggleButton.prototype.set__icon = function(value) {
  org.apache.royale.jewel.ToggleButton.superClass_.set__icon.apply(this, [ value] );
  if (this.icon && org.apache.royale.utils.Language.is(this.icon, org.apache.royale.core.ISelectable)) {
    var /** @type {org.apache.royale.core.ISelectable} */ selectableIcon = org.apache.royale.utils.Language.as(this.icon, org.apache.royale.core.ISelectable);
    selectableIcon.selected = this.org_apache_royale_jewel_ToggleButton__selected;
  }
};


Object.defineProperties(org.apache.royale.jewel.ToggleButton.prototype, /** @lends {org.apache.royale.jewel.ToggleButton.prototype} */ {
/**
  * @export
  * @type {boolean} */
selected: {
get: org.apache.royale.jewel.ToggleButton.prototype.get__selected,
set: org.apache.royale.jewel.ToggleButton.prototype.set__selected},
/**
  * @export
  * @type {org.apache.royale.core.IIcon} */
icon: {
get: org.apache.royale.jewel.IconButton.prototype.get__icon,
set: org.apache.royale.jewel.ToggleButton.prototype.set__icon}}
);


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



/**
 * Reflection
 *
 * @return {Object.<string, Function>}
 */
org.apache.royale.jewel.ToggleButton.prototype.ROYALE_REFLECTION_INFO = function () {
  return {
    variables: function () {return {};},
    accessors: function () {
      return {
        'selected': { type: 'Boolean', access: 'readwrite', declaredBy: 'org.apache.royale.jewel.ToggleButton', metadata: function () { return [ { name: 'Bindable', args: [ { key: '', value: 'change' } ] } ]; }},
        'icon': { type: 'org.apache.royale.core.IIcon', access: 'writeonly', declaredBy: 'org.apache.royale.jewel.ToggleButton'}
      };
    },
    methods: function () {
      return {
        'ToggleButton': { type: '', declaredBy: 'org.apache.royale.jewel.ToggleButton'}
      };
    },
    metadata: function () { return [  ]; }
  };
};