Removed Options, not enough time

workbranch
asdfasdf 6 years ago
parent 3629449c0f
commit bc7542de7a

@ -1,7 +1,5 @@
package ui;
import ui.Options;
public interface Iface {
//private Options ifaceOpts;

@ -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);
//}
}

@ -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();
}

@ -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
}
}
Loading…
Cancel
Save