Updated Branches: refs/heads/develop 03ec92ada -> 130d94271
JavaScript version of ButtonBar. Enhanced itemRenderer factory model, too. Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/130d9427 Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/130d9427 Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/130d9427 Branch: refs/heads/develop Commit: 130d94271d7d971af91ecf702efcc24c8dfd8ed4 Parents: 03ec92a Author: Peter Ent <p...@apache.org> Authored: Wed Sep 25 11:56:05 2013 -0400 Committer: Peter Ent <p...@apache.org> Committed: Wed Sep 25 11:56:05 2013 -0400 ---------------------------------------------------------------------- .../flex/html/staticControls/ButtonBar.js | 74 ++++++++ .../org/apache/flex/html/staticControls/List.js | 2 +- .../DataItemRendererFactoryForArrayData.js | 101 ++++++++++ .../beads/layouts/NonVirtualHorizontalLayout.js | 22 ++- .../ButtonBarButtonItemRenderer.js | 105 +++++++++++ .../supportClasses/DataItemRenderer.js | 182 +++++++++++++++++++ 6 files changed, 480 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/130d9427/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/ButtonBar.js ---------------------------------------------------------------------- diff --git a/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/ButtonBar.js b/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/ButtonBar.js new file mode 100644 index 0000000..23eac85 --- /dev/null +++ b/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/ButtonBar.js @@ -0,0 +1,74 @@ +/** + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +goog.provide('org.apache.flex.html.staticControls.ButtonBar'); + +goog.require('org.apache.flex.core.ListBase'); +goog.require('org.apache.flex.html.staticControls.List'); +goog.require('org.apache.flex.html.staticControls.beads.DataItemRendererFactoryForArrayData'); +goog.require('org.apache.flex.html.staticControls.beads.layouts.NonVirtualHorizontalLayout'); +goog.require('org.apache.flex.html.staticControls.supportClasses.ButtonBarButtonItemRenderer'); + + + +/** + * @constructor + * @extends {org.apache.flex.core.ListBase} + */ +org.apache.flex.html.staticControls.ButtonBar = function() { + + this.model = new + org.apache.flex.html.staticControls.beads.models.ArraySelectionModel(); + this.addBead(this.model); + + goog.base(this); + + this.addBead(new + org.apache.flex.html.staticControls.beads.ListView()); + + this.addBead(new +org.apache.flex.html.staticControls.beads.layouts.NonVirtualHorizontalLayout()); + + this.itemRendererFactory = new + org.apache.flex.html.staticControls.beads. + DataItemRendererFactoryForArrayData(); + this.itemRendererFactory.set_itemRendererClass('org.apache.flex.html.' + + 'staticControls.supportClasses.ButtonBarButtonItemRenderer'); + this.addBead(this.itemRendererFactory); + + this.addBead(new + org.apache.flex.html.staticControls.beads.controllers. + ListSingleSelectionMouseController()); +}; +goog.inherits(org.apache.flex.html.staticControls.ButtonBar, + org.apache.flex.core.ListBase); + + +/** + * @override + * @this {org.apache.flex.html.staticControls.List} + */ +org.apache.flex.html.staticControls.ButtonBar.prototype.createElement = + function() { + //goog.base(this, 'createElement'); + + this.element = document.createElement('div'); + this.element.style.overflow = 'auto'; + this.element.style.border = 'solid'; + this.element.style.borderWidth = '1px'; + this.element.style.borderColor = '#333333'; + this.positioner = this.element; + + this.set_className('ButtonBar'); +}; http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/130d9427/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/List.js ---------------------------------------------------------------------- diff --git a/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/List.js b/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/List.js index 8805adc..de6ea81 100644 --- a/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/List.js +++ b/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/List.js @@ -58,7 +58,7 @@ org.apache.flex.html.staticControls.List.prototype.createElement = /** * @expose - * @this {org.apache.flex.html.staticControls.TextInput} + * @this {org.apache.flex.html.staticControls.List} * @param {object} event The event that triggered the selection. */ org.apache.flex.html.staticControls.List.prototype.selectedHandler = http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/130d9427/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/beads/DataItemRendererFactoryForArrayData.js ---------------------------------------------------------------------- diff --git a/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/beads/DataItemRendererFactoryForArrayData.js b/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/beads/DataItemRendererFactoryForArrayData.js new file mode 100644 index 0000000..f32cbe1 --- /dev/null +++ b/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/beads/DataItemRendererFactoryForArrayData.js @@ -0,0 +1,101 @@ +/** + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +goog.provide('org.apache.flex.html.staticControls.beads.DataItemRendererFactoryForArrayData'); + +goog.require('org.apache.flex.events.EventDispatcher'); +goog.require('org.apache.flex.html.staticControls.beads.models.ArraySelectionModel'); +goog.require('org.apache.flex.html.staticControls.supportClasses.ButtonBarButtonItemRenderer'); + +/** + * @constructor + * @extends {org.apache.flex.events.EventDispatcher} + */ +org.apache.flex.html.staticControls.beads.DataItemRendererFactoryForArrayData = +function() { + goog.base(this); +}; +goog.inherits( + org.apache.flex.html.staticControls.beads.DataItemRendererFactoryForArrayData, + org.apache.flex.events.EventDispatcher); + + + +/** + * @expose + * @this {org.apache.flex.html.staticControls.beads. + DataItemRendererFactoryForArrayData} + * @param {object} value The component strand. + */ +org.apache.flex.html.staticControls.beads.DataItemRendererFactoryForArrayData. +prototype.set_strand = function(value) { + this.strand_ = value; + + this.model = value.getBeadByType( + org.apache.flex.html.staticControls.beads.models.ArraySelectionModel); + + this.listView = value.getBeadByType( + org.apache.flex.html.staticControls.beads.ListView); + this.dataGroup = this.listView.get_dataGroup(); + + this.model.addEventListener('dataProviderChanged', + goog.bind(this.dataProviderChangedHandler, this)); +}; + + +/** + * @expose + * @this {org.apache.flex.html.staticControls.beads. + * DataItemRendererFactoryForArrayData} + * @return {object} Class used for the itemRenderer. + */ +org.apache.flex.html.staticControls.beads.DataItemRendererFactoryForArrayData. +prototype.get_itemRendererClass = function() { + return this.itemRendererClass_; +}; + +/** + * @expose + * @this {org.apache.flex.html.staticControls.beads. + DataItemRendererFactoryForArrayData} + * @param {object} value class to use for the item renderer. + */ +org.apache.flex.html.staticControls.beads.DataItemRendererFactoryForArrayData. +prototype.set_itemRendererClass = function(value) { + this.itemRendererClass_ = value; +}; + + +/** + * @expose + * @this {org.apache.flex.html.staticControls.beads. + DataItemRendererFactoryForArrayData} + * @param {object} event The event that triggered the dataProvider change. + */ +org.apache.flex.html.staticControls.beads.DataItemRendererFactoryForArrayData. +prototype.dataProviderChangedHandler = function(event) { + var dp, i, n, opt; + + dp = this.model.get_dataProvider(); + n = dp.length; + for (i = 0; i < n; i++) { + var expr = 'new ' + String(this.itemRendererClass_) + '()'; + opt = eval(expr); + this.dataGroup.addElement(opt); + opt.set_data(dp[i]); + } + + var newEvent = new org.apache.flex.events.Event('itemsCreated'); + this.strand_.dispatchEvent(newEvent); +}; http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/130d9427/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/beads/layouts/NonVirtualHorizontalLayout.js ---------------------------------------------------------------------- diff --git a/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/beads/layouts/NonVirtualHorizontalLayout.js b/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/beads/layouts/NonVirtualHorizontalLayout.js index 35828df..a9f29a0 100644 --- a/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/beads/layouts/NonVirtualHorizontalLayout.js +++ b/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/beads/layouts/NonVirtualHorizontalLayout.js @@ -14,6 +14,7 @@ goog.provide('org.apache.flex.html.staticControls.beads.layouts.NonVirtualHorizontalLayout'); +goog.require('org.apache.flex.html.staticControls.beads.ListView'); /** * @constructor @@ -30,27 +31,38 @@ org.apache.flex.html.staticControls.beads.layouts.NonVirtualHorizontalLayout = /** * @expose - * @this {org.apache.flex.html.staticControls.beads.layouts.NonVirtualHorizontalLayout} + * @this {org.apache.flex.html.staticControls.beads.layouts. + NonVirtualHorizontalLayout} * @param {Object} value The new host. */ -org.apache.flex.html.staticControls.beads.layouts.NonVirtualHorizontalLayout.prototype.set_strand = +org.apache.flex.html.staticControls.beads.layouts.NonVirtualHorizontalLayout. +prototype.set_strand = function(value) { if (this.strand_ !== value) { this.strand_ = value; this.strand_.addEventListener('childrenAdded', goog.bind(this.changeHandler, this)); + this.strand_.addEventListener('itemsCreated', + goog.bind(this.changeHandler, this)); + this.strand_.element.style.display = 'block'; } }; /** - * @this {org.apache.flex.html.staticControls.beads.layouts.NonVirtualHorizontalLayout} + * @this {org.apache.flex.html.staticControls.beads.layouts. + NonVirtualHorizontalLayout} * @param {org.apache.flex.events.Event} event The text getter. */ -org.apache.flex.html.staticControls.beads.layouts.NonVirtualHorizontalLayout.prototype.changeHandler = function(event) { +org.apache.flex.html.staticControls.beads.layouts.NonVirtualHorizontalLayout. +prototype.changeHandler = function(event) { var children, i, n; - children = this.strand_.internalChildren(); + var layoutParent = this.strand_.getBeadByType( + org.apache.flex.html.staticControls.beads.ListView); + var contentView = layoutParent.get_dataGroup(); + + children = contentView.internalChildren(); n = children.length; for (i = 0; i < n; i++) { http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/130d9427/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/supportClasses/ButtonBarButtonItemRenderer.js ---------------------------------------------------------------------- diff --git a/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/supportClasses/ButtonBarButtonItemRenderer.js b/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/supportClasses/ButtonBarButtonItemRenderer.js new file mode 100644 index 0000000..4257074 --- /dev/null +++ b/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/supportClasses/ButtonBarButtonItemRenderer.js @@ -0,0 +1,105 @@ +/** + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +goog.provide('org.apache.flex.html.staticControls.supportClasses.ButtonBarButtonItemRenderer'); + +goog.require('org.apache.flex.html.staticControls.beads.controllers.ItemRendererMouseController'); +goog.require('org.apache.flex.html.staticControls.supportClasses.DataItemRenderer'); + +/** + * @constructor + * @extends {org.apache.flex.html.staticControls.supportClasses.DataItemRenderer} + */ +org.apache.flex.html.staticControls.supportClasses.ButtonBarButtonItemRenderer = +function() { + goog.base(this); +}; +goog.inherits( + org.apache.flex.html.staticControls.supportClasses.ButtonBarButtonItemRenderer, + org.apache.flex.html.staticControls.supportClasses.DataItemRenderer); + + +/** + * @override + * @this {org.apache.flex.html.staticControls.supportClasses. + ButtonBarButtonItemRenderer} + */ +org.apache.flex.html.staticControls.supportClasses.ButtonBarButtonItemRenderer. +prototype.createElement = function() { + + this.element = document.createElement('div'); + this.positioner = this.element; + + this.button = document.createElement('button'); + this.element.appendChild(this.button); + + this.element.flexjs_wrapper = this; + this.set_className('ButtonBarButtonItemRenderer'); + + // itemRenderers should provide something for the background to handle + // the selection and highlight + this.backgroundView = this.element; + + this.controller = new org.apache.flex.html.staticControls.beads.controllers. + ItemRendererMouseController(); + this.controller.set_strand(this); +}; + + +/** + * @expose + * @this {org.apache.flex.html.staticControls.supportClasses. + ButtonBarButtonItemRenderer} + * @param {Object} value The strand. + */ +org.apache.flex.html.staticControls.supportClasses.ButtonBarButtonItemRenderer. +prototype.set_strand = function(value) { + + this.strand_ = value; +}; + + +/** + * @expose + * @this {org.apache.flex.html.staticControls.supportClasses. + ButtonBarButtonItemRenderer} + * @return {Object} The strand. + */ +org.apache.flex.html.staticControls.supportClasses.ButtonBarButtonItemRenderer. +prototype.get_strand = function() { + return this.strand_; +}; + + +/** + * @expose + * @this {org.apache.flex.html.staticControls.supportClasses. + ButtonBarButtonItemRenderer} + * @param {Object} value The text to display. + */ +org.apache.flex.html.staticControls.supportClasses.ButtonBarButtonItemRenderer. +prototype.set_data = function(value) { + + goog.base(this, 'set_data', value); + + if (value.hasOwnProperty('label')) { + this.button.innerHTML = value['label']; + } + else if (value.hasOwnProperty('title')) { + this.button.innerHTML = value['title']; + } + else { + this.button.innerHHTML = String(value); + } +}; http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/130d9427/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/supportClasses/DataItemRenderer.js ---------------------------------------------------------------------- diff --git a/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/supportClasses/DataItemRenderer.js b/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/supportClasses/DataItemRenderer.js new file mode 100644 index 0000000..ce89be3 --- /dev/null +++ b/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/supportClasses/DataItemRenderer.js @@ -0,0 +1,182 @@ +/** + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +goog.provide('org.apache.flex.html.staticControls.supportClasses.DataItemRenderer'); + +goog.require('org.apache.flex.core.UIBase'); +goog.require('org.apache.flex.html.staticControls.beads.controllers.ItemRendererMouseController'); + +/** + * @constructor + * @extends {org.apache.flex.core.UIBase} + */ +org.apache.flex.html.staticControls.supportClasses.DataItemRenderer = +function() { + goog.base(this); +}; +goog.inherits( + org.apache.flex.html.staticControls.supportClasses.DataItemRenderer, + org.apache.flex.core.UIBase); + + +/** + * @override + * @this {org.apache.flex.html.staticControls.supportClasses.DataItemRenderer} + */ +org.apache.flex.html.staticControls.supportClasses.DataItemRenderer. +prototype.createElement = function() { + + this.element = document.createElement('div'); + this.positioner = this.element; + + this.element.flexjs_wrapper = this; + this.set_className('DataItemRenderer'); + + // itemRenderers should provide something for the background to handle + // the selection and highlight + this.backgroundView = this.element; + + this.controller = new org.apache.flex.html.staticControls.beads.controllers. + ItemRendererMouseController(); + this.controller.set_strand(this); +}; + + +/** + * @expose + * @this {org.apache.flex.html.staticControls.supportClasses.DataItemRenderer} + * @param {Object} value The strand. + */ +org.apache.flex.html.staticControls.supportClasses.DataItemRenderer. +prototype.set_strand = function(value) { + + this.strand_ = value; +}; + + +/** + * @expose + * @this {org.apache.flex.html.staticControls.supportClasses.DataItemRenderer} + * @return {Object} The strand. + */ +org.apache.flex.html.staticControls.supportClasses.DataItemRenderer. +prototype.get_strand = function() { + return this.strand_; +}; + + +/** + * @expose + * @this {org.apache.flex.html.staticControls.supportClasses.DataItemRenderer} + * @return {Object} The item renderer's parent. + */ +org.apache.flex.html.staticControls.supportClasses.DataItemRenderer. +prototype.get_itemRendererParent = function() { + return this.rendererParent_; +}; + + +/** + * @expose + * @this {org.apache.flex.html.staticControls.supportClasses.DataItemRenderer} + * @param {Object} value The item renderer's parent. + */ +org.apache.flex.html.staticControls.supportClasses.DataItemRenderer. +prototype.set_itemRendererParent = function(value) { + this.rendererParent_ = value; +}; + + +/** + * @expose + * @this {org.apache.flex.html.staticControls.supportClasses.DataItemRenderer} + * @return {Object} The renderer's index. + */ +org.apache.flex.html.staticControls.supportClasses.DataItemRenderer. +prototype.get_index = function() { + return this.index_; +}; + + +/** + * @expose + * @this {org.apache.flex.html.staticControls.supportClasses.DataItemRenderer} + * @param {Object} value The renderer's index. + */ +org.apache.flex.html.staticControls.supportClasses.DataItemRenderer. +prototype.set_index = function(value) { + this.index_ = value; +}; + + +/** + * @expose + * @this {org.apache.flex.html.staticControls.supportClasses.DataItemRenderer} + * @param {Object} value The data to display. + */ +org.apache.flex.html.staticControls.supportClasses.DataItemRenderer. +prototype.set_data = function(value) { + + this.data = value; +}; + + +/** + * @expose + * @this {org.apache.flex.html.staticControls.supportClasses.DataItemRenderer} + * @return {Object} The value being displayed. + */ +org.apache.flex.html.staticControls.supportClasses.DataItemRenderer. +prototype.get_data = function() { + + return this.data; +}; + + +/** + * @expose + * @this {org.apache.flex.html.staticControls.supportClasses.DataItemRenderer} + * @param {boolean} value The selection state. + */ +org.apache.flex.html.staticControls.supportClasses.DataItemRenderer. +prototype.set_selected = function(value) { + this.selected_ = value; + + if (value) { + this.backgroundView.style.backgroundColor = '#9C9C9C'; + } else { + this.backgroundView.style.backgroundColor = null; + } +}; + + +/** + * @expose + * @this {org.apache.flex.html.staticControls.supportClasses.DataItemRenderer} + * @param {boolean} value The hovered state. + */ +org.apache.flex.html.staticControls.supportClasses.DataItemRenderer. +prototype.set_hovered = function(value) { + this.hovered_ = value; + + if (value) { + this.backgroundView.style.backgroundColor = '#ECECEC'; + } else { + if (this.selected_) { + this.backgroundView.style.backgroundColor = '#9C9C9C'; + } else { + this.backgroundView.style.backgroundColor = null; + } + } +};