shapeportrayal2d.java

来自「MASON代表多主体邻里或网络仿真(Multi-Agent Simulator 」· Java 代码 · 共 57 行

JAVA
57
字号
package sim.portrayal.simple;import sim.portrayal.*;import java.awt.*;import java.awt.geom.*;/**   A simple portrayal for 2D visualization of java.awt.Shapes. It extends the SimplePortrayal2D and   it manages the drawing and hit-testing for shapes.*/public class ShapePortrayal2D extends SimplePortrayal2D    {    public Paint paint;    public double scale;    public Shape shape;    AffineTransform transform = new AffineTransform();    double bufferedWidth;    double bufferedHeight;    Shape bufferedShape;        public ShapePortrayal2D(Shape shape) { this(shape,Color.gray,1.0); }    public ShapePortrayal2D(Shape shape, Paint paint) { this(shape,paint,1.0); }    public ShapePortrayal2D(Shape shape, double scale) { this(shape,Color.gray,scale); }        public ShapePortrayal2D(Shape shape, Paint paint, double scale)        {        this.shape = shape;        this.paint = paint;        this.scale = scale;        }        // assumes the graphics already has its color set    public void draw(Object object, Graphics2D graphics, DrawInfo2D info)        {        final double width = info.draw.width*scale;        final double height = info.draw.height*scale;        if (bufferedShape == null || width != bufferedWidth || height != bufferedHeight)            {            transform.setToScale(bufferedWidth = width, bufferedHeight = height);            bufferedShape = transform.createTransformedShape(shape);            }        graphics.setPaint(paint);        // we are doing a simple draw, so we ignore the info.clip        // draw centered on the origin        transform.setToTranslation(info.draw.x,info.draw.y);        graphics.fill(transform.createTransformedShape(bufferedShape));        }    public boolean hitObject(Object object, DrawInfo2D range)        {        return false;        }    }

⌨️ 快捷键说明

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