diff --git a/processing/app/PdeEditor.java b/processing/app/PdeEditor.java
index 16a74a1e3..d4dc6ddf1 100644
--- a/processing/app/PdeEditor.java
+++ b/processing/app/PdeEditor.java
@@ -4,6 +4,7 @@ import java.awt.*;
import java.io.*;
import java.net.*;
import java.util.*;
+import java.util.zip.*;
// play, stop, open, save, courseware, print, beautify
@@ -62,10 +63,10 @@ public class PdeEditor extends Panel implements PdeEnvironment {
top.setBackground(buttonBgColor);
top.setLayout(new BorderLayout());
- boolean privileges = PdeApplet.hasFullPrivileges();
- boolean courseware = PdeApplet.get("save_as") != null;
- buttons = new PdeEditorButtons(this, privileges, courseware,
- (privileges & !courseware), false);
+ //boolean privileges = PdeApplet.hasFullPrivileges();
+ //boolean courseware = PdeApplet.get("save_as") != null;
+ buttons = new PdeEditorButtons(this); //, privileges, courseware,
+ //(privileges & !courseware), false);
buttons.setBackground(buttonBgColor);
//add("North", buttons);
//top.add("North", buttons);
@@ -272,6 +273,171 @@ public class PdeEditor extends Panel implements PdeEnvironment {
}
+ public void doExport() {
+ message("Exporting to applet...");
+ String s = textarea.getText();
+ FileDialog fd = new FileDialog(new Frame(),
+ "Create applet project named...",
+ FileDialog.SAVE);
+ fd.setDirectory(lastDirectory);
+ fd.setFile(lastFile);
+ fd.show();
+
+ String directory = fd.getDirectory();
+ String projectName = fd.getFile();
+ if (projectName == null) { // user cancelled
+ message(EMPTY);
+ buttons.clear();
+ return;
+ } else if (projectName.indexOf(' ') != -1) { // space in filename
+ message("Project name cannot have spaces.");
+ buttons.clear();
+ return;
+ }
+ //File file = new File(directory, filename);
+
+ // write java code for applet
+ /*
+ File javaOutputFile = new File(outputDirectory, projectName + ".java");
+ FileOutputStream fos = new FileOutputStream(javaOutputFile);
+ PrintStream ps = new PrintStream(fos);
+ ps.println("public class " +
+ ps.print(converted);
+ ps.flush();
+ ps.close();
+ */
+
+ try {
+ String program = textarea.getText();
+
+ // create the project directory
+ KjcEngine engine = new KjcEngine(program, this);
+ File projectDir = new File(directory, projectName);
+ projectDir.mkdirs();
+
+ engine.writeJava(projectName, false);
+ if (!engine.compileJava()) return;
+ // message() should already hava a message in this case
+
+ // copy .java to project dir
+ String javaName = projectName + ".java";
+ copyFile(new File(javaName), new File(projectDir, javaName));
+
+ // remove temporary .java and .class files
+ //engine.cleanup();
+
+ int wide = 320;
+ int high = 240;
+ int index = program.indexOf("size(");
+ if (index != -1) {
+ try {
+ String str = program.substring(index + 5);
+ int comma = str.indexOf(',');
+ int paren = str.indexOf(')');
+ wide = Integer.parseInt(str.substring(0, comma).trim());
+ high = Integer.parseInt(str.substring(comma+1, paren).trim());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ File htmlOutputFile = new File(projectDir, "index.html");
+ FileOutputStream fos = new FileOutputStream(htmlOutputFile);
+ PrintStream ps = new PrintStream(fos);
+ ps.println("
");
+ ps.println();
+ ps.println("
");
+
+ ps.println();
+ ps.print("");
+ ps.println();
+
+ ps.println("source code");
+ ps.println();
+
+ ps.println("");
+
+ ps.println(" ");
+ ps.flush();
+ ps.close();
+
+ final String classes[] = {
+ "Bagel.class", "BagelConstants.class", "BagelFont.class",
+ "BagelImage.class", "BagelLight.class", "BagelPolygon.class",
+ "ProcessingApplet.class"
+ };
+
+ // create new .jar file
+ FileOutputStream zipOutputFile =
+ new FileOutputStream(new File(projectDir, projectName + ".jar"));
+ ZipOutputStream zos = new ZipOutputStream(zipOutputFile);
+ ZipEntry entry;
+
+ // add standard .class files to the jar
+ for (int i = 0; i < classes.length; i++) {
+ //System.out.println("adding class " + (i+1) + " of " + classes.length);
+ entry = new ZipEntry(classes[i]);
+ zos.putNextEntry(entry);
+ zos.write(grabFile(new File("lib\\export\\" + classes[i])));
+ zos.closeEntry();
+ }
+
+ // add the project's .class to the jar
+ //System.out.println("adding " + projectName + ".class");
+ entry = new ZipEntry(projectName + ".class");
+ zos.putNextEntry(entry);
+ zos.write(grabFile(new File("lib", projectName + ".class")));
+ zos.closeEntry();
+
+ // close up the jar file
+ zos.flush();
+ zos.close();
+ //zipOutputFile.close();
+
+ engine.cleanup();
+
+ message("Done exporting.");
+
+ } catch (Exception e) {
+ message("Error during export.");
+ e.printStackTrace();
+ }
+ buttons.clear();
+ }
+
+ static protected byte[] grabFile(File file) throws IOException {
+ int size = (int) file.length();
+ FileInputStream input = new FileInputStream(file);
+ byte buffer[] = new byte[size];
+ int offset = 0;
+ int bytesRead;
+ while ((bytesRead = input.read(buffer, offset, size-offset)) != -1) {
+ offset += bytesRead;
+ //System.out.println(offset + " " + bytesRead);
+ if (bytesRead == 0) break;
+ }
+ //System.out.println("done grabbing file");
+ return buffer;
+ }
+
+ static protected void copyFile(File afile, File bfile) {
+ try {
+ FileInputStream from = new FileInputStream(afile);
+ FileOutputStream to = new FileOutputStream(bfile);
+ byte[] buffer = new byte[4096];
+ int bytesRead;
+ while ((bytesRead = from.read(buffer)) != -1) {
+ to.write(buffer, 0, bytesRead);
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+
public void doSnapshot() {
/*
//dbcp.msg("Sending your file to the server...");
@@ -469,6 +635,7 @@ public class PdeEditor extends Panel implements PdeEnvironment {
public void doBeautify() {
+ /*
String prog = textarea.getText();
if ((prog.charAt(0) == '#') || (prog.charAt(0) == ';')) {
message("Only DBN code can be made beautiful.");
@@ -526,6 +693,7 @@ public class PdeEditor extends Panel implements PdeEnvironment {
}
}
textarea.setText(buffer.toString());
+ */
buttons.clear();
}
diff --git a/processing/app/PdeEditorButtons.java b/processing/app/PdeEditorButtons.java
index a2526b3cb..d57fc3853 100644
--- a/processing/app/PdeEditorButtons.java
+++ b/processing/app/PdeEditorButtons.java
@@ -9,7 +9,7 @@ public class PdeEditorButtons extends Panel {
static final String title[] = {
"Play", "Stop", "Close",
- "Open", "Save", "Save on Server", "Print", "Beautify",
+ "Open", "Save", "Export Applet", "Print", "Beautify",
"Disable Full Screen", "Full Screen"
};
@@ -23,7 +23,7 @@ public class PdeEditorButtons extends Panel {
static final int OPEN = 3;
static final int SAVE = 4;
- static final int SNAPSHOT = 5; // only available is save_as defined
+ static final int EXPORT = 5;
static final int PRINT = 6;
static final int BEAUTIFY = 7;
@@ -55,9 +55,9 @@ public class PdeEditorButtons extends Panel {
int y1, y2;
- public PdeEditorButtons(PdeEditor editor, boolean useOpenSave,
+ public PdeEditorButtons(PdeEditor editor /*, boolean useOpenSave,
boolean useCourseware, boolean usePrint,
- boolean useBeautify) {
+ boolean useBeautify*/) {
this.editor = editor;
buttons = PdeApplet.readImage("buttons.gif");
@@ -70,13 +70,14 @@ public class PdeEditorButtons extends Panel {
which[buttonCount++] = CLOSE;
// the rest are conditional
- if (useOpenSave) {
+ //if (useOpenSave) {
which[buttonCount++] = OPEN;
which[buttonCount++] = SAVE;
- }
- if (useCourseware) which[buttonCount++] = SNAPSHOT;
- if (usePrint) which[buttonCount++] = PRINT;
- if (useBeautify) which[buttonCount++] = BEAUTIFY;
+ //}
+ which[buttonCount++] = EXPORT;
+ //if (useCourseware) which[buttonCount++] = SNAPSHOT;
+ //if (usePrint) which[buttonCount++] = PRINT;
+ //if (useBeautify) which[buttonCount++] = BEAUTIFY;
which[buttonCount++] = FULL_SCREEN;
@@ -286,7 +287,7 @@ public class PdeEditorButtons extends Panel {
case OPEN: editor.doOpen(); break;
case SAVE: editor.doSave(); break;
- case SNAPSHOT: editor.doSnapshot(); break;
+ case EXPORT: editor.doExport(); break;
case PRINT: editor.doPrint(); break;
case BEAUTIFY: editor.doBeautify(); break;
diff --git a/processing/app/ProcessingApplet.java b/processing/app/ProcessingApplet.java
index 53fcddc06..8f988c374 100644
--- a/processing/app/ProcessingApplet.java
+++ b/processing/app/ProcessingApplet.java
@@ -723,6 +723,10 @@ public class ProcessingApplet extends Applet
g.colorMode(colorMode, maxX, maxY, maxZ, maxA);
}
+ public void colorScale(int max) {
+ g.colorScale(max);
+ }
+
public void colorScale(int maxX, int maxY, int maxZ, int maxA) {
g.colorScale(maxX, maxY, maxZ, maxA);
}
@@ -771,6 +775,10 @@ public class ProcessingApplet extends Applet
g.stroke(x, y, z, a);
}
+ public void clear() {
+ g.clear();
+ }
+
public void noBackground() {
g.noBackground();
}