示例#1
0
 public static TextStyle valueOf(string name)
 {
     foreach (TextStyle enumInstance in TextStyle.values())
     {
         if (enumInstance.nameValue == name)
         {
             return(enumInstance);
         }
     }
     throw new System.ArgumentException(name);
 }
示例#2
0
 /// <summary>
 /// Returns the stand-alone style with the same size. </summary>
 /// <returns> the stand-alone style with the same size </returns>
 public TextStyle AsStandalone()
 {
     return(TextStyle.values()[ordinal() | 1]);
 }
示例#3
0
 /// <summary>
 /// Returns the normal style with the same size.
 /// </summary>
 /// <returns> the normal style with the same size </returns>
 public TextStyle AsNormal()
 {
     return(TextStyle.values()[ordinal() & ~1]);
 }
示例#4
0
        private Object CreateStore(TemporalField field, Locale locale)
        {
            IDictionary <TextStyle, IDictionary <Long, String> > styleMap = new Dictionary <TextStyle, IDictionary <Long, String> >();

            if (field == ERA)
            {
                foreach (TextStyle textStyle in TextStyle.values())
                {
                    if (textStyle.Standalone)
                    {
                        // Stand-alone isn't applicable to era names.
                        continue;
                    }
                    IDictionary <String, Integer> displayNames = CalendarDataUtility.retrieveJavaTimeFieldValueNames("gregory", DateTime.ERA, textStyle.toCalendarStyle(), locale);
                    if (displayNames != null)
                    {
                        IDictionary <Long, String> map = new Dictionary <Long, String>();
                        foreach (Map_Entry <String, Integer> entry in displayNames)
                        {
                            map[(long)entry.Value] = entry.Key;
                        }
                        if (map.Count > 0)
                        {
                            styleMap[textStyle] = map;
                        }
                    }
                }
                return(new LocaleStore(styleMap));
            }

            if (field == MONTH_OF_YEAR)
            {
                foreach (TextStyle textStyle in TextStyle.values())
                {
                    IDictionary <String, Integer> displayNames = CalendarDataUtility.retrieveJavaTimeFieldValueNames("gregory", DateTime.MONTH, textStyle.toCalendarStyle(), locale);
                    IDictionary <Long, String>    map          = new Dictionary <Long, String>();
                    if (displayNames != null)
                    {
                        foreach (Map_Entry <String, Integer> entry in displayNames)
                        {
                            map[(long)(entry.Value + 1)] = entry.Key;
                        }
                    }
                    else
                    {
                        // Narrow names may have duplicated names, such as "J" for January, Jun, July.
                        // Get names one by one in that case.
                        for (int month = 1; month <= 12; month++)
                        {
                            String name;
                            name = CalendarDataUtility.retrieveJavaTimeFieldValueName("gregory", DateTime.MONTH, month, textStyle.toCalendarStyle(), locale);
                            if (name == null)
                            {
                                break;
                            }
                            map[(long)(month + 1)] = name;
                        }
                    }
                    if (map.Count > 0)
                    {
                        styleMap[textStyle] = map;
                    }
                }
                return(new LocaleStore(styleMap));
            }

            if (field == DAY_OF_WEEK)
            {
                foreach (TextStyle textStyle in TextStyle.values())
                {
                    IDictionary <String, Integer> displayNames = CalendarDataUtility.retrieveJavaTimeFieldValueNames("gregory", DateTime.DAY_OF_WEEK, textStyle.toCalendarStyle(), locale);
                    IDictionary <Long, String>    map          = new Dictionary <Long, String>();
                    if (displayNames != null)
                    {
                        foreach (Map_Entry <String, Integer> entry in displayNames)
                        {
                            map[(long)ToWeekDay(entry.Value)] = entry.Key;
                        }
                    }
                    else
                    {
                        // Narrow names may have duplicated names, such as "S" for Sunday and Saturday.
                        // Get names one by one in that case.
                        for (int wday = DayOfWeek.Sunday; wday <= DayOfWeek.Saturday; wday++)
                        {
                            String name;
                            name = CalendarDataUtility.retrieveJavaTimeFieldValueName("gregory", DateTime.DAY_OF_WEEK, wday, textStyle.toCalendarStyle(), locale);
                            if (name == null)
                            {
                                break;
                            }
                            map[(long)ToWeekDay(wday)] = name;
                        }
                    }
                    if (map.Count > 0)
                    {
                        styleMap[textStyle] = map;
                    }
                }
                return(new LocaleStore(styleMap));
            }

            if (field == AMPM_OF_DAY)
            {
                foreach (TextStyle textStyle in TextStyle.values())
                {
                    if (textStyle.Standalone)
                    {
                        // Stand-alone isn't applicable to AM/PM.
                        continue;
                    }
                    IDictionary <String, Integer> displayNames = CalendarDataUtility.retrieveJavaTimeFieldValueNames("gregory", DateTime.AM_PM, textStyle.toCalendarStyle(), locale);
                    if (displayNames != null)
                    {
                        IDictionary <Long, String> map = new Dictionary <Long, String>();
                        foreach (Map_Entry <String, Integer> entry in displayNames)
                        {
                            map[(long)entry.Value] = entry.Key;
                        }
                        if (map.Count > 0)
                        {
                            styleMap[textStyle] = map;
                        }
                    }
                }
                return(new LocaleStore(styleMap));
            }

            if (field == IsoFields.QUARTER_OF_YEAR)
            {
                // The order of keys must correspond to the TextStyle.values() order.
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final String[] keys = { "QuarterNames", "standalone.QuarterNames", "QuarterAbbreviations", "standalone.QuarterAbbreviations", "QuarterNarrows", "standalone.QuarterNarrows"};
                String[] keys = new String[] { "QuarterNames", "standalone.QuarterNames", "QuarterAbbreviations", "standalone.QuarterAbbreviations", "QuarterNarrows", "standalone.QuarterNarrows" };
                for (int i = 0; i < keys.Length; i++)
                {
                    String[] names = GetLocalizedResource(keys[i], locale);
                    if (names != null)
                    {
                        IDictionary <Long, String> map = new Dictionary <Long, String>();
                        for (int q = 0; q < names.Length; q++)
                        {
                            map[(long)(q + 1)] = names[q];
                        }
                        styleMap[TextStyle.values()[i]] = map;
                    }
                }
                return(new LocaleStore(styleMap));
            }

            return("");            // null marker for map
        }