View Javadoc

1   /*
2    * @(#)$Id: JdomRecordedGesture3D.java
3    * 
4    * Author       :   Arthur Vogels, arthur.vogels@gmail.com
5    *
6    * Purpose      :   Constructs an XML representation of a RecordedGesture3D represented
7    *                  by a list of Point3D's.
8    *
9    * -----------------------------------------------------------------------
10   *
11   * Revision Information:
12   *
13   * Date             Who         Reason
14   *
15   * Jan 04, 2009     vogelsar    Initial Release
16   *
17   * -----------------------------------------------------------------------
18   *
19   * Copyright 1999-2009 ETH Zurich. All Rights Reserved.
20   *
21   * This software is the proprietary information of ETH Zurich.
22   * Use is subject to license terms.
23   * 
24   */
25  
26  package org.ximtec.igesture.util.additions3d.jdom;
27  
28  import java.util.List;
29  
30  import org.jdom.Element;
31  import org.ximtec.igesture.util.additions3d.Point3D;
32  import org.ximtec.igesture.util.additions3d.RecordedGesture3D;
33  import org.ximtec.igesture.util.additions3d.jdom.JdomAccelerations;
34  
35  
36  /**
37   * Constructs an XML representation of a RecordedGesture3D represented by a list of Point3D's.
38   * @version 1.0, Jan 2009
39   * @author Arthur Vogels, arthur.vogels@gmail.com
40   */
41  public class JdomRecordedGesture3D extends Element {
42  
43     public static final String ROOT_TAG = "recordedGesture3D";
44  
45  
46     public JdomRecordedGesture3D(RecordedGesture3D gesture) {
47        super(ROOT_TAG);
48  
49        for (Point3D point : gesture.getPoints()) {
50           addContent(new JdomPoint3D(point));
51        }
52        
53        addContent(new JdomAccelerations(gesture.getAccelerations()));
54     }
55  
56  
57     @SuppressWarnings("unchecked")
58     public static RecordedGesture3D unmarshal(Element gesture) {
59        RecordedGesture3D newGesture = new RecordedGesture3D();
60  
61        for (Element point : (List<Element>)gesture.getChildren(JdomPoint3D.ROOT_TAG)) {
62           newGesture.add(JdomPoint3D.unmarshal(point));
63        }
64        
65        Element acc = gesture.getChild(JdomAccelerations.ROOT_TAG);
66        newGesture.setAccelerations(JdomAccelerations.unmarshal(acc));
67  
68        return newGesture;
69     } // unmarshal
70  
71  }