View Javadoc
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 * 26 * @author Carlos da Silva dos Santos 27 */ 28 class VcSpotLightXMLHandler extends VcLightXMLHandler { 29 30 private static final String concenAttrib = "Concentration"; 31 private static final String spreadAttrib = "SpreadAngle"; 32 33 34 public VcSpotLightXMLHandler() { 35 super(); 36 this.type = "VcSpotLight"; 37 } 38 39 Element createElement(VcObject obj){ 40 if(!(obj instanceof VcSpotLight)) return null; 41 Element element = super.createElement(obj); 42 VcSpotLight light = (VcSpotLight) obj; 43 //element.setName(type); 44 element.setAttribute(concenAttrib,Double.toString(light.getConcentration())); 45 element.setAttribute(spreadAttrib,Double.toString(light.getSpreadAngle())); 46 return element; 47 } 48 49 VcObject createObject (Element el){ 50 if(!type.equals(el.getName())) return null; 51 VcSpotLight light = new VcSpotLight(); 52 initializeObject(el,light); 53 return (VcObject)light; 54 } 55 56 /*** 57 * Sets concentration and spread angle attributes for a given VcSpotLight. This 58 * method will print an error message and return without doing anything if the 59 * VcObject given as input parameter is not an instance of VcSpotLight. 60 * @param el Element containing VcSpotLight parameters. 61 * @param obj VcSpotLight whose parametes will be set. 62 */ 63 void initializeObject(Element el,VcObject obj){ 64 super.initializeObject(el,obj); 65 if(!(obj instanceof VcSpotLight)){ 66 System.err.println("VcSpotLightXMLHandler: object for initialization is not a VcSpotLight"); 67 return; 68 } 69 VcSpotLight light = (VcSpotLight) obj; 70 try{ 71 double conc,spread; 72 conc = el.getAttribute(concenAttrib).getDoubleValue(); 73 spread = el.getAttribute(spreadAttrib).getDoubleValue(); 74 light.setConcentration(conc); 75 light.setSpreadAngle(spread); 76 } catch(org.jdom.DataConversionException dce){ 77 dce.printStackTrace(); 78 } 79 } 80 81 /*** 82 * Adds a new SpotLight to the scene graph. The VcObject given as input parameter 83 * must be an instance of VcSpotLight, otherwise this method will return without 84 * doing anything. 85 * @param vcObject VcSpotLiight to be added. 86 * @param base object that will receive the new light. 87 */ 88 void addObject(VcObject vcObject, J3DBase base){ 89 if(!(vcObject instanceof VcSpotLight)){ 90 System.err.println("VcSpotLightXMLHandler: object to be added to scene graph is not a VcSpotLight"); 91 return; 92 } 93 // checks whether an objects by the same name already exists; it will discard 94 // the old object if it is a VcSpotLight, otherwise it will keep the old object, 95 // but changing its name 96 VcObject obj = base.getByLabel(vcObject.getLabel()); 97 if(obj!=null){ 98 if(obj instanceof VcSpotLight) base.removeVcObject(obj); 99 else obj.setLabel("_"+obj.getLabel()); 100 } 101 base.addLight((VcSpotLight)vcObject); 102 } 103 104 }

This page was automatically generated by Maven