javax.swing.text
Class DateFormatter

java.lang.Object
  extended byjavax.swing.JFormattedTextField.AbstractFormatter
      extended byjavax.swing.text.DefaultFormatter
          extended byjavax.swing.text.InternationalFormatter
              extended byjavax.swing.text.DateFormatter
All Implemented Interfaces:
Cloneable, Serializable
Direct Known Subclasses:
JSpinner.DateEditorFormatter

public class DateFormatter
extends InternationalFormatter

DateFormatter is an InternationalFormatter that does its formatting by way of an instance of java.text.DateFormat.

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeansTM has been added to the java.beans package. Please see XMLEncoder.

Since:
1.4
See Also:
DateFormat, Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.text.InternationalFormatter
InternationalFormatter.ExtendedReplaceHolder
 
Nested classes inherited from class javax.swing.text.DefaultFormatter
DefaultFormatter.ReplaceHolder
 
Field Summary
 
Fields inherited from class javax.swing.text.InternationalFormatter
 
Fields inherited from class javax.swing.text.DefaultFormatter
replaceHolder
 
Fields inherited from class javax.swing.JFormattedTextField.AbstractFormatter
 
Constructor Summary
DateFormatter()
          This is shorthand for new DateFormatter(DateFormat.getDateInstance()).
DateFormatter(DateFormat format)
          Returns a DateFormatter configured with the specified Format instance.
 
Method Summary
(package private)  Object adjustValue(Object value, Map attributes, Object key, int direction)
          Adjusts the Date if FieldPosition identifies a known calendar field.
(package private)  Object getAdjustField(int start, Map attributes)
          Returns the field that will be adjusted by adjustValue.
private  Calendar getCalendar()
          Returns the Calendar that DateFormat is associated with, or if the Format is not a DateFormat Calendar.getInstance is returned.
(package private)  boolean getSupportsIncrement()
          Returns true, as DateFormatterFilter will support incrementing/decrementing of the value.
 void setFormat(DateFormat format)
          Sets the format that dictates the legal values that can be edited and displayed.
 
Methods inherited from class javax.swing.text.InternationalFormatter
canIncrement, canReplace, clone, getActions, getAttributes, getAttributeStart, getBufferedChar, getFields, getFormat, getIterator, getLiteral, getLiteralCountTo, getMaximum, getMinimum, getReplaceHolder, install, isLiteral, isLiteral, isNavigatable, isValidMask, isValidValue, replace, replace, resetValue, selectField, setFormat, setMaximum, setMinimum, stringToValue, stringToValue, updateMask, updateMaskIfNecessary, updateValue, valueToString
 
Methods inherited from class javax.swing.text.DefaultFormatter
commitEdit, getAllowsInvalid, getCommitsOnValidEdit, getDocumentFilter, getInitialVisualPosition, getNavigationFilter, getNextCursorPosition, getNextVisualPositionFrom, getOverwriteMode, getReplaceString, getValueClass, isLegalInsertText, isValidEdit, moveDot, positionCursorAtInitialLocation, repositionCursor, setAllowsInvalid, setCommitsOnValidEdit, setDot, setOverwriteMode, setValueClass, updateValue
 
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
 

Constructor Detail

DateFormatter

public DateFormatter()
This is shorthand for new DateFormatter(DateFormat.getDateInstance()).


DateFormatter

public DateFormatter(DateFormat format)
Returns a DateFormatter configured with the specified Format instance.

Parameters:
format - Format used to dictate legal values
Method Detail

setFormat

public void setFormat(DateFormat format)
Sets the format that dictates the legal values that can be edited and displayed.

If you have used the nullary constructor the value of this property will be determined for the current locale by way of the Dateformat.getDateInstance() method.

Parameters:
format - DateFormat instance used for converting from/to Strings

getCalendar

private Calendar getCalendar()
Returns the Calendar that DateFormat is associated with, or if the Format is not a DateFormat Calendar.getInstance is returned.


getSupportsIncrement

boolean getSupportsIncrement()
Returns true, as DateFormatterFilter will support incrementing/decrementing of the value.

Overrides:
getSupportsIncrement in class InternationalFormatter

getAdjustField

Object getAdjustField(int start,
                      Map attributes)
Returns the field that will be adjusted by adjustValue.

Overrides:
getAdjustField in class InternationalFormatter

adjustValue

Object adjustValue(Object value,
                   Map attributes,
                   Object key,
                   int direction)
             throws BadLocationException,
                    ParseException
Adjusts the Date if FieldPosition identifies a known calendar field.

Overrides:
adjustValue in class InternationalFormatter
Throws:
BadLocationException
ParseException