Package pi.config
Class ConfigurationGroup
java.lang.Object
pi.config.ConfigurationGroup
- Direct Known Subclasses:
CoordinatesystemConfiguration,DebugConfiguration,GameConfiguration,GraphicsConfiguration,SoundConfiguration
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceThis listener interface receives events when any property of the configuration changed. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedInitializes a new instance of theConfigurationGroupclass. -
Method Summary
Modifier and TypeMethodDescriptionGets the prefix for the configuration group.protected voidinitializeByProperty(String key, String value) Initializes a property by its key and value.booleanisDebug()Checks if debug mode is enabled.voidAdds the specified configuration changed listener to receive events about any configuration property that changed.voidRemoves the specified configuration changed listener.protected <T> voidUse this method to set configuration properties if you want to supportconfigurationChangedfor your property.voidsetDebug(boolean debug) Sets the debug mode.protected voidstoreProperties(Properties properties) Store properties.
-
Constructor Details
-
ConfigurationGroup
protected ConfigurationGroup()Initializes a new instance of theConfigurationGroupclass.
-
-
Method Details
-
onChanged
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
Removes the specified configuration changed listener.- Parameters:
listener- The listener to remove.
-
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
Initializes a property by its key and value.- Parameters:
key- The key of the property.value- The value of the property.
-
storeProperties
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
Use this method to set configuration properties if you want to supportconfigurationChangedfor 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.
-