You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by gr...@apache.org on 2020/03/25 10:45:42 UTC
[royale-asjs] 05/06: Adding ZipCodeFormatter (function still to be
verified/tested)
This is an automated email from the ASF dual-hosted git repository.
gregdove pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git
commit 370efba0e62af0177975782989864204b8528eb7
Author: greg-dove <gr...@gmail.com>
AuthorDate: Wed Mar 25 13:30:22 2020 +1300
Adding ZipCodeFormatter (function still to be verified/tested)
---
.../MXRoyale/src/main/royale/MXRoyaleClasses.as | 1 +
.../royale/mx/formatters/SwitchSymbolFormatter.as | 11 +-
.../main/royale/mx/formatters/ZipCodeFormatter.as | 296 +++++++++++++++++++++
3 files changed, 302 insertions(+), 6 deletions(-)
diff --git a/frameworks/projects/MXRoyale/src/main/royale/MXRoyaleClasses.as b/frameworks/projects/MXRoyale/src/main/royale/MXRoyaleClasses.as
index 50e7b37..c2fab52 100644
--- a/frameworks/projects/MXRoyale/src/main/royale/MXRoyaleClasses.as
+++ b/frameworks/projects/MXRoyale/src/main/royale/MXRoyaleClasses.as
@@ -138,6 +138,7 @@ internal class MXRoyaleClasses
import mx.styles.StyleManagerImpl; StyleManagerImpl;
import mx.modules.IModuleInfo; IModuleInfo;
import mx.formatters.SwitchSymbolFormatter; SwitchSymbolFormatter;
+ import mx.formatters.ZipCodeFormatter; ZipCodeFormatter;
import mx.printing.FlexPrintJob; FlexPrintJob;
import mx.utils.URLUtil; URLUtil;
import mx.core.UITextField; UITextField;
diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/formatters/SwitchSymbolFormatter.as b/frameworks/projects/MXRoyale/src/main/royale/mx/formatters/SwitchSymbolFormatter.as
index 8287c09..f357484 100644
--- a/frameworks/projects/MXRoyale/src/main/royale/mx/formatters/SwitchSymbolFormatter.as
+++ b/frameworks/projects/MXRoyale/src/main/royale/mx/formatters/SwitchSymbolFormatter.as
@@ -87,8 +87,7 @@ public class SwitchSymbolFormatter
{
super();
- //this.numberSymbol = numberSymbol;
- //isValid = true;
+ this.numberSymbol = numberSymbol;
}
//--------------------------------------------------------------------------
@@ -100,12 +99,12 @@ public class SwitchSymbolFormatter
/**
* @private
*/
- // private var numberSymbol:String;
+ private var numberSymbol:String;
/**
* @private
*/
- // private var isValid:Boolean;
+ private var isValid:Boolean = true;
//--------------------------------------------------------------------------
//
@@ -129,7 +128,7 @@ public class SwitchSymbolFormatter
* @playerversion AIR 1.1
* @productversion Royale 0.9.3
*/
- /* public function formatValue(format:String, source:Object):String
+ public function formatValue(format:String, source:Object):String
{
var numStr:String = "";
@@ -146,7 +145,7 @@ public class SwitchSymbolFormatter
}
return numStr;
- } */
+ }
}
}
diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/formatters/ZipCodeFormatter.as b/frameworks/projects/MXRoyale/src/main/royale/mx/formatters/ZipCodeFormatter.as
new file mode 100644
index 0000000..704d007
--- /dev/null
+++ b/frameworks/projects/MXRoyale/src/main/royale/mx/formatters/ZipCodeFormatter.as
@@ -0,0 +1,296 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 mx.formatters
+{
+
+import mx.managers.ISystemManager;
+import mx.managers.SystemManager;
+
+//[ResourceBundle("formatters")]
+
+/**
+ * The ZipCodeFormatter class formats a valid number
+ * into one of the following formats, based on a
+ * user-supplied <code>formatString</code> property.
+ *
+ * <ul>
+ * <li>#####-####</li>
+ * <li>##### ####</li>
+ * <li>#####</li>
+ * <li>### ### (Canadian)</li>
+ * </ul>
+ *
+ * <p>A six-digit number must be supplied for a six-digit mask.
+ * If you use a five-digit or a nine-digit mask, you can use
+ * either a five-digit or a nine-digit number for formatting.</p>
+ *
+ * <p>If an error occurs, an empty String is returned and a String that
+ * describes the error is saved to the <code>error</code> property.
+ * The <code>error</code> property can have one of the following values:</p>
+ *
+ * <ul>
+ * <li><code>"Invalid value"</code> means an invalid numeric value is passed
+ * to the <code>format()</code> method. The value should be a valid number
+ * in the form of a Number or a String, except for Canadian postal code,
+ * which allows alphanumeric values, or the number of digits does not match
+ * the allowed digits from the <code>formatString</code> property.</li>
+ * <li> <code>"Invalid format"</code> means any of the characters in the
+ * <code>formatString</code> property do not match the allowed characters
+ * specified in the <code>validFormatChars</code> property,
+ * or the number of numeric placeholders does not equal 9, 5, or 6.</li>
+ * </ul>
+ *
+ * @mxml
+ *
+ * <p>The <code><mx:ZipCodeFormatter></code> tag
+ * inherits all of the tag attributes of its superclass,
+ * and adds the following tag attributes:</p>
+ *
+ * <pre>
+ * <mx:ZipCodeFormatter
+ * formatString="#####|#####-####|### ###"
+ * />
+ * </pre>
+ *
+ * @includeExample examples/ZipCodeFormatterExample.mxml
+ *
+ * @see mx.formatters.SwitchSymbolFormatter
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ */
+public class ZipCodeFormatter extends Formatter
+{
+ //include "../core/Version.as";
+
+ //--------------------------------------------------------------------------
+ //
+ // Class constants
+ //
+ //--------------------------------------------------------------------------
+
+ /**
+ * @private
+ */
+ private static const VALID_LENGTHS:String = "9,5,6";
+
+ //--------------------------------------------------------------------------
+ //
+ // Constructor
+ //
+ //--------------------------------------------------------------------------
+
+ /**
+ * Constructor.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ */
+ public function ZipCodeFormatter()
+ {
+ super();
+ }
+
+ //--------------------------------------------------------------------------
+ //
+ // Properties
+ //
+ //--------------------------------------------------------------------------
+
+ //----------------------------------
+ // formatString
+ //----------------------------------
+
+ /**
+ * @private
+ * Storage for the formatString property.
+ */
+ private var _formatString:String;
+
+ /**
+ * @private
+ */
+ private var formatStringOverride:String;
+
+ [Inspectable(category="General", defaultValue="null")]
+
+ /**
+ * The mask pattern.
+ * Possible values are <code>"#####-####"</code>,
+ * <code>"##### ####"</code>, <code>"#####"</code>,
+ * <code>"###-###"</code> and <code>"### ###"</code>.
+ *
+ * @default "#####"
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ */
+ public function get formatString():String
+ {
+ return _formatString;
+ }
+
+ /**
+ * @private
+ */
+ public function set formatString(value:String):void
+ {
+ formatStringOverride = value;
+
+ _formatString = value != null ?
+ value : '#####';
+ /*resourceManager.getString(
+ "formatters", "zipCodeFormat")*/;
+ }
+
+ //--------------------------------------------------------------------------
+ //
+ // Overidden methods
+ //
+ //--------------------------------------------------------------------------
+
+ /**
+ * @private
+ */
+ /*override protected function resourcesChanged():void
+ {
+ super.resourcesChanged();
+
+ formatString = formatStringOverride;
+ }*/
+
+ /**
+ * Formats the String by using the specified format.
+ * If the value cannot be formatted, return an empty String
+ * and write a description of the error to the <code>error</code> property.
+ *
+ * @param value Value to format.
+ *
+ * @return Formatted String. Empty if an error occurs. A description
+ * of the error condition is written to the <code>error</code> property.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ */
+ override public function format(value:Object):String
+ {
+ // Reset any previous errors.
+ if (error)
+ error = null;
+
+ // -- lengths --
+
+ var fStrLen:int;
+ var uStrLen:int = String(value).length;
+
+ if (VALID_LENGTHS.indexOf("" + uStrLen) == -1)
+ {
+ error = defaultInvalidValueError;
+ return "";
+ }
+
+ if (formatString == "#####-####" || formatString == "##### ####")
+ {
+ if (uStrLen != 5 && uStrLen != 9)
+ {
+ error = defaultInvalidValueError;
+ return "";
+ }
+ fStrLen = 9;
+ }
+
+ else if (formatString == "#####")
+ {
+ if (uStrLen != 5 && uStrLen != 9)
+ {
+ error = defaultInvalidValueError;
+ return "";
+ }
+ fStrLen = 5;
+ }
+
+ else if (formatString == "### ###" || formatString == "###-###")
+ {
+ if (uStrLen != 6)
+ {
+ error = defaultInvalidValueError;
+ return "";
+ }
+ fStrLen = 6;
+ }
+
+ else
+ {
+ error = defaultInvalidFormatError;
+ return "";
+ }
+
+ if (fStrLen == 6 && uStrLen != 6)
+ {
+ error = defaultInvalidValueError;
+ return "";
+ }
+
+ // -- value --
+
+ if (fStrLen == 6)
+ {
+ for (var i:int = 0; i < uStrLen; i++)
+ {
+ if ((value.charCodeAt(i) < 64 || value.charCodeAt(i) > 90) &&
+ (value.charCodeAt(i) < 48 || value.charCodeAt(i) > 57))
+ {
+ error = defaultInvalidValueError;
+ return "";
+ }
+ }
+ }
+ else
+ {
+ if (value === null || isNaN(Number(value)))
+ {
+ error = defaultInvalidValueError;
+ return "";
+ }
+ }
+
+ // --format--
+
+ if (fStrLen == 9 && uStrLen == 5)
+ value = String(value).concat("0000");
+
+ if (fStrLen == 5 && uStrLen == 9)
+ value = value.substr(0, 5);
+
+ var dataFormatter:SwitchSymbolFormatter = new SwitchSymbolFormatter();
+
+ return dataFormatter.formatValue(formatString, value);
+ }
+}
+
+}