com.jgoodies.validation.formatter
Class RelativeDateFormatter

java.lang.Object
  extended by javax.swing.JFormattedTextField.AbstractFormatter
      extended by javax.swing.text.DefaultFormatter
          extended by javax.swing.text.InternationalFormatter
              extended by javax.swing.text.DateFormatter
                  extended by com.jgoodies.validation.formatter.EmptyDateFormatter
                      extended by com.jgoodies.validation.formatter.RelativeDateFormatter
All Implemented Interfaces:
Serializable, Cloneable

public class RelativeDateFormatter
extends EmptyDateFormatter

Adds relative dates and output shortcuts to its superclass EmptyDateFormatter.

If output shortcuts are enabled, Yesterday, Today and Tomorrow are formatted using their localized human-language print strings.

If relative input is allowed, the parser accepts signed integers that encode a date relative to today; this input would otherwise be considered invalid.

Version:
$Revision: 1.10 $
Author:
Karsten Lentzsch
See Also:
ValidationUtils, JFormattedTextField, Serialized Form

Field Summary
static String KEY_TODAY
          The resource bundle key used to localize 'Today'.
static String KEY_TOMORROW
          The resource bundle key used to localize 'Tomorrow'.
static String KEY_YESTERDAY
          The resource bundle key used to localize 'Yesterday'.
 
Constructor Summary
RelativeDateFormatter()
          Constructs a RelativeDateFormatter using the default DateFormat with output shortcuts and relative input enabled.
RelativeDateFormatter(boolean useOutputShortcuts, boolean allowRelativeInput)
          Constructs a RelativeDateFormatter using the default DateFormat with output shortcuts and relative input configured as specified.
RelativeDateFormatter(DateFormat format)
          Constructs a RelativeDateFormatter using the given DateFormat with output shortcuts and relative input enabled.
RelativeDateFormatter(DateFormat format, boolean useOutputShortcuts, boolean allowRelativeInput)
          Constructs a RelativeDateFormatter using the given DateFormat with output shortcuts and relative input configured as specified.
 
Method Summary
static ResourceBundle getDefaultResourceBundle()
          Returns the ResourceBundle that is used as default unless overridden by an individual bundle.
 ResourceBundle getResourceBundle()
          Returns the ResourceBundle used to lookup localized texts for Yesterday, Today, and Tomorrow.
static void setDefaultResourceBundle(ResourceBundle newDefaultBundle)
          Sets the ResourceBundle that is used as default for all RelativeDateFormatters that have no individual bundle set.
 void setResourceBundle(ResourceBundle newBundle)
          Sets a ResourceBundle that will be used to lookup localized texts for Yesterday, Today, and Tomorrow.
 Object stringToValue(String text)
          Returns the Object representation of the String text.
 String valueToString(Object value)
          Returns a String representation of the Object value.
 
Methods inherited from class javax.swing.text.DateFormatter
setFormat
 
Methods inherited from class javax.swing.text.InternationalFormatter
clone, getActions, getFields, getFormat, getMaximum, getMinimum, install, setFormat, setMaximum, setMinimum
 
Methods inherited from class javax.swing.text.DefaultFormatter
getAllowsInvalid, getCommitsOnValidEdit, getDocumentFilter, getNavigationFilter, getOverwriteMode, getValueClass, setAllowsInvalid, setCommitsOnValidEdit, setOverwriteMode, setValueClass
 
Methods inherited from class javax.swing.JFormattedTextField.AbstractFormatter
getFormattedTextField, invalidEdit, setEditValid, uninstall
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

KEY_YESTERDAY

public static final String KEY_YESTERDAY
The resource bundle key used to localize 'Yesterday'.

See Also:
Constant Field Values

KEY_TODAY

public static final String KEY_TODAY
The resource bundle key used to localize 'Today'.

See Also:
Constant Field Values

KEY_TOMORROW

public static final String KEY_TOMORROW
The resource bundle key used to localize 'Tomorrow'.

See Also:
Constant Field Values
Constructor Detail

RelativeDateFormatter

public RelativeDateFormatter()
Constructs a RelativeDateFormatter using the default DateFormat with output shortcuts and relative input enabled.


RelativeDateFormatter

public RelativeDateFormatter(DateFormat format)
Constructs a RelativeDateFormatter using the given DateFormat with output shortcuts and relative input enabled.

Parameters:
format - the DateFormat used to format and parse dates

RelativeDateFormatter

public RelativeDateFormatter(boolean useOutputShortcuts,
                             boolean allowRelativeInput)
Constructs a RelativeDateFormatter using the default DateFormat with output shortcuts and relative input configured as specified.

Parameters:
useOutputShortcuts - true indicates that dates are formatted with shortcuts for yesterday, today, and tomorrow, where false always converts using absolute numbers for day, month and year.
allowRelativeInput - true indicates that the parser accepts signed integers that encode a date relative to today; if false such input is considered invalid

RelativeDateFormatter

public RelativeDateFormatter(DateFormat format,
                             boolean useOutputShortcuts,
                             boolean allowRelativeInput)
Constructs a RelativeDateFormatter using the given DateFormat with output shortcuts and relative input configured as specified.

Parameters:
format - the DateFormat used to format and parse dates
useOutputShortcuts - true indicates that dates are formatted with shortcuts for yesterday, today, and tomorrow, where false always converts using absolute numbers for day, month and year.
allowRelativeInput - true indicates that the parser accepts signed integers that encode a date relative to today; if false such input is considered invalid
Method Detail

stringToValue

public Object stringToValue(String text)
                     throws ParseException
Returns the Object representation of the String text.

In addition to the delegate's behavior, this methods accepts signed integers interpreted as days relative to today.

Overrides:
stringToValue in class EmptyDateFormatter
Parameters:
text - the String to convert
Returns:
the Object representation of text
Throws:
ParseException - if there is an error in the conversion

valueToString

public String valueToString(Object value)
                     throws ParseException
Returns a String representation of the Object value. This invokes format on the current DateFormat.

In addition to the superclass behavior, this method formats the dates for yesterday, today and tomorrow to the natural language strings.

Overrides:
valueToString in class EmptyDateFormatter
Parameters:
value - The value to convert
Returns:
a String representation for the value
Throws:
ParseException - if there is an error in the conversion

getDefaultResourceBundle

public static ResourceBundle getDefaultResourceBundle()
Returns the ResourceBundle that is used as default unless overridden by an individual bundle.

Returns:
the ResourceBundle that is used as default

setDefaultResourceBundle

public static void setDefaultResourceBundle(ResourceBundle newDefaultBundle)
Sets the ResourceBundle that is used as default for all RelativeDateFormatters that have no individual bundle set.

Parameters:
newDefaultBundle - the ResourceBundle to be used as default

getResourceBundle

public final ResourceBundle getResourceBundle()
Returns the ResourceBundle used to lookup localized texts for Yesterday, Today, and Tomorrow. In case no bundle is set, these 3 dates will be formatted using the English texts.

Returns:
the ResourceBundle used to lookup localized texts
See Also:
setResourceBundle(ResourceBundle), getDefaultResourceBundle(), setDefaultResourceBundle(ResourceBundle)

setResourceBundle

public final void setResourceBundle(ResourceBundle newBundle)
Sets a ResourceBundle that will be used to lookup localized texts for Yesterday, Today, and Tomorrow. In case no bundle is set, the default bundle will be used.

Parameters:
newBundle - the ResourceBundle to set
See Also:
getResourceBundle(), getDefaultResourceBundle(), setDefaultResourceBundle(ResourceBundle)


Copyright © 2003-2008 JGoodies Karsten Lentzsch. All Rights Reserved.