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

📄 editableomrect.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                    if (renderType == OMGraphic.RENDERTYPE_LATLON) {                        doStraight = false;                        top = (int) p.getY();                        left = (int) p.getX();                        gpnw.set((int) p.getX(), (int) p.getY());                        p = projection.forward(slat, elon);                        gpse.set((int) p.getX(), (int) p.getY());                        p = projection.forward(nlat, elon);                        gpne.set((int) p.getX(), (int) p.getY());                        p = projection.forward(slat, wlon);                        gpsw.set((int) p.getX(), (int) p.getY());                        p = projection.forward(nlat - (nlat - slat) / 2f, wlon                                + (elon - wlon) / 2f);                        gpc.set((int) p.getX(), (int) p.getY());                    } else {                        latoffset = (int) p.getY();                        lonoffset = (int) p.getX();                        gpo.set(lonoffset, latoffset);                    }                }            }            if (doStraight) {                Debug.message("eomg",                        "EditableOMRect: drawing straight line rectangle");                top = rect.getTop() + latoffset;                bottom = rect.getBottom() + latoffset;                right = rect.getRight() + lonoffset;                left = rect.getLeft() + lonoffset;                // We have to do some fancy point wrangling to keep                // from messing up the next setGrabPoints().                if (movingPoint == gpc || movingPoint == gpo                        || movingPoint == null) {                    gpne.set(right, top);                    gpnw.set(left, top);                    gpse.set(right, bottom);                    gpsw.set(left, bottom);                } else if (movingPoint == gpnw) {                    gpne.set(gpse.getX(), gpnw.getY());                    gpsw.set(gpnw.getX(), gpse.getY());                } else if (movingPoint == gpse) {                    gpne.set(gpse.getX(), gpnw.getY());                    gpsw.set(gpnw.getX(), gpse.getY());                } else if (movingPoint == gpsw) {                    gpnw.set(gpsw.getX(), gpne.getY());                    gpse.set(gpne.getX(), gpsw.getY());                } else if (movingPoint == gpne) {                    gpnw.set(gpsw.getX(), gpne.getY());                    gpse.set(gpne.getX(), gpsw.getY());                }                int middlex = (right - left) / 2;                int middley = (bottom - top) / 2;                gpc.set(left + middlex, top + middley);                gpc.updateOffsets();                //              Debug.output("Center setting x: " + gpc.getX() + ",                // y:" + gpc.getY());            }            if (renderType == OMGraphic.RENDERTYPE_OFFSET) {                gpo.updateOffsets();            }        } else {            Debug.message("eomg",                    "EditableOMRect.setGrabPoints: graphic needs to be regenerated");        }    }    /**     * Take the current location of the GrabPoints, and modify the     * location parameters of the OMRect with them. Called when you     * want the graphic to change according to the grab points.     */    public void setGrabPoints() {        int renderType = rect.getRenderType();        LatLonPoint llp1;        Debug.message("eomg", "EditableOMRect.setGrabPoints()");        // Do center point for lat/lon or offset rects        if (renderType == OMGraphic.RENDERTYPE_LATLON) {            if (projection != null) {                // Need to figure out which point was moved, and then                // set the upper left and lower right points                // accordingly.                if (movingPoint == gpne) {                    llp1 = projection.inverse(gpne.getX(), gpne.getY());                    rect.lat1 = llp1.getLatitude();                    rect.lon2 = llp1.getLongitude();                } else if (movingPoint == gpnw) {                    llp1 = projection.inverse(gpnw.getX(), gpnw.getY());                    rect.lat1 = llp1.getLatitude();                    rect.lon1 = llp1.getLongitude();                } else if (movingPoint == gpsw) {                    llp1 = projection.inverse(gpsw.getX(), gpsw.getY());                    rect.lat2 = llp1.getLatitude();                    rect.lon1 = llp1.getLongitude();                } else if (movingPoint == gpse) {                    llp1 = projection.inverse(gpse.getX(), gpse.getY());                    LatLonPoint llp2 = projection.inverse(gpnw.getX(),                            gpnw.getY());                    rect.lat1 = llp2.getLatitude();                    rect.lon1 = llp2.getLongitude();                    rect.lat2 = llp1.getLatitude();                    rect.lon2 = llp1.getLongitude();                } else {                    //movingPoint == gpc                    llp1 = projection.inverse(gpc.getX(), gpc.getY());                    rect.lat1 = llp1.getLatitude() + diffy;                    rect.lon1 = llp1.getLongitude() - diffx;                    rect.lat2 = llp1.getLatitude() - diffy;                    rect.lon2 = llp1.getLongitude() + diffx;                }                rect.setNeedToRegenerate(true);            }        }        boolean settingOffset = getStateMachine().getState() instanceof GraphicSetOffsetState                && movingPoint == gpo;        // If the center point is moving, the offset distance changes        if (renderType == OMGraphic.RENDERTYPE_OFFSET) {            llp1 = projection.inverse(gpo.getX(), gpo.getY());            rect.lat1 = llp1.getLatitude();            rect.lon1 = llp1.getLongitude();            if (settingOffset || movingPoint == gpc) {                int halfheight = (gpse.getY() - gpnw.getY()) / 2;                int halfwidth = (gpse.getX() - gpnw.getX()) / 2;                // Don't call rect.setLocation because we only want to                // setNeedToRegenerate if !settingOffset.                rect.x1 = gpc.getX() - halfwidth - gpo.getX();                rect.y1 = gpc.getY() - halfheight - gpo.getY();                rect.x2 = gpc.getX() + halfwidth - gpo.getX();                rect.y2 = gpc.getY() + halfheight - gpo.getY();            }            if (!settingOffset) {                Debug.message("eomg", "EditableOMRect: updating offset rect");                if (movingPoint == gpnw || movingPoint == gpse) {                    rect.setLocation(gpnw.getX() - gpo.getX(), gpnw.getY()                            - gpo.getY(), gpse.getX() - gpo.getX(), gpse.getY()                            - gpo.getY());                } else if (movingPoint == gpne || movingPoint == gpsw) {                    rect.setLocation(rect.x1 = gpsw.getX() - gpo.getX(),                            gpne.getY() - gpo.getY(),                            gpne.getX() - gpo.getX(),                            gpsw.getY() - gpo.getY());                }                rect.setNeedToRegenerate(true);            }            // Set Location has reset the rendertype, but provides            // the convenience of setting the max and min values            // for us.            rect.setRenderType(OMGraphic.RENDERTYPE_OFFSET);        }        // Do the rect height and width for XY and OFFSET render        // types.        if (renderType == OMGraphic.RENDERTYPE_XY) {            Debug.message("eomg", "EditableOMRect: updating x/y rect");            if (movingPoint == gpc) {                int halfheight = (gpse.getY() - gpnw.getY()) / 2;                int halfwidth = (gpse.getX() - gpnw.getX()) / 2;                rect.setLocation(gpc.getX() - halfwidth, gpc.getY()                        - halfheight, gpc.getX() + halfwidth, gpc.getY()                        + halfheight);            } else if (movingPoint == gpnw || movingPoint == gpse) {                rect.setLocation(gpnw.getX(),                        gpnw.getY(),                        gpse.getX(),                        gpse.getY());            } else if (movingPoint == gpne || movingPoint == gpsw) {                rect.setLocation(gpsw.getX(),                        gpne.getY(),                        gpne.getX(),                        gpsw.getY());            }        }        if (projection != null) {            regenerate(projection);        }    }    /**     * 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) {}    /**     * 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("eomgdetail", "EditableOMRect.generate()");        if (rect != null)            rect.generate(proj);        for (int i = 0; i < gPoints.length; i++) {            GrabPoint gp = gPoints[i];            if (gp != null) {                gp.generate(proj);            }        }        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", "EditableOMRect.regenerate()");        if (rect != null)            rect.regenerate(proj);        setGrabPoints(rect);        generate(proj);    }    /**     * Draw the EditableOMRect parts into the java.awt.Graphics     * object. The grab points are only rendered if the rect machine     * state is RectSelectedState.RECT_SELECTED.     *      * @param graphics java.awt.Graphics.     */    public void render(java.awt.Graphics graphics) {        Debug.message("eomgdetail", "EditableOMRect.render()");        State state = getStateMachine().getState();        if (rect != null) {            rect.setVisible(true);            rect.render(graphics);            rect.setVisible(false);        } else {            Debug.message("eomg", "EditableOMRect.render: null rect.");        }        int renderType = rect.getRenderType();        if (state instanceof GraphicSelectedState                || state instanceof GraphicEditState) {            for (int i = 0; i < gPoints.length; i++) {                GrabPoint gp = gPoints[i];                if (gp != null) {                    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);                    }                }            }        }    }}

⌨️ 快捷键说明

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