http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/d8221452/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/ToggleTextButton.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/ToggleTextButton.as b/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/ToggleTextButton.as new file mode 100644 index 0000000..be86d41 --- /dev/null +++ b/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/ToggleTextButton.as @@ -0,0 +1,170 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 +{ + import org.apache.flex.core.IStrand; + import org.apache.flex.core.IToggleButtonModel; + import org.apache.flex.core.IUIBase; + import org.apache.flex.core.ValuesManager; + import org.apache.flex.events.IEventDispatcher; + + COMPILE::JS + { + import org.apache.flex.core.WrappedHTMLElement; + } + + //-------------------------------------- + // Events + //-------------------------------------- + + /** + * Dispatched when the user clicks on a button. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + [Event(name="click", type="org.apache.flex.events.MouseEvent")] + + /** + * The ToggleButton class is a TextButton that supports + * a selected property. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class ToggleTextButton extends TextButton implements IStrand, IEventDispatcher, IUIBase + { + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function ToggleTextButton() + { + super(); + COMPILE::JS + { + this.typeNames = 'toggleTextButton'; + } + } + + COMPILE::JS + private var _selected:Boolean; + + COMPILE::JS + private var SELECTED:String = "selected"; + + /** + * <code>true</code> if the Button is selected. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get selected():Boolean + { + COMPILE::SWF + { + return IToggleButtonModel(model).selected; + } + COMPILE::JS + { + return _selected; + } + } + + /** + * @private + */ + public function set selected(value:Boolean):void + { + COMPILE::SWF + { + IToggleButtonModel(model).selected = value; + } + COMPILE::JS + { + if (_selected != value) + { + _selected = value; + + var className:String = this.className; + var typeNames:String = this.typeNames; + if (value) { + if (typeNames.indexOf(SELECTED) == -1) { + typeNames = typeNames + SELECTED; + if (className) + element.className = typeNames + ' ' + className; + else + element.className = typeNames; + } + } + else { + if (typeNames.indexOf(SELECTED) == typeNames.length - SELECTED.length) { + typeNames = typeNames.substring(0, typeNames.length - SELECTED.length); + if (className) + element.className = typeNames + ' ' + className; + else + element.className = typeNames; + } + } + } + } + } + + /** + * @private + * add another class selector + */ + override public function get className():String + { + // we don't have a model yet so just pass through otherwise you will loop + if (!parent) + return super.className; + + var name:String = super.className; + if (selected) + return "toggleTextButton_Selected" + (name ? " " + name : ""); + else + return "toggleTextButton" + (name ? " " + name : ""); + } + + COMPILE::JS + override protected function createElement():WrappedHTMLElement + { + super.createElement(); + element.addEventListener("click", clickHandler, false); + return element; + } + + COMPILE::JS + private function clickHandler(event:Event):void + { + selected = !selected; + } + } +}
http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/d8221452/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/ToolTip.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/ToolTip.as b/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/ToolTip.as new file mode 100644 index 0000000..4093b09 --- /dev/null +++ b/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/ToolTip.as @@ -0,0 +1,60 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 +{ + import org.apache.flex.core.ITextModel; + import org.apache.flex.core.UIBase; + import org.apache.flex.core.ValuesManager; + import org.apache.flex.events.Event; + import org.apache.flex.events.IEventDispatcher; + + /* + * Label probably should extend TextField directly, + * but the player's APIs for TextLine do not allow + * direct instantiation, and we might want to allow + * Labels to be declared and have their actual + * view be swapped out. + */ + + /** + * The Label class implements the basic control for labeling + * other controls. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class ToolTip extends Label + { + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function ToolTip() + { + super(); + } + + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/d8221452/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/Tree.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/Tree.as b/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/Tree.as new file mode 100644 index 0000000..c23e7f9 --- /dev/null +++ b/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/Tree.as @@ -0,0 +1,73 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 +{ + import org.apache.flex.collections.FlattenedList; + import org.apache.flex.collections.HierarchicalData; + + /** + * The Tree component displays structured data. The Tree uses a HierarchicalData + * object as its data provider. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class Tree extends List + { + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function Tree() + { + super(); + } + + private var _hierarchicalData:HierarchicalData; + private var _flatList:FlattenedList; + + /** + * The dataProvider should be of type HierarchicalData. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + * @see org.apache.flex.collections.HierarchicalData. + */ + override public function get dataProvider():Object + { + return _hierarchicalData; + } + override public function set dataProvider(value:Object):void + { + _hierarchicalData = value as HierarchicalData; + + _flatList = new FlattenedList(_hierarchicalData); + + super.dataProvider = _flatList; + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/d8221452/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/VContainer.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/VContainer.as b/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/VContainer.as new file mode 100644 index 0000000..92ebdca --- /dev/null +++ b/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/VContainer.as @@ -0,0 +1,62 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 +{ + import org.apache.flex.core.ContainerBase; + import org.apache.flex.core.IChrome; + import org.apache.flex.core.IContainer; + import org.apache.flex.core.IUIBase; + import org.apache.flex.events.Event; + + [DefaultProperty("mxmlContent")] + + /** + * A Container that has a VerticalLayout. + * + * This is effectively the same as the pattern + * <code> + * <basic:Container xmlns:basic="library://ns.apache.org/flexjs/basic"> + * <basic:layout> + * <basic:VerticalLayout /> + * </basic:layout> + * </basic:Container> + * </code> + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class VContainer extends Container implements IContainer + { + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function VContainer() + { + super(); + } + + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/d8221452/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/VRule.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/VRule.as b/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/VRule.as new file mode 100644 index 0000000..d727f2a --- /dev/null +++ b/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/VRule.as @@ -0,0 +1,68 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 +{ + import org.apache.flex.core.UIBase; + COMPILE::JS + { + import org.apache.flex.core.WrappedHTMLElement; + } + + /** + * The VRule class displays a vertical line + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class VRule extends UIBase + { + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function VRule() + { + super(); + } + + /** + * @flexjsignorecoercion org.apache.flex.core.WrappedHTMLElement + */ + COMPILE::JS + override protected function createElement():WrappedHTMLElement + { + element = document.createElement('div') as WrappedHTMLElement; + element.style.borderLeftStyle = 'solid'; + element.style.borderLeftWidth = '1px'; + element.style.borderTop = 'none'; + element.style.borderBottom = 'none'; + element.style.borderRight = 'none'; + positioner = element; + positioner.style.position = 'relative'; + element.flexjs_wrapper = this; + return element; + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/d8221452/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/WebBrowser.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/WebBrowser.as b/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/WebBrowser.as new file mode 100644 index 0000000..7027359 --- /dev/null +++ b/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/WebBrowser.as @@ -0,0 +1,145 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 +{ + COMPILE::SWF { + import flash.events.Event; + import flash.html.HTMLLoader; + import flash.net.URLRequest; + + import org.apache.flex.events.utils.IHandlesOriginalEvent; + } + COMPILE::JS + { + import org.apache.flex.core.WrappedHTMLElement; + } + + import org.apache.flex.core.UIBase + import org.apache.flex.html.beads.models.WebBrowserModel; + + /** + * Dispatched whenever the WebBrowser's location has been changed. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + [Event(name="locationChanged", type="org.apache.flex.events.Event")] + + /** + * The WebBrowser provides a space in which to display a web page within + * a FlexJS application. Use the url property to change the location of + * the web page being displayed. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + COMPILE::SWF + public class WebBrowser extends UIBase implements IHandlesOriginalEvent + { + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function WebBrowser() + { + super(); + } + + /** + * The location of the web page to display. Security restrictions may + * apply. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get url():String + { + return (model as WebBrowserModel).url; + } + + public function set url(value:String):void + { + (model as WebBrowserModel).url = value; + } + } + + COMPILE::JS + public class WebBrowser extends UIBase + { + /** + * Constructor + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function WebBrowser() + { + super(); + } + + /** + * @flexjsignorecoercion org.apache.flex.core.WrappedHTMLElement + */ + override protected function createElement():WrappedHTMLElement + { + element = document.createElement('iframe') as WrappedHTMLElement; + element.flexjs_wrapper = this; + + var iframe:HTMLIFrameElement = element as HTMLIFrameElement; + iframe.frameBorder = "0"; + iframe.src = "JavaScript:''"; + iframe.sandbox = "allow-top-navigation allow-forms allow-scripts"; + + positioner = element; + + return element; + } + + /** + * The location of the web page to display. Security restrictions may + * apply. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get url():String + { + return (model as WebBrowserModel).url; + } + + public function set url(value:String):void + { + (model as WebBrowserModel).url = value; + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/d8221452/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/accessories/NumericOnlyTextInputBead.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/accessories/NumericOnlyTextInputBead.as b/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/accessories/NumericOnlyTextInputBead.as new file mode 100644 index 0000000..3b23f5b --- /dev/null +++ b/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/accessories/NumericOnlyTextInputBead.as @@ -0,0 +1,199 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.accessories +{ + COMPILE::JS + { + import goog.events.BrowserEvent; + } + COMPILE::SWF + { + import flash.events.TextEvent; + + import org.apache.flex.core.CSSTextField; + } + import org.apache.flex.core.IBead; + import org.apache.flex.core.IStrand; + import org.apache.flex.events.Event; + import org.apache.flex.events.IEventDispatcher; + COMPILE::SWF + { + import org.apache.flex.html.beads.ITextFieldView; + } + + /** + * The NumericOnlyTextInputBead class is a specialty bead that can be used with + * any TextInput control. The bead prevents non-numeric entry into the text input + * area. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class NumericOnlyTextInputBead implements IBead + { + /** + * constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function NumericOnlyTextInputBead() + { + } + + 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; + + COMPILE::SWF + { + IEventDispatcher(value).addEventListener("viewChanged",viewChangeHandler); + } + COMPILE::JS + { + IEventDispatcher(value).addEventListener("keypress",validateInput); + } + } + + private var _decimalSeparator:String = "."; + + /** + * The character used to separate the integer and fraction parts of numbers. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get decimalSeparator():String + { + return _decimalSeparator; + } + public function set decimalSeparator(value:String):void + { + if (_decimalSeparator != value) { + _decimalSeparator = value; + } + } + + private var _maxChars:int = 0; + + /** + * The character used to separate the integer and fraction parts of numbers. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get maxChars():int + { + return _maxChars; + } + public function set maxChars(value:int):void + { + if (_maxChars != value) { + _maxChars = value; + } + } + + /** + * @private + */ + COMPILE::SWF + private function viewChangeHandler(event:Event):void + { + // get the ITextFieldView bead, which is required for this bead to work + var textView:ITextFieldView = _strand.getBeadByType(ITextFieldView) as ITextFieldView; + if (textView) { + var textField:CSSTextField = textView.textField; + textField.restrict = "0-9" + decimalSeparator; + textField.maxChars = maxChars; + // listen for changes to this textField and prevent non-numeric values, such + // as 34.09.94 + textField.addEventListener(TextEvent.TEXT_INPUT, handleTextInput); + } + else { + throw new Error("NumericOnlyTextInputBead requires strand to have an ITextFieldView bead"); + } + } + + /** + * @private + */ + COMPILE::SWF + private function handleTextInput(event:TextEvent):void + { + var insert:String = event.text; + var caretIndex:int = (event.target as CSSTextField).caretIndex; + var current:String = (event.target as CSSTextField).text; + var value:String = current.substring(0,caretIndex) + insert + current.substr(caretIndex); + var n:Number = Number(value); + if (isNaN(n)) event.preventDefault(); + } + + COMPILE::JS + private function validateInput(event:BrowserEvent):void + { + var code:int = event.charCode; + + // backspace or delete + if (event.keyCode == 8 || event.keyCode == 46) return; + + // tab or return/enter + if (event.keyCode == 9 || event.keyCode == 13) return; + + // left or right cursor arrow + if (event.keyCode == 37 || event.keyCode == 39) return; + + var key:String = String.fromCharCode(code); + + var regex:RegExp = /[0-9]|\./; + if (!regex.test(key)) { + event["returnValue"] = false; + if (event.preventDefault) event.preventDefault(); + return; + } + var cursorStart:int = event.target.selectionStart; + var cursorEnd:int = event.target.selectionEnd; + var left:String = event.target.value.substring(0, cursorStart); + var right:String = event.target.value.substr(cursorEnd); + var complete:String = left + key + right; + if (isNaN(parseFloat(complete))) { + event["returnValue"] = false; + if (event.preventDefault) event.preventDefault(); + } + + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/d8221452/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/accessories/PasswordInputBead.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/accessories/PasswordInputBead.as b/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/accessories/PasswordInputBead.as new file mode 100644 index 0000000..e73822b --- /dev/null +++ b/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/accessories/PasswordInputBead.as @@ -0,0 +1,102 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.accessories +{ + COMPILE::SWF + { + import org.apache.flex.core.CSSTextField; + } + import org.apache.flex.core.IBead; + import org.apache.flex.core.IStrand; + import org.apache.flex.core.UIBase; + import org.apache.flex.events.Event; + import org.apache.flex.events.IEventDispatcher; + COMPILE::SWF + { + import org.apache.flex.html.beads.ITextFieldView; + } + + /** + * The PasswordInput class is a specialty bead that can be used with + * any TextInput control. The bead secures the text input area by masking + * the input as it is typed. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class PasswordInputBead implements IBead + { + /** + * constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function PasswordInputBead() + { + } + + 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; + + COMPILE::SWF + { + IEventDispatcher(value).addEventListener("viewChanged",viewChangeHandler); + } + COMPILE::JS + { + var host:UIBase = value as UIBase; + var e:HTMLInputElement = host.element as HTMLInputElement; + e.type = 'password'; + } + } + + /** + * @private + */ + COMPILE::SWF + private function viewChangeHandler(event:Event):void + { + // get the ITextFieldView bead, which is required for this bead to work + var textView:ITextFieldView = _strand.getBeadByType(ITextFieldView) as ITextFieldView; + if (textView) { + var textField:CSSTextField = textView.textField; + textField.displayAsPassword = true; + } + else { + throw new Error("PasswordInputBead requires strand to have a TextInputView bead"); + } + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/d8221452/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/accessories/TextPromptBead.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/accessories/TextPromptBead.as b/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/accessories/TextPromptBead.as new file mode 100644 index 0000000..99e2866 --- /dev/null +++ b/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/accessories/TextPromptBead.as @@ -0,0 +1,148 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.accessories +{ + COMPILE::SWF + { + import flash.text.TextFieldType; + + import org.apache.flex.core.CSSTextField; + } + + import org.apache.flex.core.IBead; + 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 TextPromptBead class is a specialty bead that can be used with + * any TextInput control. The bead places a string into the input field + * when there is no value associated with the text property. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class TextPromptBead implements IBead + { + /** + * constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function TextPromptBead() + { + } + + private var _prompt:String; + + /** + * The string to use as the placeholder prompt. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get prompt():String + { + return _prompt; + } + public function set prompt(value:String):void + { + _prompt = value; + } + + 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 + * @flexjsignorecoercion HTMLInputElement + * @flexjsignorecoercion org.apache.flex.core.UIBase; + */ + public function set strand(value:IStrand):void + { + _strand = value; + + COMPILE::SWF + { + // listen for changes in text to hide or show the prompt + var model:Object = UIBase(_strand).model; + if (!model.hasOwnProperty("text")) { + throw new Error("Model requires a text property when used with TextPromptBead"); + } + IEventDispatcher(model).addEventListener("textChange", handleTextChange); + + // create a TextField that displays the prompt - it shows + // and hides based on the model's content + promptField = new CSSTextField(); + promptField.selectable = false; + promptField.type = TextFieldType.DYNAMIC; + promptField.mouseEnabled = false; + promptField.multiline = false; + promptField.wordWrap = false; + promptField.textColor = 0xBBBBBB; + + // trigger the event handler to display if needed + handleTextChange(null); + } + COMPILE::JS + { + var host:UIBase = value as UIBase; + var e:HTMLInputElement = host.element as HTMLInputElement; + e.placeholder = prompt; + } + } + + COMPILE::SWF + private var promptField:CSSTextField; + private var promptAdded:Boolean; + + /** + * @private + */ + COMPILE::SWF + private function handleTextChange( event:Event ):void + { + // see what the model currently has to determine if the prompt should be + // displayed or not. + var model:Object = UIBase(_strand).model; + + if (model.text != null && model.text.length > 0 ) { + if (promptAdded) UIBase(_strand).removeChild(promptField); + promptAdded = false; + } + else { + if (!promptAdded) UIBase(_strand).addChild(promptField); + promptField.text = prompt; + promptAdded = true; + } + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/d8221452/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/accessories/ToolTipBead.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/accessories/ToolTipBead.as b/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/accessories/ToolTipBead.as new file mode 100644 index 0000000..64d04bf --- /dev/null +++ b/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/accessories/ToolTipBead.as @@ -0,0 +1,141 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.accessories +{ + + import org.apache.flex.core.IBead; + import org.apache.flex.core.IPopUpHost; + 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.events.MouseEvent; + import org.apache.flex.events.utils.MouseUtils; + import org.apache.flex.geom.Point; + import org.apache.flex.html.ToolTip; + import org.apache.flex.utils.PointUtils; + import org.apache.flex.utils.UIUtils; + + /** + * The ToolTipBead class is a specialty bead that can be used with + * any control. The bead floats a string over a control if + * the user hovers over the control with a mouse. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class ToolTipBead implements IBead + { + /** + * constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function ToolTipBead() + { + } + + private var _toolTip:String; + + /** + * The string to use as the toolTip. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get toolTip():String + { + return _toolTip; + } + public function set toolTip(value:String):void + { + _toolTip = value; + } + + 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(_strand).addEventListener(MouseEvent.MOUSE_OVER, rollOverHandler, false); + } + + private var tt:ToolTip; + private var host:IPopUpHost; + + /** + * @private + */ + protected function rollOverHandler( event:MouseEvent ):void + { + IEventDispatcher(_strand).addEventListener(MouseEvent.MOUSE_OUT, rollOutHandler, false); + + var comp:IUIBase = _strand as IUIBase + host = UIUtils.findPopUpHost(comp); + if (tt) host.removeElement(tt); + + tt = new ToolTip(); + tt.text = toolTip; + var pt:Point = determinePosition(event, event.target); + tt.x = pt.x; + tt.y = pt.y; + host.addElement(tt, false); // don't trigger a layout + } + + /** + * @private + * Determines the position of the toolTip. + */ + protected function determinePosition(event:MouseEvent, base:Object):Point + { + var comp:IUIBase = _strand as IUIBase; + var pt:Point = new Point(comp.width, comp.height); + pt = PointUtils.localToGlobal(pt, comp); + return pt; + } + + /** + * @private + */ + private function rollOutHandler( event:MouseEvent ):void + { + if (tt) { + host.removeElement(tt); + } + tt = null; + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/d8221452/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/beads/AlertMeasurementBead.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/beads/AlertMeasurementBead.as b/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/beads/AlertMeasurementBead.as new file mode 100644 index 0000000..dbe6c05 --- /dev/null +++ b/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/beads/AlertMeasurementBead.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 +{ + import org.apache.flex.core.IMeasurementBead; + import org.apache.flex.core.IStrand; + + /** + * The AlertMeasureBead class provides boundary measurements for an + * org.apache.flex.html.Alert component. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class AlertMeasurementBead implements IMeasurementBead + { + /** + * constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function AlertMeasurementBead() + { + } + + /** + * Returns the overall width of the org.apache.flex.html.Alert component. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get measuredWidth():Number + { + return 0; + } + + /** + * Returns the overall height of the org.apache.flex.html.Alert component. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get measuredHeight():Number + { + return 0; + } + + 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/d8221452/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/beads/AlertView.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/beads/AlertView.as b/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/beads/AlertView.as new file mode 100644 index 0000000..5788d47 --- /dev/null +++ b/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/beads/AlertView.as @@ -0,0 +1,226 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.BeadViewBase; + import org.apache.flex.core.IAlertModel; + import org.apache.flex.core.IBead; + import org.apache.flex.core.IBeadView; + import org.apache.flex.core.IMeasurementBead; + import org.apache.flex.core.IParent; + import org.apache.flex.core.IStrand; + import org.apache.flex.core.UIBase; + 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.Alert; + import org.apache.flex.html.ControlBar; + import org.apache.flex.html.Label; + import org.apache.flex.html.TextButton; + import org.apache.flex.html.TitleBar; + import org.apache.flex.utils.CSSContainerUtils; + + /** + * The AlertView class creates the visual elements of the org.apache.flex.html.Alert + * component. The job of the view bead is to put together the parts of the Alert, such as the + * title bar, message, and various buttons, within the space of the Alert component strand. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class AlertView extends BeadViewBase implements IBeadView + { + /** + * constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function AlertView() + { + } + + private var _titleBar:TitleBar; + private var _controlBar:ControlBar; + private var _label:Label; + private var _okButton:TextButton; + private var _cancelButton:TextButton; + private var _yesButton:TextButton; + private var _noButton:TextButton; + + /** + * @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; + + var backgroundColor:Object = ValuesManager.valuesImpl.getValue(value, "background-color"); + var backgroundImage:Object = ValuesManager.valuesImpl.getValue(value, "background-image"); + if (backgroundColor != null || backgroundImage != null) + { + if (value.getBeadByType(IBackgroundBead) == null) + value.addBead(new (ValuesManager.valuesImpl.getValue(value, "iBackgroundBead")) as IBead); + } + + var borderStyle:String; + var borderStyles:Object = ValuesManager.valuesImpl.getValue(value, "border"); + if (borderStyles is Array) + { + borderStyle = borderStyles[1]; + } + if (borderStyle == null) + { + borderStyle = ValuesManager.valuesImpl.getValue(value, "border-style") as String; + } + if (borderStyle != null && borderStyle != "none") + { + if (value.getBeadByType(IBorderBead) == null) + value.addBead(new (ValuesManager.valuesImpl.getValue(value, "iBorderBead")) as IBead); + } + + var flags:uint = IAlertModel(UIBase(_strand).model).flags; + if( flags & Alert.OK ) { + _okButton = new TextButton(); + _okButton.text = IAlertModel(UIBase(_strand).model).okLabel; + _okButton.addEventListener("click",handleOK); + } + if( flags & Alert.CANCEL ) { + _cancelButton = new TextButton(); + _cancelButton.text = IAlertModel(UIBase(_strand).model).cancelLabel; + _cancelButton.addEventListener("click",handleCancel); + } + if( flags & Alert.YES ) { + _yesButton = new TextButton(); + _yesButton.text = IAlertModel(UIBase(_strand).model).yesLabel; + _yesButton.addEventListener("click",handleYes); + } + if( flags & Alert.NO ) { + _noButton = new TextButton(); + _noButton.text = IAlertModel(UIBase(_strand).model).noLabel; + _noButton.addEventListener("click",handleNo); + } + + _titleBar = new TitleBar(); + _titleBar.title = IAlertModel(UIBase(_strand).model).title; + + _label = new Label(); + _label.text = IAlertModel(UIBase(_strand).model).message; + + _controlBar = new ControlBar(); + if( _okButton ) _controlBar.addElement(_okButton); + if( _cancelButton ) _controlBar.addElement(_cancelButton); + if( _yesButton ) _controlBar.addElement(_yesButton); + if( _noButton ) _controlBar.addElement(_noButton); + + IParent(_strand).addElement(_titleBar); + IParent(_strand).addElement(_controlBar); + IParent(_strand).addElement(_label); + + sizeHandler(null); + } + + /** + * @private + */ + private function sizeHandler(event:Event):void + { + var labelMeasure:IMeasurementBead = _label.measurementBead; + var titleMeasure:IMeasurementBead = _titleBar.measurementBead; + var ctrlMeasure:IMeasurementBead = _controlBar.measurementBead; + var maxWidth:Number = Math.max(titleMeasure.measuredWidth, ctrlMeasure.measuredWidth, labelMeasure.measuredWidth); + + var metrics:Rectangle = CSSContainerUtils.getBorderAndPaddingMetrics(_strand); + + _titleBar.x = 0; + _titleBar.y = 0; + _titleBar.width = maxWidth; + _titleBar.height = 25; + _titleBar.dispatchEvent(new Event("layoutNeeded")); + + // content placement here + _label.x = metrics.left; + _label.y = _titleBar.y + _titleBar.height + metrics.top; + _label.width = maxWidth - metrics.left - metrics.right; + + _controlBar.x = 0; + _controlBar.y = _titleBar.height + _label.y + _label.height + metrics.bottom; + _controlBar.width = maxWidth; + _controlBar.height = 25; + _controlBar.dispatchEvent(new Event("layoutNeeded")); + + UIBase(_strand).width = maxWidth; + UIBase(_strand).height = _titleBar.height + _label.height + _controlBar.height + metrics.top + metrics.bottom; + } + + /** + * @private + */ + private function handleOK(event:Event):void + { + // create some custom event where the detail value + // is the OK button flag. Do same for other event handlers + dispatchCloseEvent(Alert.OK); + } + + /** + * @private + */ + private function handleCancel(event:Event):void + { + dispatchCloseEvent(Alert.CANCEL); + } + + /** + * @private + */ + private function handleYes(event:Event):void + { + dispatchCloseEvent(Alert.YES); + } + + /** + * @private + */ + private function handleNo(event:Event):void + { + dispatchCloseEvent(Alert.NO); + } + + /** + * @private + */ + public function dispatchCloseEvent(buttonFlag:uint):void + { + // TO DO: buttonFlag should be part of the event + var newEvent:Event = new Event("close",true); + IEventDispatcher(_strand).dispatchEvent(newEvent); + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/d8221452/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/beads/BackgroundImageBead.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/beads/BackgroundImageBead.as b/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/beads/BackgroundImageBead.as new file mode 100644 index 0000000..8cedc9a --- /dev/null +++ b/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/beads/BackgroundImageBead.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.Bitmap; + import flash.display.Loader; + import flash.display.LoaderInfo; + import flash.display.Sprite; + import flash.events.Event; + import flash.events.IOErrorEvent; + import flash.net.URLRequest; + + import org.apache.flex.core.IBead; + import org.apache.flex.core.IStrand; + import org.apache.flex.core.UIBase; + import org.apache.flex.core.ValuesManager; + + /** + * The BackgroundImageBead is used to render an image as the background to any component + * that supports it, such as Container. + * + * Note that this bead is for ActionScript only since CSS/HTML allows this just by specifying + * a background image in the style selector. To use this bead, place a ClassReference to it + * within @media -flex-flash { } group in the CSS declarations. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class BackgroundImageBead implements IBead, IBackgroundBead + { + /** + * Constructor + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function BackgroundImageBead() + { + backgroundSprite = new Sprite(); + } + + private var _strand:IStrand; + private var backgroundSprite:Sprite; + private var bitmap:Bitmap; + private var loader:Loader; + + public function set strand(value:IStrand):void + { + _strand = value; + + setupBackground(backgroundSprite); + } + + /** + * @private + */ + private function setupBackground(sprite:Sprite, state:String = null):void + { + var backgroundImage:Object = ValuesManager.valuesImpl.getValue(_strand, "background-image", state); + if (backgroundImage) + { + loader = new Loader(); + var url:String = backgroundImage as String; + loader.load(new URLRequest(url)); + loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, function (e:IOErrorEvent):void { + trace(e); + e.preventDefault(); + }); + loader.contentLoaderInfo.addEventListener(flash.events.Event.COMPLETE, function (e:flash.events.Event):void { + var host:UIBase = UIBase(_strand); + if (bitmap) { + host.removeChild(bitmap); + } + + bitmap = Bitmap(LoaderInfo(e.target).content); + + host.addChildAt(bitmap,0); + + if (isNaN(host.explicitWidth) && isNaN(host.percentWidth)) + host.setWidth(loader.content.width); + else + bitmap.width = UIBase(_strand).width; + + if (isNaN(host.explicitHeight) && isNaN(host.percentHeight)) + host.setHeight(loader.content.height); + else + bitmap.height = UIBase(_strand).height; + }); + } + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/d8221452/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/beads/ButtonBarView.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/beads/ButtonBarView.as b/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/beads/ButtonBarView.as new file mode 100644 index 0000000..cbe0a3e --- /dev/null +++ b/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/beads/ButtonBarView.as @@ -0,0 +1,69 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.IBeadModel; + import org.apache.flex.core.IParent; + import org.apache.flex.core.IStrand; + import org.apache.flex.core.ValuesManager; + import org.apache.flex.core.UIBase; + import org.apache.flex.events.Event; + import org.apache.flex.events.IEventDispatcher; + import org.apache.flex.html.supportClasses.Border; + + /** + * The ButtonBarView class creates the visual elements of the org.apache.flex.html.ButtonBar + * component. A ButtonBar is a type of List and ButtonBarView extends the ListView bead, adding a border. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class ButtonBarView extends ListView + { + /** + * constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function ButtonBarView() + { + super(); + } + + /** + * @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 + { + _strand = value; + super.strand = value; + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/d8221452/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/beads/CSSButtonView.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/beads/CSSButtonView.as b/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/beads/CSSButtonView.as new file mode 100644 index 0000000..fcd14cc --- /dev/null +++ b/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/beads/CSSButtonView.as @@ -0,0 +1,167 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.Loader; + import flash.display.Shape; + import flash.display.SimpleButton; + import flash.display.Sprite; + import flash.events.Event; + import flash.net.URLRequest; + + import org.apache.flex.core.BeadViewBase; + import org.apache.flex.core.IBeadView; + import org.apache.flex.core.IStrand; + import org.apache.flex.core.ITextModel; + import org.apache.flex.core.ValuesManager; + import org.apache.flex.events.Event; + import org.apache.flex.events.IEventDispatcher; + import org.apache.flex.utils.CSSBorderUtils; + import org.apache.flex.utils.CSSUtils; + import org.apache.flex.utils.StringTrimmer; + + /** + * The CSSButtonView class is the default view for + * the org.apache.flex.html.Button class. + * It allows the look of the button to be expressed + * in CSS via the background-image style. This view + * does not display text. Use CSSTextButtonView and + * TextButton instead. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class CSSButtonView extends BeadViewBase implements IBeadView + { + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function CSSButtonView() + { + upSprite = new Sprite(); + downSprite = new Sprite(); + overSprite = new Sprite(); + } + + private var textModel:ITextModel; + + 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, 10, 10); + shape.graphics.endFill(); + SimpleButton(value).upState = upSprite; + SimpleButton(value).downState = downSprite; + SimpleButton(value).overState = overSprite; + SimpleButton(value).hitTestState = shape; + + setupBackground(overSprite, "hover"); + setupBackground(downSprite, "active"); + setupBackground(upSprite); + + IEventDispatcher(_strand).addEventListener("widthChanged",sizeChangeHandler); + IEventDispatcher(_strand).addEventListener("heightChanged",sizeChangeHandler); + } + + private function sizeChangeHandler(event:org.apache.flex.events.Event):void + { + setupSkins(); + } + + protected function setupSkins():void + { + setupSkin(overSprite, "hover"); + setupSkin(downSprite, "active"); + setupSkin(upSprite); + updateHitArea(); + } + + private function setupSkin(sprite:Sprite, state:String = null):void + { + var padding:Object = ValuesManager.valuesImpl.getValue(_strand, "padding", state); + var paddingLeft:Object = ValuesManager.valuesImpl.getValue(_strand, "padding-left", state); + var paddingRight:Object = ValuesManager.valuesImpl.getValue(_strand, "padding-right", state); + var paddingTop:Object = ValuesManager.valuesImpl.getValue(_strand, "padding-top", state); + var paddingBottom:Object = ValuesManager.valuesImpl.getValue(_strand, "padding-bottom", state); + var pl:Number = CSSUtils.getLeftValue(paddingLeft, padding, DisplayObject(_strand).width); + var pr:Number = CSSUtils.getRightValue(paddingRight, padding, DisplayObject(_strand).width); + var pt:Number = CSSUtils.getTopValue(paddingTop, padding, DisplayObject(_strand).height); + var pb:Number = CSSUtils.getBottomValue(paddingBottom, padding, DisplayObject(_strand).height); + + CSSBorderUtils.draw(sprite.graphics, + DisplayObject(_strand).width + pl + pr, + DisplayObject(_strand).height + pt + pb, + _strand as DisplayObject, + state, true); + } + + private function setupBackground(sprite:Sprite, state:String = null):void + { + var backgroundImage:Object = ValuesManager.valuesImpl.getValue(_strand, "background-image", state); + if (backgroundImage) + { + var loader:Loader = new Loader(); + sprite.addChildAt(loader, 0); + var url:String = backgroundImage as String; + loader.load(new URLRequest(url)); + loader.contentLoaderInfo.addEventListener(flash.events.Event.COMPLETE, function (e:flash.events.Event):void { + setupSkin(sprite, state); + updateHitArea(); + }); + } + else { + setupSkin(sprite, state); + updateHitArea(); + } + } + + private var upSprite:Sprite; + private var downSprite:Sprite; + private var overSprite:Sprite; + + private function updateHitArea():void + { + shape.graphics.clear(); + shape.graphics.beginFill(0xCCCCCC); + shape.graphics.drawRect(0, 0, upSprite.width, upSprite.height); + shape.graphics.endFill(); + + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/d8221452/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/beads/CSSImageAndTextButtonView.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/beads/CSSImageAndTextButtonView.as b/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/beads/CSSImageAndTextButtonView.as new file mode 100644 index 0000000..12ac07d --- /dev/null +++ b/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/beads/CSSImageAndTextButtonView.as @@ -0,0 +1,367 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.Loader; + import flash.display.Shape; + import flash.display.SimpleButton; + import flash.display.Sprite; + import flash.events.Event; + import flash.net.URLRequest; + import flash.text.TextField; + import flash.text.TextFieldType; + + import org.apache.flex.core.BeadViewBase; + import org.apache.flex.core.CSSTextField; + import org.apache.flex.core.IBeadView; + 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.html.TextButton; + import org.apache.flex.html.beads.models.ImageAndTextModel; + import org.apache.flex.utils.CSSUtils; + import org.apache.flex.utils.SolidBorderUtil; + import org.apache.flex.utils.StringTrimmer; + + /** + * The CSSTextButtonView class is the default view for + * the org.apache.flex.html.TextButton class. + * It allows the look of the button to be expressed + * in CSS via the background-image style and displays + * a text label. This view does not support right-to-left + * text. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class CSSImageAndTextButtonView extends BeadViewBase implements IBeadView + { + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function CSSImageAndTextButtonView() + { + upSprite = new Sprite(); + downSprite = new Sprite(); + overSprite = new Sprite(); + upTextField = new CSSTextField(); + downTextField = new CSSTextField(); + overTextField = new CSSTextField(); + upTextField.selectable = false; + upTextField.type = TextFieldType.DYNAMIC; + downTextField.selectable = false; + downTextField.type = TextFieldType.DYNAMIC; + overTextField.selectable = false; + overTextField.type = TextFieldType.DYNAMIC; + upTextField.autoSize = "left"; + downTextField.autoSize = "left"; + overTextField.autoSize = "left"; + upSprite.addChild(upTextField); + downSprite.addChild(downTextField); + overSprite.addChild(overTextField); + } + + private var textModel:ImageAndTextModel; + + 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 + { + _strand = value; + textModel = value.getBeadByType(ImageAndTextModel) as ImageAndTextModel; + textModel.addEventListener("textChange", textChangeHandler); + textModel.addEventListener("htmlChange", htmlChangeHandler); + textModel.addEventListener("imageChange", imageChangeHandler); + shape = new Shape(); + shape.graphics.beginFill(0xCCCCCC); + shape.graphics.drawRect(0, 0, 10, 10); + shape.graphics.endFill(); + upTextField.styleParent = _strand; + downTextField.styleParent = _strand; + overTextField.styleParent = _strand; + upTextField.parentDrawsBackground = true; + downTextField.parentDrawsBackground = true; + overTextField.parentDrawsBackground = true; + upTextField.parentHandlesPadding = true; + downTextField.parentHandlesPadding = true; + overTextField.parentHandlesPadding = true; + SimpleButton(value).upState = upSprite; + SimpleButton(value).downState = downSprite; + SimpleButton(value).overState = overSprite; + SimpleButton(value).hitTestState = shape; + if (textModel.text !== null) + text = textModel.text; + if (textModel.html !== null) + html = textModel.html; + + setupSkins(); + + IEventDispatcher(_strand).addEventListener("widthChanged",sizeChangeHandler); + IEventDispatcher(_strand).addEventListener("heightChanged",sizeChangeHandler); + IEventDispatcher(_strand).addEventListener("sizeChanged",sizeChangeHandler); + } + + protected function setupSkins():void + { + setupSkin(overSprite, overTextField, "hover"); + setupSkin(downSprite, downTextField, "active"); + setupSkin(upSprite, upTextField); + updateHitArea(); + } + + private function setupSkin(sprite:Sprite, textField:TextField, state:String = null):void + { + var sw:uint = DisplayObject(_strand).width; + var sh:uint = DisplayObject(_strand).height; + + textField.defaultTextFormat.leftMargin = 0; + textField.defaultTextFormat.rightMargin = 0; + // set it again so it gets noticed + textField.defaultTextFormat = textField.defaultTextFormat; + + var borderColor:uint; + var borderThickness:uint; + var borderStyle:String; + var borderStyles:Object = ValuesManager.valuesImpl.getValue(_strand, "border", state); + if (borderStyles is Array) + { + borderColor = CSSUtils.toColor(borderStyles[2]); + borderStyle = borderStyles[1]; + borderThickness = borderStyles[0]; + } + else if (borderStyles is String) + borderStyle = borderStyles as String; + var value:Object = ValuesManager.valuesImpl.getValue(_strand, "border-style", state); + if (value != null) + borderStyle = value as String; + value = ValuesManager.valuesImpl.getValue(_strand, "border-color", state); + if (value != null) + borderColor = CSSUtils.toColor(value); + value = ValuesManager.valuesImpl.getValue(_strand, "border-width", state); + if (value != null) + borderThickness = value as uint; + if (borderStyle == "none") + { + borderStyle = "solid"; + borderThickness = 0; + } + + var borderRadius:String; + var borderEllipseWidth:Number = NaN; + var borderEllipseHeight:Number = NaN; + value = ValuesManager.valuesImpl.getValue(_strand, "border-radius", state); + if (value != null) + { + if (value is Number) + borderEllipseWidth = 2 * (value as Number); + else + { + borderRadius = value as String; + var arr:Array = StringTrimmer.splitAndTrim(borderRadius, "/"); + borderEllipseWidth = 2 * CSSUtils.toNumber(arr[0]); + if (arr.length > 1) + borderEllipseHeight = 2 * CSSUtils.toNumber(arr[1]); + } + } + + var padding:Object = ValuesManager.valuesImpl.getValue(_strand, "padding", state); + var paddingLeft:Object = ValuesManager.valuesImpl.getValue(_strand, "padding-left", state); + var paddingRight:Object = ValuesManager.valuesImpl.getValue(_strand, "padding-right", state); + var paddingTop:Object = ValuesManager.valuesImpl.getValue(_strand, "padding-top", state); + var paddingBottom:Object = ValuesManager.valuesImpl.getValue(_strand, "padding-bottom", state); + var pl:Number = CSSUtils.getLeftValue(paddingLeft, padding, DisplayObject(_strand).width); + var pr:Number = CSSUtils.getRightValue(paddingRight, padding, DisplayObject(_strand).width); + var pt:Number = CSSUtils.getTopValue(paddingTop, padding, DisplayObject(_strand).height); + var pb:Number = CSSUtils.getBottomValue(paddingBottom, padding, DisplayObject(_strand).height); + + var backgroundColor:Object = ValuesManager.valuesImpl.getValue(_strand, "background-color", state); + var bgColor:uint; + var bgAlpha:Number = 1; + if (backgroundColor != null) + { + bgColor = CSSUtils.toColorWithAlpha(backgroundColor); + if (bgColor & 0xFF000000) + { + bgAlpha = bgColor >>> 24 / 255; + bgColor = bgColor & 0xFFFFFF; + } + } + if (borderStyle == "solid") + { + var useWidth:Number = Math.max(sw,textField.textWidth); + var useHeight:Number = Math.max(sh,textField.textHeight); + + if ((useWidth-pl-pr-2*borderThickness) < textField.textWidth) + useWidth = textField.textWidth+pl+pr+2*borderThickness; + if ((useHeight-pt-pb-2*borderThickness) < textField.textHeight) + useHeight = textField.textHeight+pt+pb+2*borderThickness; + + sprite.graphics.clear(); + SolidBorderUtil.drawBorder(sprite.graphics, + 0, 0, useWidth, useHeight, + borderColor, backgroundColor == null ? null : bgColor, borderThickness, bgAlpha, + borderEllipseWidth, borderEllipseHeight); + textField.y = ((useHeight - textField.textHeight) / 2) - 2; + textField.x = ((useWidth - textField.textWidth) / 2) - 2; + } + var backgroundImage:Object = image; + if (backgroundImage) + { + var loader:Loader = new Loader(); + sprite.addChildAt(loader, 0); + sprite.addChild(textField); + var url:String = backgroundImage as String; + loader.load(new URLRequest(url)); + loader.contentLoaderInfo.addEventListener(flash.events.Event.COMPLETE, function (e:flash.events.Event):void { + updateHitArea(); + loader.x = pl; + textField.x = loader.width + pl; + textField.y = pt; + loader.y = (textField.height + pt + pb - loader.height) / 2; + sprite.graphics.clear(); + SolidBorderUtil.drawBorder(sprite.graphics, + 0, 0, textField.x + textField.width + pr + borderThickness, + textField.y + textField.height + pb + borderThickness, + borderColor, backgroundColor == null ? null : bgColor, borderThickness, bgAlpha, + borderEllipseWidth, borderEllipseHeight); + }); + } + var textColor:Object = ValuesManager.valuesImpl.getValue(_strand, "color", state); + if (textColor) { + textField.textColor = Number(textColor); + } + } + + private function textChangeHandler(event:org.apache.flex.events.Event):void + { + text = textModel.text; + } + + private function htmlChangeHandler(event:org.apache.flex.events.Event):void + { + html = textModel.html; + } + + private function sizeChangeHandler(event:org.apache.flex.events.Event):void + { + setupSkins(); + } + + private var upTextField:CSSTextField; + private var downTextField:CSSTextField; + private var overTextField:CSSTextField; + private var upSprite:Sprite; + private var downSprite:Sprite; + private var overSprite:Sprite; + + /** + * The URL of an icon to use in the button + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get image():String + { + return textModel.image; + } + + private function imageChangeHandler(event:org.apache.flex.events.Event):void + { + setupSkins(); + } + + /** + * The text to be displayed in the button + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get text():String + { + return upTextField.text; + } + + /** + * @private + */ + public function set text(value:String):void + { + upTextField.text = value; + downTextField.text = value; + overTextField.text = value; + updateHitArea(); + } + + private function updateHitArea():void + { + var useWidth:uint = Math.max(DisplayObject(_strand).width, upTextField.textWidth); + var useHeight:uint = Math.max(DisplayObject(_strand).height, upTextField.textHeight); + + shape.graphics.clear(); + shape.graphics.beginFill(0xCCCCCC); + shape.graphics.drawRect(0, 0, useWidth, useHeight); + shape.graphics.endFill(); + + } + + /** + * The html-formatted text to be displayed in the button + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get html():String + { + return upTextField.htmlText; + } + + /** + * @private + */ + public function set html(value:String):void + { + upTextField.htmlText = value; + downTextField.htmlText = value; + overTextField.htmlText = value; + } + } +}