FileDocCategorySizeDatePackage
DateFormatter.javaAPI DocJava SE 5 API4295Fri Aug 26 14:58:14 BST 2005javax.swing.text

DateFormatter

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 {@link java.beans.XMLEncoder}.

see
java.text.DateFormat
version
1.5 04/09/01
since
1.4

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

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

param
format Format used to dictate legal values

        super(format);
        setFormat(format);
    
Methods Summary
java.lang.ObjectadjustValue(java.lang.Object value, java.util.Map attributes, java.lang.Object key, int direction)
Adjusts the Date if FieldPosition identifies a known calendar field.

        if (key != null) {
            int field;

            // HOUR1 has no corresponding calendar field, thus, map
            // it to HOUR0 which will give the correct behavior.
            if (key == DateFormat.Field.HOUR1) {
                key = DateFormat.Field.HOUR0;
            }
            field = ((DateFormat.Field)key).getCalendarField();

            Calendar calendar = getCalendar();

            if (calendar != null) {
                calendar.setTime((Date)value);

                int fieldValue = calendar.get(field);

                try {
                    calendar.add(field, direction);
                    value = calendar.getTime();
                } catch (Throwable th) {
                    value = null;
                }
                return value;
            }
        }
        return null;
    
java.lang.ObjectgetAdjustField(int start, java.util.Map attributes)
Returns the field that will be adjusted by adjustValue.

        Iterator attrs = attributes.keySet().iterator();

        while (attrs.hasNext()) {
            Object key = attrs.next();

            if ((key instanceof DateFormat.Field) &&
                (key == DateFormat.Field.HOUR1 || 
                 ((DateFormat.Field)key).getCalendarField() != -1)) {
                return key;
            }
        }
        return null;
    
private java.util.CalendargetCalendar()
Returns the Calendar that DateFormat is associated with, or if the Format is not a DateFormat Calendar.getInstance is returned.

        Format f = getFormat();

        if (f instanceof DateFormat) {
            return ((DateFormat)f).getCalendar();
        }
        return Calendar.getInstance();
    
booleangetSupportsIncrement()
Returns true, as DateFormatterFilter will support incrementing/decrementing of the value.

        return true;
    
public voidsetFormat(java.text.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.

param
format DateFormat instance used for converting from/to Strings

        super.setFormat(format);