com.quadrique.jbuildingblocks.core.application.preferences
Class JbbUserPreferences

java.lang.Object
  extended by com.quadrique.jbuildingblocks.core.application.preferences.JbbUserPreferences

public class JbbUserPreferences
extends Object

This class is used to save/retrieve the user preferences for a given client side application. Please note that this is different than the ApplicationParameters that are appplicable to all user sof the application

Version:
1.0.0
Author:
Hervé Rivere

Constructor Summary
JbbUserPreferences()
          constructor
 
Method Summary
 Color getColorPreference(String zKey)
          Retrieve the color value associated to the given key
static JbbUserPreferences getInstance()
          This method returns an instance of the UserPreferences class.
 String getPreference(String zKey)
          Retrieve the value associated to the given key
 ArrayList<String> getPreferences(String zParentKey, String zChildrenKey)
          To retrieve a preference that is multi-valued: this method retrieves all the values associated to the given parent key and the child key (i.e.
 void initialize(String zPreferencesFileName)
          Open the preferences file (if any)
 boolean isInitialized()
           
 void save(String zPreferencesFileName)
          Save the preferences file
 void setColorPreference(String zKey, Color zValue)
          Set the color value associated to the given key
 void setPreference(String zKey, String zValue)
          Set the value associated to the given key
 void setPreferences(String zParentKey, String zChildrenKey, ArrayList<String> zValues)
          To set a preference that is multi-valued.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JbbUserPreferences

public JbbUserPreferences()
constructor

Method Detail

getInstance

public static final JbbUserPreferences getInstance()
This method returns an instance of the UserPreferences class. If there has been already one instantiation, the same instance is returned so that it can be shared accross the application. A typical usage would be: UserPreferences.getInstance().getXxxx() or UserPreferences lPreferences = UserPreferences.getInstance();

Returns:
the unique UserPreferences instance

initialize

public void initialize(String zPreferencesFileName)
                throws Exception
Open the preferences file (if any)

Parameters:
zPreferencesFileName - the full preferences file name
Throws:
Exception - if an error occurs

isInitialized

public boolean isInitialized()
Returns:
true if acquireConnection or false otherwise

getPreference

public String getPreference(String zKey)
                     throws Exception
Retrieve the value associated to the given key

Parameters:
zKey - the key that identifies the preference in the preferences file
Returns:
the value associated to this key or null
Throws:
Exception - if an error occurs

getPreferences

public ArrayList<String> getPreferences(String zParentKey,
                                        String zChildrenKey)
                                 throws Exception
To retrieve a preference that is multi-valued: this method retrieves all the values associated to the given parent key and the child key (i.e. with ...Val1Val2 ...ValN ... , the method will return an ArrayList instance that contains Val1,Val2 and ValN)

Parameters:
zParentKey - the parent key that identifies the preference in the preferences file
zChildrenKey - the children key that identifies the individual values in the preferences file under the parent key
Returns:
an ArrayList instance that contains the values (can be empty if none)
Throws:
Exception - if an error occurs

getColorPreference

public Color getColorPreference(String zKey)
                         throws Exception
Retrieve the color value associated to the given key

Parameters:
zKey - the key that identifies the preference in the preferences file
Returns:
the value associated to this key or null
Throws:
Exception - if an error occurs

setPreference

public void setPreference(String zKey,
                          String zValue)
                   throws Exception
Set the value associated to the given key

Parameters:
zKey - the key that identifies the preference in the preferences file
zValue - the value
Throws:
Exception - if an error occurs

setColorPreference

public void setColorPreference(String zKey,
                               Color zValue)
                        throws Exception
Set the color value associated to the given key

Parameters:
zKey - the key that identifies the preference in the preferences file
zValue - the color value
Throws:
Exception - if an error occurs

setPreferences

public void setPreferences(String zParentKey,
                           String zChildrenKey,
                           ArrayList<String> zValues)
                    throws Exception
To set a preference that is multi-valued. From an ArrayList instance that contains Val1,Val2 and ValN, the method builds something of the form: ...Val1Val2 ...ValN ... ,

Parameters:
zParentKey - the key that identifies the preference in the preferences file
zChildrenKey - the key that identifies the individual value in the preferences file
zValues - the values
Throws:
Exception - if an error occurs

save

public void save(String zPreferencesFileName)
          throws Exception
Save the preferences file

Parameters:
zPreferencesFileName - the full preferences file name
Throws:
Exception - if an error occurs


Copyright © 2001-2008 Quadrique Corporation. All Rights Reserved.