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

📄 stringparser.java

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

import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.StringTokenizer;

import javax.media.j3d.ColoringAttributes;
import javax.media.j3d.PointAttributes;
import javax.media.j3d.PolygonAttributes;
import javax.media.j3d.RenderingAttributes;
import javax.media.j3d.TransparencyAttributes;
import javax.vecmath.Color3f;
import javax.vecmath.Vector3f;
import javax.vecmath.Vector3d;
import javax.vecmath.Point3f;
import javax.vecmath.Point3d;

import org.j3de.exception.ExceptionHandler;
import org.j3de.ui.Skin;

public class StringParser {
  
  /** This class should not be instantiated */
  private StringParser() {
  }   
                                          
  public static Vector3d parseVector3d(String vector) {
    StringTokenizer st = new StringTokenizer(vector);
    double x = Double.parseDouble(st.nextToken());
    double y = Double.parseDouble(st.nextToken());
    double z = Double.parseDouble(st.nextToken());
       
    return new Vector3d(x, y, z); 
  }   

  public static Point3d parsePoint3d(String point) {
    return new Point3d(parseVector3d(point));
  }

  public static Vector3f parseVector3f(String vector) {
    return new Vector3f(parseVector3d(vector)); 
  }                                                                                    
  
  public static Color3f parseColor3f(String color) {
    return new Color3f(parseVector3f(color));
  } 

  public static Point3f parsePoint3f(String point) {
    return new Point3f(parseVector3f(point));
  }
  
  public static ColoringAttributes parseColoringAttributes(String attributes, Skin skin) throws Exception {
    StringTokenizer st = new StringTokenizer(attributes);  
    Color3f color = skin.getColorByName(st.nextToken());    
    int shadeModel = ColoringAttributes.SHADE_FLAT;
    
    String shading = st.nextToken();
    
    if (shading.equals("SHADE_FLAT")) {
      shadeModel = ColoringAttributes.SHADE_FLAT;
    } else if (shading.equals("SHADE_GOURAUD")) {  
      shadeModel = ColoringAttributes.SHADE_GOURAUD;  
    }   
        
    return new ColoringAttributes(color, shadeModel);
  }

  public static TransparencyAttributes parseTransparencyAttributes(final String attributes) throws Exception {
    // Calling code might have accessDeclaredMembers permission, so we have to do this privileged
    return (TransparencyAttributes)AccessController.doPrivileged(new PrivilegedAction() {
      public Object run() {   
        try {
          StringTokenizer st = new StringTokenizer(attributes);  
    
          int   tMode = 
            ((Integer)TransparencyAttributes.class.getDeclaredField(st.nextToken()).get(null)).intValue();
    
          float tVal  = Float.parseFloat(st.nextToken());
    
          int srcBlendFunction  = 
            ((Integer)TransparencyAttributes.class.getDeclaredField(st.nextToken()).get(null)).intValue();   
      
          int dstBlendFunction = 
            ((Integer)TransparencyAttributes.class.getDeclaredField(st.nextToken()).get(null)).intValue();  
      
          return new TransparencyAttributes(tMode, tVal, srcBlendFunction,dstBlendFunction);  
        } catch (Exception e) {
          ExceptionHandler.handleException(e); 
          return null;
        } 
      }
    }); 
    
  }

  public static PolygonAttributes parsePolygonAttributes(final String attributes) throws Exception {
    // Calling code might have accessDeclaredMembers permission, so we have to do this privileged
    return (PolygonAttributes)AccessController.doPrivileged(new PrivilegedAction() {
      public Object run() {   
        try {
          StringTokenizer st = new StringTokenizer(attributes);    
        
          int polygonMode =
            ((Integer)PolygonAttributes.class.getDeclaredField(st.nextToken()).get(null)).intValue();
          
          int cullFace =                             
            ((Integer)PolygonAttributes.class.getDeclaredField(st.nextToken()).get(null)).intValue();
        
          float polygonOffset = Float.parseFloat(st.nextToken());
          
          boolean backFaceNormalFlip = st.nextToken().equals("true");
          
          float polygonOffsetFactor = Float.parseFloat(st.nextToken());
          
          return new PolygonAttributes(polygonMode, cullFace, polygonOffset, backFaceNormalFlip, polygonOffsetFactor);
        } catch (Exception e) {
          ExceptionHandler.handleException(e); 
          return null;
        } 
      }
    }); 
  }
  
  public static PointAttributes parsePointAttributes(String attributes) throws Exception {
    StringTokenizer st = new StringTokenizer(attributes);     
    
    float   pointSize = Float.parseFloat(st.nextToken());      
    boolean pointAntialiasing = st.nextToken().equals("true");
    
    return new PointAttributes(pointSize, pointAntialiasing); 
  }      public static RenderingAttributes parseRenderingtAttributes(String attributes) throws Exception {
    StringTokenizer st = new StringTokenizer(attributes);         // TODO: parse rendering attributes    return new RenderingAttributes();  }    
}

⌨️ 快捷键说明

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