1 /*****************************************************************************
2 * Virtual Mockup for Machine Vision
3 * Copyright (C) 2001-2003 Fabio R. de Miranda, João E. Kogler Jr.,
4 * Carlos S. Santos.
5 * Virtual Mockup for Machine Vision Project funded by SENAC-SP
6 *
7 * Permission is granted to redistribute and/or modify this
8 * software under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License (http://www.gnu.org/copyleft/lesser.html)
16 * for more details.
17 *
18 *****************************************************************************/
19
20 package camera3d;
21
22 import org.jdom.*;
23
24 /***
25 * Object that handles conversion between a DistanceMeasurer object and its XML
26 * representation.
27 *
28 * @author Fábio Roberto de Miranda, Carlos da Silva dos Santos
29 * @version 1.0
30 */
31 class DistanceMeasurerXMLHandler extends VcObjectXMLHandler {
32
33 /*** Attribute to signal whether the target is bound to the measurer main object. */
34 private static final String boundAttrib = "Bound";
35
36 private DistanceMeasurer measurer;
37 private Element targetElement;
38 private Element element;
39
40 public DistanceMeasurerXMLHandler() {
41 super();
42 this.type = "DistanceMeasurer";
43 }
44
45 /***
46 * Creates XML element from DistanceMeasurer object.
47 */
48 public Element createElement(VcObject obj){
49 if(!(obj instanceof DistanceMeasurer)) return null;
50 element = super.createElement(obj);
51 measurer =(DistanceMeasurer) obj;
52 measurer.setBound(false);
53
54 String ax;
55 if(measurer.isBound()) ax = trueString;
56 else ax = falseString;
57 element.setAttribute(boundAttrib,ax);
58
59 VcObject target = (VcObject) measurer.getTarget();
60 targetElement = super.createElement(target);
61 targetElement.setName("Target");
62 element.addContent(targetElement);
63
64 return element;
65 }
66
67 /***
68 * Creates an DistanceMeasurer from a XML element describing it.
69 */
70 public VcObject createObject(Element el){
71 if(!type.equals(el.getName())) return null;
72 DistanceMeasurer measurer = new DistanceMeasurer();
73 initializeObject(el,measurer);
74 String ax = el.getAttributeValue(boundAttrib);
75 if(ax!=null){
76 //cannot use setBound cause it depends on the object being live
77 //if(ax.equals(falseString)) measurer.setBound(false);
78 //else measurer.setBound(true);
79 }
80
81 targetElement = el.getChild("Target");
82 if(targetElement!=null){
83 VcObject target = (VcObject) measurer.getTarget();
84 super.initializeObject(targetElement,target);
85 }
86 return (VcObject)measurer;
87 }
88
89 /***
90 * Adds DistanceMeasurer to scene graph
91 * @param vcObject DistanceMeasurer to be added.
92 * @param base object that will receive the measurer.
93 */
94 void addObject(VcObject vcObject, J3DBase base){
95 if(!(vcObject instanceof DistanceMeasurer))return;
96 VcObject obj = base.getByLabel(vcObject.getLabel());
97 if(obj!=null){
98 if(obj instanceof DistanceMeasurer) base.removeVcObject(obj);
99 else obj.setLabel("_"+obj.getLabel());
100 }
101 base.addHelper((VcHelper)vcObject);
102 }
103
104 }
This page was automatically generated by Maven