JIDE 3.5.15

com.jidesoft.converter
Class DateConverter

java.lang.Object
  extended by com.jidesoft.converter.DateConverter
All Implemented Interfaces:
ObjectConverter
Direct Known Subclasses:
CalendarConverter

public class DateConverter
extends Object
implements ObjectConverter

Converter which converts Date to String and converts it back.


Field Summary
static ConverterContext DATE_CONTEXT
           
static ConverterContext DATETIME_CONTEXT
           
static ConverterContext TIME_CONTEXT
           
 
Constructor Summary
DateConverter()
          Creates a DateConverter.
 
Method Summary
 Object fromString(String string, ConverterContext context)
          Converts from a String to a Date.
 DateFormat getDefaultDatetimeFormat()
          Gets DefaultDatetimeFormat to format an calendar.
 DateFormat getDefaultFormat()
          Gets DefaultFormat to format an calendar.
 DateFormat getDefaultTimeFormat()
          Gets DefaultTimeFormat to format an calendar.
 void setDefaultDatetimeFormat(DateFormat defaultDatetimeFormat)
          Sets DefaultDatetimeFormat to format an calendar.
 void setDefaultFormat(DateFormat defaultFormat)
          Sets DefaultFormat to format an calendar.
 void setDefaultTimeFormat(DateFormat defaultTimeFormat)
          Sets DefaultTimeFormat to format an calendar.
 boolean supportFromString(String string, ConverterContext context)
          If it supports fromString.
 boolean supportToString(Object object, ConverterContext context)
          If it supports toString method.
 String toString(Object object, ConverterContext context)
          Converts the object to String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DATETIME_CONTEXT

public static final ConverterContext DATETIME_CONTEXT

TIME_CONTEXT

public static final ConverterContext TIME_CONTEXT

DATE_CONTEXT

public static final ConverterContext DATE_CONTEXT
Constructor Detail

DateConverter

public DateConverter()
Creates a DateConverter.

Method Detail

toString

public String toString(Object object,
                       ConverterContext context)
Converts the object to String. The object can be a Calendar, a Date or a Number. As long as the DateFormat can format it correctly, it will be converted to a String. If the object is already a String, we will return it directly as it is.

Specified by:
toString in interface ObjectConverter
Parameters:
object - the object to be converted
context - the converter context.
Returns:
the string

supportToString

public boolean supportToString(Object object,
                               ConverterContext context)
Description copied from interface: ObjectConverter
If it supports toString method.

Specified by:
supportToString in interface ObjectConverter
Parameters:
object - object to be converted
context - converter context to be used
Returns:
true if supports toString

fromString

public Object fromString(String string,
                         ConverterContext context)
Converts from a String to a Date.

Specified by:
fromString in interface ObjectConverter
Parameters:
string - the string to be converted.
context - the context. It could be DATETIME_CONTEXT, DATE_CONTEXT or TIME_CONTEXT.
Returns:
the Date. If the string is null or empty, null will be returned. If the string cannot be parsed as a date, the string itself will be returned.

supportFromString

public boolean supportFromString(String string,
                                 ConverterContext context)
Description copied from interface: ObjectConverter
If it supports fromString.

Specified by:
supportFromString in interface ObjectConverter
Parameters:
string - the string
context - context to be converted
Returns:
true if it supports

getDefaultFormat

public DateFormat getDefaultFormat()
Gets DefaultFormat to format an calendar.

Returns:
DefaultFormat

setDefaultFormat

public void setDefaultFormat(DateFormat defaultFormat)
Sets DefaultFormat to format an calendar.

Parameters:
defaultFormat - the new default date format

getDefaultTimeFormat

public DateFormat getDefaultTimeFormat()
Gets DefaultTimeFormat to format an calendar. This is used only when context is TIME_CONTEXT.

Returns:
DefaultTimeFormat

setDefaultTimeFormat

public void setDefaultTimeFormat(DateFormat defaultTimeFormat)
Sets DefaultTimeFormat to format an calendar. This is used only when context is TIME_CONTEXT.

Parameters:
defaultTimeFormat - the new default time format

getDefaultDatetimeFormat

public DateFormat getDefaultDatetimeFormat()
Gets DefaultDatetimeFormat to format an calendar. This is used only when context is DATETIME_CONTEXT.

Returns:
DefaultDatetimeFormat

setDefaultDatetimeFormat

public void setDefaultDatetimeFormat(DateFormat defaultDatetimeFormat)
Sets DefaultDatetimeFormat to format an calendar. This is used only when context is DATETIME_CONTEXT.

Parameters:
defaultDatetimeFormat - the new defaultdatetime format

JIDE 3.5.15