diff --git a/app/src/processing/mode/java/AutoFormat.java b/app/src/processing/mode/java/AutoFormat.java index 1f78fc67d..f98e6509d 100644 --- a/app/src/processing/mode/java/AutoFormat.java +++ b/app/src/processing/mode/java/AutoFormat.java @@ -36,10 +36,10 @@ import processing.core.PApplet; * Contributed by Martin Gomez, additional bug fixes by Ben Fry. * Additional fixes by Jonathan Feinberg in March 2010. *

- * After some further digging, this code in fact appears to be a modified - * version of Jason Pell's GPLed "Java Beautifier" class found + * After some further digging, this code in fact appears to be a modified + * version of Jason Pell's GPLed "Java Beautifier" class found * here. - * Which is itself based on code from Van Di-Han Ho from + * Which is itself based on code from Van Di-Han Ho from * here. * [Ben Fry, August 2009] */ @@ -73,8 +73,8 @@ public class AutoFormat implements Formatter { private char c; private final Stack castFlags = new Stack(); - - + + private void comment() { final boolean save_s_flg = s_flag; @@ -101,7 +101,7 @@ public class AutoFormat implements Formatter { return; } - + private char get_string() { char ch; while (true) { @@ -129,7 +129,7 @@ public class AutoFormat implements Formatter { } } - + private void writeIndentedLine() { if (buf.length() == 0) { if (s_flag) { @@ -154,7 +154,7 @@ public class AutoFormat implements Formatter { buf.setLength(0); } - + private void writeIndentedComment() { final boolean saved_s_flag = s_flag; if (buf.length() > 0) { @@ -186,7 +186,7 @@ public class AutoFormat implements Formatter { } } - + private void handleSingleLineComment() { c = next(); while (c != '\n') { @@ -198,7 +198,7 @@ public class AutoFormat implements Formatter { s_flag = true; } - + private void printIndentation() { if (tabs < 0) { tabs = 0; @@ -212,7 +212,7 @@ public class AutoFormat implements Formatter { } } - + private char peek() { if (pos + 1 >= chars.length) { return 0; @@ -220,10 +220,10 @@ public class AutoFormat implements Formatter { return chars[pos + 1]; } - + private char lastNonWhitespace = 0; - + private int prev() { return lastNonWhitespace; } @@ -272,7 +272,7 @@ public class AutoFormat implements Formatter { if_flg = true; } - + /* read to new_line */ private boolean getnl() { final int savedTabs = tabs; @@ -306,7 +306,7 @@ public class AutoFormat implements Formatter { return false; } - + private boolean lookup(final String keyword) { return Pattern.matches("^\\s*" + keyword + "(?![a-zA-Z0-9_&]).*$", buf); } @@ -316,8 +316,8 @@ public class AutoFormat implements Formatter { final String regex = "^\\s*" + keyword.replaceAll("\\*", "\\\\*") + ".*$"; return Pattern.matches(regex, buf); } - - + + private void trimRight(final StringBuilder sb) { while (sb.length() >= 1 && Character.isWhitespace(sb.charAt(sb.length() - 1))) @@ -430,9 +430,8 @@ public class AutoFormat implements Formatter { tabs--; } trimRight(buf); - if (buf.length() > 0 - || (result.length() > 0 && !Character.isWhitespace(result - .charAt(result.length() - 1)))) + if (buf.length() > 0 || + (result.length() > 0 && !Character.isWhitespace(result.charAt(result.length() - 1)))) buf.append(" "); buf.append(c); writeIndentedLine(); diff --git a/app/src/processing/mode/java/JavaBuild.java b/app/src/processing/mode/java/JavaBuild.java index 2e47f5f54..91639a788 100644 --- a/app/src/processing/mode/java/JavaBuild.java +++ b/app/src/processing/mode/java/JavaBuild.java @@ -263,6 +263,7 @@ public class JavaBuild { File outputFolder = (packageName == null) ? srcFolder : new File(srcFolder, packageName.replace('.', '/')); outputFolder.mkdirs(); +// Base.openFolder(outputFolder); final File java = new File(outputFolder, sketch.getName() + ".java"); final PrintWriter stream = new PrintWriter(new FileWriter(java)); try { @@ -276,7 +277,6 @@ public class JavaBuild { throw new SketchException(msg); } catch (antlr.RecognitionException re) { // re also returns a column that we're not bothering with for now - // first assume that it's the main file // int errorFile = 0; int errorLine = re.getLine() - 1; diff --git a/app/src/processing/mode/java/preproc/PdePreprocessor.java b/app/src/processing/mode/java/preproc/PdePreprocessor.java index 1d7d29879..270f9a328 100644 --- a/app/src/processing/mode/java/preproc/PdePreprocessor.java +++ b/app/src/processing/mode/java/preproc/PdePreprocessor.java @@ -828,28 +828,29 @@ public class PdePreprocessor { */ protected void writeFooter(PrintWriter out, String className) { if (mode == Mode.STATIC) { - // close off draw() definition - out.println(indent + "noLoop();"); - out.println("} "); + // close off setup() definition + out.println(indent + indent + "noLoop();"); + out.println(indent + "}"); + out.println(); } if ((mode == Mode.STATIC) || (mode == Mode.ACTIVE)) { 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")) { + 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")) { + 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 (sketchRenderer.equals("P2D") || - sketchRenderer.equals("P3D") || + if (sketchRenderer.equals("P2D") || + sketchRenderer.equals("P3D") || sketchRenderer.equals("OPENGL") || sketchRenderer.equals("JAVA2D")) { out.println(indent + "public String sketchRenderer() { return " + sketchRenderer + "; }"); @@ -857,8 +858,9 @@ public class PdePreprocessor { } if (!hasMethod("main")) { - out.println(indent + "static public void main(String args[]) {"); - out.print(indent + indent + "PApplet.main(new String[] { "); + 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.fullscreen")) { out.print("\"" + PApplet.ARGS_FULL_SCREEN + "\", "); @@ -878,7 +880,14 @@ public class PdePreprocessor { // String farbe = Preferences.get("run.window.bgcolor"); // out.print("\"" + PApplet.ARGS_BGCOLOR + "=" + farbe + "\", "); } - out.println("\"" + className + "\" });"); + 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 + "}"); } diff --git a/core/src/processing/core/PApplet.java b/core/src/processing/core/PApplet.java index 0f7a552b1..71609151e 100644 --- a/core/src/processing/core/PApplet.java +++ b/core/src/processing/core/PApplet.java @@ -7483,6 +7483,7 @@ public class PApplet extends Applet System.arraycopy(b, 0, c, a.length, b.length); return c; } + static public Object concat(Object a, Object b) { Class type = a.getClass().getComponentType(); int alength = Array.getLength(a); @@ -9105,7 +9106,7 @@ public class PApplet extends Applet * The simplest way to turn and applet into an application is to * add the following code to your program: *

static public void main(String args[]) {
-   *   PApplet.main(new String[] { "YourSketchName" });
+   *   PApplet.main("YourSketchName", args);
    * }
* This will properly launch your applet from a double-clickable * .jar or from the command line. @@ -9146,7 +9147,33 @@ public class PApplet extends Applet * editor window, for placement of applet window * */ - public static void main(final String[] args) { + static public void main(final String[] args) { + runSketch(args, null); + } + + + /** + * Convenience method so that PApplet.main("YourSketch") launches a sketch, + * rather than having to wrap it into a String array. + * @param mainClass name of the class to load (with package if any) + */ + static public void main(final String mainClass) { + main(mainClass, null); + } + + + /** + * Convenience method so that PApplet.main("YourSketch", args) launches a + * sketch, rather than having to wrap it into a String array, and appending + * the 'args' array when not null. + * @param mainClass name of the class to load (with package if any) + * @param args command line arguments to pass to the sketch + */ + static public void main(final String mainClass, final String[] passedArgs) { + String[] args = new String[] { mainClass }; + if (passedArgs != null) { + args = concat(args, passedArgs); + } runSketch(args, null); } @@ -13959,7 +13986,7 @@ public class PApplet extends Applet * PGraphicsJava2D, or resized image data and OpenGL texture indices for * PGraphicsOpenGL. * @param renderer The PGraphics renderer associated to the image - * @param storage The metadata required by the renderer + * @param storage The metadata required by the renderer */ public void setCache(PGraphics renderer, Object storage) { if (recorder != null) recorder.setCache(renderer, storage); @@ -13994,7 +14021,7 @@ public class PApplet extends Applet * Store parameters for a renderer that requires extra metadata of * some kind. * @param renderer The PGraphics renderer associated to the image - * @param storage The parameters required by the renderer + * @param storage The parameters required by the renderer */ public void setParams(PGraphics renderer, Object params) { if (recorder != null) recorder.setParams(renderer, params); @@ -14024,26 +14051,26 @@ public class PApplet extends Applet /** * ( begin auto-generated from PImage_get.xml ) - * - * Reads the color of any pixel or grabs a section of an image. If no - * parameters are specified, the entire image is returned. Use the x - * and y parameters to get the value of one pixel. Get a section of - * the display window by specifying an additional width and - * height parameter. When getting an image, the x and - * y parameters define the coordinates for the upper-left corner of + * + * Reads the color of any pixel or grabs a section of an image. If no + * parameters are specified, the entire image is returned. Use the x + * and y parameters to get the value of one pixel. Get a section of + * the display window by specifying an additional width and + * height parameter. When getting an image, the x and + * y parameters define the coordinates for the upper-left corner of * the image, regardless of the current imageMode().
*
- * If the pixel requested is outside of the image window, black is - * returned. The numbers returned are scaled according to the current color - * ranges, but only RGB values are returned by this function. For example, - * even though you may have drawn a shape with colorMode(HSB), the + * If the pixel requested is outside of the image window, black is + * returned. The numbers returned are scaled according to the current color + * ranges, but only RGB values are returned by this function. For example, + * even though you may have drawn a shape with colorMode(HSB), the * numbers returned will be in RGB format.
*
- * Getting the color of a single pixel with get(x, y) is easy, but - * not as fast as grabbing the data directly from pixels[]. The - * equivalent statement to get(x, y) using pixels[] is + * Getting the color of a single pixel with get(x, y) is easy, but + * not as fast as grabbing the data directly from pixels[]. The + * equivalent statement to get(x, y) using pixels[] is * pixels[y*width+x]. See the reference for pixels[] for more information. - * + * * ( end auto-generated ) * *

Advanced

@@ -14063,7 +14090,7 @@ public class PApplet extends Applet * is inside the bounds, and then has to check to see what image * type it is. If you want things to be more efficient, access the * pixels[] array directly. - * + * * @webref image:pixels * @brief Reads the color of any pixel or grabs a rectangle of pixels * @usage web_application @@ -14097,25 +14124,25 @@ public class PApplet extends Applet /** * ( begin auto-generated from PImage_set.xml ) - * - * Changes the color of any pixel or writes an image directly into the + * + * Changes the color of any pixel or writes an image directly into the * display window.
*
- * The x and y parameters specify the pixel to change and the - * color parameter specifies the color value. The color parameter is - * affected by the current color mode (the default is RGB values from 0 to - * 255). When setting an image, the x and y parameters define - * the coordinates for the upper-left corner of the image, regardless of + * The x and y parameters specify the pixel to change and the + * color parameter specifies the color value. The color parameter is + * affected by the current color mode (the default is RGB values from 0 to + * 255). When setting an image, the x and y parameters define + * the coordinates for the upper-left corner of the image, regardless of * the current imageMode(). *

- * Setting the color of a single pixel with set(x, y) is easy, but - * not as fast as putting the data directly into pixels[]. The - * equivalent statement to set(x, y, #000000) using pixels[] - * is pixels[y*width+x] = #000000. See the reference for + * Setting the color of a single pixel with set(x, y) is easy, but + * not as fast as putting the data directly into pixels[]. The + * equivalent statement to set(x, y, #000000) using pixels[] + * is pixels[y*width+x] = #000000. See the reference for * pixels[] for more information. - * + * * ( end auto-generated ) - * + * * @webref image:pixels * @brief writes a color to any pixel or writes an image into another * @usage web_application @@ -14148,18 +14175,18 @@ public class PApplet extends Applet /** * ( begin auto-generated from PImage_mask.xml ) - * - * Masks part of an image from displaying by loading another image and - * using it as an alpha channel. This mask image should only contain - * grayscale data, but only the blue color channel is used. The mask image + * + * Masks part of an image from displaying by loading another image and + * using it as an alpha channel. This mask image should only contain + * grayscale data, but only the blue color channel is used. The mask image * needs to be the same size as the image to which it is applied.
*
- * In addition to using a mask image, an integer array containing the alpha - * channel data can be specified directly. This method is useful for - * creating dynamically generated alpha masks. This array must be of the - * same length as the target image's pixels array and should contain only + * In addition to using a mask image, an integer array containing the alpha + * channel data can be specified directly. This method is useful for + * creating dynamically generated alpha masks. This array must be of the + * same length as the target image's pixels array and should contain only * grayscale data of values between 0-255. - * + * * ( end auto-generated ) * *

Advanced

@@ -14204,31 +14231,31 @@ public class PApplet extends Applet /** * ( begin auto-generated from PImage_filter.xml ) - * - * Filters an image as defined by one of the following modes:

THRESHOLD - converts the image to black and white pixels depending if - * they are above or below the threshold defined by the level parameter. - * The level must be between 0.0 (black) and 1.0(white). If no level is + * + * Filters an image as defined by one of the following modes:

THRESHOLD - converts the image to black and white pixels depending if + * they are above or below the threshold defined by the level parameter. + * The level must be between 0.0 (black) and 1.0(white). If no level is * specified, 0.5 is used.
*
* GRAY - converts any colors in the image to grayscale equivalents
*
* INVERT - sets each pixel to its inverse value
*
- * POSTERIZE - limits each channel of the image to the number of colors + * POSTERIZE - limits each channel of the image to the number of colors * specified as the level parameter
*
- * BLUR - executes a Guassian blur with the level parameter specifying the - * extent of the blurring. If no level parameter is used, the blur is + * BLUR - executes a Guassian blur with the level parameter specifying the + * extent of the blurring. If no level parameter is used, the blur is * equivalent to Guassian blur of radius 1
*
* OPAQUE - sets the alpha channel to entirely opaque
*
- * ERODE - reduces the light areas with the amount defined by the level + * ERODE - reduces the light areas with the amount defined by the level * parameter
*
* DILATE - increases the light areas with the amount defined by the level parameter - * + * * ( end auto-generated ) * *

Advanced

@@ -14263,17 +14290,17 @@ public class PApplet extends Applet /** * ( begin auto-generated from PImage_copy.xml ) - * - * Copies a region of pixels from one image into another. If the source and - * destination regions aren't the same size, it will automatically resize - * source pixels to fit the specified target region. No alpha information - * is used in the process, however if the source image has an alpha channel + * + * Copies a region of pixels from one image into another. If the source and + * destination regions aren't the same size, it will automatically resize + * source pixels to fit the specified target region. No alpha information + * is used in the process, however if the source image has an alpha channel * set, it will be copied as well. *

* As of release 0149, this function ignores imageMode(). - * + * * ( end auto-generated ) - * + * * @webref image:pixels * @brief Copies the entire image * @usage web_application @@ -14308,11 +14335,11 @@ public class PApplet extends Applet /** * ( begin auto-generated from blendColor.xml ) - * - * Blends two color values together based on the blending mode given as the - * MODE parameter. The possible modes are described in the reference + * + * Blends two color values together based on the blending mode given as the + * MODE parameter. The possible modes are described in the reference * for the blend() function. - * + * * ( end auto-generated ) *

Advanced

*