com.jp.comp.calendar
Class DateDocument

java.lang.Object
  extended byjavax.swing.text.AbstractDocument
      extended byjavax.swing.text.PlainDocument
          extended bycom.jp.comp.calendar.DateDocument
All Implemented Interfaces:
javax.swing.text.Document, java.io.Serializable

public class DateDocument
extends javax.swing.text.PlainDocument

DateDocument formats and validates the date in the DateField

See Also:
DateField, Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.text.AbstractDocument
javax.swing.text.AbstractDocument.AbstractElement, javax.swing.text.AbstractDocument.AttributeContext, javax.swing.text.AbstractDocument.BranchElement, javax.swing.text.AbstractDocument.Content, javax.swing.text.AbstractDocument.DefaultDocumentEvent, javax.swing.text.AbstractDocument.ElementEdit, javax.swing.text.AbstractDocument.LeafElement
 
Field Summary
static java.lang.String DATE_ELEMENTS
           
protected static java.text.SimpleDateFormat DEFAULT_DATE_FORMAT
           
protected  java.text.DateFormat fDateFormat
           
protected  java.lang.String fDatePattern
           
protected  java.lang.String fDateSymbols
           
protected  java.lang.String fEmptyDate
           
protected  java.util.Locale fLocale
           
protected  char fSeparator
           
protected  boolean fSeparatorTraversed
           
protected  int fYearDigitsAmount
           
protected  char fZeroChar
           
static char WHITESPACE_CHAR
           
 
Fields inherited from class javax.swing.text.PlainDocument
lineLimitAttribute, tabSizeAttribute
 
Fields inherited from class javax.swing.text.AbstractDocument
BAD_LOCATION, BidiElementName, ContentElementName, ElementNameAttribute, listenerList, ParagraphElementName, SectionElementName
 
Fields inherited from interface javax.swing.text.Document
StreamDescriptionProperty, TitleProperty
 
Constructor Summary
DateDocument()
          Constructs the class with default Locale
DateDocument(java.util.Locale aLocale)
          Constructs the class with specified Locale
 
Method Summary
protected  java.lang.String fillWithSpace(java.lang.String aDate)
          Filles the date with extra space for some locales to allow entering 2 digits
protected  java.lang.String fillWithSpace(java.lang.String aDate, boolean anAddExtraSpace)
          Filles the date with extra space for some locales to allow entering 2 digits
 java.util.Date getDate()
          Returns entered Date
 java.util.Locale getLocale()
          Gets the Locale
 int getYearDigitsAmount()
          Gets the year digits amount.
 void insertString(int anOffset, java.lang.String aStr, javax.swing.text.AttributeSet anAttrSet)
           
 boolean isDateEmpty()
          Returns true if date field is empty
protected  boolean isDateValueEmpty(java.lang.String aDate, int anOffSet)
           
protected  boolean isDateValueValid(java.lang.String aDate, int anOffSet)
          Validates typing value in the date field suppressing entering invalid date.
 void reformDate()
          Validates and reforms entered date.
 void remove(int anOffset, int aLen)
           
 void setDate(java.util.Date aDate)
          Sets a new Date
 void setLocale(java.util.Locale aLocale)
          Sets a new Locale
 void setYearDigitsAmount(int aYearDigitsAmount)
          Sets the year digits amount.
protected  java.lang.String[] splitString(java.lang.String aString)
          Splits the string by its parts using the date separator
 
Methods inherited from class javax.swing.text.PlainDocument
createDefaultRoot, getDefaultRootElement, getParagraphElement, insertUpdate, removeUpdate
 
Methods inherited from class javax.swing.text.AbstractDocument
addDocumentListener, addUndoableEditListener, createBranchElement, createLeafElement, createPosition, dump, fireChangedUpdate, fireInsertUpdate, fireRemoveUpdate, fireUndoableEditUpdate, getAsynchronousLoadPriority, getAttributeContext, getBidiRootElement, getContent, getCurrentWriter, getDocumentFilter, getDocumentListeners, getDocumentProperties, getEndPosition, getLength, getListeners, getProperty, getRootElements, getStartPosition, getText, getText, getUndoableEditListeners, postRemoveUpdate, putProperty, readLock, readUnlock, removeDocumentListener, removeUndoableEditListener, render, replace, setAsynchronousLoadPriority, setDocumentFilter, setDocumentProperties, writeLock, writeUnlock
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WHITESPACE_CHAR

public static final char WHITESPACE_CHAR
See Also:
Constant Field Values

DATE_ELEMENTS

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

DEFAULT_DATE_FORMAT

protected static final java.text.SimpleDateFormat DEFAULT_DATE_FORMAT

fZeroChar

protected char fZeroChar

fDateSymbols

protected java.lang.String fDateSymbols

fYearDigitsAmount

protected int fYearDigitsAmount

fLocale

protected java.util.Locale fLocale

fDateFormat

protected java.text.DateFormat fDateFormat

fDatePattern

protected java.lang.String fDatePattern

fEmptyDate

protected java.lang.String fEmptyDate

fSeparator

protected char fSeparator

fSeparatorTraversed

protected boolean fSeparatorTraversed
Constructor Detail

DateDocument

public DateDocument()
Constructs the class with default Locale


DateDocument

public DateDocument(java.util.Locale aLocale)
Constructs the class with specified Locale

Parameters:
aLocale - the Locale
Method Detail

insertString

public void insertString(int anOffset,
                         java.lang.String aStr,
                         javax.swing.text.AttributeSet anAttrSet)
                  throws javax.swing.text.BadLocationException
Throws:
javax.swing.text.BadLocationException

remove

public void remove(int anOffset,
                   int aLen)
            throws javax.swing.text.BadLocationException
Throws:
javax.swing.text.BadLocationException

getLocale

public java.util.Locale getLocale()
Gets the Locale

Returns:
the Locale

setLocale

public void setLocale(java.util.Locale aLocale)
Sets a new Locale

Parameters:
aLocale - a new Locale

getDate

public java.util.Date getDate()
Returns entered Date

Returns:
entered Date

setDate

public void setDate(java.util.Date aDate)
Sets a new Date

Parameters:
aDate - a new Date

isDateEmpty

public boolean isDateEmpty()
Returns true if date field is empty

Returns:
true if date field is empty

reformDate

public void reformDate()
Validates and reforms entered date. It validates that all date's parts are filled out and month and day are whithin their legitimate values. If some date's part is ivalid its nearest value will be placed. This method invoked when the date editor control losses its focus


fillWithSpace

protected java.lang.String fillWithSpace(java.lang.String aDate)
Filles the date with extra space for some locales to allow entering 2 digits

Parameters:
aDate - the date to fill up with spaces
Returns:
filled up date

fillWithSpace

protected java.lang.String fillWithSpace(java.lang.String aDate,
                                         boolean anAddExtraSpace)
Filles the date with extra space for some locales to allow entering 2 digits

Parameters:
aDate - the date to fill up with spaces
anAddExtraSpace - to add extra spaces for some locales to parse them
Returns:
filled up date

splitString

protected java.lang.String[] splitString(java.lang.String aString)
Splits the string by its parts using the date separator

Parameters:
aString - the date to split
Returns:
splitted date

isDateValueValid

protected boolean isDateValueValid(java.lang.String aDate,
                                   int anOffSet)
Validates typing value in the date field suppressing entering invalid date. It checks that the day may be between 1 - 31 and the month between 1-12

Parameters:
aDate - the date to validate
anOffSet - current offset in the date editor
Returns:
true if valid

isDateValueEmpty

protected boolean isDateValueEmpty(java.lang.String aDate,
                                   int anOffSet)

getYearDigitsAmount

public int getYearDigitsAmount()
Gets the year digits amount. The default is 0

Returns:
the year digits amount
See Also:
setYearDigitsAmount(int)

setYearDigitsAmount

public void setYearDigitsAmount(int aYearDigitsAmount)
Sets the year digits amount. There are three allowed values:

  • 0 - Locale's default year digits amount
  • 2 - 2 year digits
  • 4 - 4 year digits

Otherwise the exception IllegalArgumentException will be thrown

Parameters:
aYearDigitsAmount - the year digits amount
Throws:
java.lang.IllegalArgumentException