You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by pe...@apache.org on 2013/05/16 22:31:04 UTC

git commit: [flex-asjs] [refs/heads/develop] - Initial work to create a TitleBar component using a model and TitleBarBead.

Updated Branches:
  refs/heads/develop e4681d936 -> a01d31f0f


Initial work to create a TitleBar component using a model and TitleBarBead.


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/a01d31f0
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/a01d31f0
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/a01d31f0

Branch: refs/heads/develop
Commit: a01d31f0f6d128332db6e0ce6adaeccde64f69cc
Parents: e4681d9
Author: Peter Ent <pe...@apache.org>
Authored: Thu May 16 16:30:50 2013 -0400
Committer: Peter Ent <pe...@apache.org>
Committed: Thu May 16 16:30:50 2013 -0400

----------------------------------------------------------------------
 frameworks/as/basic-manifest.xml                   |    1 +
 frameworks/as/defaults.css                         |    5 +
 frameworks/as/src/FlexJSUIClasses.as               |    1 +
 .../as/src/org/apache/flex/core/ITitleBarBead.as   |   32 +++
 .../apache/flex/html/staticControls/TitleBar.as    |   76 ++++++
 .../flex/html/staticControls/beads/PanelBead.as    |   82 ++-----
 .../flex/html/staticControls/beads/TitleBarBead.as |  211 +++++++++++++++
 7 files changed, 343 insertions(+), 65 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/a01d31f0/frameworks/as/basic-manifest.xml
----------------------------------------------------------------------
diff --git a/frameworks/as/basic-manifest.xml b/frameworks/as/basic-manifest.xml
index 240ce76..50cdda6 100644
--- a/frameworks/as/basic-manifest.xml
+++ b/frameworks/as/basic-manifest.xml
@@ -46,6 +46,7 @@
     <component id="BinaryUploader" class="org.apache.flex.net.BinaryUploader"/>
     <component id="Container" class="org.apache.flex.html.staticControls.Container"/>
     <component id="ControlBar" class="org.apache.flex.html.staticControls.ControlBar"/>
+    <component id="TitleBar" class="org.apache.flex.html.staticControls.TitleBar"/>
     <component id="NonVirtualVerticalLayout" class="org.apache.flex.html.staticControls.beads.layouts.NonVirtualVerticalLayout"/>
     <component id="NonVirtualHorizontalLayout" class="org.apache.flex.html.staticControls.beads.layouts.NonVirtualHorizontalLayout"/>
     <component id="PanelBead" class="org.apache.flex.html.staticControls.beads.PanelBead"/>

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/a01d31f0/frameworks/as/defaults.css
----------------------------------------------------------------------
diff --git a/frameworks/as/defaults.css b/frameworks/as/defaults.css
index 900c97d..bbd739d 100644
--- a/frameworks/as/defaults.css
+++ b/frameworks/as/defaults.css
@@ -119,6 +119,11 @@ TextInput
 	height: 20;
 }
 
+TitleBar
+{
+	ITitleBarBead: ClassReference("org.apache.flex.html.staticControls.beads.TitleBarBead");
+}
+
 /* HTML5 */
 
 h5|TextButton

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/a01d31f0/frameworks/as/src/FlexJSUIClasses.as
----------------------------------------------------------------------
diff --git a/frameworks/as/src/FlexJSUIClasses.as b/frameworks/as/src/FlexJSUIClasses.as
index 033ed29..8da7cd7 100644
--- a/frameworks/as/src/FlexJSUIClasses.as
+++ b/frameworks/as/src/FlexJSUIClasses.as
@@ -38,6 +38,7 @@ internal class FlexJSUIClasses
 	import org.apache.flex.html.staticControls.beads.RadioButtonBead; RadioButtonBead;
 	import org.apache.flex.html.staticControls.beads.ComboBoxBead; ComboBoxBead;
     import org.apache.flex.html.staticControls.beads.ContainerBead; ContainerBead;
+	import org.apache.flex.html.staticControls.beads.TitleBarBead; TitleBarBead;
 	import org.apache.flex.html.staticControls.beads.models.TextModel; TextModel;
 	import org.apache.flex.html.staticControls.beads.models.ComboBoxModel; ComboBoxModel;
 	import org.apache.flex.html.staticControls.beads.models.ToggleButtonModel; ToggleButtonModel;

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/a01d31f0/frameworks/as/src/org/apache/flex/core/ITitleBarBead.as
----------------------------------------------------------------------
diff --git a/frameworks/as/src/org/apache/flex/core/ITitleBarBead.as b/frameworks/as/src/org/apache/flex/core/ITitleBarBead.as
new file mode 100644
index 0000000..bae3b98
--- /dev/null
+++ b/frameworks/as/src/org/apache/flex/core/ITitleBarBead.as
@@ -0,0 +1,32 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.core
+{
+	public interface ITitleBarBead extends IBead
+	{
+		function get text():String;
+		function set text(value:String):void;
+		
+		function get html():String;
+		function set html(value:String):void;
+		
+		function get showCloseButton() : Boolean;
+		function set showCloseButton(value:Boolean):void;
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/a01d31f0/frameworks/as/src/org/apache/flex/html/staticControls/TitleBar.as
----------------------------------------------------------------------
diff --git a/frameworks/as/src/org/apache/flex/html/staticControls/TitleBar.as b/frameworks/as/src/org/apache/flex/html/staticControls/TitleBar.as
new file mode 100644
index 0000000..9bcb171
--- /dev/null
+++ b/frameworks/as/src/org/apache/flex/html/staticControls/TitleBar.as
@@ -0,0 +1,76 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.staticControls
+{
+	import flash.display.DisplayObject;
+	
+	import org.apache.flex.core.IBead;
+	import org.apache.flex.core.ITextModel;
+	import org.apache.flex.core.ITitleBarBead;
+	import org.apache.flex.core.UIBase;
+	import org.apache.flex.core.ValuesManager;
+	import org.apache.flex.events.Event;
+	import org.apache.flex.events.IEventDispatcher;
+	
+	public class TitleBar extends UIBase
+	{
+		public function TitleBar()
+		{
+			super();
+			
+			this.addEventListener('widthChanged',handleSizeChange);
+			this.addEventListener('heightChanged',handleSizeChange);
+		}
+		
+		public function get text():String
+		{
+			return ITextModel(model).text;
+		}
+		public function set text(value:String):void
+		{
+			ITextModel(model).text = value;
+		}
+		
+		public function get html():String
+		{
+			return ITextModel(model).html;
+		}
+		public function set html(value:String):void
+		{
+			ITextModel(model).html = value;
+		}
+		
+		override public function initModel():void
+		{
+			if (getBeadByType(ITextModel) == null)
+				addBead(new (ValuesManager.valuesImpl.getValue(this, "iTextModel")) as IBead);
+		}
+		
+		public function initSkin():void
+		{
+			if (getBeadByType(ITitleBarBead) == null)
+				addBead(new (ValuesManager.valuesImpl.getValue(this, "iTitleBarBead")) as IBead);			
+		}
+		
+		private function handleSizeChange(event:Event):void
+		{
+			IEventDispatcher(getBeadByType(ITextModel)).dispatchEvent(new Event("widthChanged"));
+		}
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/a01d31f0/frameworks/as/src/org/apache/flex/html/staticControls/beads/PanelBead.as
----------------------------------------------------------------------
diff --git a/frameworks/as/src/org/apache/flex/html/staticControls/beads/PanelBead.as b/frameworks/as/src/org/apache/flex/html/staticControls/beads/PanelBead.as
index 96d2b8d..ff24958 100644
--- a/frameworks/as/src/org/apache/flex/html/staticControls/beads/PanelBead.as
+++ b/frameworks/as/src/org/apache/flex/html/staticControls/beads/PanelBead.as
@@ -36,6 +36,7 @@ package org.apache.flex.html.staticControls.beads
 	import org.apache.flex.events.IEventDispatcher;
 	import org.apache.flex.html.staticControls.Container;
 	import org.apache.flex.html.staticControls.ControlBar;
+	import org.apache.flex.html.staticControls.TitleBar;
 	import org.apache.flex.html.staticControls.beads.layouts.NonVirtualHorizontalLayout;
 	import org.apache.flex.html.staticControls.beads.layouts.NonVirtualVerticalLayout;
 	import org.apache.flex.utils.MXMLDataInterpreter;
@@ -44,26 +45,29 @@ package org.apache.flex.html.staticControls.beads
 	{
 		public function PanelBead()
 		{
+			titleBar = new TitleBar();
+			titleBar.initModel();
+			titleBar.initSkin();
+			titleBar.text = "Panel";
 		}
 		
-		private var _title:String = "Panel";
 		public function get title() : String
 		{
-			return _title;
+			return titleBar.text;
 		}
 		public function set title(value:String):void
 		{
-			_title = value;
+			titleBar.text = value;
 		}
 		
-		private var _showCloseButton:Boolean = false;
 		public function get showCloseButton() : Boolean
 		{
-			return _showCloseButton;
+//			return titleBar.showCloseButton;
+			return false;
 		}
 		public function set showCloseButton(value:Boolean):void
 		{
-			_showCloseButton = value;
+//			titleBar.showCloseButton = value;
 		}
 		
 		private var _controlBar:Array;
@@ -159,10 +163,7 @@ package org.apache.flex.html.staticControls.beads
 			IEventDispatcher(_strand).addEventListener("childrenAdded", changeHandler);
 		}
 		
-		private var titleArea:Sprite;
-		private var titleField:TextField;
-		private var titleBackground:Shape;
-		private var closeButton:SimpleButton;
+		private var titleBar:TitleBar;
 		private var contentArea:DisplayObjectContainer;
 		private var controlBarArea:ControlBar;
 		private var controlBarBackground:Shape;
@@ -172,7 +173,7 @@ package org.apache.flex.html.staticControls.beads
 			layoutTitleArea();
 			
 			contentArea.x = 0;
-			contentArea.y = titleArea.height;
+			contentArea.y = titleBar.height;
 			contentArea.width = Container(_strand).width;
 			
 			if( controlBar ) {
@@ -185,26 +186,7 @@ package org.apache.flex.html.staticControls.beads
 		
 		protected function createTitleArea() : void
 		{
-			titleArea = new Sprite();
-			Container(_strand).addChild(titleArea);
-			
-			titleBackground = new Shape();
-			titleArea.addChild(titleBackground);
-			
-			titleField = new TextField();
-			titleField.type = TextFieldType.DYNAMIC;
-			titleField.text = title;
-			titleField.textColor = 0x000000;
-			titleField.autoSize = TextFieldAutoSize.CENTER;
-			titleArea.addChild(titleField);
-			
-			if( showCloseButton ) {
-				closeButton = new SimpleButton();
-				titleArea.addChild(closeButton);
-			}
-			else {
-				closeButton = null;
-			}
+			Container(_strand).addChild(titleBar);
 		}
 		
 		protected function createControlBar() : void
@@ -216,40 +198,10 @@ package org.apache.flex.html.staticControls.beads
 		
 		protected function layoutTitleArea() : void
 		{
-			titleBackground.graphics.clear();
-			titleBackground.graphics.beginFill(0xCCCCCC);
-			titleBackground.graphics.lineStyle(1,0x333333);
-			titleBackground.graphics.drawRect(0,0,Container(_strand).width,25);
-			titleBackground.graphics.endFill();
-			
-			titleField.width = titleBackground.width;
-			titleField.x = (titleBackground.width - titleField.width)/2;
-			titleField.y = (titleBackground.height - titleField.height)/2;
-			
-			if( closeButton )
-			{
-				var downState:Sprite = new Sprite();
-				downState.graphics.clear();
-				downState.graphics.beginFill(0x006600);
-				downState.graphics.lineStyle(1,0x333333);
-				downState.graphics.drawRect(0,0,16,16);
-				downState.graphics.endFill();
-				closeButton.downState = downState;
-			
-				var upState:Sprite = new Sprite();
-				upState.graphics.clear();
-				upState.graphics.beginFill(0xAA0000);
-				upState.graphics.lineStyle(1,0x333333);
-				upState.graphics.drawRect(0,0,16,16);
-				upState.graphics.endFill();
-				closeButton.upState = closeButton.overState = upState;
-				
-				closeButton.x = titleBackground.width - 21;
-				closeButton.y = 5;
-			}
-			
-			titleArea.x = 0;
-			titleArea.y = 0;
+			titleBar.x = 0;
+			titleBar.y = 0;
+			titleBar.width = Container(_strand).width;
+			titleBar.height = 25;
 		}
 		
 		protected function layoutControlBar() : void

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/a01d31f0/frameworks/as/src/org/apache/flex/html/staticControls/beads/TitleBarBead.as
----------------------------------------------------------------------
diff --git a/frameworks/as/src/org/apache/flex/html/staticControls/beads/TitleBarBead.as b/frameworks/as/src/org/apache/flex/html/staticControls/beads/TitleBarBead.as
new file mode 100644
index 0000000..d95b4f9
--- /dev/null
+++ b/frameworks/as/src/org/apache/flex/html/staticControls/beads/TitleBarBead.as
@@ -0,0 +1,211 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.staticControls.beads
+{
+	import flash.display.DisplayObject;
+	import flash.display.DisplayObjectContainer;
+	import flash.display.SimpleButton;
+	import flash.display.Sprite;
+	import flash.text.TextField;
+	import flash.text.TextFieldAutoSize;
+	import flash.text.TextFieldType;
+	
+	import org.apache.flex.core.CSSTextField;
+	import org.apache.flex.core.IBead;
+	import org.apache.flex.core.IInitSkin;
+	import org.apache.flex.core.IStrand;
+	import org.apache.flex.core.ITextModel;
+	import org.apache.flex.core.ITitleBarBead;
+	import org.apache.flex.events.Event;
+	
+	public class TitleBarBead implements ITitleBarBead,IInitSkin, IStrand
+	{
+		public function TitleBarBead()
+		{
+			_titleField = new CSSTextField();
+			_titleField.type = TextFieldType.DYNAMIC;
+			_titleField.autoSize = TextFieldAutoSize.LEFT;
+			
+			_closeButton = new SimpleButton();
+			_closeButton.mouseEnabled = true;
+			_closeButton.useHandCursor = true;
+			
+			var upState:Sprite = new Sprite();
+			upState.graphics.clear();
+			upState.graphics.beginFill(0xAAAAAA);
+			upState.graphics.lineStyle(1,0x333333);
+			upState.graphics.drawRect(0,0,9,9);
+			upState.graphics.endFill();
+			_closeButton.upState = upState;
+			
+			var overState:Sprite = new Sprite();
+			overState.graphics.clear();
+			overState.graphics.beginFill(0x999999);
+			overState.graphics.lineStyle(1,0x333333);
+			overState.graphics.drawRect(0,0,9,9);
+			overState.graphics.endFill();
+			_closeButton.overState = overState;
+			
+			var downState:Sprite = new Sprite();
+			downState.graphics.clear();
+			downState.graphics.beginFill(0x666666);
+			downState.graphics.lineStyle(1,0x333333);
+			downState.graphics.drawRect(0,0,9,9);
+			downState.graphics.endFill();
+			_closeButton.downState = downState;
+		}
+		
+		private var _titleField:CSSTextField;
+		private var _closeButton:SimpleButton;
+		
+		protected function get textField() : CSSTextField
+		{
+			return _titleField;
+		}
+		
+		private var _textModel:ITextModel;
+		
+		public function get textModel() : ITextModel
+		{
+			return _textModel;
+		}
+		
+		private var _strand:IStrand;
+		
+		public function set strand(value:IStrand):void
+		{
+			_strand = value;
+			
+			_textModel = value.getBeadByType(ITextModel) as ITextModel;
+			textModel.addEventListener("textChange", textChangeHandler);
+			textModel.addEventListener("htmlChange", htmlChangeHandler);
+			textModel.addEventListener("widthChanged", sizeChangeHandler);
+			textModel.addEventListener("heightChanged", sizeChangeHandler);
+			
+			DisplayObjectContainer(value).addChild(_titleField);
+			
+			if (textModel.text !== null)
+				text = textModel.text;
+			if (textModel.html !== null)
+				html = textModel.html;
+			
+			sizeChangeHandler(null);
+		}
+		
+		public function initSkin():void
+		{
+		}
+		
+		public function get text():String
+		{
+			return _titleField.text;
+		}
+		public function set text(value:String):void
+		{
+			_titleField.text = value;
+		}
+		
+		public function get html():String
+		{
+			return _titleField.htmlText;
+		}
+		
+		public function set html(value:String):void
+		{
+			_titleField.htmlText = value;
+		}
+		
+		private var _showCloseButton:Boolean = false;
+		public function get showCloseButton() : Boolean
+		{
+			return _showCloseButton;
+		}
+		public function set showCloseButton(value:Boolean):void
+		{
+			_showCloseButton = value;
+			if( value ) {
+				DisplayObjectContainer(_strand).addChild(_closeButton);
+			}
+			else {
+				DisplayObjectContainer(_strand).removeChild(_closeButton);
+			}
+		}
+		
+		private function textChangeHandler(event:Event):void
+		{
+			text = textModel.text;
+		}
+		
+		private function htmlChangeHandler(event:Event):void
+		{
+			html = textModel.html;
+		}
+		
+		private function sizeChangeHandler(event:Event):void
+		{
+			_titleField.x = (DisplayObject(_strand).width - _titleField.width)/2;
+			_titleField.y = (DisplayObject(_strand).height - _titleField.height)/2;
+			
+			trace("TitleBarBead. strand.width="+DisplayObject(_strand).width+"; titleField.width="+_titleField.width);
+			
+			if( showCloseButton ) {
+				_closeButton. x = DisplayObject(_strand).width - _closeButton.width - 5;
+				_closeButton.y = (DisplayObject(_strand).height - _closeButton.height)/2;
+			}
+		}
+		
+		// beads declared in MXML are added to the strand.
+		// from AS, just call addBead()
+		public var beads:Array;
+		
+		private var _beads:Vector.<IBead>;
+		public function addBead(bead:IBead):void
+		{
+			if (!_beads)
+				_beads = new Vector.<IBead>;
+			_beads.push(bead);
+			bead.strand = this;
+		}
+		
+		public function getBeadByType(classOrInterface:Class):IBead
+		{
+			for each (var bead:IBead in _beads)
+			{
+				if (bead is classOrInterface)
+					return bead;
+			}
+			return null;
+		}
+		
+		public function removeBead(value:IBead):IBead	
+		{
+			var n:int = _beads.length;
+			for (var i:int = 0; i < n; i++)
+			{
+				var bead:IBead = _beads[i];
+				if (bead == value)
+				{
+					_beads.splice(i, 1);
+					return bead;
+				}
+			}
+			return null;
+		}
+	}
+}
\ No newline at end of file