be.saltwater.jaqel.settings
Class SettingsManager

java.lang.Object
  extended bybe.saltwater.jaqel.settings.SettingsManager

public class SettingsManager
extends java.lang.Object

This is the main class for accessing and modifying the settings of the application. Every setting has a name (the key) and a value. It also has permissions whether modification is allowed and whether the setting should be stored by when passed to a SettingsWriter. There can be only one instance of a SettingsManager and you can get it with the static method getInstance(). You can read settings of several types (Integer, String, ...), but make sure that the value attached to the key you pass is of the type the method returns, otherwise null is returned. If uncertain, use readSetting(). There are readXXX(String key) and writeXXX(String key, XXX value) methods. Respectivly for reading and writing a setting of type XXX. When the application starts, create the neccesary SettingsReader objects and pass the only instance of this object to it's read() method. When the application terminates, create a SettingsWriter and pass the SettingsManager to it's write method. Below are the keys of some settings with some description:

KeyTypeDescription
language StringThe current language. Is modifiable but should be "en", "fr", "nl" or "de".
data_pathStringThe path where all the data (models, textures, ...) are stored.
creature_pathStringThe path where all creature files are stored.
weapon_pathStringThe path where all weapon files are stored.
maze_pathStringThe path where all maze files are stored.

Author:
Bruno Windels
See Also:
SettingsReader, SettingsWriter

Method Summary
protected  void addSetting(java.lang.String key, java.lang.Object value, byte permissions)
           
 void addSettingChangeListener(java.lang.String key, SettingChangeListener listener)
          'listener' will be notified (his settingChanged method will be called) if the setting with key 'key' is modified.
static SettingsManager getInstance()
           
protected  java.util.Iterator getIterator()
          Get the iterator of the setting keys, meant for SettingsWriter to iterate through all the keys.
protected  be.saltwater.jaqel.settings.Setting getSetting(java.lang.String key)
           
 java.lang.Boolean readBoolean(java.lang.String key)
          Read the value associated with key.
 java.lang.Integer readInteger(java.lang.String key)
          Read the value associated with key.
 java.lang.Object readSetting(java.lang.String key)
          Read the value associated with key, you will have to determine the type yourself.
 java.lang.String readString(java.lang.String key)
          Read the value associated with key.
 void writeBoolean(java.lang.String key, java.lang.Boolean value)
          Set the value of setting 'key' to value.
 void writeInteger(java.lang.String key, java.lang.Integer value)
          Set the value of setting 'key' to value.
 void writeString(java.lang.String key, java.lang.String value)
          Set the value of setting 'key' to value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

addSetting

protected void addSetting(java.lang.String key,
                          java.lang.Object value,
                          byte permissions)

getSetting

protected be.saltwater.jaqel.settings.Setting getSetting(java.lang.String key)

readSetting

public java.lang.Object readSetting(java.lang.String key)
Read the value associated with key, you will have to determine the type yourself. It is probably better to use the type specific read... methods.


writeString

public void writeString(java.lang.String key,
                        java.lang.String value)
Set the value of setting 'key' to value.

Throws:
java.lang.IllegalAccessException - When this setting may not be modified.

readString

public java.lang.String readString(java.lang.String key)
Read the value associated with key.

Returns:
null if the key does not exists or it is not an String, otherwise the value.

writeInteger

public void writeInteger(java.lang.String key,
                         java.lang.Integer value)
Set the value of setting 'key' to value.

Throws:
java.lang.IllegalAccessException - When this setting cannot be modified.

readInteger

public java.lang.Integer readInteger(java.lang.String key)
Read the value associated with key.

Returns:
null if the key does not exists or it is not an Integer, otherwise the value.

readBoolean

public java.lang.Boolean readBoolean(java.lang.String key)
Read the value associated with key.

Returns:
null if the key does not exists or it is not a Boolean, otherwise the value.

writeBoolean

public void writeBoolean(java.lang.String key,
                         java.lang.Boolean value)
Set the value of setting 'key' to value.

Throws:
java.lang.IllegalAccessException - When this setting may not be modified.

addSettingChangeListener

public void addSettingChangeListener(java.lang.String key,
                                     SettingChangeListener listener)
'listener' will be notified (his settingChanged method will be called) if the setting with key 'key' is modified.

See Also:
SettingChangeListener

getIterator

protected java.util.Iterator getIterator()
Get the iterator of the setting keys, meant for SettingsWriter to iterate through all the keys.


getInstance

public static SettingsManager getInstance()