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

goog.provide('org.apache.royale.jewel.beads.views.NumericStepperView');

goog.require('org.apache.royale.core.BeadViewBase');
goog.require('org.apache.royale.core.IBead');
goog.require('org.apache.royale.core.IParent');
goog.require('org.apache.royale.core.IParentIUIBase');
goog.require('org.apache.royale.core.IRangeModel');
goog.require('org.apache.royale.core.IStrand');
goog.require('org.apache.royale.core.IUIBase');
goog.require('org.apache.royale.core.UIBase');
goog.require('org.apache.royale.events.Event');
goog.require('org.apache.royale.events.IEventDispatcher');
goog.require('org.apache.royale.events.ValueChangeEvent');
goog.require('org.apache.royale.jewel.Label');
goog.require('org.apache.royale.jewel.Spinner');
goog.require('org.apache.royale.jewel.TextInput');
goog.require('org.apache.royale.core.IBeadView');
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.core.BeadViewBase}
 * @implements {org.apache.royale.core.IBeadView}
 */
org.apache.royale.jewel.beads.views.NumericStepperView = function() {
  org.apache.royale.jewel.beads.views.NumericStepperView.base(this, 'constructor');
};
goog.inherits(org.apache.royale.jewel.beads.views.NumericStepperView, org.apache.royale.core.BeadViewBase);


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


/**
 * @private
 * @type {org.apache.royale.jewel.Label}
 */
org.apache.royale.jewel.beads.views.NumericStepperView.prototype.org_apache_royale_jewel_beads_views_NumericStepperView_label;


/**
 * @private
 * @type {org.apache.royale.jewel.TextInput}
 */
org.apache.royale.jewel.beads.views.NumericStepperView.prototype.org_apache_royale_jewel_beads_views_NumericStepperView_input;


/**
 * @private
 * @type {org.apache.royale.jewel.Spinner}
 */
org.apache.royale.jewel.beads.views.NumericStepperView.prototype.org_apache_royale_jewel_beads_views_NumericStepperView_spinner;


/**
 * @asprivate
 * @royaleignorecoercion org.apache.royale.core.UIBase
 * @private
 * @param {org.apache.royale.events.Event} event
 */
org.apache.royale.jewel.beads.views.NumericStepperView.prototype.org_apache_royale_jewel_beads_views_NumericStepperView_sizeChangeHandler = function(event) {
  var /** @type {boolean} */ widthToContent = this._strand.isWidthSizedToContent();
  var /** @type {number} */ inputWidth = this.org_apache_royale_jewel_beads_views_NumericStepperView_input.width;
  var /** @type {number} */ inputHeight = this.org_apache_royale_jewel_beads_views_NumericStepperView_input.height;
  var /** @type {number} */ strandWidth;
  if (!widthToContent) {
    strandWidth = this._strand.width;
  }
  if (!widthToContent)
    this.org_apache_royale_jewel_beads_views_NumericStepperView_input.width = strandWidth - this.org_apache_royale_jewel_beads_views_NumericStepperView_spinner.width - 2;
  
};


/**
 * @asprivate
 * @royaleignorecoercion org.apache.royale.events.IEventDispatcher
 * @private
 * @param {org.apache.royale.events.ValueChangeEvent} event
 */
org.apache.royale.jewel.beads.views.NumericStepperView.prototype.org_apache_royale_jewel_beads_views_NumericStepperView_spinnerValueChanged = function(event) {
  this.org_apache_royale_jewel_beads_views_NumericStepperView_input.text = "" + this.org_apache_royale_jewel_beads_views_NumericStepperView_spinner.value;
  var /** @type {org.apache.royale.events.ValueChangeEvent} */ newEvent = org.apache.royale.events.ValueChangeEvent.createUpdateEvent(this._strand, "value", event.oldValue, event.newValue);
  this._strand.dispatchEvent(newEvent);
};


/**
 * @asprivate
 * @private
 * @param {org.apache.royale.events.Event} event
 */
org.apache.royale.jewel.beads.views.NumericStepperView.prototype.org_apache_royale_jewel_beads_views_NumericStepperView_inputChangeHandler = function(event) {
  var /** @type {number} */ newValue = Number(this.org_apache_royale_jewel_beads_views_NumericStepperView_input.text);
  if (!isNaN(newValue)) {
    var /** @type {number} */ oldValue = this.org_apache_royale_jewel_beads_views_NumericStepperView_spinner.value;
    this.org_apache_royale_jewel_beads_views_NumericStepperView_spinner.value = newValue;
    if (oldValue != this.org_apache_royale_jewel_beads_views_NumericStepperView_spinner.value) {
      var /** @type {org.apache.royale.events.ValueChangeEvent} */ newEvent = org.apache.royale.events.ValueChangeEvent.createUpdateEvent(this._strand, "value", oldValue, this.org_apache_royale_jewel_beads_views_NumericStepperView_spinner.value);
      org.apache.royale.utils.Language.as(this._strand, org.apache.royale.events.IEventDispatcher, true).dispatchEvent(newEvent);
    }
  } else {
    this.org_apache_royale_jewel_beads_views_NumericStepperView_input.text = String(this.org_apache_royale_jewel_beads_views_NumericStepperView_spinner.value);
  }
};


/**
 * @asprivate
 * @royaleignorecoercion org.apache.royale.core.UIBase
 * @royaleignorecoercion org.apache.royale.core.IRangeModel
 * @private
 * @param {org.apache.royale.events.Event} event
 */
org.apache.royale.jewel.beads.views.NumericStepperView.prototype.org_apache_royale_jewel_beads_views_NumericStepperView_modelChangeHandler = function(event) {
  var /** @type {number} */ n = this._strand.model.value;
  this.org_apache_royale_jewel_beads_views_NumericStepperView_input.text = String(this._strand.model.value);
};


org.apache.royale.jewel.beads.views.NumericStepperView.prototype.set__strand = function(value) {
  org.apache.royale.jewel.beads.views.NumericStepperView.superClass_.set__strand.apply(this, [ value] );
  this.org_apache_royale_jewel_beads_views_NumericStepperView_input = new org.apache.royale.jewel.TextInput();
  value.addElement(this.org_apache_royale_jewel_beads_views_NumericStepperView_input);
  this.org_apache_royale_jewel_beads_views_NumericStepperView_spinner = new org.apache.royale.jewel.Spinner();
  this.org_apache_royale_jewel_beads_views_NumericStepperView_spinner.addBead(value.model);
  value.addElement(this.org_apache_royale_jewel_beads_views_NumericStepperView_spinner);
  
  this.org_apache_royale_jewel_beads_views_NumericStepperView_input.addEventListener(org.apache.royale.events.Event.CHANGE, org.apache.royale.utils.Language.closure(this.org_apache_royale_jewel_beads_views_NumericStepperView_inputChangeHandler, this, 'inputChangeHandler'));
  this.org_apache_royale_jewel_beads_views_NumericStepperView_spinner.addEventListener("valueChange", org.apache.royale.utils.Language.closure(this.org_apache_royale_jewel_beads_views_NumericStepperView_spinnerValueChanged, this, 'spinnerValueChanged'));
  value.addEventListener("widthChanged", org.apache.royale.utils.Language.closure(this.org_apache_royale_jewel_beads_views_NumericStepperView_sizeChangeHandler, this, 'sizeChangeHandler'));
  value.addEventListener("heightChanged", org.apache.royale.utils.Language.closure(this.org_apache_royale_jewel_beads_views_NumericStepperView_sizeChangeHandler, this, 'sizeChangeHandler'));
  value.addEventListener("sizeChanged", org.apache.royale.utils.Language.closure(this.org_apache_royale_jewel_beads_views_NumericStepperView_sizeChangeHandler, this, 'sizeChangeHandler'));
  value.model.addEventListener("valueChange", org.apache.royale.utils.Language.closure(this.org_apache_royale_jewel_beads_views_NumericStepperView_modelChangeHandler, this, 'modelChangeHandler'));
  value.model.addEventListener("minimumChange", org.apache.royale.utils.Language.closure(this.org_apache_royale_jewel_beads_views_NumericStepperView_modelChangeHandler, this, 'modelChangeHandler'));
  value.model.addEventListener("maximumChange", org.apache.royale.utils.Language.closure(this.org_apache_royale_jewel_beads_views_NumericStepperView_modelChangeHandler, this, 'modelChangeHandler'));
  value.model.addEventListener("stepSizeChange", org.apache.royale.utils.Language.closure(this.org_apache_royale_jewel_beads_views_NumericStepperView_modelChangeHandler, this, 'modelChangeHandler'));
  value.model.addEventListener("snapIntervalChange", org.apache.royale.utils.Language.closure(this.org_apache_royale_jewel_beads_views_NumericStepperView_modelChangeHandler, this, 'modelChangeHandler'));
  this.org_apache_royale_jewel_beads_views_NumericStepperView_input.text = String(this.org_apache_royale_jewel_beads_views_NumericStepperView_spinner.value);
  
  this.org_apache_royale_jewel_beads_views_NumericStepperView_sizeChangeHandler(null);
};


org.apache.royale.jewel.beads.views.NumericStepperView.prototype.get__contentView = function() {
  return this._strand;
};


org.apache.royale.jewel.beads.views.NumericStepperView.prototype.get__resizableView = function() {
  return this._strand;
};


Object.defineProperties(org.apache.royale.jewel.beads.views.NumericStepperView.prototype, /** @lends {org.apache.royale.jewel.beads.views.NumericStepperView.prototype} */ {
/**
  * @export
  * @type {org.apache.royale.core.IStrand} */
strand: {
set: org.apache.royale.jewel.beads.views.NumericStepperView.prototype.set__strand},
/**
  * @export
  * @type {org.apache.royale.core.IParentIUIBase} */
contentView: {
get: org.apache.royale.jewel.beads.views.NumericStepperView.prototype.get__contentView},
/**
  * @export
  * @type {org.apache.royale.core.IUIBase} */
resizableView: {
get: org.apache.royale.jewel.beads.views.NumericStepperView.prototype.get__resizableView}}
);


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



/**
 * Reflection
 *
 * @return {Object.<string, Function>}
 */
org.apache.royale.jewel.beads.views.NumericStepperView.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.views.NumericStepperView'},
        'contentView': { type: 'org.apache.royale.core.IParentIUIBase', access: 'readonly', declaredBy: 'org.apache.royale.jewel.beads.views.NumericStepperView'},
        'resizableView': { type: 'org.apache.royale.core.IUIBase', access: 'readonly', declaredBy: 'org.apache.royale.jewel.beads.views.NumericStepperView'}
      };
    },
    methods: function () {
      return {
        'NumericStepperView': { type: '', declaredBy: 'org.apache.royale.jewel.beads.views.NumericStepperView'}
      };
    }
  };
};