mirror of
https://github.com/DanilaFe/abacus
synced 2025-12-28 03:31:08 +00:00
Move TOML code out of the configuration in core, and into fx.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
apply plugin: 'application'
|
||||
|
||||
dependencies {
|
||||
compile 'com.moandjiezana.toml:toml4j:0.7.1'
|
||||
compile project(':core')
|
||||
}
|
||||
|
||||
|
||||
@@ -197,7 +197,7 @@ public class AbacusController implements PluginListener {
|
||||
*/
|
||||
private final Runnable TIMER_RUNNABLE = () -> {
|
||||
try {
|
||||
Configuration abacusConfig = abacus.getConfiguration();
|
||||
ExtendedConfiguration abacusConfig = (ExtendedConfiguration) abacus.getConfiguration();
|
||||
if (abacusConfig.getComputationDelay() == 0) return;
|
||||
Thread.sleep((long) (abacusConfig.getComputationDelay() * 1000));
|
||||
performStop();
|
||||
@@ -257,12 +257,12 @@ public class AbacusController implements PluginListener {
|
||||
if (oldValue.equals(settingsTab)) alertIfApplyNeeded(true);
|
||||
});
|
||||
|
||||
abacus = new Abacus(new Configuration(CONFIG_FILE));
|
||||
abacus = new Abacus(new ExtendedConfiguration(CONFIG_FILE));
|
||||
PluginManager abacusPluginManager = abacus.getPluginManager();
|
||||
abacusPluginManager.addListener(this);
|
||||
performScan();
|
||||
|
||||
computationLimitField.setText(Double.toString(abacus.getConfiguration().getComputationDelay()));
|
||||
computationLimitField.setText(Double.toString(((ExtendedConfiguration) abacus.getConfiguration()).getComputationDelay()));
|
||||
computationLimitField.textProperty().addListener((observable, oldValue, newValue) -> {
|
||||
if (!newValue.matches("(\\d+(\\.\\d*)?)?")) {
|
||||
computationLimitField.setText(oldValue);
|
||||
@@ -339,8 +339,8 @@ public class AbacusController implements PluginListener {
|
||||
if (!pluginEntry.isEnabled()) disabledPlugins.add(pluginEntry.getClassName());
|
||||
}
|
||||
if (computationLimitField.getText().matches("\\d*(\\.\\d+)?") && computationLimitField.getText().length() != 0)
|
||||
configuration.setComputationDelay(Double.parseDouble(computationLimitField.getText()));
|
||||
configuration.saveTo(CONFIG_FILE);
|
||||
((ExtendedConfiguration) configuration).setComputationDelay(Double.parseDouble(computationLimitField.getText()));
|
||||
((ExtendedConfiguration) configuration).saveTo(CONFIG_FILE);
|
||||
changesMade = false;
|
||||
reloadAlertShown = false;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package org.nwapw.abacus.fx
|
||||
|
||||
import com.moandjiezana.toml.Toml
|
||||
import com.moandjiezana.toml.TomlWriter
|
||||
import org.nwapw.abacus.config.Configuration
|
||||
import java.io.File
|
||||
|
||||
class ExtendedConfiguration(var computationDelay: Double = 0.0,
|
||||
implementation: String = "<default>",
|
||||
disabledPlugins: Array<String> = emptyArray())
|
||||
: Configuration(implementation, disabledPlugins) {
|
||||
|
||||
companion object {
|
||||
val DEFAULT_TOML_STRING = """
|
||||
computationDelay=0.0
|
||||
implementation="naive"
|
||||
disabledPlugins=[]
|
||||
"""
|
||||
val DEFAULT_TOML_READER = Toml().read(DEFAULT_TOML_STRING)
|
||||
val DEFAULT_TOML_WRITER = TomlWriter()
|
||||
}
|
||||
|
||||
constructor(tomlFile: File) : this() {
|
||||
copyFrom(Toml(DEFAULT_TOML_READER).read(tomlFile).to(ExtendedConfiguration::class.java))
|
||||
}
|
||||
|
||||
fun copyFrom(config: ExtendedConfiguration) {
|
||||
computationDelay = config.computationDelay
|
||||
numberImplementation = config.numberImplementation
|
||||
disabledPlugins.clear()
|
||||
disabledPlugins.addAll(config.disabledPlugins)
|
||||
}
|
||||
|
||||
fun saveTo(file: File) {
|
||||
DEFAULT_TOML_WRITER.write(this, file)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user