Add Java support (beta)
This commit is contained in:
parent
db013410c5
commit
e22222a493
@ -74,7 +74,7 @@ public class CodeCompleter {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param language Either js or py.
|
* @param language Either js, py, or java.
|
||||||
*/
|
*/
|
||||||
public CodeCompleter(String language) {
|
public CodeCompleter(String language) {
|
||||||
lang = language;
|
lang = language;
|
||||||
|
@ -156,11 +156,11 @@ public class CodeRunner {
|
|||||||
se = new ScriptEngineManager().getEngineByName("java");
|
se = new ScriptEngineManager().getEngineByName("java");
|
||||||
try {
|
try {
|
||||||
// Add custom functions.
|
// Add custom functions.
|
||||||
/*se.eval("importClass(net.apocalypselabs.symat.Functions);"
|
se.eval("import net.apocalypselabs.symat.Functions;"
|
||||||
+ "SyMAT_Functions = new net.apocalypselabs.symat.Functions();"
|
+ "Functions SyMAT_Functions = new Functions();"
|
||||||
+ "SyMAT_Functions.setLang('js');\n"
|
+ "SyMAT_Functions.setLang(\"java\");\n"
|
||||||
+ getFunctions("js")
|
+ getFunctions("java")
|
||||||
+ loadToolkits());*/
|
+ loadToolkits());
|
||||||
// Allow engine access from scripts.
|
// Allow engine access from scripts.
|
||||||
se.put("engine", se);
|
se.put("engine", se);
|
||||||
attachWriters();
|
attachWriters();
|
||||||
@ -364,12 +364,12 @@ public class CodeRunner {
|
|||||||
|
|
||||||
private String getFunctions(String lang) {
|
private String getFunctions(String lang) {
|
||||||
String text = "";
|
String text = "";
|
||||||
if (!lang.equals("java")) {
|
//if (!lang.equals("java")) {
|
||||||
try {
|
try {
|
||||||
BufferedReader reader = new BufferedReader(
|
BufferedReader reader = new BufferedReader(
|
||||||
new InputStreamReader(
|
new InputStreamReader(
|
||||||
CodeRunner.class
|
CodeRunner.class
|
||||||
.getResourceAsStream("functions." + lang)));
|
.getResourceAsStream("functions." + (lang.equals("java") ? "java.txt" : lang))));
|
||||||
String line;
|
String line;
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
text += line + "\n";
|
text += line + "\n";
|
||||||
@ -377,7 +377,7 @@ public class CodeRunner {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
}
|
}
|
||||||
return text;
|
return text;
|
||||||
}
|
//}
|
||||||
return "";
|
//return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,8 +82,10 @@ public class Interpreter extends javax.swing.JInternalFrame {
|
|||||||
|
|
||||||
private CompletionProvider jscomp = new CodeCompleter("js").getProvider();
|
private CompletionProvider jscomp = new CodeCompleter("js").getProvider();
|
||||||
private CompletionProvider pycomp = new CodeCompleter("py").getProvider();
|
private CompletionProvider pycomp = new CodeCompleter("py").getProvider();
|
||||||
|
private CompletionProvider javacomp = new CodeCompleter("java").getProvider();
|
||||||
private AutoCompletion jsac = new AutoCompletion(jscomp);
|
private AutoCompletion jsac = new AutoCompletion(jscomp);
|
||||||
private AutoCompletion pyac = new AutoCompletion(pycomp);
|
private AutoCompletion pyac = new AutoCompletion(pycomp);
|
||||||
|
private AutoCompletion javaac = new AutoCompletion(javacomp);
|
||||||
|
|
||||||
private Interpreter thisobject;
|
private Interpreter thisobject;
|
||||||
|
|
||||||
@ -123,6 +125,7 @@ public class Interpreter extends javax.swing.JInternalFrame {
|
|||||||
javascriptMenu.setSelected(false);
|
javascriptMenu.setSelected(false);
|
||||||
pythonMenu.setSelected(false);
|
pythonMenu.setSelected(false);
|
||||||
javaMenu.setSelected(true);
|
javaMenu.setSelected(true);
|
||||||
|
javaac.install(inputBox);
|
||||||
} else {
|
} else {
|
||||||
jsac.install(inputBox);
|
jsac.install(inputBox);
|
||||||
setTitle("Shell [javascript]");
|
setTitle("Shell [javascript]");
|
||||||
@ -386,6 +389,8 @@ public class Interpreter extends javax.swing.JInternalFrame {
|
|||||||
String pref = "javascript";
|
String pref = "javascript";
|
||||||
if (pythonMenu.isSelected()) {
|
if (pythonMenu.isSelected()) {
|
||||||
pref = "python";
|
pref = "python";
|
||||||
|
} else if (javaMenu.isSelected()) {
|
||||||
|
pref = "java";
|
||||||
}
|
}
|
||||||
PrefStorage.saveSetting("shellLang", pref);
|
PrefStorage.saveSetting("shellLang", pref);
|
||||||
PrefStorage.save();
|
PrefStorage.save();
|
||||||
|
162
src/net/apocalypselabs/symat/functions.java.txt
Normal file
162
src/net/apocalypselabs/symat/functions.java.txt
Normal file
@ -0,0 +1,162 @@
|
|||||||
|
void notify(String msg) {
|
||||||
|
SyMAT_Functions.notify(msg);
|
||||||
|
}
|
||||||
|
Object ask(String msg) {
|
||||||
|
return SyMAT_Functions.ask(msg);
|
||||||
|
}
|
||||||
|
Object factorial(int n) {
|
||||||
|
return SyMAT_Functions.factorial(n);
|
||||||
|
}
|
||||||
|
Object diff(String fun,String var) {
|
||||||
|
return SyMAT_Functions.diff(fun,var);
|
||||||
|
}
|
||||||
|
Object integrate(String fun,String var) {
|
||||||
|
return SyMAT_Functions.integrate(fun,var);
|
||||||
|
}
|
||||||
|
Object rad(double num) {
|
||||||
|
return SyMAT_Functions.rad(num);
|
||||||
|
}
|
||||||
|
Object deg(double num) {
|
||||||
|
return SyMAT_Functions.deg(num);
|
||||||
|
}
|
||||||
|
Object subs(String fun,String var) {
|
||||||
|
return SyMAT_Functions.subs(fun,var);
|
||||||
|
}
|
||||||
|
void plot(String fun) {
|
||||||
|
SyMAT_Functions.plot(fun);
|
||||||
|
}
|
||||||
|
void plot() {
|
||||||
|
SyMAT_Functions.plot();
|
||||||
|
}
|
||||||
|
void plotname(String fun) {
|
||||||
|
SyMAT_Functions.plotname(fun);
|
||||||
|
}
|
||||||
|
Object plotname() {
|
||||||
|
return SyMAT_Functions.plotname();
|
||||||
|
}
|
||||||
|
void xlim(int min, int max) {
|
||||||
|
SyMAT_Functions.xlim(min,max);
|
||||||
|
}
|
||||||
|
void plotclr() {
|
||||||
|
SyMAT_Functions.plotclr();
|
||||||
|
}
|
||||||
|
void drawdot(int x, int y) {
|
||||||
|
SyMAT_Functions.drawdot(x, y);
|
||||||
|
}
|
||||||
|
Object simplify(String expr) {
|
||||||
|
return SyMAT_Functions.simplify(expr);
|
||||||
|
}
|
||||||
|
Object vpa(String expr) {
|
||||||
|
return SyMAT_Functions.vpa(expr);
|
||||||
|
}
|
||||||
|
Object readfile(String path) {
|
||||||
|
return SyMAT_Functions.readfile(path);
|
||||||
|
}
|
||||||
|
void savefile(String data,String path) {
|
||||||
|
SyMAT_Functions.savefile(data,path);
|
||||||
|
}
|
||||||
|
Object mtimes(double[][] a, double[][] b) {
|
||||||
|
return SyMAT_Functions.mtimes(a,b);
|
||||||
|
}
|
||||||
|
Object mpower(double[][] a, int b) {
|
||||||
|
return SyMAT_Functions.mpower(a,b);
|
||||||
|
}
|
||||||
|
Object add(double a...) {
|
||||||
|
return SyMAT_Functions.add(a);
|
||||||
|
}
|
||||||
|
Object subtract(double a...) {
|
||||||
|
return SyMAT_Functions.subtract(a);
|
||||||
|
}
|
||||||
|
Object times(double a...) {
|
||||||
|
return SyMAT_Functions.times(a);
|
||||||
|
}
|
||||||
|
Object divide(double a...) {
|
||||||
|
return SyMAT_Functions.divide(a);
|
||||||
|
}
|
||||||
|
Object mod(double a...) {
|
||||||
|
return SyMAT_Functions.mod(a);
|
||||||
|
}
|
||||||
|
Object rand(int min, int max) {
|
||||||
|
return SyMAT_Functions.rand(min,max);
|
||||||
|
}
|
||||||
|
Object rand(int min) {
|
||||||
|
return SyMAT_Functions.rand(min,1);
|
||||||
|
}
|
||||||
|
Object rand() {
|
||||||
|
return SyMAT_Functions.rand(0,1);
|
||||||
|
}
|
||||||
|
Object randb() {
|
||||||
|
return SyMAT_Functions.randb();
|
||||||
|
}
|
||||||
|
void sleep(int x) {
|
||||||
|
SyMAT_Functions.sleep(x);
|
||||||
|
}
|
||||||
|
void pause(int x) {
|
||||||
|
SyMAT_Functions.pause(x);
|
||||||
|
}
|
||||||
|
Object perms(double a...) {
|
||||||
|
return SyMAT_Functions.perms(a);
|
||||||
|
}
|
||||||
|
Object md5sum(String a) {
|
||||||
|
return SyMAT_Functions.md5sum(a);
|
||||||
|
}
|
||||||
|
Object save(String a, String b) {
|
||||||
|
return SyMAT_Functions.save(a,b);
|
||||||
|
}
|
||||||
|
Object load(String a) {
|
||||||
|
return SyMAT_Functions.load(a);
|
||||||
|
}
|
||||||
|
Object powermod(String a,String b,String m) {
|
||||||
|
return SyMAT_Functions.powermod(a,b,m);
|
||||||
|
}
|
||||||
|
Object powermod(double a,double b,double m) {
|
||||||
|
return SyMAT_Functions.powermod(a,b,m);
|
||||||
|
}
|
||||||
|
Object gcd(long a,long b) {
|
||||||
|
return SyMAT_Functions.gcd(a,b);
|
||||||
|
}
|
||||||
|
Object solve(String a, String b, int c) {
|
||||||
|
return SyMAT_Functions.solve(a,b,c);
|
||||||
|
}
|
||||||
|
Object solve(String a) {
|
||||||
|
return SyMAT_Functions.solve(a,"x",0);
|
||||||
|
}
|
||||||
|
Object printa(Object a) {
|
||||||
|
return SyMAT_Functions.printa(a);
|
||||||
|
}
|
||||||
|
Object sec(double a) {
|
||||||
|
return SyMAT_Functions.sec(a);
|
||||||
|
}
|
||||||
|
Object csc(double a) {
|
||||||
|
return SyMAT_Functions.csc(a);
|
||||||
|
}
|
||||||
|
Object cot(double a) {
|
||||||
|
return SyMAT_Functions.cot(a);
|
||||||
|
}
|
||||||
|
Object asec(double a) {
|
||||||
|
return SyMAT_Functions.asec(a);
|
||||||
|
}
|
||||||
|
Object acsc(double a) {
|
||||||
|
return SyMAT_Functions.acsc(a);
|
||||||
|
}
|
||||||
|
Object acot(double a) {
|
||||||
|
return SyMAT_Functions.acot(a);
|
||||||
|
}
|
||||||
|
Object sech(double a) {
|
||||||
|
return SyMAT_Functions.sech(a);
|
||||||
|
}
|
||||||
|
Object csch(double a) {
|
||||||
|
return SyMAT_Functions.csch(a);
|
||||||
|
}
|
||||||
|
Object coth(double a) {
|
||||||
|
return SyMAT_Functions.coth(a);
|
||||||
|
}
|
||||||
|
Object filedialog() {
|
||||||
|
return SyMAT_Functions.filedialog();
|
||||||
|
}
|
||||||
|
Object textbox() {
|
||||||
|
return SyMAT_Functions.textbox();
|
||||||
|
}
|
||||||
|
Object browser() {
|
||||||
|
return SyMAT_Functions.browser();
|
||||||
|
}
|
8
src/net/apocalypselabs/symat/resources/javaconstants.txt
Normal file
8
src/net/apocalypselabs/symat/resources/javaconstants.txt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
E
|
||||||
|
PI
|
||||||
|
LN2
|
||||||
|
LN10
|
||||||
|
LOG2E
|
||||||
|
LOG10E
|
||||||
|
SQRT1_2
|
||||||
|
SQRT2
|
Loading…
x
Reference in New Issue
Block a user