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

  1. /*
  2.  * @(#JDateMaskedFieldStyleEditor.java
  3.  *
  4.  * Copyright (c) 1998 Symantec Corporation. All Rights Reserved.
  5.  *
  6.  */
  7. // package statement
  8. package com.symantec.itools.swing;
  9.  
  10. import java.beans.*;
  11. import com.symantec.itools.swing.*;
  12. import java.util.*;
  13. import java.text.DateFormat;
  14.  
  15. /**
  16.  * Property editor for setting the formatting style of JDateMaskedField.
  17.  *
  18.  * @author Vasudev J. Rao
  19.  * @version 1.0 
  20.  */
  21. public class JDateMaskedFieldStyleEditor extends PropertyEditorSupport {
  22.     // static variables
  23.     //private static BRLEditorsResourceLoader loader;
  24.     //private static ResourceBundle bundle;
  25.     
  26.     //static {
  27.         //loader = BRLEditorsResourceLoader.getInstance();
  28.         //bundle = loader.getBundle();
  29.     //}
  30.     
  31.     /**
  32.      * return the property value as a text
  33.      *
  34.      * @return the value as text
  35.      */
  36.     public String getAsText() {
  37.         Integer value = (Integer)getValue();
  38.         int intValue = value.intValue();
  39.         String text = null;
  40.  
  41.         if ( intValue == DateFormat.DEFAULT ) {
  42.             text = JDateMaskedField.DEFAULT_STYLE_STRING;
  43.         }
  44.         else if ( intValue == DateFormat.FULL ) {
  45.             text = JDateMaskedField.FULL_STYLE_STRING;
  46.         }
  47.         else if ( intValue == DateFormat.LONG ) {
  48.             text = JDateMaskedField.LONG_STYLE_STRING;
  49.         }
  50.         else if ( intValue == DateFormat.MEDIUM ) {
  51.             text = JDateMaskedField.MEDIUM_STYLE_STRING;
  52.         }
  53.         else if ( intValue == DateFormat.SHORT ) {
  54.             text = JDateMaskedField.SHORT_STYLE_STRING;
  55.         }
  56.         else {
  57.             text = "Illegal Value" ;
  58.         }
  59.  
  60.         return text;
  61.     }
  62.  
  63.     /**
  64.      * getTags() method
  65.      *
  66.      * @return array of tags
  67.      */
  68.     public String[] getTags() {
  69.         String[] tags = new String[ JDateMaskedField.NUMBER_OF_STYLES ];
  70.         tags[0] = new String( JDateMaskedField.DEFAULT_STYLE_STRING );
  71.         tags[1] = new String( JDateMaskedField.FULL_STYLE_STRING );
  72.         tags[2] = new String( JDateMaskedField.LONG_STYLE_STRING );
  73.         tags[3] = new String( JDateMaskedField.MEDIUM_STYLE_STRING );
  74.         tags[4] = new String( JDateMaskedField.SHORT_STYLE_STRING );
  75.  
  76.         return tags;
  77.     }
  78.  
  79.     /**
  80.      * setAsText() method
  81.      *
  82.      * @param text set to String
  83.      */
  84.     public void setAsText( String text ) throws IllegalArgumentException {
  85.         int type = 0 ;
  86.         if      ( text.equals ( JDateMaskedField.DEFAULT_STYLE_STRING ) ) {
  87.             type = DateFormat.DEFAULT;
  88.         }
  89.         else if ( text.equals ( JDateMaskedField.FULL_STYLE_STRING ) ) {
  90.             type = DateFormat.FULL;
  91.         }
  92.         else if ( text.equals ( JDateMaskedField.LONG_STYLE_STRING ) ) {
  93.             type = DateFormat.LONG;
  94.         }
  95.         else if ( text.equals ( JDateMaskedField.MEDIUM_STYLE_STRING ) ) {
  96.             type = DateFormat.MEDIUM;
  97.         }
  98.         else if ( text.equals ( JDateMaskedField.SHORT_STYLE_STRING ) ) {
  99.             type = DateFormat.SHORT;
  100.         }
  101.         else    {
  102.             type = DateFormat.LONG;
  103.         }
  104.         setValue( new Integer( type ) );
  105.     }
  106.  
  107.     /**
  108.      * This method is intended for use when generating Java code to set
  109.      * the value of the property.  It should return a fragment of Java code
  110.      * that can be used to initialize a variable with the current property
  111.      * value.
  112.      * <p>
  113.      * Example results are "2", "new Color(127,127,34)", "Color.orange", etc.
  114.      *
  115.      * @return A fragment of Java code representing an initializer for the
  116.      *       current value.
  117.      */
  118.     public String getJavaInitializationString() {
  119.         
  120.         StringBuffer buf = new StringBuffer();
  121.         Integer value = (Integer)getValue();
  122.         int intValue = value.intValue();
  123.         
  124.         buf.append ("java.text.DateFormat").append ("." );
  125.         if ( intValue == DateFormat.DEFAULT ) {
  126.             buf.append ( JDateMaskedField.DEFAULT_STYLE_STRING ) ;
  127.         }
  128.         else if ( intValue == DateFormat.FULL ) {
  129.             buf.append ( JDateMaskedField.FULL_STYLE_STRING );
  130.         }
  131.         else if ( intValue == DateFormat.LONG ) {
  132.             buf.append (JDateMaskedField.LONG_STYLE_STRING );
  133.         }
  134.         else if ( intValue == DateFormat.MEDIUM ) {
  135.             buf.append (JDateMaskedField.MEDIUM_STYLE_STRING );
  136.         }
  137.         else if ( intValue == DateFormat.SHORT ) {
  138.             buf.append (JDateMaskedField.SHORT_STYLE_STRING );
  139.         }
  140.         else {
  141.             buf .append ( JDateMaskedField.LONG_STYLE_STRING );
  142.         }
  143.         
  144.         return buf.toString();
  145.     }
  146. }
  147.