You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by ha...@apache.org on 2019/01/22 17:09:31 UTC
[royale-asjs] branch feature/redo-formatters updated: Formatters
appear to work
This is an automated email from the ASF dual-hosted git repository.
harbs pushed a commit to branch feature/redo-formatters
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git
The following commit(s) were added to refs/heads/feature/redo-formatters by this push:
new 4fabdc7 Formatters appear to work
4fabdc7 is described below
commit 4fabdc796fb890ef92fc45f14aa5f06e49e30ae8
Author: Harbs <ha...@in-tools.com>
AuthorDate: Tue Jan 22 19:09:20 2019 +0200
Formatters appear to work
---
.../JewelJS/src/main/config/compile-js-config.xml | 1 +
.../src/main/resources/basic-manifest.xml | 6 +-
.../royale/html/accessories/SimpleDateFormatter.as | 4 +-
.../royale/html/accessories/StringDateFormatter.as | 119 +++++++++++++++++++++
frameworks/projects/Jewel/pom.xml | 14 +++
.../Jewel/src/main/config/compile-swf-config.xml | 1 +
.../projects/Jewel/src/main/resources/defaults.css | 2 +-
.../royale/org/apache/royale/jewel/DateField.as | 2 +-
.../controls/datefield/DateFieldMaskedTextInput.as | 37 +++----
.../royale/jewel/beads/views/DateFieldView.as | 14 ++-
10 files changed, 166 insertions(+), 34 deletions(-)
diff --git a/frameworks/js/projects/JewelJS/src/main/config/compile-js-config.xml b/frameworks/js/projects/JewelJS/src/main/config/compile-js-config.xml
index c49c05c..fe6ef45 100644
--- a/frameworks/js/projects/JewelJS/src/main/config/compile-js-config.xml
+++ b/frameworks/js/projects/JewelJS/src/main/config/compile-js-config.xml
@@ -66,6 +66,7 @@
<path-element>../../../../../libs/CollectionsJS.swc</path-element>
<path-element>../../../../../libs/BasicJS.swc</path-element>
<path-element>../../../../../libs/HTMLJS.swc</path-element>
+ <path-element>../../../../../libs/FormattersJS.swc</path-element>
</library-path>
<namespaces>
diff --git a/frameworks/projects/Formatters/src/main/resources/basic-manifest.xml b/frameworks/projects/Formatters/src/main/resources/basic-manifest.xml
index 05bc912..8f998e5 100644
--- a/frameworks/projects/Formatters/src/main/resources/basic-manifest.xml
+++ b/frameworks/projects/Formatters/src/main/resources/basic-manifest.xml
@@ -20,11 +20,13 @@
<componentPackage>
+ <component id="CurrencyFormatter" class="org.apache.royale.html.accessories.CurrencyFormatter"/>
+ <component id="DateAndTimeFormatter" class="org.apache.royale.html.accessories.DateAndTimeFormatter"/>
<component id="DateFormatter" class="org.apache.royale.html.accessories.SimpleDateFormatter"/>
<component id="DateFormatDDMMYYYY" class="org.apache.royale.html.accessories.DateFormatDDMMYYYY"/>
<component id="DateFormatMMDDYYYY" class="org.apache.royale.html.accessories.DateFormatMMDDYYYY"/>
<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"/>
+ <component id="SimpleDateFormatter" class="org.apache.royale.html.accessories.SimpleDateFormatter"/>
+ <component id="StringDateFormatter" class="org.apache.royale.html.accessories.StringDateFormatter"/>
</componentPackage>
diff --git a/frameworks/projects/Formatters/src/main/royale/org/apache/royale/html/accessories/SimpleDateFormatter.as b/frameworks/projects/Formatters/src/main/royale/org/apache/royale/html/accessories/SimpleDateFormatter.as
index 05860bf..b2d7656 100644
--- a/frameworks/projects/Formatters/src/main/royale/org/apache/royale/html/accessories/SimpleDateFormatter.as
+++ b/frameworks/projects/Formatters/src/main/royale/org/apache/royale/html/accessories/SimpleDateFormatter.as
@@ -45,7 +45,7 @@ package org.apache.royale.html.accessories
}
private var _dateFormat:String;
- private var _separator:String;
+ protected var _separator:String;
/**
* The dateFormat of the date string.
@@ -103,7 +103,7 @@ package org.apache.royale.html.accessories
var month:String = String(selectedDate.getMonth()+1);
var day:String = String(selectedDate.getDate());
var year:String = String(selectedDate.getFullYear());
- var tokens:Array = _dateFormat.split(_separator);
+ var tokens:Array = dateFormat.split(_separator);
var length:int = tokens.length;
diff --git a/frameworks/projects/Formatters/src/main/royale/org/apache/royale/html/accessories/StringDateFormatter.as b/frameworks/projects/Formatters/src/main/royale/org/apache/royale/html/accessories/StringDateFormatter.as
new file mode 100644
index 0000000..2ce8c15
--- /dev/null
+++ b/frameworks/projects/Formatters/src/main/royale/org/apache/royale/html/accessories/StringDateFormatter.as
@@ -0,0 +1,119 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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.FormatBase;
+ /**
+ * Formats a date from a string
+ * Because of the compleixities of date formatting, this formatter does not
+ * differentiate between single digit formats and double digit formats for days and months.
+ */
+ public class StringDateFormatter extends SimpleDateFormatter
+ {
+ public function StringDateFormatter()
+ {
+ super();
+ }
+ /**
+ * Formats the date.
+ * If a String is passed in, the date string is formatted using the dateFormat.
+ * If a Date is passed in, it formats the same as other Date formatters.
+ */
+ override public function format(value:Object):String
+ {
+ if(value is Date)
+ {
+ return super.format(value);
+ }
+ var str:String = value as String;
+ str = str.replace(/[^0-9]/g,"");
+ var result:String = "";
+ var tokens:Array = dateFormat.split(_separator);
+ var length:int = tokens.length;
+ var part:String;
+ var val:Number;
+
+ for (var i:int = 0; i < length; i++) {
+ if(!str)
+ break;
+ switch (tokens[i]) {
+ case "YYYY":
+ part = str.substr(0,4);
+ str = str.substr(4);
+ result += part;
+ break;
+ case "YY":
+ part = str.substr(0,2);
+ str = str.substr(2);
+ result += part;
+ break;
+ case "M":
+ case "MM":
+ part = str.substr(0,2);
+ val = Number(part);
+ if(val > 12)// should be single digit
+ {
+ part = "0" + str.substr(0,1);
+ str = str.substr(1);
+ } else
+ {
+ // part is ok. We need to slice the str
+ str = str.substr(2);
+ }
+ result += part;
+ break;
+ case "DD":
+ case "D":
+ part = str.substr(0,2);
+ val = Number(part);
+ if(val > 31)// should be single digit
+ {
+ part = "0" + str.substr(0,1);
+ str = str.substr(1);
+ } else
+ {
+ // part is ok. We need to slice the str
+ str = str.substr(2);
+ }
+ result += part;
+ break;
+ }
+ // if there's no more left, str is empty and no separator
+ if (str && i <= length - 2) {
+ result += _separator;
+ }
+ }
+
+ return result;
+ }
+ // Some calendar systems can have a different value
+ private var _maxMonths:Number = 12;
+ private function isValidMonth(value:Number):Boolean
+ {
+ if(isNaN(value))
+ return false;
+ if(Math.round(value) != value)
+ return false;
+ if(value > _maxMonths)
+ return false;
+
+ return true;
+ }
+ }
+}
\ No newline at end of file
diff --git a/frameworks/projects/Jewel/pom.xml b/frameworks/projects/Jewel/pom.xml
index 2ac6519..74d84db 100644
--- a/frameworks/projects/Jewel/pom.xml
+++ b/frameworks/projects/Jewel/pom.xml
@@ -181,6 +181,20 @@
<type>swc</type>
<classifier>js</classifier>
</dependency>
+ <dependency>
+ <groupId>org.apache.royale.framework</groupId>
+ <artifactId>Formatters</artifactId>
+ <version>0.9.6-SNAPSHOT</version>
+ <type>swc</type>
+ <classifier>swf</classifier>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.royale.framework</groupId>
+ <artifactId>Formatters</artifactId>
+ <version>0.9.6-SNAPSHOT</version>
+ <type>swc</type>
+ <classifier>js</classifier>
+ </dependency>
</dependencies>
</project>
diff --git a/frameworks/projects/Jewel/src/main/config/compile-swf-config.xml b/frameworks/projects/Jewel/src/main/config/compile-swf-config.xml
index 9656867..10f07d4 100644
--- a/frameworks/projects/Jewel/src/main/config/compile-swf-config.xml
+++ b/frameworks/projects/Jewel/src/main/config/compile-swf-config.xml
@@ -35,6 +35,7 @@
<path-element>../../../../../libs/Basic.swc</path-element>
<path-element>../../../../../libs/Collections.swc</path-element>
<path-element>../../../../../libs/HTML.swc</path-element>
+ <path-element>../../../../../libs/Formatters.swc</path-element>
</external-library-path>
<allow-subclass-overrides>true</allow-subclass-overrides>
diff --git a/frameworks/projects/Jewel/src/main/resources/defaults.css b/frameworks/projects/Jewel/src/main/resources/defaults.css
index 3b7cbed..9efadea 100644
--- a/frameworks/projects/Jewel/src/main/resources/defaults.css
+++ b/frameworks/projects/Jewel/src/main/resources/defaults.css
@@ -568,7 +568,7 @@ j|DateField {
IBeadView: ClassReference("org.apache.royale.jewel.beads.views.DateFieldView");
IBeadModel: ClassReference("org.apache.royale.jewel.beads.models.DateChooserModel");
IBeadController: ClassReference("org.apache.royale.jewel.beads.controllers.DateFieldMouseController");
- IFormatter: ClassReference("org.apache.royale.html.accessories.DateFormatMMDDYYYY");
+ IFormatter: ClassReference("org.apache.royale.html.accessories.StringDateFormatter");
IPopUp: ClassReference("org.apache.royale.jewel.DateChooser");
}
diff --git a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/DateField.as b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/DateField.as
index 4053474..8bb8eb5 100644
--- a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/DateField.as
+++ b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/DateField.as
@@ -76,7 +76,7 @@ package org.apache.royale.jewel
override public function addedToParent():void
{
super.addedToParent();
- loadBeadFromValuesManager(IFormatter, "IFormatter", this);
+ loadBeadFromValuesManager(IFormatter, "iFormatter", this);
loadBeadFromValuesManager(IDateControlConfigBead, "iDateControlConfigBead", this);
diff --git a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/controls/datefield/DateFieldMaskedTextInput.as b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/controls/datefield/DateFieldMaskedTextInput.as
index b003690..b35c602 100644
--- a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/controls/datefield/DateFieldMaskedTextInput.as
+++ b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/controls/datefield/DateFieldMaskedTextInput.as
@@ -33,6 +33,7 @@ package org.apache.royale.jewel.beads.controls.datefield
import org.apache.royale.core.UIBase;
import org.apache.royale.events.Event;
import org.apache.royale.events.IEventDispatcher;
+ import org.apache.royale.core.IFormatter;
/**
* The DateFieldMaskedTextInput class is a specialty bead that is used
@@ -116,6 +117,18 @@ package org.apache.royale.jewel.beads.controls.datefield
var n:Number = Number(value);
if (isNaN(n)) event.preventDefault();
}
+
+ private var _formatter:IFormatter;
+
+ public function get formatter():IFormatter
+ {
+ return _formatter;
+ }
+
+ public function set formatter(value:IFormatter):void
+ {
+ _formatter = value;
+ }
COMPILE::JS
private function validateInput(event:BrowserEvent):void
@@ -156,29 +169,7 @@ package org.apache.royale.jewel.beads.controls.datefield
* (TODO carlosrovira): this should take into account IFormatter
*/
private function dateInputMask(event:BrowserEvent):void {
- if(event.keyCode < 47 || event.keyCode > 57) {
- event.preventDefault();
- }
-
- var len:int = event.target.value.length;
-
- // If we're at a particular place, let the user type the slash
- // i.e., 12/12/1212
- if(len !== 1 || len !== 3) {
- if(event.keyCode == 47) {
- event.preventDefault();
- }
- }
-
- // If they don't add the slash, do it for them...
- if(len === 2) {
- event.target.value += '/';
- }
-
- // If they don't add the slash, do it for them...
- if(len === 5) {
- event.target.value += '/';
- }
+ event.target.value = formatter.format(event.target.value);
}
}
}
diff --git a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/views/DateFieldView.as b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/views/DateFieldView.as
index fb1f9e5..1ba239b 100644
--- a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/views/DateFieldView.as
+++ b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/views/DateFieldView.as
@@ -122,11 +122,6 @@ package org.apache.royale.jewel.beads.views
super.strand = value;
_textInput = new TextInput();
- _textInput.addBead(new DateFieldMaskedTextInput());
-
- var maxNumberCharacters:MaxNumberCharacters = new MaxNumberCharacters();
- maxNumberCharacters.maxlength = 10;
- _textInput.addBead(maxNumberCharacters);
getHost().addElement(_textInput);
@@ -159,6 +154,15 @@ package org.apache.royale.jewel.beads.views
{
model = _strand.getBeadByType(IDateChooserModel) as IDateChooserModel;
IEventDispatcher(model).addEventListener("selectedDateChanged", selectionChangeHandler);
+ var mask:DateFieldMaskedTextInput = new DateFieldMaskedTextInput();
+ _textInput.addBead(mask);
+
+ var maxNumberCharacters:MaxNumberCharacters = new MaxNumberCharacters();
+ maxNumberCharacters.maxlength = 10;
+ _textInput.addBead(maxNumberCharacters);
+
+ var formatter:IFormatter = _strand.getBeadByType(IFormatter) as IFormatter;
+ mask.formatter = formatter;
}
private function handlePopUpInitComplete(event:Event):void