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.Color;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
import javax.swing.text.DefaultCaret;
|
import javax.swing.text.DefaultCaret;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -284,20 +285,54 @@ public class Interpreter extends javax.swing.JInternalFrame {
|
|||||||
private void doRunCode() {
|
private void doRunCode() {
|
||||||
String code = inputBox.getText();
|
String code = inputBox.getText();
|
||||||
mainBox.append(" " + code + "\n");
|
mainBox.append(" " + code + "\n");
|
||||||
|
new EvalThread(code).start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private class EvalThread extends Thread {
|
||||||
|
|
||||||
|
private String code = "";
|
||||||
|
|
||||||
|
public EvalThread(String cmd) {
|
||||||
|
code = cmd;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
try {
|
try {
|
||||||
mainBox.append(cr.evalString(code).toString() + "\n");
|
|
||||||
|
append(cr.evalString(code).toString() + "\n");
|
||||||
} catch (NullPointerException ex) {
|
} catch (NullPointerException ex) {
|
||||||
|
|
||||||
}
|
}
|
||||||
mainBox.append(">>");
|
append(">>");
|
||||||
for (int i = 9; i > 0; i--) {
|
for (int i = 9; i > 0; i--) {
|
||||||
history[i] = history[i - 1];
|
history[i] = history[i - 1];
|
||||||
}
|
}
|
||||||
history[0] = code;
|
history[0] = code;
|
||||||
inputBox.setText("");
|
clrInput();
|
||||||
historyIndex = -1;
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||||
private javax.swing.JTextField inputBox;
|
private javax.swing.JTextField inputBox;
|
||||||
private javax.swing.JLabel jLabel1;
|
private javax.swing.JLabel jLabel1;
|
||||||
|
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