royale-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From carlosrov...@apache.org
Subject [royale-asjs] branch develop updated: jewel slider working ok
Date Thu, 12 Apr 2018 16:25:42 GMT
This is an automated email from the ASF dual-hosted git repository.

carlosrovira pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git


The following commit(s) were added to refs/heads/develop by this push:
     new ae10781  jewel slider working ok
ae10781 is described below

commit ae10781c7ae7a5ee61ce52a9461540ddf0468548
Author: Carlos Rovira <carlosrovira@apache.org>
AuthorDate: Thu Apr 12 18:25:38 2018 +0200

    jewel slider working ok
---
 .../src/main/royale/SliderPlayGround.mxml          | 32 ++++++++++++--
 .../main/royale/org/apache/royale/jewel/Slider.as  |  2 +-
 .../beads/controllers/SliderMouseController.as     | 49 +++++++++++++++-------
 .../royale/jewel/beads/models/SliderRangeModel.as  |  4 +-
 .../apache/royale/jewel/beads/views/SliderView.as  | 18 ++++++--
 5 files changed, 80 insertions(+), 25 deletions(-)

diff --git a/examples/royale/JewelExample/src/main/royale/SliderPlayGround.mxml b/examples/royale/JewelExample/src/main/royale/SliderPlayGround.mxml
index 0886393..c64d197 100644
--- a/examples/royale/JewelExample/src/main/royale/SliderPlayGround.mxml
+++ b/examples/royale/JewelExample/src/main/royale/SliderPlayGround.mxml
@@ -25,12 +25,31 @@ limitations under the License.
     
 	<fx:Script>
 		<![CDATA[
-        private function onChange(event:Event):void
+		
+		private function clickHandler(event:MouseEvent):void
+		{
+			trace("clickHandler");
+			slider_w.value = 400;
+			slider_h.value = 200;
+		}
+
+        private function onInput(event:Event):void
         {
+			trace("onInput");
         	button.width = slider_w.value;
 			button.height = slider_h.value;
 			button.text = slider_w.value + "x" + slider_h.value;
         }
+
+		private function onChange(event:Event):void
+        {
+			trace("onChange");
+		}
+
+		private function onValueChange(event:Event):void
+        {
+			trace("onValueChange");
+		}
     	]]>
 	</fx:Script>
 
@@ -41,9 +60,13 @@ limitations under the License.
 	<html:H3 text="Jewel Slider"/>
 	
 	<j:Slider id="slider_w" width="250" value="250" minimum="100" maximum="500"
-				change="onChange(event)" input="onChange(event)"/>
+				change="onChange(event)" 
+				input="onInput(event)"
+				valueChange="onValueChange(event)"/>
 	<j:Slider id="slider_h" width="250" value="80" minimum="40" maximum="300"
-				change="onChange(event)" input="onChange(event)"/>
+				change="onChange(event)" 
+				input="onInput(event)"
+				valueChange="onValueChange(event)"/>
 
 	<j:Slider id="slider_dis" width="250" value="70" minimum="0" maximum="100">
 		<j:beads>
@@ -51,6 +74,7 @@ limitations under the License.
 		</j:beads>
 	</j:Slider>
 
-	<j:TextButton id="button" text="Button" width="250" height="140" primary="true"/>
+	<j:TextButton id="button" text="Slider to 400x200" width="250" height="80" primary="true"
+					click="clickHandler(event)"/>
 
 </js:Group>
diff --git a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/Slider.as b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/Slider.as
index 99b02a6..8a7b2e8 100644
--- a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/Slider.as
+++ b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/Slider.as
@@ -41,7 +41,7 @@ package org.apache.royale.jewel
      *  @playerversion AIR 2.6
      *  @productversion Royale 0.9.3
      */
-	[Event(name="valueChange", type="org.apache.royale.events.Event")]
+	[Event(name="valueChange", type="org.apache.royale.events.ValueChangeEvent")]
 
      /**
      *  Dispatched when Slider ends its change from one position to another.
diff --git a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/controllers/SliderMouseController.as
b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/controllers/SliderMouseController.as
index 59f53d8..0b7b2f3 100644
--- a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/controllers/SliderMouseController.as
+++ b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/controllers/SliderMouseController.as
@@ -29,14 +29,14 @@ package org.apache.royale.jewel.beads.controllers
 	import org.apache.royale.events.ValueChangeEvent;
 	import org.apache.royale.geom.Point;
 	import org.apache.royale.html.beads.ISliderView;
+    import org.apache.royale.jewel.beads.views.SliderView;
+    import org.apache.royale.jewel.Slider;
 
     COMPILE::JS
     {
         import goog.events;
         import goog.events.EventType;
         import org.apache.royale.events.BrowserEvent;
-        import org.apache.royale.jewel.Slider;
-        import org.apache.royale.jewel.beads.views.SliderView;
     }
 	
 	/**
@@ -78,6 +78,8 @@ package org.apache.royale.jewel.beads.controllers
 		private var _strand:IStrand;
 
 		private var oldValue:Number;
+
+		public var sliderView:ISliderView;
 				
 		/**
 		 *  @copy org.apache.royale.core.IBead#strand
@@ -109,11 +111,36 @@ package org.apache.royale.jewel.beads.controllers
                 goog.events.listen(UIBase(_strand).element, goog.events.EventType.CHANGE,
handleChange, false, this);
                 goog.events.listen(UIBase(_strand).element, goog.events.EventType.INPUT,
handleInput, false, this);
 
-				changeStyles();
+				SliderView(sliderView).redraw();
             }
+
+			// listen for changes to the model and adjust the model accordingly.
+			IEventDispatcher(rangeModel).addEventListener("valueChange",modelChangeHandler);
+			IEventDispatcher(rangeModel).addEventListener("stepSizeChange", modelChangeHandler);
+			IEventDispatcher(rangeModel).addEventListener("minimumChange", modelChangeHandler);
+			IEventDispatcher(rangeModel).addEventListener("maximumChange", modelChangeHandler);
+			IEventDispatcher(rangeModel).addEventListener("valueChange", modelChangeHandler);
 		}
 
-		public var sliderView:ISliderView;
+		/**
+		 * @private
+		 * @royaleignorecoercion org.apache.royale.core.UIBase
+		 * @royaleignorecoercion org.apache.royale.core.IRangeModel
+		 */
+		private function modelChangeHandler( event:Event ) : void
+		{
+			COMPILE::JS
+			{
+				SliderView(sliderView).redraw();
+
+				// value has change so dispatch VALUE_CHANGE event to the strand
+				if(event is ValueChangeEvent) {
+					IEventDispatcher(_strand).dispatchEvent(event.cloneEvent());
+				}
+			}
+		}
+
+		
 
 		/**
          *  Manages the change event to update the range model value
@@ -130,7 +157,7 @@ package org.apache.royale.jewel.beads.controllers
 
             rangeModel.value = Number((UIBase(_strand).element as HTMLInputElement).value);
 
-			changeStyles();
+			SliderView(sliderView).redraw();
 
             //host.dispatchEvent(new org.apache.royale.events.Event('change')); --- This
is not needed, the event is thrown in the main comp
         }
@@ -152,19 +179,9 @@ package org.apache.royale.jewel.beads.controllers
 
             host.dispatchEvent(new org.apache.royale.events.Event('input'));
 
-			changeStyles();
+			SliderView(sliderView).redraw();
         }
 
-		COMPILE::JS
-        private function changeStyles():void
-        {
-			var barsize:Number = (rangeModel.value - rangeModel.minimum) / (rangeModel.maximum - rangeModel.minimum);
-
-			SliderView(sliderView).sliderTrack.style.flex = ( 1 - barsize ).toString();
-			SliderView(sliderView).sliderTrackFill.style.flex = barsize.toString();
-		}
-
-
 		COMPILE::SWF
 		private var origin:Point;
         COMPILE::SWF
diff --git a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/models/SliderRangeModel.as
b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/models/SliderRangeModel.as
index c7055a7..0d227b4 100644
--- a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/models/SliderRangeModel.as
+++ b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/models/SliderRangeModel.as
@@ -23,6 +23,7 @@ package org.apache.royale.jewel.beads.models
     import org.apache.royale.core.IStrand;
     import org.apache.royale.events.EventDispatcher;
     import org.apache.royale.events.Event;
+    import org.apache.royale.events.ValueChangeEvent;
 
     /**
      *  The SliderRangeModel class bead defines a set of for a numeric range of values
@@ -190,8 +191,9 @@ package org.apache.royale.jewel.beads.models
         {
             if (value != _value)
             {
+                var newEvent:ValueChangeEvent = ValueChangeEvent.createUpdateEvent(_strand,
"value", _value, value);
                 _value = value;
-                dispatchEvent(new Event("valueChange"));
+                dispatchEvent(newEvent);
             }
         }
     }
diff --git a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/views/SliderView.as
b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/views/SliderView.as
index d41eccc..29d7148 100644
--- a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/views/SliderView.as
+++ b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/views/SliderView.as
@@ -35,6 +35,7 @@ package org.apache.royale.jewel.beads.views
     import org.apache.royale.core.ValuesManager;
     import org.apache.royale.events.Event;
     import org.apache.royale.events.IEventDispatcher;
+	import org.apache.royale.events.ValueChangeEvent;
     import org.apache.royale.jewel.Button;
 	
 	/**
@@ -62,10 +63,11 @@ package org.apache.royale.jewel.beads.views
 			super();
 		}
 		
+        private var rangeModel:IRangeModel;
+		
 		private var _track:Button;
-		private var _thumb:Button;
 
-        private var rangeModel:IRangeModel;
+		private var _thumb:Button;
 		
 		/**
 		 *  The track component.
@@ -157,6 +159,15 @@ package org.apache.royale.jewel.beads.views
 
 		COMPILE::JS
 		public var sliderTrack:HTMLDivElement;
+
+		COMPILE::JS
+        public function redraw():void
+        {
+			var barsize:Number = (rangeModel.value - rangeModel.minimum) / (rangeModel.maximum - rangeModel.minimum);
+
+			sliderTrack.style.flex = ( 1 - barsize ).toString();
+			sliderTrackFill.style.flex = barsize.toString();
+		}
 		
 		/**
 		 * @private
@@ -170,13 +181,14 @@ package org.apache.royale.jewel.beads.views
 		{
 			COMPILE::JS
 			{
+				
 				var inputElement:HTMLInputElement = (UIBase(_strand).element as HTMLInputElement);
 				inputElement.step = String(rangeModel.stepSize);
 				inputElement.min = String(rangeModel.minimum);
 				inputElement.max = String(rangeModel.maximum);
 				inputElement.value = rangeModel.value.toString();
 			}
-
+			
 			//(_strand as IEventDispatcher).dispatchEvent(new Event("layoutNeeded"));
 		}
 	}

-- 
To stop receiving notification emails like this one, please contact
carlosrovira@apache.org.

Mime
View raw message