editableomline.java

来自「OpenMap是一个基于JavaBeansTM的开发工具包。利用OpenMap你」· Java 代码 · 共 457 行 · 第 1/2 页

JAVA
457
字号
// **********************************************************************// // <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/EditableOMLine.java,v $// $RCSfile: EditableOMLine.java,v $// $Revision: 1.5.2.5 $// $Date: 2008/01/29 02:21:01 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.omGraphics;import java.awt.event.MouseEvent;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.LineStateMachine;import com.bbn.openmap.omGraphics.geom.NonRegional;import com.bbn.openmap.proj.Projection;import com.bbn.openmap.util.Debug;/** * The EditableOMLine encompasses an OMLine, providing methods for * modifying or creating it. */public class EditableOMLine extends EditableOMAbstractLine implements NonRegional {    protected GrabPoint gp1;    protected GrabPoint gp2;    protected OffsetGrabPoint gpo; // offset    protected OffsetGrabPoint gpm; // for grabing the line and moving    // it.    protected OMLine line;    public final static int STARTING_POINT_INDEX = 0;    public final static int ENDING_POINT_INDEX = 1;    public final static int OFFSET_POINT_INDEX = 2;    /**     * Create the EditableOMLine, setting the state machine to create     * the line off of the gestures.     */    public EditableOMLine() {        createGraphic(null);    }    /**     * Create an EditableOMLine with the lineType and renderType     * parameters in the GraphicAttributes object.     */    public EditableOMLine(GraphicAttributes ga) {        createGraphic(ga);    }    /**     * Create the EditableOMLine with an OMLine already defined, ready     * for editing.     *      * @param oml OMLine that should be edited.     */    public EditableOMLine(OMLine oml) {        setGraphic(oml);    }    /**     * 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     * EditableOMLine.     */    public void init() {        Debug.message("eomg", "EditableOMLine.init()");        setStateMachine(new LineStateMachine(this));        gPoints = new GrabPoint[3];    }    /**     * 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 OMLine) {            line = (OMLine) graphic;            stateMachine.setSelected();            setGrabPoints(line);        } else {            createGraphic(null);        }    }    /**     * Create and set the graphic within the state machine. The     * GraphicAttributes describe the type of line to create.     */    public void createGraphic(GraphicAttributes ga) {        init();        stateMachine.setUndefined();        int renderType = OMGraphic.RENDERTYPE_UNKNOWN;        int lineType = OMGraphic.LINETYPE_GREATCIRCLE;        if (ga != null) {            renderType = ga.getRenderType();            lineType = ga.getLineType();        }        if (Debug.debugging("eoml")) {            Debug.output("EditableOMLine.createGraphic(): rendertype = "                    + renderType);        }        if (lineType == OMGraphic.LINETYPE_UNKNOWN) {            lineType = OMGraphic.LINETYPE_GREATCIRCLE;            ga.setLineType(OMGraphic.LINETYPE_GREATCIRCLE);        }        switch (renderType) {        case (OMGraphic.RENDERTYPE_LATLON):            line = new OMLine(90f, -180f, 90f, -180f, lineType);            break;        case (OMGraphic.RENDERTYPE_OFFSET):            line = new OMLine(90f, -180f, 0, 0, 0, 0);            break;        default:            line = new OMLine(-1, -1, -1, -1);        }        if (ga != null) {            ga.setTo(line, true);        }    }    /**     * Get the OMGraphic being created/modified by the EditableOMLine.     */    public OMGraphic getGraphic() {        return line;    }    /**     * 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);        gpm = null;    }    /**     * 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);    }    /**     * 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() {        if (gp1 == null) {            gp1 = new GrabPoint(-1, -1);            gPoints[STARTING_POINT_INDEX] = gp1;        }        if (gp2 == null) {            gp2 = new GrabPoint(-1, -1);            gPoints[ENDING_POINT_INDEX] = gp2;        }        if (gpo == null) {            gpo = new OffsetGrabPoint(-1, -1);            gPoints[OFFSET_POINT_INDEX] = gpo;            gpo.addGrabPoint(gp1);            gpo.addGrabPoint(gp2);        }    }    /**     * 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 OMLine)) {            return;        }        assertGrabPoints();        OMLine line = (OMLine) graphic;        boolean ntr = line.getNeedToRegenerate();        int renderType = line.getRenderType();        if (ntr == false) {            if (renderType == OMGraphic.RENDERTYPE_LATLON) {                Debug.message("eomg", "EditableOMLine: modifying lat/lon line");                // Complicated lines!!!! Need to grab the end points                // that are on the map! See, for very large lines                // that go around the earth, they are acutally drawn                // in OpenMap as an array of lines that are clipped as                // they go offscreen. Eventually, one of the points

⌨️ 快捷键说明

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