editableomline.java

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

JAVA
457
字号
                // should appear on the map somewhere. If they don't,                // then then the end points may not be on the screen.                if (projection != null) {                    float[] ll = line.getLL();                    java.awt.Point p = projection.forward(ll[0], ll[1]);                    gp1.set((int) p.getX(), (int) p.getY());                    projection.forward(ll[2], ll[3], p);                    gp2.set((int) p.getX(), (int) p.getY());                }            } else {                // Grab the projected endpoints                Debug.message("eomg",                        "EditableOMLine: modifying x/y or offset standard line");                gp1.set(line.xpoints[0][0], line.ypoints[0][0]);                int last = line.xpoints[0].length - 1;                gp2.set(line.xpoints[0][last], line.ypoints[0][last]);            }            // Check to see if the line is a offset line, and set the            // offset grab point accordingly.            if (line.getRenderType() == OMGraphic.RENDERTYPE_OFFSET                    && projection != null) {                float[] ll = line.getLL();                java.awt.Point p = projection.forward(ll[0], ll[1]);                gpo.set((int) p.getX(), (int) p.getY());                gpo.updateOffsets();            }        } else {            Debug.message("eomg",                    "EditableOMLine.setGrabPoints: graphic needs to be regenerated");        }    }    /**     * Take the current location of the GrabPoints, and modify the     * location parameters of the OMLine with them. Called when you     * want the graphic to change according to the grab points.     */    public void setGrabPoints() {        int renderType = line.getRenderType();        if (renderType == OMGraphic.RENDERTYPE_LATLON) {            if (projection != null) {                float[] floats = new float[4];                com.bbn.openmap.LatLonPoint llp = projection.inverse(gp1.getX(),                        gp1.getY());                floats[0] = llp.getLatitude();                floats[1] = llp.getLongitude();                projection.inverse(gp2.getX(), gp2.getY(), llp);                floats[2] = llp.getLatitude();                floats[3] = llp.getLongitude();                line.setLL(floats);            } else {                Debug.message("eomg",                        "EditableOMLine.setGrabPoints: projection is null, can't figure out LATLON points for line.");            }        } else if (renderType == OMGraphic.RENDERTYPE_OFFSET) {            // Do the offset point.            if (projection != null) {                float[] floats = new float[4];                com.bbn.openmap.LatLonPoint llp = projection.inverse(gpo.getX(),                        gpo.getY());                floats[0] = llp.getLatitude();                floats[1] = llp.getLongitude();                floats[2] = 0;// not used                floats[3] = 0;// not used                line.setLL(floats);            } else {                Debug.message("eomg",                        "EditableOMLine.setGrabPoints: projection is null, can't figure out LATLON points for line offset.");            }        }        if (renderType == OMGraphic.RENDERTYPE_XY                || renderType == OMGraphic.RENDERTYPE_OFFSET) {            int[] ints = new int[4];            if (renderType == OMGraphic.RENDERTYPE_OFFSET && gpo != null) {                // If offset rendertype, the x-y have to be offset                // distances, not screen pixel locations.                ints[0] = gp1.getX() - gpo.getX();                ints[1] = gp1.getY() - gpo.getY();                ints[2] = gp2.getX() - gpo.getX();                ints[3] = gp2.getY() - gpo.getY();            } else {                ints[0] = gp1.getX();                ints[1] = gp1.getY();                ints[2] = gp2.getX();                ints[3] = gp2.getY();            }            line.setPts(ints);        }    }    /**     * 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(MouseEvent e) {        // Need to check to see if the OffsetGrabPoint is currently        // being used. If not, just use it, otherwise, will need to        // create a special one for the move.        if (line.getRenderType() == OMGraphic.RENDERTYPE_OFFSET) {            gpm = new OffsetGrabPoint(e.getX(), e.getY());            gpm.addGrabPoint(gp1);            gpm.addGrabPoint(gp2);        } else {            gpm = gpo;            gpm.set(e.getX(), e.getY());            gpm.updateOffsets();        }        movingPoint = gpm;    }    /**     * 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", "EditableOMLine.generate()");        if (line != null)            line.generate(proj);        if (gp1 != null)            gp1.generate(proj);        if (gp2 != null)            gp2.generate(proj);        if (gpo != null) {            gpo.generate(proj);            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", "EditableOMLine.regenerate()");        if (line != null)            line.generate(proj);        setGrabPoints(line);        if (gp1 != null)            gp1.generate(proj);        if (gp2 != null)            gp2.generate(proj);        if (gpo != null) {            gpo.generate(proj);            gpo.updateOffsets();        }    }    /**     * Draw the EditableOMLine parts into the java.awt.Graphics     * object. The grab points are only rendered if the line machine     * state is LineSelectedState.LINE_SELECTED.     *      * @param graphics java.awt.Graphics.     */    public void render(java.awt.Graphics graphics) {        Debug.message("eomg", "EditableOMLine.render()");        State state = getStateMachine().getState();        if (line != null) {            line.setVisible(true);            line.render(graphics);            line.setVisible(false);        } else {            Debug.message("eomg", "EditableOMLine.render: null line.");        }        if (state instanceof GraphicSelectedState) {            if (gp1 != null) {                gp1.setVisible(true);                gp1.render(graphics);                gp1.setVisible(false);            }            if (gp2 != null) {                gp2.setVisible(true);                gp2.render(graphics);                gp2.setVisible(false);            }        }        if (state instanceof GraphicSelectedState                || state instanceof GraphicEditState /*                                                         * || state                                                         * instanceof                                                         * LineSetOffsetState                                                         */) {            if (gpo != null                    && line.getRenderType() == OMGraphic.RENDERTYPE_OFFSET) {                gpo.setVisible(true);                gpo.render(graphics);                gpo.setVisible(false);            }        }    }}

⌨️ 快捷键说明

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