diff --git a/core/src/processing/core/PApplet.java b/core/src/processing/core/PApplet.java
index b4739358c..1d29d80d0 100644
--- a/core/src/processing/core/PApplet.java
+++ b/core/src/processing/core/PApplet.java
@@ -5046,7 +5046,7 @@ public class PApplet extends Applet
} else if (extension.equals("svgz")) {
try {
InputStream input = new GZIPInputStream(createInput(filename));
- PNode xml = new PNode(createReader(input));
+ XML xml = new XML(createReader(input));
return new PShapeSVG(xml);
} catch (IOException e) {
e.printStackTrace();
@@ -5084,8 +5084,8 @@ public class PApplet extends Applet
// ???
// NODE I/O (XML, JSON, etc.)
- public PNode loadNode(String filename) {
- return new PNode(this, filename);
+ public XML loadNode(String filename) {
+ return new XML(this, filename);
}
diff --git a/core/src/processing/core/PShapeSVG.java b/core/src/processing/core/PShapeSVG.java
index 6db6bf691..be19faa94 100644
--- a/core/src/processing/core/PShapeSVG.java
+++ b/core/src/processing/core/PShapeSVG.java
@@ -140,7 +140,7 @@ import java.util.HashMap;
* here.
*/
public class PShapeSVG extends PShape {
- PNode element;
+ XML element;
/// Values between 0 and 1.
float opacity;
@@ -170,7 +170,7 @@ public class PShapeSVG extends PShape {
/**
* Initializes a new SVG Object from the given PNode.
*/
- public PShapeSVG(PNode svg) {
+ public PShapeSVG(XML svg) {
this(null, svg, true);
if (!svg.getName().equals("svg")) {
@@ -212,7 +212,7 @@ public class PShapeSVG extends PShape {
}
- public PShapeSVG(PShapeSVG parent, PNode properties, boolean parseKids) {
+ public PShapeSVG(PShapeSVG parent, XML properties, boolean parseKids) {
// Need to set this so that findChild() works.
// Otherwise 'parent' is null until addChild() is called later.
this.parent = parent;
@@ -290,12 +290,12 @@ public class PShapeSVG extends PShape {
}
- protected void parseChildren(PNode graphics) {
- PNode[] elements = graphics.getChildren();
+ protected void parseChildren(XML graphics) {
+ XML[] elements = graphics.getChildren();
children = new PShape[elements.length];
childCount = 0;
- for (PNode elem : elements) {
+ for (XML elem : elements) {
PShape kid = parseChild(elem);
if (kid != null) {
// if (kid.name != null) {
@@ -312,7 +312,7 @@ public class PShapeSVG extends PShape {
* Parse a child XML element.
* Override this method to add parsing for more SVG elements.
*/
- protected PShape parseChild(PNode elem) {
+ protected PShape parseChild(XML elem) {
// System.err.println("parsing child in pshape " + elem.getName());
String name = elem.getName();
PShapeSVG shape = null;
@@ -981,7 +981,7 @@ public class PShapeSVG extends PShape {
}
- protected void parseColors(PNode properties) {
+ protected void parseColors(XML properties) {
if (properties.hasAttribute("opacity")) {
String opacityText = properties.getString("opacity");
setOpacity(opacityText);
@@ -1204,7 +1204,7 @@ public class PShapeSVG extends PShape {
* @param attribute name of the attribute to get
* @return unit-parsed version of the data
*/
- static protected float getFloatWithUnit(PNode element, String attribute) {
+ static protected float getFloatWithUnit(XML element, String attribute) {
String val = element.getString(attribute);
return (val == null) ? 0 : parseUnitSize(val);
}
@@ -1253,16 +1253,16 @@ public class PShapeSVG extends PShape {
int[] color;
int count;
- public Gradient(PShapeSVG parent, PNode properties) {
+ public Gradient(PShapeSVG parent, XML properties) {
super(parent, properties, true);
- PNode elements[] = properties.getChildren();
+ XML elements[] = properties.getChildren();
offset = new float[elements.length];
color = new int[elements.length];
//
for (int i = 0; i < elements.length; i++) {
- PNode elem = elements[i];
+ XML elem = elements[i];
String name = elem.getName();
if (name.equals("stop")) {
String offsetAttr = elem.getString("offset");
@@ -1294,7 +1294,7 @@ public class PShapeSVG extends PShape {
class LinearGradient extends Gradient {
float x1, y1, x2, y2;
- public LinearGradient(PShapeSVG parent, PNode properties) {
+ public LinearGradient(PShapeSVG parent, XML properties) {
super(parent, properties);
this.x1 = getFloatWithUnit(properties, "x1");
@@ -1324,7 +1324,7 @@ public class PShapeSVG extends PShape {
class RadialGradient extends Gradient {
float cx, cy, r;
- public RadialGradient(PShapeSVG parent, PNode properties) {
+ public RadialGradient(PShapeSVG parent, XML properties) {
super(parent, properties);
this.cx = getFloatWithUnit(properties, "cx");
@@ -1645,11 +1645,11 @@ public class PShapeSVG extends PShape {
int horizAdvX;
- public Font(PShapeSVG parent, PNode properties) {
+ public Font(PShapeSVG parent, XML properties) {
super(parent, properties, false);
// handle(parent, properties);
- PNode[] elements = properties.getChildren();
+ XML[] elements = properties.getChildren();
horizAdvX = properties.getInt("horiz-adv-x", 0);
@@ -1660,7 +1660,7 @@ public class PShapeSVG extends PShape {
for (int i = 0; i < elements.length; i++) {
String name = elements[i].getName();
- PNode elem = elements[i];
+ XML elem = elements[i];
if (name == null) {
// skip it
} else if (name.equals("glyph")) {
@@ -1767,7 +1767,7 @@ public class PShapeSVG extends PShape {
//String unicodeRange; // gonna ignore for now
- public FontFace(PShapeSVG parent, PNode properties) {
+ public FontFace(PShapeSVG parent, XML properties) {
super(parent, properties, true);
unitsPerEm = properties.getInt("units-per-em", 1000);
@@ -1788,7 +1788,7 @@ public class PShapeSVG extends PShape {
char unicode;
int horizAdvX;
- public FontGlyph(PShapeSVG parent, PNode properties, Font font) {
+ public FontGlyph(PShapeSVG parent, XML properties, Font font) {
super(parent, properties, true);
super.parsePath(); // ??
diff --git a/core/src/processing/core/PNode.java b/core/src/processing/core/XML.java
similarity index 91%
rename from core/src/processing/core/PNode.java
rename to core/src/processing/core/XML.java
index d399b4032..6e4a5b041 100644
--- a/core/src/processing/core/PNode.java
+++ b/core/src/processing/core/XML.java
@@ -39,7 +39,7 @@ import processing.core.PApplet;
* This is the base class used for the Processing XML library,
* representing a single node of an XML tree.
*/
-public class PNode implements Serializable {
+public class XML implements Serializable {
/** The internal representation, a DOM node. */
protected Node node;
@@ -48,13 +48,13 @@ public class PNode implements Serializable {
protected String name;
/** The parent element. */
- protected PNode parent;
+ protected XML parent;
/** Child elements, once loaded. */
- protected PNode[] children;
+ protected XML[] children;
- protected PNode() { }
+ protected XML() { }
/**
@@ -62,7 +62,7 @@ public class PNode implements Serializable {
* wraps exception handling, for more advanced exception handling,
* use the constructor that takes a Reader or InputStream.
*/
- public PNode(PApplet parent, String filename) {
+ public XML(PApplet parent, String filename) {
this(parent.createReader(filename));
}
@@ -72,7 +72,7 @@ public class PNode implements Serializable {
// }
- public PNode(Reader reader) {
+ public XML(Reader reader) {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// factory.setValidating(false);
@@ -123,7 +123,7 @@ public class PNode implements Serializable {
// 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 PNode(String name) {
+ public XML(String name) {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
@@ -147,7 +147,7 @@ public class PNode implements Serializable {
// }
- protected PNode(PNode parent, Node node) {
+ protected XML(XML parent, Node node) {
this.node = node;
this.parent = parent;
@@ -157,8 +157,8 @@ public class PNode implements Serializable {
}
- static public PNode parse(String xml) {
- return new PNode(new StringReader(xml));
+ static public XML parse(String xml) {
+ return new XML(new StringReader(xml));
}
@@ -166,7 +166,7 @@ public class PNode implements Serializable {
* Returns the parent element. This method returns null for the root
* element.
*/
- public PNode getParent() {
+ public XML getParent() {
return this.parent;
}
@@ -197,9 +197,9 @@ public class PNode implements Serializable {
if (children == null) {
NodeList kids = node.getChildNodes();
int childCount = kids.getLength();
- children = new PNode[childCount];
+ children = new XML[childCount];
for (int i = 0; i < childCount; i++) {
- children[i] = new PNode(this, kids.item(i));
+ children[i] = new XML(this, kids.item(i));
}
}
}
@@ -241,7 +241,7 @@ public class PNode implements Serializable {
/**
* Returns an array containing all the child elements.
*/
- public PNode[] getChildren() {
+ public XML[] getChildren() {
// NodeList children = node.getChildNodes();
// int childCount = children.getLength();
// XMLElement[] kids = new XMLElement[childCount];
@@ -259,7 +259,7 @@ public class PNode implements Serializable {
* Quick accessor for an element at a particular index.
* @author processing.org
*/
- public PNode getChild(int index) {
+ public XML getChild(int index) {
checkChildren();
return children[index];
}
@@ -270,13 +270,13 @@ public class PNode implements Serializable {
* @param name element name or path/to/element
* @return the first matching element
*/
- public PNode getChild(String name) {
+ public XML getChild(String name) {
if (name.indexOf('/') != -1) {
return getChildRecursive(PApplet.split(name, '/'), 0);
}
int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
- PNode kid = getChild(i);
+ XML kid = getChild(i);
String kidName = kid.getName();
if (kidName != null && kidName.equals(name)) {
return kid;
@@ -293,10 +293,10 @@ public class PNode implements Serializable {
* @return matching element or null if no match
* @author processing.org
*/
- protected PNode getChildRecursive(String[] items, int offset) {
+ protected XML getChildRecursive(String[] items, int offset) {
// if it's a number, do an index instead
if (Character.isDigit(items[offset].charAt(0))) {
- PNode kid = getChild(Integer.parseInt(items[offset]));
+ XML kid = getChild(Integer.parseInt(items[offset]));
if (offset == items.length-1) {
return kid;
} else {
@@ -305,7 +305,7 @@ public class PNode implements Serializable {
}
int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
- PNode kid = getChild(i);
+ XML kid = getChild(i);
String kidName = kid.getName();
if (kidName != null && kidName.equals(items[offset])) {
if (offset == items.length-1) {
@@ -326,56 +326,56 @@ public class PNode implements Serializable {
* @return array of child elements that match
* @author processing.org
*/
- public PNode[] getChildren(String name) {
+ public XML[] getChildren(String name) {
if (name.indexOf('/') != -1) {
return getChildrenRecursive(PApplet.split(name, '/'), 0);
}
// if it's a number, do an index instead
// (returns a single element array, since this will be a single match
if (Character.isDigit(name.charAt(0))) {
- return new PNode[] { getChild(Integer.parseInt(name)) };
+ return new XML[] { getChild(Integer.parseInt(name)) };
}
int childCount = getChildCount();
- PNode[] matches = new PNode[childCount];
+ XML[] matches = new XML[childCount];
int matchCount = 0;
for (int i = 0; i < childCount; i++) {
- PNode kid = getChild(i);
+ XML kid = getChild(i);
String kidName = kid.getName();
if (kidName != null && kidName.equals(name)) {
matches[matchCount++] = kid;
}
}
- return (PNode[]) PApplet.subset(matches, 0, matchCount);
+ return (XML[]) PApplet.subset(matches, 0, matchCount);
}
- protected PNode[] getChildrenRecursive(String[] items, int offset) {
+ protected XML[] getChildrenRecursive(String[] items, int offset) {
if (offset == items.length-1) {
return getChildren(items[offset]);
}
- PNode[] matches = (PNode[]) getChildren(items[offset]);
- PNode[] outgoing = new PNode[0];
+ XML[] matches = (XML[]) getChildren(items[offset]);
+ XML[] outgoing = new XML[0];
for (int i = 0; i < matches.length; i++) {
- PNode[] kidMatches = matches[i].getChildrenRecursive(items, offset+1);
- outgoing = (PNode[]) PApplet.concat(outgoing, kidMatches);
+ XML[] kidMatches = matches[i].getChildrenRecursive(items, offset+1);
+ outgoing = (XML[]) PApplet.concat(outgoing, kidMatches);
}
return outgoing;
}
- public PNode addChild(String tag) {
+ public XML addChild(String tag) {
Document document = node.getOwnerDocument();
Node newChild = document.createElement(tag);
node.appendChild(newChild);
- PNode pn = new PNode(this, newChild);
+ XML pn = new XML(this, newChild);
if (children != null) {
- children = (PNode[]) PApplet.concat(children, new PNode[] { pn });
+ children = (XML[]) PApplet.concat(children, new XML[] { pn });
}
return pn;
}
- public void removeChild(PNode kid) {
+ public void removeChild(XML kid) {
node.removeChild(kid.node);
children = null; // TODO not efficient
}
diff --git a/core/todo.txt b/core/todo.txt
index 32e0e50c3..03ff1167b 100644
--- a/core/todo.txt
+++ b/core/todo.txt
@@ -1,6 +1,13 @@
0200 core
X remove textMode(SCREEN)
_ enable smooth() by default
+_ better to learn noSmooth() later
+_ disable smoothing on noSmooth(), use hint to do 2x vs 4x smoothing
+_ document how things are sometimes null in XML
+_ test xml examples to see if they break
+
+_ add resize().. make it call setSize().
+_ also needs to do a redraw if noLoop() has been called
_ trimming text on URLs?
_ http://code.google.com/p/processing/issues/detail?id=715