home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 39 / IOPROG_39.ISO / SOFT / sdkjava40.exe / data1.cab / fg_Samples / Samples / ActiveX / JCalendar / JCalendarMonthEditor.java < prev    next >
Encoding:
Java Source  |  2000-05-04  |  1.9 KB  |  70 lines

  1. ///////////////////////////////////////////////////////////////////////////
  2. //
  3. //  JCalendarMonthEditor.java
  4. //
  5. //  This class is an editor for editing the calendar month. It uses
  6. //  PropertyEditorSupport.
  7. //
  8. //  (C) Copyright 1995 - 1999 Microsoft Corporation.  All rights reserved.
  9. //
  10. ///////////////////////////////////////////////////////////////////////////
  11.  
  12. import java.beans.*;
  13.  
  14. public class JCalendarMonthEditor extends PropertyEditorSupport
  15. {
  16.     
  17.     /**
  18.      * Returns a string representation of the property suitable for
  19.      * inclusion in java code. Note month being an int will be wrapped in Integer.
  20.      *
  21.      * @return  String  The java representation of the month.
  22.      */
  23.     public String getJavaInitializationString()
  24.     {
  25.         // start off with january
  26.        return ((Integer) getValue()).toString();
  27.     }
  28.  
  29.     /**
  30.      * Get the list of valid values for the month
  31.      *
  32.      * @return  String[]    The array of month names
  33.      */
  34.     public String[] getTags()
  35.     {
  36.         return JCalendar.monthNames;
  37.     }
  38.  
  39.     /**
  40.      * Return a string representation of the property suitable for display
  41.      *
  42.      * @return  String  The month name.
  43.      */
  44.     public String getAsText()
  45.     {
  46.         int month = ((Integer) getValue()).intValue();  // the month number;
  47.  
  48.         return JCalendar.monthNames[month];
  49.     }
  50.  
  51.     /**
  52.      * Set the value of the month based on the month name given as a string
  53.      *
  54.      * @param   String  The month name
  55.      */
  56.     public void setAsText(String month) throws java.lang.IllegalArgumentException
  57.     {
  58.         for(int i=0; i< JCalendar.MONTHS_IN_YEAR; i++)
  59.         {
  60.             if( month.toLowerCase().equals(JCalendar.monthNames[i].toLowerCase()) )
  61.             {
  62.                 setValue(new Integer(i));
  63.                 return;
  64.             }
  65.         }
  66.      
  67.         throw new java.lang.IllegalArgumentException("Unknown month: "+month);
  68.     }
  69.  
  70. }