move XML and Table to processing.data, update preproc

This commit is contained in:
benfry
2012-04-03 00:26:26 +00:00
parent 3c1da90edd
commit fc6d4d49c7
11 changed files with 594 additions and 597 deletions
+13 -25
View File
@@ -23,40 +23,29 @@
package processing.core;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.io.*;
import java.lang.reflect.*;
import java.net.*;
import java.text.NumberFormat;
import java.util.*;
import java.util.regex.*;
import java.util.zip.*;
import android.app.*;
import android.content.*;
import android.content.pm.ActivityInfo;
import android.content.pm.ConfigurationInfo;
import android.content.res.AssetManager;
import android.content.res.Configuration;
import android.graphics.*;
import java.io.*;
import java.lang.reflect.*;
import java.net.MalformedURLException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.text.NumberFormat;
import java.util.*;
import java.util.regex.*;
import java.util.zip.*;
import android.app.Activity;
import android.app.ActivityManager;
import android.net.Uri;
import android.text.format.Time;
import android.util.*;
import android.view.MotionEvent;
import android.view.SurfaceView;
import android.opengl.GLSurfaceView;
import android.view.WindowManager;
import android.os.Bundle;
import android.os.Handler;
import android.text.format.Time;
import android.util.*;
import android.view.*;
import android.widget.LinearLayout;
import android.widget.*;
import android.widget.RelativeLayout;
import org.apache.http.client.HttpClient;
@@ -65,9 +54,8 @@ import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.HttpResponse;
import org.apache.http.HttpEntity;
import processing.opengl.PGraphicsOpenGL;
import java.net.URI;
import processing.data.*;
import processing.opengl.*;
public class PApplet extends Activity implements PConstants, Runnable {
@@ -23,6 +23,8 @@
package processing.core;
import processing.data.*;
import java.util.HashMap;
import android.graphics.*;
+1 -1
View File
@@ -20,7 +20,7 @@
Boston, MA 02111-1307 USA
*/
package processing.core;
package processing.data;
import java.io.*;
@@ -40,21 +40,21 @@ import antlr.TokenStreamException;
public class AndroidPreprocessor extends PdePreprocessor {
Sketch sketch;
String packageName;
String sizeStatement;
String sketchWidth;
String sketchWidth;
String sketchHeight;
String sketchRenderer;
public AndroidPreprocessor(final Sketch sketch,
public AndroidPreprocessor(final Sketch sketch,
final String packageName) throws IOException {
super(sketch.getName());
this.sketch = sketch;
this.packageName = packageName;
}
// TODO this needs to be a generic function inside Sketch or elsewhere
protected boolean parseSketchSize() {
@@ -70,7 +70,7 @@ public class AndroidPreprocessor extends PdePreprocessor {
if (matches != null) {
boolean badSize = false;
if (!matches[1].equals("screenWidth") &&
!matches[1].equals("screenHeight") &&
PApplet.parseInt(matches[1], -1) == -1) {
@@ -84,7 +84,7 @@ public class AndroidPreprocessor extends PdePreprocessor {
if (badSize) {
// found a reference to size, but it didn't seem to contain numbers
final String message =
final String message =
"The size of this applet could not automatically be determined\n" +
"from your code. Use only numeric values (not variables) for the\n" +
"size() command. See the size() reference for more information.";
@@ -116,7 +116,7 @@ public class AndroidPreprocessor extends PdePreprocessor {
throws SketchException, RecognitionException, TokenStreamException {
if (sizeStatement != null) {
int start = program.indexOf(sizeStatement);
program = program.substring(0, start) +
program = program.substring(0, start) +
program.substring(start + sizeStatement.length());
}
// String[] found = PApplet.match(program, "import\\s+processing.opengl.*\\s*");
@@ -166,8 +166,9 @@ public class AndroidPreprocessor extends PdePreprocessor {
@Override
public String[] getCoreImports() {
return new String[] {
"processing.core.*"
return new String[] {
"processing.core.*",
"processing.data.*"
};
}
@@ -192,7 +193,7 @@ public class AndroidPreprocessor extends PdePreprocessor {
//"java.util.zip.*", "java.util.regex.*" // not necessary w/ newer i/o
};
Preferences.set("android.preproc.imports.list",
Preferences.set("android.preproc.imports.list",
PApplet.join(androidImports, ","));
return androidImports;
+32 -32
View File
@@ -29,28 +29,28 @@ import java.io.PrintWriter;
import processing.app.*;
import processing.core.PApplet;
import processing.core.XML;
import processing.data.XML;
public class Manifest {
static final String MANIFEST_XML = "AndroidManifest.xml";
static final String WORLD_OF_HURT_COMING =
"Errors occurred while reading or writing " + MANIFEST_XML + ",\n" +
static final String WORLD_OF_HURT_COMING =
"Errors occurred while reading or writing " + MANIFEST_XML + ",\n" +
"which means lots of things are likely to stop working properly.\n" +
"To prevent losing any data, it's recommended that you use “Save As”\n" +
"to save a separate copy of your sketch, and the restart Processing.";
static final String MULTIPLE_ACTIVITIES =
"To prevent losing any data, it's recommended that you use “Save As”\n" +
"to save a separate copy of your sketch, and the restart Processing.";
static final String MULTIPLE_ACTIVITIES =
"Processing only supports a single Activity in the AndroidManifest.xml\n" +
"file. Only the first activity entry will be updated, and you better \n" +
"file. Only the first activity entry will be updated, and you better \n" +
"hope that's the right one, smartypants.";
// private Editor editor;
private Sketch sketch;
// entries we care about from the manifest file
// private String packageName;
/** the manifest data read from the file */
private XML xml;
@@ -64,13 +64,13 @@ public class Manifest {
this.sketch = sketch;
load();
}
private String defaultPackageName() {
// Sketch sketch = editor.getSketch();
return AndroidBuild.basePackage + "." + sketch.getName().toLowerCase();
}
// called by other classes who want an actual package name
// internally, we'll figure this out ourselves whether it's filled or not
@@ -78,20 +78,20 @@ public class Manifest {
String pkg = xml.getString("package");
return pkg.length() == 0 ? defaultPackageName() : pkg;
}
public void setPackageName(String packageName) {
// this.packageName = packageName;
// this is the package attribute in the root <manifest> object
xml.setString("package", packageName);
save();
}
//writer.println(" <uses-permission android:name=\"android.permission.INTERNET\" />");
//writer.println(" <uses-permission android:name=\"android.permission.WRITE_EXTERNAL_STORAGE\" />");
static final String PERMISSION_PREFIX = "android.permission.";
public String[] getPermissions() {
XML[] elements = xml.getChildren("uses-permission");
int count = elements.length;
@@ -101,8 +101,8 @@ public class Manifest {
}
return names;
}
public void setPermissions(String[] names) {
// just remove all the old ones
for (XML kid : xml.getChildren("uses-permission")) {
@@ -141,14 +141,14 @@ public class Manifest {
writer.println("<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\" ");
// writer.println(" package=\"" + defaultPackageName() + "\" ");
writer.println(" package=\"\" ");
// Tempting to use 'preferExternal' here, but might annoy some users.
// Tempting to use 'preferExternal' here, but might annoy some users.
// 'auto' at least enables it to be moved back and forth
// http://developer.android.com/guide/appendix/install-location.html
// writer.println(" android:installLocation=\"auto\" ");
// Disabling this for now (0190), requires default.properties to use API 8
// This is just a number (like the Processing 'revision'). It should
// This is just a number (like the Processing 'revision'). It should
// increment with each release. Perhaps P5 should do this automatically
// with each build or read/write of the manifest file?
writer.println(" android:versionCode=\"1\" ");
@@ -168,8 +168,8 @@ public class Manifest {
//// writer.println(" android:label=\"@string/app_name\">"); // pretty name
// writer.println(" android:label=\"\">");
// activity/android:name should be the full name (package + class name) of
// the actual activity class. or the package can be replaced by a single
// activity/android:name should be the full name (package + class name) of
// the actual activity class. or the package can be replaced by a single
// dot as a prefix as an easier shorthand.
writer.println(" <activity android:name=\"\">");
@@ -186,14 +186,14 @@ public class Manifest {
/**
* Save a new version of the manifest info to the build location.
* Save a new version of the manifest info to the build location.
* Also fill in any missing attributes that aren't yet set properly.
*/
protected void writeBuild(File file, String className,
protected void writeBuild(File file, String className,
boolean debug) throws IOException {
// write a copy to the build location
save(file);
// load the copy from the build location and start messing with it
XML mf = new XML(new FileReader(file));
@@ -235,7 +235,7 @@ public class Manifest {
} catch (Exception e) {
e.printStackTrace();
System.err.println("Problem reading AndroidManifest.xml, creating a new version");
// remove the old manifest file, rename it with date stamp
long lastModified = manifestFile.lastModified();
String stamp = AndroidMode.getDateStamp(lastModified);
@@ -247,7 +247,7 @@ public class Manifest {
return;
}
}
}
}
if (xml == null) {
writeBlankManifest(manifestFile);
try {
@@ -262,13 +262,13 @@ public class Manifest {
}
// return xml;
}
protected void save() {
save(getManifestFile());
}
/**
* Save to the sketch folder, so that it can be copied in later.
*/
@@ -127,13 +127,13 @@ import antlr.collections.AST;
* itself. The ANTLR manual goes into a fair amount of detail about the
* what each type of file is for.
* <P/>
*
*
* Hacked to death in 2010 by
* @author Jonathan Feinberg &lt;jdf@pobox.com&gt;
*/
public class PdePreprocessor {
protected static final String UNICODE_ESCAPES = "0123456789abcdefABCDEF";
protected static final String UNICODE_ESCAPES = "0123456789abcdefABCDEF";
// used for calling the ASTFactory to get the root node
private static final int ROOT_ID = 0;
@@ -271,7 +271,7 @@ public class PdePreprocessor {
if (UNICODE_ESCAPES.indexOf(program.charAt(i)) == -1) {
throw new SketchException("Bad or unfinished \\uXXXX sequence " +
"(malformed Unicode character constant)", 0,
countNewlines(program.substring(0, i)));
countNewlines(program.substring(0, i)));
}
i++;
}
@@ -394,13 +394,13 @@ public class PdePreprocessor {
return new String(p2, 0, index);
}
private static final Pattern PUBLIC_CLASS =
private static final Pattern PUBLIC_CLASS =
Pattern.compile("(^|;)\\s*public\\s+class\\s+\\S+\\s+extends\\s+PApplet", Pattern.MULTILINE);
// Can't only match any 'public class', needs to be a PApplet
// http://code.google.com/p/processing/issues/detail?id=551
// http://code.google.com/p/processing/issues/detail?id=551
//Pattern.compile("(^|;)\\s*public\\s+class", Pattern.MULTILINE);
private static final Pattern FUNCTION_DECL =
private static final Pattern FUNCTION_DECL =
Pattern.compile("(^|;)\\s*((public|private|protected|final|static)\\s+)*" +
"(void|int|float|double|String|char|byte)" +
"(\\s*\\[\\s*\\])?\\s+[a-zA-Z0-9]+\\s*\\(",
@@ -550,8 +550,8 @@ public class PdePreprocessor {
final AST oldFirstMod = mods.getFirstChild();
for (AST mod = oldFirstMod; mod != null; mod = mod.getNextSibling()) {
final int t = mod.getType();
if (t == PdeTokenTypes.LITERAL_private ||
t == PdeTokenTypes.LITERAL_protected ||
if (t == PdeTokenTypes.LITERAL_private ||
t == PdeTokenTypes.LITERAL_protected ||
t == PdeTokenTypes.LITERAL_public) {
return;
}
@@ -559,7 +559,7 @@ public class PdePreprocessor {
if (mods.getNextSibling().getType() == PdeTokenTypes.TYPE_PARAMETERS) {
return;
}
final CommonHiddenStreamToken publicToken =
final CommonHiddenStreamToken publicToken =
new CommonHiddenStreamToken(PdeTokenTypes.LITERAL_public, "public") {
{
setHiddenAfter(new CommonHiddenStreamToken(PdeTokenTypes.WS, " "));
@@ -593,7 +593,7 @@ public class PdePreprocessor {
}
/**
*
*
* @param out
* @param programImports
* @param codeFolderImports
@@ -695,8 +695,9 @@ public class PdePreprocessor {
}
public String[] getCoreImports() {
return new String[] {
"processing.core.*"
return new String[] {
"processing.core.*",
"processing.data.*"
};
}
@@ -705,7 +706,7 @@ public class PdePreprocessor {
String prefsLine = Preferences.get("preproc.imports.list");
return PApplet.splitTokens(prefsLine, ", ");
}
/**
* Return true if this import should be removed from the code. This is used
* for packages like processing.xml which no longer exist.
File diff suppressed because it is too large Load Diff
+3 -1
View File
@@ -23,6 +23,8 @@
package processing.core;
import processing.data.*;
import java.awt.Paint;
import java.awt.PaintContext;
import java.awt.Rectangle;
@@ -1662,7 +1664,7 @@ public class PShapeSVG extends PShape {
String name = elements[i].getName();
XML elem = elements[i];
if (name == null) {
// skip it
// skip it
} else if (name.equals("glyph")) {
FontGlyph fg = new FontGlyph(this, elem, this);
if (fg.isLegit()) {
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -20,7 +20,7 @@
Boston, MA 02111-1307 USA
*/
package processing.core;
package processing.data;
import java.io.*;
+2 -2
View File
@@ -47,8 +47,8 @@ o vectors shouldn't be exposed, need to expose attr lists as arrays
o or also add a method for getting the vectors?
X no longer an issue post-NanoXML
X several other items under the LIBRARIES / XML section below
_ move to processing.data.* package
_ update the internal code for Android and desktop to add the import
X move to processing.data.* package
X update the internal code for Android and desktop to add the import
_ change screenWidth/Height to displayWidth/Height
_ also fix the Android etc docs