From fa772df0ad2309b4bd0b1ca9ed06fc21c2730964 Mon Sep 17 00:00:00 2001 From: benfry Date: Sun, 19 Jun 2011 12:56:32 +0000 Subject: [PATCH] fixing the build for the XML and P3D changes --- app/src/processing/mode/android/Manifest.java | 25 ++-- core/src/processing/core/PNode.java | 11 +- core/src/processing/core/PNodeXML.java | 111 ++++++++++-------- core/todo.txt | 36 +++++- .../dxf/src/processing/dxf/RawDXF.java | 2 +- todo.txt | 11 +- 6 files changed, 124 insertions(+), 72 deletions(-) diff --git a/app/src/processing/mode/android/Manifest.java b/app/src/processing/mode/android/Manifest.java index 8158ef1c5..688b7f0a4 100644 --- a/app/src/processing/mode/android/Manifest.java +++ b/app/src/processing/mode/android/Manifest.java @@ -29,7 +29,8 @@ import java.io.PrintWriter; import processing.app.*; import processing.core.PApplet; -import processing.xml.XMLElement; +import processing.core.PNode; +import processing.core.PNodeXML; public class Manifest { @@ -52,7 +53,7 @@ public class Manifest { // private String packageName; /** the manifest data read from the file */ - private XMLElement xml; + private PNode xml; // public Manifest(Editor editor) { @@ -93,7 +94,7 @@ public class Manifest { static final String PERMISSION_PREFIX = "android.permission."; public String[] getPermissions() { - XMLElement[] elements = xml.getChildren("uses-permission"); + PNode[] elements = xml.getChildren("uses-permission"); int count = elements.length; String[] names = new String[count]; for (int i = 0; i < count; i++) { @@ -105,12 +106,12 @@ public class Manifest { public void setPermissions(String[] names) { // just remove all the old ones - for (XMLElement kid : xml.getChildren("uses-permission")) { + for (PNode kid : xml.getChildren("uses-permission")) { xml.removeChild(kid); } // ...and add the new kids back for (String name : names) { - XMLElement newbie = new XMLElement("uses-permission"); + PNode newbie = new PNodeXML("uses-permission"); newbie.setString("android:name", PERMISSION_PREFIX + name); xml.addChild(newbie); } @@ -119,11 +120,11 @@ public class Manifest { public void setClassName(String className) { - XMLElement[] kids = xml.getChildren("application/activity"); + PNode[] kids = xml.getChildren("application/activity"); if (kids.length != 1) { Base.showWarning("Don't touch that", MULTIPLE_ACTIVITIES, null); } - XMLElement activity = kids[0]; + PNode activity = kids[0]; String currentName = activity.getString("android:name"); // only update if there are changes if (currentName == null || !currentName.equals(className)) { @@ -193,7 +194,7 @@ public class Manifest { save(file); // load the copy from the build location and start messing with it - XMLElement mf = new XMLElement(new FileReader(file)); + PNode mf = new PNodeXML(new FileReader(file)); // package name, or default String p = mf.getString("package").trim(); @@ -202,14 +203,14 @@ public class Manifest { } // app name and label, or the class name - XMLElement app = mf.getChild("application"); + PNode app = mf.getChild("application"); String label = app.getString("android:label"); if (label.length() == 0) { app.setString("android:label", className); } app.setString("android:debuggable", debug ? "true" : "false"); - XMLElement activity = app.getChild("activity"); + PNode activity = app.getChild("activity"); // the '.' prefix is just an alias for the full package name // http://developer.android.com/guide/topics/manifest/activity-element.html#name activity.setString("android:name", "." + className); // this has to be right @@ -227,7 +228,7 @@ public class Manifest { File manifestFile = getManifestFile(); if (manifestFile.exists()) { try { - xml = new XMLElement(new FileReader(manifestFile)); + xml = new PNodeXML(new FileReader(manifestFile)); } catch (Exception e) { e.printStackTrace(); System.err.println("Problem reading AndroidManifest.xml, creating a new version"); @@ -247,7 +248,7 @@ public class Manifest { if (xml == null) { writeBlankManifest(manifestFile); try { - xml = new XMLElement(new FileReader(manifestFile)); + xml = new PNodeXML(new FileReader(manifestFile)); } catch (FileNotFoundException e) { System.err.println("Could not read " + manifestFile.getAbsolutePath()); e.printStackTrace(); diff --git a/core/src/processing/core/PNode.java b/core/src/processing/core/PNode.java index 75a2686cd..451cd1c47 100644 --- a/core/src/processing/core/PNode.java +++ b/core/src/processing/core/PNode.java @@ -98,6 +98,12 @@ public interface PNode extends Serializable { public PNode[] getChildren(String name); + public void addChild(PNode kid); + + + public void removeChild(PNode kid); + + /** * Returns the number of attributes. */ @@ -193,5 +199,8 @@ public interface PNode extends Serializable { public String toString(); - public String toString(boolean indent); + public String toString(int indent); + + + public void write(PrintWriter writer); } \ No newline at end of file diff --git a/core/src/processing/core/PNodeXML.java b/core/src/processing/core/PNodeXML.java index 59d70852d..63fbd2070 100644 --- a/core/src/processing/core/PNodeXML.java +++ b/core/src/processing/core/PNodeXML.java @@ -118,19 +118,32 @@ public class PNodeXML implements PNode, Serializable { e2.printStackTrace(); } } - - + + + // TODO is there a more efficient way of doing this? wow. + // i.e. can we use one static document object for all PNodeXML objects? public PNodeXML(String name) { - this(name, null); + try { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + Document document = builder.newDocument(); + node = document.createElement(name); + + this.name = name; + this.parent = null; + + } catch (ParserConfigurationException e) { + e.printStackTrace(); + } } - public PNodeXML(String name, PNode parent) { - PNodeXML pxml = PNodeXML.parse("<" + name + ">"); - this.node = pxml.node; - this.name = name; - this.parent = parent; - } +// public PNodeXML(String name, PNode parent) { +// PNodeXML pxml = PNodeXML.parse("<" + name + ">"); +// this.node = pxml.node; +// this.name = name; +// this.parent = parent; +// } protected PNodeXML(PNode parent, Node node) { @@ -347,6 +360,18 @@ public class PNodeXML implements PNode, Serializable { } return outgoing; } + + + public void addChild(PNode kid) { + node.appendChild(((PNodeXML) kid).node); + children = null; // TODO not efficient + } + + + public void removeChild(PNode kid) { + node.removeChild(((PNodeXML) kid).node); + children = null; // TODO not efficient + } /** @@ -401,12 +426,6 @@ public class PNodeXML implements PNode, Serializable { // } - /** @deprecated */ - public String getStringAttribute(String name) { - return getString(name, null); - } - - public String getString(String name) { return getString(name, null); } @@ -418,11 +437,21 @@ public class PNodeXML implements PNode, Serializable { } + public void setString(String name, String value) { + ((Element) node).setAttribute(name, value); + } + + public int getInt(String name) { return getInt(name, 0); } + + public void setInt(String name, int value) { + setString(name, String.valueOf(value)); + } + /** * Returns the value of an attribute. * @@ -437,12 +466,6 @@ public class PNodeXML implements PNode, Serializable { } - /** @deprecated */ - public float getFloatAttribute(String name) { - return getFloat(name); - } - - /** * Returns the value of an attribute, or zero if not present. */ @@ -465,12 +488,11 @@ public class PNodeXML implements PNode, Serializable { } - /** @deprecated */ - public double getDoubleAttribute(String name) { - return getDouble(name, 0); + public void setFloat(String name, float value) { + setString(name, String.valueOf(value)); } - + public double getDouble(String name) { return getDouble(name, 0); } @@ -488,6 +510,11 @@ public class PNodeXML implements PNode, Serializable { String value = getString(name); return (value == null) ? defaultValue : Double.parseDouble(value); } + + + public void setDouble(String name, double value) { + setString(name, String.valueOf(value)); + } /** @@ -504,11 +531,11 @@ public class PNodeXML implements PNode, Serializable { public String toString() { - return toString(true); + return toString(2); } - public String toString(boolean indent) { + public String toString(int indent) { try { DOMSource dumSource = new DOMSource(node); TransformerFactory tf = TransformerFactory.newInstance(); @@ -521,8 +548,8 @@ public class PNodeXML implements PNode, Serializable { // transformer.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1"); transformer.setOutputProperty(OutputKeys.ENCODING,"UTF8"); // indent by default, but sometimes this needs to be turned off - if (indent) { - transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); + if (indent != 0) { + transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", String.valueOf(indent)); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); } java.io.StringWriter sw = new java.io.StringWriter(); @@ -566,24 +593,10 @@ public class PNodeXML implements PNode, Serializable { } -// return toString(true); -// } -// -// -// // TODO finish the writer here! -// public String toString(boolean pretty) { -// ByteArrayOutputStream baos = new ByteArrayOutputStream(); -// OutputStreamWriter osw = new OutputStreamWriter(baos); -// XMLWriter writer = new XMLWriter(osw); -// try { -// if (pretty) { -// writer.write(this, true, 2, true); -// } else { -// writer.write(this, false, 0, true); -// } -// } catch (IOException e) { -// e.printStackTrace(); -// } -// return baos.toString(); -// } + static final String HEADER = ""; + + public void write(PrintWriter writer) { + writer.println(HEADER); + writer.print(toString(2)); + } } diff --git a/core/todo.txt b/core/todo.txt index 8938550db..36e10d205 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -19,6 +19,15 @@ A http://code.google.com/p/processing/issues/detail?id=495 o Can resize sketch with P3D, but not OPENGL o http://code.google.com/p/processing/issues/detail?id=383 +cleaning +o call reapplySettings() when using beginRecord()? +X nope, won't work for many fonts, can't get the background + +_ see if write() is necessary inside PNodeXML +_ it needs a proper header on it, so maybe that's the difference w/ toString() +_ inefficient: the way new nodes are created +_ also inefficient: adding/removing kids just nukes the children array +_ check on DXFWriter, since it used to subclass P3D _ Potential race condition when resizing sketches _ http://code.google.com/p/processing/issues/detail?id=697 @@ -53,36 +62,50 @@ _ start()/stop() perform like onPause()/onResume() _ all of which call pause() and resume() _ decision on registered methods _ remove registerPre() et al +_ add register("pause", ...) _ add PEvent - -_ call reapplySettings() when using beginRecord()? _ binary() auto-sizes, hex() does not +_ decision: remove auto-sizing from binary _ in PShape, getChild(name) refers to a _ however in an XML file, that's , meaning the name of the tag _ change it to getShape(name)? also for fonts getShape(char c) +_ decision: use getShape() (maybe add getShapeCount and getShape(int)) +_ and remove getChild() from PShape _ move to new XML library _ add XHTML parsing or any others? -_ html parser? javax.swing.text.html.parser... has binary DTDs -_ how should quadVertex() be named? +_ html parser? javax.swing.text.html.parser... has binary DTDs +_ decision: it's someone else's job +_ how should quadVertex() be named? bezierVertex() quadraticVertex() _ need documentation for it +_ decision: quadraticVertex() to avoid confusion with quads _ load/save methods.. is it save("blah.svg") or saveSVG("blah.svg") _ also works that way with tables +_ decision: useExtension() or something like that _ XMLElemnt.parse() or new XMLElement(xmldata)? _ same goes for PShape.. parse from a string? _ http://code.google.com/p/processing/issues/detail?id=277 _ how should stroke work w/ arcs? _ has an effect elliptical arc _ http://code.google.com/p/processing/issues/detail?id=130 +_ decision: we should do pie, you can make the other kind w/o it _ rounded rectangle method _ http://code.google.com/p/processing/issues/detail?id=265 +_ clockwise from upper-left +_ require people to put things in the data folder _ make sure that loadXxxx() methods are used after init() _ nasty errors when loadImage/Font/createFont/etc used outside +_ decision: add error messages where possible _ selectInput() and selectOutput() freezes _ just nix the function and go with a callback setup _ http://code.google.com/p/processing/issues/detail?id=173 o http://code.google.com/p/processing/issues/detail?id=445 -o selectInput() fails when called from within keyPressed() -o http://dev.processing.org/bugs/show_bug.cgi?id=1220 +_ decision: named callback functions +_ if can't find the function, tell people to put it in the main tab +_ remove delay() +_ if you really want it, you can use Thread.sleep() + +_ thread() and method() + _ OpenGL Applets won't load with JRE 6 update 21 or higher _ need to make the final call on this and implement _ http://code.google.com/p/processing/issues/detail?id=429 @@ -121,6 +144,7 @@ _ Table? StringIntPairs? JSON? MD5? Integrator? ColorIntegrator? _ actual shape api for things like rectangles and whatnot? _ PShape api to handle internal vertex stuff _ size() and resize() and whatever? +_ thread() method (web workers?) _ hitting ESC in a running noLoop()ed sketch won't close the sketch? _ work through serial examples diff --git a/java/libraries/dxf/src/processing/dxf/RawDXF.java b/java/libraries/dxf/src/processing/dxf/RawDXF.java index d5df748a6..bdbfce072 100644 --- a/java/libraries/dxf/src/processing/dxf/RawDXF.java +++ b/java/libraries/dxf/src/processing/dxf/RawDXF.java @@ -112,7 +112,7 @@ import processing.core.*; * Updated again for inclusion as a core library in March 2006. * Constructor modifications in September 2008 as we approach 1.0. */ -public class RawDXF extends PGraphics3D { +public class RawDXF extends PGraphics { File file; PrintWriter writer; diff --git a/todo.txt b/todo.txt index 585ba806c..dbce04f6e 100644 --- a/todo.txt +++ b/todo.txt @@ -23,9 +23,17 @@ o prevent people from setting the font size too small in the editor o how do we figure out what "too small" is? X -> everyone thinks this is funny +_ write quicktime uncompressed (w/o qtjava) +_ http://www.randelshofer.ch/blog/2010/10/writing-quicktime-movies-in-pure-java/ + +_ add INTERNET permissions to the android net examples + _ Resize box on OS X is not present in Examples box _ http://code.google.com/p/processing/issues/detail?id=730 +_ fix opengl applets so that we can safely kill P3D +_ automatically insert the 'import processing.opengl' when P3D used + pnode: look more closely at json and xml compatibility @@ -372,9 +380,6 @@ _ http://dev.processing.org/bugs/show_bug.cgi?id=1444 _ for tools, maybe don't run on event thread? (makes the gui hang) _ but instead, things that affect gui need to be called w/ invokeLater? -_ write quicktime uncompressed (w/o qtjava) -_ http://blog.hslu.ch/rawcoder/2008/06/21/writing-quicktime-movies-in-pure-java/ - _ improve the speed of file copying _ use FileChannels, see FileInputStream.getChannel(), _ and use transferFrom() or transferTo().)