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

📄 editableomcircle.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
// **********************************************************************// // <copyright>// //  BBN Technologies//  10 Moulton Street//  Cambridge, MA 02138//  (617) 873-8000// //  Copyright (C) BBNT Solutions LLC. All rights reserved.// // </copyright>// **********************************************************************// // $Source: /cvs/distapps/openmap/src/openmap/com/bbn/openmap/omGraphics/EditableOMCircle.java,v $// $RCSfile: EditableOMCircle.java,v $// $Revision: 1.5.2.2 $// $Date: 2005/12/22 23:14:25 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.omGraphics;import java.awt.event.MouseEvent;import com.bbn.openmap.LatLonPoint;import com.bbn.openmap.layer.util.stateMachine.State;import com.bbn.openmap.omGraphics.editable.CircleStateMachine;import com.bbn.openmap.omGraphics.editable.GraphicEditState;import com.bbn.openmap.omGraphics.editable.GraphicSelectedState;import com.bbn.openmap.omGraphics.editable.GraphicSetOffsetState;import com.bbn.openmap.proj.GreatCircle;import com.bbn.openmap.proj.Length;import com.bbn.openmap.proj.Projection;import com.bbn.openmap.util.Debug;/** * The EditableOMCircle encompasses an OMCircle, providing methods for modifying * or creating it. This class only modifies circles in lat/lon space * (RENDERTYPE_LATLON) - and ellipses in screen space (RENDERTYPE_XY or * RENDERTYPE_OFFSET). When you grab at the circle, you change the radius of the * entire circle. Grabbing the center point moves the circle. If there is an * offset point, moving the center point changes the circle's position in * relation to the offset point. Moving the offset point moves the circle, * keeping the distance to the center point constant. */public class EditableOMCircle extends EditableOMGraphic {    protected VerticalGrabPoint gpn;    protected HorizontalGrabPoint gpw;    protected VerticalGrabPoint gps;    protected HorizontalGrabPoint gpe;    protected GrabPoint gpnw;    protected GrabPoint gpne;    protected GrabPoint gpsw;    protected GrabPoint gpse;    protected OffsetGrabPoint gpc;    protected GrabPoint gpr;    protected OffsetGrabPoint gpo; // offset    protected OffsetGrabPoint gpm; // for grabbing the circle and    // changing the radius during creation.    protected OMCircle circle;    public final static int CENTER_POINT_INDEX = 0;    public final static int NW_POINT_INDEX = 1;    public final static int N_POINT_INDEX = 2;    public final static int NE_POINT_INDEX = 3;    public final static int W_POINT_INDEX = 4;    public final static int E_POINT_INDEX = 5;    public final static int SW_POINT_INDEX = 6;    public final static int S_POINT_INDEX = 7;    public final static int SE_POINT_INDEX = 8;    public final static int RADIUS_POINT_INDEX = 9;    public final static int OFFSET_POINT_INDEX = 10;    /**     * Create the EditableOMCircle, setting the state machine to create the     * circle off of the gestures.     */    public EditableOMCircle() {        createGraphic(null);    }    /**     * Create an EditableOMCircle with the circleType and renderType parameters     * in the GraphicAttributes object.     */    public EditableOMCircle(GraphicAttributes ga) {        createGraphic(ga);    }    /**     * Create the EditableOMCircle with an OMCircle already defined, ready for     * editing.     *      * @param omc OMCircle that should be edited.     */    public EditableOMCircle(OMCircle omc) {        setGraphic(omc);    }    /**     * Create and initialize the state machine that interprets the modifying     * gestures/commands, as well as ititialize the grab points. Also allocates     * the grab point array needed by the EditableOMCircle.     */    public void init() {        setCanGrabGraphic(false);        Debug.message("eomg", "EditableOMCircle.init()");        setStateMachine(new CircleStateMachine(this));        gPoints = new GrabPoint[11];    }    /**     * Set the graphic within the state machine. If the graphic is null, then     * one shall be created, and located off screen until the gestures driving     * the state machine place it on the map.     */    public void setGraphic(OMGraphic graphic) {        init();        if (graphic instanceof OMCircle) {            circle = (OMCircle) graphic;            stateMachine.setSelected();            setGrabPoints(circle);        } else {            createGraphic(null);        }    }    /**     * Create and set the graphic within the state machine. The     * GraphicAttributes describe the type of circle to create.     */    public void createGraphic(GraphicAttributes ga) {        init();        stateMachine.setUndefined();        int renderType = OMGraphic.RENDERTYPE_UNKNOWN;        if (ga != null) {            renderType = ga.getRenderType();        }        if (Debug.debugging("eomc")) {            Debug.output("EditableOMCircle.createGraphic(): rendertype = "                    + renderType);        }        switch (renderType) {        case (OMGraphic.RENDERTYPE_LATLON):            circle = new OMCircle(90f, -180f, 0f);            break;        case (OMGraphic.RENDERTYPE_OFFSET):            circle = new OMCircle(90f, -180f, 0, 0, 1, 1);            break;        default:            circle = new OMCircle(-1, -1, 1, 1);        }        if (ga != null) {            ga.setTo(circle);        }    }    /**     * Get whether a graphic can be manipulated by its edges, rather than just     * by its grab points.     */    public boolean getCanGrabGraphic() {        return canGrabGraphic                || circle.renderType == OMGraphic.RENDERTYPE_LATLON;    }    /**     * Get the OMGraphic being created/modified by the EditableOMCircle.     */    public OMGraphic getGraphic() {        return circle;    }    /**     * Attach to the Moving OffsetGrabPoint so if it moves, it will move this     * EditableOMGraphic with it. EditableOMGraphic version doesn't do anything,     * each subclass has to decide which of its OffsetGrabPoints should be     * attached to it.     */    public void attachToMovingGrabPoint(OffsetGrabPoint gp) {        gp.addGrabPoint(gpo);    }    /**     * Detach from a Moving OffsetGrabPoint. The EditableOMGraphic version     * doesn't do anything, each subclass should remove whatever GrabPoint it     * would have attached to an OffsetGrabPoint.     */    public void detachFromMovingGrabPoint(OffsetGrabPoint gp) {        gp.removeGrabPoint(gpo);    }    /**     * Set the GrabPoint that is in the middle of being modified, as a result of     * a mouseDragged event, or other selection process.     */    public void setMovingPoint(GrabPoint gp) {        super.setMovingPoint(gp);        // set as a flag that the graphic is being moved, and it's        // parameters should not be adjusted.        gpm = null;    }    /**     * Given a MouseEvent, find a GrabPoint that it is touching, and set the     * moving point to that GrabPoint.     *      * @param e MouseEvent     * @return GrabPoint that is touched by the MouseEvent, null if none are.     */    public GrabPoint getMovingPoint(MouseEvent e) {        movingPoint = null;        GrabPoint[] gb = getGrabPoints();        int x = e.getX();        int y = e.getY();        for (int i = gb.length - 1; i >= 0; i--) {            if (i != RADIUS_POINT_INDEX && gb[i] != null                    && gb[i].distance(x, y) == 0) {                setMovingPoint(gb[i]);                // in case the points are on top of each other, the                // last point in the array will take precidence.                break;            }        }        return movingPoint;    }    protected int lastRenderType = -1;    /**     * Check to make sure the grab points are not null. If they are, allocate     * them, and them assign them to the array.     */    public void assertGrabPoints() {        int rt = getGraphic().getRenderType();        if (rt != lastRenderType) {            clearGrabPoints();            lastRenderType = rt;        }        if (gpr == null) {            gpr = new GrabPoint(-1, -1);            gPoints[RADIUS_POINT_INDEX] = gpr;        }        if (gpnw == null) {            gpnw = new GrabPoint(-1, -1);            gPoints[NW_POINT_INDEX] = gpnw;        }        if (gpn == null) {            gpn = new VerticalGrabPoint(-1, -1);            gPoints[N_POINT_INDEX] = gpn;        }        if (gpne == null) {            gpne = new GrabPoint(-1, -1);            gPoints[NE_POINT_INDEX] = gpne;        }        if (gpw == null) {            gpw = new HorizontalGrabPoint(-1, -1);            gPoints[W_POINT_INDEX] = gpw;        }        if (gpe == null) {            gpe = new HorizontalGrabPoint(-1, -1);            gPoints[E_POINT_INDEX] = gpe;        }        if (gpsw == null) {            gpsw = new GrabPoint(-1, -1);            gPoints[SW_POINT_INDEX] = gpsw;        }        if (gps == null) {            gps = new VerticalGrabPoint(-1, -1);            gPoints[S_POINT_INDEX] = gps;        }        if (gpse == null) {            gpse = new GrabPoint(-1, -1);            gPoints[SE_POINT_INDEX] = gpse;        }        if (gpc == null) {            gpc = new OffsetGrabPoint(-1, -1);            gPoints[CENTER_POINT_INDEX] = gpc;            if (getGraphic().getRenderType() != OMGraphic.RENDERTYPE_LATLON) {                gpc.addGrabPoint(gpnw);                gpc.addGrabPoint(gpn);                gpc.addGrabPoint(gpne);                gpc.addGrabPoint(gpw);                gpc.addGrabPoint(gpe);                gpc.addGrabPoint(gpsw);                gpc.addGrabPoint(gps);                gpc.addGrabPoint(gpse);            }        }        if (gpo == null) {            gpo = new OffsetGrabPoint(-1, -1);            gPoints[OFFSET_POINT_INDEX] = gpo;            gpo.addGrabPoint(gpc);        }    }    protected void clearGrabPoints() {        gpc = null;        gpr = null;        gpnw = null;        gpn = null;        gpne = null;        gpw = null;        gpe = null;        gpsw = null;        gps = null;        gpse = null;        gpo = null;        gPoints[CENTER_POINT_INDEX] = gpc;        gPoints[RADIUS_POINT_INDEX] = gpr;        gPoints[NW_POINT_INDEX] = gpnw;        gPoints[N_POINT_INDEX] = gpn;        gPoints[NE_POINT_INDEX] = gpne;        gPoints[W_POINT_INDEX] = gpw;        gPoints[E_POINT_INDEX] = gpe;        gPoints[SW_POINT_INDEX] = gpsw;        gPoints[S_POINT_INDEX] = gps;        gPoints[SE_POINT_INDEX] = gpse;        gPoints[OFFSET_POINT_INDEX] = gpo;    }    /**     * Set the grab points for the graphic provided, setting them on the extents     * of the graphic. Called when you want to set the grab points off the     * location of the graphic.     */    public void setGrabPoints(OMGraphic graphic) {        if (!(graphic instanceof OMCircle)) {            return;        }        assertGrabPoints();        OMCircle circle = (OMCircle) graphic;        boolean ntr = circle.getNeedToRegenerate();        int renderType = circle.getRenderType();        int centerx = 0;        int centery = 0;        if (ntr == false) {            if (renderType == OMGraphic.RENDERTYPE_LATLON

⌨️ 快捷键说明

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