Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.jgoodies.validation.tutorial.formatted.format
Class RelativeDateFormat  view RelativeDateFormat download RelativeDateFormat.java

java.lang.Object
  extended byjava.text.Format
      extended byjava.text.DateFormat
          extended bycom.jgoodies.validation.tutorial.formatted.format.RelativeDateFormat
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable

public final class RelativeDateFormat
extends java.text.DateFormat

A Format that provides special handling for output shortcuts and relative input.

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.

This class is intended for demonstration purposes only. It is superceded by the com.jgoodies.validation.formatter.RelativeDateFormatter.

Version:
$Revision: 1.5 $

Nested Class Summary
 
Nested classes inherited from class java.text.DateFormat
java.text.DateFormat.Field
 
Field Summary
private  boolean allowRelativeInput
           
private  java.text.DateFormat delegate
           
private static java.text.NumberFormat INTEGER_FORMAT
           
static java.lang.String KEY_TODAY
           
static java.lang.String KEY_TOMORROW
           
static java.lang.String KEY_YESTERDAY
           
private  java.util.ResourceBundle resourceBundle
          Refers to an optional ResourceBundle that is used to localize the texts for the output shortcuts: Yesterday, Today, Tomorrow.
private  boolean useOutputShortcuts
           
private static java.lang.String VALUE_TODAY
           
private static java.lang.String VALUE_TOMORROW
           
private static java.lang.String VALUE_YESTERDAY
           
 
Fields inherited from class java.text.DateFormat
AM_PM_FIELD, calendar, DATE_FIELD, DAY_OF_WEEK_FIELD, DAY_OF_WEEK_IN_MONTH_FIELD, DAY_OF_YEAR_FIELD, DEFAULT, ERA_FIELD, EXTENDED_YEAR_FIELD, FULL, HOUR_OF_DAY0_FIELD, HOUR_OF_DAY1_FIELD, HOUR0_FIELD, HOUR1_FIELD, ISO_YEAR_FIELD, LOCALIZED_DAY_OF_WEEK_FIELD, LONG, MEDIUM, MILLISECOND_FIELD, MILLISECOND_IN_DAY_FIELD, MINUTE_FIELD, MODIFIED_JULIAN_DAY_FIELD, MONTH_FIELD, numberFormat, RFC822_TIMEZONE_FIELD, SECOND_FIELD, SHORT, TIMEZONE_FIELD, WEEK_OF_MONTH_FIELD, WEEK_OF_YEAR_FIELD, YEAR_FIELD
 
Constructor Summary
RelativeDateFormat()
          Constructs a wrapped format that provides special handling for output shortcuts and relative input.
RelativeDateFormat(java.text.DateFormat delegate, boolean useOutputShortcuts, boolean allowRelativeInput)
          Constructs a wrapped format that provides special handling for output shortcuts and relative input.
 
Method Summary
private static java.text.Format createDateFormat(int style, boolean useOutputShortcuts, boolean allowRelativeInput)
          Creates and returns a Format that converts Dates to Strings and vice versa.
 java.lang.StringBuffer format(java.util.Date date, java.lang.StringBuffer toAppendTo, java.text.FieldPosition fieldPosition)
          Formats a Date into a date/time string.
static java.text.Format getDefaultDisplayDateFormat()
          Creates and answers the default Format that is used to edit instances of java.util.Date in the UI: It converts null to empty Strings, uses the short DateFormat, uses shortcuts for output and does not accepts relative input.
static java.text.Format getDefaultEditDateFormat()
          Creates and answers the default Format that is used to edit instances of java.util.Date in the UI: It converts null to empty Strings, uses the short DateFormat, uses shortcuts for output and accepts relative input.
static java.text.Format getDefaultPrintDateFormat()
          Creates and answers the default Format that is used to edit instances of java.util.Date in the UI: It converts null to empty Strings, uses the short DateFormat, does not uses shortcuts for output and does not accepts relative input.
 java.util.ResourceBundle getResourceBundle()
           
private  java.lang.String getString(java.lang.String key, java.lang.String defaultText)
          Retrieves and returns a String for the given key from the a resource bundle.
 java.util.Date parse(java.lang.String source, java.text.ParsePosition pos)
          Parse a date/time string according to the given parse position.
 void setResourceBundle(java.util.ResourceBundle newBundle)
           
 
Methods inherited from class java.text.DateFormat
clone, equals, format, format, getAvailableLocales, getCalendar, getDateInstance, getDateInstance, getDateInstance, getDateTimeInstance, getDateTimeInstance, getDateTimeInstance, getInstance, getNumberFormat, getTimeInstance, getTimeInstance, getTimeInstance, getTimeZone, hashCode, isLenient, parse, parseObject, setCalendar, setLenient, setNumberFormat, setTimeZone
 
Methods inherited from class java.text.Format
format, formatToCharacterIterator, parseObject
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

KEY_YESTERDAY

public static final java.lang.String KEY_YESTERDAY
See Also:
Constant Field Values

KEY_TODAY

public static final java.lang.String KEY_TODAY
See Also:
Constant Field Values

KEY_TOMORROW

public static final java.lang.String KEY_TOMORROW
See Also:
Constant Field Values

VALUE_YESTERDAY

private static final java.lang.String VALUE_YESTERDAY
See Also:
Constant Field Values

VALUE_TODAY

private static final java.lang.String VALUE_TODAY
See Also:
Constant Field Values

VALUE_TOMORROW

private static final java.lang.String VALUE_TOMORROW
See Also:
Constant Field Values

INTEGER_FORMAT

private static final java.text.NumberFormat INTEGER_FORMAT

delegate

private final java.text.DateFormat delegate

useOutputShortcuts

private final boolean useOutputShortcuts

allowRelativeInput

private final boolean allowRelativeInput

resourceBundle

private java.util.ResourceBundle resourceBundle
Refers to an optional ResourceBundle that is used to localize the texts for the output shortcuts: Yesterday, Today, Tomorrow.

Constructor Detail

RelativeDateFormat

public RelativeDateFormat()
Constructs a wrapped format that provides special handling for output shortcuts and relative input.


RelativeDateFormat

public RelativeDateFormat(java.text.DateFormat delegate,
                          boolean useOutputShortcuts,
                          boolean allowRelativeInput)
Constructs a wrapped format that provides special handling for output shortcuts and relative input.

Method Detail

getDefaultEditDateFormat

public static java.text.Format getDefaultEditDateFormat()
Creates and answers the default Format that is used to edit instances of java.util.Date in the UI: It converts null to empty Strings, uses the short DateFormat, uses shortcuts for output and accepts relative input.


getDefaultDisplayDateFormat

public static java.text.Format getDefaultDisplayDateFormat()
Creates and answers the default Format that is used to edit instances of java.util.Date in the UI: It converts null to empty Strings, uses the short DateFormat, uses shortcuts for output and does not accepts relative input.


getDefaultPrintDateFormat

public static java.text.Format getDefaultPrintDateFormat()
Creates and answers the default Format that is used to edit instances of java.util.Date in the UI: It converts null to empty Strings, uses the short DateFormat, does not uses shortcuts for output and does not accepts relative input.


createDateFormat

private static java.text.Format createDateFormat(int style,
                                                 boolean useOutputShortcuts,
                                                 boolean allowRelativeInput)
Creates and returns a Format that converts Dates to Strings and vice versa. The format uses the specified java.text.DateFormat style and can be configured via the parameters. Also, the editable format allows to enter shortcuts for

Printable indicates that dates must always be converted using absolute numbers, where displayed dates will use shortcuts for yesterday, today and tomorrow.


format

public java.lang.StringBuffer format(java.util.Date date,
                                     java.lang.StringBuffer toAppendTo,
                                     java.text.FieldPosition fieldPosition)
Formats a Date into a date/time string. In addition to the delegate's behavior, this method formats the dates for yesterday, today and tomorrow to the natural language strings.


parse

public java.util.Date parse(java.lang.String source,
                            java.text.ParsePosition pos)
Parse a date/time string according to the given parse position. For example, a time text "07/10/96 4:5 PM, PDT" will be parsed into a Date that is equivalent to Date(837039928046).

By default, parsing is lenient: If the input is not in the form used by this object's format method but can still be parsed as a date, then the parse succeeds. Clients may insist on strict adherence to the format by calling setLenient(false).

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


getResourceBundle

public java.util.ResourceBundle getResourceBundle()

setResourceBundle

public void setResourceBundle(java.util.ResourceBundle newBundle)

getString

private java.lang.String getString(java.lang.String key,
                                   java.lang.String defaultText)
Retrieves and returns a String for the given key from the a resource bundle. This implementation refers to the bundle that is provided by the UIF's ResourceManager.