home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / VCAFE.3.0A / Main.bin / DateMaskFormatter.java < prev    next >
Text File  |  1998-12-09  |  3KB  |  94 lines

  1. /*
  2.  * @(#DateMaskFormatter.java
  3.  *
  4.  * Copyright (c) 1998 Symantec Corporation. All Rights Reserved.
  5.  *
  6.  */
  7. package com.symantec.itools.swing;
  8.  
  9. import java.text.DateFormat;
  10. import java.io.Serializable;
  11.  
  12. /**
  13.  * DateMaskFormatter is like a factory class which can be used to get the  
  14.  * date formatter based on the current locale, type and formatting style.
  15.  * It delegates all the work to DateFormat factory methods.
  16.  *
  17.  * @author Vasudev J. Rao
  18.  * @version 1.0 
  19.  * @see java.text.DateFormat
  20.  * @see com.symantec.itools.swing.JMaskedTextField
  21.  */
  22. public class DateMaskFormatter implements Serializable {
  23.     /**
  24.      * Get an instance of date formatter for the given type and style. Type can be 
  25.      * one of DateMaskedFieldConstants.DATE_TYPE, TIME_TYPE or TIMESTAMP_TYPE.
  26.      * 
  27.      * @param type the given type.
  28.      * @param style the given formatting style.
  29.      * @return a date/time formatter.
  30.      */
  31.     public DateFormat getInstance ( int type , int style  ) {
  32.         DateFormat dateFormatter;
  33.         if ( type == DateMaskedFieldConstants.DATE_TYPE ) {
  34.             dateFormatter = getDateInstance ( style );
  35.         }
  36.         else if ( type == DateMaskedFieldConstants.TIME_TYPE ) {
  37.             dateFormatter = getTimeInstance ( style );
  38.             
  39.         }
  40.         else if ( type == DateMaskedFieldConstants.TIMESTAMP_TYPE ) {
  41.             dateFormatter = getDateTimeInstance ( style );
  42.         
  43.         }
  44.         else {
  45.             
  46.             throw new IllegalArgumentException ( DateMaskedFieldConstants.INVALID_TYPE ) ;
  47.             
  48.         }
  49.         return dateFormatter;
  50.         
  51.     }
  52.     
  53.     
  54.     /**
  55.      * Get an instance of date formatter for the given style.
  56.      * 
  57.      * @param style the given formatting style. For example, SHORT for "M/d/yy" in the US locale.
  58.      * @return a date formatter.
  59.      * @see java.text.DateFormat#getDateInstance ( int )
  60.      */
  61.     public DateFormat getDateInstance ( int style  ) {
  62.         
  63.         return DateFormat.getDateInstance( style ) ;
  64.         
  65.     }
  66.     
  67.     /**
  68.      * Get an instance of time formatter for the given style.
  69.      * 
  70.      * @param style the given formatting style.
  71.      * @return a time formatter.
  72.      * @see java.text.DateFormat#getTimeInstance ( int )
  73.      */
  74.     public DateFormat getTimeInstance ( int style  ) {
  75.         
  76.         return DateFormat.getTimeInstance( style ) ;
  77.         
  78.     }
  79.   
  80.     /**
  81.      * Get an instance of timestamp formatter for the given style.
  82.      * 
  83.      * @param style the given formatting style.
  84.      * @return a date/time formatter.
  85.      * @see java.text.DateFormat#getDateTimeInstance ( int , int )
  86.      */
  87.     public DateFormat getDateTimeInstance ( int style  ) {
  88.         
  89.         return DateFormat.getDateTimeInstance( style , style ) ;
  90.         
  91.     }
  92. }
  93.     
  94.