add library support now getting closer

This commit is contained in:
benfry
2004-09-05 22:26:05 +00:00
parent 8277f8f9ab
commit b2724cf9e4
6 changed files with 87 additions and 17 deletions

View File

@@ -581,9 +581,7 @@ implements MRJAboutHandler, MRJQuitHandler, MRJPrefsHandler
//
menu.add(sketchbook.getAddLibraryMenu());
item = new JMenuItem("Import...");
item = new JMenuItem("Add File...");
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
sketch.addFile();
@@ -591,6 +589,8 @@ implements MRJAboutHandler, MRJQuitHandler, MRJPrefsHandler
});
menu.add(item);
menu.add(sketchbook.getAddLibraryMenu());
item = new JMenuItem("Create font...");
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {

View File

@@ -28,10 +28,13 @@
import processing.core.*;
import java.io.*;
import antlr.*;
import antlr.collections.*;
import antlr.collections.impl.*;
import com.oroinc.text.regex.*;
public class PdePreprocessor {
@@ -77,8 +80,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,
String extraImports[]) throws java.lang.Exception {
//public String write(String program, String buildPath, String name,
// String extraImports[]) throws java.lang.Exception {
public String write(String program, String buildPath, String name)
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:
if ((program.length() > 0) &&
@@ -123,6 +128,45 @@ public class PdePreprocessor {
}
}
// 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();
//String mess = "^\\s*(import\\s*[\\w\\d_\\.]+\\s*\\;)";
//String mess = "^\\s*(import\\s*[\\w\\d\\_\\.]+\\s*\\;)";
String mess = "^\\s*(import\\s+\\S+\\s*;)";
java.util.Vector imports = new java.util.Vector();
Pattern pattern = null;
try {
pattern = compiler.compile(mess);
} catch (MalformedPatternException e) {
e.printStackTrace();
return null;
}
do {
PatternMatcherInput input = new PatternMatcherInput(program);
if (!matcher.contains(input, pattern)) break;
MatchResult result = matcher.getMatch();
String piece = result.group(1).toString();
int len = piece.length();
imports.add(piece);
int idx = program.indexOf(piece);
// just remove altogether?
program = program.substring(0, idx) + program.substring(idx + len);
System.out.println("removing " + piece);
} while (true);
String extraImports[] = new String[imports.size()];
imports.copyInto(extraImports);
//
// do this after the program gets re-combobulated
this.programReader = new StringReader(program);
this.buildPath = buildPath;
@@ -236,11 +280,18 @@ public class PdePreprocessor {
out.print("import processing.core.*; ");
// emit emports that are needed for classes from the code folder
/*
if (imports != null) {
for (int i = 0; i < imports.length; i++) {
out.print("import " + imports[i] + ".*; ");
}
}
*/
if (imports != null) {
for (int i = 0; i < imports.length; i++) {
out.print(imports[i]);
}
}
// emit standard imports (read from pde.properties)
// for each language level that's being used.

View File

@@ -730,12 +730,24 @@ public class PdeSketch {
public void addLibrary(String jarPath) {
String list[] = PdeCompiler.packageListFromClassPath(jarPath);
// import statements into the main sketch file (code[0])
// if the current code is a .java file, insert into current
// else import statements into the main sketch file (code[0])
for (int i = 0; i < list.length; i++) {
System.out.println(list[i]);
if (current.flavor == PDE) {
setCurrent(0);
}
// could also scan the text in the file to see if each import
// statement is already in there, but if the user has the import
// commented out, then this will be a problem.
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < list.length; i++) {
buffer.append("import ");
buffer.append(list[i]);
buffer.append(".*;\n");
}
buffer.append('\n');
buffer.append(editor.getText());
editor.setText(buffer.toString(), false);
setModified();
}
@@ -1015,7 +1027,9 @@ public class PdeSketch {
// java mode, since that's required
String className =
preprocessor.write(bigCode.toString(), buildPath,
suggestedClassName, importPackageList);
suggestedClassName);
//preprocessor.write(bigCode.toString(), buildPath,
// suggestedClassName, importPackageList);
if (className == null) {
throw new PdeException("Could not find main class");
// this situation might be perfectly fine,
@@ -1598,13 +1612,13 @@ public class PdeSketch {
* volumes or folders without appropraite permissions.
*/
public boolean isReadOnly() {
//System.out.println("checking read only: " + folder.canWrite());
if (folder.getAbsolutePath().startsWith(PdeSketchbook.examplesPath)) {
String apath = folder.getAbsolutePath();
if (apath.startsWith(PdeSketchbook.examplesPath) ||
apath.startsWith(PdeSketchbook.librariesPath)) {
return true;
// this doesn't work on directories
//} else if (!folder.canWrite()) { // is this ok for directories?
//System.err.println("read only directory...");
//} else if (!folder.canWrite()) {
} else {
// check to see if each modified code file can be written to
for (int i = 0; i < codeCount; i++) {

View File

@@ -189,8 +189,8 @@ cd app
#CLASSPATH="..\\build\\windows\\work\\lib\\core.jar;..\\build\\windows\\work\\lib\\mrj.jar;..\\build\\windows\\work\\lib\antlr.jar;..\\build\\windows\\work\\lib\\oro.jar;..\\build\\windows\\work\\java\\lib\\rt.jar;..\\build\\windows\\work\\lib\\comm.jar"
CLASSPATH="..\\build\\windows\\work\\lib\\core.jar;..\\build\\windows\\work\\lib\\mrj.jar;..\\build\\windows\\work\\lib\antlr.jar;..\\build\\windows\\work\\lib\\oro.jar;..\\build\\windows\\work\\java\\lib\\rt.jar"
#perl ../bagel/buzz.pl "../build/windows/work/jikes +D -classpath \"$CLASSPATH\" -d \"..\\build\\windows\\work/classes\"" -dJDK13 -dJDK14 *.java jeditsyntax/*.java preprocessor/*.java
../build/windows/work/jikes +D -classpath $CLASSPATH -d ..\\build\\windows\\work/classes *.java jeditsyntax/*.java preprocessor/*.java
#/cygdrive/c/jdk-1.4.2_05/bin/javac.exe -classpath $CLASSPATH -d ..\\build\\windows\\work/classes *.java jeditsyntax/*.java preprocessor/*.java
cd ../build/windows/work/classes
rm -f ../lib/pde.jar

View File

@@ -3469,7 +3469,7 @@ public class PApplet extends Applet
public void setupExternal(Frame frame) {
//externalRuntime = true;
Thread thread = new Thread() { //new Runnable() {
Thread ethread = new Thread() { //new Runnable() {
public void run() {
while ((Thread.currentThread() == this) && !finished) {
@@ -3491,7 +3491,7 @@ public class PApplet extends Applet
}
}
};
thread.start();
ethread.start();
frame.addComponentListener(new ComponentAdapter() {
public void componentMoved(ComponentEvent e) {

View File

@@ -44,6 +44,11 @@ _ "add library" menu item and submenu
_ looks for subfolder called 'libraries' inside p5 folder
_ libraries are determined by having a subfolder named 'library'
_ import all libraries into classpath
_ all libs found during sketchbook build + all libs in libraries
_ this means sketchbook menu will need to be rebuilt after lib build
_ append the user's classpath to the end of that
_ add preference for showing library stuff
_ make built-in libraries read-only
_ libraries: static and non-static init for libs