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

📄 editableompoint.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/EditableOMPoint.java,v $// $RCSfile: EditableOMPoint.java,v $// $Revision: 1.7.2.2 $// $Date: 2005/08/09 21:17:46 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.omGraphics;import java.awt.Component;import java.awt.event.MouseEvent;import javax.swing.JPanel;import javax.swing.JToolBar;import com.bbn.openmap.LatLonPoint;import com.bbn.openmap.gui.GridBagToolBar;import com.bbn.openmap.layer.util.stateMachine.State;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.omGraphics.editable.GraphicUndefinedState;import com.bbn.openmap.omGraphics.editable.PointStateMachine;import com.bbn.openmap.proj.Projection;import com.bbn.openmap.util.Debug;/** * An EditableOMGraphic that encapsulates an OMPoint. */public class EditableOMPoint extends EditableOMGraphic {    protected GrabPoint gpc;    protected OffsetGrabPoint gpo; // offset    protected OMPoint point;    public final static String OffsetResetCmd = "OffsetResetCmd";    public final static int CENTER_POINT_INDEX = 0;    public final static int OFFSET_POINT_INDEX = 1;    /**     * Create the EditableOMPoint, setting the state machine to create     * the point off of the gestures.     */    public EditableOMPoint() {        createGraphic(null);    }    /**     * Create an EditableOMPoint with the pointType and renderType     * parameters in the GraphicAttributes object.     */    public EditableOMPoint(GraphicAttributes ga) {        createGraphic(ga);    }    /**     * Create the EditableOMPoint with an OMPoint already defined,     * ready for editing.     *      * @param omc OMPoint that should be edited.     */    public EditableOMPoint(OMPoint 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     * EditableOMPoint.     */    public void init() {        Debug.message("eomg", "EditableOMPoint.init()");        setCanGrabGraphic(false);        setStateMachine(new PointStateMachine(this));        gPoints = new GrabPoint[2];    }    /**     * 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 OMPoint) {            point = (OMPoint) graphic;            stateMachine.setSelected();            setGrabPoints(point);        } else {            createGraphic(null);        }    }    /**     * Create and set the graphic within the state machine. The     * GraphicAttributes describe the type of point to create.     */    public void createGraphic(GraphicAttributes ga) {        init();        stateMachine.setUndefined();        int renderType = OMGraphic.RENDERTYPE_UNKNOWN;        if (ga != null) {            renderType = ga.getRenderType();        }        if (Debug.debugging("eomg")) {            Debug.output("EditableOMPoint.createGraphic(): rendertype = "                    + renderType);        }        switch (renderType) {        case (OMGraphic.RENDERTYPE_LATLON):            point = new OMPoint(90f, -180f);            break;        case (OMGraphic.RENDERTYPE_OFFSET):            point = new OMPoint(90f, -180f, 0, 0);            break;        default:            point = new OMPoint(-1, -1);        }        if (ga != null) {            ga.setTo(point);        }        assertGrabPoints();    }    /**     * Get the OMGraphic being created/modified by the     * EditableOMPoint.     */    public OMGraphic getGraphic() {        return point;    }    /**     * 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);    }    /**     * 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 (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;    }    /**     * 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);    }    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 (gpc == null) {            gpc = new GrabPoint(-1, -1);            gPoints[CENTER_POINT_INDEX] = gpc;        }        if (gpo == null) {            gpo = new OffsetGrabPoint(-1, -1);            gPoints[OFFSET_POINT_INDEX] = gpo;            gpo.addGrabPoint(gpc);        }    }    protected void clearGrabPoints() {        gpc = null;        gpo = null;        gPoints[CENTER_POINT_INDEX] = gpc;        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) {        Debug.message("eomg", "EditableOMPoint.setGrabPoints(graphic)");        if (!(graphic instanceof OMPoint)) {            return;        }

⌨️ 快捷键说明

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