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

goog.provide('org.apache.royale.jewel.beads.validators.Validator');

goog.require('org.apache.royale.core.IPopUpHost');
goog.require('org.apache.royale.core.IStrand');
goog.require('org.apache.royale.core.UIBase');
goog.require('org.apache.royale.events.Event');
goog.require('org.apache.royale.geom.Point');
goog.require('org.apache.royale.jewel.supportClasses.tooltip.ErrorTipLabel');
goog.require('org.apache.royale.utils.PointUtils');
goog.require('org.apache.royale.utils.UIUtils');
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.9.4
 * @constructor
 * @implements {org.apache.royale.core.IBead}
 */
org.apache.royale.jewel.beads.validators.Validator = function() {

this.org_apache_royale_jewel_beads_validators_Validator__xPos = org.apache.royale.jewel.beads.validators.Validator.LEFT;
this.org_apache_royale_jewel_beads_validators_Validator__yPos = org.apache.royale.jewel.beads.validators.Validator.TOP;
};


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


/**
 * @export
 * @const
 * @type {number}
 */
org.apache.royale.jewel.beads.validators.Validator.TOP = 10000;


/**
 * @export
 * @const
 * @type {number}
 */
org.apache.royale.jewel.beads.validators.Validator.BOTTOM = 10001;


/**
 * @export
 * @const
 * @type {number}
 */
org.apache.royale.jewel.beads.validators.Validator.LEFT = 10002;


/**
 * @export
 * @const
 * @type {number}
 */
org.apache.royale.jewel.beads.validators.Validator.RIGHT = 10003;


/**
 * @export
 * @const
 * @type {number}
 */
org.apache.royale.jewel.beads.validators.Validator.MIDDLE = 10004;


/**
 * @private
 * @type {org.apache.royale.jewel.supportClasses.tooltip.ErrorTipLabel}
 */
org.apache.royale.jewel.beads.validators.Validator.prototype.org_apache_royale_jewel_beads_validators_Validator__errorTip;


/**
 * @private
 * @type {org.apache.royale.core.IPopUpHost}
 */
org.apache.royale.jewel.beads.validators.Validator.prototype.org_apache_royale_jewel_beads_validators_Validator__host;


/**
 * @private
 * @type {number}
 */
org.apache.royale.jewel.beads.validators.Validator.prototype.org_apache_royale_jewel_beads_validators_Validator__xPos;


/**
 * @private
 * @type {number}
 */
org.apache.royale.jewel.beads.validators.Validator.prototype.org_apache_royale_jewel_beads_validators_Validator__yPos;


/**
 * @protected
 * @type {org.apache.royale.core.UIBase}
 */
org.apache.royale.jewel.beads.validators.Validator.prototype.hostComponent;


/**
 * @protected
 * @type {DOMTokenList}
 */
org.apache.royale.jewel.beads.validators.Validator.prototype.hostClassList;


/**
 * @private
 * @type {Function}
 */
org.apache.royale.jewel.beads.validators.Validator.prototype.org_apache_royale_jewel_beads_validators_Validator__validateFunction;


/**
 * @private
 * @type {number}
 */
org.apache.royale.jewel.beads.validators.Validator.prototype.org_apache_royale_jewel_beads_validators_Validator__required = 0;


/**
 * @private
 * @type {string}
 */
org.apache.royale.jewel.beads.validators.Validator.prototype.org_apache_royale_jewel_beads_validators_Validator__requiredFieldError = "This field is required.";


/**
 *  Performs validation and return the result.
 *  When result is false(invalid), errorTip appears on the control.
 *  And true(valid), the errorTip will disappear.
 * 
 *  @langversion 3.0
 *  @playerversion Flash 10.2
 *  @playerversion AIR 2.6
 *  @productversion Royale 0.9.4
 * @export
 * @param {org.apache.royale.events.Event=} event
 * @return {boolean}
 */
org.apache.royale.jewel.beads.validators.Validator.prototype.validate = function(event) {
  event = typeof event !== 'undefined' ? event : null;
  if (this.validateFunction) {
    var /** @type {string} */ errorText = org.apache.royale.utils.Language.string(this.validateFunction(this.hostComponent));
    if (errorText) {
      this.createErrorTip(errorText);
    } else {
      this.destroyErrorTip();
    }
    return !this.isError;
  }
  return true;
};


/**
 *  Create an errorTip that floats a error text over a control
 * 
 *  @langversion 3.0
 *  @playerversion Flash 10.2
 *  @playerversion AIR 2.6
 *  @productversion Royale 0.9.4
 * @protected
 * @param {string} errorText
 */
org.apache.royale.jewel.beads.validators.Validator.prototype.createErrorTip = function(errorText) {
  if (!errorText)
    return;
  if (this.org_apache_royale_jewel_beads_validators_Validator__errorTip == null) {
    this.org_apache_royale_jewel_beads_validators_Validator__errorTip = new org.apache.royale.jewel.supportClasses.tooltip.ErrorTipLabel();
    this.org_apache_royale_jewel_beads_validators_Validator__host = org.apache.royale.utils.UIUtils.findPopUpHost(this.hostComponent);
    this.org_apache_royale_jewel_beads_validators_Validator__host.popUpParent.addElement(this.org_apache_royale_jewel_beads_validators_Validator__errorTip, false);
  }
  this.org_apache_royale_jewel_beads_validators_Validator__errorTip.text = errorText;
  var /** @type {org.apache.royale.geom.Point} */ pt = this.determinePosition();
  this.org_apache_royale_jewel_beads_validators_Validator__errorTip.x = pt.x;
  this.org_apache_royale_jewel_beads_validators_Validator__errorTip.y = pt.y;
  if (!this.hostClassList.contains("errorBorder"))
    this.hostClassList.add("errorBorder");
};


/**
 *  Determines the position of the errorTip.
 * 
 *  @langversion 3.0
 *  @playerversion Flash 10.2
 *  @playerversion AIR 2.6
 *  @productversion Royale 0.9.4
 * @protected
 * @return {org.apache.royale.geom.Point}
 */
org.apache.royale.jewel.beads.validators.Validator.prototype.determinePosition = function() {
  var /** @type {number} */ xFactor = 1;
  var /** @type {number} */ yFactor = 1;
  var /** @type {org.apache.royale.geom.Point} */ hp = org.apache.royale.utils.PointUtils.localToGlobal(new org.apache.royale.geom.Point(0, 0), this.org_apache_royale_jewel_beads_validators_Validator__host);
  var /** @type {org.apache.royale.geom.Point} */ pt;
  if (this.org_apache_royale_jewel_beads_validators_Validator__xPos == org.apache.royale.jewel.beads.validators.Validator.LEFT) {
    xFactor = Number["POSITIVE_INFINITY"];
  } else if (this.org_apache_royale_jewel_beads_validators_Validator__xPos == org.apache.royale.jewel.beads.validators.Validator.MIDDLE) {
    xFactor = 2;
  } else if (this.org_apache_royale_jewel_beads_validators_Validator__xPos == org.apache.royale.jewel.beads.validators.Validator.RIGHT) {
    xFactor = 1;
  }
  if (this.org_apache_royale_jewel_beads_validators_Validator__yPos == org.apache.royale.jewel.beads.validators.Validator.TOP) {
    yFactor = Number["POSITIVE_INFINITY"];
  } else if (this.org_apache_royale_jewel_beads_validators_Validator__yPos == org.apache.royale.jewel.beads.validators.Validator.MIDDLE) {
    yFactor = 2;
  } else if (this.org_apache_royale_jewel_beads_validators_Validator__yPos == org.apache.royale.jewel.beads.validators.Validator.BOTTOM) {
    yFactor = 1;
  }
  pt = new org.apache.royale.geom.Point(this.hostComponent.width / xFactor - hp.x, this.hostComponent.height / yFactor - hp.y);
  pt = org.apache.royale.utils.PointUtils.localToGlobal(pt, this.hostComponent);
  return pt;
};


/**
 *  Destroy the created errorTip
 * 
 *  @langversion 3.0
 *  @playerversion Flash 10.2
 *  @playerversion AIR 2.6
 *  @productversion Royale 0.9.4
 * @protected
 */
org.apache.royale.jewel.beads.validators.Validator.prototype.destroyErrorTip = function() {
  if (this.org_apache_royale_jewel_beads_validators_Validator__errorTip) {
    this.org_apache_royale_jewel_beads_validators_Validator__host.popUpParent.removeElement(this.org_apache_royale_jewel_beads_validators_Validator__errorTip);
    this.org_apache_royale_jewel_beads_validators_Validator__errorTip = null;
    if (this.hostClassList.contains("errorBorder"))
      this.hostClassList.remove("errorBorder");
  }
};


org.apache.royale.jewel.beads.validators.Validator.prototype.set__strand = function(value) {
  this.hostComponent = org.apache.royale.utils.Language.as(value, org.apache.royale.core.UIBase);
  this.hostClassList = this.hostComponent.positioner.classList;
};


org.apache.royale.jewel.beads.validators.Validator.prototype.get__isError = function() {
  return (this.org_apache_royale_jewel_beads_validators_Validator__errorTip != null);
};


org.apache.royale.jewel.beads.validators.Validator.prototype.get__validateFunction = function() {
  return this.org_apache_royale_jewel_beads_validators_Validator__validateFunction;
};


org.apache.royale.jewel.beads.validators.Validator.prototype.set__validateFunction = function(func) {
  this.org_apache_royale_jewel_beads_validators_Validator__validateFunction = func;
};


org.apache.royale.jewel.beads.validators.Validator.prototype.get__required = function() {
  return this.org_apache_royale_jewel_beads_validators_Validator__required;
};


org.apache.royale.jewel.beads.validators.Validator.prototype.set__required = function(value) {
  this.org_apache_royale_jewel_beads_validators_Validator__required = value;
};


org.apache.royale.jewel.beads.validators.Validator.prototype.get__requiredFieldError = function() {
  return this.org_apache_royale_jewel_beads_validators_Validator__requiredFieldError;
};


org.apache.royale.jewel.beads.validators.Validator.prototype.set__requiredFieldError = function(value) {
  this.org_apache_royale_jewel_beads_validators_Validator__requiredFieldError = value;
};


org.apache.royale.jewel.beads.validators.Validator.prototype.set__xPos = function(pos) {
  this.org_apache_royale_jewel_beads_validators_Validator__xPos = pos;
};


org.apache.royale.jewel.beads.validators.Validator.prototype.set__yPos = function(pos) {
  this.org_apache_royale_jewel_beads_validators_Validator__yPos = pos;
};


Object.defineProperties(org.apache.royale.jewel.beads.validators.Validator.prototype, /** @lends {org.apache.royale.jewel.beads.validators.Validator.prototype} */ {
/**
  * @export
  * @type {org.apache.royale.core.IStrand} */
strand: {
set: org.apache.royale.jewel.beads.validators.Validator.prototype.set__strand},
/**
  * @export
  * @type {boolean} */
isError: {
get: org.apache.royale.jewel.beads.validators.Validator.prototype.get__isError},
/**
  * @export
  * @type {Function} */
validateFunction: {
get: org.apache.royale.jewel.beads.validators.Validator.prototype.get__validateFunction,
set: org.apache.royale.jewel.beads.validators.Validator.prototype.set__validateFunction},
/**
  * @export
  * @type {number} */
required: {
get: org.apache.royale.jewel.beads.validators.Validator.prototype.get__required,
set: org.apache.royale.jewel.beads.validators.Validator.prototype.set__required},
/**
  * @export
  * @type {string} */
requiredFieldError: {
get: org.apache.royale.jewel.beads.validators.Validator.prototype.get__requiredFieldError,
set: org.apache.royale.jewel.beads.validators.Validator.prototype.set__requiredFieldError},
/**
  * @export
  * @type {number} */
xPos: {
set: org.apache.royale.jewel.beads.validators.Validator.prototype.set__xPos},
/**
  * @export
  * @type {number} */
yPos: {
set: org.apache.royale.jewel.beads.validators.Validator.prototype.set__yPos}}
);


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



/**
 * Reflection
 *
 * @return {Object.<string, Function>}
 */
org.apache.royale.jewel.beads.validators.Validator.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.validators.Validator'},
        'isError': { type: 'Boolean', access: 'readonly', declaredBy: 'org.apache.royale.jewel.beads.validators.Validator'},
        'validateFunction': { type: 'Function', access: 'readwrite', declaredBy: 'org.apache.royale.jewel.beads.validators.Validator'},
        'required': { type: 'int', access: 'readwrite', declaredBy: 'org.apache.royale.jewel.beads.validators.Validator'},
        'requiredFieldError': { type: 'String', access: 'readwrite', declaredBy: 'org.apache.royale.jewel.beads.validators.Validator'},
        'xPos': { type: 'int', access: 'writeonly', declaredBy: 'org.apache.royale.jewel.beads.validators.Validator'},
        'yPos': { type: 'int', access: 'writeonly', declaredBy: 'org.apache.royale.jewel.beads.validators.Validator'}
      };
    },
    methods: function () {
      return {
        'Validator': { type: '', declaredBy: 'org.apache.royale.jewel.beads.validators.Validator'},
        'validate': { type: 'Boolean', declaredBy: 'org.apache.royale.jewel.beads.validators.Validator', parameters: function () { return [  { index: 1, type: 'org.apache.royale.events.Event', optional: true } ]; }}
      };
    }
  };
};