mirror of
https://github.com/DanilaFe/abacus
synced 2024-12-22 07:20:09 -08:00
Add loading of files to the core, but not the UI.
This commit is contained in:
parent
095d374949
commit
9bdf188ca7
|
@ -23,9 +23,12 @@ import org.nwapw.abacus.EvaluationResult;
|
||||||
import org.nwapw.abacus.tree.nodes.TreeNode;
|
import org.nwapw.abacus.tree.nodes.TreeNode;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.Scanner;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -69,6 +72,7 @@ public class AbacusController implements PluginListener {
|
||||||
* Constant string that is displayed if the calculations are interrupted by an exception.
|
* Constant string that is displayed if the calculations are interrupted by an exception.
|
||||||
*/
|
*/
|
||||||
private static final String ERR_EXCEPTION = "Exception Thrown";
|
private static final String ERR_EXCEPTION = "Exception Thrown";
|
||||||
|
private static final String ERR_DEFINITION = "Definition Error";
|
||||||
@FXML
|
@FXML
|
||||||
private TabPane coreTabPane;
|
private TabPane coreTabPane;
|
||||||
@FXML
|
@FXML
|
||||||
|
@ -304,6 +308,30 @@ public class AbacusController implements PluginListener {
|
||||||
reloadAlertShown = false;
|
reloadAlertShown = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void loadDefinitionFile(String fileName){
|
||||||
|
File definitionFile = new File(fileName);
|
||||||
|
if(!definitionFile.exists()) return;
|
||||||
|
try {
|
||||||
|
FileReader fileReader = new FileReader(definitionFile);
|
||||||
|
Scanner scanner = new Scanner(fileReader);
|
||||||
|
while(scanner.hasNext()){
|
||||||
|
abacus.evaluateTree(abacus.parseString(scanner.nextLine()));
|
||||||
|
}
|
||||||
|
} catch (AbacusException abacusError) {
|
||||||
|
outputText.setText(ERR_DEFINITION + "(" + abacusError.getMessage() + ")");
|
||||||
|
} catch (RuntimeException runtime) {
|
||||||
|
outputText.setText(ERR_DEFINITION + "(" + ERR_EXCEPTION + ")");
|
||||||
|
} catch (FileNotFoundException ignored) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void reloadAbacus(){
|
||||||
|
abacus.reload();
|
||||||
|
ExtendedConfiguration abacusConfig = (ExtendedConfiguration) abacus.getConfiguration();
|
||||||
|
for(String fileName: abacusConfig.getDefinitionFiles()) {
|
||||||
|
loadDefinitionFile(fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public void performScan() {
|
public void performScan() {
|
||||||
PluginManager abacusPluginManager = abacus.getPluginManager();
|
PluginManager abacusPluginManager = abacus.getPluginManager();
|
||||||
|
@ -314,13 +342,13 @@ public class AbacusController implements PluginListener {
|
||||||
} catch (IOException | ClassNotFoundException e) {
|
} catch (IOException | ClassNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
abacus.reload();
|
reloadAbacus();
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public void performReload() {
|
public void performReload() {
|
||||||
alertIfApplyNeeded(true);
|
alertIfApplyNeeded(true);
|
||||||
abacus.reload();
|
reloadAbacus();
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
|
|
|
@ -17,6 +17,7 @@ import java.io.File
|
||||||
* @param disabledPlugins the list of plugins that should be disabled, same as [Configuration.disabledPlugins]
|
* @param disabledPlugins the list of plugins that should be disabled, same as [Configuration.disabledPlugins]
|
||||||
*/
|
*/
|
||||||
class ExtendedConfiguration(var computationDelay: Double = 0.0,
|
class ExtendedConfiguration(var computationDelay: Double = 0.0,
|
||||||
|
definitionFiles: Array<String> = emptyArray(),
|
||||||
implementation: String = "<default>",
|
implementation: String = "<default>",
|
||||||
disabledPlugins: Array<String> = emptyArray())
|
disabledPlugins: Array<String> = emptyArray())
|
||||||
: Configuration(implementation, disabledPlugins) {
|
: Configuration(implementation, disabledPlugins) {
|
||||||
|
@ -27,6 +28,7 @@ class ExtendedConfiguration(var computationDelay: Double = 0.0,
|
||||||
*/
|
*/
|
||||||
val DEFAULT_TOML_STRING = """
|
val DEFAULT_TOML_STRING = """
|
||||||
computationDelay=0.0
|
computationDelay=0.0
|
||||||
|
definitionFiles=[]
|
||||||
implementation="naive"
|
implementation="naive"
|
||||||
disabledPlugins=[]
|
disabledPlugins=[]
|
||||||
"""
|
"""
|
||||||
|
@ -40,6 +42,11 @@ class ExtendedConfiguration(var computationDelay: Double = 0.0,
|
||||||
val DEFAULT_TOML_WRITER = TomlWriter()
|
val DEFAULT_TOML_WRITER = TomlWriter()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The set of files that definitions should be loaded from.
|
||||||
|
*/
|
||||||
|
val definitionFiles: MutableSet<String> = mutableSetOf(*definitionFiles)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new configuration from a file on disk.
|
* Constructs a new configuration from a file on disk.
|
||||||
* @param tomlFile the file from disk to load.
|
* @param tomlFile the file from disk to load.
|
||||||
|
@ -59,6 +66,8 @@ class ExtendedConfiguration(var computationDelay: Double = 0.0,
|
||||||
numberImplementation = config.numberImplementation
|
numberImplementation = config.numberImplementation
|
||||||
disabledPlugins.clear()
|
disabledPlugins.clear()
|
||||||
disabledPlugins.addAll(config.disabledPlugins)
|
disabledPlugins.addAll(config.disabledPlugins)
|
||||||
|
definitionFiles.clear()
|
||||||
|
definitionFiles.addAll(config.definitionFiles)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue
Block a user