Package fr.iut.tetris
Class Config
- java.lang.Object
-
- fr.iut.tetris.Config
-
public class Config extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description (package private) java.lang.String
appConfigPath
(package private) java.util.Map<java.lang.String,java.lang.Object>
cachedRessources
(package private) java.util.Properties
config
(package private) java.util.Map<java.lang.String,java.awt.Font>
fonts
private static Config
inst
(package private) java.lang.String
rootPath
-
Constructor Summary
Constructors Constructor Description Config()
Load the config and generate fonts used by the program
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cacheObject(java.lang.String key, java.lang.Object obj)
Put an object into memory(package private) static java.util.Properties
defaultConfig()
Generate a default config in case the user don't have oneboolean
getBool(java.lang.String key)
Read a boolean from the config filejava.lang.Object
getCachedObject(java.lang.String key)
Read an object from memoryjava.awt.Font
getFont(java.lang.String key)
Return a font with correct size specified in the configstatic Config
getInstance()
Return the first instance of the config instead of re instantiation every time which would defeat the purpose of the caching mechanismint
getInt(java.lang.String key)
Read a int from the config filejava.awt.image.BufferedImage
getRessourceImage(java.lang.String name)
Load an image into memory for faster loading time later if the image is already cached when loading it if the image is not found a dummy will be loaded insteadjava.lang.String
getString(java.lang.String key)
Read a string from the config filevoid
putBool(java.lang.String key, boolean value)
Save a boolean a the emplacement "key" in th config filevoid
putInt(java.lang.String key, int value)
Save a int a the emplacement "key" in th config filevoid
putString(java.lang.String key, java.lang.String value)
Save a string a the emplacement "key" in th config filevoid
reloadFonts()
Reload fonts (used after a resolution change)void
saveAsync()
Save the config asynchronously to a file
-
-
-
Field Detail
-
rootPath
java.lang.String rootPath
-
appConfigPath
java.lang.String appConfigPath
-
config
java.util.Properties config
-
inst
private static volatile Config inst
-
fonts
java.util.Map<java.lang.String,java.awt.Font> fonts
-
cachedRessources
java.util.Map<java.lang.String,java.lang.Object> cachedRessources
-
-
Method Detail
-
getInstance
public static Config getInstance()
Return the first instance of the config instead of re instantiation every time which would defeat the purpose of the caching mechanism- Returns:
- Config
-
cacheObject
public void cacheObject(java.lang.String key, java.lang.Object obj)
Put an object into memory- Parameters:
key
- a string which you can use to retrive the key laterobj
- the object in question
-
getCachedObject
public java.lang.Object getCachedObject(java.lang.String key)
Read an object from memory- Parameters:
key
- the key used when using cacheObject- Returns:
- the object that have been cached
-
getRessourceImage
public java.awt.image.BufferedImage getRessourceImage(java.lang.String name)
Load an image into memory for faster loading time later if the image is already cached when loading it if the image is not found a dummy will be loaded instead- Parameters:
name
- the path of the image you wann read- Returns:
- The image at the path
-
reloadFonts
public void reloadFonts()
Reload fonts (used after a resolution change)
-
getFont
public java.awt.Font getFont(java.lang.String key)
Return a font with correct size specified in the config- Parameters:
key
- name of the font you want to get- Returns:
- the font
-
saveAsync
public void saveAsync()
Save the config asynchronously to a file
-
putString
public void putString(java.lang.String key, java.lang.String value)
Save a string a the emplacement "key" in th config file- Parameters:
key
- The emplacement of the stringvalue
- The string
-
putInt
public void putInt(java.lang.String key, int value)
Save a int a the emplacement "key" in th config file- Parameters:
key
- The emplacement of the intvalue
- The int
-
putBool
public void putBool(java.lang.String key, boolean value)
Save a boolean a the emplacement "key" in th config file- Parameters:
key
- The emplacement of the booleanvalue
- The boolean
-
getString
public java.lang.String getString(java.lang.String key)
Read a string from the config file- Parameters:
key
- The emplacement of the string- Returns:
- the string a the emplacement "key"
-
getInt
public int getInt(java.lang.String key)
Read a int from the config file- Parameters:
key
- The emplacement of the int- Returns:
- the int a the emplacement "key"
-
getBool
public boolean getBool(java.lang.String key)
Read a boolean from the config file- Parameters:
key
- The emplacement of the boolean- Returns:
- the boolean a the emplacement "key"
-
defaultConfig
static java.util.Properties defaultConfig()
Generate a default config in case the user don't have one- Returns:
- the default config
-
-