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 TypeMethodDescriptionvoid
addListener
(ConfigListener listener) Adds a newConfigListener
to thisconfig
, this listeners will be notified of all the changes that happen to thenon-volatile
field of this config.static Config
A wrapper foron(String)
Retrieves a rawvalue
for a givenkey
boolean
Retrieves thevalue
for a givenkey
as aboolean
double
Retrieves thevalue
for a givenkey
as adouble
Retrieves thevalue
for a givenkey
as anImageIcon
int
Retrieves thevalue
for a givenkey
as anint
Retrieves thevalue
for a givenkey
as aString
static Config
Retrieves aConfig
instance associated with a givenname
, this is usually the module/plugin name.void
Set's a configkey,value
pair.static void
read
(InputStream is, String name) static void
Destroys an instance ofConfig
for 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.void
removeListener
(ConfigListener listener) Removes a previously registeredConfigListener
void
save
(OutputStream os) Savesthis
Config
in the givenOutputStream
.static void
saveAll
(OutputStream os) Saves all the available Configs in the givenOutputStream
.void
A wrapper forConfig.put(String,Object)
static int
size()
Retrieves the number of createdConfig
objects.
-
Method Details
-
from
A wrapper foron(String)
- Parameters:
name
- config name- Returns:
Config
object- See Also:
-
on
Retrieves aConfig
instance 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:
Config
object
-
remove
Destroys an instance ofConfig
for 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 createdConfig
objects.- Returns:
- number of configs
-
set
A wrapper forConfig.put(String,Object)
- Parameters:
key
-key
value
-value
- See Also:
-
put
Set's a configkey,value
pair. This values can be exported and imported.
Note: every change in this values will trigger aConfigEvent
on all the registeredConfigListener
s.- Parameters:
key
-key
value
-value
- See Also:
-
get
Retrieves a rawvalue
for a givenkey
- Parameters:
key
-key
- Returns:
value
-
getColor
- Parameters:
key
-key
- Returns:
- value as
Color
- Throws:
ClassCastException
- if thevalue
isn't aColor
-
getBool
Retrieves thevalue
for a givenkey
as aboolean
- Parameters:
key
-key
- Returns:
- value as
Boolean
- Throws:
ClassCastException
- if thevalue
isn't aBoolean
-
getDouble
Retrieves thevalue
for a givenkey
as adouble
- Parameters:
key
-key
- Returns:
- value as
Double
- Throws:
ClassCastException
- if thevalue
isn't aDouble
-
getIcon
Retrieves thevalue
for a givenkey
as anImageIcon
- Parameters:
key
-key
- Returns:
- value as
ImageIcon
- Throws:
ClassCastException
- if thevalue
isn't aImageIcon
-
getInt
Retrieves thevalue
for a givenkey
as anint
- Parameters:
key
-key
- Returns:
- value as
Integer
- Throws:
ClassCastException
- if thevalue
isn't aInteger
-
getString
Retrieves thevalue
for a givenkey
as aString
- Parameters:
key
-key
- Returns:
- value as
String
- Throws:
ClassCastException
- if thevalue
isn't aString
-
addListener
Adds a newConfigListener
to thisconfig
, this listeners will be notified of all the changes that happen to thenon-volatile
field 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
Config
object must beSerializable
for this to work- Parameters:
os
-OutputStream
on which to write- Throws:
IOException
- in case an I/O error occurs- See Also:
-
save
Savesthis
Config
in the givenOutputStream
.Note: all of the values of the
Config
object must beSerializable
for this to work- Parameters:
os
-OutputStream
on which to write- Throws:
IOException
- in case an I/O error occurs- See Also:
-
read
- Parameters:
is
-InputStream
from which to readname
- If reading a singleConfig
this is the name it will have when callingfrom(java.lang.String)
, it should benull
when reading a set of configs.- Throws:
IOException
- in case an I/O error occursClassNotFoundException
- If theInputStream
doesn't point to an appropriateConfig
- See Also:
-