From bc7542de7a26d1b022b12e8cdd7a484c07b1928b Mon Sep 17 00:00:00 2001 From: asdfasdf Date: Thu, 21 Nov 2019 22:05:00 -0800 Subject: [PATCH] Removed Options, not enough time --- src/main/ui/Iface.java | 2 - src/main/ui/IfaceFactory.java | 6 -- src/main/ui/Main.java | 12 --- src/main/ui/Options.java | 150 ---------------------------------- 4 files changed, 170 deletions(-) delete mode 100644 src/main/ui/Options.java diff --git a/src/main/ui/Iface.java b/src/main/ui/Iface.java index ef9a902..fec6f52 100644 --- a/src/main/ui/Iface.java +++ b/src/main/ui/Iface.java @@ -1,7 +1,5 @@ package ui; -import ui.Options; - public interface Iface { //private Options ifaceOpts; diff --git a/src/main/ui/IfaceFactory.java b/src/main/ui/IfaceFactory.java index f5e8933..3683da5 100644 --- a/src/main/ui/IfaceFactory.java +++ b/src/main/ui/IfaceFactory.java @@ -1,6 +1,5 @@ package ui; -import ui.Options; import ui.Tui; public class IfaceFactory { @@ -9,9 +8,4 @@ public class IfaceFactory { //uses Tui for now return new Tui(); } - //public static Iface getIface(Options iOpts) { - // //XXX iOpts not ready - // //uses Tui for now - // return new Tui(iOpts); - //} } diff --git a/src/main/ui/Main.java b/src/main/ui/Main.java index deab031..7acd224 100644 --- a/src/main/ui/Main.java +++ b/src/main/ui/Main.java @@ -1,7 +1,6 @@ package ui; import data.Const; -import ui.Options; import data.StypeMap; import data.StockType; import data.WatchList; @@ -10,26 +9,15 @@ import data.exceptions.*; public class Main { private Iface iface; - private Options allOptions; //Constructor, not the java main public Main(String[] args) { - //init options, it will load defaults - //from resource xml - allOptions = new Options(); - //parse args, uses - allOptions.parseArgs(args); WatchList mainList = new WatchList(); - //initalize UI thread, options not ready - //this.Iface = IfaceFactory.getIface(allOptions.getSection("ui")); iface = IfaceFactory.getIface(); } //Constructor for testing public Main(boolean debug) { - //init options, it will load defaults - //from resource xml - allOptions = new Options(); WatchList mainList = new WatchList(); } diff --git a/src/main/ui/Options.java b/src/main/ui/Options.java deleted file mode 100644 index 8ca6d59..0000000 --- a/src/main/ui/Options.java +++ /dev/null @@ -1,150 +0,0 @@ -package ui; - -import java.util.prefs.Preferences; -import java.util.prefs.BackingStoreException; -import java.util.prefs.InvalidPreferencesFormatException; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.FileNotFoundException; -import java.io.InputStream; -import data.Const; - -public class Options { - private Preferences store; - private boolean wasEmpty; - private boolean noSave; - private static final String DEF_OPTS_PATH = ""; - private static final String DEF_BACKUP = ".jwatch-backup.xml"; - private static final String RES_DEF = "defPref.xml"; - - public Options() { - store = Preferences.userRoot(); - try { - wasEmpty = store.nodeExists(Const.PROGRAM_NAME); - store = store.node(Const.PROGRAM_NAME); - if (wasEmpty) { - //load default opts from resource - //XXX - //importDefPreferences(); - } - } catch (BackingStoreException e) { - System.out.println("Critical Error: preference backing cannot be initialized"); - throw new RuntimeException(); - } - } - - public Options(String pathname) { - store = Preferences.userRoot().node(pathname); - } - - public Options getSection(String section) { - //String path = Const.PROGRAM_NAME + "/" + section; - //Options result = new Options(path); - //return result; - return null; - } - - public void importPreferences(String xmlpath) { - try { - File tarFile = new File(xmlpath); - FileInputStream tarStream = new FileInputStream(tarFile); - store.importPreferences(tarStream); - tarStream.close(); - } catch (FileNotFoundException e) { - System.out.println("File not found: " + xmlpath); - } catch (IOException e) { - System.out.println("IO Error when reading: " + xmlpath); - e.printStackTrace(); - } catch (InvalidPreferencesFormatException e) { - System.out.println("Import format error, possible file corruption"); - } - } - - public void importDefPreferences() { - try { - InputStream istream = getClass().getResourceAsStream(RES_DEF); - store.importPreferences(istream); - istream.close(); - } catch (IOException e) { - System.out.println("IO Error while reading def pref: " - + RES_DEF); - } catch (InvalidPreferencesFormatException e) { - System.out.println("Def resPref format error, possible program corruption"); - } - } - - public void exportPreferences(String xmlpath) { - try { - File tarFile = new File(xmlpath); - if (tarFile.isFile()) { - tarFile.delete(); - } else { - tarFile.createNewFile(); - } - FileOutputStream tarStream = new FileOutputStream(tarFile); - store.exportSubtree(tarStream); - tarStream.flush(); - tarStream.close(); - System.out.println("Exported preference to: " + xmlpath); - } catch (IOException e) { - System.out.println("IO Error when writing: " + xmlpath); - } catch (BackingStoreException e) { - System.out.println("Error retriving pref from store"); - e.printStackTrace(); - } - } - - public void destroy() { - // Clear config if requested or config was empty - // and is not saving - if (wasEmpty && noSave) { - try { - this.store.clear(); - } catch (BackingStoreException e) { - System.out.println("Error clearing pref store"); - e.printStackTrace(); - } - } else if (noSave) { - restorePrevious(); - } - delBackup(); - } - - public void backupPref() { - exportPreferences(DEF_BACKUP); - System.out.println("User Pref Backup created"); - } - - public void delBackup() { - try { - File tarFile = new File(DEF_BACKUP); - tarFile.delete(); - } catch (Exception e) { - System.out.println("Error deleting backup user pref"); - e.printStackTrace(); - } - } - - public void restorePrevious() { - importPreferences(DEF_BACKUP); - } - - // Default all false bool pref to be safe - // Default should be imported by constructor regardless - public boolean getBool(String key) { - return this.store.getBoolean(key, false); - } - - // Default all empty string pref to be safe - // Default should be imported by constructor regardless - public String getString(String key) { - return this.store.get(key, ""); - } - - public void parseArgs(String[] args) { - //XXX - } - -}