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

📄 primitive.java

📁 fortran并行计算包
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* *  (C) 2001 by Argonne National Laboratory *      See COPYRIGHT in top-level directory. *//* *  @author  Anthony Chan */package base.drawable;import java.awt.Graphics2D;import java.awt.Color;import java.awt.Point;import java.util.Map;import java.util.List;import java.util.ArrayList;import base.io.MixedDataInput;import base.io.MixedDataOutput;import base.io.MixedDataIO;import base.topology.Line;import base.topology.Arrow;import base.topology.State;import base.topology.Event;// Primitive should be considered as an InfoBox of Coord[]// Cloneable interface is for the creation of Shadow. public class Primitive extends Drawable                       implements MixedDataIO//                       implements Cloneable{    private static final int    INIT_BYTESIZE  = 2  /* vertices.length */ ;     private   Coord[]      vertices;    private   int          last_vtx_idx;    public Primitive()    {        super();        vertices        = null;    }    public Primitive( int Nvertices )    {        super();        vertices        = new Coord[ Nvertices ];        last_vtx_idx    = vertices.length - 1;    }    public Primitive( Category in_type, int Nvertices )    {        super( in_type );        vertices        = new Coord[ Nvertices ];        last_vtx_idx    = vertices.length - 1;    }    //  This is NOT a copy constructor,    //  only Category and InfoType[] are copied, not InfoValue[].    public Primitive( final Primitive prime )    {        super( prime );        Coord[] prime_vtxs = prime.vertices;        vertices        = new Coord[ prime_vtxs.length ];        for ( int idx = 0; idx < vertices.length; idx++ )            vertices[ idx ] = new Coord( prime_vtxs[ idx ] );        last_vtx_idx    = vertices.length - 1;    }    public Primitive( Category in_type, final Primitive prime )    {        super( in_type, prime );        Coord[] prime_vtxs = prime.vertices;        vertices        = new Coord[ prime_vtxs.length ];        for ( int idx = 0; idx < vertices.length; idx++ )            vertices[ idx ] = new Coord( prime_vtxs[ idx ] );        last_vtx_idx    = vertices.length - 1;    }    // Class to support JNI in TRACE-API    public Primitive( int type_idx, double starttime, double endtime,                      double[] time_coords, int[] y_coords,                      byte[]   byte_infovals )    {        super( type_idx, byte_infovals );        super.setEarliestTime( starttime );        super.setLatestTime( endtime );        int time_coords_length = time_coords.length;        vertices = new Coord[ time_coords_length ];        if ( time_coords_length == y_coords.length ) {            for ( int idx = 0; idx < time_coords_length; idx++ )                vertices[ idx ] = new Coord( time_coords[ idx ],                                             y_coords[ idx ] );        }        else {            for ( int idx = 0; idx < time_coords_length; idx++ )                vertices[ idx ] = new Coord( time_coords[ idx ],                                             y_coords[ idx / 2 ] );        }        // super.affectTimeBounds( vertices );    }    /*  Abstract method of Drawable  */    public int getNumOfPrimitives()    {        return 1;    }    public int getByteSize()    {        int bytesize;        bytesize = super.getByteSize() + INIT_BYTESIZE;        if ( vertices != null && vertices.length > 0 )            bytesize += vertices.length * Coord.BYTESIZE;        return bytesize;    }    public void writeObject( MixedDataOutput outs )    throws java.io.IOException    {        int vertices_length, idx;        super.writeObject( outs );        vertices_length = (short) vertices.length;        outs.writeShort( vertices_length );        for ( idx = 0; idx < vertices_length; idx++ )            vertices[ idx ].writeObject( outs );    }    public Primitive( MixedDataInput ins )    throws java.io.IOException    {        super();     // InfoBox();        this.readObject( ins );    }    public void readObject( MixedDataInput ins )    throws java.io.IOException    {        short idx, Nvertices;        super.readObject( ins );        Nvertices  = ins.readShort();        vertices   = new Coord[ Nvertices ];        for ( idx = 0; idx < vertices.length; idx++ )            vertices[ idx ] = new Coord( ins );        last_vtx_idx  = vertices.length - 1;        // Determine the SuperClass, TimeBoundingBox.        super.affectTimeBounds( vertices );    }    /*        Vertices related operation:    */    // 0 <= vertex_order < vertices.length    public void setVertex( int vertex_idx, final Coord vertex )    throws ArrayIndexOutOfBoundsException    {        if ( vertex_idx < 0 || vertex_idx >= vertices.length ) {            throw new ArrayIndexOutOfBoundsException( "input index, "                                                    + vertex_idx                                                    + ", is out of range, [0.."                                                    + vertices.length + "]." );        }        vertices[ vertex_idx ] = vertex;        super.affectTimeBounds( vertex );    }    public Coord getVertex( int vertex_idx )    throws ArrayIndexOutOfBoundsException    {        if ( vertex_idx < 0 || vertex_idx >= vertices.length ) {            throw new ArrayIndexOutOfBoundsException( "input index, "                                                    + vertex_idx                                                    + ", is out of range, [0.."                                                    + vertices.length + "]." );        }        return vertices[ vertex_idx ];    }    public void setVertices( final Coord[] in_vertices )    throws IllegalArgumentException    {        if ( in_vertices.length != vertices.length ) {            throw new IllegalArgumentException( "input array size, "                                              + in_vertices.length + ", is "                                              + "different from the original, "                                              + vertices.length );        }        vertices = in_vertices;        super.affectTimeBounds( vertices );    }    public Coord[] getVertices()    {        return vertices;    }    //  API to support Shadow generation    public List getListOfVertexLineIDs()    {        List lineIDs = new ArrayList( vertices.length );        for ( int idx = 0; idx < vertices.length; idx++ )            lineIDs.add( new Integer( vertices[ idx ].lineID ) );        return lineIDs;    }    /*  Abstract method of Drawable  */    //  Used to generate IdentityLineIDMap    public Integer[] getArrayOfLineIDs()    {        Integer[] lineIDs = new Integer[ vertices.length ];        for ( int idx = 0; idx < vertices.length; idx++ )            lineIDs[ idx ] = new Integer( vertices[ idx ].lineID );        return lineIDs;    }    /*        setStartVertex()/setFinalVertex()/getStartVertex()/getFinalVertex()        are stilll good for Primitive with only ONE vertex, like a event marker.    */    public void setStartVertex( final Coord start_vtx )    {        vertices[ 0 ] = start_vtx;        super.affectTimeBounds( start_vtx );    }    public void setFinalVertex( final Coord final_vtx )    {        vertices[ last_vtx_idx ] = final_vtx;        super.affectTimeBounds( final_vtx );    }    public Coord getStartVertex()    {        return vertices[ 0 ];    }    public Coord getFinalVertex()    {        return vertices[ last_vtx_idx ];    }    public String toString()    {        StringBuffer rep;        int idx;        rep = new StringBuffer( "Primitive[ " + super.toString() + " " );        for ( idx = 0; idx < vertices.length; idx++ )            rep.append( vertices[ idx ].toString() + " " );

⌨️ 快捷键说明

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