Add threading to Shell, start making code samples

This commit is contained in:
skylarmt 2014-12-19 17:36:01 -07:00
parent 48509cf537
commit 09ff148208
5 changed files with 63 additions and 14 deletions

View File

@ -30,6 +30,7 @@ package net.apocalypselabs.symat;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.KeyEvent;
import javax.swing.SwingUtilities;
import javax.swing.text.DefaultCaret;
/**
@ -284,18 +285,52 @@ public class Interpreter extends javax.swing.JInternalFrame {
private void doRunCode() {
String code = inputBox.getText();
mainBox.append(" " + code + "\n");
try {
mainBox.append(cr.evalString(code).toString() + "\n");
} catch (NullPointerException ex) {
new EvalThread(code).start();
}
private class EvalThread extends Thread {
private String code = "";
public EvalThread(String cmd) {
code = cmd;
}
mainBox.append(">>");
for (int i = 9; i > 0; i--) {
history[i] = history[i - 1];
@Override
public void run() {
try {
append(cr.evalString(code).toString() + "\n");
} catch (NullPointerException ex) {
}
append(">>");
for (int i = 9; i > 0; i--) {
history[i] = history[i - 1];
}
history[0] = code;
clrInput();
historyIndex = -1;
}
private void clrInput() {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
inputBox.setText("");
}
});
}
private void append(String out) {
final String output = out;
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
mainBox.append(output);
}
});
}
history[0] = code;
inputBox.setText("");
historyIndex = -1;
}
// Variables declaration - do not modify//GEN-BEGIN:variables

View File

@ -0,0 +1,3 @@
var formula = ask("Enter formula:");
plot(formula);
plotname("Cool graph!");

View File

@ -0,0 +1,3 @@
formula = _.ask("Enter formula:")
_.plot(formula)
_.plotname("Cool graph!")

View File

@ -0,0 +1,4 @@
var message = "Hello World!";
var x = 5;
print(message);
notify(message+" X is "+x+".");

View File

@ -0,0 +1,4 @@
message = "Hello World!"
x=5
print message
_.notify(message+" X is "+str(x)+".")