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

📄 scenegraphobjectstate.java

📁 JAVA3D矩陈的相关类
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * This method MUST be implemented by all State objects but is not     * abstract to allow for external subclassing     */    protected SceneGraphObject createNode() {	throw new SGIORuntimeException("createNode() not implemented in class "+this.getClass().getName());    }        /**      * Create a new Java3D node from the supplied class using the parameterless constructor      *       * For Java3D nodes which do not have a default constructor you must      * overload this method and create the object using createNode( className, parameters )      * This will correctly handle subclasses of Java3D classes     */    protected SceneGraphObject createNode( Class state ) {	SceneGraphObject ret;	try {	    ret = (SceneGraphObject)state.newInstance();	    //System.err.println("Created J3D node for "+className );	} catch( IllegalAccessException exce ) {	    throw new SGIORuntimeException( "Broken State class for "+						state.getClass().getName()+" - IllegalAccess" );	} catch( InstantiationException excep ) {	    throw new SGIORuntimeException( "Broken State class for "+						state.getClass().getName() );	}	return ret;    }            /**      * Create a new Java3D node from the supplied class name using the parameterless constructor      *       * For Java3D nodes which do not have a default constructor you must      * overload this method and create the object using createNode( className, parameters )      * This will correctly handle subclasses of Java3D classes     */    protected SceneGraphObject createNode( String className ) {	SceneGraphObject ret;	try {            Class state = Class.forName( className, true, control.getClassLoader() );            	    ret = createNode( state );	    //System.err.println("Created J3D node for "+className );	} catch(ClassNotFoundException e) {            if (control.useSuperClassIfNoChildClass())                ret = createNodeFromSuper( className );            else                throw new SGIORuntimeException( "No Such Class "+						className );	}	return ret;    }        /**     * If createNode cannot locate the correct class to instantiate     * the node this method is called and will instantiate the     * node using it's Java3D Core superclass     */    private SceneGraphObject createNodeFromSuper( String className ) {	SceneGraphObject ret;                String tmp = this.getClass().getName();        String superClass = tmp.substring( tmp.indexOf("state")+6, tmp.length()-5 );        System.err.println("Unable to create node "+className+" attempting Java3D superclass "+superClass );        	try {            Class state = Class.forName( superClass );            	    ret = (SceneGraphObject)state.newInstance();	} catch(ClassNotFoundException e) {	    throw new SGIORuntimeException( "No Such Class "+						className );	} catch( IllegalAccessException exce ) {	    throw new SGIORuntimeException( "Broken State class for "+						className+" - IllegalAccess" );	} catch( InstantiationException excep ) {	    throw new SGIORuntimeException( "Unable to instantiate class "+						className );	}                return ret;    }        /**     * Create a Java3D node which does not have a default constructor     *     * parameterTypes must contain the classes required by the constructor,     * use Integer.TYPE, Float.TYPE etc to specifiy primitive types     *     * paramters should contain the list of parameters for the constructor,     * primitive types should be wrapped in the appropriate class (ie Integer, Float )     */    private SceneGraphObject createNode( String className, Class[] parameterTypes, Object[] parameters ) {        SceneGraphObject ret;        Constructor constructor;        try {            Class state = Class.forName( className );            constructor = state.getConstructor( parameterTypes );            ret = (SceneGraphObject)constructor.newInstance( parameters );	} catch(ClassNotFoundException e1) {            if (control.useSuperClassIfNoChildClass())                ret = createNodeFromSuper( className, parameterTypes, parameters );            else                throw new SGIORuntimeException( "No State class for "+						className );	} catch( IllegalAccessException e2 ) {	    throw new SGIORuntimeException( "Broken State class for "+						className+" - IllegalAccess" );	} catch( InstantiationException e3 ) {	    throw new SGIORuntimeException( "Broken State class for "+						className );        } catch( java.lang.reflect.InvocationTargetException e4 ) {	    throw new SGIORuntimeException( "InvocationTargetException for "+						className );        } catch( NoSuchMethodException e5 ) {            for(int i=0; i<parameterTypes.length; i++)                System.err.println( parameterTypes[i].getName() );            System.err.println("------");	    throw new SGIORuntimeException( "Invalid constructor for "+						className );        }                return ret;    }    /**     * Create a Java3D node which does not have a default constructor     *     * parameterTypes must contain the classes required by the constructor,     * use Interger.TYPE, Float.TYPE etc to specifiy primitive types     *     * paramters should contain the list of parameters for the constructor,     * primitive types should be wrapped in the appropriate class (ie Integer, Float )     */    protected SceneGraphObject createNode( Class j3dClass, Class[] parameterTypes, Object[] parameters ) {        SceneGraphObject ret;        Constructor constructor;        try {            constructor = j3dClass.getConstructor( parameterTypes );            ret = (SceneGraphObject)constructor.newInstance( parameters );	} catch( IllegalAccessException e2 ) {	    throw new SGIORuntimeException( "Broken State class for "+						j3dClass.getClass().getName()+" - IllegalAccess" );	} catch( InstantiationException e3 ) {	    throw new SGIORuntimeException( "Broken State class for "+						j3dClass.getClass().getName() );        } catch( java.lang.reflect.InvocationTargetException e4 ) {	    throw new SGIORuntimeException( "InvocationTargetException for "+						j3dClass.getClass().getName() );        } catch( NoSuchMethodException e5 ) {            for(int i=0; i<parameterTypes.length; i++)                System.err.println( parameterTypes[i].getName() );            System.err.println("------");	    throw new SGIORuntimeException( "Invalid constructor for "+						j3dClass.getClass().getName() );        }                return ret;    }        /**     * If createNode cannot locate the correct class to instantiate     * the node this method is called and will instantiate the     * node using it's Java3D Core superclass     */    private SceneGraphObject createNodeFromSuper( String className, Class[] parameterTypes, Object[] parameters ) {	SceneGraphObject ret;                String tmp = this.getClass().getName();        String superClass = tmp.substring( tmp.indexOf("state")+6, tmp.length()-5 );        Constructor constructor;        try {            Class state = Class.forName( superClass );            constructor = state.getConstructor( parameterTypes );            ret = (SceneGraphObject)constructor.newInstance( parameters );	} catch(ClassNotFoundException e1) {	    throw new SGIORuntimeException( "No State class for "+						superClass );	} catch( IllegalAccessException e2 ) {	    throw new SGIORuntimeException( "Broken State class for "+						className+" - IllegalAccess" );	} catch( InstantiationException e3 ) {	    throw new SGIORuntimeException( "Broken State class for "+						className );        } catch( java.lang.reflect.InvocationTargetException e4 ) {	    throw new SGIORuntimeException( "InvocationTargetException for "+						className );        } catch( NoSuchMethodException e5 ) {            for(int i=0; i<parameterTypes.length; i++)                System.err.println( parameterTypes[i].getName() );            System.err.println("------");	    throw new SGIORuntimeException( "Invalid constructor for "+						className );        }                return ret;    }    /**      * Given a scene graph object instantiate the correct State class      * for that object      */    protected SceneGraphObjectState createState( SceneGraphObject obj, Controller control ) {        return control.createState( obj );    }    /**      * Return the class name of the Class, the fully qualified classname      * is stripped of all package information and returned      */    private String getClassName( Class c ) {	return c.getName().substring(c.getName().lastIndexOf('.')+1);    }    /**     * Subclasses should processes their own buildGraph requirements BEFORE     * calling super.buildGraph().     *     * This ensures that when restoreSceneGraphObjectReferences is called in     * user code our references have been resolved     */    public void buildGraph() {        //System.err.println("Build Graph "+this);            if (node instanceof com.sun.j3d.utils.scenegraph.io.SceneGraphIO)                ((com.sun.j3d.utils.scenegraph.io.SceneGraphIO)node).restoreSceneGraphObjectReferences( control.getSymbolTable() );    }        public void cleanup() {        control = null;        node = null;    }        /**     * Read and return a possibly null string     */    protected String readString(DataInput in) throws IOException {            if (in.readBoolean())                return (in.readUTF());            return null;            }        /**      * Write a possibly null string to the stream     */    protected void writeString(String str, DataOutput out) throws IOException {        out.writeBoolean(str!=null);        if (str!=null)            out.writeUTF(str);           }    }

⌨️ 快捷键说明

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