1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 package org.ximtec.igesture.util.additions3d.jdom;
27
28 import org.jdom.Element;
29 import org.sigtec.jdom.element.JdomDoubleElement;
30 import org.sigtec.jdom.element.JdomLongElement;
31 import org.ximtec.igesture.util.additions3d.Point3D;
32
33
34
35
36
37
38
39 public class JdomPoint3D extends Element {
40
41 public static final String ROOT_TAG = "point3D";
42 public static final String POINT_ELEMENT_X = "x";
43 public static final String POINT_ELEMENT_Y = "y";
44 public static final String POINT_ELEMENT_Z = "z";
45 public static final String POINT_ELEMENT_TIMESTAMP = "timestamp";
46
47 public JdomPoint3D(Point3D point) {
48 super(ROOT_TAG);
49 addContent(new JdomDoubleElement(POINT_ELEMENT_X, point.getX()));
50 addContent(new JdomDoubleElement(POINT_ELEMENT_Y, point.getY()));
51 addContent(new JdomDoubleElement(POINT_ELEMENT_Z, point.getZ()));
52
53 if (point.hasTimeStamp()) {
54 addContent(new JdomLongElement(POINT_ELEMENT_TIMESTAMP, point
55 .getTimeStamp()));
56 }
57
58 }
59
60
61 public static Point3D unmarshal(Element point) {
62 Point3D newPoint = new Point3D(Double.parseDouble(point
63 .getChildText(POINT_ELEMENT_X)), Double.parseDouble(point
64 .getChildText(POINT_ELEMENT_Y)), Double.parseDouble(point
65 .getChildText(POINT_ELEMENT_Z)), 0);
66 setTimestamp(newPoint, point);
67 return newPoint;
68 }
69
70
71 private static void setTimestamp(Point3D point, Element source) {
72 Element timestamp = source.getChild(POINT_ELEMENT_TIMESTAMP);
73
74 if (timestamp != null) {
75 point.setTimeStamp(Long.parseLong(timestamp.getText()));
76 }
77
78 }
79
80 }