protected int writeImportList(PrintWriter out, String[] imports) { int count = 0; if (imports != null && imports.length != 0) { for (String item : imports) { out.println("import " + item + "; "); count++; } out.println(); count++; } return count; }
/** * Write any required header material (eg imports, class decl stuff) * * @param out PrintStream to write it to. * @param exporting Is this being exported from PDE? * @param className Name of the class being created. */ protected void writeDeclaration(PrintWriter out, String className) { if (mode == Mode.JAVA) { // Print two blank lines so that the offset doesn't change out.println(); out.println(); } else if (mode == Mode.ACTIVE) { // Print an extra blank line so the offset is identical to the others out.println("public class " + className + " extends PApplet {"); out.println(); } else if (mode == Mode.STATIC) { out.println("public class " + className + " extends PApplet {"); out.println(indent + "public void setup() {"); } }
/** * Write any necessary closing text. * * @param out PrintStream to write it to. */ protected void writeFooter(PrintWriter out, String className) { if (mode == Mode.STATIC) { // close off setup() definition out.println(indent + indent + "noLoop();"); out.println(indent + "}"); out.println(); } if ((mode == Mode.STATIC) || (mode == Mode.ACTIVE)) { // doesn't remove the oriiginal size() method, but calling size() // again in setup() is harmless. if (!hasMethod("settings") && sizeInfo.statement != null) { out.println(indent + "public void settings() { " + sizeInfo.statement + " }"); // out.println(indent + "public void settings() {"); // out.println(indent + indent + sizeStatement); // out.println(indent + "}"); } /* if (sketchWidth != null && !hasMethod("sketchWidth")) { // Only include if it's a number (a variable will be a problem) if (PApplet.parseInt(sketchWidth, -1) != -1 || sketchWidth.equals("displayWidth")) { out.println(indent + "public int sketchWidth() { return " + sketchWidth + "; }"); } } if (sketchHeight != null && !hasMethod("sketchHeight")) { // Only include if it's a number if (PApplet.parseInt(sketchHeight, -1) != -1 || sketchHeight.equals("displayHeight")) { out.println(indent + "public int sketchHeight() { return " + sketchHeight + "; }"); } } if (sketchRenderer != null && !hasMethod("sketchRenderer")) { // Only include if it's a known renderer (otherwise it might be a variable) //if (PConstants.rendererList.hasValue(sketchRenderer)) { out.println(indent + "public String sketchRenderer() { return " + sketchRenderer + "; }"); //} } if (sketchOutputPath != null && !hasMethod("sketchOutputPath")) { out.println(indent + "public String sketchOutputPath() { return " + sketchOutputPath + "; }"); } */ if (!hasMethod("main")) { out.println(indent + "static public void main(String[] passedArgs) {"); // out.print(indent + indent + "PApplet.main(new String[] { "); out.print(indent + indent + "String[] appletArgs = new String[] { "); if (Preferences.getBoolean("export.application.present")) { out.print("\"" + PApplet.ARGS_PRESENT + "\", "); String farbe = Preferences.get("run.present.bgcolor"); out.print("\"" + PApplet.ARGS_WINDOW_COLOR + "=" + farbe + "\", "); if (Preferences.getBoolean("export.application.stop")) { farbe = Preferences.get("run.present.stop.color"); out.print("\"" + PApplet.ARGS_STOP_COLOR + "=" + farbe + "\", "); } else { out.print("\"" + PApplet.ARGS_HIDE_STOP + "\", "); } // } else { // // This is set initially based on the system control color, just // // sets the color for what goes behind the sketch before it's added. // String farbe = Preferences.get("run.window.bgcolor"); // out.print("\"" + PApplet.ARGS_BGCOLOR + "=" + farbe + "\", "); } out.println("\"" + className + "\" };"); out.println(indent + indent + "if (passedArgs != null) {"); out.println(indent + indent + " PApplet.main(concat(appletArgs, passedArgs));"); out.println(indent + indent + "} else {"); out.println(indent + indent + " PApplet.main(appletArgs);"); out.println(indent + indent + "}"); out.println(indent + "}"); } // close off the class definition out.println("}"); } }