Skip to content

Commit 2e6c555

Browse files
committed
renaming PNode to XML
1 parent 53e0e8f commit 2e6c555

File tree

4 files changed

+63
-56
lines changed

4 files changed

+63
-56
lines changed

core/src/processing/core/PApplet.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5046,7 +5046,7 @@ public PShape loadShape(String filename, Object params) {
50465046
} else if (extension.equals("svgz")) {
50475047
try {
50485048
InputStream input = new GZIPInputStream(createInput(filename));
5049-
PNode xml = new PNode(createReader(input));
5049+
XML xml = new XML(createReader(input));
50505050
return new PShapeSVG(xml);
50515051
} catch (IOException e) {
50525052
e.printStackTrace();
@@ -5084,8 +5084,8 @@ public PShape createShape(int size, Object params) {
50845084

50855085
// ???
50865086
// NODE I/O (XML, JSON, etc.)
5087-
public PNode loadNode(String filename) {
5088-
return new PNode(this, filename);
5087+
public XML loadNode(String filename) {
5088+
return new XML(this, filename);
50895089
}
50905090

50915091

core/src/processing/core/PShapeSVG.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140
* <A HREF="http://www.w3.org/TR/SVG">here</A>.
141141
*/
142142
public class PShapeSVG extends PShape {
143-
PNode element;
143+
XML element;
144144

145145
/// Values between 0 and 1.
146146
float opacity;
@@ -170,7 +170,7 @@ public PShapeSVG(PApplet parent, String filename) {
170170
/**
171171
* Initializes a new SVG Object from the given PNode.
172172
*/
173-
public PShapeSVG(PNode svg) {
173+
public PShapeSVG(XML svg) {
174174
this(null, svg, true);
175175

176176
if (!svg.getName().equals("svg")) {
@@ -212,7 +212,7 @@ public PShapeSVG(PNode svg) {
212212
}
213213

214214

215-
public PShapeSVG(PShapeSVG parent, PNode properties, boolean parseKids) {
215+
public PShapeSVG(PShapeSVG parent, XML properties, boolean parseKids) {
216216
// Need to set this so that findChild() works.
217217
// Otherwise 'parent' is null until addChild() is called later.
218218
this.parent = parent;
@@ -290,12 +290,12 @@ public PShapeSVG(PShapeSVG parent, PNode properties, boolean parseKids) {
290290
}
291291

292292

293-
protected void parseChildren(PNode graphics) {
294-
PNode[] elements = graphics.getChildren();
293+
protected void parseChildren(XML graphics) {
294+
XML[] elements = graphics.getChildren();
295295
children = new PShape[elements.length];
296296
childCount = 0;
297297

298-
for (PNode elem : elements) {
298+
for (XML elem : elements) {
299299
PShape kid = parseChild(elem);
300300
if (kid != null) {
301301
// if (kid.name != null) {
@@ -312,7 +312,7 @@ protected void parseChildren(PNode graphics) {
312312
* Parse a child XML element.
313313
* Override this method to add parsing for more SVG elements.
314314
*/
315-
protected PShape parseChild(PNode elem) {
315+
protected PShape parseChild(XML elem) {
316316
// System.err.println("parsing child in pshape " + elem.getName());
317317
String name = elem.getName();
318318
PShapeSVG shape = null;
@@ -981,7 +981,7 @@ static protected PMatrix2D parseSingleTransform(String matrixStr) {
981981
}
982982

983983

984-
protected void parseColors(PNode properties) {
984+
protected void parseColors(XML properties) {
985985
if (properties.hasAttribute("opacity")) {
986986
String opacityText = properties.getString("opacity");
987987
setOpacity(opacityText);
@@ -1204,7 +1204,7 @@ static protected HashMap<String, String> parseStyleAttributes(String style) {
12041204
* @param attribute name of the attribute to get
12051205
* @return unit-parsed version of the data
12061206
*/
1207-
static protected float getFloatWithUnit(PNode element, String attribute) {
1207+
static protected float getFloatWithUnit(XML element, String attribute) {
12081208
String val = element.getString(attribute);
12091209
return (val == null) ? 0 : parseUnitSize(val);
12101210
}
@@ -1253,16 +1253,16 @@ static class Gradient extends PShapeSVG {
12531253
int[] color;
12541254
int count;
12551255

1256-
public Gradient(PShapeSVG parent, PNode properties) {
1256+
public Gradient(PShapeSVG parent, XML properties) {
12571257
super(parent, properties, true);
12581258

1259-
PNode elements[] = properties.getChildren();
1259+
XML elements[] = properties.getChildren();
12601260
offset = new float[elements.length];
12611261
color = new int[elements.length];
12621262

12631263
// <stop offset="0" style="stop-color:#967348"/>
12641264
for (int i = 0; i < elements.length; i++) {
1265-
PNode elem = elements[i];
1265+
XML elem = elements[i];
12661266
String name = elem.getName();
12671267
if (name.equals("stop")) {
12681268
String offsetAttr = elem.getString("offset");
@@ -1294,7 +1294,7 @@ public Gradient(PShapeSVG parent, PNode properties) {
12941294
class LinearGradient extends Gradient {
12951295
float x1, y1, x2, y2;
12961296

1297-
public LinearGradient(PShapeSVG parent, PNode properties) {
1297+
public LinearGradient(PShapeSVG parent, XML properties) {
12981298
super(parent, properties);
12991299

13001300
this.x1 = getFloatWithUnit(properties, "x1");
@@ -1324,7 +1324,7 @@ public LinearGradient(PShapeSVG parent, PNode properties) {
13241324
class RadialGradient extends Gradient {
13251325
float cx, cy, r;
13261326

1327-
public RadialGradient(PShapeSVG parent, PNode properties) {
1327+
public RadialGradient(PShapeSVG parent, XML properties) {
13281328
super(parent, properties);
13291329

13301330
this.cx = getFloatWithUnit(properties, "cx");
@@ -1645,11 +1645,11 @@ public class Font extends PShapeSVG {
16451645
int horizAdvX;
16461646

16471647

1648-
public Font(PShapeSVG parent, PNode properties) {
1648+
public Font(PShapeSVG parent, XML properties) {
16491649
super(parent, properties, false);
16501650
// handle(parent, properties);
16511651

1652-
PNode[] elements = properties.getChildren();
1652+
XML[] elements = properties.getChildren();
16531653

16541654
horizAdvX = properties.getInt("horiz-adv-x", 0);
16551655

@@ -1660,7 +1660,7 @@ public Font(PShapeSVG parent, PNode properties) {
16601660

16611661
for (int i = 0; i < elements.length; i++) {
16621662
String name = elements[i].getName();
1663-
PNode elem = elements[i];
1663+
XML elem = elements[i];
16641664
if (name == null) {
16651665
// skip it
16661666
} else if (name.equals("glyph")) {
@@ -1767,7 +1767,7 @@ class FontFace extends PShapeSVG {
17671767
//String unicodeRange; // gonna ignore for now
17681768

17691769

1770-
public FontFace(PShapeSVG parent, PNode properties) {
1770+
public FontFace(PShapeSVG parent, XML properties) {
17711771
super(parent, properties, true);
17721772

17731773
unitsPerEm = properties.getInt("units-per-em", 1000);
@@ -1788,7 +1788,7 @@ public class FontGlyph extends PShapeSVG { // extends Path
17881788
char unicode;
17891789
int horizAdvX;
17901790

1791-
public FontGlyph(PShapeSVG parent, PNode properties, Font font) {
1791+
public FontGlyph(PShapeSVG parent, XML properties, Font font) {
17921792
super(parent, properties, true);
17931793
super.parsePath(); // ??
17941794

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
* This is the base class used for the Processing XML library,
4040
* representing a single node of an XML tree.
4141
*/
42-
public class PNode implements Serializable {
42+
public class XML implements Serializable {
4343

4444
/** The internal representation, a DOM node. */
4545
protected Node node;
@@ -48,21 +48,21 @@ public class PNode implements Serializable {
4848
protected String name;
4949

5050
/** The parent element. */
51-
protected PNode parent;
51+
protected XML parent;
5252

5353
/** Child elements, once loaded. */
54-
protected PNode[] children;
54+
protected XML[] children;
5555

5656

57-
protected PNode() { }
57+
protected XML() { }
5858

5959

6060
/**
6161
* Begin parsing XML data passed in from a PApplet. This code
6262
* wraps exception handling, for more advanced exception handling,
6363
* use the constructor that takes a Reader or InputStream.
6464
*/
65-
public PNode(PApplet parent, String filename) {
65+
public XML(PApplet parent, String filename) {
6666
this(parent.createReader(filename));
6767
}
6868

@@ -72,7 +72,7 @@ public PNode(PApplet parent, String filename) {
7272
// }
7373

7474

75-
public PNode(Reader reader) {
75+
public XML(Reader reader) {
7676
try {
7777
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
7878
// factory.setValidating(false);
@@ -123,7 +123,7 @@ public PNode(Reader reader) {
123123

124124
// TODO is there a more efficient way of doing this? wow.
125125
// i.e. can we use one static document object for all PNodeXML objects?
126-
public PNode(String name) {
126+
public XML(String name) {
127127
try {
128128
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
129129
DocumentBuilder builder = factory.newDocumentBuilder();
@@ -147,7 +147,7 @@ public PNode(String name) {
147147
// }
148148

149149

150-
protected PNode(PNode parent, Node node) {
150+
protected XML(XML parent, Node node) {
151151
this.node = node;
152152
this.parent = parent;
153153

@@ -157,16 +157,16 @@ protected PNode(PNode parent, Node node) {
157157
}
158158

159159

160-
static public PNode parse(String xml) {
161-
return new PNode(new StringReader(xml));
160+
static public XML parse(String xml) {
161+
return new XML(new StringReader(xml));
162162
}
163163

164164

165165
/**
166166
* Returns the parent element. This method returns null for the root
167167
* element.
168168
*/
169-
public PNode getParent() {
169+
public XML getParent() {
170170
return this.parent;
171171
}
172172

@@ -197,9 +197,9 @@ protected void checkChildren() {
197197
if (children == null) {
198198
NodeList kids = node.getChildNodes();
199199
int childCount = kids.getLength();
200-
children = new PNode[childCount];
200+
children = new XML[childCount];
201201
for (int i = 0; i < childCount; i++) {
202-
children[i] = new PNode(this, kids.item(i));
202+
children[i] = new XML(this, kids.item(i));
203203
}
204204
}
205205
}
@@ -241,7 +241,7 @@ public String[] listChildren() {
241241
/**
242242
* Returns an array containing all the child elements.
243243
*/
244-
public PNode[] getChildren() {
244+
public XML[] getChildren() {
245245
// NodeList children = node.getChildNodes();
246246
// int childCount = children.getLength();
247247
// XMLElement[] kids = new XMLElement[childCount];
@@ -259,7 +259,7 @@ public PNode[] getChildren() {
259259
* Quick accessor for an element at a particular index.
260260
* @author processing.org
261261
*/
262-
public PNode getChild(int index) {
262+
public XML getChild(int index) {
263263
checkChildren();
264264
return children[index];
265265
}
@@ -270,13 +270,13 @@ public PNode getChild(int index) {
270270
* @param name element name or path/to/element
271271
* @return the first matching element
272272
*/
273-
public PNode getChild(String name) {
273+
public XML getChild(String name) {
274274
if (name.indexOf('/') != -1) {
275275
return getChildRecursive(PApplet.split(name, '/'), 0);
276276
}
277277
int childCount = getChildCount();
278278
for (int i = 0; i < childCount; i++) {
279-
PNode kid = getChild(i);
279+
XML kid = getChild(i);
280280
String kidName = kid.getName();
281281
if (kidName != null && kidName.equals(name)) {
282282
return kid;
@@ -293,10 +293,10 @@ public PNode getChild(String name) {
293293
* @return matching element or null if no match
294294
* @author processing.org
295295
*/
296-
protected PNode getChildRecursive(String[] items, int offset) {
296+
protected XML getChildRecursive(String[] items, int offset) {
297297
// if it's a number, do an index instead
298298
if (Character.isDigit(items[offset].charAt(0))) {
299-
PNode kid = getChild(Integer.parseInt(items[offset]));
299+
XML kid = getChild(Integer.parseInt(items[offset]));
300300
if (offset == items.length-1) {
301301
return kid;
302302
} else {
@@ -305,7 +305,7 @@ protected PNode getChildRecursive(String[] items, int offset) {
305305
}
306306
int childCount = getChildCount();
307307
for (int i = 0; i < childCount; i++) {
308-
PNode kid = getChild(i);
308+
XML kid = getChild(i);
309309
String kidName = kid.getName();
310310
if (kidName != null && kidName.equals(items[offset])) {
311311
if (offset == items.length-1) {
@@ -326,56 +326,56 @@ protected PNode getChildRecursive(String[] items, int offset) {
326326
* @return array of child elements that match
327327
* @author processing.org
328328
*/
329-
public PNode[] getChildren(String name) {
329+
public XML[] getChildren(String name) {
330330
if (name.indexOf('/') != -1) {
331331
return getChildrenRecursive(PApplet.split(name, '/'), 0);
332332
}
333333
// if it's a number, do an index instead
334334
// (returns a single element array, since this will be a single match
335335
if (Character.isDigit(name.charAt(0))) {
336-
return new PNode[] { getChild(Integer.parseInt(name)) };
336+
return new XML[] { getChild(Integer.parseInt(name)) };
337337
}
338338
int childCount = getChildCount();
339-
PNode[] matches = new PNode[childCount];
339+
XML[] matches = new XML[childCount];
340340
int matchCount = 0;
341341
for (int i = 0; i < childCount; i++) {
342-
PNode kid = getChild(i);
342+
XML kid = getChild(i);
343343
String kidName = kid.getName();
344344
if (kidName != null && kidName.equals(name)) {
345345
matches[matchCount++] = kid;
346346
}
347347
}
348-
return (PNode[]) PApplet.subset(matches, 0, matchCount);
348+
return (XML[]) PApplet.subset(matches, 0, matchCount);
349349
}
350350

351351

352-
protected PNode[] getChildrenRecursive(String[] items, int offset) {
352+
protected XML[] getChildrenRecursive(String[] items, int offset) {
353353
if (offset == items.length-1) {
354354
return getChildren(items[offset]);
355355
}
356-
PNode[] matches = (PNode[]) getChildren(items[offset]);
357-
PNode[] outgoing = new PNode[0];
356+
XML[] matches = (XML[]) getChildren(items[offset]);
357+
XML[] outgoing = new XML[0];
358358
for (int i = 0; i < matches.length; i++) {
359-
PNode[] kidMatches = matches[i].getChildrenRecursive(items, offset+1);
360-
outgoing = (PNode[]) PApplet.concat(outgoing, kidMatches);
359+
XML[] kidMatches = matches[i].getChildrenRecursive(items, offset+1);
360+
outgoing = (XML[]) PApplet.concat(outgoing, kidMatches);
361361
}
362362
return outgoing;
363363
}
364364

365365

366-
public PNode addChild(String tag) {
366+
public XML addChild(String tag) {
367367
Document document = node.getOwnerDocument();
368368
Node newChild = document.createElement(tag);
369369
node.appendChild(newChild);
370-
PNode pn = new PNode(this, newChild);
370+
XML pn = new XML(this, newChild);
371371
if (children != null) {
372-
children = (PNode[]) PApplet.concat(children, new PNode[] { pn });
372+
children = (XML[]) PApplet.concat(children, new XML[] { pn });
373373
}
374374
return pn;
375375
}
376376

377377

378-
public void removeChild(PNode kid) {
378+
public void removeChild(XML kid) {
379379
node.removeChild(kid.node);
380380
children = null; // TODO not efficient
381381
}

0 commit comments

Comments
 (0)