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

goog.provide('org.apache.royale.html.accessories.NumericOnlyTextInputBead');

goog.require('goog.events.BrowserEvent');
goog.require('org.apache.royale.core.IStrand');
goog.require('org.apache.royale.core.UIBase');
goog.require('org.apache.royale.core.IBead');
goog.require('org.apache.royale.utils.Language');



/**
 *  constructor.
 *
 *  @langversion 3.0
 *  @playerversion Flash 10.2
 *  @playerversion AIR 2.6
 *  @productversion Royale 0.8
 * @constructor
 * @implements {org.apache.royale.core.IBead}
 */
org.apache.royale.html.accessories.NumericOnlyTextInputBead = function() {
};


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


/**
 * @private
 * @type {org.apache.royale.core.IStrand}
 */
org.apache.royale.html.accessories.NumericOnlyTextInputBead.prototype.org_apache_royale_html_accessories_NumericOnlyTextInputBead__strand;


/**
 * @private
 * @type {string}
 */
org.apache.royale.html.accessories.NumericOnlyTextInputBead.prototype.org_apache_royale_html_accessories_NumericOnlyTextInputBead__decimalSeparator = ".";


/**
 * @private
 * @type {number}
 */
org.apache.royale.html.accessories.NumericOnlyTextInputBead.prototype.org_apache_royale_html_accessories_NumericOnlyTextInputBead__maxChars = 0;


/**
 * @private
 * @param {goog.events.BrowserEvent} event
 */
org.apache.royale.html.accessories.NumericOnlyTextInputBead.prototype.org_apache_royale_html_accessories_NumericOnlyTextInputBead_validateInput = function(event) {
  var /** @type {number} */ code = event.charCode;
  if (event.keyCode == 8 || event.keyCode == 46)
    return;
  if (event.keyCode == 9 || event.keyCode == 13)
    return;
  if (event.keyCode == 37 || event.keyCode == 39)
    return;
  var /** @type {string} */ key = String.fromCharCode(code);
  var /** @type {RegExp} */ regex = /[0-9]|\./;
  if (!regex.test(key)) {
    event["returnValue"] = false;
    if (org.apache.royale.utils.Language.closure(event.preventDefault, event, 'preventDefault'))
      event.preventDefault();
    return;
  }
  var /** @type {number} */ cursorStart = Number(event.target.selectionStart);
  var /** @type {number} */ cursorEnd = Number(event.target.selectionEnd);
  var /** @type {string} */ left = org.apache.royale.utils.Language.string(event.target.value.substring(0, cursorStart));
  var /** @type {string} */ right = org.apache.royale.utils.Language.string(event.target.value.substr(cursorEnd));
  var /** @type {string} */ complete = left + key + right;
  if (isNaN(parseFloat(complete))) {
    event["returnValue"] = false;
    if (org.apache.royale.utils.Language.closure(event.preventDefault, event, 'preventDefault'))
      event.preventDefault();
  }
};


org.apache.royale.html.accessories.NumericOnlyTextInputBead.prototype.set__strand = function(value) {
  this.org_apache_royale_html_accessories_NumericOnlyTextInputBead__strand = value;
  
  var /** @type {org.apache.royale.core.UIBase} */ host = this.org_apache_royale_html_accessories_NumericOnlyTextInputBead__strand;
  host.element.addEventListener("keypress", org.apache.royale.utils.Language.closure(this.org_apache_royale_html_accessories_NumericOnlyTextInputBead_validateInput, this, 'validateInput'), false);
};


org.apache.royale.html.accessories.NumericOnlyTextInputBead.prototype.get__decimalSeparator = function() {
  return this.org_apache_royale_html_accessories_NumericOnlyTextInputBead__decimalSeparator;
};


org.apache.royale.html.accessories.NumericOnlyTextInputBead.prototype.set__decimalSeparator = function(value) {
  if (this.org_apache_royale_html_accessories_NumericOnlyTextInputBead__decimalSeparator != value) {
    this.org_apache_royale_html_accessories_NumericOnlyTextInputBead__decimalSeparator = value;
  }
};


org.apache.royale.html.accessories.NumericOnlyTextInputBead.prototype.get__maxChars = function() {
  return this.org_apache_royale_html_accessories_NumericOnlyTextInputBead__maxChars;
};


org.apache.royale.html.accessories.NumericOnlyTextInputBead.prototype.set__maxChars = function(value) {
  if (this.org_apache_royale_html_accessories_NumericOnlyTextInputBead__maxChars != value) {
    this.org_apache_royale_html_accessories_NumericOnlyTextInputBead__maxChars = value;
  }
};


Object.defineProperties(org.apache.royale.html.accessories.NumericOnlyTextInputBead.prototype, /** @lends {org.apache.royale.html.accessories.NumericOnlyTextInputBead.prototype} */ {
/**
  * @export
  * @type {org.apache.royale.core.IStrand} */
strand: {
set: org.apache.royale.html.accessories.NumericOnlyTextInputBead.prototype.set__strand},
/**
  * @export
  * @type {string} */
decimalSeparator: {
get: org.apache.royale.html.accessories.NumericOnlyTextInputBead.prototype.get__decimalSeparator,
set: org.apache.royale.html.accessories.NumericOnlyTextInputBead.prototype.set__decimalSeparator},
/**
  * @export
  * @type {number} */
maxChars: {
get: org.apache.royale.html.accessories.NumericOnlyTextInputBead.prototype.get__maxChars,
set: org.apache.royale.html.accessories.NumericOnlyTextInputBead.prototype.set__maxChars}}
);


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



/**
 * Reflection
 *
 * @return {Object.<string, Function>}
 */
org.apache.royale.html.accessories.NumericOnlyTextInputBead.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.accessories.NumericOnlyTextInputBead'},
        'decimalSeparator': { type: 'String', access: 'readwrite', declaredBy: 'org.apache.royale.html.accessories.NumericOnlyTextInputBead'},
        'maxChars': { type: 'int', access: 'readwrite', declaredBy: 'org.apache.royale.html.accessories.NumericOnlyTextInputBead'}
      };
    },
    methods: function () {
      return {
        'NumericOnlyTextInputBead': { type: '', declaredBy: 'org.apache.royale.html.accessories.NumericOnlyTextInputBead'}
      };
    }
  };
};