diff --git a/app/PdePreprocessor.java b/app/PdePreprocessor.java index 3d98bea6f..542f51507 100644 --- a/app/PdePreprocessor.java +++ b/app/PdePreprocessor.java @@ -44,10 +44,6 @@ public class PdePreprocessor { static final int JAVA = 2; // formerly ADVANCED static int programType = -1; - //String tempClass; - //String tempFilename; - //String tempClassFilename; - Reader programReader; String buildPath; @@ -77,11 +73,10 @@ public class PdePreprocessor { /** * preprocesses a pde file and write out a java file - * * @return the classname of the exported Java */ public String write(String program, String buildPath, - String name, String imports[]) throws java.lang.Exception { + String name, String extraImports[]) throws java.lang.Exception { this.programReader = new StringReader(program); this.buildPath = buildPath; @@ -146,7 +141,7 @@ public class PdePreprocessor { PrintStream stream = new PrintStream( new FileOutputStream(buildPath + File.separator + name + ".java")); - writeHeader(stream, imports, name); + writeHeader(stream, extraImports, name); emitter.setOut(stream); emitter.print(rootNode); @@ -206,34 +201,13 @@ public class PdePreprocessor { } } - /* - // Spew out a semi-standard set of java imports. - // - // Prior to 68, these were only done when not in JAVA mode, - // but these won't hurt, and may be helpful in cases where the user - // can't be bothered to add imports to the top of their classes. - // - if (!exporting) { // if running in environment, or exporting an app - for (int i = 0; i < application_imports.length; i++) { - out.print("import " + application_imports[i] + ".*; "); - } - } else { // exporting an applet - for (int i = 0; i < applet_imports.length; i++) { - out.print("import " + applet_imports[i] + ".*; "); - } - } - */ - if (programType < JAVA) { + // open the class definition out.print("public class " + className + " extends BApplet {"); if (programType == STATIC) { - // XXXdmose need to actually deal with size / background info here - String sizeInfo = ""; - String backgroundInfo = ""; - - out.print("void setup() { " + sizeInfo + backgroundInfo + "} " - + "void draw() {"); + // now that size() and background() can go inside of draw() + out.print("void draw() {"); } } } @@ -256,6 +230,7 @@ public class PdePreprocessor { } } + static String advClassName = ""; /** diff --git a/app/PdeSketch.java b/app/PdeSketch.java index b844d22d1..eb04abec3 100644 --- a/app/PdeSketch.java +++ b/app/PdeSketch.java @@ -77,6 +77,8 @@ Export to: [ Library + ] [ OK ] */ public class Sketch { + String path; // path to 'main' file for this sketch + String name; File directory; @@ -228,7 +230,8 @@ public class Sketch { */ public void run() { try { - String program = textarea.getText(); + //String program = textarea.getText(); + current.program = textarea.getText(); current.history.record(program, PdeHistory.RUN); // if an external editor is being used, need to grab the @@ -250,15 +253,17 @@ public class Sketch { if (!buildDir.exists()) { buildDir.mkdirs(); } - // copy (changed) files from data directory into build folder - //sketch.updateDataDirectory(buildDir); - // copy contents of data dir.. eventually, if the files - // already exist in the target, don't' bother. - //public void updateDataDirectory(File buildDir) { + // copy contents of data dir into lib/build + // TODO write a file sync procedure here.. if the files + // already exist in the target, or haven't been modified + // don't' bother. this can waste a lot of time when running. File dataDir = new File(directory, "data"); if (dataDir.exists()) { - PdeBase.copyDir(dataDir, buildDir); + // just drop the files in the build folder (pre-68) + //PdeBase.copyDir(dataDir, buildDir); + // drop the files into a 'data' subfolder of the build dir + PdeBase.copyDir(dataDir, new File(buildDir, "data")); } // make up a temporary class name to suggest @@ -342,7 +347,8 @@ public class Sketch { if (runtime != null) runtime.stop(); cleanTempFiles(); //tempBuildPath); - } + } + } /** @@ -362,9 +368,6 @@ public class Sketch { protected String build(String program, String suggestedClassName, String buildPath) throws PdeException, Exception { - // true if this should extend BApplet instead of BAppletGL - //boolean extendsNormal = base.normalItem.getState(); - externalRuntime = false; externalPaths = null; String externalImports[] = null; @@ -381,9 +384,9 @@ public class Sketch { PdePreprocessor preprocessor = new PdePreprocessor(); try { - className = + mainClassName = preprocessor.write(program, buildPath, - className, imports, false); + suggestedClassName, externalImports); } catch (antlr.RecognitionException re) { // this even returns a column @@ -423,14 +426,14 @@ public class Sketch { throw new PdeException(ex.toString()); } - if (PdePreprocessor.programType == PdePreprocessor.ADVANCED) { + if (PdePreprocessor.programType == PdePreprocessor.JAVA) { externalRuntime = true; // we in advanced mode now, boy } // compile the program // PdeCompiler compiler = - new PdeCompiler(buildPath, className, externalCode, this); + new PdeCompiler(buildPath, mainClassName, externalCode, this); // run the compiler, and funnel errors to the leechErr // which is a wrapped around