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

📄 editableomcircle.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                    || renderType == OMGraphic.RENDERTYPE_OFFSET) {                if (projection != null) {                    LatLonPoint center = circle.getLatLon();                    java.awt.Point p = projection.forward(center);                    centerx = (int) p.getX();                    centery = (int) p.getY();                }                if (renderType == OMGraphic.RENDERTYPE_OFFSET) {                    gpo.setX(centerx);                    gpo.setY(centery);                    centerx += circle.getOffX();                    centery += circle.getOffY();                }            } else if (renderType == OMGraphic.RENDERTYPE_XY) {                centerx = circle.getX();                centery = circle.getY();            }            if (renderType == OMGraphic.RENDERTYPE_LATLON) {                Debug.message("eomg",                        "EditableOMCircle: modifying lat/lon circle");                if (projection != null) {                    gpc.set(centerx, centery);                }                // Note that we really don't handle this situation                // well, if there isn't a projection. We kind of                // assume later that there is one, and although there                // shouldn't be massive meltdowns, data could look                // funky on the screen if the projection is                // unavailable.            } else {                // Grab the projected endpoints                Debug.message("eomg",                        "EditableOMCircle: modifying x/y or offset standard circle");                int height = circle.getHeight() / 2;                int width = circle.getWidth() / 2;                gpc.set(centerx, centery);                gpe.set(centerx + width, centery, true);                gps.set(centerx, centery + height, true);                gpw.set(centerx - width, centery, true);                gpn.set(centerx, centery - height, true);                gpne.set(gpe.getX(), gpn.getY());                gpnw.set(gpw.getX(), gpn.getY());                gpse.set(gpe.getX(), gps.getY());                gpsw.set(gpw.getX(), gps.getY());                gpc.updateOffsets();                // Debug.output("***\nheight:" + height + ", width:" +                // width +                // "\n EditableOMCircle: east at x: " + gpe.getX() +                // ", y:" + gpe.getY());                // Debug.output(" EditableOMCircle: north at x: " +                // gpn.getX() +                // ", y:" + gpn.getY());                // Debug.output(" EditableOMCircle: northeast at x: "                // + gpne.getX() +                // ", y:" + gpne.getY());                // Debug.output(" EditableOMCircle: center at x: " +                // centerx +                // ", y:" + centery);            }            // Check to see if the circle is a offset circle, and set            // the            // offset grab point offsets accordingly.            if (circle.getRenderType() == OMGraphic.RENDERTYPE_OFFSET) {                gpo.updateOffsets();            }        } else {            Debug.message("eomg",                    "EditableOMCircle.setGrabPoints: graphic needs to be regenerated");        }    }    /**     * Take the current location of the GrabPoints, and modify the location     * parameters of the OMCircle with them. Called when you want the graphic to     * change according to the grab points.     */    public void setGrabPoints() {        int renderType = circle.getRenderType();        // If the gpm is a movement GP or the gpc, then we need to        // update all the grab points relative location to the gpm,        // and then use the code below.        // If the gpm is the gpo, then the circle moves, too. That's        // OK, because if the gpo is moving, then the other points        // have been moved already.        // If the gpm is one of the other GPs, then we need to update        // the radius or height and width based on that point, as well        // as the other GP locations.        Debug.message("eomg", "EditableOMCircle.setGrabPoints()");        // Do center point for lat/lon or offset circles        if (renderType == OMGraphic.RENDERTYPE_LATLON                || renderType == OMGraphic.RENDERTYPE_OFFSET) {            GrabPoint llgp;            // OK, to set the center, if the rendertype is offset,            // then the center lat/lon has to be set to the offset            // point. When the circle is initially defined, this is            // OK because the offset x and y are 0, and the render            // method knows not to render the point yet.            if (// movingPoint == gpo ||            renderType == OMGraphic.RENDERTYPE_OFFSET) {                llgp = gpo;            } else {                // If the moving point is the radius, the the center                // grab point is the lat/lon point.                llgp = gpc;            }            if (projection != null) {                LatLonPoint llp = projection.inverse(llgp.getX(), llgp.getY());                circle.setLatLon(llp.getLatitude(), llp.getLongitude());                // Do the radius for LATLON circles.                if (renderType == OMGraphic.RENDERTYPE_LATLON                        && movingPoint == gpr) {                    LatLonPoint llpm = projection.inverse(gpr.getX(),                            gpr.getY());                    float radius = Length.DECIMAL_DEGREE.fromRadians((float) GreatCircle.spherical_distance(llpm.radlat_,                            llpm.radlon_,                            llp.radlat_,                            llp.radlon_));                    setRadius(radius);                }            } else {                Debug.message("eomg",                        "EditableOMCircle.setGrabPoints: projection is null, can't figure out LATLON points for circle.");            }        }        boolean settingOffset = getStateMachine().getState() instanceof GraphicSetOffsetState                && movingPoint == gpo;        // If the center point is moving, the offset distance changes        if (renderType == OMGraphic.RENDERTYPE_OFFSET                && (settingOffset || movingPoint == gpc)) {            // Do the offset point.            circle.setOffX(gpc.getX() - gpo.getX());            circle.setOffY(gpc.getY() - gpo.getY());            Debug.message("eomg",                    "EditableOMCircle: updating offset distance, ox:"                            + circle.getOffX() + ", oy:" + circle.getOffY());        }        // Do the circle height and width for XY and OFFSET render        // types.        if (renderType == OMGraphic.RENDERTYPE_XY                || (renderType == OMGraphic.RENDERTYPE_OFFSET && !settingOffset)) {            if (renderType == OMGraphic.RENDERTYPE_XY) {                circle.setX(gpc.getX());                circle.setY(gpc.getY());            }            if (movingPoint instanceof HorizontalGrabPoint) {                // Must be the left or right...                circle.setWidth(Math.abs(movingPoint.getX() - gpc.getX()) * 2);            } else if (movingPoint instanceof VerticalGrabPoint) {                // Must be the top or bottom...                circle.setHeight(Math.abs(movingPoint.getY() - gpc.getY()) * 2);            } else if (movingPoint != gpo && movingPoint != gpc) {                // Must be one of the corners...                circle.setWidth(Math.abs(movingPoint.getX() - gpc.getX()) * 2);                circle.setHeight(Math.abs(movingPoint.getY() - gpc.getY()) * 2);            }            // Debug.output("EditableOMCircle.setGrabPoints():            // movingPoint x:" +            // movingPoint.getX() + ", y:" + movingPoint.getY() +            // ", gpc.x:" + gpc.getX() + ", gpc.y:" + gpc.getY());        }        if (projection != null) {            regenerate(projection);        }    }    /**     * To be overloaded if needed when setting circle's radius.     *      * @param radius in DECIMAL_DEGREES     */    protected void setRadius(float radius) {        if (circle != null) {            circle.setRadius(radius);        }    }    /**     * Called to set the OffsetGrabPoint to the current mouse location, and     * update the OffsetGrabPoint with all the other GrabPoint locations, so     * everything can shift smoothly. Should also set the OffsetGrabPoint to the     * movingPoint. Should be called only once at the beginning of the general     * movement, in order to set the movingPoint. After that, redraw(e) should     * just be called, and the movingPoint will make the adjustments to the     * graphic that are needed.     */    public void move(java.awt.event.MouseEvent e) {        if (getGraphic().getRenderType() == OMGraphic.RENDERTYPE_LATLON                && getGraphic().distanceToEdge(e.getX(), e.getY()) < 2) {            if (gpr == null) {                gpr = new GrabPoint(-1, -1);            }            gpr.set(e.getX(), e.getY());            movingPoint = gpr;        }    }    /**     * Use the current projection to place the graphics on the screen. Has to be     * called to at least assure the graphics that they are ready for rendering.     * Called when the graphic position changes.     *      * @param proj com.bbn.openmap.proj.Projection     * @return true     */    public boolean generate(Projection proj) {        Debug.message("eomg", "EditableOMCircle.generate()");        if (circle != null)            circle.generate(proj);        for (int i = 0; i < gPoints.length; i++) {            GrabPoint gp = gPoints[i];            if (gp != null) {                gp.generate(proj);                // Why is this here???                // if (gp instanceof OffsetGrabPoint) {                // ((OffsetGrabPoint)gpo).updateOffsets();                // }            }        }        return true;    }    /**     * Given a new projection, the grab points may need to be repositioned off     * the current position of the graphic. Called when the projection changes.     */    public void regenerate(Projection proj) {        Debug.message("eomg", "EditableOMCircle.regenerate()");        if (circle != null)            circle.regenerate(proj);        setGrabPoints(circle);        generate(proj);    }    /**     * Draw the EditableOMCircle parts into the java.awt.Graphics object. The     * grab points are only rendered if the circle machine state is     * CircleSelectedState.CIRCLE_SELECTED.     *      * @param graphics java.awt.Graphics.     */    public void render(java.awt.Graphics graphics) {        Debug.message("eomg", "EditableOMCircle.render()");        State state = getStateMachine().getState();        // All the rotation stuff isn't ready for primetime, yet.        // Need to translate the mouse events, too.        // graphics = graphics.create();        // double rotationAngle = OMGraphic.DEFAULT_ROTATIONANGLE;        if (circle != null) {            circle.setVisible(true);            circle.render(graphics);            circle.setVisible(false);            // rotationAngle = circle.getRotationAngle();        } else {            Debug.message("eomg", "EditableOMCircle.render: null circle.");        }        int renderType = circle.getRenderType();        // if (rotationAngle != OMGraphic.DEFAULT_ROTATIONANGLE) {        // ((java.awt.Graphics2D)graphics).rotate(rotationAngle,        // circle.getX(), circle.getY());        // }        if (state instanceof GraphicSelectedState                || state instanceof GraphicEditState) {            for (int i = 0; i < gPoints.length; i++) {                GrabPoint gp = gPoints[i];                if (gp != null) {                    if (i == RADIUS_POINT_INDEX)                        continue;                    if (renderType == OMGraphic.RENDERTYPE_LATLON                            && i != CENTER_POINT_INDEX)                        continue;                    if ((i == OFFSET_POINT_INDEX                            && renderType == OMGraphic.RENDERTYPE_OFFSET && movingPoint == gpo)                            ||                            (state instanceof GraphicSelectedState && ((i != OFFSET_POINT_INDEX && renderType != OMGraphic.RENDERTYPE_OFFSET) || (renderType == OMGraphic.RENDERTYPE_OFFSET)))                    ) {                        gp.setVisible(true);                        gp.render(graphics);                        gp.setVisible(false);                    }                }            }        }    }    /**     * If this EditableOMGraphic has parameters that can be manipulated that are     * independent of other EditableOMGraphic types, then you can provide the     * widgets to control those parameters here. By default, returns the     * GraphicAttributes GUI widgets. If you don't want a GUI to appear when a     * widget is being created/edited, then don't call this method from the     * EditableOMGraphic implementation, and return a null Component from     * getGUI.     *      * @param graphicAttributes the GraphicAttributes to use to get the GUI     *        widget from to control those parameters for this EOMG.     * @return java.awt.Component to use to control parameters for this EOMG.     */    public java.awt.Component getGUI(GraphicAttributes graphicAttributes) {        Debug.message("eomg", "EditableOMCircle.getGUI");        if (graphicAttributes != null) {            return graphicAttributes.getColorAndLineGUI();        } else {            return null;        }    }}

⌨️ 快捷键说明

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