Class DateFormatter
java.lang.Object
org.eclipse.nebula.widgets.formattedtext.AbstractFormatter
org.eclipse.nebula.widgets.formattedtext.DateTimeFormatter
org.eclipse.nebula.widgets.formattedtext.DateFormatter
- All Implemented Interfaces:
java.util.EventListener
,ITextFormatter
,org.eclipse.swt.events.VerifyListener
,org.eclipse.swt.internal.SWTEventListener
public class DateFormatter extends DateTimeFormatter
This class provides formatting of
Date
values in a
FormattedText
, restricting the edit and display to the time part.
Supports a subset of time patterns defined in SimpleDateFormat
for input.
See DateTimeFormatter
for a full description of patterns, given
that only patterns chars related to time are allowed.
Examples
new DateFormatter("MM/dd/yyyy")
- 8 jul 2006 will edit and display as "07/08/2006".new DateFormatter("dd/MM/yyyy, "dd MMM yyyy")
- 8 jul 2006 will edit as "08/07/2006" and display as "08 Jul 2006".
-
Field Summary
Fields inherited from class org.eclipse.nebula.widgets.formattedtext.DateTimeFormatter
cachedPatterns, calendar, fieldCount, fields, flistener, inputCache, inputMask, klistener, locale, modifyFilter, sdfDisplay, yearStart
Fields inherited from class org.eclipse.nebula.widgets.formattedtext.AbstractFormatter
EMPTY, ignore, SPACE, text
-
Constructor Summary
Constructors Constructor Description DateFormatter()
Constructs a new instance with all defaults : edit mask in SHORT date format for the default locale display mask identical to the edit mask default localeDateFormatter(java.lang.String editPattern)
Constructs a new instance with the given edit mask.DateFormatter(java.lang.String editPattern, java.lang.String displayPattern)
Constructs a new instance with the given edit and display masks.DateFormatter(java.lang.String editPattern, java.lang.String displayPattern, java.util.Locale loc)
Constructs a new instance with the given masks and locale.DateFormatter(java.lang.String editPattern, java.util.Locale loc)
Constructs a new instance with the given edit mask and locale.DateFormatter(java.util.Locale loc)
Constructs a new instance with default edit and display masks for the given locale. -
Method Summary
Modifier and Type Method Description java.lang.String
getDefaultEditPattern(java.util.Locale loc)
Returns the default edit pattern for the givenLocale
.protected void
isValidCharPattern(char c)
Checks if a given char is valid for the edit pattern.Methods inherited from class org.eclipse.nebula.widgets.formattedtext.DateTimeFormatter
detach, getDisplayString, getEditString, getLocale, getValue, getValueType, isEmpty, isValid, setLocale, setText, setTimeZone, setValue, verifyText
Methods inherited from class org.eclipse.nebula.widgets.formattedtext.AbstractFormatter
beep, setIgnore, updateText, updateText
-
Constructor Details
-
DateFormatter
public DateFormatter()Constructs a new instance with all defaults :- edit mask in SHORT date format for the default locale
- display mask identical to the edit mask
- default locale
-
DateFormatter
public DateFormatter(java.util.Locale loc)Constructs a new instance with default edit and display masks for the given locale.- Parameters:
loc
- locale
-
DateFormatter
public DateFormatter(java.lang.String editPattern)Constructs a new instance with the given edit mask. Display mask is identical to the edit mask, and locale is the default one.- Parameters:
editPattern
- edit mask
-
DateFormatter
public DateFormatter(java.lang.String editPattern, java.util.Locale loc)Constructs a new instance with the given edit mask and locale. Display mask is identical to the edit mask.- Parameters:
editPattern
- edit maskloc
- locale
-
DateFormatter
public DateFormatter(java.lang.String editPattern, java.lang.String displayPattern)Constructs a new instance with the given edit and display masks. Uses the default locale.- Parameters:
editPattern
- edit maskdisplayPattern
- display mask
-
DateFormatter
public DateFormatter(java.lang.String editPattern, java.lang.String displayPattern, java.util.Locale loc)Constructs a new instance with the given masks and locale.- Parameters:
editPattern
- edit maskdisplayPattern
- display maskloc
- locale
-
-
Method Details
-
getDefaultEditPattern
public java.lang.String getDefaultEditPattern(java.util.Locale loc)Returns the default edit pattern for the givenLocale
.A
DateFormat
object is instantiated with SHORT format for both the date part for the given locale. The corresponding pattern string is then retrieved by calling thetoPattern
.Default patterns are stored in a cache with ISO3 language and country codes as key. So they are computed only once by locale.
- Overrides:
getDefaultEditPattern
in classDateTimeFormatter
- Parameters:
loc
- locale- Returns:
- edit pattern for the locale
-
isValidCharPattern
protected void isValidCharPattern(char c)Checks if a given char is valid for the edit pattern. This method overrides the parent method, restricting authorized chars to date patterns.- Overrides:
isValidCharPattern
in classDateTimeFormatter
- Parameters:
c
- pattern char- Throws:
java.lang.IllegalArgumentException
- if not valid- See Also:
DateTimeFormatter.isValidCharPattern(char)
-