Skip to content

Commit fa772df

Browse files
committed
fixing the build for the XML and P3D changes
1 parent 87deeaa commit fa772df

File tree

6 files changed

+124
-72
lines changed

6 files changed

+124
-72
lines changed

app/src/processing/mode/android/Manifest.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929

3030
import processing.app.*;
3131
import processing.core.PApplet;
32-
import processing.xml.XMLElement;
32+
import processing.core.PNode;
33+
import processing.core.PNodeXML;
3334

3435

3536
public class Manifest {
@@ -52,7 +53,7 @@ public class Manifest {
5253
// private String packageName;
5354

5455
/** the manifest data read from the file */
55-
private XMLElement xml;
56+
private PNode xml;
5657

5758

5859
// public Manifest(Editor editor) {
@@ -93,7 +94,7 @@ public void setPackageName(String packageName) {
9394
static final String PERMISSION_PREFIX = "android.permission.";
9495

9596
public String[] getPermissions() {
96-
XMLElement[] elements = xml.getChildren("uses-permission");
97+
PNode[] elements = xml.getChildren("uses-permission");
9798
int count = elements.length;
9899
String[] names = new String[count];
99100
for (int i = 0; i < count; i++) {
@@ -105,12 +106,12 @@ public String[] getPermissions() {
105106

106107
public void setPermissions(String[] names) {
107108
// just remove all the old ones
108-
for (XMLElement kid : xml.getChildren("uses-permission")) {
109+
for (PNode kid : xml.getChildren("uses-permission")) {
109110
xml.removeChild(kid);
110111
}
111112
// ...and add the new kids back
112113
for (String name : names) {
113-
XMLElement newbie = new XMLElement("uses-permission");
114+
PNode newbie = new PNodeXML("uses-permission");
114115
newbie.setString("android:name", PERMISSION_PREFIX + name);
115116
xml.addChild(newbie);
116117
}
@@ -119,11 +120,11 @@ public void setPermissions(String[] names) {
119120

120121

121122
public void setClassName(String className) {
122-
XMLElement[] kids = xml.getChildren("application/activity");
123+
PNode[] kids = xml.getChildren("application/activity");
123124
if (kids.length != 1) {
124125
Base.showWarning("Don't touch that", MULTIPLE_ACTIVITIES, null);
125126
}
126-
XMLElement activity = kids[0];
127+
PNode activity = kids[0];
127128
String currentName = activity.getString("android:name");
128129
// only update if there are changes
129130
if (currentName == null || !currentName.equals(className)) {
@@ -193,7 +194,7 @@ protected void writeBuild(File file, String className,
193194
save(file);
194195

195196
// load the copy from the build location and start messing with it
196-
XMLElement mf = new XMLElement(new FileReader(file));
197+
PNode mf = new PNodeXML(new FileReader(file));
197198

198199
// package name, or default
199200
String p = mf.getString("package").trim();
@@ -202,14 +203,14 @@ protected void writeBuild(File file, String className,
202203
}
203204

204205
// app name and label, or the class name
205-
XMLElement app = mf.getChild("application");
206+
PNode app = mf.getChild("application");
206207
String label = app.getString("android:label");
207208
if (label.length() == 0) {
208209
app.setString("android:label", className);
209210
}
210211
app.setString("android:debuggable", debug ? "true" : "false");
211212

212-
XMLElement activity = app.getChild("activity");
213+
PNode activity = app.getChild("activity");
213214
// the '.' prefix is just an alias for the full package name
214215
// http://developer.android.com/guide/topics/manifest/activity-element.html#name
215216
activity.setString("android:name", "." + className); // this has to be right
@@ -227,7 +228,7 @@ protected void load() {
227228
File manifestFile = getManifestFile();
228229
if (manifestFile.exists()) {
229230
try {
230-
xml = new XMLElement(new FileReader(manifestFile));
231+
xml = new PNodeXML(new FileReader(manifestFile));
231232
} catch (Exception e) {
232233
e.printStackTrace();
233234
System.err.println("Problem reading AndroidManifest.xml, creating a new version");
@@ -247,7 +248,7 @@ protected void load() {
247248
if (xml == null) {
248249
writeBlankManifest(manifestFile);
249250
try {
250-
xml = new XMLElement(new FileReader(manifestFile));
251+
xml = new PNodeXML(new FileReader(manifestFile));
251252
} catch (FileNotFoundException e) {
252253
System.err.println("Could not read " + manifestFile.getAbsolutePath());
253254
e.printStackTrace();

core/src/processing/core/PNode.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ public interface PNode extends Serializable {
9898
public PNode[] getChildren(String name);
9999

100100

101+
public void addChild(PNode kid);
102+
103+
104+
public void removeChild(PNode kid);
105+
106+
101107
/**
102108
* Returns the number of attributes.
103109
*/
@@ -193,5 +199,8 @@ public interface PNode extends Serializable {
193199
public String toString();
194200

195201

196-
public String toString(boolean indent);
202+
public String toString(int indent);
203+
204+
205+
public void write(PrintWriter writer);
197206
}

core/src/processing/core/PNodeXML.java

Lines changed: 62 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -118,19 +118,32 @@ public PNodeXML(Reader reader) {
118118
e2.printStackTrace();
119119
}
120120
}
121-
122-
121+
122+
123+
// TODO is there a more efficient way of doing this? wow.
124+
// i.e. can we use one static document object for all PNodeXML objects?
123125
public PNodeXML(String name) {
124-
this(name, null);
126+
try {
127+
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
128+
DocumentBuilder builder = factory.newDocumentBuilder();
129+
Document document = builder.newDocument();
130+
node = document.createElement(name);
131+
132+
this.name = name;
133+
this.parent = null;
134+
135+
} catch (ParserConfigurationException e) {
136+
e.printStackTrace();
137+
}
125138
}
126139

127140

128-
public PNodeXML(String name, PNode parent) {
129-
PNodeXML pxml = PNodeXML.parse("<" + name + ">");
130-
this.node = pxml.node;
131-
this.name = name;
132-
this.parent = parent;
133-
}
141+
// public PNodeXML(String name, PNode parent) {
142+
// PNodeXML pxml = PNodeXML.parse("<" + name + ">");
143+
// this.node = pxml.node;
144+
// this.name = name;
145+
// this.parent = parent;
146+
// }
134147

135148

136149
protected PNodeXML(PNode parent, Node node) {
@@ -347,6 +360,18 @@ protected PNode[] getChildrenRecursive(String[] items, int offset) {
347360
}
348361
return outgoing;
349362
}
363+
364+
365+
public void addChild(PNode kid) {
366+
node.appendChild(((PNodeXML) kid).node);
367+
children = null; // TODO not efficient
368+
}
369+
370+
371+
public void removeChild(PNode kid) {
372+
node.removeChild(((PNodeXML) kid).node);
373+
children = null; // TODO not efficient
374+
}
350375

351376

352377
/**
@@ -401,12 +426,6 @@ public boolean hasAttribute(String name) {
401426
// }
402427

403428

404-
/** @deprecated */
405-
public String getStringAttribute(String name) {
406-
return getString(name, null);
407-
}
408-
409-
410429
public String getString(String name) {
411430
return getString(name, null);
412431
}
@@ -418,11 +437,21 @@ public String getString(String name, String defaultValue) {
418437
}
419438

420439

440+
public void setString(String name, String value) {
441+
((Element) node).setAttribute(name, value);
442+
}
443+
444+
421445
public int getInt(String name) {
422446
return getInt(name, 0);
423447
}
424448

449+
450+
public void setInt(String name, int value) {
451+
setString(name, String.valueOf(value));
452+
}
425453

454+
426455
/**
427456
* Returns the value of an attribute.
428457
*
@@ -437,12 +466,6 @@ public int getInt(String name, int defaultValue) {
437466
}
438467

439468

440-
/** @deprecated */
441-
public float getFloatAttribute(String name) {
442-
return getFloat(name);
443-
}
444-
445-
446469
/**
447470
* Returns the value of an attribute, or zero if not present.
448471
*/
@@ -465,12 +488,11 @@ public float getFloat(String name, float defaultValue) {
465488
}
466489

467490

468-
/** @deprecated */
469-
public double getDoubleAttribute(String name) {
470-
return getDouble(name, 0);
491+
public void setFloat(String name, float value) {
492+
setString(name, String.valueOf(value));
471493
}
472494

473-
495+
474496
public double getDouble(String name) {
475497
return getDouble(name, 0);
476498
}
@@ -488,6 +510,11 @@ public double getDouble(String name, double defaultValue) {
488510
String value = getString(name);
489511
return (value == null) ? defaultValue : Double.parseDouble(value);
490512
}
513+
514+
515+
public void setDouble(String name, double value) {
516+
setString(name, String.valueOf(value));
517+
}
491518

492519

493520
/**
@@ -504,11 +531,11 @@ public String getContent() {
504531

505532

506533
public String toString() {
507-
return toString(true);
534+
return toString(2);
508535
}
509536

510537

511-
public String toString(boolean indent) {
538+
public String toString(int indent) {
512539
try {
513540
DOMSource dumSource = new DOMSource(node);
514541
TransformerFactory tf = TransformerFactory.newInstance();
@@ -521,8 +548,8 @@ public String toString(boolean indent) {
521548
// transformer.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1");
522549
transformer.setOutputProperty(OutputKeys.ENCODING,"UTF8");
523550
// indent by default, but sometimes this needs to be turned off
524-
if (indent) {
525-
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
551+
if (indent != 0) {
552+
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", String.valueOf(indent));
526553
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
527554
}
528555
java.io.StringWriter sw = new java.io.StringWriter();
@@ -566,24 +593,10 @@ public String toString(boolean indent) {
566593
}
567594

568595

569-
// return toString(true);
570-
// }
571-
//
572-
//
573-
// // TODO finish the writer here!
574-
// public String toString(boolean pretty) {
575-
// ByteArrayOutputStream baos = new ByteArrayOutputStream();
576-
// OutputStreamWriter osw = new OutputStreamWriter(baos);
577-
// XMLWriter writer = new XMLWriter(osw);
578-
// try {
579-
// if (pretty) {
580-
// writer.write(this, true, 2, true);
581-
// } else {
582-
// writer.write(this, false, 0, true);
583-
// }
584-
// } catch (IOException e) {
585-
// e.printStackTrace();
586-
// }
587-
// return baos.toString();
588-
// }
596+
static final String HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
597+
598+
public void write(PrintWriter writer) {
599+
writer.println(HEADER);
600+
writer.print(toString(2));
601+
}
589602
}

core/todo.txt

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ A http://code.google.com/p/processing/issues/detail?id=495
1919
o Can resize sketch with P3D, but not OPENGL
2020
o http://code.google.com/p/processing/issues/detail?id=383
2121

22+
cleaning
23+
o call reapplySettings() when using beginRecord()?
24+
X nope, won't work for many fonts, can't get the background
25+
26+
_ see if write() is necessary inside PNodeXML
27+
_ it needs a proper header on it, so maybe that's the difference w/ toString()
28+
_ inefficient: the way new nodes are created
29+
_ also inefficient: adding/removing kids just nukes the children array
30+
_ check on DXFWriter, since it used to subclass P3D
2231

2332
_ Potential race condition when resizing sketches
2433
_ http://code.google.com/p/processing/issues/detail?id=697
@@ -53,36 +62,50 @@ _ start()/stop() perform like onPause()/onResume()
5362
_ all of which call pause() and resume()
5463
_ decision on registered methods
5564
_ remove registerPre() et al
65+
_ add register("pause", ...)
5666
_ add PEvent
57-
58-
_ call reapplySettings() when using beginRecord()?
5967
_ binary() auto-sizes, hex() does not
68+
_ decision: remove auto-sizing from binary
6069
_ in PShape, getChild(name) refers to a <blah id="name">
6170
_ however in an XML file, that's <name ...>, meaning the name of the tag
6271
_ change it to getShape(name)? also for fonts getShape(char c)
72+
_ decision: use getShape() (maybe add getShapeCount and getShape(int))
73+
_ and remove getChild() from PShape
6374
_ move to new XML library
6475
_ add XHTML parsing or any others?
65-
_ html parser? javax.swing.text.html.parser... has binary DTDs
66-
_ how should quadVertex() be named?
76+
_ html parser? javax.swing.text.html.parser... has binary DTDs
77+
_ decision: it's someone else's job
78+
_ how should quadVertex() be named? bezierVertex() quadraticVertex()
6779
_ need documentation for it
80+
_ decision: quadraticVertex() to avoid confusion with quads
6881
_ load/save methods.. is it save("blah.svg") or saveSVG("blah.svg")
6982
_ also works that way with tables
83+
_ decision: useExtension() or something like that
7084
_ XMLElemnt.parse() or new XMLElement(xmldata)?
7185
_ same goes for PShape.. parse from a string?
7286
_ http://code.google.com/p/processing/issues/detail?id=277
7387
_ how should stroke work w/ arcs?
7488
_ has an effect elliptical arc
7589
_ http://code.google.com/p/processing/issues/detail?id=130
90+
_ decision: we should do pie, you can make the other kind w/o it
7691
_ rounded rectangle method
7792
_ http://code.google.com/p/processing/issues/detail?id=265
93+
_ clockwise from upper-left
94+
_ require people to put things in the data folder
7895
_ make sure that loadXxxx() methods are used after init()
7996
_ nasty errors when loadImage/Font/createFont/etc used outside
97+
_ decision: add error messages where possible
8098
_ selectInput() and selectOutput() freezes
8199
_ just nix the function and go with a callback setup
82100
_ http://code.google.com/p/processing/issues/detail?id=173
83101
o http://code.google.com/p/processing/issues/detail?id=445
84-
o selectInput() fails when called from within keyPressed()
85-
o http://dev.processing.org/bugs/show_bug.cgi?id=1220
102+
_ decision: named callback functions
103+
_ if can't find the function, tell people to put it in the main tab
104+
_ remove delay()
105+
_ if you really want it, you can use Thread.sleep()
106+
107+
_ thread() and method()
108+
86109
_ OpenGL Applets won't load with JRE 6 update 21 or higher
87110
_ need to make the final call on this and implement
88111
_ http://code.google.com/p/processing/issues/detail?id=429
@@ -121,6 +144,7 @@ _ Table? StringIntPairs? JSON? MD5? Integrator? ColorIntegrator?
121144
_ actual shape api for things like rectangles and whatnot?
122145
_ PShape api to handle internal vertex stuff
123146
_ size() and resize() and whatever?
147+
_ thread() method (web workers?)
124148

125149
_ hitting ESC in a running noLoop()ed sketch won't close the sketch?
126150
_ work through serial examples

0 commit comments

Comments
 (0)