X collapse pdeengine/pderunner/kjcengine

X   remove 'extends' from kjcengine, make an instance of Main
X     may need to subclass at.dms.kjc.Main to override the exit()
X   make pdeengine a class
X   remove pderunner, collapse into pdeengine
This commit is contained in:
benfry
2002-07-27 23:28:59 +00:00
parent 3cad1bf929
commit 98f35ea78d
6 changed files with 116 additions and 227 deletions
+21 -12
View File
@@ -16,7 +16,7 @@ import com.oroinc.text.regex.*;
// doesn't really need to extend kjc.Main anymore,
// since reportTrouble doesn't actually do any good
public class KjcEngine implements PdeEngine {
public class KjcEngine extends PdeEngine {
static String TEMP_CLASS = "Temporary";
static final String EXTENDS = "extends BApplet ";
static final String EXTENDS_KJC = "extends KjcApplet ";
@@ -39,7 +39,7 @@ public class KjcEngine implements PdeEngine {
KjcMessageStream messageStream;
String program;
PdeEditor editor;
//PdeEditor editor;
String buildPath;
boolean running;
@@ -52,12 +52,15 @@ public class KjcEngine implements PdeEngine {
boolean usingExternal;
public KjcEngine(String program, String buildPath,
String dataPath, PdeEditor editor) {
public KjcEngine(PdeEditor editor,
String program, String buildPath,
String dataPath) {
super(editor);
this.program = program;
this.buildPath = buildPath;
//this.buildPath = "lib" + File.separator + "build";
this.editor = editor;
//this.editor = editor;
// only run cleanup if using the applications temp dir
//if (buildPath.endsWith("build")) cleanup();
@@ -561,7 +564,7 @@ public class KjcEngine implements PdeEngine {
}
public void start() throws PdeException {
public void start() throws PdeException { // part of PdeEngine
int numero1 = (int) (Math.random() * 10000);
int numero2 = (int) (Math.random() * 10000);
tempClass = TEMP_CLASS + "_" + numero1 + "_" + numero2;
@@ -820,7 +823,12 @@ public class KjcEngine implements PdeEngine {
}
public void cleanup() {
public void front() { // part of PdeEngine
window.toFront();
}
protected void cleanup() {
File buildDir = new File(buildPath);
if (!buildDir.exists()) buildDir.mkdirs();
@@ -854,7 +862,8 @@ public class KjcEngine implements PdeEngine {
}
public void stop() {
public void stop() { // part of PdeEngine
//System.out.println("PdeEngine.stop");
running = false;
//System.out.println();
@@ -901,7 +910,7 @@ public class KjcEngine implements PdeEngine {
}
public void close() {
public void close() { // part of PdeEngine
//if (window != null) window.hide();
if (window != null) {
//System.err.println("disposing window");
@@ -911,9 +920,9 @@ public class KjcEngine implements PdeEngine {
}
public void inform(String message) {
System.out.println("informing: " + message);
}
//public void inform(String message) {
//System.out.println("informing: " + message);
//}
}
+2
View File
@@ -400,11 +400,13 @@ public class PdeBase implements ActionListener {
// does this do anything useful?
/*
public void destroy() {
if (editor != null) {
editor.terminate();
}
}
*/
/*
public void paint(Graphics g) {
+68 -16
View File
@@ -42,7 +42,8 @@ public class PdeEditor extends Panel {
//String lastDirectory;
//String lastFile;
PdeRunner runner;
//PdeRunner runner;
KjcEngine engine;
Frame frame;
Window presentationWindow;
@@ -112,7 +113,7 @@ public class PdeEditor extends Panel {
//textarea.addKeyListener(new PdeKeyListener(this));
//}
runner = new PdeRunner(this);
//runner = new PdeRunner(this);
}
@@ -180,11 +181,43 @@ public class PdeEditor extends Panel {
running = true;
buttons.run();
runner.setProgram(textarea.getText());
runner.start();
//runner.setProgram(textarea.getText());
//runner.start();
try {
String program = textarea.getText();
if (program.length() != 0) {
String buildPath = "lib" + File.separator + "build"; // TEMPORARY
File buildDir = new File(buildPath);
if (!buildDir.exists()) buildDir.mkdirs();
String dataPath =
sketchFile.getParent() + File.separator + "data";
//editor.sketchFile.getParent() + File.separator + "data";
engine = new KjcEngine(this, program, buildPath, dataPath);
engine.start();
//System.out.println("done iwth engine.start()");
}
} catch (PdeException e) {
//state = RUNNER_ERROR;
//forceStop = false;
//this.stop();
engine.stop();
e.printStackTrace();
//editor.error(e);
error(e);
} catch (Exception e) {
e.printStackTrace();
//this.stop();
engine.stop();
}
//engine = null;
//System.out.println("out of doRun()");
// required so that key events go to the panel and <key> works
//graphics.requestFocus(); // removed for pde
//graphics.requestFocus(); // removed for pde
}
@@ -261,7 +294,8 @@ public class PdeEditor extends Panel {
//presentationWindow.toBack();
if (frame != null) frame.toFront();
try {
((KjcEngine)(runner.engine)).window.toFront();
//((KjcEngine)(runner.engine)).window.toFront();
engine.front();
} catch (Exception ex) { }
}
}
@@ -283,7 +317,9 @@ public class PdeEditor extends Panel {
*/
try {
((KjcEngine)(runner.engine)).window.toFront();
//((KjcEngine)(runner.engine)).window.toFront();
engine.front();
} catch (Exception e) {
// rather than writing code to check all the posible
// errors with the above statement, just fail quietly
@@ -320,7 +356,14 @@ public class PdeEditor extends Panel {
//#ifdef RECORDER
// if (!running) return;
//#endif
terminate();
//terminate();
// following 3 replace terminate
//runner.stop();
//System.out.println("doStop, engine is " + engine);
if (engine != null) engine.stop();
message(EMPTY);
buttons.clear();
running = false;
@@ -343,11 +386,17 @@ public class PdeEditor extends Panel {
// some code to close the window here
try {
// runner.engine is null (runner is not)
((KjcEngine)(runner.engine)).close();
//((KjcEngine)(runner.engine)).close();
engine.close();
// runner shouldn't be set to null because it gets reused
//System.err.println("runner = " + runner);
//runner = null;
// engine not reused
engine = null; // will this help?
} catch (Exception e) { }
buttons.clear();
}
@@ -804,16 +853,16 @@ public class PdeEditor extends Panel {
// create the project directory
// pass null for datapath because the files shouldn't be
// copied to the build dir.. that's only for the temp stuff
KjcEngine engine = new KjcEngine(program, appletDir.getPath(),
null, this);
KjcEngine ex_engine = new KjcEngine(this, program,
appletDir.getPath(), null);
//dataDir.getPath(), this);
//File projectDir = new File(appletDir, projectName);
//projectDir.mkdirs();
appletDir.mkdirs();
// projectName will be updated with actual class name
exportSketchName = engine.writeJava(exportSketchName, false);
if (!engine.compileJava()) {
exportSketchName = ex_engine.writeJava(exportSketchName, false);
if (!ex_engine.compileJava()) {
//throw new Exception("error while compiling, couldn't export");
// message() will already have error message in this case
return;
@@ -827,7 +876,7 @@ public class PdeEditor extends Panel {
//copyFile(new File(javaName), new File(appletDir, javaName));
// remove temporary .java and .class files
//engine.cleanup();
//ex_engine.cleanup();
int wide = BApplet.DEFAULT_WIDTH;
int high = BApplet.DEFAULT_HEIGHT;
@@ -933,7 +982,7 @@ public class PdeEditor extends Panel {
zos.close();
//zipOutputFile.close();
//engine.cleanup(); // no! buildPath is applet!
//ex_engine.cleanup(); // no! buildPath is applet!
message("Done exporting.");
@@ -1125,10 +1174,13 @@ public class PdeEditor extends Panel {
}
/*
public void terminate() { // part of PdeEnvironment
runner.stop();
//runner.stop();
if (engine != null) engine.stop();
message(EMPTY);
}
*/
// TODO iron out bugs with this code under
+20 -4
View File
@@ -1,5 +1,21 @@
public interface PdeEngine {
public void start() throws PdeException;
public void stop();
public void close();
public class PdeEngine {
PdeEditor editor;
public PdeEngine(PdeEditor editor) {
this.editor = editor;
}
// implemented by subclasses
public void start() throws PdeException {
}
public void front() {
}
public void stop() {
}
public void close() {
}
}
-189
View File
@@ -1,189 +0,0 @@
import java.io.*;
//import java.util.*;
public class PdeRunner /*implements Runnable*/ {
//DbnGraphics graphics;
//PdeEnvironment env;
PdeEditor editor;
String program;
PdeEngine engine;
// dbn definitely needs an engine,
// for the others it's just an interface
static final int RUNNER_STARTED = 0;
static final int RUNNER_FINISHED = 1;
static final int RUNNER_ERROR = -1;
static final int RUNNER_STOPPED = 2;
int state = RUNNER_FINISHED;
Thread thread;
boolean forceStop;
public PdeRunner(PdeEditor editor) {
this(editor, "");
}
public PdeRunner(PdeEditor editor, String program) {
this.program = program;
this.editor = editor;
}
public void setProgram(String program) {
this.program = program;
}
public void start() {
run();
/*
if (thread != null) {
try {
thread.stop();
} catch (Exception e) { }
thread = null;
}
thread = new Thread(this, "PdeRunner");
thread.start();
*/
}
public void run() {
state = RUNNER_STARTED;
//graphics.reset(); // remove for pde
//System.out.println("running");
try {
if (program.length() == 0) {
// hotspot vm or jikes 1.16 requires something
// to be here.. bad code getting compiled somewhere
System.out.println("no program");
/*
} else if (program.indexOf('#') < 2) { //charAt(0) == '#') {
#ifdef PYTHON
#ifdef OPENGL
program = "#\r\n" +
"import DbnEditorGraphics3D\r\n" +
"import ExperimentalCanvas\r\n" +
"g = DbnEditorGraphics3D.getCurrentGraphics()\r\n" +
"glc = g.canvas\r\n" +
"gl = glc.getGL()\r\n" +
"glj = glc.getGLJ()\r\n" + program;
#endif
forceStop = true;
engine = new PythonEngine(program);
engine.start();
forceStop = false;
#else
throw new Exception("python support not included");
#endif
*/
// } else if (program.indexOf("extends ProcessingApplet") != -1) {
//#ifdef JAVAC
// engine = new JavacEngine(program, graphics);
// engine.start();
//#else
// throw new Exception("javac support not included");
//#endif
} else {
/*
forceStop = true;
engine = new PythonEngine(program);
engine.start();
forceStop = false;
*/
//System.out.println("over here");
//engine = new KjcEngine(program, "lib", editor);
//this.buildPath = "lib" + File.separator + "build"; // TEMPORARY
//String buildPath =
//editor.sketchFile.getParent() + File.separator + "build";
String buildPath = "lib" + File.separator + "build"; // TEMPORARY
File buildDir = new File(buildPath);
if (!buildDir.exists()) buildDir.mkdirs();
String dataPath =
editor.sketchFile.getParent() + File.separator + "data";
/*
Properties props = System.getProperties();
String cp = props.getProperty("java.class.path");
System.out.println("in: " + cp);
props.put("java.class.path",
cp + File.pathSeparator + buildPath);
String cp2 = props.getProperty("java.class.path");
System.out.println("out: " + cp2);
System.setProperties(props);
*/
//System.out.println("over here2");
engine = new KjcEngine(program, buildPath, dataPath, editor);
//System.out.println("over here3");
engine.start();
/*
while (!((KjcEngine)engine).applet.finished) {
System.out.println("waiting");
try {
Thread.sleep(500);
} catch (InterruptedException e) { }
}
*/
}
// maybe this code shouldn't be called automatically,
// and instead ProcessingApplet and the others
// must call it explicitly
//System.out.println("finished");
/*
state = RUNNER_FINISHED;
System.out.println("finishing");
env.finished();
*/
//graphics.update(); // removed for pde
} catch (PdeException e) {
state = RUNNER_ERROR;
forceStop = false;
this.stop();
e.printStackTrace();
editor.error(e);
} catch (Exception e) {
e.printStackTrace();
this.stop();
}
}
public void finished() { // called by KjcProcessingApplet or something
state = RUNNER_FINISHED;
editor.finished();
}
public void stop() {
if (engine != null) {
engine.stop();
((KjcEngine)engine).cleanup();
/*
if (forceStop) {
thread.stop();
thread = null;
}
*/
// is this necessary [fry]
//engine = null;
}
}
}
+5 -6
View File
@@ -23,12 +23,11 @@ o background() not working
X checked but couldn't duplicate
X change editorlistener properties to use underscores
X imageMode() was gone.. now replaced
_ collapse pdeengine/pderunner/kjcengine
_ remove 'extends' from kjcengine, make an instance of Main
_ may need to subclass at.dms.kjc.Main to override the exit()
_ make pdeengine a class
_ remove pderunner, collapse into pdeengine
X collapse pdeengine/pderunner/kjcengine
X remove 'extends' from kjcengine, make an instance of Main
X may need to subclass at.dms.kjc.Main to override the exit()
X make pdeengine a class
X remove pderunner, collapse into pdeengine
_ save window position (only during session) of sketch run window
_ present mode should hide editor frame