New revisions and file renaming to match processing-0085 beta

This commit is contained in:
francisli
2005-04-20 06:53:07 +00:00
parent b066979a68
commit 02aec333cd
7 changed files with 1019 additions and 760 deletions

View File

@@ -1,12 +1,11 @@
/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
PdeCompiler - default compiler class that connects to jikes
Compiler - default compiler class that connects to jikes
Part of the Processing project - http://processing.org
Copyright (c) 2001-03
Ben Fry, Massachusetts Institute of Technology and
Casey Reas, Interaction Design Institute Ivrea
Copyright (c) 2004-05 Ben Fry and Casey Reas
Copyright (c) 2001-04 Massachusetts Institute of Technology
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -18,11 +17,13 @@
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package processing.app;
import processing.core.*;
import java.io.*;
@@ -30,24 +31,24 @@ import java.util.*;
import java.util.zip.*;
import javax.swing.*;
public class PdeCompiler implements PdeMessageConsumer {
static final String BUGS_URL =
public class Compiler implements MessageConsumer {
static final String BUGS_URL =
"http://processing.org/bugs/";
static final String SUPER_BADNESS =
static final String SUPER_BADNESS =
"Compiler error, please submit this code to " + BUGS_URL;
PdeSketch sketch;
Sketch sketch;
String buildPath;
//String buildPath;
//String className;
//File includeFolder;
PdeException exception;
//PdeEditor editor;
RunnerException exception;
//Editor editor;
/*
public PdeCompiler(String buildPath, String className,
File includeFolder, PdeEditor editor) {
public Compiler(String buildPath, String className,
File includeFolder, Editor editor) {
this.buildPath = buildPath;
this.includeFolder = includeFolder;
this.className = className;
@@ -58,29 +59,29 @@ public class PdeCompiler implements PdeMessageConsumer {
public boolean compile(PrintStream leechErr) {
*/
public PdeCompiler() { } // consider this a warning, you werkin soon.
public Compiler() { } // consider this a warning, you werkin soon.
public boolean compile(PdeSketch sketch, String buildPath, String bootClassPath)
throws PdeException {
public boolean compile(Sketch sketch, String buildPath, String bootClassPath)
throws RunnerException {
this.sketch = sketch;
this.buildPath = buildPath;
// the pms object isn't used for anything but storage
PdeMessageStream pms = new PdeMessageStream(this);
MessageStream pms = new MessageStream(this);
String baseCommand[] = new String[] {
// user.dir is folder containing P5 (and therefore jikes)
// macosx needs the extra path info. linux doesn't like it, though
// windows doesn't seem to care. write once, headache anywhere.
((PdeBase.platform != PdeBase.MACOSX) ? "jikes" :
((!Base.isMacOS()) ? "jikes" :
System.getProperty("user.dir") + File.separator + "jikes"),
// this doesn't help much.. also java 1.4 seems to not support
// -source 1.1 for javac, and jikes seems to also have dropped it.
// for versions of jikes that don't complain, "final int" inside
// a function doesn't throw an error, so it could just be a
// a function doesn't throw an error, so it could just be a
// ms jvm error that this sort of thing doesn't work. blech.
//"-source",
//"1.1",
@@ -88,7 +89,7 @@ public class PdeCompiler implements PdeMessageConsumer {
// necessary to make output classes compatible with 1.1
// i.e. so that exported applets can work with ms jvm on the web
"-target",
PdePreferences.get("preproc.jdk_version"), //"1.1",
Preferences.get("preproc.jdk_version"), //"1.1",
// let the incompatability headache begin
// used when run without a vm ("expert" mode)
@@ -120,39 +121,38 @@ public class PdeCompiler implements PdeMessageConsumer {
System.arraycopy(baseCommand, 0, command, 0, baseCommand.length);
// append each of the files to the command string
for (int i = 0; i < preprocCount; i++) {
command[baseCommand.length + i] =
command[baseCommand.length + i] =
buildPath + File.separator + preprocNames[i];
}
//PApplet.printarr(command);
/*
String command[] = new String[baseCommand.length + sketch.codeCount];
System.arraycopy(baseCommand, 0, command, 0, baseCommand.length);
// append each of the files to the command string
for (int i = 0; i < sketch.codeCount; i++) {
command[baseCommand.length + i] =
command[baseCommand.length + i] =
buildPath + File.separator + sketch.code[i].preprocName;
}
*/
/*
for (int i = 0; i < command.length; i++) {
System.out.println("cmd " + i + ": " + command[i]);
}
*/
//for (int i = 0; i < command.length; i++) {
//System.out.println("cmd " + i + " " + command[i]);
//}
firstErrorFound = false; // haven't found any errors yet
secondErrorFound = false;
int result = 0; // pre-initialized to quiet a bogus warning from jikes
try {
// execute the compiler, and create threads to deal
try {
// execute the compiler, and create threads to deal
// with the input and error streams
//
Process process = Runtime.getRuntime().exec(command);
PdeMessageSiphon errSiphon = new PdeMessageSiphon(process.getErrorStream(), this);
PdeMessageSiphon inSiphon = new PdeMessageSiphon(process.getInputStream(), this);
// wait for the process to finish. if interrupted
new MessageSiphon(process.getInputStream(), this);
new MessageSiphon(process.getErrorStream(), this);
// wait for the process to finish. if interrupted
// before waitFor returns, continue waiting
//
boolean compiling = true;
@@ -161,15 +161,14 @@ public class PdeCompiler implements PdeMessageConsumer {
result = process.waitFor();
//System.out.println("result is " + result);
compiling = false;
} catch (InterruptedException ignored) {
}
} catch (InterruptedException ignored) { }
}
} catch (Exception e) {
String msg = e.getMessage();
if ((msg != null) && (msg.indexOf("jikes: not found") != -1)) {
//System.err.println("jikes is missing");
PdeBase.showWarning("Compiler error",
Base.showWarning("Compiler error",
"Could not find the compiler.\n" +
"jikes is missing from your PATH,\n" +
"see readme.txt for help.", null);
@@ -182,21 +181,21 @@ public class PdeCompiler implements PdeMessageConsumer {
}
// an error was queued up by message(), barf this back to build()
// which will barf it back to PdeEditor. if you're having trouble
// which will barf it back to Editor. if you're having trouble
// discerning the imagery, consider how cows regurgitate their food
// to digest it, and the fact that they have five stomaches.
//
//System.out.println("throwing up " + exception);
if (exception != null) throw exception;
if (exception != null) throw exception;
// if the result isn't a known, expected value it means that something
// is fairly wrong, one possibility is that jikes has crashed.
//
if (result != 0 && result != 1 ) {
//exception = new PdeException(SUPER_BADNESS);
//exception = new RunnerException(SUPER_BADNESS);
//editor.error(exception); // this will instead be thrown
PdeBase.openURL(BUGS_URL);
throw new PdeException(SUPER_BADNESS);
Base.openURL(BUGS_URL);
throw new RunnerException(SUPER_BADNESS);
}
// success would mean that 'result' is set to zero
@@ -209,21 +208,21 @@ public class PdeCompiler implements PdeMessageConsumer {
boolean secondErrorFound;
/**
* Part of the PdeMessageConsumer interface, this is called
* whenever a piece (usually a line) of error message is spewed
* Part of the MessageConsumer interface, this is called
* whenever a piece (usually a line) of error message is spewed
* out from the compiler. The errors are parsed for their contents
* and line number, which is then reported back to PdeEditor.
* and line number, which is then reported back to Editor.
*/
public void message(String s) {
// This receives messages as full lines, so a newline needs
// This receives messages as full lines, so a newline needs
// to be added as they're printed to the console.
//// MOBILE: moving to end due to wierd jikes output
//System.err.println(s);
//System.err.println(s);
// ignore cautions
if (s.indexOf("Caution") != -1) return;
// jikes always uses a forward slash character as its separator,
// jikes always uses a forward slash character as its separator,
// so replace any platform-specific separator characters before
// attemping to compare
//
@@ -254,7 +253,7 @@ public class PdeCompiler implements PdeMessageConsumer {
// skip past the path and parse the int after the first colon
//
String s1 = s.substring(partialStartIndex +
String s1 = s.substring(partialStartIndex +
partialTempPath.length() + 1);
int colon = s1.indexOf(':');
int lineNumber = Integer.parseInt(s1.substring(0, colon));
@@ -262,7 +261,7 @@ public class PdeCompiler implements PdeMessageConsumer {
if (fileIndex == 0) { // main class, figure out which tab
for (int i = 1; i < sketch.codeCount; i++) {
if (sketch.code[i].flavor == PdeSketch.PDE) {
if (sketch.code[i].flavor == Sketch.PDE) {
if (sketch.code[i].lineOffset < lineNumber) {
fileIndex = i;
//System.out.println("i'm thinkin file " + i);
@@ -287,20 +286,19 @@ public class PdeCompiler implements PdeMessageConsumer {
}
// if executing at this point, this is *at least* the first error
/// MOBILE: moving to end due to wierd jikes output
firstErrorFound = true;
//err += "error:".length();
String description = s1.substring(err + "Error:".length());
description = description.trim();
String hasLoop = "The method \"void loop();\" with default access";
if (description.indexOf(hasLoop) != -1) {
description =
description =
"Rename loop() to draw() in Processing 0070 and higher";
}
String constructorProblem =
String constructorProblem =
"No applicable overload was found for a constructor of type";
if (description.indexOf(constructorProblem) != -1) {
//"simong.particles.ParticleSystem". Perhaps you wanted the overloaded version "ParticleSystem();" instead?
@@ -319,23 +317,23 @@ public class PdeCompiler implements PdeMessageConsumer {
if (description.indexOf(classpathProblem) != -1) {
if (description.indexOf("quicktime/std") != -1) {
// special case for the quicktime libraries
description =
description =
"To run sketches that use the Processing video library, " +
"you must first install QuickTime for Java.";
} else {
int nextSentence = description.indexOf(". Package") + 2;
description =
description.substring(nextSentence, description.indexOf(':')) +
description =
description.substring(nextSentence, description.indexOf(':')) +
" the code folder or in any libraries.";
}
}
}
//// MOBILE: ignore wierd jikes errors that get output even though it compiles fine
if (description.indexOf("Type java.io.Serializable was not found.") != -1) {
if (description.indexOf("Type \"java.io.Serializable\" was not found.") != -1) {
return;
}
if (description.indexOf("Type java.lang.Cloneable was not found.") != -1) {
if (description.indexOf("Type \"java.lang.Cloneable\" was not found.") != -1) {
return;
}
if (description.indexOf("A non-standard version of the type \"java.lang.StringBuffer\" was found.") != -1) {
@@ -343,12 +341,11 @@ public class PdeCompiler implements PdeMessageConsumer {
}
//// MOBILE: moving to end due to wierd jikes output
firstErrorFound = true;
System.err.println(s);
//System.out.println("description = " + description);
//System.out.println("creating exception " + exception);
exception = new PdeException(description, fileIndex, lineNumber-1, -1);
exception = new RunnerException(description, fileIndex, lineNumber-1, -1);
// NOTE!! major change here, this exception will be queued
// here to be thrown by the compile() function
@@ -362,9 +359,9 @@ public class PdeCompiler implements PdeMessageConsumer {
// this isn't the start of an error line, so don't attempt to parse
// a line number out of it.
// if the second error hasn't been discovered yet, these lines
// are probably associated with the first error message,
// which is already in the status bar, and are likely to be
// if the second error hasn't been discovered yet, these lines
// are probably associated with the first error message,
// which is already in the status bar, and are likely to be
// of interest to the user, so spit them to the console.
//
if (!secondErrorFound) {
@@ -379,8 +376,8 @@ public class PdeCompiler implements PdeMessageConsumer {
static public String calcBootClassPath() {
if (bootClassPath == null) {
String additional = "";
if (PdeBase.platform == PdeBase.MACOSX) {
additional =
if (Base.isMacOS()) {
additional =
contentsToClassPath(new File("/System/Library/Java/Extensions/"));
}
bootClassPath = System.getProperty("sun.boot.class.path") + additional;
@@ -389,16 +386,16 @@ public class PdeCompiler implements PdeMessageConsumer {
}
///
///
/**
* Return the path for a folder, with appended paths to
* Return the path for a folder, with appended paths to
* any .jar or .zip files inside that folder.
* This will prepend a colon (or whatever the path separator is)
* so that it can be directly appended to another path string.
*
* This will always add the root folder as well, and doesn't bother
* This will always add the root folder as well, and doesn't bother
* checking to see if there are any .class files in the folder or
* within a subfolder.
*/
@@ -428,7 +425,7 @@ public class PdeCompiler implements PdeMessageConsumer {
abuffer.append(list[i]);
}
}
} catch (IOException e) {
} catch (IOException e) {
e.printStackTrace(); // this would be odd
}
//System.out.println("included path is " + abuffer.toString());
@@ -447,14 +444,14 @@ public class PdeCompiler implements PdeMessageConsumer {
*/
static public String[] packageListFromClassPath(String path) {
Hashtable table = new Hashtable();
String pieces[] =
String pieces[] =
PApplet.split(path, File.pathSeparatorChar);
for (int i = 0; i < pieces.length; i++) {
//System.out.println("checking piece '" + pieces[i] + "'");
if (pieces[i].length() == 0) continue;
if (pieces[i].toLowerCase().endsWith(".jar") ||
if (pieces[i].toLowerCase().endsWith(".jar") ||
pieces[i].toLowerCase().endsWith(".zip")) {
packageListFromZip(pieces[i], table);
@@ -462,8 +459,8 @@ public class PdeCompiler implements PdeMessageConsumer {
File dir = new File(pieces[i]);
if (dir.exists() && dir.isDirectory()) {
packageListFromFolder(dir, null, table);
//importCount = magicImportsRecursive(dir, null,
// table);
//importCount = magicImportsRecursive(dir, null,
// table);
//imports, importCount);
}
}
@@ -476,6 +473,7 @@ public class PdeCompiler implements PdeMessageConsumer {
output[index++] = ((String) e.nextElement()).replace('/', '.');
}
//System.arraycopy(imports, 0, output, 0, importCount);
//PApplet.printarr(output);
return output;
}
@@ -492,7 +490,7 @@ public class PdeCompiler implements PdeMessageConsumer {
if (name.endsWith(".class")) {
int slash = name.lastIndexOf('/');
if (slash == -1) continue;
if (slash == -1) continue;
String pname = name.substring(0, slash);
if (table.get(pname) == null) {
@@ -510,13 +508,13 @@ public class PdeCompiler implements PdeMessageConsumer {
/**
* Make list of package names by traversing a directory hierarchy.
* Each time a class is found in a folder, add its containing set
* of folders to the package list. If another folder is found,
* Each time a class is found in a folder, add its containing set
* of folders to the package list. If another folder is found,
* walk down into that folder and continue.
*/
static private void packageListFromFolder(File dir, String sofar,
static private void packageListFromFolder(File dir, String sofar,
Hashtable table) {
//String imports[],
//String imports[],
//int importCount) {
//System.err.println("checking dir '" + dir + "'");
boolean foundClass = false;
@@ -527,12 +525,12 @@ public class PdeCompiler implements PdeMessageConsumer {
File sub = new File(dir, files[i]);
if (sub.isDirectory()) {
String nowfar =
String nowfar =
(sofar == null) ? files[i] : (sofar + "." + files[i]);
packageListFromFolder(sub, nowfar, table);
//System.out.println(nowfar);
//imports[importCount++] = nowfar;
//importCount = magicImportsRecursive(sub, nowfar,
//importCount = magicImportsRecursive(sub, nowfar,
// imports, importCount);
} else if (!foundClass) { // if no classes found in this folder yet
if (files[i].endsWith(".class")) {
@@ -546,9 +544,9 @@ public class PdeCompiler implements PdeMessageConsumer {
}
/*
static public int magicImportsRecursive(File dir, String sofar,
static public int magicImportsRecursive(File dir, String sofar,
Hashtable table) {
//String imports[],
//String imports[],
//int importCount) {
System.err.println("checking dir '" + dir + "'");
String files[] = dir.list();
@@ -557,12 +555,12 @@ public class PdeCompiler implements PdeMessageConsumer {
File sub = new File(dir, files[i]);
if (sub.isDirectory()) {
String nowfar = (sofar == null) ?
String nowfar = (sofar == null) ?
files[i] : (sofar + "." + files[i]);
//System.out.println(nowfar);
imports[importCount++] = nowfar;
importCount = magicImportsRecursive(sub, nowfar,
importCount = magicImportsRecursive(sub, nowfar,
imports, importCount);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,13 +1,10 @@
/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
PdeEditorButtons - run/stop/etc buttons for the ide
Part of the Processing project - http://processing.org
Copyright (c) 2004 Ben Fry and the Processing project.
The original rendition of this code was written by Ben Fry and
Copyright (c) 2001-03 Massachusetts Institute of Technology
Copyright (c) 2004-05 Ben Fry and Casey Reas
Copyright (c) 2001-04 Massachusetts Institute of Technology
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -19,11 +16,13 @@
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package processing.app;
import java.awt.*;
import java.awt.event.*;
import java.awt.font.*;
@@ -32,30 +31,33 @@ import javax.swing.*;
import javax.swing.event.*;
public class PdeEditorButtons extends JComponent implements MouseInputListener {
/**
* run/stop/etc buttons for the ide
*/
public class EditorButtons extends JComponent implements MouseInputListener {
static final String title[] = {
"", "run", "stop", "new", "open", "save", "export"
"Run", "Stop", "New", "Open", "Save", "Export"
};
static final int BUTTON_COUNT = title.length;
static final int BUTTON_WIDTH = PdePreferences.GRID_SIZE;
static final int BUTTON_HEIGHT = PdePreferences.GRID_SIZE;
static final int BUTTON_WIDTH = 27; //Preferences.GRID_SIZE;
static final int BUTTON_HEIGHT = 32; //Preferences.GRID_SIZE;
static final int BUTTON_GAP = 15; //BUTTON_WIDTH / 2;
static final int NOTHING = 0;
static final int RUN = 1;
static final int STOP = 2;
static final int RUN = 0;
static final int STOP = 1;
static final int NEW = 3;
static final int OPEN = 4;
static final int SAVE = 5;
static final int EXPORT = 6;
static final int NEW = 2;
static final int OPEN = 3;
static final int SAVE = 4;
static final int EXPORT = 5;
static final int INACTIVE = 0;
static final int ROLLOVER = 1;
static final int ACTIVE = 2;
PdeEditor editor;
Editor editor;
boolean disableRun;
//Label status;
@@ -78,23 +80,23 @@ public class PdeEditorButtons extends JComponent implements MouseInputListener {
Image stateImage[];
int which[]; // mapping indices to implementation
int x1, x2;
int y1[], y2[];
int x1[], x2[];
int y1, y2;
String status;
Font statusFont;
Color statusColor;
int statusY;
//int statusY;
public PdeEditorButtons(PdeEditor editor) {
public EditorButtons(Editor editor) {
this.editor = editor;
buttons = PdeBase.getImage("buttons.gif", this);
buttons = Base.getImage("buttons.gif", this);
buttonCount = 0;
which = new int[BUTTON_COUNT];
which[buttonCount++] = NOTHING;
//which[buttonCount++] = NOTHING;
which[buttonCount++] = RUN;
which[buttonCount++] = STOP;
which[buttonCount++] = NEW;
@@ -104,61 +106,40 @@ public class PdeEditorButtons extends JComponent implements MouseInputListener {
currentRollover = -1;
bgcolor = PdePreferences.getColor("buttons.bgcolor");
bgcolor = Preferences.getColor("buttons.bgcolor");
status = "";
//setLayout(null);
//status = new JLabel();
statusFont = PdePreferences.getFont("buttons.status.font");
statusColor = PdePreferences.getColor("buttons.status.color");
//add(status);
statusFont = Preferences.getFont("buttons.status.font");
statusColor = Preferences.getColor("buttons.status.color");
//status.setBounds(-5, BUTTON_COUNT * BUTTON_HEIGHT,
// BUTTON_WIDTH + 15, BUTTON_HEIGHT);
//status.setAlignment(Label.CENTER);
statusY = (BUTTON_COUNT + 1) * BUTTON_HEIGHT;
//statusY = (BUTTON_COUNT + 1) * BUTTON_HEIGHT;
addMouseListener(this);
addMouseMotionListener(this);
}
/*
public void update() {
paint(this.getGraphics());
}
public void update(Graphics g) {
paint(g);
}
*/
//public void paintComponent(Graphics g) {
//super.paintComponent(g);
//}
public void paintComponent(Graphics screen) {
if (inactive == null) {
inactive = new Image[BUTTON_COUNT];
rollover = new Image[BUTTON_COUNT];
active = new Image[BUTTON_COUNT];
//state = new int[BUTTON_COUNT];
int IMAGE_SIZE = 33;
for (int i = 0; i < BUTTON_COUNT; i++) {
inactive[i] = createImage(BUTTON_WIDTH, BUTTON_HEIGHT);
Graphics g = inactive[i].getGraphics();
g.drawImage(buttons, -(i*BUTTON_WIDTH), -2*BUTTON_HEIGHT, null);
g.drawImage(buttons, -(i*IMAGE_SIZE) - 3, -2*IMAGE_SIZE, null);
rollover[i] = createImage(BUTTON_WIDTH, BUTTON_HEIGHT);
g = rollover[i].getGraphics();
g.drawImage(buttons, -(i*BUTTON_WIDTH), -1*BUTTON_HEIGHT, null);
g.drawImage(buttons, -(i*IMAGE_SIZE) - 3, -1*IMAGE_SIZE, null);
active[i] = createImage(BUTTON_WIDTH, BUTTON_HEIGHT);
g = active[i].getGraphics();
g.drawImage(buttons, -(i*BUTTON_WIDTH), -0*BUTTON_HEIGHT, null);
g.drawImage(buttons, -(i*IMAGE_SIZE) - 3, -0*IMAGE_SIZE, null);
}
state = new int[buttonCount];
@@ -168,23 +149,24 @@ public class PdeEditorButtons extends JComponent implements MouseInputListener {
}
}
Dimension size = size();
if ((offscreen == null) ||
if ((offscreen == null) ||
(size.width != width) || (size.height != height)) {
offscreen = createImage(size.width, size.height);
width = size.width;
height = size.height;
x1 = 0;
x2 = BUTTON_WIDTH;
y1 = 0;
y2 = BUTTON_HEIGHT;
y1 = new int[buttonCount];
y2 = new int[buttonCount];
x1 = new int[buttonCount];
x2 = new int[buttonCount];
int offsetY = 0;
int offsetX = 3;
for (int i = 0; i < buttonCount; i++) {
y1[i] = offsetY;
y2[i] = offsetY + BUTTON_HEIGHT;
offsetY = y2[i];
x1[i] = offsetX;
if (i == 2) x1[i] += BUTTON_GAP;
x2[i] = x1[i] + BUTTON_WIDTH;
offsetX = x2[i];
}
}
Graphics g = offscreen.getGraphics();
@@ -192,31 +174,31 @@ public class PdeEditorButtons extends JComponent implements MouseInputListener {
g.fillRect(0, 0, width, height);
for (int i = 0; i < buttonCount; i++) {
//g.drawImage(stateImage[i], x1[i], y1, null);
g.drawImage(stateImage[i], x1, y1[i], null);
g.drawImage(stateImage[i], x1[i], y1, null);
}
g.setColor(statusColor);
g.setFont(statusFont);
// if i ever find the guy who wrote the java2d api,
// i will hurt him. or just laugh in his face. or pity him.
/*
// if i ever find the guy who wrote the java2d api, i will hurt him.
Graphics2D g2 = (Graphics2D) g;
FontRenderContext frc = g2.getFontRenderContext();
float statusW = (float) statusFont.getStringBounds(status, frc).getWidth();
float statusX = (getSize().width - statusW) / 2;
//int statusWidth = g.getFontMetrics().stringWidth(status);
//int statusX = (getSize().width - statusWidth) / 2;
g2.drawString(status, statusX, statusY);
*/
//int statusY = (BUTTON_HEIGHT + statusFont.getAscent()) / 2;
int statusY = (BUTTON_HEIGHT + g.getFontMetrics().getAscent()) / 2;
g.drawString(status, buttonCount * BUTTON_WIDTH + 2 * BUTTON_GAP, statusY);
screen.drawImage(offscreen, 0, 0, null);
}
public void mouseMoved(MouseEvent e) {
// mouse events before paint();
if (state == null) return;
if (state == null) return;
if (state[OPEN] != INACTIVE) {
// avoid flicker, since there will probably be an update event
@@ -233,8 +215,8 @@ public class PdeEditorButtons extends JComponent implements MouseInputListener {
public void handleMouse(int x, int y) {
if (currentRollover != -1) {
if ((y > y1[currentRollover]) && (x > x1) &&
(y < y2[currentRollover]) && (x < x2)) {
if ((x > x1[currentRollover]) && (y > y1) &&
(x < x2[currentRollover]) && (y < y2)) {
return;
} else {
@@ -256,15 +238,14 @@ public class PdeEditorButtons extends JComponent implements MouseInputListener {
private int findSelection(int x, int y) {
// if app loads slowly and cursor is near the buttons
// if app loads slowly and cursor is near the buttons
// when it comes up, the app may not have time to load
if ((y1 == null) || (y2 == null)) return -1;
if ((x1 == null) || (x2 == null)) return -1;
for (int i = 0; i < buttonCount; i++) {
if ((x > x1) && (y > y1[i]) &&
(x < x2) && (y < y2[i])) {
//if ((x > x1[i]) && (y > y1) &&
//(x < x2[i]) && (y < y2)) {
if ((y > y1) && (x > x1[i]) &&
(y < y2) && (x < x2[i])) {
//System.out.println("sel is " + i);
return i;
}
}
@@ -277,13 +258,13 @@ public class PdeEditorButtons extends JComponent implements MouseInputListener {
state[slot] = newState;
switch (newState) {
case INACTIVE:
stateImage[slot] = inactive[which[slot]];
stateImage[slot] = inactive[which[slot]];
break;
case ACTIVE:
stateImage[slot] = active[which[slot]];
case ACTIVE:
stateImage[slot] = active[which[slot]];
break;
case ROLLOVER:
stateImage[slot] = rollover[which[slot]];
case ROLLOVER:
stateImage[slot] = rollover[which[slot]];
message(title[which[slot]]);
break;
}
@@ -301,13 +282,7 @@ public class PdeEditorButtons extends JComponent implements MouseInputListener {
if (state[OPEN] != INACTIVE) {
setState(OPEN, INACTIVE, true);
}
// kludge
//for (int i = 0; i < BUTTON_COUNT; i++) {
//messageClear(title[i]);
//}
status = "";
//mouseMove(e);
handleMouse(e.getX(), e.getY());
}
@@ -317,7 +292,7 @@ public class PdeEditorButtons extends JComponent implements MouseInputListener {
public void mousePressed(MouseEvent e) {
int x = e.getX();
int y = e.getY();
int sel = findSelection(x, y);
///if (sel == -1) return false;
if (sel == -1) return;
@@ -344,16 +319,16 @@ public class PdeEditorButtons extends JComponent implements MouseInputListener {
public void mouseReleased(MouseEvent e) {
switch (currentSelection) {
case RUN:
case RUN:
if (!disableRun) {
editor.handleRunEmulator();//(e.isShiftDown());
editor.handleRunEmulator();//(e.isShiftDown());
}
break;
case STOP:
case STOP:
if (!disableRun) {
setState(RUN, INACTIVE, true);
editor.handleStop();
setState(RUN, INACTIVE, true);
editor.handleStop();
}
break;
@@ -405,13 +380,25 @@ public class PdeEditorButtons extends JComponent implements MouseInputListener {
status = msg;
}
public void messageClear(String msg) {
//if (status.getText().equals(msg + " ")) status.setText(PdeEditor.EMPTY);
//if (status.getText().equals(msg + " ")) status.setText(Editor.EMPTY);
if (status.equals(msg)) status = "";
}
public Dimension getPreferredSize() {
return new Dimension(BUTTON_WIDTH, (BUTTON_COUNT + 1)*BUTTON_HEIGHT);
return new Dimension((BUTTON_COUNT + 1)*BUTTON_WIDTH, BUTTON_HEIGHT);
//return new Dimension(BUTTON_WIDTH, (BUTTON_COUNT + 1)*BUTTON_HEIGHT);
}
public Dimension getMinimumSize() {
return getPreferredSize();
}
public Dimension getMaximumSize() {
return new Dimension(3000, BUTTON_HEIGHT);
}
}

View File

@@ -1,3 +1,5 @@
package processing.app;
import java.awt.Point;
import java.io.*;
@@ -5,16 +7,16 @@ import java.io.*;
*
* @author Francis Li
*/
public class PdeEmulator extends PdeRuntime {
public class Emulator extends Runner {
/** Creates a new instance of PdeEmulator */
public PdeEmulator(PdeSketch sketch, PdeEditor editor) {
/** Creates a new instance of Emulator */
public Emulator(Sketch sketch, Editor editor) {
super(sketch, editor);
}
public void start(Point windowLocation) throws PdeException {
public void start(Point windowLocation) throws RunnerException {
try{
String wtkBinPath = PdePreferences.get("wtk.path") + File.separator + "bin";
String wtkBinPath = Preferences.get("wtk.path") + File.separator + "bin";
StringBuffer command = new StringBuffer();
command.append(wtkBinPath);
@@ -29,7 +31,7 @@ public class PdeEmulator extends PdeRuntime {
process = Runtime.getRuntime().exec(command.toString(), null, new File(wtkBinPath));
processInput = new SystemOutSiphon(process.getInputStream());
processError = new PdeMessageSiphon(process.getErrorStream(), this);
processError = new MessageSiphon(process.getErrorStream(), this);
processOutput = process.getOutputStream();
} catch (Exception e) {
e.printStackTrace();

View File

@@ -1,12 +1,14 @@
package processing.app;
import java.io.*;
public class PdePreverifier implements PdeMessageConsumer {
public class Preverifier implements MessageConsumer {
public PdePreverifier() {
public Preverifier() {
}
public boolean preverify(File source, File output) {
String wtkPath = PdePreferences.get("wtk.path");
String wtkPath = Preferences.get("wtk.path");
String wtkBinPath = wtkPath + File.separator + "bin" + File.separator;
String wtkLibPath = wtkPath + File.separator + "lib" + File.separator;
@@ -32,8 +34,8 @@ public class PdePreverifier implements PdeMessageConsumer {
while (running) {
try {
result = p.waitFor();
new PdeMessageSiphon(p.getInputStream(), this);
new PdeMessageSiphon(p.getErrorStream(), this);
new MessageSiphon(p.getInputStream(), this);
new MessageSiphon(p.getErrorStream(), this);
running = false;
} catch (InterruptedException ie) {

File diff suppressed because it is too large Load Diff

View File

@@ -4,10 +4,10 @@
PdePreprocessor - wrapper for default ANTLR-generated parser
Part of the Processing project - http://processing.org
Except where noted, code is written by Ben Fry and
Copyright (c) 2001-03 Massachusetts Institute of Technology
Copyright (c) 2004-05 Ben Fry and Casey Reas
Copyright (c) 2001-04 Massachusetts Institute of Technology
ANTLR-generated parser and several supporting classes written
ANTLR-generated parser and several supporting classes written
by Dan Mosedale via funding from the Interaction Institute IVREA.
This program is free software; you can redistribute it and/or modify
@@ -20,11 +20,14 @@
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package processing.app.preproc;
import processing.app.*;
import processing.core.*;
import java.io.*;
@@ -48,17 +51,17 @@ public class PdePreprocessor {
// might be at the end instead of .* whcih would make trouble
// other classes using this can lop of the . and anything after
// it to produce a package name consistently.
String extraImports[];
public String extraImports[];
// imports just from the code folder, treated differently
// than the others, since the imports are auto-generated.
String codeFolderImports[];
static final int STATIC = 0; // formerly BEGINNER
static final int ACTIVE = 1; // formerly INTERMEDIATE
static final int JAVA = 2; // formerly ADVANCED
public String codeFolderImports[];
static public final int STATIC = 0; // formerly BEGINNER
static public final int ACTIVE = 1; // formerly INTERMEDIATE
static public final int JAVA = 2; // formerly ADVANCED
// static to make it easier for the antlr preproc to get at it
static int programType = -1;
static public int programType = -1;
Reader programReader;
String buildPath;
@@ -82,13 +85,13 @@ public class PdePreprocessor {
* These may change in-between (if the prefs panel adds this option)
* so grab them here on construction.
*/
public PdePreprocessor() {
defaultImports[JDK11] =
PApplet.split(PdePreferences.get("preproc.imports.jdk11"), ',');
defaultImports[JDK13] =
PApplet.split(PdePreferences.get("preproc.imports.jdk13"), ',');
defaultImports[JDK14] =
PApplet.split(PdePreferences.get("preproc.imports.jdk14"), ',');
public PdePreprocessor() {
defaultImports[JDK11] =
PApplet.split(Preferences.get("preproc.imports.jdk11"), ',');
defaultImports[JDK13] =
PApplet.split(Preferences.get("preproc.imports.jdk13"), ',');
defaultImports[JDK14] =
PApplet.split(Preferences.get("preproc.imports.jdk14"), ',');
}
@@ -102,9 +105,10 @@ public class PdePreprocessor {
* preprocesses a pde file and write out a java file
* @return the classname of the exported Java
*/
//public String write(String program, String buildPath, String name,
//public String write(String program, String buildPath, String name,
// String extraImports[]) throws java.lang.Exception {
public String write(String program, String buildPath, String name, String codeFolderPackages[])
public String write(String program, String buildPath,
String name, String codeFolderPackages[])
throws java.lang.Exception {
// if the program ends with no CR or LF an OutOfMemoryError will happen.
// not gonna track down the bug now, so here's a hack for it:
@@ -113,7 +117,7 @@ public class PdePreprocessor {
program += "\n";
}
if (PdePreferences.getBoolean("preproc.substitute_unicode")) {
if (Preferences.getBoolean("preproc.substitute_unicode")) {
// check for non-ascii chars (these will be/must be in unicode format)
char p[] = program.toCharArray();
int unicodeCount = 0;
@@ -122,7 +126,7 @@ public class PdePreprocessor {
}
// if non-ascii chars are in there, convert to unicode escapes
if (unicodeCount != 0) {
// add unicodeCount * 5.. replacing each unicode char
// add unicodeCount * 5.. replacing each unicode char
// with six digit uXXXX sequence (xxxx is in hex)
// (except for nbsp chars which will be a replaced with a space)
int index = 0;
@@ -150,7 +154,7 @@ public class PdePreprocessor {
}
}
// if this guy has his own imports, need to remove them
// if this guy has his own imports, need to remove them
// just in case it's not an advanced mode sketch
PatternMatcher matcher = new Perl5Matcher();
PatternCompiler compiler = new Perl5Compiler();
@@ -178,7 +182,7 @@ public class PdePreprocessor {
int len = piece.length();
//imports.add(piece);
imports.add(piece2);
imports.add(piece2);
int idx = program.indexOf(piece);
// just remove altogether?
program = program.substring(0, idx) + program.substring(idx + len);
@@ -187,10 +191,17 @@ public class PdePreprocessor {
} while (true);
int importsCount = imports.size();
extraImports = new String[importsCount];
extraImports = new String[imports.size()];
imports.copyInto(extraImports);
// if using opengl, add it to the special imports
/*
if (Preferences.get("renderer").equals("opengl")) {
extraImports = new String[imports.size() + 1];
imports.copyInto(extraImports);
extraImports[extraImports.length - 1] = "processing.opengl.*";
}
*/
/*
if (codeFolderPackages != null) {
@@ -212,21 +223,19 @@ public class PdePreprocessor {
codeFolderImports = null;
}
//
// do this after the program gets re-combobulated
this.programReader = new StringReader(program);
this.buildPath = buildPath;
// create a lexer with the stream reader, and tell it to handle
// create a lexer with the stream reader, and tell it to handle
// hidden tokens (eg whitespace, comments) since we want to pass these
// through so that the line numbers when the compiler reports errors
// match those that will be highlighted in the PDE IDE
//
//
PdeLexer lexer = new PdeLexer(programReader);
lexer.setTokenObjectClass("antlr.CommonHiddenStreamToken");
// create the filter for hidden tokens and specify which tokens to
// create the filter for hidden tokens and specify which tokens to
// hide and which to copy to the hidden text
//
filter = new TokenStreamCopyingHiddenTokenFilter(lexer);
@@ -264,8 +273,10 @@ public class PdePreprocessor {
// unclear if this actually works, but it's worth a shot
//
((CommonAST)parserAST).setVerboseStringConversion(
true, parser.getTokenNames());
//((CommonAST)parserAST).setVerboseStringConversion(
// true, parser.getTokenNames());
// (made to use the static version because of jikes 1.22 warning)
CommonAST.setVerboseStringConversion(true, parser.getTokenNames());
// if this is an advanced program, the classname is already defined.
//
@@ -273,9 +284,9 @@ public class PdePreprocessor {
name = getFirstClassName(parserAST);
}
// if 'null' was passed in for the name, but this isn't
// if 'null' was passed in for the name, but this isn't
// a 'java' mode class, then there's a problem, so punt.
//
//
if (name == null) return null;
// output the code
@@ -296,7 +307,7 @@ public class PdePreprocessor {
// if desired, serialize the parse tree to an XML file. can
// be viewed usefully with Mozilla or IE
if (PdePreferences.getBoolean("preproc.output_parse_tree")) {
if (Preferences.getBoolean("preproc.output_parse_tree")) {
stream = new PrintStream(new FileOutputStream("parseTree.xml"));
stream.println("<?xml version=\"1.0\"?>");
@@ -316,7 +327,7 @@ public class PdePreprocessor {
/**
* 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 name Name of the class being created.
@@ -341,7 +352,7 @@ public class PdePreprocessor {
// emit standard imports (read from pde.properties)
// for each language level that's being used.
String jdkVersionStr = PdePreferences.get("preproc.jdk_version");
String jdkVersionStr = Preferences.get("preproc.jdk_version");
int jdkVersion = JDK11; // default
if (jdkVersionStr.equals("1.3")) { jdkVersion = JDK13; };
@@ -360,8 +371,12 @@ public class PdePreprocessor {
}
}
//boolean opengl = Preferences.get("renderer").equals("opengl");
//if (opengl) {
//out.println("import processing.opengl.*; ");
//}
if (programType < JAVA) {
// open the class definition
if (baseClass != null) {
out.print("public class " + className + " extends " + baseClass + "{");
} else {
@@ -381,7 +396,7 @@ public class PdePreprocessor {
/**
* Write any necessary closing text.
*
*
* @param out PrintStream to write it to.
*/
void writeFooter(PrintStream out) {