Permalink
Browse files

Updated for Processing 2.0+, closes #2

  • Loading branch information...
1 parent 3c2b8d2 commit 9b326dcb80919db83297df5cda3f953f10e4c808 @RandomEtc committed Feb 9, 2013
Showing with 61 additions and 62 deletions.
  1. +1 −0 .gitignore
  2. +4 −0 CHANGES
  3. +18 −20 GPX.java
  4. +11 −13 GPXPoint.java
  5. +8 −9 GPXTrack.java
  6. +7 −8 GPXTrackSeg.java
  7. +10 −10 GPXWayPoint.java
  8. +2 −2 Makefile
  9. BIN library/gpx.jar
View
@@ -1,2 +1,3 @@
classes
tomc
+test.gpx.xml
View
@@ -1,3 +1,7 @@
+09/02/2011 13:27 PST
+--------------------
+
+Updated for Processing 2.0+, closes #2.
01/06/2011 10:33 PDT
--------------------
View
@@ -41,7 +41,7 @@
import processing.core.PApplet;
import java.util.Vector;
-import processing.xml.XMLElement;
+import processing.data.XML;
/** contains a collection of GPXTrack objects and GPXWayPoint objects */
public class GPX {
@@ -52,17 +52,15 @@
private Vector wayPoints = new Vector();
private Vector tracks = new Vector();
-
+
public GPX(PApplet parent) {
- this.parent = parent;
+ this.parent = parent;
}
-
- public void parse(String url) {
+
+ public void parse(String url) {
try {
- XMLElement xmldata = new XMLElement(parent, url);
- XMLElement[] xmlthings = xmldata.getChildren();
- for (int i = 0; i < xmlthings.length; i++) {
- XMLElement xmlthing = xmlthings[i];
+ XML xmldata = parent.loadXML(url);
+ for (XML xmlthing : xmldata.getChildren()) {
if (xmlthing.getName().equals("trk")) {
addTrack(new GPXTrack(xmlthing));
}
@@ -72,40 +70,40 @@ else if (xmlthing.getName().equals("wpt")) {
}
}
catch(Exception e) {
- e.printStackTrace();
- }
+ e.printStackTrace();
+ }
}
/* Tracks */
-
+
public void addTrack(GPXTrack trk) {
- tracks.addElement(trk);
+ tracks.addElement(trk);
}
public void removeTrack(GPXTrack trk) {
- tracks.removeElement(trk);
+ tracks.removeElement(trk);
}
public GPXTrack getTrack(int i) {
- return (GPXTrack)tracks.elementAt(i);
+ return (GPXTrack)tracks.elementAt(i);
}
public int getTrackCount() {
return tracks.size();
}
/* WayPoints */
-
+
public void addWayPoint(GPXWayPoint wpt) {
- wayPoints.addElement(wpt);
+ wayPoints.addElement(wpt);
}
public void removeWayPoint(GPXWayPoint wpt) {
- wayPoints.removeElement(wpt);
+ wayPoints.removeElement(wpt);
}
public GPXWayPoint getWayPoint(int i) {
- return (GPXWayPoint)wayPoints.elementAt(i);
+ return (GPXWayPoint)wayPoints.elementAt(i);
}
public int getWayPointCount() {
@@ -139,6 +137,6 @@ public static void main(String[] args) {
System.err.println("no filename supplied");
}
}
-
+
}
View
@@ -23,9 +23,9 @@
import java.util.Date;
import java.text.SimpleDateFormat;
-import processing.xml.XMLElement;
+import processing.data.XML;
-/** simple GPX point, only understands latitude, longitude, elevation and time
+/** simple GPX point, only understands latitude, longitude, elevation and time
FIXME extend parsing to understand other properties */
public class GPXPoint {
@@ -34,25 +34,25 @@
public double lat,lon;
public double ele;
- public Date time;
+ public Date time;
public GPXPoint() {
- this.lat = 0.0;
- this.lon = 0.0;
- this.ele = 0.0;
+ this.lat = 0.0;
+ this.lon = 0.0;
+ this.ele = 0.0;
this.time = new Date();
}
-
- public GPXPoint(double lat, double lon, double ele, Date time) {
+
+ public GPXPoint(double lat, double lon, double ele, Date time) {
this.lat = lat;
this.lon = lon;
this.ele = ele;
this.time = time;
}
- /** parses a GPXPoint from the given XMLElement
+ /** parses a GPXPoint from the given XML
understands 2 time formats: ISO 8601 with and without milliseconds */
- public GPXPoint(XMLElement trkpt) {
+ public GPXPoint(XML trkpt) {
// NB:- this is a bit more complex than it should be
// but it should handle a wider variety of broken
@@ -82,9 +82,7 @@ public GPXPoint(XMLElement trkpt) {
this.lon = 0.0;
}
- XMLElement[] children = trkpt.getChildren();
- for (int i = 0; i < children.length; i++) {
- XMLElement element = children[i];
+ for (XML element : trkpt.getChildren()) {
if (element.getName().equals("ele")) {
try {
String sEle = element.getContent();
View
@@ -21,32 +21,31 @@
package tomc.gpx;
-import processing.xml.XMLElement;
+import processing.data.XML;
import java.util.Vector;
/** a collection of GPXTrackSeg objects, with type-safe convenience methods for adding/removing/getting track segments */
public class GPXTrack extends Vector {
public String name;
- public GPXTrack(XMLElement xmltrk) {
+ public GPXTrack(XML xmltrk) {
this.name = xmltrk.getChild("name").getContent();
- XMLElement[] children = xmltrk.getChildren("trkseg");
- for (int i = 0; i < children.length; i++) {
- this.addTrackSeg(new GPXTrackSeg(children[i]));
+ for (XML child : xmltrk.getChildren("trkseg")) {
+ this.addTrackSeg(new GPXTrackSeg(child));
}
}
-
+
public GPXTrackSeg getTrackSeg(int i) {
return (GPXTrackSeg)elementAt(i);
}
-
+
public void addTrackSeg(GPXTrackSeg trkseg) {
addElement(trkseg);
}
-
+
public void removeTrackSeg(GPXTrackSeg trkseg) {
removeElement(trkseg);
}
-
+
}
View
@@ -21,29 +21,28 @@
package tomc.gpx;
-import processing.xml.XMLElement;
+import processing.data.XML;
import java.util.Vector;
/** a collection of GPXPoint objects, with type-safe convenience methods for adding/removing/getting points */
public class GPXTrackSeg extends Vector {
- public GPXTrackSeg(XMLElement trkseg) {
- XMLElement[] children = trkseg.getChildren("trkpt");
- for (int i = 0; i < children.length; i++) {
- addPoint(new GPXPoint(children[i]));
+ public GPXTrackSeg(XML trkseg) {
+ for (XML child : trkseg.getChildren("trkpt")) {
+ addPoint(new GPXPoint(child));
}
}
public void addPoint(GPXPoint trkpt) {
- addElement(trkpt);
+ addElement(trkpt);
}
public GPXPoint getPoint(int i) {
- return (GPXPoint)elementAt(i);
+ return (GPXPoint)elementAt(i);
}
public void removePoint(GPXPoint trkpt) {
- removeElement(trkpt);
+ removeElement(trkpt);
}
}
View
@@ -21,32 +21,32 @@
package tomc.gpx;
-import processing.xml.XMLElement;
+import processing.data.XML;
-/** simple GPX waypoint, only understands latitude, longitude, name and type
+/** simple GPX waypoint, only understands latitude, longitude, name and type
FIXME extend parsing to understand other properties */
public class GPXWayPoint {
public double lat,lon;
public String name;
public String type;
-
+
public GPXWayPoint() {
- this.lat = 0.0;
- this.lon = 0.0;
- this.name = "";
+ this.lat = 0.0;
+ this.lon = 0.0;
+ this.name = "";
this.type = "";
}
-
- public GPXWayPoint(double lat, double lon, String name, String type) {
+
+ public GPXWayPoint(double lat, double lon, String name, String type) {
this.lat = lat;
this.lon = lon;
this.name = name;
this.type = type;
}
- /** parses a GPXWayPoint from the given XMLElement */
- public GPXWayPoint(XMLElement trkpt) {
+ /** parses a GPXWayPoint from the given XML */
+ public GPXWayPoint(XML trkpt) {
this.lat = trkpt.getDouble("lat");
this.lon = trkpt.getDouble("lon");
this.name = trkpt.getChild("name").getContent();
View
@@ -1,5 +1,5 @@
-PROCESSING_CORE = /Applications/Processing.app/Contents/Resources/Java/core.jar
+PROCESSING_CORE = /Applications/Processing.app/Contents/Resources/Java/core/library/core.jar
SRC_FILES = \
GPX.java \
@@ -9,7 +9,7 @@ SRC_FILES = \
GPXTrackSeg.java
library/gpx.jar: $(SRC_FILES) Makefile
- javac -cp $(PROCESSING_CORE) -sourcepath src -d . -target 1.1 -source 1.3 $(SRC_FILES)
+ javac -cp $(PROCESSING_CORE) -sourcepath src -d . -target 1.5 -source 5 $(SRC_FILES)
jar -Mcvf library/gpx.jar tomc/gpx/*.class
test:
View
Binary file not shown.

0 comments on commit 9b326dc

Please sign in to comment.