You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by eh...@apache.org on 2007/04/06 00:37:35 UTC

svn commit: r525987 - in /incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket-datetime/src/main/java/wicket/datetime: markup/html/form/DateTextField.java util/DateConverter.java

Author: ehillenius
Date: Thu Apr  5 15:37:34 2007
New Revision: 525987

URL: http://svn.apache.org/viewvc?view=rev&rev=525987
Log:
javadoc fixes

Modified:
    incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket-datetime/src/main/java/wicket/datetime/markup/html/form/DateTextField.java
    incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket-datetime/src/main/java/wicket/datetime/util/DateConverter.java

Modified: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket-datetime/src/main/java/wicket/datetime/markup/html/form/DateTextField.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket-datetime/src/main/java/wicket/datetime/markup/html/form/DateTextField.java?view=diff&rev=525987&r1=525986&r2=525987
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket-datetime/src/main/java/wicket/datetime/markup/html/form/DateTextField.java (original)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket-datetime/src/main/java/wicket/datetime/markup/html/form/DateTextField.java Thu Apr  5 15:37:34 2007
@@ -35,13 +35,14 @@
  * A TextField that is mapped to a <code>java.util.Date</code> object and that
  * uses Joda time to parse and format values.
  * <p>
- * You must use on of the factory methods to construct the kind you want.
+ * You should use on of the factory methods to construct the kind you want or
+ * use the public constructor and pass in the converter to use.
  * </p>
  * <p>
  * This component tries to apply the time zone difference between the client and
  * server. See the
- * {@link StyleDateConverter#getApplyTimeZoneDifference() date converter} of
- * this package for more information on that.
+ * {@link DateConverter#getApplyTimeZoneDifference() date converter} of this
+ * package for more information on that.
  * </p>
  * 
  * @see StyleDateConverter
@@ -51,7 +52,8 @@
  * 
  * @author eelcohillenius
  */
-public class DateTextField extends TextField implements ITextFormatProvider {
+public class DateTextField extends TextField implements ITextFormatProvider
+{
 
 	private static final long serialVersionUID = 1L;
 
@@ -68,10 +70,9 @@
 	 * 
 	 * @see wicket.markup.html.form.TextField
 	 */
-	public static DateTextField forDatePattern(String id, IModel model,
-			String datePattern) {
-		return new DateTextField(id, model, new PatternDateConverter(
-				datePattern, true));
+	public static DateTextField forDatePattern(String id, IModel model, String datePattern)
+	{
+		return new DateTextField(id, model, new PatternDateConverter(datePattern, true));
 	}
 
 	/**
@@ -85,7 +86,8 @@
 	 * 
 	 * @see wicket.markup.html.form.TextField
 	 */
-	public static DateTextField forDatePattern(String id, String datePattern) {
+	public static DateTextField forDatePattern(String id, String datePattern)
+	{
 		return forDatePattern(id, null, datePattern);
 	}
 
@@ -103,10 +105,9 @@
 	 * 
 	 * @see wicket.markup.html.form.TextField
 	 */
-	public static DateTextField forDateStyle(String id, IModel model,
-			String dateStyle) {
-		return new DateTextField(id, model, new StyleDateConverter(dateStyle,
-				true));
+	public static DateTextField forDateStyle(String id, IModel model, String dateStyle)
+	{
+		return new DateTextField(id, model, new StyleDateConverter(dateStyle, true));
 	}
 
 	/**
@@ -121,7 +122,8 @@
 	 * 
 	 * @see wicket.markup.html.form.TextField
 	 */
-	public static DateTextField forDateStyle(String id, String dateStyle) {
+	public static DateTextField forDateStyle(String id, String dateStyle)
+	{
 		return forDateStyle(id, null, dateStyle);
 	}
 
@@ -133,7 +135,8 @@
 	 * 
 	 * @see wicket.markup.html.form.TextField
 	 */
-	public static DateTextField forShortStyle(String id) {
+	public static DateTextField forShortStyle(String id)
+	{
 		return forShortStyle(id, null);
 	}
 
@@ -147,7 +150,8 @@
 	 * 
 	 * @see wicket.markup.html.form.TextField
 	 */
-	public static DateTextField forShortStyle(String id, IModel model) {
+	public static DateTextField forShortStyle(String id, IModel model)
+	{
 		return new DateTextField(id, model, new StyleDateConverter(true));
 	}
 
@@ -161,7 +165,8 @@
 	 * 
 	 * @see wicket.markup.html.form.TextField
 	 */
-	public static DateTextField withConverter(String id, DateConverter converter) {
+	public static DateTextField withConverter(String id, DateConverter converter)
+	{
 		return withConverter(id, null, converter);
 	}
 
@@ -177,8 +182,8 @@
 	 * 
 	 * @see wicket.markup.html.form.TextField
 	 */
-	public static DateTextField withConverter(String id, IModel model,
-			DateConverter converter) {
+	public static DateTextField withConverter(String id, IModel model, DateConverter converter)
+	{
 		return new DateTextField(id, model, converter);
 	}
 
@@ -188,7 +193,7 @@
 	private final DateConverter converter;
 
 	/**
-	 * Construct. Hidden to force clients to use one of the factory methods.
+	 * Construct with a converter.
 	 * 
 	 * @param The
 	 *            component id
@@ -197,9 +202,11 @@
 	 * @param converter
 	 *            The converter to use
 	 */
-	public DateTextField(String id, IModel model, DateConverter converter) {
+	public DateTextField(String id, IModel model, DateConverter converter)
+	{
 		super(id, model, Date.class);
-		if (converter == null) {
+		if (converter == null)
+		{
 			throw new IllegalStateException("converter may not be null");
 		}
 		this.converter = converter;
@@ -209,14 +216,16 @@
 	 * @return The specialized converter.
 	 * @see wicket.Component#getConverter(java.lang.Class)
 	 */
-	public final IConverter getConverter(Class clazz) {
+	public final IConverter getConverter(Class clazz)
+	{
 		return converter;
 	}
 
 	/**
 	 * @see wicket.markup.html.form.AbstractTextComponent.ITextFormatProvider#getTextFormat()
 	 */
-	public final String getTextFormat() {
-		return ((DateConverter) converter).getDatePattern();
+	public final String getTextFormat()
+	{
+		return ((DateConverter)converter).getDatePattern();
 	}
 }

Modified: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket-datetime/src/main/java/wicket/datetime/util/DateConverter.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket-datetime/src/main/java/wicket/datetime/util/DateConverter.java?view=diff&rev=525987&r1=525986&r2=525987
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket-datetime/src/main/java/wicket/datetime/util/DateConverter.java (original)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket-datetime/src/main/java/wicket/datetime/util/DateConverter.java Thu Apr  5 15:37:34 2007
@@ -17,6 +17,7 @@
 package wicket.datetime.util;
 
 import java.util.Date;
+import java.util.Locale;
 import java.util.TimeZone;
 
 import org.joda.time.DateTime;
@@ -27,7 +28,7 @@
 import wicket.Session;
 import wicket.protocol.http.request.WebClientInfo;
 import wicket.request.ClientInfo;
-import wicket.util.convert.SimpleConverterAdapter;
+import wicket.util.convert.IConverter;
 
 /**
  * Base class for Joda Time based date converters. It contains the logic to
@@ -39,8 +40,8 @@
  * 
  * @author eelcohillenius
  */
-public abstract class DateConverter extends SimpleConverterAdapter {
-
+public abstract class DateConverter implements IConverter
+{
 	/**
 	 * Whether to apply the time zone difference when interpreting dates.
 	 */
@@ -62,47 +63,26 @@
 	 *            whether to apply the difference in time zones between client
 	 *            and server
 	 */
-	public DateConverter(boolean applyTimeZoneDifference) {
+	public DateConverter(boolean applyTimeZoneDifference)
+	{
 		this.applyTimeZoneDifference = applyTimeZoneDifference;
 	}
 
 	/**
-	 * Gets whether to apply the time zone difference when interpreting dates.
-	 * 
-	 * </p>
-	 * When true, the current time is applied on the parsed date, and the date
-	 * will be corrected for the time zone difference between the server and the
-	 * client. For instance, if I'm in Seattle and the server I'm working on is
-	 * in Amsterdam, the server is 9 hours ahead. So, if I'm inputting say 12/24
-	 * at a couple of hours before midnight, at the server it is already 12/25.
-	 * If this boolean is true, it will be transformed to 12/25, while the
-	 * client sees 12/24.
-	 * </p>
-	 * 
-	 * @return whether to apply the difference in time zones between client and
-	 *         server
-	 */
-	public final boolean getApplyTimeZoneDifference() {
-		return applyTimeZoneDifference;
-	}
-
-	/**
-	 * @return Gets the pattern that is used for printing and parsing
-	 */
-	public abstract String getDatePattern();
-
-	/**
-	 * @see wicket.util.convert.SimpleConverterAdapter#toObject(java.lang.String)
+	 * @see wicket.util.convert.IConverter#convertToObject(java.lang.String,
+	 *      java.util.Locale)
 	 */
-	public final Object toObject(String value) {
-
+	public Object convertToObject(String value, Locale locale)
+	{
 		DateTimeFormatter format = getFormat();
 
-		if (applyTimeZoneDifference) {
+		if (applyTimeZoneDifference)
+		{
 			TimeZone zone = getClientTimeZone();
 			// instantiate now/ current time
 			MutableDateTime dt = new MutableDateTime();
-			if (zone != null) {
+			if (zone != null)
+			{
 				// set time zone for client
 				format = format.withZone(DateTimeZone.forTimeZone(zone));
 				dt.setZone(DateTimeZone.forTimeZone(zone));
@@ -112,22 +92,27 @@
 			// apply the server time zone to the parsed value
 			dt.setZone(getTimeZone());
 			return dt.toDate();
-		} else {
+		}
+		else
+		{
 			return format.parseDateTime(value).toDate();
 		}
 	}
 
 	/**
-	 * @see wicket.util.convert.SimpleConverterAdapter#toString(java.lang.Object)
+	 * @see wicket.util.convert.IConverter#convertToString(java.lang.Object,
+	 *      java.util.Locale)
 	 */
-	public final String toString(Object value) {
-
-		DateTime dt = new DateTime(((Date) value).getTime(), getTimeZone());
+	public String convertToString(Object value, Locale locale)
+	{
+		DateTime dt = new DateTime(((Date)value).getTime(), getTimeZone());
 		DateTimeFormatter format = getFormat();
 
-		if (applyTimeZoneDifference) {
+		if (applyTimeZoneDifference)
+		{
 			TimeZone zone = getClientTimeZone();
-			if (zone != null) {
+			if (zone != null)
+			{
 				// apply time zone to formatter
 				format = format.withZone(DateTimeZone.forTimeZone(zone));
 			}
@@ -136,14 +121,42 @@
 	}
 
 	/**
+	 * Gets whether to apply the time zone difference when interpreting dates.
+	 * 
+	 * </p>
+	 * When true, the current time is applied on the parsed date, and the date
+	 * will be corrected for the time zone difference between the server and the
+	 * client. For instance, if I'm in Seattle and the server I'm working on is
+	 * in Amsterdam, the server is 9 hours ahead. So, if I'm inputting say 12/24
+	 * at a couple of hours before midnight, at the server it is already 12/25.
+	 * If this boolean is true, it will be transformed to 12/25, while the
+	 * client sees 12/24.
+	 * </p>
+	 * 
+	 * @return whether to apply the difference in time zones between client and
+	 *         server
+	 */
+	public final boolean getApplyTimeZoneDifference()
+	{
+		return applyTimeZoneDifference;
+	}
+
+	/**
+	 * @return Gets the pattern that is used for printing and parsing
+	 */
+	public abstract String getDatePattern();
+
+	/**
 	 * Gets the client's time zone.
 	 * 
 	 * @return The client's time zone or null
 	 */
-	protected TimeZone getClientTimeZone() {
+	protected TimeZone getClientTimeZone()
+	{
 		ClientInfo info = Session.get().getClientInfo();
-		if (info instanceof WebClientInfo) {
-			return ((WebClientInfo) info).getProperties().getTimeZone();
+		if (info instanceof WebClientInfo)
+		{
+			return ((WebClientInfo)info).getProperties().getTimeZone();
 		}
 		return null;
 	}
@@ -159,7 +172,8 @@
 	 * 
 	 * @return The server time zone
 	 */
-	protected DateTimeZone getTimeZone() {
+	protected DateTimeZone getTimeZone()
+	{
 		return DateTimeZone.getDefault();
 	}
 }