mirror of
https://github.com/DanilaFe/abacus
synced 2025-12-28 03:31:08 +00:00
Merge branch 'master' into context
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
apply plugin: 'application'
|
||||
|
||||
dependencies {
|
||||
compile 'com.moandjiezana.toml:toml4j:0.7.1'
|
||||
compile project(':core')
|
||||
}
|
||||
|
||||
|
||||
@@ -200,7 +200,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();
|
||||
@@ -260,12 +260,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);
|
||||
@@ -342,8 +342,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,70 @@
|
||||
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
|
||||
|
||||
/**
|
||||
* Additional settings for user interface.
|
||||
*
|
||||
* ExtendedConfiguration is used to add other settings
|
||||
* that aren't built into Abacus core, but are necessary
|
||||
* for the fx module.
|
||||
*
|
||||
* @property computationDelay the delay before which the computation stops.
|
||||
* @param implementation the number implementation, same as [Configuration.numberImplementation]
|
||||
* @param disabledPlugins the list of plugins that should be disabled, same as [Configuration.disabledPlugins]
|
||||
*/
|
||||
class ExtendedConfiguration(var computationDelay: Double = 0.0,
|
||||
implementation: String = "<default>",
|
||||
disabledPlugins: Array<String> = emptyArray())
|
||||
: Configuration(implementation, disabledPlugins) {
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* The default TOML.
|
||||
*/
|
||||
val DEFAULT_TOML_STRING = """
|
||||
computationDelay=0.0
|
||||
implementation="naive"
|
||||
disabledPlugins=[]
|
||||
"""
|
||||
/**
|
||||
* A reader with the default TOML data.
|
||||
*/
|
||||
val DEFAULT_TOML_READER = Toml().read(DEFAULT_TOML_STRING)
|
||||
/**
|
||||
* A writer used to writing the configuration to disk.
|
||||
*/
|
||||
val DEFAULT_TOML_WRITER = TomlWriter()
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new configuration from a file on disk.
|
||||
* @param tomlFile the file from disk to load.
|
||||
*/
|
||||
constructor(tomlFile: File) : this() {
|
||||
copyFrom(Toml(DEFAULT_TOML_READER).read(tomlFile).to(ExtendedConfiguration::class.java))
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies data from another configuration into this one.
|
||||
* @param config the configuration to copy from.
|
||||
*/
|
||||
fun copyFrom(config: ExtendedConfiguration) {
|
||||
computationDelay = config.computationDelay
|
||||
numberImplementation = config.numberImplementation
|
||||
disabledPlugins.clear()
|
||||
disabledPlugins.addAll(config.disabledPlugins)
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves this configuration to a file.
|
||||
* @param file the file to save to.
|
||||
*/
|
||||
fun saveTo(file: File) {
|
||||
DEFAULT_TOML_WRITER.write(this, file)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user