royale-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ha...@apache.org
Subject [royale-asjs] 13/14: Add a wrapper bead the date formatter to add hours
Date Sun, 02 Sep 2018 08:57:43 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit 3650e4e3c626d4590ba8b1fd5f601fe25d63dd75
Author: DESKTOP-RH4S838\Yishay <yishayjobs@hotmail.com>
AuthorDate: Thu Aug 23 09:28:21 2018 +0300

    Add a wrapper bead the date formatter to add hours
---
 .../src/main/resources/basic-manifest.xml          |   1 +
 .../html/accessories/DateAndTimeFormatter.as       | 175 +++++++++++++++++++++
 2 files changed, 176 insertions(+)

diff --git a/frameworks/projects/Formatters/src/main/resources/basic-manifest.xml b/frameworks/projects/Formatters/src/main/resources/basic-manifest.xml
index ce9d2d4..05bc912 100644
--- a/frameworks/projects/Formatters/src/main/resources/basic-manifest.xml
+++ b/frameworks/projects/Formatters/src/main/resources/basic-manifest.xml
@@ -26,4 +26,5 @@
     <component id="DateFormatYYYYMMDD" class="org.apache.royale.html.accessories.DateFormatYYYYMMDD"/>
     <component id="NumberFormatter" class="org.apache.royale.html.accessories.NumberFormatter"/>
     <component id="CurrencyFormatter" class="org.apache.royale.html.accessories.CurrencyFormatter"/>
+    <component id="DateAndTimeFormatter" class="org.apache.royale.html.accessories.DateAndTimeFormatter"/>
 </componentPackage>
diff --git a/frameworks/projects/Formatters/src/main/royale/org/apache/royale/html/accessories/DateAndTimeFormatter.as
b/frameworks/projects/Formatters/src/main/royale/org/apache/royale/html/accessories/DateAndTimeFormatter.as
new file mode 100644
index 0000000..0b3c09d
--- /dev/null
+++ b/frameworks/projects/Formatters/src/main/royale/org/apache/royale/html/accessories/DateAndTimeFormatter.as
@@ -0,0 +1,175 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.royale.html.accessories
+{
+	import org.apache.royale.core.IBead;
+	import org.apache.royale.core.IBeadModel;
+	import org.apache.royale.core.Strand;
+	import org.apache.royale.core.IDateChooserModel;
+	import org.apache.royale.core.IFormatBead;
+	import org.apache.royale.core.IStrand;
+	import org.apache.royale.core.IStrandWithModel;
+	import org.apache.royale.events.Event;
+	import org.apache.royale.events.IEventDispatcher;
+	
+	/**
+	 * The DateFormatter class wraps an IFormatBead and adds an hour.
+	 *  
+	 *  @royaleignoreimport org.apache.royale.core.IStrandWithModel
+	 * 
+	 *  @langversion 3.0
+	 *  @playerversion Flash 10.2
+	 *  @playerversion AIR 2.6
+	 *  @productversion Royale 0.9.3
+	 */
+	public class DateAndTimeFormatter extends Strand implements IFormatBead
+	{
+
+		private var _formattedResult:String;
+		private var _originalFormatter:IFormatBead;
+		private var _model:IDateChooserModel;
+		private var _strand:IStrand;
+		/**
+		 *  The name of the property on the model holding the value to be formatted.
+		 *  The default is selectedDate.
+		 *  
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion Royale 0.9.3
+		 */
+		public function get propertyName():String
+		{
+			return _originalFormatter.propertyName;
+		}
+
+		public function set propertyName(value:String):void
+		{
+			_originalFormatter.propertyName = value;
+		}
+		
+		/**
+		 *  The name of the event dispatched when the property changes. The
+		 *  default is selectedDateChanged.
+		 *  
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion Royale 0.9.3
+		 */
+		public function get eventName():String
+		{
+			return _originalFormatter.eventName;
+		}
+
+		public function set eventName(value:String):void
+		{
+			_originalFormatter.eventName = value;
+		}
+
+		/**
+		 *  The formatted result.
+		 *  
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion Royale 0.9.3
+		 */
+		public function get formattedString():String
+		{
+			return _formattedResult;
+		}
+		
+		
+		/**
+		 *  @copy org.apache.royale.core.IBead#strand
+		 *  
+		 *  @royaleignorecoercion org.apache.royale.core.IStrandWithModel
+		 * 
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion Royale 0.9.3
+		 */
+		public function set strand(value:IStrand):void
+		{
+			_strand = value;
+			_model = IStrandWithModel(_strand).model as IDateChooserModel;
+			if (_originalFormatter)
+			{
+				addBead(_originalFormatter);
+			} else
+			{
+				_originalFormatter = getBeadByType(IFormatBead) as IFormatBead;
+			}
+			IEventDispatcher(_originalFormatter).addEventListener('formatChanged', formatChangedHandler);
+		}
+		
+		/**
+		 *  @copy org.apache.royale.core.UIBase#model
+		 *  
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion Royale 0.9.3
+		 */
+		override public function get model():IBeadModel
+		{
+			return _model;
+		}
+
+		override public function addBead(bead:IBead):void
+		{
+			if (model)
+			{
+				super.addBead(bead);
+			} else
+			{
+				_originalFormatter = bead as IFormatBead;
+			}
+		}
+
+		private function formatChangedHandler(event:Event):void
+		{
+			var dateResult:String = _originalFormatter.formattedString;
+			var selectedDate:Date = _model.selectedDate;
+			_formattedResult = getFormattedResult(selectedDate);
+			dispatchEvent(new Event('formatChanged'));
+		}
+
+		protected function getFormattedResult(date:Date):String
+		{
+			var formattedHour:String = getFormattedHour(date);
+			return _originalFormatter.formattedString + " " + formattedHour;
+		}
+		
+		private function getNumberAsPaddedString(value:Number):String
+		{
+			return (value < 10 ? "0" : "") + value;
+		}
+
+		protected function getFormattedHour(date:Date):String
+		{
+			var hours:String = getNumberAsPaddedString(date.getHours());
+			var minutes:String = getNumberAsPaddedString(date.getMinutes());
+			var seconds:String = getNumberAsPaddedString(date.getSeconds());
+			return hours + ":" + minutes + ":" + seconds;
+		}
+	}
+}


Mime
View raw message