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

📄 controller.java

📁 JAVA3D矩陈的相关类
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        if (classID==-1)            return nullObject;        else if (classID==0) {             String stateClassName = in.readUTF();            try {                Class cl = Class.forName( stateClassName, true, classLoader );                // System.out.println("Got class "+cl );                Constructor construct = cl.getConstructor(                        new Class[] {                         com.sun.j3d.utils.scenegraph.io.retained.SymbolTableData.class,                        com.sun.j3d.utils.scenegraph.io.retained.Controller.class} );                // System.out.println("Got constructor "+construct );                state = (SceneGraphObjectState)construct.newInstance(                                                    new Object[]{ null, this } );                // System.out.println("Got state instance "+state);            } catch(ClassNotFoundException e) {                throw new java.io.IOException( "Error Loading State Class "+stateClassName+"  "+e.getMessage() );            } catch( NoSuchMethodException ex ) {                 throw new java.io.IOException( "1 Broken State class for "+                                                    stateClassName+"  "+ex.getMessage() );            } catch( InvocationTargetException exc ) {                exc.printStackTrace();                throw new java.io.IOException( "2 Broken State class for "+                                                    stateClassName );            } catch( IllegalAccessException exce ) {                throw new java.io.IOException( "3 Broken State class for "+                                                    stateClassName );            } catch( InstantiationException excep ) {                throw new java.io.IOException( "4 Broken State class for "+                                                    stateClassName );            }             } else {            state = createCoreState( classID );        }                state.readObject( in );                return state;    }    /**       * Set the class loader used to load the Scene Graph Objects and      * the serialized user data. The default is       * ClassLoader.getSystemClassLoader()      */    public void setClassLoader( ClassLoader classLoader ) {        this.classLoader = classLoader;    }    /**       * Get the class loader used to load the Scene Graph Objects and      * the serialized user data. The default is       * ClassLoader.getSystemClassLoader()      */    public ClassLoader getClassLoader() {        return classLoader;    }    /**     * Write all the unsaved NodeComponents and SharedGroups to DataOutput.     * Mark all the NodeComponents as saved.     */    protected void writeNodeComponents( DataOutput out ) throws IOException {        // This method is overridden by RandomAccessFileControl        // The RandomAccessFileControl version sets the pointer to        // the next NodeComponent correclty                ListIterator list = symbolTable.getUnsavedNodeComponents();        out.writeInt( symbolTable.getUnsavedNodeComponentsSize() );        while( list.hasNext() ) {            SymbolTableData symbol = (SymbolTableData)list.next();                        out.writeInt( symbol.nodeID );            out.writeLong( 0L );            // Pointer to next NodeComponent                        writeObject( out, symbol.getNodeState() );        }    }        /**     * Read in all the node components in this block      */    protected void readNodeComponents( DataInput in ) throws IOException {        int count = in.readInt();                for(int i=0; i<count; i++) {            // nodeID and nextNC data is used in RandomAccessFileControl            // version of readNodeComponents            int nodeID = in.readInt();            long nextNC = in.readLong();                        SceneGraphObjectState nodeComponent = readObject( in );        }    }        /**     * Write the shared group and it's node components to the IO stream     */    public void writeSharedGroup( DataOutput out, SharedGroup sharedGroup, SymbolTableData symbol ) throws IOException {        SceneGraphObjectState state = createState( sharedGroup, symbol );        symbolTable.startUnsavedNodeComponentFrame();        writeObject( out, state );        writeNodeComponents( out );        symbolTable.endUnsavedNodeComponentFrame();    }        /**     * Read a Shared group and it's node components from the IO Stream     */    public int readSharedGroup( DataInput in ) throws IOException {        SceneGraphObjectState state = readObject( in );        readNodeComponents( in );                return state.getNodeID();    }            /**     * Write out the Universe information.     */    public void writeUniverse( DataOutput out, SimpleUniverse universe,                               boolean writeUniverseContent ) throws IOException, UnsupportedUniverseException, CapabilityNotSetException {        if (universe==null) {            out.writeUTF( "null" );        } else if ( universe instanceof SimpleUniverse ) {            out.writeUTF( universe.getClass().getName() );            SimpleUniverseState state = new SimpleUniverseState( universe, this );            state.writeObject( out );                        if (writeUniverseContent) {                state.detachAllGraphs();                int[] graphs = state.getAllGraphIDs();                for(int i=0; i<graphs.length; i++) {                    SymbolTableData symbol = symbolTable.getBranchGraphRoot( graphs[i] );                    System.out.println("Writing "+graphs[i]+"  "+symbol.j3dNode );                    writeBranchGraph( (BranchGroup)symbol.j3dNode, null );                }                                state.attachAllGraphs();            }        } else {            throw new UnsupportedUniverseException(		"Current Implementation only support SimpleUniverse/ConfiguredUniverse.");        }    }        /**     * Read and create a new Universe matching the one used during save.     *     * @param attachBranchGraphs If true then all the branchGraph attached to      * the universe when it was saved will be loaded and reattached.     */    public ConfiguredUniverse readUniverse(DataInput in, boolean attachBranchGraphs,					   Canvas3D canvas) throws IOException {        String universeClass = in.readUTF();        //System.out.println(universeClass);        if (universeClass.equals("null"))            return null;        else if ( (universeClass.equals("com.sun.j3d.utils.universe.SimpleUniverse")) ||                  (universeClass.equals("com.sun.j3d.utils.universe.ConfiguredUniverse")) ) {            SimpleUniverseState state = new SimpleUniverseState( this );            state.readObject( in, canvas );                        if (attachBranchGraphs) {                int[] graphs = state.getAllGraphIDs();                readBranchGraphs( graphs );                                state.buildGraph();            }                        return state.getNode();        }        throw new IOException("Unrecognized universe class "+universeClass);    }        /**     * Read the set of branchgraps.     *     * Used by readUniverse     *     * RandomAccessFileControl will read the graphs in the array,     * StreamControl will read all graphs in the stream     */    protected abstract void readBranchGraphs( int[] graphs ) throws IOException;        public abstract void writeBranchGraph( BranchGroup bg, java.io.Serializable userData) throws IOException;        /**     * Reset the controller, ready to load/save data to a new file     */    public void reset() {        symbolTable.clear();    }        /**     * 'Core' classes (ie those hard coded in this API) are assigned a     * numerical value representing their class. This simply saves space     * and IO bandwidth     */    private SceneGraphObjectState createCoreState( int classID ) {                if (classID==-1)            return nullObject;        else if (classID==0)            return null;                Class j3dClass = getNodeClassFromID( classID-1 );        String j3dClassName = j3dClass.getName();        String stateClassName = "com.sun.j3d.utils.scenegraph.io.state."+j3dClassName+"State";        SceneGraphObjectState stateObj = null;        try {            Class stateClass = Class.forName( stateClassName );            Constructor stateConstructor = stateClass.getConstructor( new Class[] { SymbolTableData.class, Controller.class } );            stateObj = (SceneGraphObjectState)stateConstructor.newInstance( new Object[] { null, this } );        } catch( Exception e ) {            e.printStackTrace();        }                return stateObj;    }        /**     * Return the id of the state class     */    private int getStateID( SceneGraphObjectState state ) {                if (state instanceof NullSceneGraphObjectState)            return -1;                return getNodeClassID( state.getNode() )+1;    }        // The order of this array dictates the ID's of classes therefore    // changing the order of this array will break backward compatability    Class[] j3dClasses = new Class[] {        javax.media.j3d.Alpha.class,        javax.media.j3d.Appearance.class,        javax.media.j3d.Billboard.class,        javax.media.j3d.BranchGroup.class,        javax.media.j3d.ColoringAttributes.class,        javax.media.j3d.ConeSound.class,        javax.media.j3d.DecalGroup.class,        javax.media.j3d.DirectionalLight.class,        javax.media.j3d.DistanceLOD.class,        javax.media.j3d.ExponentialFog.class,        javax.media.j3d.Font3D.class,        javax.media.j3d.Group.class,        javax.media.j3d.ImageComponent2D.class,        javax.media.j3d.ImageComponent3D.class,        javax.media.j3d.IndexedLineArray.class,        javax.media.j3d.IndexedLineStripArray.class,        javax.media.j3d.IndexedPointArray.class,        javax.media.j3d.IndexedQuadArray.class,        javax.media.j3d.IndexedTriangleArray.class,        javax.media.j3d.IndexedTriangleFanArray.class,        javax.media.j3d.IndexedTriangleStripArray.class,        javax.media.j3d.LinearFog.class,        javax.media.j3d.LineArray.class,        javax.media.j3d.LineAttributes.class,        javax.media.j3d.LineStripArray.class,        javax.media.j3d.Link.class,        javax.media.j3d.Material.class,        javax.media.j3d.Morph.class,        javax.media.j3d.OrderedGroup.class,        javax.media.j3d.OrientedShape3D.class,        javax.media.j3d.PathInterpolator.class,        javax.media.j3d.PointArray.class,        javax.media.j3d.PointAttributes.class,        javax.media.j3d.PositionInterpolator.class,        javax.media.j3d.PositionPathInterpolator.class,        javax.media.j3d.QuadArray.class,        javax.media.j3d.RenderingAttributes.class,        javax.media.j3d.RotationInterpolator.class,        javax.media.j3d.RotationPathInterpolator.class,        javax.media.j3d.RotPosPathInterpolator.class,        javax.media.j3d.RotPosScalePathInterpolator.class,        javax.media.j3d.ScaleInterpolator.class,        javax.media.j3d.Shape3D.class,        javax.media.j3d.SharedGroup.class,        javax.media.j3d.Soundscape.class,        javax.media.j3d.SpotLight.class,        javax.media.j3d.Switch.class,        javax.media.j3d.SwitchValueInterpolator.class,        javax.media.j3d.Text3D.class,        javax.media.j3d.Texture2D.class,        javax.media.j3d.Texture3D.class,        javax.media.j3d.TextureAttributes.class,        javax.media.j3d.TextureCubeMap.class,        javax.media.j3d.TextureUnitState.class,        javax.media.j3d.TransformGroup.class,        javax.media.j3d.TransformInterpolator.class,        javax.media.j3d.TransparencyAttributes.class,        javax.media.j3d.TransparencyInterpolator.class,        javax.media.j3d.TriangleArray.class,        javax.media.j3d.TriangleFanArray.class,        javax.media.j3d.TriangleStripArray.class,        javax.media.j3d.ViewPlatform.class    };    public Class getNodeClassFromID( int classID ) {        if (classID<0)            return null;        else            return j3dClasses[classID];    }        // TODO Use a HashMap to eliminate the linear search for the class    //    public int getNodeClassID( javax.media.j3d.SceneGraphObject node ) {                int ret = -1;        Class cl = node.getClass();                for(int i=0; i<j3dClasses.length && ret==-1; i++)            if (j3dClasses[i]==cl)                ret = i;

⌨️ 快捷键说明

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