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

📄 omtextlabeler.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
字号:
// **********************************************************************////<copyright>////BBN Technologies, a Verizon Company//10 Moulton Street//Cambridge, MA 02138//(617) 873-8000////Copyright (C) BBNT Solutions LLC. All rights reserved.////</copyright>//**********************************************************************////$Source:///cvs/darwars/ambush/aar/src/com/bbn/ambush/mission/MissionHandler.java,v//$//$RCSfile: OMTextLabeler.java,v $//$Revision: 1.1.2.2 $//$Date: 2005/09/21 13:55:41 $//$Author: dietrick $////**********************************************************************package com.bbn.openmap.omGraphics;import java.awt.Font;import java.awt.Point;import java.awt.Rectangle;import java.awt.geom.GeneralPath;/** * A default implementation of OMLabeler that extends from OMText. *  * @author dietrick */public class OMTextLabeler extends OMText implements OMLabeler {    /**     *      */    public OMTextLabeler(String stuff) {        this(stuff, DEFAULT_FONT, JUSTIFY_LEFT);    }    /**     * @param stuff     * @param just     */    public OMTextLabeler(String stuff, int just) {        this(stuff, DEFAULT_FONT, just);    }    /**     * @param stuff     * @param font     * @param just     */    public OMTextLabeler(String stuff, Font font, int just) {        setRenderType(RENDERTYPE_XY);        setData(stuff);        setFont(font);        setJustify(just);    }    public void setLocation(GeneralPath gp) {        if (gp != null) {            Rectangle rect = gp.getBounds();            setLocation(new Point((int) (rect.getX() + rect.getWidth() / 2), (int) (rect.getY() + rect.getHeight() / 2)));        }    }    /*     * (non-Javadoc)     *      * @see com.bbn.openmap.omGraphics.OMLabeler#setLocation(java.awt.Point)     */    public void setLocation(Point p) {        polyBounds = null;        setX((int) p.getX());        setY((int) p.getY());        setMapLocation(p);        computeBounds();        setNeedToRegenerate(false);    }    /*     * (non-Javadoc)     *      * @see com.bbn.openmap.omGraphics.OMLabeler#setLocation(int[][],     *      int[][])     */    public void setLocation(int[] xpoints, int[] ypoints) {        setLocation(getCenter(xpoints, ypoints));    }    /**     * Calculate the projected area of the poly. Algorithm used is     * from some australian astronomy website =)     * http://astronomy.swin.edu.au/~pbourke/geometry/polyarea     */    protected double calculateProjectedArea(int[] xpts, int[] ypts) {        int j = 0;        double area = 0.0;        int npoints = xpts.length;        for (int i = 0; i < npoints; ++i) {            j = (i + 1) % npoints;            area += xpts[i] * ypts[j];            area -= ypts[i] * xpts[j];        }        return area / 2.0;    }    /**     * Get the calculated center where the label string is drawn.     * Algorithm used is from some australian astronomy website =)     * http://astronomy.swin.edu.au/~pbourke/geometry/polyarea     */    protected Point getCenter(int[] xpts, int[] ypts) {        float cx = 0.0f;        float cy = 0.0f;        double A = calculateProjectedArea(xpts, ypts);        int j = 0;        double factor = 0;        int npoints = xpts.length;        for (int i = 0; i < npoints; ++i) {            j = (i + 1) % npoints;            factor = xpts[i] * ypts[j] - xpts[j] * ypts[i];            cx += (xpts[i] + xpts[j]) * factor;            cy += (ypts[i] + ypts[j]) * factor;        }        A = A * 6.0;        factor = 1.0 / A;        // bbenyo: take the absolute value cause I was getting        // negative values        // for polys with all positive vertices        // cx = Math.abs(cx * factor);        // cy = Math.abs(cy * factor);        // DFD and RS - let the area calculation return negative        // values, and don't do this absolute value calculation.        // Negative values get returned when the points are        // counterclockwise, indicating holes. We may want labels        // offscreen however, and the abs pushes them onscreen.        cx *= factor;        cy *= factor;        Point center = new Point(Math.round(cx), Math.round(cy));        return center;    }}

⌨️ 快捷键说明

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