GeoSoft API

no.geosoft.cc.locale
Class LocaleManager

Object
  |
  +--LocaleManager

public class LocaleManager
extends Object

Class for holding current locale information, and notify client application about locale changes. Used for dynamic (or static) locale updates and language translations during a program session.

For language dependent user interfaces, put translation files into the packages where reguired. The files are named as follows: Messages_xx_XX.properties where xx is the laguage identifier and XX is the country identifier, for instance

   Messages_en_US.properties  // american
   Messages_fr_FR.properties  // french
   Messages_ch_CH.properties  // chineese
 
and so on. These are ordinary properties files containing language translations, for instance (french):
   Close = Fermer
   New   = Nouveau
   Help  = Aide
 
and (american):
   Close = Close
   New   = New
   Help  = Help
 

A locale aware GUI will use the locale manager like this:

   JButton helpButton = new JButton();
   :
   helpButton.setText (localeManager.getText ("Help"));
 
If the latter is done inside a localeChanged callback, the GUI will update itself dynamically if locale is changed during a session.

Author:
GeoSoft

Method Summary
 void addLocaleListener(LocaleListener localeListener)
          Add a locale listener.
 String getDate(Date date)
          Return default localized text reprentation of the specified date.
 String getDate(Date date, int style)
          Return default localized text reprentation of the specified date.
 DateFormat getDateFormat(int style)
          Get default date format for the current locale.
 String getDateTime(Date date)
          Return default localized text representation of the specified date/time.
 String getDateTime(Date date, int dateStyle, int timeStyle)
          Return default localized text representation of the specified date/time.
 DateFormat getDateTimeFormat(int dateStyle, int timeStyle)
          Get defaut date/time format for current locale.
static LocaleManager getInstance()
          Return the sole instance of this class.
 Locale getLocale()
          Return current locale.
 String getText(String tag)
          Return localized text for a specified tag.
 String getTime(Date date)
          Return default localized text representation of the specified time.
 String getTime(Date date, int style)
          Return default localized text representation of the specified time.
 DateFormat getTimeFormat(int style)
          Get default time format for the current locale.
 void removeLocaleListener(LocaleListener localeListener)
          Remove a locale listener.
 void setDefaultLocale(String language, String country)
          Set the default locale.
 void setLocale(Locale locale)
          Set current locale.
 void setLocale(String language, String country)
          Set the current locale, and notify listeners about the change.
 
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static LocaleManager getInstance()
Return the sole instance of this class.

Returns:
The sole locale manager instance.

setDefaultLocale

public void setDefaultLocale(String language,
                             String country)
Set the default locale. If a translation is not found for a key in the current locale, the current locale is used instead.

Parameters:
language - Language of default locale.
country - Country of default locale.

setLocale

public void setLocale(Locale locale)
Set current locale.

Parameters:
locale - New current locale.

getLocale

public Locale getLocale()
Return current locale.

Returns:
Current locale.

setLocale

public void setLocale(String language,
                      String country)
Set the current locale, and notify listeners about the change.

Parameters:
language - Language of new locale.
country - Country of new locale.

getText

public String getText(String tag)
Return localized text for a specified tag. The text is looked up in the resource bundle of the package of the caller.

Parameters:
tag - Tag of text to locate.
Returns:
Localized text of tag.

addLocaleListener

public void addLocaleListener(LocaleListener localeListener)
Add a locale listener. The listener is notified when the current locale of the LocaleManager is changed.

Parameters:
localeListener - Listener to add.

removeLocaleListener

public void removeLocaleListener(LocaleListener localeListener)
Remove a locale listener.

Parameters:
localeListener - Locale listener to remove.

getDateFormat

public DateFormat getDateFormat(int style)
Get default date format for the current locale.

Parameters:
style - One of DateFormat.SHORT, MEDIUM or LONG.
Returns:
Date format for current locale.

getTimeFormat

public DateFormat getTimeFormat(int style)
Get default time format for the current locale.

Parameters:
style - One of DateFormat.SHORT, MEDIUM or LONG.
Returns:
Time format for current locale.

getDateTimeFormat

public DateFormat getDateTimeFormat(int dateStyle,
                                    int timeStyle)
Get defaut date/time format for current locale.

Parameters:
dateStyle - One of DateFormat.SHORT, MEDIUM or LONG.
timeStyle - One of DateFormat.SHORT, MEDIUM or LONG.
Returns:
Date/time format for the currnt locale.

getDate

public String getDate(Date date)
Return default localized text reprentation of the specified date.

Parameters:
date - Date to format.
Returns:
String representation of specified date.

getDate

public String getDate(Date date,
                      int style)
Return default localized text reprentation of the specified date.

Parameters:
date - Date to format.
style - DateFormat.SHORT, MEDIUM or LONG
Returns:
String representation of specified date.

getTime

public String getTime(Date date,
                      int style)
Return default localized text representation of the specified time.

Parameters:
date - Time to format.
style - DateFormat.SHORT, MEDIUM or LONG
Returns:
String representation of specified time.

getTime

public String getTime(Date date)
Return default localized text representation of the specified time.

Parameters:
date - Time to format.
Returns:
String representation of specified time.

getDateTime

public String getDateTime(Date date,
                          int dateStyle,
                          int timeStyle)
Return default localized text representation of the specified date/time.

Parameters:
date - Date/time to format.
dateStyle - One of DateFormat.SHORT, MEDIUM or LONG.
timeStyle - One of DateFormat.SHORT, MEDIUM or LONG.
Returns:
String representation of specified date/time.

getDateTime

public String getDateTime(Date date)
Return default localized text representation of the specified date/time.

Parameters:
date - Date/time to format.
Returns:
String representation of specified date/time.

GeoSoft API

Copyright © 2004 - Geotechnical Software Services     geosoft.no