[Mathlib-commitlog] SF.net SVN: mathlib:[808] JMathLib/trunk/src/jmathlib/core/interpreter/ GlobalV
Status: Beta
Brought to you by:
st_mueller
|
From: <st_...@us...> - 2009-01-31 14:42:19
|
Revision: 808
http://mathlib.svn.sourceforge.net/mathlib/?rev=808&view=rev
Author: st_mueller
Date: 2009-01-31 14:42:09 +0000 (Sat, 31 Jan 2009)
Log Message:
-----------
corrections of "property loading"
Modified Paths:
--------------
JMathLib/trunk/src/jmathlib/core/interpreter/GlobalValues.java
Modified: JMathLib/trunk/src/jmathlib/core/interpreter/GlobalValues.java
===================================================================
--- JMathLib/trunk/src/jmathlib/core/interpreter/GlobalValues.java 2009-01-31 14:41:39 UTC (rev 807)
+++ JMathLib/trunk/src/jmathlib/core/interpreter/GlobalValues.java 2009-01-31 14:42:09 UTC (rev 808)
@@ -10,6 +10,7 @@
package jmathlib.core.interpreter;
import java.io.*;
+import java.net.URL;
import java.util.Locale;
import java.util.Properties;
import java.applet.Applet;
@@ -36,6 +37,9 @@
/**Object to control function usage*/
private jmathlib.core.functions.FunctionManager functionManager;
+ /** global pointer to applet */
+ private Applet applet = null;
+
/**A pointer to the interpreter itself*/
private Interpreter interpreter;
@@ -46,7 +50,7 @@
private jmathlib.plugins.PluginsManager pluginsManager;
/**stores the number format for displaying the number*/
- public NumberFormat numFormat = new DecimalFormat("0.0000", new DecimalFormatSymbols(Locale.ENGLISH));
+ private NumberFormat numFormat = new DecimalFormat("0.0000", new DecimalFormatSymbols(Locale.ENGLISH));
/** global properties */
private static Properties props = new Properties();
@@ -55,11 +59,14 @@
* @param _interpreter = the Interpreter object
* @param _runningStandalone = true if this was run from an application
*/
- public GlobalValues(Interpreter _interpreter, boolean _runningStandalone, Applet applet)
+ public GlobalValues(Interpreter _interpreter, boolean _runningStandalone, Applet _applet)
{
// the list of contexts
contextList = new ContextList();
+ // pointer to applet
+ applet = _applet;
+
// the function manager for loading m-files class-files
functionManager = new jmathlib.core.functions.FunctionManager(_runningStandalone, applet);
@@ -101,25 +108,28 @@
return contextList.getVariable(name);
}
- /** create a variable in the local or global workspace
- * @param
- * @return
+ /**
+ * Create a variable in the local or global workspace
+ * @param creates a new variable
+ * @return returns the handle to that variable
*/
public Variable createVariable(String name)
{
return contextList.createVariable(name);
}
- /** create a variable in the local or global workspace
- * @param
- * @param
+ /**
+ * Create a variable in the local or global workspace
+ * @param name of the variable
+ * @param data of the variable
*/
public void setVariable(String name, OperandToken value)
{
contextList.setVariable(name, value);
}
- /**Change the current context to point to the new Variable List
+ /**
+ * Change the current context to point to the new Variable List
* @param _Variables = the new list of Variables to use
*/
public void createContext(VariableList _variables)
@@ -127,22 +137,25 @@
contextList.createContext(_variables);
}
- /**Return to the previous variable list
+ /**
+ * Return to the previous variable list
*/
public void popContext()
{
contextList.popContext();
}
- /**Allow access to the context list
- * @return
+ /**
+ * Allow access to the context list
+ * @return the context list
*/
public ContextList getContextList()
{
return contextList;
}
- /**returns the interpreter object
+ /**
+ * Returns the interpreter object
* @return pointer to Interpreter
*/
public Interpreter getInterpreter()
@@ -151,6 +164,7 @@
}
/**
+ * Returns a handle to the function manager
* @return the function manager
*/
public jmathlib.core.functions.FunctionManager getFunctionManager()
@@ -159,6 +173,7 @@
}
/**
+ * Returns a handle to the graphics manager
* @return handle to graphics manager
*/
public jmathlib.core.graphics.GraphicsManager getGraphicsManager()
@@ -167,6 +182,7 @@
}
/**
+ * Returns a handle to the plugin manager
* @return handle to plugins manager
*/
public jmathlib.plugins.PluginsManager getPluginsManager()
@@ -175,6 +191,7 @@
}
/**
+ * Returns the working directory
* @return actual working directory
*/
public File getWorkingDirectory()
@@ -183,6 +200,7 @@
}
/**
+ * Sets the working directory
* @param set working directory
*/
public void setWorkingDirectory(File _workingDir)
@@ -209,22 +227,42 @@
}
/**
- *
- *
+ * load JMathLib properties from a file or in applet version
+ * from the web server.
*/
public void loadPropertiesFromFile()
{
-
// load global properties from disc
try
{
- props.load(new FileInputStream(new File("JMathLib.properties")));
+ // check if JMathLib is running is applet or application
+ if (applet != null)
+ {
+ // running as applet
+ //System.out.println("properties applet " + getWorkingDirectory());
+ URL url = new URL(applet.getCodeBase(), "JMathLib.properties");
+ props.load( url.openStream() );
+ }
+ else
+ {
+ // running as application
+ File f = new File("JMathLib.properties");
+
+ // check if property file exist in "working directory" or
+ // if it is not available yet, then take the original one
+ // from the bin directory
+ if (!f.exists())
+ f = new File("bin/JMathLib.properties");
+
+ // load properties
+ //System.out.println("properties file "+f.getCanonicalPath().toString());
+ props.load(new FileInputStream(f));
+ }
}
catch (Exception e)
{
System.out.println("Properties global error");
}
- //System.out.println("Properties loaded");
// display properties
//Enumeration propnames = props.propertyNames();
@@ -233,32 +271,37 @@
// String propname = (String)globalPropnames.nextElement();
// System.out.println("Property: "+propname+" = "+globalProps.getProperty(propname));
//}
-
-
}
/**
- *
+ * store properties back to a file on disc. In applet version
+ * do not store, since there is no disc
*/
public void storePropertiesToFile()
{
+ // do not try to store properties is an applet
+ if (applet!=null)
+ return;
// store properties back to file
try
{
- props.store(new FileOutputStream(new File("JMathLib.properties")),
+ File f = new File("JMathLib.properties");
+ //System.out.println("properties file "+f.getCanonicalPath().toString());
+
+ props.store(new FileOutputStream(f.getCanonicalPath()),
"JMathLib property file" );
}
catch (Exception e)
{
- System.out.println("Property: Error");
+ System.out.println("GlobalVAues: properties store error");
}
}
/**
- *
+ * Returns one of JMathLib's properties
* @param property
- * @return
+ * @return string value of the requested property
*/
public String getProperty(String property)
{
@@ -266,9 +309,9 @@
}
/**
- *
- * @param property
- * @param value
+ * Sets a property of JMathLib
+ * @param name of property
+ * @param value of property
*/
public void setProperty(String property, String value)
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|