Add threading to Shell, start making code samples
This commit is contained in:
parent
48509cf537
commit
09ff148208
@ -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
|
||||
|
3
src/net/apocalypselabs/symat/codesamples/graph.js
Normal file
3
src/net/apocalypselabs/symat/codesamples/graph.js
Normal file
@ -0,0 +1,3 @@
|
||||
var formula = ask("Enter formula:");
|
||||
plot(formula);
|
||||
plotname("Cool graph!");
|
3
src/net/apocalypselabs/symat/codesamples/graph.py
Normal file
3
src/net/apocalypselabs/symat/codesamples/graph.py
Normal file
@ -0,0 +1,3 @@
|
||||
formula = _.ask("Enter formula:")
|
||||
_.plot(formula)
|
||||
_.plotname("Cool graph!")
|
4
src/net/apocalypselabs/symat/codesamples/helloworld.js
Normal file
4
src/net/apocalypselabs/symat/codesamples/helloworld.js
Normal file
@ -0,0 +1,4 @@
|
||||
var message = "Hello World!";
|
||||
var x = 5;
|
||||
print(message);
|
||||
notify(message+" X is "+x+".");
|
4
src/net/apocalypselabs/symat/codesamples/helloworld.py
Normal file
4
src/net/apocalypselabs/symat/codesamples/helloworld.py
Normal file
@ -0,0 +1,4 @@
|
||||
message = "Hello World!"
|
||||
x=5
|
||||
print message
|
||||
_.notify(message+" X is "+str(x)+".")
|
Loading…
x
Reference in New Issue
Block a user