mirror of
https://github.com/processing/processing4.git
synced 2026-02-10 00:59:40 +01:00
still going
This commit is contained in:
@@ -1793,211 +1793,6 @@ public class PdeEditor extends JFrame
|
||||
}
|
||||
*/
|
||||
|
||||
protected void handleExport(File appletDir, String exportSketchName,
|
||||
File dataDir) {
|
||||
try {
|
||||
String program = textarea.getText();
|
||||
|
||||
// create the project directory
|
||||
// pass null for datapath because the files shouldn't be
|
||||
// copied to the build dir.. that's only for the temp stuff
|
||||
appletDir.mkdirs();
|
||||
|
||||
// build the sketch
|
||||
exportSketchName =
|
||||
build(program, exportSketchName, appletDir.getPath(), true);
|
||||
|
||||
// (already reported) error during export, exit this function
|
||||
if (exportSketchName == null) {
|
||||
buttons.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
int wide = BApplet.DEFAULT_WIDTH;
|
||||
int high = BApplet.DEFAULT_HEIGHT;
|
||||
|
||||
try {
|
||||
PatternMatcher matcher = new Perl5Matcher();
|
||||
PatternCompiler compiler = new Perl5Compiler();
|
||||
|
||||
// don't just use this version, since it only grabs the numbers
|
||||
//String sizing = "[\\s\\;]size\\s*\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*\\);";
|
||||
|
||||
// this matches against any uses of the size() function, whether they
|
||||
// contain numbers of variables or whatever. this way, no warning is
|
||||
// shown if size() isn't actually used in the applet, which is the case
|
||||
// especially for beginners that are cutting/pasting from the reference.
|
||||
String sizing = "[\\s\\;]size\\s*\\(\\s*(\\S+)\\s*,\\s*(\\S+)\\s*\\);";
|
||||
|
||||
Pattern pattern = compiler.compile(sizing);
|
||||
|
||||
// adds a space at the beginning, in case size() is the very first
|
||||
// thing in the program (very common), since the regexp needs to check
|
||||
// for things in front of it.
|
||||
PatternMatcherInput input = new PatternMatcherInput(" " + program);
|
||||
if (matcher.contains(input, pattern)) {
|
||||
MatchResult result = matcher.getMatch();
|
||||
try {
|
||||
wide = Integer.parseInt(result.group(1).toString());
|
||||
high = Integer.parseInt(result.group(2).toString());
|
||||
//System.out.println("width " + wide + " high " + high);
|
||||
|
||||
} catch (NumberFormatException e) {
|
||||
|
||||
// found a reference to size, but it didn't seem to contain numbers
|
||||
final String message =
|
||||
"The size of this applet could not automatically be\n" +
|
||||
"determined from your code. You'll have to edit the\n" +
|
||||
"HTML file to set the size of the applet.";
|
||||
|
||||
JOptionPane.showMessageDialog(this, message,
|
||||
"Could not find applet size",
|
||||
JOptionPane.WARNING_MESSAGE);
|
||||
}
|
||||
} // else no size() command found
|
||||
|
||||
} catch (MalformedPatternException e){
|
||||
e.printStackTrace();
|
||||
//System.err.println("Bad pattern.");
|
||||
//System.err.println(e.getMessage());
|
||||
}
|
||||
|
||||
File htmlOutputFile = new File(appletDir, "index.html");
|
||||
FileOutputStream fos = new FileOutputStream(htmlOutputFile);
|
||||
PrintStream ps = new PrintStream(fos);
|
||||
|
||||
// wide, high, and exportSketchName
|
||||
|
||||
// @@sketch@@, @@width@@, @@height@@, @@archive@@
|
||||
|
||||
InputStream is = PdeBase.getStream("applet.html");
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
||||
|
||||
String line = null;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (line.indexOf("@@") != -1) {
|
||||
StringBuffer sb = new StringBuffer(line);
|
||||
int index = 0;
|
||||
while ((index = sb.indexOf("@@sketch@@")) != -1) {
|
||||
sb.replace(index, index + "@@sketch@@".length(),
|
||||
exportSketchName);
|
||||
}
|
||||
while ((index = sb.indexOf("@@archive@@")) != -1) {
|
||||
sb.replace(index, index + "@@archive@@".length(),
|
||||
exportSketchName + ".jar");
|
||||
}
|
||||
while ((index = sb.indexOf("@@width@@")) != -1) {
|
||||
sb.replace(index, index + "@@width@@".length(),
|
||||
String.valueOf(wide));
|
||||
}
|
||||
while ((index = sb.indexOf("@@height@@")) != -1) {
|
||||
sb.replace(index, index + "@@height@@".length(),
|
||||
String.valueOf(wide));
|
||||
}
|
||||
line = sb.toString();
|
||||
}
|
||||
ps.println(line);
|
||||
}
|
||||
|
||||
reader.close();
|
||||
|
||||
ps.flush();
|
||||
ps.close();
|
||||
|
||||
// create new .jar file
|
||||
FileOutputStream zipOutputFile =
|
||||
new FileOutputStream(new File(appletDir, exportSketchName + ".jar"));
|
||||
ZipOutputStream zos = new ZipOutputStream(zipOutputFile);
|
||||
ZipEntry entry;
|
||||
|
||||
File codeFolder = new File(sketchDir, "code");
|
||||
if (codeFolder.exists()) {
|
||||
String includes = PdeCompiler.includeFolder(codeFolder);
|
||||
PdeCompiler.magicExports(includes, zos);
|
||||
}
|
||||
|
||||
// add standard .class files to the jar
|
||||
// these are the bagel classes found in export
|
||||
// they are a jdk11-only version of bagel
|
||||
String exportDir = ("lib" + File.separator +
|
||||
"export" + File.separator);
|
||||
String bagelClasses[] = new File(exportDir).list();
|
||||
|
||||
for (int i = 0; i < bagelClasses.length; i++) {
|
||||
if (!bagelClasses[i].endsWith(".class")) continue;
|
||||
entry = new ZipEntry(bagelClasses[i]);
|
||||
zos.putNextEntry(entry);
|
||||
zos.write(PdeBase.grabFile(new File(exportDir + bagelClasses[i])));
|
||||
zos.closeEntry();
|
||||
}
|
||||
|
||||
// files to include from data directory
|
||||
if ((dataDir != null) && (dataDir.exists())) {
|
||||
String datafiles[] = dataDir.list();
|
||||
for (int i = 0; i < datafiles.length; i++) {
|
||||
// don't export hidden files, this handles, . .. .DS_Store
|
||||
if (datafiles[i].charAt(0) == '.') continue;
|
||||
//if (datafiles[i].equals(".") || datafiles[i].equals("..")) {
|
||||
//continue;
|
||||
//}
|
||||
entry = new ZipEntry(datafiles[i]);
|
||||
zos.putNextEntry(entry);
|
||||
zos.write(PdeBase.grabFile(new File(dataDir, datafiles[i])));
|
||||
zos.closeEntry();
|
||||
}
|
||||
}
|
||||
|
||||
// add the project's .class to the jar
|
||||
// actually, these should grab everything from the build directory
|
||||
// since there may be some inner classes
|
||||
// (add any .class files from the applet dir, then delete them)
|
||||
String classfiles[] = appletDir.list();
|
||||
for (int i = 0; i < classfiles.length; i++) {
|
||||
if (classfiles[i].endsWith(".class")) {
|
||||
entry = new ZipEntry(classfiles[i]);
|
||||
zos.putNextEntry(entry);
|
||||
zos.write(PdeBase.grabFile(new File(appletDir, classfiles[i])));
|
||||
zos.closeEntry();
|
||||
}
|
||||
}
|
||||
|
||||
// remove the .class files from the applet folder. if they're not
|
||||
// removed, the msjvm will complain about an illegal access error,
|
||||
// since the classes are outside the jar file.
|
||||
for (int i = 0; i < classfiles.length; i++) {
|
||||
if (classfiles[i].endsWith(".class")) {
|
||||
File deadguy = new File(appletDir, classfiles[i]);
|
||||
if (!deadguy.delete()) {
|
||||
System.err.println(classfiles[i] +
|
||||
" could not be deleted from the applet folder.");
|
||||
System.err.println("You'll need to remove it by hand.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// close up the jar file
|
||||
zos.flush();
|
||||
zos.close();
|
||||
|
||||
// make a copy of the .pde file to post on the web
|
||||
FileOutputStream sketchOutput =
|
||||
new FileOutputStream(new File(appletDir, exportSketchName + ".pde"));
|
||||
PrintWriter sketchWriter =
|
||||
new PrintWriter(new OutputStreamWriter(sketchOutput));
|
||||
sketchWriter.print(program);
|
||||
sketchWriter.flush();
|
||||
sketchWriter.close();
|
||||
|
||||
message("Done exporting.");
|
||||
PdeBase.openFolder(appletDir);
|
||||
|
||||
} catch (Exception e) {
|
||||
message("Error during export.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
buttons.clear();
|
||||
}
|
||||
|
||||
|
||||
public void doPrint() {
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user