From 28b9e15fc8d2dd8c3b709c3e161807bf9853952b Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Fri, 28 Jul 2017 21:37:47 -0700 Subject: [PATCH] Add configuration object to Abacus. --- src/org/nwapw/abacus/Abacus.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/org/nwapw/abacus/Abacus.java b/src/org/nwapw/abacus/Abacus.java index 9b6a6ea..be3b378 100644 --- a/src/org/nwapw/abacus/Abacus.java +++ b/src/org/nwapw/abacus/Abacus.java @@ -1,5 +1,6 @@ package org.nwapw.abacus; +import org.nwapw.abacus.config.ConfigurationObject; import org.nwapw.abacus.function.Operator; import org.nwapw.abacus.number.NumberInterface; import org.nwapw.abacus.plugin.ClassFinder; @@ -12,6 +13,7 @@ import org.nwapw.abacus.tree.TreeNode; import org.nwapw.abacus.window.Window; import javax.swing.*; +import java.io.File; import java.io.IOException; /** @@ -21,6 +23,11 @@ import java.io.IOException; */ public class Abacus implements PluginListener { + /** + * The file used for saving and loading configuration. + */ + public static final File CONFIG_FILE = new File("config.yml"); + /** * The main Abacus UI. */ @@ -40,6 +47,10 @@ public class Abacus implements PluginListener { * The reducer used to evaluate the tree. */ private NumberReducer numberReducer; + /** + * The configuration loaded from a file. + */ + private ConfigurationObject configuration; /** * Creates a new instance of the Abacus calculator. @@ -48,6 +59,8 @@ public class Abacus implements PluginListener { pluginManager = new PluginManager(this); mainUi = new Window(this); numberReducer = new NumberReducer(this); + configuration = new ConfigurationObject(CONFIG_FILE); + configuration.save(CONFIG_FILE); pluginManager.addListener(this); pluginManager.addInstantiated(new StandardPlugin(pluginManager)); @@ -95,6 +108,14 @@ public class Abacus implements PluginListener { return numberReducer; } + /** + * Gets the configuration object associated with this instance. + * @return the configuration object. + */ + public ConfigurationObject getConfiguration() { + return configuration; + } + /** * Parses a string into a tree structure using the main * tree builder.