Package com.dkt.graphics.utils.config
Class Config
java.lang.Object
com.dkt.graphics.utils.config.Config
- All Implemented Interfaces:
 Serializable
This class represents a generic Configuration class, with change listeners.
 This class supports a 
ConfigListener that is fired when key-values
 are updated, added or removed on a per config basis.- Author:
 - Federico Vera <dktcoding [at] gmail>
 - See Also:
 
- 
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(ConfigListener listener) Adds a newConfigListenerto thisconfig, this listeners will be notified of all the changes that happen to thenon-volatilefield of this config.static ConfigA wrapper foron(String)Retrieves a rawvaluefor a givenkeybooleanRetrieves thevaluefor a givenkeyas abooleandoubleRetrieves thevaluefor a givenkeyas adoubleRetrieves thevaluefor a givenkeyas anImageIconintRetrieves thevaluefor a givenkeyas anintRetrieves thevaluefor a givenkeyas aStringstatic ConfigRetrieves aConfiginstance associated with a givenname, this is usually the module/plugin name.voidSet's a configkey,valuepair.static voidread(InputStream is, String name) static voidDestroys an instance ofConfigfor a givenname, this is useful when you have more than one application using this Class, and they don't start and stop at the same time.voidremoveListener(ConfigListener listener) Removes a previously registeredConfigListenervoidsave(OutputStream os) SavesthisConfigin the givenOutputStream.static voidsaveAll(OutputStream os) Saves all the available Configs in the givenOutputStream.voidA wrapper forConfig.put(String,Object)static intsize()Retrieves the number of createdConfigobjects. 
- 
Method Details
- 
from
A wrapper foron(String)- Parameters:
 name- config name- Returns:
 Configobject- See Also:
 
 - 
on
Retrieves aConfiginstance associated with a givenname, this is usually the module/plugin name.
Config myApp = Config.on("my.config"); myApp.set("key.1", "value.1"); ...- Parameters:
 name- config name- Returns:
 Configobject
 - 
remove
Destroys an instance ofConfigfor a givenname, this is useful when you have more than one application using this Class, and they don't start and stop at the same time.- Parameters:
 name- config name
 - 
configSet
- Returns:
 - Set of configs
 
 - 
size
public static int size()Retrieves the number of createdConfigobjects.- Returns:
 - number of configs
 
 - 
set
A wrapper forConfig.put(String,Object)- Parameters:
 key-keyvalue-value- See Also:
 
 - 
put
Set's a configkey,valuepair. This values can be exported and imported.
Note: every change in this values will trigger aConfigEventon all the registeredConfigListeners.- Parameters:
 key-keyvalue-value- See Also:
 
 - 
get
Retrieves a rawvaluefor a givenkey- Parameters:
 key-key- Returns:
 value
 - 
getColor
- Parameters:
 key-key- Returns:
 - value as 
Color - Throws:
 ClassCastException- if thevalueisn't aColor
 - 
getBool
Retrieves thevaluefor a givenkeyas aboolean- Parameters:
 key-key- Returns:
 - value as 
Boolean - Throws:
 ClassCastException- if thevalueisn't aBoolean
 - 
getDouble
Retrieves thevaluefor a givenkeyas adouble- Parameters:
 key-key- Returns:
 - value as 
Double - Throws:
 ClassCastException- if thevalueisn't aDouble
 - 
getIcon
Retrieves thevaluefor a givenkeyas anImageIcon- Parameters:
 key-key- Returns:
 - value as 
ImageIcon - Throws:
 ClassCastException- if thevalueisn't aImageIcon
 - 
getInt
Retrieves thevaluefor a givenkeyas anint- Parameters:
 key-key- Returns:
 - value as 
Integer - Throws:
 ClassCastException- if thevalueisn't aInteger
 - 
getString
Retrieves thevaluefor a givenkeyas aString- Parameters:
 key-key- Returns:
 - value as 
String - Throws:
 ClassCastException- if thevalueisn't aString
 - 
addListener
Adds a newConfigListenerto thisconfig, this listeners will be notified of all the changes that happen to thenon-volatilefield of this config.- Parameters:
 listener-ConfigListener
 - 
removeListener
Removes a previously registeredConfigListener- Parameters:
 listener-ConfigListener
 - 
saveAll
Saves all the available Configs in the givenOutputStream.Note: all of the values of the
Configobject must beSerializablefor this to work- Parameters:
 os-OutputStreamon which to write- Throws:
 IOException- in case an I/O error occurs- See Also:
 
 - 
save
SavesthisConfigin the givenOutputStream.Note: all of the values of the
Configobject must beSerializablefor this to work- Parameters:
 os-OutputStreamon which to write- Throws:
 IOException- in case an I/O error occurs- See Also:
 
 - 
read
- Parameters:
 is-InputStreamfrom which to readname- If reading a singleConfigthis is the name it will have when callingfrom(java.lang.String), it should benullwhen reading a set of configs.- Throws:
 IOException- in case an I/O error occursClassNotFoundException- If theInputStreamdoesn't point to an appropriateConfig- See Also:
 
 
 -