Package pi.config

Class ConfigurationGroup

java.lang.Object
pi.config.ConfigurationGroup
Direct Known Subclasses:
CoordinatesystemConfiguration, DebugConfiguration, GameConfiguration, GraphicsConfiguration, SoundConfiguration

public abstract class ConfigurationGroup extends Object
This class contains some basic functionality for all setting groups. It gets the SettingsGroupInfo annotation and reads out the prefix that is used when reading/ writing the settings into a property file.
Since:
0.42.0
Author:
Steffen Wilke, Matthias Wilke
  • Constructor Details

    • ConfigurationGroup

      protected ConfigurationGroup()
      Initializes a new instance of the ConfigurationGroup class.
  • Method Details

    • onChanged

      public void onChanged(ConfigurationGroup.ConfigurationChangedListener listener)
      Adds the specified configuration changed listener to receive events about any configuration property that changed.

      The event is supported for any property that uses the set(String, Object) method to set the field value.

      The event will provide you with the fieldName of the called setter (e.g. "debug" for the "setDebug" call).

      Parameters:
      listener - The listener to add.
      See Also:
    • removeListener

      public void removeListener(ConfigurationGroup.ConfigurationChangedListener listener)
      Removes the specified configuration changed listener.
      Parameters:
      listener - The listener to remove.
    • getPrefix

      public String getPrefix()
      Gets the prefix for the configuration group.
      Returns:
      The prefix for the configuration group, or an empty string if the prefix is null.
    • isDebug

      public boolean isDebug()
      Checks if debug mode is enabled.
      Returns:
      true if debug mode is enabled, false otherwise.
    • setDebug

      public void setDebug(boolean debug)
      Sets the debug mode.
      Parameters:
      debug - true to enable debug mode, false to disable.
    • initializeByProperty

      protected void initializeByProperty(String key, String value)
      Initializes a property by its key and value.
      Parameters:
      key - The key of the property.
      value - The value of the property.
    • storeProperties

      protected void storeProperties(Properties properties)
      Store properties. By default, it is supported to store the following types: boolean, int, double, float, String and enum values. If you need to store any other object, you should overwrite this method as well as the initializeProperty method and implement a custom approach.
      Parameters:
      properties - the properties
    • set

      protected <T> void set(String fieldName, T value)
      Use this method to set configuration properties if you want to support configurationChanged for your property.
      Type Parameters:
      T - The type of the value to set.
      Parameters:
      fieldName - The name of the field to set.
      value - The value to set.