Synergy Home Page

au.edu.swin.synergy.plugin.dialect
Class BDialect

java.lang.Object
  |
  +--au.edu.swin.synergy.kernel.BPlugin
        |
        +--au.edu.swin.synergy.plugin.dialect.BDialect

public class BDialect
extends BPlugin

The dialect class provides a common location for loading language resources from specific or global resources bundles.

This primarily consists of static methods which can be accessed without the need for command events however it will also add a language preferences panel to the Preferences plugin which will allow the user to change the current language to another.

When this happens, an dialect change event will be broadcast to all plugins on the client and it is up to them to update their users interfaces by requesting the required language resources from this plugin.

Author:
Tristan Austin

Field Summary
static String kGlobalTextFileName
          This is the default name the global property files will have
static String kPreferencesFile
          The path of the preferences file
protected static String kResourceExtension
          This is the file name extension for language resource files
static String kSavedLocale
          The key in the preferences file for the locale
static String kScreenTextFileName
          This is the default name the property files should have
 
Fields inherited from class au.edu.swin.synergy.kernel.BPlugin
kernel
 
Constructor Summary
BDialect()
           
 
Method Summary
protected  void doDialectChange()
          This will be called when the user changes the current dialect.
protected static void doLoad()
          This will load up the last used locale so that we can start up with the last locale used next time.
protected  void doSave()
          This will write the current locale to a file so that we can start up with the last locale used next time.
static String formatText(String formatMe, Object[] arguments)
          When dealing with compound messages, you need to specify the location and type of the arguments in the compound message in the following form: eg.
At {2,time,short} on {2,date,long}, we detected {1,number,integer} spaceships on the planet {0}.
 BStringList getDependancies()
          Return a list of plugin dependancies
static String getString(Object object, String key)
          This will find the screentext<>.properties file in the same directory as the class is defined of the object passed in.
static String getString(Object object, String key, Locale locale)
          This will find the screentext<>.properties file in the same directory as the class is defined of the object passed in.
static String getString(Object object, String key, Object[] args)
          This will find the screentext<>.properties file in the same directory as the class is defined of the object passed in.
static String getString(String key)
          This version of getString will search the global text language resource file for the text mapping to the given key.
static String getString(String key, Locale locale)
          This version of getString will search the global text language resource file for the text mapping to the given key.
 String getString(String key, Object[] args)
          This version of getString will search the global text language resource file for the text mapping to the given key.
 void onBCommandEvent(Object source, BCommandEvent event)
          When events are dispatched by the kernel, they are received here.
 void setup(BStringList params)
          Called by the kernel when the plugin is first loaded
 
Methods inherited from class au.edu.swin.synergy.kernel.BPlugin
dispatchEvent, dispatchEventAndWait, dispatchEventServer, dispatchEventServerAndWait, dispatchEventTo, dispatchEventToAndWait, getKernel, setKernel, setup, unload
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

kScreenTextFileName

public static final String kScreenTextFileName
This is the default name the property files should have

kResourceExtension

protected static final String kResourceExtension
This is the file name extension for language resource files

kGlobalTextFileName

public static final String kGlobalTextFileName
This is the default name the global property files will have

kPreferencesFile

public static final String kPreferencesFile
The path of the preferences file

kSavedLocale

public static final String kSavedLocale
The key in the preferences file for the locale
Constructor Detail

BDialect

public BDialect()
Method Detail

getString

public String getString(String key,
                        Object[] args)
This version of getString will search the global text language resource file for the text mapping to the given key.

In addition, it will take the arguments array and format the text before returning it initially.

Because the global properties file is defined by the BDialect plugin you don't need to specify any file or location, it already knows.

Parameters:
key - The key to be mapped to a value in the resource file
Returns:
The string mapped to the give key in the global resource file

getString

public static String getString(String key)
This version of getString will search the global text language resource file for the text mapping to the given key.

Because the global properties file is defined by the BDialect plugin you don't need to specify any file or location, it already knows.

Parameters:
key - The key to be mapped to a value in the resource file
Returns:
The string mapped to the give key in the global resource file

getString

public static String getString(String key,
                               Locale locale)
This version of getString will search the global text language resource file for the text mapping to the given key.

Because the global properties file is defined by the BDialect plugin you don't need to specify any file or location, it already knows.

Parameters:
key - The key to be mapped to a value in the resource file
locale - The locale to get the text for
Returns:
The string mapped to the give key in the global resource file

getString

public static String getString(Object object,
                               String key,
                               Object[] args)
This will find the screentext<>.properties file in the same directory as the class is defined of the object passed in.

For example, if the plugin au.edu.swin.synergy.plugin.mod13.BWindowManager wants to load a resource, it will pass in an instance of the window manager, or anything else declared in the same package.

The package is taken from it, converted to a path and the basename is appended to the end of the package. It will therefore try and locate it in the directory: ./au/edu/swin/synergy/plugin/mod13/screentext.properties or a more specific version for specific locales.

Parameters:
object - The object who's package indicates the location of the resource file
key - The key to be mapped to a value.
Returns:
The string value mapped to the given key for the current locale

getString

public static String getString(Object object,
                               String key)
This will find the screentext<>.properties file in the same directory as the class is defined of the object passed in.

For example, if the plugin au.edu.swin.synergy.plugin.mod13.BWindowManager wants to load a resource, it will pass in an instance of the window manager, or anything else declared in the same package.

The package is taken from it, converted to a path and the basename is appended to the end of the package. It will therefore try and locate it in the directory: ./au/edu/swin/synergy/plugin/mod13/screentext.properties or a more specific version for specific locales.

Parameters:
object - The object who's package indicates the location of the resource file
key - The key to be mapped to a value.
Returns:
The string value mapped to the given key for the current locale

getString

public static String getString(Object object,
                               String key,
                               Locale locale)
This will find the screentext<>.properties file in the same directory as the class is defined of the object passed in.

For example, if the plugin au.edu.swin.synergy.plugin.mod13.BWindowManager wants to load a resource, it will pass in an instance of the window manager, or anything else declared in the same package.

The package is taken from it, converted to a path and the basename is appended to the end of the package. It will therefore try and locate it in the directory: ./au/edu/swin/synergy/plugin/mod13/screentext.properties or a more specific version for specific locales.

Parameters:
object - The object who's package indicates the location of the resource file
key - The key to be mapped to a value.
locale - The locale to get the text for
Returns:
The string value mapped to the given key for the current locale

doDialectChange

protected void doDialectChange()
This will be called when the user changes the current dialect. It will make sure there is a change and update the contents of the resourceBundles hashtable as well as notify all the other plugins.

formatText

public static String formatText(String formatMe,
                                Object[] arguments)
When dealing with compound messages, you need to specify the location and type of the arguments in the compound message in the following form:

eg.
At {2,time,short} on {2,date,long}, we detected {1,number,integer} spaceships on the planet {0}.

Where {2, time, short} indicates the third argument in the argument array, it is a time and short is the short date format
{2, date, long} indicates the third argument again, date says it's in date format, and long says long date format
{1, number, integer} Indicates second argument in array, it's a number and should be an integer (as opposed to float)
{0} The first String in the argument array

Parameters:
formatMe - The compound string to format
arguments - The arguments for the compound statement

onBCommandEvent

public void onBCommandEvent(Object source,
                            BCommandEvent event)
When events are dispatched by the kernel, they are received here. Currently don't handle anything.
Overrides:
onBCommandEvent in class BPlugin

doSave

protected void doSave()
This will write the current locale to a file so that we can start up with the last locale used next time.

doLoad

protected static void doLoad()
This will load up the last used locale so that we can start up with the last locale used next time.

setup

public void setup(BStringList params)
Called by the kernel when the plugin is first loaded
Overrides:
setup in class BPlugin

getDependancies

public BStringList getDependancies()
Return a list of plugin dependancies
Returns:
a list of plugins such as "au.edu.swin.synergy.plugin.mod13.BWindowManager" or null if there are no dependancies
Overrides:
getDependancies in class BPlugin

Synergy Home Page