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 /***
23 *
24 * @author Fábio Roberto de Miranda e Carlos da Silva dos Santos
25 */
26
27 import org.jdom.*;
28
29 abstract class VcLightXMLHandler extends VcObjectXMLHandler {
30
31 private static final String redAttrib = "red";
32 private static final String blueAttrib = "blue";
33 private static final String greenAttrib = "green";
34 private static final String enableAttrib = "Enable";
35
36 VcLightXMLHandler() {
37 super();
38 }
39
40 Element createElement(VcObject obj){
41 if(!(obj instanceof VcLight)) return null;
42 element = super.createElement(obj);
43 VcLight light = (VcLight) obj;
44 // set light parameters
45 element.setAttribute(redAttrib,Float.toString(light.getRed()));
46 element.setAttribute(greenAttrib,Float.toString(light.getGreen()));
47 element.setAttribute(blueAttrib,Float.toString(light.getBlue()));
48 String ax;
49 if(light.isEnabled()) ax = trueString;
50 else ax = falseString;
51 element.setAttribute(enableAttrib,ax);
52 //
53 return element;
54 }
55
56 abstract VcObject createObject(Element el);
57
58 /***
59 * Initializes a VcLight, copying state and color attributes from XML element.
60 * @param el describes VcLight.
61 * @param obj must be a VcLight.
62 */
63 void initializeObject(Element el,VcObject obj){
64 super.initializeObject(el,obj);
65 if(!(obj instanceof VcLight)) return;
66 VcLight light = (VcLight)obj;
67 float red=1.0f,green=1.0f,blue=1.0f;
68 try{
69 red = el.getAttribute(redAttrib).getFloatValue();
70 green = el.getAttribute(greenAttrib).getFloatValue();
71 blue = el.getAttribute(blueAttrib).getFloatValue();
72 }catch(org.jdom.DataConversionException dce ){
73 dce.printStackTrace();
74 }
75 String ax = el.getAttributeValue(enableAttrib);
76 if(ax.equals(falseString)) light.setEnable(false);
77 else light.setEnable(true);
78 light.setColor(red,green,blue);
79 }
80
81 abstract void addObject(VcObject vcObject, J3DBase base);
82
83 }
This page was automatically generated by Maven