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

📄 editableomgraphic.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    /**     * 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.     */    public abstract void move(MouseEvent e);    /**     * Clean the surface all the painting is taking place over.     */    public void cleanMap(MouseEvent e) {        Object obj = e.getSource();        if (!(obj instanceof MapBean)) {            return;        }        // Could call repaint(), but I think we should paint in this        // thread...        MapBean map = (MapBean) obj;        // Gets the buffer cleaned out.        map.setBufferDirty(true);        map.paintChildren(map.getGraphics());    }    /** Same as redraw(e, false) */    public void redraw(MouseEvent e) {        redraw(e, false);    }    public void redraw(MouseEvent e, boolean firmPaint) {        redraw(e, firmPaint, true);    }    /**     * A DrawingAttributes object used to hold OMGraphic settings     * while it is being moved. When an OMGraphic is being moved,     * basic (DEFAULT) settings are put on the OMGraphic to make it as     * light and uncomplicated as possible.     */    protected DrawingAttributes holder = new DrawingAttributes();    /**     * Given a MouseEvent, check the source, and if it's a MapBean,     * then grab the projection and java.awt.Graphics from it to use     * for generation and rendering of the EditableOMGraphic objects.     *      * @param e MouseEvent     * @param firmPaint true if the graphic is being rendered at rest,     *        with fill colors and true colors, with the grab point if     *        the state allows it. If false, then the fill color will     *        not be used, and just the graphic will be drawn. Use     *        false for graphics that are moving.     */    public void redraw(MouseEvent e, boolean firmPaint, boolean drawXOR) {        if (DEBUG) {            Debug.output("EditableOMGraphic.redraw("                    + (firmPaint ? "firmPaint)" : ")"));        }        if (e == null) {            if (lastMouseEvent == null) {                return;            }            e = lastMouseEvent;        }        Object obj = e.getSource();        if (!(obj instanceof MapBean)) {            return;        }        MapBean map = (MapBean) obj;        Graphics g = map.getGraphics();        OMGraphic graphic = getGraphic();        if (firmPaint) {            // So, with a firm paint, we want to clean the screen. If            // the map is being buffered, we need to clean out the            // buffer, which is why we set the Request paint to true,            // to get the image rebuilt. Otherwise, a copy of the            // graphic remains.            map.setBufferDirty(true);            graphic.generate(getProjection());            map.repaint();        } else {            // If we get here, we are painting a moving object, so we            // only want to do the outline to make it as fast as            // possible.            holder.setFrom(graphic);            DrawingAttributes.DEFAULT.setTo(graphic);            modifyOMGraphicForEditRender();            graphic.regenerate(getProjection());            if (drawXOR) {                g.setXORMode(Color.lightGray);                g.setColor((Color) graphic.getDisplayPaint());                render(g);            }            GrabPoint gp = getMovingPoint();            if (gp != null) {                gp.set(e.getX(), e.getY());                if (gp instanceof OffsetGrabPoint) {                    ((OffsetGrabPoint) gp).moveOffsets();                }                setGrabPoints();            }        }        if (!firmPaint) {            generate(getProjection());            render(g);            holder.setTo(graphic);        }        resetOMGraphicAfterEditRender();        g.dispose();        lastMouseEvent = e;    }    protected MouseEvent lastMouseEvent;    /**     * A convenience method that gives an EditableOMGraphic a chance     * to modify the OMGraphic so it can be drawn quickly, by turning     * off labels, etc, right before the XORpainting happens. The     * OMGraphic should be configured so that the render method does     * the least amount of painting possible. Note that the     * DrawingAttributes for the OMGraphic have already been set to     * DrawingAttributes.DEFAULT (black line, clear fill).     */    protected void modifyOMGraphicForEditRender() {}    /**     * A convenience method that gives an EditableOMGraphic a chance     * to reset the OMGraphic so it can be rendered normally, after it     * has been modified for quick paints. The DrawingAttributes for     * the OMGraphic have already been reset to their normal settings,     * from the DrawingAttributes.DEFAULT settings that were used for     * the quick paint.     */    protected void resetOMGraphicAfterEditRender() {}    public void repaint() {        if (lastMouseEvent != null) {            redraw(lastMouseEvent, true);        }    }    public void finalize() {        if (getGraphic() != null) {            getGraphic().setVisible(true);        }        if (Debug.debugging("gc")) {            Debug.output("EditableOMGraphic gone.");        }    }    /**     * 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 abstract boolean generate(Projection proj);    /**     * Given a new projection, the grab points may need to be     * repositioned off the current position of the graphic. Called     * when the projection changes. IMPORTANT! Set the GrabPoints for     * the graphic here.     */    public abstract void regenerate(Projection proj);    public void repaintRender(Graphics g) {        render(g);    }    /**     */    public abstract void render(Graphics g);    /**     * Set the current projection.     */    public void setProjection(Projection proj) {        projection = proj;        // This is important. In the EditableOMGraphics, the        // GrabPoints are set when regenerate is called.        regenerate(proj);    }    /**     * Get the current projection.     */    public Projection getProjection() {        return projection;    }    // Mouse Listener events    ////////////////////////    /**     */    public boolean mousePressed(MouseEvent e) {        if (DEBUG_DETAIL)            Debug.output(getClass().getName() + ".mousePressed()");        if (!mouseOnMap)            return false;        return stateMachine.getState().mousePressed(e);    }    /**     */    public boolean mouseReleased(MouseEvent e) {        if (DEBUG_DETAIL)            Debug.output(getClass().getName() + ".mouseReleased()");        if (!mouseOnMap)            return false;        return stateMachine.getState().mouseReleased(e);    }    /**     */    public boolean mouseClicked(MouseEvent e) {        if (DEBUG_DETAIL)            Debug.output(getClass().getName() + ".mouseClicked()");        if (!mouseOnMap)            return false;        return stateMachine.getState().mouseClicked(e);    }    boolean mouseOnMap = true;    /**     */    public void mouseEntered(MouseEvent e) {        if (DEBUG_DETAIL)            Debug.output(getClass().getName() + ".mouseEntered()");        mouseOnMap = true;        stateMachine.getState().mouseEntered(e);    }    /**     */    public void mouseExited(MouseEvent e) {        if (DEBUG_DETAIL)            Debug.output(getClass().getName() + ".mouseExited()");        mouseOnMap = false;        stateMachine.getState().mouseExited(e);    }    // Mouse Motion Listener events    ///////////////////////////////    /**     */    public boolean mouseDragged(MouseEvent e) {        if (DEBUG_DETAIL)            Debug.output(getClass().getName() + ".mouseDragged()");        if (!mouseOnMap)            return false;        return stateMachine.getState().mouseDragged(e);    }    /**     */    public boolean mouseMoved(MouseEvent e) {        if (DEBUG_DETAIL)            Debug.output(getClass().getName() + ".mouseMoved()");        if (!mouseOnMap)            return false;        return stateMachine.getState().mouseMoved(e);    }    /**     */    public void mouseMoved() {        if (DEBUG_DETAIL)            Debug.output(getClass().getName() + ".mouseMoved()");        if (!mouseOnMap)            return;        stateMachine.getState().mouseMoved();    }    /**     * Add a EOMGListener.     *      * @param l EOMGListener     */    public synchronized void addEOMGListener(EOMGListener l) {        if (listeners == null) {            listeners = new EOMGListenerSupport(this);        }        listeners.addEOMGListener(l);    }    /**     * Remove a EOMGListener.     *      * @param l EOMGListener     */    public synchronized void removeEOMGListener(EOMGListener l) {        if (listeners == null) {            return;        }        listeners.removeEOMGListener(l);    }    /**     * The method to call if you want to let listeners know that the     * state has changed. Usually called when a graphic is selected or     * not, so that GUIs can be directed.     */    public void fireEvent(EOMGEvent event) {        if (listeners != null) {            listeners.fireEvent(event);        }    }    /**     * Create the event with a Cursor and/or message, and then fire     * it.     *      * @param cursor Cursor to be used.     * @param message an instruction/error to be displayed to the     *        user.     */    public void fireEvent(Cursor cursor, String message) {        fireEvent(cursor, message, null);    }    /**     * Create the event with the Cursor, message and/or MouseEvent.     *      * @param cursor Cursor to be used.     * @param message an instruction/error to be displayed to the     *        user.     * @param mouseEvent where that caused the EOMGEvent. May be null.     */    public void fireEvent(Cursor cursor, String message, MouseEvent mouseEvent) {        if (listeners != null) {            EditableOMGraphic theSource = listeners.getEOMG();            EOMGEvent event = new EOMGEvent(theSource, cursor, message, mouseEvent);            fireEvent(event);        }    }    /**     * Create the event with no cursor change or message to be     * displayed.     */    public void fireEvent() {        fireEvent(null, null);    }    /**     * 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, this method returns null, which     * indicates that you can extend this method to return a Component     * that controls parameters for the EditableOMGraphic other than     * the GraphicAttribute parameters. Should return something like a     * toolbar, small.     *      * @return Component to control EOMG parameters, without the     *         GraphicAttribute GUI.     */    public Component getGUI() {        return getGUI(null);    }    /**     * 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 Component to use to control parameters for this EOMG.     */    public Component getGUI(GraphicAttributes graphicAttributes) {        if (graphicAttributes != null) {            graphicAttributes.setLineMenuAdditions(null);            return graphicAttributes.getGUI();        }        return null;    }}

⌨️ 快捷键说明

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