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/06/28 20:21:23 UTC

git commit: [flex-asjs] [refs/heads/develop] - NumericStepper for ActionScript. Modified sample Flex app to include a NumericStepper.

Updated Branches:
  refs/heads/develop 318d5fc44 -> b82ee1a04


NumericStepper for ActionScript. Modified sample Flex app to include a NumericStepper.


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

Branch: refs/heads/develop
Commit: b82ee1a04af524653e8b783ec867ec9514f7471e
Parents: 318d5fc
Author: Peter Ent <pe...@apache.org>
Authored: Fri Jun 28 14:21:13 2013 -0400
Committer: Peter Ent <pe...@apache.org>
Committed: Fri Jun 28 14:21:13 2013 -0400

----------------------------------------------------------------------
 .../FlexJSTest_Panel/src/MyInitialView.mxml     |  21 ++--
 frameworks/as/basic-manifest.xml                |   1 +
 frameworks/as/defaults.css                      |  14 +++
 frameworks/as/src/FlexJSUIClasses.as            |   1 +
 .../flex/html/staticControls/NumericStepper.as  |  95 +++++++++++++++
 .../staticControls/beads/INumericStepperBead.as |  27 +++++
 .../staticControls/beads/NumericStepperBead.as  | 115 +++++++++++++++++++
 7 files changed, 262 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b82ee1a0/examples/FlexJSTest_Panel/src/MyInitialView.mxml
----------------------------------------------------------------------
diff --git a/examples/FlexJSTest_Panel/src/MyInitialView.mxml b/examples/FlexJSTest_Panel/src/MyInitialView.mxml
index 89f5a1f..e517c17 100644
--- a/examples/FlexJSTest_Panel/src/MyInitialView.mxml
+++ b/examples/FlexJSTest_Panel/src/MyInitialView.mxml
@@ -24,7 +24,6 @@ limitations under the License.
         <![CDATA[
 			import org.apache.flex.html.staticControls.Alert;
 			import org.apache.flex.html.staticControls.SimpleAlert;
-			import org.apache.flex.html.staticControls.Spinner;
 			
 			private function initControls():void
 			{
@@ -39,9 +38,9 @@ limitations under the License.
 
 			}
 			
-			private function spinnerChanged():void
+			private function spinnerChanged(control:Object):void
 			{
-				spinMe.text = "Spin: "+String(spinner.value);
+				spinMe.text = "Spin: "+String(control.value);
 			}
 			
 			private function showSimpleAlert() : void
@@ -93,7 +92,6 @@ limitations under the License.
 		}
 		
 		.numStepper {
-			padding: 5px;
 			border-style: solid;
 			border-color: #000000;
 			border-thickness: 1;
@@ -101,6 +99,7 @@ limitations under the License.
 			iBorderBead: ClassReference('org.apache.flex.html.staticControls.beads.SingleLineBorderBead');
 			iBackgroundBead: ClassReference('org.apache.flex.html.staticControls.beads.SolidBackgroundBead');
 		}
+		
 	</fx:Style>
 	
 	
@@ -112,14 +111,12 @@ limitations under the License.
 		<basic:TextButton text="Show Simple Alert" click="showSimpleAlert()" />
 		<basic:Label text="Displays an Alert which can have multiple buttons." />
 		<basic:TextButton text="Push Me" click="onButtonClick()" />
-		<basic:Container className="numStepper">
-			<basic:beads>
-				<basic:NonVirtualHorizontalLayout />
-			</basic:beads>
-			<basic:Label id="spinMe" width="50" text="Spin: 0" />
-			<basic:Spinner id="spinner" valueChanged="spinnerChanged()" />
-		</basic:Container>
+		<basic:Label id="spinMe" />
+		<basic:NumericStepper id="stepper" 
+							  valueChanged="spinnerChanged(stepper)" 
+							  className="numStepper"
+							  stepSize="10"/>
 	</basic:Panel>
-		
+
 	
 </basic:ViewBase>

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b82ee1a0/frameworks/as/basic-manifest.xml
----------------------------------------------------------------------
diff --git a/frameworks/as/basic-manifest.xml b/frameworks/as/basic-manifest.xml
index e4744aa..533fd9f 100644
--- a/frameworks/as/basic-manifest.xml
+++ b/frameworks/as/basic-manifest.xml
@@ -56,5 +56,6 @@
     <component id="Alert" class="org.apache.flex.html.staticControls.Alert"/>
     <component id="Spinner" class="org.apache.flex.html.staticControls.Spinner"/>
     <component id="ViewBaseDataBinding" class="org.apache.flex.core.ViewBaseDataBinding"/>
+    <component id="NumericStepper" class="org.apache.flex.html.staticControls.NumericStepper" />
 
 </componentPackage>

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b82ee1a0/frameworks/as/defaults.css
----------------------------------------------------------------------
diff --git a/frameworks/as/defaults.css b/frameworks/as/defaults.css
index e5fd96a..b5b9f12 100644
--- a/frameworks/as/defaults.css
+++ b/frameworks/as/defaults.css
@@ -179,6 +179,20 @@ Spinner
     iSpinnerBead:  ClassReference("org.apache.flex.html.staticControls.beads.SpinnerBead");
 }
 
+NumericStepper
+{
+    iNumericStepperModel: ClassReference("org.apache.flex.html.staticControls.beads.models.SpinnerModel");
+    iNumericStepperBead: ClassReference("org.apache.flex.html.staticControls.beads.NumericStepperBead");
+
+    padding: 0px;
+    border-style: solid;
+    border-color: #000000;
+    border-thickness: 1;
+    background-color: #FFFFFF;
+    iBorderBead: ClassReference('org.apache.flex.html.staticControls.beads.SingleLineBorderBead');
+    iBackgroundBead: ClassReference('org.apache.flex.html.staticControls.beads.SolidBackgroundBead');
+}
+
 /* HTML5 */
 
 h5|TextButton

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b82ee1a0/frameworks/as/src/FlexJSUIClasses.as
----------------------------------------------------------------------
diff --git a/frameworks/as/src/FlexJSUIClasses.as b/frameworks/as/src/FlexJSUIClasses.as
index 93101a7..83ca716 100644
--- a/frameworks/as/src/FlexJSUIClasses.as
+++ b/frameworks/as/src/FlexJSUIClasses.as
@@ -46,6 +46,7 @@ internal class FlexJSUIClasses
 	import org.apache.flex.html.staticControls.beads.TitleBarMeasurementBead; TitleBarMeasurementBead;
 	import org.apache.flex.html.staticControls.beads.ControlBarMeasurementBead; ControlBarMeasurementBead;
 	import org.apache.flex.html.staticControls.beads.SpinnerBead; SpinnerBead;
+	import org.apache.flex.html.staticControls.beads.NumericStepperBead; NumericStepperBead;
 	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/b82ee1a0/frameworks/as/src/org/apache/flex/html/staticControls/NumericStepper.as
----------------------------------------------------------------------
diff --git a/frameworks/as/src/org/apache/flex/html/staticControls/NumericStepper.as b/frameworks/as/src/org/apache/flex/html/staticControls/NumericStepper.as
new file mode 100644
index 0000000..bcdf804
--- /dev/null
+++ b/frameworks/as/src/org/apache/flex/html/staticControls/NumericStepper.as
@@ -0,0 +1,95 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.flex.html.staticControls
+{
+	import org.apache.flex.core.IBead;
+	import org.apache.flex.core.ISpinnerModel;
+	import org.apache.flex.core.ValuesManager;
+	import org.apache.flex.html.staticControls.beads.INumericStepperBead;
+
+	[Event(name="valueChanged", type="org.apache.flex.events.Event")]
+	public class NumericStepper extends Container
+	{
+		public function NumericStepper()
+		{
+			super();
+		}
+		
+		public function get value():Number
+		{
+			return ISpinnerModel(model).value;
+		}
+		public function set value(newValue:Number):void
+		{
+			ISpinnerModel(model).value = newValue;
+		}
+		
+		public function get minimum():Number
+		{
+			return ISpinnerModel(model).minimum;
+		}
+		public function set minimum(value:Number):void
+		{
+			ISpinnerModel(model).minimum = value;
+		}
+		
+		public function get maximum():Number
+		{
+			return ISpinnerModel(model).maximum;
+		}
+		public function set maximum(value:Number):void
+		{
+			ISpinnerModel(model).maximum = value;
+		}
+		
+		public function get stepSize():Number
+		{
+			return ISpinnerModel(model).stepSize;
+		}
+		public function set stepSize(value:Number):void
+		{
+			ISpinnerModel(model).stepSize = value;
+		}
+		
+		public function get snapInterval():Number
+		{
+			return ISpinnerModel(model).snapInterval;
+		}
+		public function set snapInterval(value:Number):void
+		{
+			ISpinnerModel(model).snapInterval = value;
+		}
+		
+		override public function initModel():void
+		{
+			if (getBeadByType(ISpinnerModel) == null ) {
+				addBead(new (ValuesManager.valuesImpl.getValue(this, "iNumericStepperModel")) as IBead);
+			}
+		}
+		
+		override public function initSkin():void
+		{
+			super.initSkin();
+			
+			if (getBeadByType(INumericStepperBead) == null ) {
+				addBead(new (ValuesManager.valuesImpl.getValue(this, "iNumericStepperBead")) as IBead);
+			}
+		}
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b82ee1a0/frameworks/as/src/org/apache/flex/html/staticControls/beads/INumericStepperBead.as
----------------------------------------------------------------------
diff --git a/frameworks/as/src/org/apache/flex/html/staticControls/beads/INumericStepperBead.as b/frameworks/as/src/org/apache/flex/html/staticControls/beads/INumericStepperBead.as
new file mode 100644
index 0000000..a79be24
--- /dev/null
+++ b/frameworks/as/src/org/apache/flex/html/staticControls/beads/INumericStepperBead.as
@@ -0,0 +1,27 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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 org.apache.flex.core.IBead;
+	
+	public interface INumericStepperBead extends IBead
+	{
+		
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b82ee1a0/frameworks/as/src/org/apache/flex/html/staticControls/beads/NumericStepperBead.as
----------------------------------------------------------------------
diff --git a/frameworks/as/src/org/apache/flex/html/staticControls/beads/NumericStepperBead.as b/frameworks/as/src/org/apache/flex/html/staticControls/beads/NumericStepperBead.as
new file mode 100644
index 0000000..5cd690a
--- /dev/null
+++ b/frameworks/as/src/org/apache/flex/html/staticControls/beads/NumericStepperBead.as
@@ -0,0 +1,115 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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 org.apache.flex.core.IBead;
+	import org.apache.flex.core.ISpinnerModel;
+	import org.apache.flex.core.IStrand;
+	import org.apache.flex.core.UIBase;
+	import org.apache.flex.createjs.staticControls.Label;
+	import org.apache.flex.events.Event;
+	import org.apache.flex.events.IEventDispatcher;
+	import org.apache.flex.html.staticControls.Spinner;
+	import org.apache.flex.html.staticControls.TextInput;
+	import org.apache.flex.html.staticControls.beads.layouts.NonVirtualHorizontalLayout;
+	
+	public class NumericStepperBead implements IBead, INumericStepperBead
+	{
+		public function NumericStepperBead()
+		{
+		}
+		
+		private var _strand:IStrand;
+		
+		private var label:Label;
+		private var input:TextInput;
+		private var spinner:Spinner;
+		
+		public function set strand(value:IStrand):void
+		{
+			_strand = value;
+			
+			// add a horizontal layout bead
+			value.addBead(new NonVirtualHorizontalLayout());
+			
+			// add an input field
+			input = new TextInput();
+			input.initModel();
+			input.addToParent(value);
+			input.initSkin();
+			
+			// add a spinner
+			spinner = new Spinner();
+			spinner.addBead( value.getBeadByType(ISpinnerModel) );
+			spinner.initModel();
+			spinner.addToParent(value);
+			spinner.initSkin();
+			spinner.width = 17;
+			
+			// listen for changes to the text input field which will reset the
+			// value. ideally, we should either set the input to accept only
+			// numeric values or, barring that, reject non-numeric entries. we
+			// cannot do that right now however.
+			input.model.addEventListener("textChange",inputChangeHandler);
+			
+			// listen for change events on the spinner so the value can be updated as
+			// as resizing the component
+			spinner.addEventListener("valueChanged",spinnerValueChanged);
+			IEventDispatcher(value).addEventListener("widthChanged",sizeChangeHandler);
+			IEventDispatcher(value).addEventListener("heightChanged",sizeChangeHandler);
+			
+			input.text = String(spinner.value);
+			
+			// set a default size which will trigger the sizeChangeHandler
+			var minWidth:Number = Math.max(50+spinner.width,UIBase(value).width);
+			
+			UIBase(value).width = minWidth;
+			UIBase(value).height = spinner.height;
+		}
+		
+		private function sizeChangeHandler(event:Event) : void
+		{
+			input.x = 2;
+			input.y = (UIBase(_strand).height - input.height)/2;
+			input.width = UIBase(_strand).width-spinner.width-2;
+			spinner.x = input.width+2;
+			spinner.y = 0;
+		}
+		
+		private function spinnerValueChanged(event:Event) : void
+		{
+			input.text = String(spinner.value);
+			
+			var newEvent:Event = new Event(event.type,event.bubbles);
+			IEventDispatcher(_strand).dispatchEvent(newEvent);
+		}
+		
+		private function inputChangeHandler(event:Event) : void
+		{
+			var newValue:Number = Number(input.text);
+
+			if( !isNaN(newValue) ) {
+				spinner.value = newValue;
+			}
+			else {
+				input.text = String(spinner.value);
+			}
+		}
+	}
+}
\ No newline at end of file