Add save and load commands (PrefStorage)

This commit is contained in:
skylarmt 2015-04-10 23:05:20 -06:00
parent acc44f0765
commit 9e6d4e4230

View File

@ -63,6 +63,7 @@ import java.util.Iterator;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.prefs.Preferences;
import javax.swing.JOptionPane;
import static net.apocalypselabs.symat.Main.API_URL;
import org.matheclipse.core.eval.EvalUtilities;
@ -762,56 +763,20 @@ public class Functions {
return FileUtils.MD5(data);
}
// TODO: Make globals work!
// /*
// Global variables are accessible across scripts.
// */
// /**
// * Set a global variable.
// *
// * @param name The variable name
// * @param var The variable
// */
// public static void global(String name, Object var) {
// GLOBALS.put(name, var);
// }
//
// /**
// * Get a global variable.
// *
// * @param name The variable name
// * @return The variable
// */
// public static Object global(String name) {
// Object item = GLOBALS.get(name);
// return item;
// }
//
// // Fix for Python reserved word "global"
// public static void setglobal(String name, Object var) {
// global(name, var);
// }
//
// // Fix for Python reserved word "global"
// public static void getglobal(String name) {
// global(name);
// }
//
// /**
// * Clear all the GLOBALS.
// */
// public static void clrglobals() {
// GLOBALS.clear();
// }
//
// /**
// * Check if the given global key is set.
// * @param name The key to check.
// * @return True if the key exists, else false.
// */
// public static boolean globalcontains(String name) {
// return GLOBALS.containsKey(name);
// }
public void save(String key, String val) {
Preferences prefs = Preferences.userNodeForPackage(Functions.class);
prefs.put(key, val);
try {
prefs.flush();
} catch (Exception ex) {
}
}
public String load(String key) {
Preferences prefs = Preferences.userNodeForPackage(Functions.class);
return prefs.get(key, "");
}
/*
Other