home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Languages Suite
/
ProgLangD.iso
/
VCAFE.3.0A
/
Main.bin
/
DateMaskFormatter.java
< prev
next >
Wrap
Text File
|
1998-12-09
|
3KB
|
94 lines
/*
* @(#DateMaskFormatter.java
*
* Copyright (c) 1998 Symantec Corporation. All Rights Reserved.
*
*/
package com.symantec.itools.swing;
import java.text.DateFormat;
import java.io.Serializable;
/**
* DateMaskFormatter is like a factory class which can be used to get the
* date formatter based on the current locale, type and formatting style.
* It delegates all the work to DateFormat factory methods.
*
* @author Vasudev J. Rao
* @version 1.0
* @see java.text.DateFormat
* @see com.symantec.itools.swing.JMaskedTextField
*/
public class DateMaskFormatter implements Serializable {
/**
* Get an instance of date formatter for the given type and style. Type can be
* one of DateMaskedFieldConstants.DATE_TYPE, TIME_TYPE or TIMESTAMP_TYPE.
*
* @param type the given type.
* @param style the given formatting style.
* @return a date/time formatter.
*/
public DateFormat getInstance ( int type , int style ) {
DateFormat dateFormatter;
if ( type == DateMaskedFieldConstants.DATE_TYPE ) {
dateFormatter = getDateInstance ( style );
}
else if ( type == DateMaskedFieldConstants.TIME_TYPE ) {
dateFormatter = getTimeInstance ( style );
}
else if ( type == DateMaskedFieldConstants.TIMESTAMP_TYPE ) {
dateFormatter = getDateTimeInstance ( style );
}
else {
throw new IllegalArgumentException ( DateMaskedFieldConstants.INVALID_TYPE ) ;
}
return dateFormatter;
}
/**
* Get an instance of date formatter for the given style.
*
* @param style the given formatting style. For example, SHORT for "M/d/yy" in the US locale.
* @return a date formatter.
* @see java.text.DateFormat#getDateInstance ( int )
*/
public DateFormat getDateInstance ( int style ) {
return DateFormat.getDateInstance( style ) ;
}
/**
* Get an instance of time formatter for the given style.
*
* @param style the given formatting style.
* @return a time formatter.
* @see java.text.DateFormat#getTimeInstance ( int )
*/
public DateFormat getTimeInstance ( int style ) {
return DateFormat.getTimeInstance( style ) ;
}
/**
* Get an instance of timestamp formatter for the given style.
*
* @param style the given formatting style.
* @return a date/time formatter.
* @see java.text.DateFormat#getDateTimeInstance ( int , int )
*/
public DateFormat getDateTimeInstance ( int style ) {
return DateFormat.getDateTimeInstance( style , style ) ;
}
}