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

goog.provide('org.apache.royale.html.beads.layouts.DataGridLayout');

goog.require('org.apache.royale.core.IBorderPaddingMarginValuesImpl');
goog.require('org.apache.royale.core.IDataGridModel');
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.core.ValuesManager');
goog.require('org.apache.royale.core.layout.EdgeData');
goog.require('org.apache.royale.events.Event');
goog.require('org.apache.royale.events.IEventDispatcher');
goog.require('org.apache.royale.html.beads.IDataGridView');
goog.require('org.apache.royale.html.beads.models.ButtonBarModel');
goog.require('org.apache.royale.html.supportClasses.IDataGridColumn');
goog.require('org.apache.royale.core.IBeadLayout');
goog.require('org.apache.royale.utils.Language');



/**
 *  constructor
 *  
 *  @langversion 3.0
 *  @playerversion Flash 10.2
 *  @playerversion AIR 2.6
 *  @productversion Royale 0.9
 * @constructor
 * @implements {org.apache.royale.core.IBeadLayout}
 */
org.apache.royale.html.beads.layouts.DataGridLayout = function() {
};


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


/**
 * @private
 * @type {org.apache.royale.core.IStrand}
 */
org.apache.royale.html.beads.layouts.DataGridLayout.prototype.org_apache_royale_html_beads_layouts_DataGridLayout__strand;


/**
 * @private
 * @param {org.apache.royale.events.Event} event
 */
org.apache.royale.html.beads.layouts.DataGridLayout.prototype.org_apache_royale_html_beads_layouts_DataGridLayout_handleSizeChanges = function(event) {
  this.layout();
};


/**
 * @private
 * @param {org.apache.royale.events.Event} event
 */
org.apache.royale.html.beads.layouts.DataGridLayout.prototype.org_apache_royale_html_beads_layouts_DataGridLayout_handleLayoutNeeded = function(event) {
  this.layout();
};


/**
 * @copy org.apache.royale.core.IBeadLayout#layout
 * @royaleignorecoercion org.apache.royale.core.IBorderPaddingMarginValuesImpl
 * @royaleignorecoercion org.apache.royale.core.IDataGridModel
 * @royaleignorecoercion org.apache.royale.core.IUIBase
 * @royaleignorecoercion org.apache.royale.core.UIBase
 * @royaleignorecoercion org.apache.royale.html.beads.IDataGridView
 * @royaleignorecoercion org.apache.royale.html.beads.models.ButtonBarModel
 * @royaleignorecoercion org.apache.royale.html.supportClasses.IDataGridColumn
 * @export
 * @return {boolean}
 */
org.apache.royale.html.beads.layouts.DataGridLayout.prototype.layout = function() {
  var /** @type {Object} */ header = this.org_apache_royale_html_beads_layouts_DataGridLayout_uiHost.view.header;
  var /** @type {Object} */ listArea = this.org_apache_royale_html_beads_layouts_DataGridLayout_uiHost.view.listArea;
  var /** @type {Array} */ displayedColumns = this.org_apache_royale_html_beads_layouts_DataGridLayout_uiHost.view.columnLists;
  var /** @type {Object} */ model = this.org_apache_royale_html_beads_layouts_DataGridLayout_uiHost.model;
  var /** @type {org.apache.royale.core.layout.EdgeData} */ borderMetrics = org.apache.royale.core.ValuesManager["valuesImpl"].getBorderMetrics(this.org_apache_royale_html_beads_layouts_DataGridLayout__strand);
  var /** @type {number} */ useWidth = this.org_apache_royale_html_beads_layouts_DataGridLayout_uiHost.width - (borderMetrics.left + borderMetrics.right);
  var /** @type {number} */ useHeight = this.org_apache_royale_html_beads_layouts_DataGridLayout_uiHost.height - (borderMetrics.top + borderMetrics.bottom);
  var /** @type {number} */ xpos = 0;
  var /** @type {number} */ defaultColumnWidth = useWidth / model.columns.length;
  var /** @type {Array} */ columnWidths = [];
  for (var /** @type {number} */ i = 0; i < displayedColumns.length; i++) {
    var /** @type {Object} */ columnDef = model.columns[i];
    var /** @type {Object} */ columnList = displayedColumns[i];
    columnList.x = xpos;
    columnList.y = 0;
    var /** @type {number} */ columnWidth = defaultColumnWidth;
    if (!isNaN(columnDef.columnWidth)) {
      columnWidth = (columnDef.columnWidth / this.org_apache_royale_html_beads_layouts_DataGridLayout_uiHost.width) * useWidth;
    }
    columnList.width = columnWidth;
    columnWidths.push(columnWidth);
    xpos += columnList.width;
  }
  var /** @type {Object} */ bbmodel = header.getBeadByType(org.apache.royale.html.beads.models.ButtonBarModel);
  bbmodel.buttonWidths = columnWidths;
  header.x = borderMetrics.left;
  header.y = borderMetrics.top;
  
  header.percentWidth = 100;
  listArea.element.style.position = "absolute";
  listArea.x = borderMetrics.left;
  listArea.y = header.height + header.y;
  
  listArea.percentWidth = 100;
  listArea.height = useHeight - header.height;
  header.dispatchEvent(new org.apache.royale.events.Event("layoutNeeded"));
  listArea.dispatchEvent(new org.apache.royale.events.Event("layoutNeeded"));
  return true;
};


org.apache.royale.html.beads.layouts.DataGridLayout.prototype.set__strand = function(value) {
  this.org_apache_royale_html_beads_layouts_DataGridLayout__strand = value;
  this.org_apache_royale_html_beads_layouts_DataGridLayout__strand.addEventListener("widthChanged", org.apache.royale.utils.Language.closure(this.org_apache_royale_html_beads_layouts_DataGridLayout_handleSizeChanges, this, 'handleSizeChanges'));
  this.org_apache_royale_html_beads_layouts_DataGridLayout__strand.addEventListener("heightChanged", org.apache.royale.utils.Language.closure(this.org_apache_royale_html_beads_layouts_DataGridLayout_handleSizeChanges, this, 'handleSizeChanges'));
  this.org_apache_royale_html_beads_layouts_DataGridLayout__strand.addEventListener("sizeChanged", org.apache.royale.utils.Language.closure(this.org_apache_royale_html_beads_layouts_DataGridLayout_handleSizeChanges, this, 'handleSizeChanges'));
  this.org_apache_royale_html_beads_layouts_DataGridLayout__strand.addEventListener("layoutNeeded", org.apache.royale.utils.Language.closure(this.org_apache_royale_html_beads_layouts_DataGridLayout_handleLayoutNeeded, this, 'handleLayoutNeeded'));
};


org.apache.royale.html.beads.layouts.DataGridLayout.prototype.get__org_apache_royale_html_beads_layouts_DataGridLayout_uiHost = function() {
  return this.org_apache_royale_html_beads_layouts_DataGridLayout__strand;
};


Object.defineProperties(org.apache.royale.html.beads.layouts.DataGridLayout.prototype, /** @lends {org.apache.royale.html.beads.layouts.DataGridLayout.prototype} */ {
/**
  * @export
  * @type {org.apache.royale.core.IStrand} */
strand: {
set: org.apache.royale.html.beads.layouts.DataGridLayout.prototype.set__strand},
/**
  * @export
  * @type {org.apache.royale.core.UIBase} */
org_apache_royale_html_beads_layouts_DataGridLayout_uiHost: {
get: org.apache.royale.html.beads.layouts.DataGridLayout.prototype.get__org_apache_royale_html_beads_layouts_DataGridLayout_uiHost}}
);


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



/**
 * Reflection
 *
 * @return {Object.<string, Function>}
 */
org.apache.royale.html.beads.layouts.DataGridLayout.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.beads.layouts.DataGridLayout'}
      };
    },
    methods: function () {
      return {
        'DataGridLayout': { type: '', declaredBy: 'org.apache.royale.html.beads.layouts.DataGridLayout'},
        'layout': { type: 'Boolean', declaredBy: 'org.apache.royale.html.beads.layouts.DataGridLayout'}
      };
    }
  };
};