Skip to content

Commit 723eb81

Browse files
committed
working to enforce size() rules, move settings() around, remove exportApplet()
1 parent 18790aa commit 723eb81

File tree

5 files changed

+24
-347
lines changed

5 files changed

+24
-347
lines changed

core/todo.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ X backspace key is identified as delete in OpenGL renderers
2626
X https://github.com/processing/processing/issues/3338
2727
X set icon for OpenGL windows
2828
X https://github.com/processing/processing/issues/3348
29+
X key problem with DELETE, BACKSPACE and CMD in P3D / P2D
30+
X https://github.com/processing/processing/issues/3352
2931
_ save() and saveFrame() with OPENGL renderer fails
3032
_ https://github.com/processing/processing/issues/3334
3133

@@ -36,7 +38,12 @@ _ size() inside settings() is left alone and can do whatever it wants
3638
_ comments are being removed before size() is getting checked
3739
_ probably remove anything inside settings() as well?
3840
_ fullScreen() method
39-
_ sort out display stuff
41+
_ take display into account for fullScreen()
42+
_ noSmooth()
43+
_ can only be called inside setup(), show warning elsewhere
44+
_ is lifted out of setup() and into settings()
45+
_ goes before the first beginDraw() with createGraphics()
46+
_ sort out display stuff (bug in the numbering in 3.0a9)
4047
_ Text looks blurry in GL Retina (andres)
4148
_ https://github.com/processing/processing/issues/2739
4249
_ check retina with PGraphicsRetina2D

java/src/processing/mode/java/Debugger.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ public synchronized void startDebug() {
199199

200200
log(Level.INFO, "building sketch: {0}", sketch.getName());
201201
//LineMapping.addLineNumbers(sketch); // annotate
202-
mainClassName = build.build(false);
202+
// mainClassName = build.build(false);
203+
mainClassName = build.build(true);
203204
//LineMapping.removeLineNumbers(sketch); // annotate
204205
log(Level.INFO, "class: {0}", mainClassName);
205206

java/src/processing/mode/java/JavaBuild.java

Lines changed: 4 additions & 338 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,10 @@ public String preprocess(File srcFolder,
251251
//String[] sizeParts =
252252
SizeInfo sizeInfo =
253253
preprocessor.initSketchSize(sketch.getMainProgram(), sizeWarning);
254+
if (sizeInfo == null) {
255+
// An error occurred while trying to pull out the size, so exit here
256+
return null;
257+
}
254258
//System.out.format("size() is '%s'%n", info[0]);
255259

256260
// Remove the size() statement (will be added back by writeFooter())
@@ -748,344 +752,6 @@ public SketchException placeException(String message,
748752
}
749753

750754

751-
/*
752-
protected boolean exportApplet() throws SketchException, IOException {
753-
return exportApplet(new File(sketch.getFolder(), "applet"));
754-
}
755-
*/
756-
757-
758-
/**
759-
* Handle export to applet.
760-
*/
761-
/*
762-
public boolean exportApplet(File appletFolder) throws SketchException, IOException {
763-
mode.prepareExportFolder(appletFolder);
764-
765-
srcFolder = sketch.makeTempFolder();
766-
binFolder = sketch.makeTempFolder();
767-
String foundName = build(srcFolder, binFolder, true);
768-
769-
// (already reported) error during export, exit this function
770-
if (foundName == null) return false;
771-
772-
// If name != exportSketchName, then that's weirdness
773-
// BUG unfortunately, that can also be a bug in the preproc :(
774-
if (!sketch.getName().equals(foundName)) {
775-
Base.showWarning("Error during export",
776-
"Sketch name is " + sketch.getName() + " but the\n" +
777-
"name found in the code was " + foundName + ".", null);
778-
return false;
779-
}
780-
781-
String[] sizeInfo =
782-
PdePreprocessor.parseSketchSize(sketch.getMainProgram(), false);
783-
int sketchWidth = PApplet.DEFAULT_WIDTH;
784-
int sketchHeight = PApplet.DEFAULT_HEIGHT;
785-
boolean openglApplet = false;
786-
boolean foundSize = false;
787-
if (sizeInfo != null) {
788-
try {
789-
if (sizeInfo[1] != null && sizeInfo[2] != null) {
790-
sketchWidth = Integer.parseInt(sizeInfo[1]);
791-
sketchHeight = Integer.parseInt(sizeInfo[2]);
792-
foundSize = true;
793-
}
794-
} catch (Exception e) {
795-
e.printStackTrace();
796-
// parsing errors, whatever; ignored
797-
}
798-
799-
String sketchRenderer = sizeInfo[3];
800-
if (sketchRenderer != null) {
801-
if (sketchRenderer.equals("P2D") ||
802-
sketchRenderer.equals("P3D") ||
803-
sketchRenderer.equals("OPENGL")) {
804-
openglApplet = true;
805-
}
806-
}
807-
}
808-
if (!foundSize) {
809-
final String message =
810-
"The size of this applet could not automatically be\n" +
811-
"determined from your code. You'll have to edit the\n" +
812-
"HTML file to set the size of the applet.\n" +
813-
"Use only numeric values (not variables) for the size()\n" +
814-
"command. See the size() reference for an explanation.";
815-
Base.showWarning("Could not find applet size", message, null);
816-
}
817-
818-
// // If the renderer is set to the built-in OpenGL library,
819-
// // then it's definitely an OpenGL applet.
820-
// if (sketchRenderer.equals("P3D") || sketchRenderer.equals("OPENGL")) {
821-
// openglApplet = true;
822-
// }
823-
824-
825-
// int wide = PApplet.DEFAULT_WIDTH;
826-
// int high = PApplet.DEFAULT_HEIGHT;
827-
// String renderer = "";
828-
//
829-
// String scrubbed = PdePreprocessor.scrubComments(sketch.getCode(0).getProgram());
830-
// String[] matches = PApplet.match(scrubbed, PdePreprocessor.SIZE_REGEX);
831-
//
832-
// if (matches != null) {
833-
// try {
834-
// wide = Integer.parseInt(matches[1]);
835-
// high = Integer.parseInt(matches[2]);
836-
//
837-
// // Adding back the trim() for 0136 to handle Bug #769
838-
// if (matches.length == 4) renderer = matches[3].trim();
839-
// // Actually, matches.length should always be 4...
840-
//
841-
// } catch (NumberFormatException e) {
842-
// // found a reference to size, but it didn't
843-
// // seem to contain numbers
844-
// final String message =
845-
// "The size of this applet could not automatically be\n" +
846-
// "determined from your code. You'll have to edit the\n" +
847-
// "HTML file to set the size of the applet.\n" +
848-
// "Use only numeric values (not variables) for the size()\n" +
849-
// "command. See the size() reference for an explanation.";
850-
//
851-
// Base.showWarning("Could not find applet size", message, null);
852-
// }
853-
// } // else no size() command found
854-
855-
// Grab the Javadoc-style description from the main code.
856-
String description = "";
857-
// If there are multiple closings, need to catch the first,
858-
// which is what the (.*?) will do for us.
859-
// http://code.google.com/p/processing/issues/detail?id=877
860-
String[] javadoc = PApplet.match(sketch.getCode(0).getProgram(), "/\\*{2,}(.*?)\\*+/");
861-
if (javadoc != null) {
862-
StringBuffer dbuffer = new StringBuffer();
863-
String found = javadoc[1];
864-
String[] pieces = PApplet.split(found, '\n');
865-
for (String line : pieces) {
866-
// if this line starts with * characters, remove 'em
867-
String[] m = PApplet.match(line, "^\\s*\\*+(.*)");
868-
dbuffer.append(m != null ? m[1] : line);
869-
// insert the new line into the html to help w/ line breaks
870-
dbuffer.append('\n');
871-
}
872-
description = dbuffer.toString();
873-
}
874-
875-
// Add links to all the code
876-
StringBuffer sources = new StringBuffer();
877-
//for (int i = 0; i < codeCount; i++) {
878-
for (SketchCode code : sketch.getCode()) {
879-
sources.append("<a href=\"" + code.getFileName() + "\">" +
880-
code.getPrettyName() + "</a> ");
881-
}
882-
883-
// Copy the source files to the target, since we like
884-
// to encourage people to share their code
885-
// for (int i = 0; i < codeCount; i++) {
886-
for (SketchCode code : sketch.getCode()) {
887-
try {
888-
File exportedSource = new File(appletFolder, code.getFileName());
889-
//Base.copyFile(code[i].getFile(), exportedSource);
890-
code.copyTo(exportedSource);
891-
892-
} catch (IOException e) {
893-
e.printStackTrace(); // ho hum, just move on...
894-
}
895-
}
896-
// move the .java file from the preproc there too
897-
String preprocFilename = sketch.getName() + ".java";
898-
File preprocFile = new File(srcFolder, preprocFilename);
899-
if (preprocFile.exists()) {
900-
preprocFile.renameTo(new File(appletFolder, preprocFilename));
901-
} else {
902-
System.err.println("Could not copy source file: " + preprocFile.getAbsolutePath());
903-
}
904-
905-
// Use separate .jar files whenever a library or code folder is in use.
906-
boolean separateJar =
907-
Preferences.getBoolean("export.applet.separate_jar_files") ||
908-
sketch.hasCodeFolder() ||
909-
javaLibraryPath.length() != 0;
910-
911-
File skeletonFolder = mode.getContentFile("applet");
912-
913-
// Copy the loading gif to the applet
914-
String LOADING_IMAGE = "loading.gif";
915-
// Check if the user already has their own loader image
916-
File loadingImage = new File(sketch.getFolder(), LOADING_IMAGE);
917-
if (!loadingImage.exists()) {
918-
// File skeletonFolder = new File(Base.getContentFile("lib"), "export");
919-
loadingImage = new File(skeletonFolder, LOADING_IMAGE);
920-
}
921-
Base.copyFile(loadingImage, new File(appletFolder, LOADING_IMAGE));
922-
923-
// not a good idea after all
924-
// File deployFile = new File(skeletonFolder, "deployJava.js");
925-
// Base.copyFile(deployFile, new File(appletFolder, "deployJava.js"));
926-
927-
// Create new .jar file
928-
FileOutputStream zipOutputFile =
929-
new FileOutputStream(new File(appletFolder, sketch.getName() + ".jar"));
930-
ZipOutputStream zos = new ZipOutputStream(zipOutputFile);
931-
// ZipEntry entry;
932-
933-
StringBuffer archives = new StringBuffer();
934-
archives.append(sketch.getName() + ".jar");
935-
936-
// Add the manifest file
937-
addManifest(zos);
938-
939-
// File openglLibraryFolder =
940-
// new File(editor.getMode().getLibrariesFolder(), "opengl/library");
941-
// String openglLibraryPath = openglLibraryFolder.getAbsolutePath();
942-
// boolean openglApplet = false;
943-
944-
HashMap<String,Object> zipFileContents = new HashMap<String,Object>();
945-
946-
// add contents of 'library' folders
947-
for (Library library : importedLibraries) {
948-
// if (library.getPath().equals(openglLibraryPath)) {
949-
if (library.getName().equals("OpenGL")) {
950-
openglApplet = true;
951-
}
952-
for (File exportFile : library.getAppletExports()) {
953-
String exportName = exportFile.getName();
954-
if (!exportFile.exists()) {
955-
System.err.println("File " + exportFile.getAbsolutePath() + " does not exist");
956-
957-
} else if (exportFile.isDirectory()) {
958-
System.out.println("Ignoring sub-folder \"" + exportFile.getAbsolutePath() + "\"");
959-
960-
} else if (exportName.toLowerCase().endsWith(".zip") ||
961-
exportName.toLowerCase().endsWith(".jar")) {
962-
if (separateJar) {
963-
Base.copyFile(exportFile, new File(appletFolder, exportName));
964-
archives.append("," + exportName);
965-
} else {
966-
String path = exportFile.getAbsolutePath();
967-
packClassPathIntoZipFile(path, zos, zipFileContents);
968-
}
969-
970-
} else { // just copy the file over.. prolly a .dll or something
971-
Base.copyFile(exportFile, new File(appletFolder, exportName));
972-
}
973-
}
974-
}
975-
976-
// Copy core.jar, or add its contents to the output .jar file
977-
File bagelJar = Base.isMacOS() ?
978-
Base.getContentFile("core.jar") :
979-
Base.getContentFile("lib/core.jar");
980-
if (separateJar) {
981-
Base.copyFile(bagelJar, new File(appletFolder, "core.jar"));
982-
archives.append(",core.jar");
983-
} else {
984-
String bagelJarPath = bagelJar.getAbsolutePath();
985-
packClassPathIntoZipFile(bagelJarPath, zos, zipFileContents);
986-
}
987-
988-
if (sketch.hasCodeFolder()) {
989-
File[] codeJarFiles = sketch.getCodeFolder().listFiles(new FilenameFilter() {
990-
public boolean accept(File dir, String name) {
991-
if (name.charAt(0) == '.') return false;
992-
if (name.toLowerCase().endsWith(".jar")) return true;
993-
if (name.toLowerCase().endsWith(".zip")) return true;
994-
return false;
995-
}
996-
});
997-
for (File exportFile : codeJarFiles) {
998-
String name = exportFile.getName();
999-
Base.copyFile(exportFile, new File(appletFolder, name));
1000-
archives.append("," + name);
1001-
}
1002-
}
1003-
1004-
// Add the data folder to the output .jar file
1005-
addDataFolder(zos);
1006-
1007-
// add the project's .class files to the jar
1008-
// just grabs everything from the build directory
1009-
// since there may be some inner classes
1010-
// (add any .class files from the applet dir, then delete them)
1011-
// TODO this needs to be recursive (for packages)
1012-
addClasses(zos, binFolder);
1013-
1014-
// close up the jar file
1015-
zos.flush();
1016-
zos.close();
1017-
1018-
//
1019-
1020-
// convert the applet template
1021-
// @@sketch@@, @@width@@, @@height@@, @@archive@@, @@source@@
1022-
// and now @@description@@
1023-
1024-
File htmlOutputFile = new File(appletFolder, "index.html");
1025-
// UTF-8 fixes http://dev.processing.org/bugs/show_bug.cgi?id=474
1026-
PrintWriter htmlWriter = PApplet.createWriter(htmlOutputFile);
1027-
1028-
InputStream is = null;
1029-
// if there is an applet.html file in the sketch folder, use that
1030-
File customHtml = new File(sketch.getFolder(), "applet.html");
1031-
if (customHtml.exists()) {
1032-
is = new FileInputStream(customHtml);
1033-
}
1034-
// for (File libraryFolder : importedLibraries) {
1035-
// System.out.println(libraryFolder + " " + libraryFolder.getAbsolutePath());
1036-
// }
1037-
if (is == null) {
1038-
if (openglApplet) {
1039-
is = mode.getContentStream("applet/template-opengl.html");
1040-
} else {
1041-
is = mode.getContentStream("applet/template.html");
1042-
}
1043-
}
1044-
BufferedReader reader = PApplet.createReader(is);
1045-
1046-
String line = null;
1047-
while ((line = reader.readLine()) != null) {
1048-
if (line.indexOf("@@") != -1) {
1049-
StringBuffer sb = new StringBuffer(line);
1050-
int index = 0;
1051-
while ((index = sb.indexOf("@@sketch@@")) != -1) {
1052-
sb.replace(index, index + "@@sketch@@".length(),
1053-
sketch.getName());
1054-
}
1055-
while ((index = sb.indexOf("@@source@@")) != -1) {
1056-
sb.replace(index, index + "@@source@@".length(),
1057-
sources.toString());
1058-
}
1059-
while ((index = sb.indexOf("@@archive@@")) != -1) {
1060-
sb.replace(index, index + "@@archive@@".length(),
1061-
archives.toString());
1062-
}
1063-
while ((index = sb.indexOf("@@width@@")) != -1) {
1064-
sb.replace(index, index + "@@width@@".length(),
1065-
String.valueOf(sketchWidth));
1066-
}
1067-
while ((index = sb.indexOf("@@height@@")) != -1) {
1068-
sb.replace(index, index + "@@height@@".length(),
1069-
String.valueOf(sketchHeight));
1070-
}
1071-
while ((index = sb.indexOf("@@description@@")) != -1) {
1072-
sb.replace(index, index + "@@description@@".length(),
1073-
description);
1074-
}
1075-
line = sb.toString();
1076-
}
1077-
htmlWriter.println(line);
1078-
}
1079-
1080-
reader.close();
1081-
htmlWriter.flush();
1082-
htmlWriter.close();
1083-
1084-
return true;
1085-
}
1086-
*/
1087-
1088-
1089755
/**
1090756
* Export to application via GUI.
1091757
*/

0 commit comments

Comments
 (0)