mirror of
https://github.com/processing/processing4.git
synced 2026-02-11 09:39:19 +01:00
PdeRuntime cleanup work
This commit is contained in:
@@ -1096,7 +1096,6 @@ public class PdeEditor extends JFrame
|
||||
|
||||
public void setSketchModified(boolean what) {
|
||||
header.sketchModified = what;
|
||||
//header.update();
|
||||
header.repaint();
|
||||
sketchModified = what;
|
||||
}
|
||||
@@ -1118,11 +1117,8 @@ public class PdeEditor extends JFrame
|
||||
String prompt = "Save changes to " + sketch.name + "? ";
|
||||
|
||||
if (checking == DO_QUIT) {
|
||||
|
||||
int result = 0;
|
||||
|
||||
//if (PdeBase.platform == PdeBase.MACOSX) {
|
||||
|
||||
// macosx java kills the app even though cancel might get hit
|
||||
// so the cancel button is (temporarily) left off
|
||||
// this may be treated differently in macosx java 1.4,
|
||||
@@ -1142,16 +1138,16 @@ public class PdeEditor extends JFrame
|
||||
options[0]); // default to save
|
||||
|
||||
/*
|
||||
} else {
|
||||
Object[] options = { "Yes", "No", "Cancel" };
|
||||
result = JOptionPane.showOptionDialog(this,
|
||||
prompt,
|
||||
"Quit",
|
||||
JOptionPane.YES_NO_CANCEL_OPTION,
|
||||
JOptionPane.QUESTION_MESSAGE,
|
||||
null,
|
||||
options,
|
||||
options[2]);
|
||||
} else {
|
||||
Object[] options = { "Yes", "No", "Cancel" };
|
||||
result = JOptionPane.showOptionDialog(this,
|
||||
prompt,
|
||||
"Quit",
|
||||
JOptionPane.YES_NO_CANCEL_OPTION,
|
||||
JOptionPane.QUESTION_MESSAGE,
|
||||
null,
|
||||
options,
|
||||
options[2]);
|
||||
*/
|
||||
|
||||
if (result == JOptionPane.YES_OPTION) {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
/*
|
||||
PdeRuntime - runs compiled java applet
|
||||
Part of the Processing project - http://Proce55ing.net
|
||||
Part of the Processing project - http://processing.org
|
||||
|
||||
Except where noted, code is written by Ben Fry and
|
||||
Copyright (c) 2001-03 Massachusetts Institute of Technology
|
||||
@@ -39,39 +39,31 @@ public class PdeRuntime implements PdeMessageConsumer {
|
||||
BApplet applet;
|
||||
PdeException exception;
|
||||
Window window;
|
||||
PdeEditor editor;
|
||||
PrintStream leechErr;
|
||||
String className;
|
||||
//String className;
|
||||
|
||||
PdeEditor editor;
|
||||
PdeSketch sketch;
|
||||
|
||||
boolean newMessage;
|
||||
int messageLineCount;
|
||||
|
||||
Process process;
|
||||
OutputStream processOutput;
|
||||
boolean externalRuntime;
|
||||
//String codeFolderPath;
|
||||
//String externalPaths;
|
||||
String libraryPath;
|
||||
String classPath;
|
||||
|
||||
//boolean externalRuntime;
|
||||
//String libraryPath;
|
||||
//String classPath;
|
||||
|
||||
|
||||
public PdeRuntime(PdeEditor editor, String className,
|
||||
boolean externalRuntime,
|
||||
String classPath, String libraryPath) {
|
||||
//String codeFolderPath, String externalPaths) {
|
||||
public PdeRuntime(PdeSketch sketch, PdeEditor editor) {
|
||||
this.sketch = sketch;
|
||||
this.editor = editor;
|
||||
this.className = className;
|
||||
|
||||
this.externalRuntime = externalRuntime;
|
||||
this.classPath = classPath;
|
||||
this.libraryPath = libraryPath;
|
||||
//this.codeFolderPath = codeFolderPath;
|
||||
//this.externalPaths = externalPaths;
|
||||
}
|
||||
|
||||
|
||||
public void start(Point windowLocation, PrintStream leechErr)
|
||||
throws PdeException {
|
||||
public void start(Point windowLocation,
|
||||
PrintStream leechErr) throws PdeException {
|
||||
|
||||
this.leechErr = new PrintStream(new PdeMessageStream(this));
|
||||
|
||||
@@ -82,23 +74,28 @@ public class PdeRuntime implements PdeMessageConsumer {
|
||||
int y1 = parentLoc.y;
|
||||
|
||||
try {
|
||||
if (externalRuntime) {
|
||||
if (sketch.externalRuntime) {
|
||||
// if there was a saved location (this guy has been run more than
|
||||
// once) then windowLocation will be set to the last position of
|
||||
// the sketch window. this will be passed to the BApplet runner
|
||||
// using something like --external=e30,20 where the e stands for
|
||||
// exact. otherwise --external=x,y for just the regular positioning.
|
||||
String location = (windowLocation != null) ?
|
||||
(BApplet.EXACT_LOCATION +
|
||||
windowLocation.x + "," + windowLocation.y) :
|
||||
(x1 + "," + y1);
|
||||
|
||||
String command[] = new String[] {
|
||||
"java",
|
||||
"-Djava.library.path=" + libraryPath, // might be ""
|
||||
"-Djava.library.path=" + sketch.libraryPath, // might be ""
|
||||
"-cp",
|
||||
classPath,
|
||||
sketch.classPath,
|
||||
"BApplet",
|
||||
BApplet.EXTERNAL_FLAG + ((windowLocation != null) ?
|
||||
("e" +
|
||||
windowLocation.x + "," +
|
||||
windowLocation.y) :
|
||||
(x1 + "," + y1)),
|
||||
className
|
||||
BApplet.EXTERNAL_FLAG + location,
|
||||
sketch.mainClassName
|
||||
};
|
||||
|
||||
process = Runtime.getRuntime().exec(command);
|
||||
//new PdeMessageSiphon(process.getInputStream(), this);
|
||||
new SystemOutSiphon(process.getInputStream());
|
||||
new PdeMessageSiphon(process.getErrorStream(), this);
|
||||
processOutput = process.getOutputStream();
|
||||
@@ -108,7 +105,6 @@ public class PdeRuntime implements PdeMessageConsumer {
|
||||
applet = (BApplet) c.newInstance();
|
||||
|
||||
// replaces setRuntime with BApplet having leechErr [fry]
|
||||
//applet.setRuntime(this);
|
||||
applet.leechErr = leechErr;
|
||||
|
||||
// has to be before init
|
||||
@@ -155,7 +151,7 @@ public class PdeRuntime implements PdeMessageConsumer {
|
||||
// toxi_030903: moved keyListener to PdeEditor's presentationWindow
|
||||
|
||||
} else {
|
||||
window = new Frame(editor.sketchName); // use ugly windows
|
||||
window = new Frame(sketch.name); // use ugly windows
|
||||
((Frame)window).setResizable(false);
|
||||
if (editor.icon != null) {
|
||||
((Frame)window).setIconImage(editor.icon);
|
||||
@@ -225,8 +221,10 @@ public class PdeRuntime implements PdeMessageConsumer {
|
||||
|
||||
int minW = PdePreferences.getInteger("run.window.width.minimum");
|
||||
int minH = PdePreferences.getInteger("run.window.height.minimum");
|
||||
int windowW = Math.max(applet.width, minW) + insets.left + insets.right;
|
||||
int windowH = Math.max(applet.height, minH) + insets.top + insets.bottom;
|
||||
int windowW =
|
||||
Math.max(applet.width, minW) + insets.left + insets.right;
|
||||
int windowH =
|
||||
Math.max(applet.height, minH) + insets.top + insets.bottom;
|
||||
|
||||
if (x1 - windowW > 10) { // if it fits to the left of the window
|
||||
window.setBounds(x1 - windowW, y1, windowW, windowH);
|
||||
@@ -246,15 +244,12 @@ public class PdeRuntime implements PdeMessageConsumer {
|
||||
window.setBounds(x1, y1, windowW, windowH); //ww, wh);
|
||||
}
|
||||
|
||||
Color windowBgColor =
|
||||
PdePreferences.getColor("run.window.bgcolor");
|
||||
//new Color(102, 102, 102));
|
||||
Color windowBgColor = PdePreferences.getColor("run.window.bgcolor");
|
||||
window.setBackground(windowBgColor);
|
||||
//window.setBackground(SystemColor.windowBorder);
|
||||
//window.setBackground(SystemColor.control);
|
||||
|
||||
applet.setBounds((windowW - applet.width)/2,
|
||||
insets.top + ((windowH - insets.top - insets.bottom) -
|
||||
insets.top + ((windowH -
|
||||
insets.top - insets.bottom) -
|
||||
applet.height)/2,
|
||||
windowW, windowH);
|
||||
}
|
||||
@@ -266,13 +261,6 @@ public class PdeRuntime implements PdeMessageConsumer {
|
||||
window.show();
|
||||
applet.requestFocus(); // necessary for key events
|
||||
}
|
||||
//System.out.println("KJC RUNNING");
|
||||
|
||||
//need to parse this code to give a decent error message
|
||||
//internal error
|
||||
//java.lang.NullPointerException
|
||||
// at ProcessingApplet.colorMode(ProcessingApplet.java:652)
|
||||
// at Temporary_203_1176.setup(Temporary_203_1176.java:3)
|
||||
|
||||
} catch (Exception e) {
|
||||
// this will pass through to the first part of message
|
||||
@@ -314,23 +302,7 @@ public class PdeRuntime implements PdeMessageConsumer {
|
||||
//e.printStackTrace();
|
||||
close();
|
||||
}
|
||||
|
||||
/*
|
||||
try {
|
||||
FileOutputStream fos = new FileOutputStream("die");
|
||||
fos.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
//System.gc();
|
||||
//System.out.println("* stopped");
|
||||
|
||||
//System.out.println("thread count: " + Thread.activeCount());
|
||||
//System.out.println();
|
||||
//System.out.println();
|
||||
}
|
||||
|
||||
|
||||
@@ -355,13 +327,15 @@ public class PdeRuntime implements PdeMessageConsumer {
|
||||
|
||||
|
||||
public void message(String s) {
|
||||
// this is BApplet sending a message (via System.out.println)
|
||||
// that signals that the applet has been quit.
|
||||
if (s.indexOf(BApplet.EXTERNAL_QUIT) == 0) {
|
||||
//close();
|
||||
//System.out.println("got proper quit message");
|
||||
editor.doClose();
|
||||
return;
|
||||
}
|
||||
|
||||
// this is the BApplet sending us a message that the applet
|
||||
// is being moved to a new window location
|
||||
if (s.indexOf(BApplet.EXTERNAL_MOVE) == 0) {
|
||||
String nums = s.substring(s.indexOf(' ') + 1);
|
||||
int space = nums.indexOf(' ');
|
||||
@@ -375,14 +349,16 @@ public class PdeRuntime implements PdeMessageConsumer {
|
||||
//System.err.println("message " + s.length() + ":" + s);
|
||||
if (s.length() > 2) System.err.println(s);
|
||||
|
||||
// this is BApplet sending a message saying "i'm about to spew
|
||||
// a stack trace because an error occurred during BApplet.run()"
|
||||
if (s.indexOf(BApplet.LEECH_WAKEUP) == 0) {
|
||||
//System.err.println("got wakeup");
|
||||
newMessage = true;
|
||||
return; // this line ignored
|
||||
}
|
||||
|
||||
// if s.length <=2, that probably means that it's just the platform
|
||||
// line-terminators. ignore it.
|
||||
// if s.length <=2, ignore it because that probably means
|
||||
// that it's just the platform line-terminators.
|
||||
if (newMessage && s.length() > 2) {
|
||||
exception = new PdeException(s); // type of java ex
|
||||
//System.out.println("setting ex type to " + s);
|
||||
@@ -392,20 +368,22 @@ public class PdeRuntime implements PdeMessageConsumer {
|
||||
} else {
|
||||
messageLineCount++;
|
||||
|
||||
// TODO this is insufficient. need to cycle through the
|
||||
// different classes that are currently loaded and see if
|
||||
// there is an error in one of them.
|
||||
String className = sketch.mainClassName;
|
||||
|
||||
int index = s.indexOf(className + ".java");
|
||||
//System.out.println("> " + index + " " + s);
|
||||
if (index != -1) {
|
||||
int len = (className + ".java").length();
|
||||
String lineNumberStr = s.substring(index + len + 1);
|
||||
index = lineNumberStr.indexOf(')');
|
||||
lineNumberStr = lineNumberStr.substring(0, index);
|
||||
//System.err.println("error line is: " + lineNumberStr);
|
||||
try {
|
||||
exception.line = Integer.parseInt(lineNumberStr) - 1; //2;
|
||||
//System.out.println("exception in RUNNING");
|
||||
editor.error(exception);
|
||||
} catch (NumberFormatException e) {
|
||||
e.printStackTrace();
|
||||
e.printStackTrace(); // a recursive error waiting to happen?
|
||||
}
|
||||
} else if ((index = s.indexOf(className + ".class")) != -1) {
|
||||
// code to check for:
|
||||
|
||||
@@ -54,7 +54,7 @@ public class PdeSketch {
|
||||
|
||||
// all these set each time build() is called
|
||||
boolean externalRuntime;
|
||||
//String mainClassName;
|
||||
String mainClassName;
|
||||
String classPath;
|
||||
String libraryPath;
|
||||
|
||||
@@ -323,7 +323,7 @@ public class PdeSketch {
|
||||
* X. afterwards, some of these steps need a cleanup function
|
||||
*/
|
||||
public void run() throws PdeException {
|
||||
current.program = textarea.getText();
|
||||
current.program = editor.getText();
|
||||
|
||||
// TODO record history here
|
||||
//current.history.record(program, PdeHistory.RUN);
|
||||
@@ -359,12 +359,13 @@ public class PdeSketch {
|
||||
"_" + String.valueOf((int) (Math.random() * 10000)));
|
||||
|
||||
// handle preprocessing the main file's code
|
||||
String mainClassName = build(TEMP_BUILD_PATH, suggestedClassName);
|
||||
mainClassName = build(TEMP_BUILD_PATH, suggestedClassName);
|
||||
// externalPaths is magically set by build()
|
||||
|
||||
// if the compilation worked, run the applet
|
||||
if (mainClassName != null) {
|
||||
|
||||
/*
|
||||
if (externalPaths == null) {
|
||||
externalPaths =
|
||||
PdeCompiler.calcClassPath(null) + File.pathSeparator +
|
||||
@@ -375,18 +376,19 @@ public class PdeSketch {
|
||||
PdeCompiler.calcClassPath(null) + File.pathSeparator +
|
||||
externalPaths;
|
||||
}
|
||||
*/
|
||||
|
||||
// get a useful folder name for the 'code' folder
|
||||
// so that it can be included in the java.library.path
|
||||
/*
|
||||
String libraryPath = "";
|
||||
if (externalCode != null) {
|
||||
libraryPath = externalCode.getCanonicalPath();
|
||||
}
|
||||
*/
|
||||
|
||||
// create a runtime object
|
||||
runtime = new PdeRuntime(this, className,
|
||||
externalRuntime,
|
||||
libraryPath, classPath);
|
||||
runtime = new PdeRuntime(this, editor);
|
||||
|
||||
// if programType is ADVANCED
|
||||
// or the code/ folder is not empty -> or just exists (simpler)
|
||||
@@ -409,32 +411,8 @@ public class PdeSketch {
|
||||
} else {
|
||||
// [dmose] throw an exception here?
|
||||
// [fry] iirc the exception will have already been thrown
|
||||
cleanTempFiles(); //tempBuildPath);
|
||||
cleanup();
|
||||
}
|
||||
|
||||
/*
|
||||
} catch (PdeException e) {
|
||||
// if it made it as far as creating a Runtime object,
|
||||
// call its stop method to unwind its thread
|
||||
if (runtime != null) runtime.stop();
|
||||
cleanTempFiles(); //tempBuildPath);
|
||||
|
||||
// printing the stack trace may be overkill since it happens
|
||||
// even on a simple parse error
|
||||
//e.printStackTrace();
|
||||
|
||||
error(e);
|
||||
|
||||
} catch (Exception e) { // something more general happened
|
||||
e.printStackTrace();
|
||||
|
||||
// if it made it as far as creating a Runtime object,
|
||||
// call its stop method to unwind its thread
|
||||
if (runtime != null) runtime.stop();
|
||||
|
||||
cleanTempFiles(); //tempBuildPath);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
@@ -515,7 +493,7 @@ public class PdeSketch {
|
||||
importPackageList = PdeCompiler.magicImports(classPath);
|
||||
libraryPath = codeFolder.getCanonicalPath();
|
||||
} else {
|
||||
externalRuntime = (codeCount > 1); // at least for now
|
||||
externalRuntime = (codeCount > 1); // may still be set true later
|
||||
importPackageList = null;
|
||||
libraryPath = "";
|
||||
}
|
||||
@@ -526,7 +504,7 @@ public class PdeSketch {
|
||||
// if .pde, run preproc to buildpath
|
||||
// if no class def'd for the pde file, then complain
|
||||
|
||||
String mainClassName = null;
|
||||
String primaryClassName = null;
|
||||
|
||||
for (int i = 0; i < codeCount; i++) {
|
||||
if (code[i].flavor == JAVA) {
|
||||
@@ -559,7 +537,7 @@ public class PdeSketch {
|
||||
|
||||
if (i == 0) {
|
||||
// store this for the compiler and the runtime
|
||||
mainClassName = className;
|
||||
primaryClassName = className;
|
||||
|
||||
// check if the 'main' file is in java mode
|
||||
if (PdePreprocessor.programType == PdePreprocessor.JAVA) {
|
||||
@@ -615,7 +593,7 @@ public class PdeSketch {
|
||||
//
|
||||
PdeCompiler compiler = new PdeCompiler();
|
||||
boolean success = compiler.compile(this, buildPath);
|
||||
return success ? mainClassName : null;
|
||||
return success ? primaryClassName : null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
8
todo.txt
8
todo.txt
@@ -73,7 +73,6 @@ o http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_Software;acti
|
||||
o try ariel's Thread.yield() suggestion
|
||||
o set default framerate of 24? 30? 2x that?
|
||||
|
||||
|
||||
_ once compiling again, change PdeException
|
||||
_ rename the class for a minute to find all references
|
||||
_ then add references to the *file index* in question
|
||||
@@ -84,6 +83,8 @@ _ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_Software;acti
|
||||
|
||||
_ fix command keys for menus (broken since switching to swing)
|
||||
|
||||
_ PdeRuntime isn't properly handling messages from all classes in project
|
||||
_ get things up and running, and see how it looks
|
||||
_ fix make.sh and dist.sh for all platforms to include new export setup
|
||||
_ re-implement history (disabled for 68)
|
||||
|
||||
@@ -133,8 +134,8 @@ _ remove the 'default' for sketchbook
|
||||
_ bring this up on bboard and get votes
|
||||
_ win2k: my documents, macosx: ~/Documents, linux: ~/sketchbook
|
||||
_ fix code for changing the sketch folder
|
||||
_ don't allow editing of multiple files in this release
|
||||
_ but support multiple java/pde files through the 'add file' option
|
||||
o don't allow editing of multiple files in this release
|
||||
o but support multiple java/pde files through the 'add file' option
|
||||
_ open mode
|
||||
_ on application open, override 'open' mode
|
||||
_ and just open an empty sketch in the sketchbook folder
|
||||
@@ -200,6 +201,7 @@ void toGrayscale() {
|
||||
BUGS / PDE
|
||||
_ find/replace hangs when recapitalizing things
|
||||
_ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1072994196;start=0
|
||||
_ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1074602643
|
||||
_ if last line of code is a comment with no CR after it,
|
||||
_ an OutOfMemoryError ensues
|
||||
_ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1067717095
|
||||
|
||||
Reference in New Issue
Block a user