Class LocaleHelper


  • public class LocaleHelper
    extends Object
    Helper class for locale setup (see ISO 639).
    Version:
    $Revision$
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    • Field Detail

      • LOCALE_DEFAULT

        public static final String LOCALE_DEFAULT
        the constant for the system's default locale.
        See Also:
        Constant Field Values
      • m_Singleton

        protected static LocaleHelper m_Singleton
        the singleton.
      • m_Properties

        protected Properties m_Properties
        the properties.
      • m_Modified

        protected boolean m_Modified
        whether the settings got modified.
      • m_DecimalSeparator

        protected char m_DecimalSeparator
        the character for the decimal point.
      • m_GroupingSeparator

        protected char m_GroupingSeparator
        the character for the grouping.
      • m_LocaleEnUS

        protected Locale m_LocaleEnUS
        en_US locale instance.
    • Method Detail

      • initialize

        protected void initialize()
        Initializes the helper.
      • initializeLocale

        public void initializeLocale()
        Initializes the locale with the current settings.
      • isModified

        public boolean isModified()
        Whether the settings got modified.
        Returns:
        true if modified
      • getLocale

        public String getLocale()
        Returns the locale.
        Returns:
        the locale
      • setLocale

        public void setLocale​(String value)
        Updates the locale.
        Parameters:
        value - the locale
      • getDefault

        public Locale getDefault()
        Returns the default locale.
        Returns:
        the default
      • setDefault

        public void setDefault​(String value)
        Sets the new default locale.
        Parameters:
        value - the new default
      • setDefault

        public void setDefault​(Locale value)
        Sets the new default locale.
        Parameters:
        value - the new default
      • getEnUS

        public Locale getEnUS()
        Returns the en_US locale.
        Returns:
        the en_US locale
      • getDecimalSeparator

        public char getDecimalSeparator()
        Returns the character representing the separator for the decimals, i.e., "." in english locales.
        Returns:
        the character
      • getDecimalSeparator

        public char getDecimalSeparator​(Locale locale)
        Returns the character representing the separator for the decimals for the specified locale, i.e., "." in english locales.
        Parameters:
        locale - the locale to get the separator for
        Returns:
        the character
      • getGroupingSeparator

        public char getGroupingSeparator()
        Returns the character representing the separator for the grouping, i.e., "," in english locales.
        Returns:
        the character
      • getGroupingSeparator

        public char getGroupingSeparator​(Locale locale)
        Returns the character representing the separator for the grouping for the specified locale, i.e., "," in english locales.
        Parameters:
        locale - the locale to get the separator for
        Returns:
        the character
      • getNumberFormat

        public NumberFormat getNumberFormat()
        Returns the number format for the default locale. Grouping is always disabled.
        Returns:
        the format
        See Also:
        getNumberFormat(Locale)
      • getNumberFormat

        public NumberFormat getNumberFormat​(Locale locale)
        Returns the number format for the specified locale. Grouping is always disabled.
        Parameters:
        locale - the locale to get the format for
        Returns:
        the format
      • getNumberFormatEnUS

        public NumberFormat getNumberFormatEnUS()
        Returns the number format for the en_US locale. Grouping is always disabled.
        Returns:
        the format
        See Also:
        getNumberFormat(Locale)
      • reload

        public void reload()
        Reloads the properties file. Discards any unsaved settings.
      • save

        public boolean save()
        Saves the settings in the user's home directory.
        Returns:
        true if successfully saved
      • getSingleton

        public static LocaleHelper getSingleton()
        Returns the singleton.
        Returns:
        the singleton
      • toString

        public static String toString​(Locale l)
        Returns the locale as string.
        Parameters:
        l - the locale object to convert
        Returns:
        the generated string
      • valueOf

        public static Locale valueOf​(String str)
        Returns a locale generated from the string (eg en, en_US).
        Parameters:
        str - the string to convert to a locale
        Returns:
        the generated locale
      • getIDs

        public static String[] getIDs()
        Returns all the locale IDs, including LOCALE_DEFAULT.
        Returns:
        the IDs