These examples were originally written for the Developer Guide. This patch
imports them into the GWT javadoc examples package, fixes them up to
compile as a standalone source file and added references to them from
the NumberFormat and DateTimeFormat source.

Reported as issue 1895

Patch by: zundel
Review by: shanjian



git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@1861 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/javadoc/com/google/gwt/examples/DateTimeFormatExample.java b/user/javadoc/com/google/gwt/examples/DateTimeFormatExample.java
new file mode 100644
index 0000000..a4d1104
--- /dev/null
+++ b/user/javadoc/com/google/gwt/examples/DateTimeFormatExample.java
@@ -0,0 +1,36 @@
+package com.google.gwt.examples;
+
+import java.util.Date;
+import com.google.gwt.core.client.EntryPoint;
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.i18n.client.DateTimeFormat;
+
+public class DateTimeFormatExample implements EntryPoint {
+
+  public void onModuleLoad() {
+    Date today = new Date();
+
+    // prints Tue Dec 18 12:01:26 GMT-500 2007 in the default locale.
+    GWT.log(today.toString(), null);
+
+    // prints 12/18/07 in the default locale
+    GWT.log(DateTimeFormat.getShortDateFormat().format(today), null);
+
+    // prints December 18, 2007 in the default locale
+    GWT.log(DateTimeFormat.getLongDateFormat().format(today), null);
+
+    // prints 12:01 PM in the default locale
+    GWT.log(DateTimeFormat.getShortTimeFormat().format(today), null);
+
+    // prints 12:01:26 PM GMT-05:00 in the default locale
+    GWT.log(DateTimeFormat.getLongTimeFormat().format(today), null);
+
+    // prints Dec 18, 2007 12:01:26 PM in the default locale
+    GWT.log(DateTimeFormat.getMediumDateTimeFormat().format(today), null);
+    
+    // A custom date format
+    DateTimeFormat fmt = DateTimeFormat.getFormat("EEEE, MMMM dd, yyyy");
+    // prints Monday, December 17, 2007 in the default locale
+    GWT.log(fmt.format(today), null);
+  }
+}
diff --git a/user/javadoc/com/google/gwt/examples/NumberFormatExample.java b/user/javadoc/com/google/gwt/examples/NumberFormatExample.java
new file mode 100644
index 0000000..ee4078a
--- /dev/null
+++ b/user/javadoc/com/google/gwt/examples/NumberFormatExample.java
@@ -0,0 +1,38 @@
+package com.google.gwt.examples;
+
+import com.google.gwt.core.client.EntryPoint;
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.i18n.client.NumberFormat;
+
+public class NumberFormatExample implements EntryPoint {
+
+  public void onModuleLoad() {
+    NumberFormat fmt = NumberFormat.getDecimalFormat();
+    double value = 12345.6789;
+    String formatted = fmt.format(value);
+    // Prints 1,2345.6789 in the default locale
+    GWT.log("Formatted string is" + formatted, null);
+
+    // Turn a string back into a double
+    value = NumberFormat.getDecimalFormat().parse("12345.6789");
+    GWT.log("Parsed value is" + value, null);
+
+    // Scientific notation
+    value = 12345.6789;
+    formatted = NumberFormat.getScientificFormat().format(value);
+    // prints 1.2345E4 in the default locale
+    GWT.log("Formatted string is" + formatted, null);
+
+    // Currency
+    fmt = NumberFormat.getCurrencyFormat();
+    formatted = fmt.format(123456.7899);
+    // prints $123,456.79 in the default locale
+    GWT.log("Formatted currency is" + formatted, null);
+    
+    // Custom format
+    value = 12345.6789;
+    formatted = NumberFormat.getFormat("000000.000000").format(value);
+    // prints 012345.678900 in the default locale
+    GWT.log("Formatted string is" + formatted, null);
+  }
+}
diff --git a/user/src/com/google/gwt/i18n/client/DateTimeFormat.java b/user/src/com/google/gwt/i18n/client/DateTimeFormat.java
index e129404..f936ebd 100644
--- a/user/src/com/google/gwt/i18n/client/DateTimeFormat.java
+++ b/user/src/com/google/gwt/i18n/client/DateTimeFormat.java
@@ -300,6 +300,9 @@
  * <code>GMT:hhmm</code>, <code>GMT:+hhmm</code>, and
  * <code>GMT:-hhmm</code>.
  * </p>
+ * 
+ * <h3>Example</h3> {@example com.google.gwt.examples.DateTimeFormatExample}
+ *
  */
 public class DateTimeFormat {
   /**
diff --git a/user/src/com/google/gwt/i18n/client/NumberFormat.java b/user/src/com/google/gwt/i18n/client/NumberFormat.java
index 0708168..8c67678 100644
--- a/user/src/com/google/gwt/i18n/client/NumberFormat.java
+++ b/user/src/com/google/gwt/i18n/client/NumberFormat.java
@@ -300,6 +300,10 @@
  * The first subpattern is for positive numbers. The second (optional)
  * subpattern is for negative numbers.
  * </p>
+ * 
+ *  <h3>Example</h3> {@example com.google.gwt.examples.NumberFormatExample}
+ *
+ * 
  */
 public class NumberFormat {