http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/7853ef15/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/TextInputView.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/TextInputView.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/TextInputView.as new file mode 100644 index 0000000..a6f1438 --- /dev/null +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/TextInputView.as @@ -0,0 +1,135 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You 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. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.html.beads +{ + import flash.display.DisplayObject; + import flash.text.TextFieldType; + + import org.apache.flex.core.ILayoutChild; + import org.apache.flex.core.IStrand; + import org.apache.flex.events.Event; + import org.apache.flex.events.IEventDispatcher; + import org.apache.flex.geom.Rectangle; + import org.apache.flex.utils.CSSContainerUtils; + + /** + * The TextInputView class is the view for + * the org.apache.flex.html.TextInput in + * a ComboBox and other controls + * because it does not display a border. + * It displays text using a TextField, so there is no + * right-to-left text support in this view. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class TextInputView extends TextFieldViewBase + { + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function TextInputView() + { + super(); + + textField.selectable = true; + textField.type = TextFieldType.INPUT; + textField.mouseEnabled = true; + textField.multiline = false; + textField.wordWrap = false; + } + + /** + * @private + */ + override public function set strand(value:IStrand):void + { + super.strand = value; + + autoWidth = autoHeight = false; + + var w:Number; + var h:Number; + var uiMetrics:Rectangle; + var ilc:ILayoutChild = host as ILayoutChild; + if (ilc.isWidthSizedToContent()) + { + uiMetrics = CSSContainerUtils.getBorderAndPaddingMetrics(host); + // use default width of 20 + var s:String = textField.text; + textField.text = "0"; + w = textField.textWidth * 20; + h = textField.textHeight; + textField.text = s; + ilc.setWidth(w + uiMetrics.left + uiMetrics.right, true); + } + if (ilc.isHeightSizedToContent()) + { + if (!uiMetrics) + uiMetrics = CSSContainerUtils.getBorderAndPaddingMetrics(host); + if (isNaN(h)) + { + s = textField.text; + textField.text = "0"; + h = textField.textHeight; + textField.text = s; + } + ilc.setHeight(h + uiMetrics.top + uiMetrics.bottom, true); + } + + heightChangeHandler(null); + } + + /** + * @private + */ + override protected function heightChangeHandler(event:Event):void + { + var hh:Number = host.height; + if( !isNaN(hh) && hh > 0 ) + { + textField.height = textField.textHeight + 5; + } + + textField.y = ((hh - textField.height) / 2); + } + + /** + * @private + */ + override protected function sizeChangeHandler(event:Event):void + { + var ww:Number = host.width; + if( !isNaN(ww) && ww > 0 ) textField.width = ww; + + var hh:Number = host.height; + if( !isNaN(hh) && hh > 0 ) + { + textField.height = textField.textHeight + 5; + textField.y = ((hh - textField.height) / 2); + } + } + } +}
http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/7853ef15/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/TextInputWithBorderView.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/TextInputWithBorderView.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/TextInputWithBorderView.as new file mode 100644 index 0000000..fbab13e --- /dev/null +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/TextInputWithBorderView.as @@ -0,0 +1,100 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You 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. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.html.beads +{ + import flash.display.DisplayObject; + + import org.apache.flex.core.IBead; + import org.apache.flex.core.IBeadModel; + import org.apache.flex.core.ILayoutChild; + import org.apache.flex.core.IParent; + import org.apache.flex.core.IStrand; + import org.apache.flex.core.ValuesManager; + import org.apache.flex.events.Event; + import org.apache.flex.events.IEventDispatcher; + import org.apache.flex.geom.Rectangle; + import org.apache.flex.html.supportClasses.Border; + import org.apache.flex.utils.CSSContainerUtils; + + /** + * The TextInputWithBorderView class is the default view for + * the org.apache.flex.html.TextInput. + * It displays text using a TextField, so there is no + * right-to-left text support in this view. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class TextInputWithBorderView extends TextInputView + { + public function TextInputWithBorderView() + { + super(); + textField.parentDrawsBackground = true; + textField.parentHandlesPadding = true; + } + + /** + * @private + */ + override public function set strand(value:IStrand):void + { + super.strand = value; + + value.addBead(new (ValuesManager.valuesImpl.getValue(value, "iBackgroundBead")) as IBead); + value.addBead(new (ValuesManager.valuesImpl.getValue(value, "iBorderBead")) as IBead); + } + + /** + * Determine the width of the TextField. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + override protected function widthChangeHandler(event:Event):void + { + if (!inWidthChange) + { + textField.autoSize = "none"; + autoWidth = false; + var uiMetrics:Rectangle = CSSContainerUtils.getBorderAndPaddingMetrics(host); + textField.width = host.width - uiMetrics.left - uiMetrics.right; + textField.x = uiMetrics.left; + } + } + + /** + * Determine the size of the TextField. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + override protected function sizeChangeHandler(event:Event):void + { + super.sizeChangeHandler(event); + widthChangeHandler(event); + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/7853ef15/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/TextItemRendererFactoryForArrayData.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/TextItemRendererFactoryForArrayData.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/TextItemRendererFactoryForArrayData.as new file mode 100644 index 0000000..f500094 --- /dev/null +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/TextItemRendererFactoryForArrayData.as @@ -0,0 +1,144 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You 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. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.html.beads +{ + import org.apache.flex.core.IBead; + import org.apache.flex.core.IDataProviderItemRendererMapper; + import org.apache.flex.core.IItemRendererClassFactory; + import org.apache.flex.core.IItemRendererParent; + import org.apache.flex.core.ISelectionModel; + import org.apache.flex.core.IStrand; + import org.apache.flex.core.ValuesManager; + import org.apache.flex.events.Event; + import org.apache.flex.events.IEventDispatcher; + + /** + * The TextItemRendererFactoryForArrayData class is the + * IDataProviderItemRendererMapper for creating + * ITextItemRenderers and assigning them data from an array. + * Other IDataProviderItemRendererMapper implementations + * assign specific array or vector types to item + * renderers expecting those types. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class TextItemRendererFactoryForArrayData implements IBead, IDataProviderItemRendererMapper + { + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function TextItemRendererFactoryForArrayData() + { + } + + private var selectionModel:ISelectionModel; + + private var _strand:IStrand; + + /** + * @copy org.apache.flex.core.IBead#strand + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function set strand(value:IStrand):void + { + _strand = value; + selectionModel = value.getBeadByType(ISelectionModel) as ISelectionModel; + var listView:IListView = value.getBeadByType(IListView) as IListView; + dataGroup = listView.dataGroup; + selectionModel.addEventListener("dataProviderChanged", dataProviderChangeHandler); + + if (!itemRendererFactory) + { + _itemRendererFactory = new (ValuesManager.valuesImpl.getValue(_strand, "iItemRendererClassFactory")) as IItemRendererClassFactory; + _strand.addBead(_itemRendererFactory); + } + + dataProviderChangeHandler(null); + } + + private var _itemRendererFactory:IItemRendererClassFactory; + + /** + * An IItemRendererClassFactory that should generate ITextItemRenderers + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get itemRendererFactory():IItemRendererClassFactory + { + return _itemRendererFactory + } + + /** + * @private + */ + public function set itemRendererFactory(value:IItemRendererClassFactory):void + { + _itemRendererFactory = value; + } + + /** + * The IItemRendererParent that should parent the ITextItemRenderers + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + protected var dataGroup:IItemRendererParent; + + private function dataProviderChangeHandler(event:Event):void + { + var dp:Array = selectionModel.dataProvider as Array; + if (!dp) + return; + + dataGroup.removeAllElements(); + + var n:int = dp.length; + for (var i:int = 0; i < n; i++) + { + var tf:ITextItemRenderer = itemRendererFactory.createItemRenderer(dataGroup) as ITextItemRenderer; + tf.index = i; + dataGroup.addElement(tf); + if (selectionModel.labelField) + tf.text = dp[i][selectionModel.labelField]; + else + tf.text = dp[i]; + } + + IEventDispatcher(_strand).dispatchEvent(new Event("itemsCreated")); + } + + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/7853ef15/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/TextItemRendererFactoryForStringVectorData.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/TextItemRendererFactoryForStringVectorData.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/TextItemRendererFactoryForStringVectorData.as new file mode 100644 index 0000000..5c034d9 --- /dev/null +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/TextItemRendererFactoryForStringVectorData.as @@ -0,0 +1,128 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You 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. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.html.beads +{ + + import org.apache.flex.core.IBead; + import org.apache.flex.core.IItemRendererClassFactory; + import org.apache.flex.core.IItemRendererParent; + import org.apache.flex.core.ISelectionModel; + import org.apache.flex.core.IStrand; + import org.apache.flex.events.Event; + + /** + * The TextItemRendererFactoryForStringVectorData class is the + * IDataProviderItemRendererMapper for creating + * ITextItemRenderers and assigning them data from an vector + * of Strings. Other IDataProviderItemRendererMapper implementations + * assign specific array or vector types to item + * renderers expecting those types. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class TextItemRendererFactoryForStringVectorData implements IBead + { + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function TextItemRendererFactoryForStringVectorData() + { + } + + private var selectionModel:ISelectionModel; + + private var _strand:IStrand; + + /** + * @copy org.apache.flex.core.IBead#strand + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function set strand(value:IStrand):void + { + _strand = value; + selectionModel = value.getBeadByType(ISelectionModel) as ISelectionModel; + var listView:IListView = value.getBeadByType(IListView) as IListView; + dataGroup = listView.dataGroup; + selectionModel.addEventListener("dataProviderChange", dataProviderChangeHandler); + dataProviderChangeHandler(null); + } + + private var _itemRendererFactory:IItemRendererClassFactory; + + /** + * An IItemRendererClassFactory that should generate ITextItemRenderers + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get itemRendererFactory():IItemRendererClassFactory + { + return _itemRendererFactory + } + + /** + * @private + */ + public function set itemRendererFactory(value:IItemRendererClassFactory):void + { + _itemRendererFactory = value; + } + + /** + * The IItemRendererParent that should parent the ITextItemRenderers + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + protected var dataGroup:IItemRendererParent; + + private function dataProviderChangeHandler(event:Event):void + { + var dp:Vector.<String> = selectionModel.dataProvider as Vector.<String>; + + dataGroup.removeAllElements(); + + var n:int = dp.length; + for (var i:int = 0; i < n; i++) + { + var tf:ITextItemRenderer = itemRendererFactory.createItemRenderer(dataGroup) as ITextItemRenderer; + tf.index = i; + dataGroup.addElement(tf); + tf.text = dp[i]; + } + } + + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/7853ef15/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/TitleBarMeasurementBead.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/TitleBarMeasurementBead.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/TitleBarMeasurementBead.as new file mode 100644 index 0000000..8195f70 --- /dev/null +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/TitleBarMeasurementBead.as @@ -0,0 +1,108 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You 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. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.html.beads +{ + import org.apache.flex.core.IMeasurementBead; + import org.apache.flex.core.IStrand; + import org.apache.flex.core.ValuesManager; + import org.apache.flex.html.TitleBar; + + /** + * The TitleBarMeasurementBead class measures the overall size of a + * org.apache.flex.html.TitleBar. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class TitleBarMeasurementBead implements IMeasurementBead + { + /** + * constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function TitleBarMeasurementBead() + { + } + + /** + * The overall width of the org.apache.flex.html.TitleBar. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get measuredWidth():Number + { + var mwidth:Number = 0; + var titleBar:TitleBar = _strand as TitleBar; + var titleView:TitleBarView = _strand.getBeadByType(TitleBarView) as TitleBarView; + var labelMeasure:IMeasurementBead = titleView.titleLabel.measurementBead; + mwidth = labelMeasure.measuredWidth; + if( titleBar.showCloseButton ) { + var buttonMeasure:IMeasurementBead = titleView.closeButton.measurementBead; + mwidth += buttonMeasure.measuredWidth; + } + return mwidth; + } + + /** + * The overall height of the org.apache.flex.html.TitleBar. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get measuredHeight():Number + { + var mheight:Number = 0; + var titleBar:TitleBar = _strand as TitleBar; + var titleView:TitleBarView = _strand.getBeadByType(TitleBarView) as TitleBarView; + var labelMeasure:IMeasurementBead = titleView.titleLabel.measurementBead; + mheight = labelMeasure.measuredHeight; + if( titleBar.showCloseButton ) { + var buttonMeasure:IMeasurementBead = titleView.closeButton.measurementBead; + mheight = Math.max(mheight,buttonMeasure.measuredHeight); + } + return mheight; + } + + private var _strand:IStrand; + + /** + * @copy org.apache.flex.core.IBead#strand + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function set strand(value:IStrand):void + { + _strand = value; + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/7853ef15/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/TitleBarView.mxml ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/TitleBarView.mxml b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/TitleBarView.mxml new file mode 100644 index 0000000..cebd24b --- /dev/null +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/TitleBarView.mxml @@ -0,0 +1,58 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You 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. + +--> +<!--- + The TitleBarView is the view for a Panel's TitleBar written in MXML + + @langversion 3.0 + @playerversion Flash 10.2 + @playerversion AIR 2.6 + @productversion FlexJS 0.0 +--> +<js:MXMLBeadViewBase xmlns:fx="http://ns.adobe.com/mxml/2009" + xmlns:js="library://ns.apache.org/flexjs/basic"> + + <fx:Script> + <![CDATA[ + import org.apache.flex.html.TitleBar; + import org.apache.flex.core.ITitleBarModel; + import org.apache.flex.core.UIBase; + import org.apache.flex.events.Event; + + private function clickHandler():void + { + var newEvent:org.apache.flex.events.Event = new org.apache.flex.events.Event('close',true); + UIBase(_strand).dispatchEvent(newEvent) + } + ]]> + </fx:Script> + <js:beads> + <js:MXMLBeadViewBaseDataBinding /> + <js:LayoutChangeNotifier watchedProperty="{titleLabel.text}" /> + </js:beads> + + <js:Label id="titleLabel" text="{ITitleBarModel(model).title}" > + <js:style> + <js:SimpleCSSStyles fontWeight="inherit" margin="5" /> + </js:style> + </js:Label> + <js:CloseButton id="closeButton" click="clickHandler()" + visible="{ITitleBarModel(model).showCloseButton}"/> + +</js:MXMLBeadViewBase> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/7853ef15/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/UpArrowButtonView.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/UpArrowButtonView.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/UpArrowButtonView.as new file mode 100644 index 0000000..8e6ff4a --- /dev/null +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/UpArrowButtonView.as @@ -0,0 +1,112 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You 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. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.html.beads +{ + import flash.display.DisplayObject; + import flash.display.Graphics; + import flash.display.Shape; + import flash.display.SimpleButton; + + import org.apache.flex.core.BeadViewBase; + import org.apache.flex.core.IBeadView; + import org.apache.flex.core.IStrand; + import org.apache.flex.events.Event; + + /** + * The UpArrowButtonView class is the view for + * the up arrow button in a ScrollBar and other controls. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class UpArrowButtonView extends BeadViewBase implements IBeadView + { + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function UpArrowButtonView() + { + upView = new Shape(); + downView = new Shape(); + overView = new Shape(); + + drawView(upView.graphics, 0xf8f8f8); + drawView(downView.graphics, 0xd8d8d8); + drawView(overView.graphics, 0xe8e8e8); + } + + private function drawView(g:Graphics, bgColor:uint):void + { + g.lineStyle(1); + g.beginFill(bgColor); + g.drawRoundRect(0, 0, ScrollBarView.FullSize, ScrollBarView.FullSize, ScrollBarView.ThirdSize); + g.endFill(); + g.lineStyle(0); + g.beginFill(0); + g.moveTo(ScrollBarView.QuarterSize, ScrollBarView.ThreeQuarterSize); + g.lineTo(ScrollBarView.ThreeQuarterSize, ScrollBarView.ThreeQuarterSize); + g.lineTo(ScrollBarView.HalfSize, ScrollBarView.QuarterSize); + g.lineTo(ScrollBarView.QuarterSize, ScrollBarView.ThreeQuarterSize); + g.endFill(); + } + + private var shape:Shape; + + /** + * @copy org.apache.flex.core.IBead#strand + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + override public function set strand(value:IStrand):void + { + super.strand = value; + shape = new Shape(); + shape.graphics.beginFill(0xCCCCCC); + shape.graphics.drawRect(0, 0, ScrollBarView.FullSize, ScrollBarView.FullSize); + shape.graphics.endFill(); + SimpleButton(value).upState = upView; + SimpleButton(value).downState = downView; + SimpleButton(value).overState = overView; + SimpleButton(value).hitTestState = shape; + + SimpleButton(_strand).addEventListener("widthChanged",sizeChangeHandler); + SimpleButton(_strand).addEventListener("heightChanged",sizeChangeHandler); + } + + private var upView:Shape; + private var downView:Shape; + private var overView:Shape; + + private function sizeChangeHandler(event:Event):void + { + SimpleButton(_strand).scaleX = SimpleButton(_strand).width / ScrollBarView.FullSize; + SimpleButton(_strand).scaleY = SimpleButton(_strand).height / ScrollBarView.FullSize; + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/7853ef15/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/VRuleView.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/VRuleView.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/VRuleView.as new file mode 100644 index 0000000..5eb6c4c --- /dev/null +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/VRuleView.as @@ -0,0 +1,87 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You 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. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.html.beads +{ + import flash.display.Bitmap; + import flash.display.Loader; + import flash.display.LoaderInfo; + import flash.net.URLRequest; + + import org.apache.flex.core.BeadViewBase; + import org.apache.flex.core.IBeadView; + import org.apache.flex.core.IImageModel; + import org.apache.flex.core.IStrand; + import org.apache.flex.core.UIBase; + import org.apache.flex.events.Event; + import org.apache.flex.events.IEventDispatcher; + + /** + * The ImageView class creates the visual elements of the org.apache.flex.html.Image component. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class VRuleView extends BeadViewBase implements IBeadView + { + /** + * constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function VRuleView() + { + } + + /** + * @copy org.apache.flex.core.IBead#strand + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + override public function set strand(value:IStrand):void + { + super.strand = value; + + IEventDispatcher(_strand).addEventListener("widthChanged",handleSizeChange); + IEventDispatcher(_strand).addEventListener("heightChanged",handleSizeChange); + IEventDispatcher(_strand).addEventListener("sizeChanged",handleSizeChange); + + handleSizeChange(null); + } + + /** + * @private + */ + private function handleSizeChange(event:Object):void + { + var ui:UIBase = _strand as UIBase; + ui.graphics.clear(); + ui.graphics.beginFill(0); + ui.graphics.drawRect(0, 0, 1, ui.height); + ui.graphics.endFill(); + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/7853ef15/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/VScrollBarThumbView.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/VScrollBarThumbView.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/VScrollBarThumbView.as new file mode 100644 index 0000000..0f70b37 --- /dev/null +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/VScrollBarThumbView.as @@ -0,0 +1,119 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You 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. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.html.beads +{ + import flash.display.Graphics; + import flash.display.Shape; + import flash.display.SimpleButton; + import flash.display.DisplayObject; + + import org.apache.flex.core.BeadViewBase; + import org.apache.flex.core.IBeadView; + import org.apache.flex.core.IStrand; + import org.apache.flex.events.Event; + import org.apache.flex.events.IEventDispatcher; + + /** + * The VScrollBarThumbView class is the view for + * the thumb button in a Vertical ScrollBar. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class VScrollBarThumbView extends BeadViewBase implements IBeadView + { + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function VScrollBarThumbView() + { + } + + private function drawView(g:Graphics, bgColor:uint):void + { + var hh:Number = DisplayObject(_strand).height; + g.clear(); + g.lineStyle(1); + g.beginFill(bgColor); + g.drawRoundRect(0, 0, ScrollBarView.FullSize, hh, ScrollBarView.HalfSize); + g.endFill(); + } + + private var shape:Shape; + + /** + * @copy org.apache.flex.core.IBead#strand + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + override public function set strand(value:IStrand):void + { + super.strand = value; + + upView = new Shape(); + downView = new Shape(); + overView = new Shape(); + + drawView(upView.graphics, 0xc8c8c8); + drawView(downView.graphics, 0xc8c8c8); + drawView(overView.graphics, 0xb8b8b8); + + shape = new Shape(); + shape.graphics.beginFill(0xCCCCCC); + shape.graphics.drawRect(0, 0, ScrollBarView.FullSize, ScrollBarView.FullSize); + shape.graphics.endFill(); + SimpleButton(value).upState = upView; + SimpleButton(value).downState = downView; + SimpleButton(value).overState = overView; + SimpleButton(value).hitTestState = shape; + IEventDispatcher(_strand).addEventListener("heightChanged", heightChangedHandler); + } + + private function heightChangedHandler(event:Event):void + { + DisplayObject(_strand).scaleY = 1.0; + DisplayObject(_strand).scaleX = 1.0; + + var hh:Number = DisplayObject(_strand).height; + drawView(upView.graphics, 0xc8c8c8); + drawView(downView.graphics, 0xc8c8c8); + drawView(overView.graphics, 0xb8b8b8); + + shape.graphics.clear(); + shape.graphics.beginFill(0xCCCCCC); + shape.graphics.drawRect(0, 0, ScrollBarView.FullSize, hh); + shape.graphics.endFill(); + } + + private var upView:Shape; + private var downView:Shape; + private var overView:Shape; + + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/7853ef15/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/VScrollBarTrackView.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/VScrollBarTrackView.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/VScrollBarTrackView.as new file mode 100644 index 0000000..3510251 --- /dev/null +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/VScrollBarTrackView.as @@ -0,0 +1,118 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You 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. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.html.beads +{ + import flash.display.DisplayObject; + import flash.display.Graphics; + import flash.display.Shape; + import flash.display.SimpleButton; + + import org.apache.flex.core.BeadViewBase; + import org.apache.flex.core.IBeadView; + import org.apache.flex.core.IStrand; + import org.apache.flex.events.Event; + + /** + * The VScrollBarTrackView class is the view for + * the track in a Vertical ScrollBar. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class VScrollBarTrackView extends BeadViewBase implements IBeadView + { + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function VScrollBarTrackView() + { + } + + private function drawView(g:Graphics, bgColor:uint):void + { + var h:Number = SimpleButton(_strand).height; + + g.clear(); + g.lineStyle(1, 0x808080); + g.beginFill(bgColor); + g.drawRect(0, 0, ScrollBarView.FullSize, h); + g.endFill(); + g.lineStyle(0); + } + + private function heightChangeHandler(event:Event):void + { + DisplayObject(_strand).scaleY = 1.0; + DisplayObject(_strand).scaleX = 1.0; + + var h:Number = SimpleButton(_strand).height; + + drawView(upView.graphics, 0xf8f8f8); + drawView(downView.graphics, 0xd8d8d8); + drawView(overView.graphics, 0xe8e8e8); + shape.graphics.clear(); + shape.graphics.beginFill(0xCCCCCC); + shape.graphics.drawRect(0, 0, ScrollBarView.FullSize, h); + shape.graphics.endFill(); + + } + + private var shape:Shape; + + /** + * @copy org.apache.flex.core.IBead#strand + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + override public function set strand(value:IStrand):void + { + super.strand = value; + + upView = new Shape(); + downView = new Shape(); + overView = new Shape(); + + drawView(upView.graphics, 0xf8f8f8); + drawView(downView.graphics, 0xd8d8d8); + drawView(overView.graphics, 0xe8e8e8); + + SimpleButton(value).addEventListener("heightChanged", heightChangeHandler); + shape = new Shape(); + SimpleButton(value).upState = upView; + SimpleButton(value).downState = downView; + SimpleButton(value).overState = overView; + SimpleButton(value).hitTestState = shape; + } + + private var upView:Shape; + private var downView:Shape; + private var overView:Shape; + + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/7853ef15/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/VScrollBarView.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/VScrollBarView.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/VScrollBarView.as new file mode 100644 index 0000000..840f7bf --- /dev/null +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/VScrollBarView.as @@ -0,0 +1,99 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You 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. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.html.beads +{ + import flash.display.DisplayObject; + + import org.apache.flex.core.IBead; + import org.apache.flex.core.IBeadLayout; + import org.apache.flex.core.IBeadView; + import org.apache.flex.core.IScrollBarModel; + import org.apache.flex.core.IStrand; + import org.apache.flex.core.IUIBase; + import org.apache.flex.core.Strand; + import org.apache.flex.core.UIBase; + import org.apache.flex.core.ValuesManager; + import org.apache.flex.events.IEventDispatcher; + import org.apache.flex.events.Event; + import org.apache.flex.html.Button; + import org.apache.flex.html.beads.controllers.ButtonAutoRepeatController; + + /** + * The ScrollBarView class is the default view for + * the org.apache.flex.html.supportClasses.VScrollBar class. + * It implements the classic desktop-like VScrollBar. + * A different view would implement more modern scrollbars that hide themselves + * until hovered over with the mouse. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class VScrollBarView extends ScrollBarView implements IBeadView, IStrand, IScrollBarView + { + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function VScrollBarView() + { + } + + /** + * @copy org.apache.flex.core.IBead#strand + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + override public function set strand(value:IStrand):void + { + super.strand = value; + + UIBase(value).setWidth(ScrollBarView.FullSize, true); + + // TODO: (aharui) put in values impl + _increment = new Button(); + Button(_increment).addBead(new DownArrowButtonView()); + Button(_increment).addBead(new ButtonAutoRepeatController()); + _decrement = new Button(); + Button(_decrement).addBead(new UpArrowButtonView()); + Button(_decrement).addBead(new ButtonAutoRepeatController()); + _track = new Button(); + Button(_track).addBead(new VScrollBarTrackView()); + _thumb = new Button(); + Button(_thumb).addBead(new VScrollBarThumbView()); + + UIBase(value).addChild(_decrement); + UIBase(value).addChild(_increment); + UIBase(value).addChild(_track); + UIBase(value).addChild(_thumb); + + IEventDispatcher(_strand).addEventListener("heightChanged", changeHandler); + + layout.layout(); + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/7853ef15/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/AlertController.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/AlertController.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/AlertController.as new file mode 100644 index 0000000..3982d0f --- /dev/null +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/AlertController.as @@ -0,0 +1,88 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You 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. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.html.beads.controllers +{ + import flash.display.DisplayObject; + + import org.apache.flex.core.IBeadController; + import org.apache.flex.core.IStrand; + import org.apache.flex.events.Event; + import org.apache.flex.events.IEventDispatcher; + + /** + * The AlertControler class bead handles the close event on the org.apache.flex.html.Alert + * by removing the org.apache.flex.html.Alert from the display. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class AlertController implements IBeadController + { + /** + * constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function AlertController() + { + } + + private var _strand:IStrand; + + /** + * @copy org.apache.flex.core.IBead#strand + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get strand():IStrand + { + return _strand; + } + + /** + * @copy org.apache.flex.core.IBead#strand + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function set strand(value:IStrand):void + { + _strand = value; + IEventDispatcher(value).addEventListener("close",handleAlertClose); + } + + /** + * @private + */ + private function handleAlertClose(event:Event):void + { + DisplayObject(_strand).parent.removeChild(DisplayObject(_strand)); + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/7853ef15/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/ButtonAutoRepeatController.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/ButtonAutoRepeatController.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/ButtonAutoRepeatController.as new file mode 100644 index 0000000..4100a28 --- /dev/null +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/ButtonAutoRepeatController.as @@ -0,0 +1,147 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You 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. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.html.beads.controllers +{ + import flash.utils.clearInterval; + import flash.utils.clearTimeout; + import flash.utils.setInterval; + import flash.utils.setTimeout; + + import org.apache.flex.core.IBead; + import org.apache.flex.core.IBeadController; + import org.apache.flex.core.IStrand; + import org.apache.flex.events.Event; + import org.apache.flex.events.MouseEvent; + import org.apache.flex.events.IEventDispatcher; + + /** + * The ButtonAutoRepeatController class adds autorepeat + * functionality to a button. This version is simply waits + * a specified amount of time (default is 250ms), then repeats the button + * event at a specified interval, which defaults to + * 125 milliseconds. Alternate implementations could + * have non-linear repeat timing, look for keyboard modifiers to choose + * different rates, etc. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class ButtonAutoRepeatController implements IBead, IBeadController + { + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function ButtonAutoRepeatController() + { + } + + private var _strand:IStrand; + + /** + * @copy org.apache.flex.core.IBead#strand + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function set strand(value:IStrand):void + { + _strand = value; + IEventDispatcher(value).addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler); + } + + /** + * The number of milliseconds to wait before repeating the event + * for the first time. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public var delay:int = 250; + + /** + * The number of milliseconds to wait before repeating the event + * after the first time. This value is not checked for + * changes after the events start repeating. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public var interval:int = 100; + + private var timeout:uint; + private var repeater:uint; + + private function mouseDownHandler(event:MouseEvent):void + { + event.target.addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler); + event.target.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler); + timeout = setTimeout(sendFirstRepeat, delay); + } + + private function mouseOutHandler(event:MouseEvent):void + { + event.target.removeEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler); + event.target.removeEventListener(MouseEvent.MOUSE_UP, mouseUpHandler); + if (repeater > 0) + clearInterval(repeater); + repeater = 0; + if (timeout > 0) + clearTimeout(timeout); + timeout = 0; + } + + private function mouseUpHandler(event:MouseEvent):void + { + event.target.removeEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler); + event.target.removeEventListener(MouseEvent.MOUSE_UP, mouseUpHandler); + if (repeater > 0) + clearInterval(repeater); + repeater = 0; + if (timeout > 0) + clearTimeout(timeout); + timeout = 0; + } + + private function sendFirstRepeat():void + { + clearTimeout(timeout); + timeout = 0; + repeater = setInterval(sendRepeats, interval); + IEventDispatcher(_strand).dispatchEvent(new Event("buttonRepeat")); + } + + private function sendRepeats():void + { + IEventDispatcher(_strand).dispatchEvent(new Event("buttonRepeat")); + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/7853ef15/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/ComboBoxController.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/ComboBoxController.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/ComboBoxController.as new file mode 100644 index 0000000..12fb59c --- /dev/null +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/ComboBoxController.as @@ -0,0 +1,104 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You 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. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.html.beads.controllers +{ + import flash.display.DisplayObject; + + import org.apache.flex.core.IBeadController; + import org.apache.flex.core.ISelectionModel; + import org.apache.flex.core.IStrand; + import org.apache.flex.events.Event; + import org.apache.flex.events.IEventDispatcher; + import org.apache.flex.events.MouseEvent; + import org.apache.flex.html.beads.IComboBoxView; + + /** + * The ComboBoxController class bead handles mouse events on the elements of + * the org.apache.flex.html.ComboBox. This includes selecting the + * button to display the selection list pop-up as well as selecting an item from the + * pop-up list. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class ComboBoxController implements IBeadController + { + /** + * constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function ComboBoxController() + { + } + + private var _strand:IStrand; + + /** + * @copy org.apache.flex.core.IBead#strand + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function set strand(value:IStrand):void + { + _strand = value; + IEventDispatcher(value).addEventListener(MouseEvent.CLICK, clickHandler); + } + + /** + * @private + */ + private function clickHandler(event:MouseEvent):void + { + var viewBead:IComboBoxView = _strand.getBeadByType(IComboBoxView) as IComboBoxView; + viewBead.popUpVisible = true; + var selectionModel:ISelectionModel = _strand.getBeadByType(ISelectionModel) as ISelectionModel; + var popUpModel:ISelectionModel = viewBead.popUp.getBeadByType(ISelectionModel) as ISelectionModel; + popUpModel.dataProvider = selectionModel.dataProvider; + popUpModel.selectedIndex = selectionModel.selectedIndex; + DisplayObject(viewBead.popUp).width = DisplayObject(_strand).width; + DisplayObject(viewBead.popUp).height = 200; + DisplayObject(viewBead.popUp).x = DisplayObject(_strand).x; + DisplayObject(viewBead.popUp).y = DisplayObject(_strand).y; + IEventDispatcher(viewBead.popUp).addEventListener("change", changeHandler); + } + + /** + * @private + */ + private function changeHandler(event:Event):void + { + var viewBead:IComboBoxView = _strand.getBeadByType(IComboBoxView) as IComboBoxView; + viewBead.popUpVisible = false; + var selectionModel:ISelectionModel = _strand.getBeadByType(ISelectionModel) as ISelectionModel; + var popUpModel:ISelectionModel = viewBead.popUp.getBeadByType(ISelectionModel) as ISelectionModel; + selectionModel.selectedIndex = popUpModel.selectedIndex; + IEventDispatcher(_strand).dispatchEvent(new Event("change")); + } + + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/7853ef15/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/DateChooserMouseController.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/DateChooserMouseController.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/DateChooserMouseController.as new file mode 100644 index 0000000..0aaa052 --- /dev/null +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/DateChooserMouseController.as @@ -0,0 +1,126 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You 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. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.html.beads.controllers +{ + import org.apache.flex.html.beads.DateChooserView; + import org.apache.flex.html.beads.models.DateChooserModel; + import org.apache.flex.html.supportClasses.DateChooserButton; + + import org.apache.flex.core.IBeadController; + import org.apache.flex.core.IBeadModel; + import org.apache.flex.core.IBeadView; + import org.apache.flex.core.IStrand; + import org.apache.flex.events.Event; + import org.apache.flex.events.IEventDispatcher; + + /** + * The DateChooserMouseController class is responsible for listening to + * mouse event related to the DateChooser. Events such as selecting a date + * or changing the calendar. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class DateChooserMouseController implements IBeadController + { + /** + * constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function DateChooserMouseController() + { + } + + private var _strand:IStrand; + + /** + * @copy org.apache.flex.core.IBead#strand + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function set strand(value:IStrand):void + { + _strand = value; + + var view:DateChooserView = value.getBeadByType(IBeadView) as DateChooserView; + view.prevMonthButton.addEventListener("click", prevMonthClickHandler); + view.nextMonthButton.addEventListener("click", nextMonthClickHandler); + + var dayButtons:Array = view.dayButtons; + for(var i:int=0; i < dayButtons.length; i++) { + IEventDispatcher(dayButtons[i]).addEventListener("click", dayButtonClickHandler); + } + } + + /** + * @private + */ + private function prevMonthClickHandler(event:Event):void + { + var model:DateChooserModel = _strand.getBeadByType(IBeadModel) as DateChooserModel; + var month:Number = model.displayedMonth - 1; + var year:Number = model.displayedYear; + if (month < 0) { + month = 11; + year--; + } + model.displayedMonth = month; + model.displayedYear = year; + } + + /** + * @private + */ + private function nextMonthClickHandler(event:Event):void + { + var model:DateChooserModel = _strand.getBeadByType(IBeadModel) as DateChooserModel; + var month:Number = model.displayedMonth + 1; + var year:Number = model.displayedYear; + if (month >= 12) { + month = 0; + year++; + } + model.displayedMonth = month; + model.displayedYear = year; + } + + /** + * @private + */ + private function dayButtonClickHandler(event:Event):void + { + var dateButton:DateChooserButton = event.target as DateChooserButton; + if (dateButton.dayOfMonth > 0) { + var model:DateChooserModel = _strand.getBeadByType(IBeadModel) as DateChooserModel; + var newDate:Date = new Date(model.displayedYear,model.displayedMonth,dateButton.dayOfMonth); + model.selectedDate = newDate; + IEventDispatcher(_strand).dispatchEvent( new Event("change") ); + } + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/7853ef15/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/DateFieldMouseController.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/DateFieldMouseController.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/DateFieldMouseController.as new file mode 100644 index 0000000..05b852d --- /dev/null +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/DateFieldMouseController.as @@ -0,0 +1,95 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You 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. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.html.beads.controllers +{ + import org.apache.flex.core.IBeadController; + import org.apache.flex.core.IDateChooserModel; + import org.apache.flex.core.IStrand; + import org.apache.flex.core.UIBase; + import org.apache.flex.events.Event; + import org.apache.flex.events.IEventDispatcher; + import org.apache.flex.html.beads.DateFieldView; + + /** + * The DateFieldMouseController class is responsible for monitoring + * the mouse events on the elements of the DateField. A click on the + * DateField's menu button triggers the pop-up, for example. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class DateFieldMouseController implements IBeadController + { + /** + * constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function DateFieldMouseController() + { + } + + private var _strand:IStrand; + + /** + * @copy org.apache.flex.core.IBead#strand + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function set strand(value:IStrand):void + { + _strand = value; + + var viewBead:DateFieldView = _strand.getBeadByType(DateFieldView) as DateFieldView; + IEventDispatcher(viewBead.menuButton).addEventListener("click", clickHandler); + } + + /** + * @private + */ + private function clickHandler(event:Event):void + { + var viewBead:DateFieldView = _strand.getBeadByType(DateFieldView) as DateFieldView; + viewBead.popUpVisible = true; + IEventDispatcher(viewBead.popUp).addEventListener("change", changeHandler); + } + + /** + * @private + */ + private function changeHandler(event:Event):void + { + var viewBead:DateFieldView = _strand.getBeadByType(DateFieldView) as DateFieldView; + + var model:IDateChooserModel = _strand.getBeadByType(IDateChooserModel) as IDateChooserModel; + model.selectedDate = IDateChooserModel(viewBead.popUp.getBeadByType(IDateChooserModel)).selectedDate; + + viewBead.popUpVisible = false; + IEventDispatcher(_strand).dispatchEvent(new Event("change")); + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/7853ef15/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/DropDownListController.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/DropDownListController.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/DropDownListController.as new file mode 100644 index 0000000..29f58e1 --- /dev/null +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/DropDownListController.as @@ -0,0 +1,116 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You 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. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.html.beads.controllers +{ + import flash.display.DisplayObject; + import flash.geom.Point; + + import org.apache.flex.core.IBead; + import org.apache.flex.core.IBeadController; + import org.apache.flex.core.ISelectionModel; + import org.apache.flex.core.IStrand; + import org.apache.flex.core.IUIBase; + import org.apache.flex.core.UIBase; + import org.apache.flex.events.Event; + import org.apache.flex.events.IEventDispatcher; + import org.apache.flex.html.beads.IDropDownListView; + + /** + * The DropDownListController class is the controller for + * org.apache.flex.html.DropDownList. Controllers + * watch for events from the interactive portions of a View and + * update the data model or dispatch a semantic event. + * This controller watches for the click event and displays the + * dropdown/popup, and watches the dropdown/popup for change events + * and updates the selection model accordingly. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class DropDownListController implements IBead, IBeadController + { + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function DropDownListController() + { + } + + private var _strand:IStrand; + + /** + * @copy org.apache.flex.core.IBead#strand + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function set strand(value:IStrand):void + { + _strand = value; + IEventDispatcher(value).addEventListener("click", clickHandler); + } + + private function clickHandler(event:Event):void + { + var viewBead:IDropDownListView = _strand.getBeadByType(IDropDownListView) as IDropDownListView; + var selectionModel:ISelectionModel = _strand.getBeadByType(ISelectionModel) as ISelectionModel; + var popUpModel:ISelectionModel = UIBase(viewBead.popUp).model as ISelectionModel; + DisplayObject(viewBead.popUp).width = DisplayObject(_strand).width; + popUpModel.dataProvider = selectionModel.dataProvider; + popUpModel.labelField = selectionModel.labelField; + viewBead.popUpVisible = true; // adds to display list as well + popUpModel.selectedIndex = selectionModel.selectedIndex; + var pt:Point = new Point(DisplayObject(_strand).x, DisplayObject(_strand).y + DisplayObject(_strand).height); + pt = DisplayObject(_strand).parent.localToGlobal(pt); + DisplayObject(viewBead.popUp).x = pt.x; + DisplayObject(viewBead.popUp).y = pt.y; + IEventDispatcher(viewBead.popUp).addEventListener("change", changeHandler); + IUIBase(_strand).topMostEventDispatcher.addEventListener("click", dismissHandler); + } + + private function dismissHandler(event:Event):void + { + if (event.target == _strand) return; + + IUIBase(_strand).topMostEventDispatcher.removeEventListener("click", dismissHandler); + var viewBead:IDropDownListView = _strand.getBeadByType(IDropDownListView) as IDropDownListView; + viewBead.popUpVisible = false; + } + + private function changeHandler(event:Event):void + { + var viewBead:IDropDownListView = _strand.getBeadByType(IDropDownListView) as IDropDownListView; + viewBead.popUpVisible = false; + var selectionModel:ISelectionModel = _strand.getBeadByType(ISelectionModel) as ISelectionModel; + var popUpModel:ISelectionModel = UIBase(viewBead.popUp).model as ISelectionModel; + selectionModel.selectedIndex = popUpModel.selectedIndex; + IEventDispatcher(_strand).dispatchEvent(new Event("change")); + } + + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/7853ef15/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/EditableTextKeyboardController.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/EditableTextKeyboardController.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/EditableTextKeyboardController.as new file mode 100644 index 0000000..4a8115f --- /dev/null +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/EditableTextKeyboardController.as @@ -0,0 +1,86 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You 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. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.html.beads.controllers +{ + import org.apache.flex.core.CSSTextField; + import org.apache.flex.core.IBead; + import org.apache.flex.core.IBeadController; + import org.apache.flex.core.IStrand; + import org.apache.flex.core.ITextModel; + import org.apache.flex.core.UIBase; + import org.apache.flex.html.beads.ITextFieldView; + + /** + * The EditableTextKeyboardController class bead intercepts keyboard events on the + * component's text field and emits change events. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class EditableTextKeyboardController implements IBead, IBeadController + { + /** + * constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function EditableTextKeyboardController() + { + } + + private var model:ITextModel; + private var textField:CSSTextField; + + private var _strand:IStrand; + + /** + * @copy org.apache.flex.core.IBead#strand + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function set strand(value:IStrand):void + { + _strand = value; + + model = UIBase(_strand).model as ITextModel; + + var viewBead:ITextFieldView = _strand.getBeadByType(ITextFieldView) as ITextFieldView; + textField = viewBead.textField; + textField.addEventListener("change", inputChangeHandler); + } + + /** + * @private + */ + private function inputChangeHandler( event:Object ) : void + { + // this will otherwise bubble an event of flash.events.Event + event.stopImmediatePropagation(); + model.text = textField.text; + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/7853ef15/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/HScrollBarMouseController.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/HScrollBarMouseController.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/HScrollBarMouseController.as new file mode 100644 index 0000000..4abaffe --- /dev/null +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/HScrollBarMouseController.as @@ -0,0 +1,101 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You 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. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.html.beads.controllers +{ + import flash.display.DisplayObject; + + import org.apache.flex.events.Event; + import org.apache.flex.events.MouseEvent; + import org.apache.flex.events.IEventDispatcher; + + /** + * The HScrollBarMouseController class is the controller for + * org.apache.flex.html.supportClasses.HScrollBar + * that acts as the Horizontal ScrollBar. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class HScrollBarMouseController extends ScrollBarMouseControllerBase + { + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function HScrollBarMouseController() + { + } + + /** + * @private + */ + override protected function trackClickHandler(event:MouseEvent):void + { + if (sbView.thumb.visible) + { + if (event.localX < sbView.thumb.x) + { + sbModel.value = snap(Math.max(sbModel.minimum, sbModel.value - sbModel.pageStepSize)); + IEventDispatcher(strand).dispatchEvent(new Event("scroll")); + } + else + { + sbModel.value = snap(Math.min(sbModel.maximum - sbModel.pageSize, sbModel.value + sbModel.pageStepSize)); + IEventDispatcher(strand).dispatchEvent(new Event("scroll")); + } + } + } + + private var thumbDownX:Number; + private var lastThumbX:Number; + + /** + * @private + */ + override protected function thumbMouseDownHandler(event:MouseEvent):void + { + sbView.thumb.stage.addEventListener(MouseEvent.MOUSE_MOVE, thumbMouseMoveHandler); + sbView.thumb.stage.addEventListener(MouseEvent.MOUSE_UP, thumbMouseUpHandler); + thumbDownX = event.screenX; + lastThumbX = sbView.thumb.x; + } + + private function thumbMouseMoveHandler(event:MouseEvent):void + { + var thumb:DisplayObject = sbView.thumb; + var track:DisplayObject = sbView.track; + thumb.x = Math.max(track.x, Math.min(lastThumbX + (event.screenX - thumbDownX), track.x + track.width - thumb.width)); + var newValue:Number = snap((thumb.x - track.x) / (track.width - thumb.width) * (sbModel.maximum - sbModel.minimum - sbModel.pageSize)); + sbModel.value = newValue; + IEventDispatcher(strand).dispatchEvent(new Event("scroll")); + } + + private function thumbMouseUpHandler(event:MouseEvent):void + { + sbView.thumb.stage.removeEventListener(MouseEvent.MOUSE_MOVE, thumbMouseMoveHandler); + sbView.thumb.stage.removeEventListener(MouseEvent.MOUSE_UP, thumbMouseUpHandler); + } + } +}