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

📄 editableomscalingraster.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                top = raster.getY() + latoffset;                bottom = raster.getY() + raster.getHeight() + latoffset;                right = raster.getX() + raster.getWidth() + lonoffset;                left = raster.getX() + 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",                    "EditableOMScalingRaster.setGrabPoints: graphic needs to be regenerated");        }    }    /**     * @param icon     */    protected void setGrabPointsForOMSI(OMScalingIcon icon) {        if (projection != null) {            float lon = icon.getLon();            float lat = icon.getLat();            int renderType = icon.getRenderType();            LatLonPoint llp = new LatLonPoint(lat, lon);            java.awt.Point p = projection.forward(llp);            if (renderType == OMGraphic.RENDERTYPE_LATLON) {                gpc.set((int) p.getX(), (int) p.getY());            }        }    }    protected void setGrabPointsForOMSI() {        if (projection != null) {            //movingPoint == gpc            LatLonPoint llp1 = projection.inverse(gpc.getX(), gpc.getY());            raster.setLat(llp1.getLatitude());            raster.setLon(llp1.getLongitude());            // point.setNeedToRegenerate set        }        if (projection != null) {            regenerate(projection);        }    }    /**     * Take the current location of the GrabPoints, and modify the     * location parameters of the OMScalingRaster with them. Called     * when you want the graphic to change according to the grab     * points.     */    public void setGrabPoints() {        int renderType = raster.getRenderType();        LatLonPoint llp1;        Debug.message("eomg", "EditableOMScalingRaster.setGrabPoints()");        // Do center point for lat/lon or offset rects        if (renderType == OMGraphic.RENDERTYPE_LATLON) {            if (projection != null) {                if (raster instanceof OMScalingIcon) {                    setGrabPointsForOMSI();                    return;                }                // 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());                    raster.setULLat(llp1.getLatitude());                    raster.setLRLon(llp1.getLongitude());                } else if (movingPoint == gpnw) {                    llp1 = projection.inverse(gpnw.getX(), gpnw.getY());                    raster.setULLat(llp1.getLatitude());                    raster.setULLon(llp1.getLongitude());                } else if (movingPoint == gpsw) {                    llp1 = projection.inverse(gpsw.getX(), gpsw.getY());                    raster.setLRLat(llp1.getLatitude());                    raster.setULLon(llp1.getLongitude());                } else if (movingPoint == gpse) {                    llp1 = projection.inverse(gpse.getX(), gpse.getY());                    LatLonPoint llp2 = projection.inverse(gpnw.getX(),                            gpnw.getY());                    raster.setULLat(llp2.getLatitude());                    raster.setULLon(llp2.getLongitude());                    raster.setLRLat(llp1.getLatitude());                    raster.setLRLon(llp1.getLongitude());                } else {                    //movingPoint == gpc                    llp1 = projection.inverse(gpc.getX(), gpc.getY());                    raster.setULLat(llp1.getLatitude() + diffy);                    raster.setULLon(llp1.getLongitude() - diffx);                    raster.setLRLat(llp1.getLatitude() - diffy);                    raster.setLRLon(llp1.getLongitude() + diffx);                }                raster.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());            raster.setULLat(llp1.getLatitude());            raster.setULLon(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.                llp1 = projection.inverse(gpc.getX() - halfwidth - gpo.getX(),                        gpc.getY() - halfheight - gpo.getY());                LatLonPoint llp2 = projection.inverse(gpc.getX() + halfwidth                        - gpo.getX(), gpc.getY() + halfheight - gpo.getY());                raster.setULLat(llp1.getLatitude());                raster.setULLon(llp1.getLongitude());                raster.setLRLat(llp2.getLatitude());                raster.setLRLon(llp2.getLongitude());            }            if (!settingOffset) {                Debug.message("eomg",                        "EditableOMScalingRaster: updating offset rect");                if (movingPoint == gpnw || movingPoint == gpse) {                    llp1 = projection.inverse(gpnw.getX() - gpo.getX(),                            gpnw.getY() - gpo.getY());                    LatLonPoint llp2 = projection.inverse(gpse.getX()                            - gpo.getX(), gpse.getY() - gpo.getY());                    raster.setULLat(llp1.getLatitude());                    raster.setULLon(llp1.getLongitude());                    raster.setLRLat(llp2.getLatitude());                    raster.setLRLon(llp2.getLongitude());                } else if (movingPoint == gpne || movingPoint == gpsw) {                    llp1 = projection.inverse(gpsw.getX() - gpo.getX(),                            gpne.getY() - gpo.getY());                    LatLonPoint llp2 = projection.inverse(gpne.getX()                            - gpo.getX(), gpsw.getY() - gpo.getY());                    raster.setULLat(llp1.getLatitude());                    raster.setULLon(llp1.getLongitude());                    raster.setLRLat(llp2.getLatitude());                    raster.setLRLon(llp2.getLongitude());                }                raster.setNeedToRegenerate(true);            }            // Set Location has reset the rendertype, but provides            // the convenience of setting the max and min values            // for us.            raster.setRenderType(OMGraphic.RENDERTYPE_OFFSET);        }        // Do the rect height and width for XY and OFFSET render        // types.        if (renderType == OMGraphic.RENDERTYPE_XY) {            Debug.message("eomg", "EditableOMScalingRaster: updating x/y rect");            if (movingPoint == gpc) {                int halfheight = (gpse.getY() - gpnw.getY()) / 2;                int halfwidth = (gpse.getX() - gpnw.getX()) / 2;                llp1 = projection.inverse(gpc.getX() - halfwidth, gpc.getY()                        - halfheight);                LatLonPoint llp2 = projection.inverse(gpc.getX() + halfwidth,                        gpc.getY() + halfheight);                raster.setULLat(llp1.getLatitude());                raster.setULLon(llp1.getLongitude());                raster.setLRLat(llp2.getLatitude());                raster.setLRLon(llp2.getLongitude());            } else if (movingPoint == gpnw || movingPoint == gpse) {                llp1 = projection.inverse(gpnw.getX(), gpnw.getY());                LatLonPoint llp2 = projection.inverse(gpse.getX(), gpse.getY());                raster.setULLat(llp1.getLatitude());                raster.setULLon(llp1.getLongitude());                raster.setLRLat(llp2.getLatitude());                raster.setLRLon(llp2.getLongitude());            } else if (movingPoint == gpne || movingPoint == gpsw) {                llp1 = projection.inverse(gpsw.getX(), gpne.getY());                LatLonPoint llp2 = projection.inverse(gpne.getX(), gpsw.getY());                raster.setULLat(llp1.getLatitude());                raster.setULLon(llp1.getLongitude());                raster.setLRLat(llp2.getLatitude());                raster.setLRLon(llp2.getLongitude());            }        }        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", "EditableOMScalingRaster.generate()");        if (raster != null)            raster.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", "EditableOMScalingRaster.regenerate()");        if (raster != null)            raster.regenerate(proj);        setGrabPoints(raster);        generate(proj);    }    /**     * Draw the EditableOMScalingRaster 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", "EditableOMScalingRaster.render()");        State state = getStateMachine().getState();        if (raster != null) {            raster.setVisible(true);            raster.render(graphics);            raster.setVisible(false);        } else {            Debug.message("eomg", "EditableOMScalingRaster.render: null rect.");        }        int renderType = raster.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 + -