You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by sm...@apache.org on 2013/02/13 18:41:07 UTC

svn commit: r1445764 - in /pivot/branches/2.0.x/tests/src/org/apache/pivot/tests: TextInputValidatorTest.java text_input_validator_test.bxml

Author: smartini
Date: Wed Feb 13 17:41:06 2013
New Revision: 1445764

URL: http://svn.apache.org/r1445764
Log:
Update Test application for some Validators, with better info on Locale usage, and other small updates

Modified:
    pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/TextInputValidatorTest.java
    pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/text_input_validator_test.bxml

Modified: pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/TextInputValidatorTest.java
URL: http://svn.apache.org/viewvc/pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/TextInputValidatorTest.java?rev=1445764&r1=1445763&r2=1445764&view=diff
==============================================================================
--- pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/TextInputValidatorTest.java (original)
+++ pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/TextInputValidatorTest.java Wed Feb 13 17:41:06 2013
@@ -13,6 +13,11 @@
  */
 package org.apache.pivot.tests;
 
+// import java.text.DecimalFormat;
+import java.text.NumberFormat;
+// import java.util.Formatter;
+import java.util.Locale;
+
 import org.apache.pivot.beans.BXMLSerializer;
 import org.apache.pivot.collections.Map;
 import org.apache.pivot.wtk.Application;
@@ -24,8 +29,8 @@ import org.apache.pivot.wtk.TextInput;
 import org.apache.pivot.wtk.TextInputListener;
 import org.apache.pivot.wtk.Window;
 import org.apache.pivot.wtk.validation.DoubleValidator;
-import org.apache.pivot.wtk.validation.FloatValidator;
 import org.apache.pivot.wtk.validation.FloatRangeValidator;
+import org.apache.pivot.wtk.validation.FloatValidator;
 import org.apache.pivot.wtk.validation.IntRangeValidator;
 import org.apache.pivot.wtk.validation.NotEmptyTextValidator;
 import org.apache.pivot.wtk.validation.RegexTextValidator;
@@ -35,7 +40,10 @@ import org.apache.pivot.wtk.validation.V
  * Text input validator test.
  */
 public class TextInputValidatorTest  extends Application.Adapter {
+    private Locale locale = Locale.getDefault();  // the default locale
+
     private Window window = null;
+    private TextInput textinputLocale = null;
     private TextInput textinputDouble = null;
     private TextInput textinputFloat = null;
     private TextInput textinputFloatRange = null;
@@ -47,10 +55,25 @@ public class TextInputValidatorTest  ext
 
     @Override
     public void startup(Display display, Map<String, String> properties) throws Exception {
+        System.out.println("Starting TextInputValidatorTest ...");
+        System.out.println("current Locale is " + locale);
+
+        // sample different ways to format numbers in i18n compatible way
+        NumberFormat  nf = NumberFormat.getInstance();
+        //
+        // String customDecimalPattern = ""###,###.###"";
+        // DecimalFormat df = new DecimalFormat(customDecimalPattern);
+        //
+        // StringBuffer sb = new StringBuffer();
+        // Formatter formatter = new Formatter(sb, locale);
+        // String customDecimalFormat = "%,.3f";
+        //
+
         BXMLSerializer bxmlSerializer = new BXMLSerializer();
         window = new Window((Component)bxmlSerializer.readObject(
             getClass().getResource("text_input_validator_test.bxml")));
 
+        textinputLocale = (TextInput)bxmlSerializer.getNamespace().get("textinputLocale");
         textinputDouble = (TextInput)bxmlSerializer.getNamespace().get("textinputDouble");
         textinputFloat = (TextInput)bxmlSerializer.getNamespace().get("textinputFloat");
         textinputFloatRange = (TextInput)bxmlSerializer.getNamespace().get("textinputFloatRange");
@@ -59,15 +82,26 @@ public class TextInputValidatorTest  ext
         textinputCustomBoolean = (TextInput)bxmlSerializer.getNamespace().get("textinputCustomBoolean");
         textinputNotEmptyText = (TextInput)bxmlSerializer.getNamespace().get("textinputNotEmptyText");
 
-        textinputDouble.setText("\u221E");
+        textinputLocale.setText(locale.toString());
+
+        textinputDouble.setText("\u221E");  // infinite symbol
         textinputDouble.setValidator(new DoubleValidator());
 
-        textinputFloat.setText("1.5");
+        // textinputFloat.setText("123456.789");
+        // new, show different ways to format decimal values in i18n format
+        Double value = new Double("123456.789");
+        // textinputFloat.setText(value.toString());
+        // textinputFloat.setText(String.format(customDecimalFormat, value)); // sample using String.format
+        // formatter.format(customDecimalFormat, value);                      // sample using Formatter
+        // textinputFloat.setText(sb.toString());                             // sample using Formatter
+        // textinputFloat.setText(nf.format(value));                          // sample using NumberFormat
+        // textinputFloat.setText(df.format(value));                          // sample using DecimalFormat
+        textinputFloat.setText(nf.format(value));  // using this as a sample
         textinputFloat.setValidator(new FloatValidator());
 
         // standard float range model
-        textinputFloatRange.setText("0.5");
-        textinputFloatRange.setValidator(new FloatRangeValidator(0.3f, 2000f));
+        textinputFloatRange.setText(nf.format(value));
+        textinputFloatRange.setValidator(new FloatRangeValidator(2.0f, 123456789f));
 
         // test the listener by updating a label
         textinputFloatRange.getTextInputListeners().add(new TextInputListener.Adapter() {

Modified: pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/text_input_validator_test.bxml
URL: http://svn.apache.org/viewvc/pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/text_input_validator_test.bxml?rev=1445764&r1=1445763&r2=1445764&view=diff
==============================================================================
--- pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/text_input_validator_test.bxml (original)
+++ pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/text_input_validator_test.bxml Wed Feb 13 17:41:06 2013
@@ -24,6 +24,11 @@ limitations under the License.
     </columns>
 
     <TablePane.Row height="-1">
+        <Label text="Current Locale:"/>
+        <TextInput bxml:id="textinputLocale" editable="false"/>
+        <Label text="use separators from the current Locale"/>
+    </TablePane.Row>
+    <TablePane.Row height="-1">
         <Label text="double"/>
         <TextInput bxml:id="textinputDouble"/>
         <Label text="valid value: any double: ~4.94e-324 to ~1.79e+308 or &#x00B1;&#x221E;"/>
@@ -36,7 +41,7 @@ limitations under the License.
     <TablePane.Row height="-1">
         <Label text="float range"/>
         <TextInput bxml:id="textinputFloatRange"/>
-        <Label text="valid range: 0.3 .. 2000"/>
+        <Label text="valid range: 2.0 .. 123456789"/>
         <Label bxml:id="invalidLabel"/>
     </TablePane.Row>
     <TablePane.Row height="-1">