⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 defaultenvironmentlightsuielement.java

📁 Java 3D Desktop Environment旨在使用Java 3D来创建一个3D桌面环境。功能包括:分布式的应用程序
💻 JAVA
字号:
package org.j3de.ui.impl;

import java.util.List;

import javax.swing.event.ChangeListener;

import javax.media.j3d.AmbientLight;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.DirectionalLight;
import javax.media.j3d.PointLight;
import javax.media.j3d.TransformGroup;
import javax.media.j3d.Transform3D;

import javax.vecmath.Color3f;
import javax.vecmath.Point3d; 
import javax.vecmath.Point3f; 
import javax.vecmath.Vector3f;

import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;

import org.j3de.exception.ExceptionHandler;    
import org.j3de.ui.Skin;
import org.j3de.ui.Skinable;
import org.j3de.ui.SkinException;
import org.j3de.ui.UIElement;
import org.j3de.ui.UILocalElement;  
import org.j3de.ui.EnvironmentLightsUIElement;
import org.j3de.util.ConfigHelper;      
import org.j3de.util.EntryFactory;      
import org.j3de.util.StringParser;

public class DefaultEnvironmentLightsUIElement implements UILocalElement, Skinable {
  private BranchGroup                lights;
  private EnvironmentLightsUIElement uiRemoteElement;  
  
  public DefaultEnvironmentLightsUIElement() {
    lights = new BranchGroup();  
    uiRemoteElement = new RemoteEnvironmentLightsUIElement();
  }
  
  public javax.media.j3d.Node getNode() { 
    return lights;
  }             
  
  public UIElement getRemoteElement() {
    return uiRemoteElement;
  }             
  
  private void addList(List list) {
    for (int i=0; i<list.size(); i++) {
      lights.addChild((javax.media.j3d.Node)list.get(i));       
    }
  }                                                                         
    
  public void setSkin(final Skin skin) throws SkinException {       
    ConfigHelper helper = new ConfigHelper(skin.getXMLFragment("environment_lights"));
    
    List ambientLights = helper.getList("ambient", 
      new EntryFactory() {
        public Object createEntry(Node node) {  
          try {                             
            NamedNodeMap attributes = node.getAttributes();  
            String color = attributes.getNamedItem("color").getNodeValue();
            String range = attributes.getNamedItem("range").getNodeValue();
            
            AmbientLight light = new AmbientLight(skin.getColorByName(color));
            light.setInfluencingBounds(new BoundingSphere(new Point3d(0.0,0.0,0.0), Integer.parseInt(range))); 
            
            return light;
          } catch (Exception e) {
            ExceptionHandler.handleException(e);
          }
          return null;
        }
      }
    ); 
    
    List directionalLights = helper.getList("directional",
      new EntryFactory() {
        public Object createEntry(Node node) {  
          try {                             
            NamedNodeMap attributes = node.getAttributes();  
            String color     = attributes.getNamedItem("color").getNodeValue();
            String range     = attributes.getNamedItem("range").getNodeValue();
            String direction = attributes.getNamedItem("direction").getNodeValue();
            String position  = attributes.getNamedItem("position").getNodeValue();
            
            DirectionalLight light = new DirectionalLight(true,
                                                          skin.getColorByName(color),
                                                          StringParser.parseVector3f(direction));
            light.setInfluencingBounds(new BoundingSphere(new Point3d(0.0,0.0,0.0), Integer.parseInt(range))); 
            
            TransformGroup lightPos = new TransformGroup();
            Transform3D t3d = new Transform3D();
            t3d.set(StringParser.parseVector3f(position));
            lightPos.setTransform(t3d);
            lightPos.addChild(light);
            
            return lightPos;
          } catch (Exception e) {
            ExceptionHandler.handleException(e);
          }
          return null;
        }
      }
    );
    
    List pointLights = helper.getList("point",
      new EntryFactory() {
        public Object createEntry(Node node) {  
          try {                             
            NamedNodeMap attributes = node.getAttributes();  
            String color       = attributes.getNamedItem("color").getNodeValue();
            String range       = attributes.getNamedItem("range").getNodeValue();
            String attenuation = attributes.getNamedItem("attenuation").getNodeValue();
            String position    = attributes.getNamedItem("position").getNodeValue();
            
            PointLight light = new PointLight(true,
                                              skin.getColorByName(color),
                                              StringParser.parsePoint3f(position),
                                              StringParser.parsePoint3f(attenuation));
            light.setInfluencingBounds(new BoundingSphere(new Point3d(0.0,0.0,0.0), Integer.parseInt(range))); 
            
            TransformGroup lightPos = new TransformGroup();
            Transform3D t3d = new Transform3D();
            t3d.set(StringParser.parseVector3f(position));
            lightPos.setTransform(t3d);
            lightPos.addChild(light);
            
            return lightPos;
          } catch (Exception e) {
            ExceptionHandler.handleException(e);
          }
          return null;
        }
      }
    );  
    
    addList(ambientLights);
    addList(directionalLights);
    addList(pointLights);
  }     

  /** Add a ChangeListener, that is notified, when the Bounds of the UIElement change. */
  public void addBoundsChangeListener(ChangeListener listener) {
  }

  /** Remove a ChangeListener, that is notified, when the Bounds of the UIElement change. */
  public void removeBoundsChangeListener(ChangeListener listener) {
  }               
  
  /** Dummy implementation, EnvironmentLights should not be accessed from a remote location. */
  private class RemoteEnvironmentLightsUIElement implements EnvironmentLightsUIElement {   
  }
  
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -