Ridge is a simple App Development Suite for Java. It is programmed with Java, by Java Programmers for Java Programmers.
Ridge does not yet have Maven Hosting!
You can find the JAR file under the most recent release, and add it to your classpath.
A config is an object that is in charge of serializing and deserializing objects. The more used Java primitives come pre made with the Ridge library (Strings, Booleans, Integers, Floats, and Longs).
To create your own config, create a class and then extend the me.djtpj.files.config.Config
class. Enter the type you want to serialize and deserialize as the type parameter for the Config
class when you extend it.
A config requires one method: read(JSONObject jsonObject)
. This is where you tell the config how to deserialize the value. You have to assign the value once it is parsed to the value variable.
If the type you are trying to deserialize or serialize isn't a JSON primitive, then you will need to override the write method, and write your own JSON Serialization code.
Note: this uses the json-simple library for JSON handling.
Here is the code for the StringConfig
file
public class StringConfig extends Config<String> {
public StringConfig(String key, String value) {
super(key, value);
}
@Override
public void read(JSONObject jsonObject) {
value = (String) jsonObject.get(key);
}
}
A config manager is used to, well, manage your configs!
This will handle the group reading and writing of the configs to and from JSON.
You can configure your own ConfigManager, but it is recommended to use the DefaultConfigManager
class.
It is also recommended to extend this class, and make it a singleton so that you may have general access to your config manager.
You add configs to your config manager via the ConfigManager.addConfig()
function.
Once you have added your configs, and assigned them values and keys they can now be written! Call the ConfigManager.write()
function to write all of your configs.
Here is an example of writing
// Define the ConfigManager
DefaultConfigManager config = new DefaultConfigManager("config.json");
// Add the default config values
config.addConfig(new IntegerConfig("screenWidth", 1920));
config.addConfig(new IntegerConfig("screenHeight", 1080));
config.addConfig(new BooleanConfig("maximized", true));
// Write the configs to "config.json" (locally)
config.write();
Reading your configs essentially updates the values from the JSON.
The ConfigManager will only grab values and data based off of the keys defined via adding. Think of the ConfigManager kind of like a template, and an instance of that template in one. The template part is used for reading, and the instance is used for writing and management
Here is an example of reading
// Define the ConfigManager
DefaultConfigManager config = new DefaultConfigManager("config.json");
// Add the default values
config.addConfig(new IntegerConfig("screenWidth", 3840));
config.addConfig(new IntegerConfig("screenHeight", 2160));
config.addConfig(new BooleanConfig("maximized", false));
// Read the configs from "config.json" (locally)
config.read("config.json");
If we ran this code after running the previous snippet, our ConfigManager would stilll have the same values as before, even though we defined different default values.
Here is a snippet of the code required to get a config from a ConfigManager
// Define the ConfigManager
DefaultConfigManager config = new DefaultConfigManager("config.json");
// Add the default values
config.addConfig(new IntegerConfig("screenWidth", 3840));
config.addConfig(new IntegerConfig("screenHeight", 2160));
config.addConfig(new BooleanConfig("maximized", false));
// Get the "screenWidth" config
IntegerConfig screenWidth = config.getConfig("screenWidth");
// to access the int, use "screenWidth.getValue()"
You cannot set Configs with just a Key and Value because there is no way to get Type parameters from a class that I know of right now (If you have an idea let me know!)
Here is a snippet for setting
// Define the ConfigManager
DefaultConfigManager config = new DefaultConfigManager("config.json");
// Add the default values
config.addConfig(new IntegerConfig("screenWidth", 3840));
config.addConfig(new IntegerConfig("screenHeight", 2160));
config.addConfig(new BooleanConfig("maximized", false));
// Set the "maximized" config to true
config.setConfig(new BooleanConfig("maximized", true));
That is all of the current features in Ridge! If you have an idea for another one let me know, and get working!