Package fr.iut.tetris

Class 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 one
      boolean getBool​(java.lang.String key)
      Read a boolean from the config file
      java.lang.Object getCachedObject​(java.lang.String key)
      Read an object from memory
      java.awt.Font getFont​(java.lang.String key)
      Return a font with correct size specified in the config
      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
      int getInt​(java.lang.String key)
      Read a int from the config file
      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
      java.lang.String getString​(java.lang.String key)
      Read a string from the config file
      void putBool​(java.lang.String key, boolean value)
      Save a boolean a the emplacement "key" in th config file
      void putInt​(java.lang.String key, int value)
      Save a int a the emplacement "key" in th config file
      void putString​(java.lang.String key, java.lang.String value)
      Save a string a the emplacement "key" in th config file
      void reloadFonts()
      Reload fonts (used after a resolution change)
      void saveAsync()
      Save the config asynchronously to a file
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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
    • Constructor Detail

      • Config

        public Config()
        Load the config and generate fonts used by the program
    • 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 later
        obj - 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 string
        value - 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 int
        value - 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 boolean
        value - 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