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

📄 circleshapedecoration.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
字号:
package com.bbn.openmap.omGraphics.awt;import java.awt.Graphics;import java.awt.Paint;import java.awt.geom.Point2D;/** * A ShapeDecoration that draws a circle on the path. */public class CircleShapeDecoration extends AbstractShapeDecoration {    /**     */    private boolean filled = true;    /**     * Constructor.     *      * @param length number of pixels of segment to draw circle in.     * @param radius number of pixels for radius of circle.     */    public CircleShapeDecoration(int length, int radius) {        super(length, radius, RIGHT);    }    /**     * Constructor.     *      * @param length number of pixels of segment to draw circle in.     * @param radius number of pixels for radius of circle.     * @param paint the Paint to use for the circle.     */    public CircleShapeDecoration(int length, int radius, Paint paint) {        super(length, radius, RIGHT);        setPaint(paint);    }    /**     * @see com.bbn.openmap.omGraphics.awt.ShapeDecoration#draw(Graphics,     *      Point2D[], boolean)     */    public void draw(Graphics g, Point2D[] points, boolean complete) {        setGraphics(g);        int nbpts = points.length;        double xcoord1 = points[0].getX();        double ycoord1 = points[0].getY();        double xcoord2 = points[nbpts - 1].getX();        double ycoord2 = points[nbpts - 1].getY();        if (complete) {            // Compute cosinus and sinus of rotation angle            double dx = xcoord2 - xcoord1;            double dy = ycoord2 - ycoord1;            double norm = Math.sqrt(dx * dx + dy * dy);            double rcos = dx / norm;            double rsin = dy / norm;            // Compute vertices            double r = getLength() / 2.0; // x radius before rotation            double w = getWidth();            // rotate            int x = (int) (xcoord1 + r * rcos);            int y = (int) (ycoord1 + r * rsin);            if (filled) {                g.fillOval((int) (x - w / 2),                        (int) (y - w / 2),                        (int) (w),                        (int) (w));            } else {                g.drawOval((int) (x - w / 2),                        (int) (y - w / 2),                        (int) (w),                        (int) (w));            }        }        restoreGraphics(g);    }    /**     * Returns the filled boolean.     *      * @return boolean     */    public boolean isFilled() {        return filled;    }    /**     * Sets the filled (draw a half disk or a half circle ?).     *      * @param filled The filled to set     */    public void setFilled(boolean filled) {        this.filled = filled;    }}

⌨️ 快捷键说明

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