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

📄 cspeclayer.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    /**     * Handle a mouse cursor leaving a window or area.     *      * @param e MouseListener MouseEvent to handle.     */    public void mouseExited(MouseEvent e) {        if (acceptingEvents && specialist != null) {            handleGesture(e, MapGesture.motionEvent, false);        }    }    // Mouse Motion Listener events    ///////////////////////////////    /**     * Handle a mouse button being pressed while the mouse cursor is     * moving.     *      * @param e MouseMotionListener MouseEvent to handle.     * @return true if the listener was able to process the event.     */    public boolean mouseDragged(MouseEvent e) {        if (acceptingEvents && specialist != null) {            return handleGesture(e, MapGesture.motionEvent, true);        }        return false;    }    /**     * Handle a mouse cursor moving without the button being pressed.     *      * @param e MouseListener MouseEvent to handle.     * @return true if the listener was able to process the event.     */    public boolean mouseMoved(MouseEvent e) {        if (acceptingEvents && specialist != null) {            return handleGesture(e, MapGesture.motionEvent, false);        }        return false;    }    /**     * Handle a mouse cursor moving without the button being pressed,     * for events that have been used by something else.     */    public void mouseMoved() {        if (acceptingEvents && specialist != null) {            handleGesture(null, MapGesture.motionEvent, false);        }    }    /**     * Relays user gestures to the specialist or to the mousable     * objects of the CSpecLayer. The function finds the closest     * object and then its comp object all by itself.     * <p>     *      * @param evt MouseEvent     * @param MouseDown true if the mouse button is down     * @return true if gesture was consumed, false if not.     */    public boolean handleGesture(MouseEvent evt, int eventType,                                 boolean MouseDown) {        boolean got_info = false;        boolean got_the_stuff = false;        boolean updated_graphics = false;        OMGraphic moused = null;        JGraphicList jjGraphics = (JGraphicList) getList();        // Do this, so when there was a one-liner about a graphic (or        // something) sent, and now there isn't a graphic associated        // with the layer, to reset the message window to nothing, so        // stale info just doesn't hang out.        if (sentInfoLine) {            fireRequestInfoLine("");            sentInfoLine = false;        }        if (!isAcceptingEvents() || (jjGraphics == null)) {            return false;        }        // This will need to change, when we figure out who to make a        // Cspecialist capabile of handling a null event, so signify a        // reset...        if (evt == null) {            if (Debug.debugging("cspec")) {                Debug.output(getName()                        + "|CSpecLayer.handleGesture(): null evt!");            }            return false;//didn't consume gesture        }        try {            mapGesture.setMouseEvent(evt, eventType, MouseDown);            moused = jjGraphics.findClosest(evt.getX(),                    evt.getY(),                    selectDist.value);            com.bbn.openmap.CSpecialist.ActionUnion[] action = null;            switch (mapGesture.getMode()) {            case (short) MapGesture.Raw:                // send the gesture to the comp object or the                // specialist                // if it wants area events.                if (moused != null                        && ((JObjectHolder) moused).getObject().comp != null) {                    action = ((JObjectHolder) moused).getObject().comp.sendGesture(JGraphic.constructGesture(mapGesture),                            clientID);                } else if (specialist != null) {                    action = wantAreaEvents.value ? specialist.sendGesture(JGraphic.constructGesture(mapGesture),                            clientID)                            : null;                    if (action == null) {                        if (Debug.debugging("cspec"))                            Debug.output(getName()                                    + "|CSpecLayer.handleGesture(): null action!");                        return false; //didn't consume gesture                    }                    if (action.length == 0) {                        return false; //didn't consume gesture                    }                }                if (action == null) {                    if (Debug.debugging("cspec")) {                        System.err.println(getName()                                + "|CSpecLayer.handleGesture(): null action!");                    }                    return false; //didn't consume gesture                }                break;            case (short) MapGesture.Cooked:            default:                System.err.println("CSpecLayer|" + getName()                        + "|handleGesture() - cooked modes not supported");                break;            }            // parse the action sequence, ignore duplicate action            // directives            mapGesture.actionType = new int[action.length];            for (int i = 0; i < action.length; i++) {                switch (action[i].discriminator().value()) {                case MapGesture.NoAction:                    break;                case MapGesture.UpdateGraphics:                    updated_graphics = true;                    // now update the specified graphics                    updateGraphics(action[i].ginfo());                    break;                case MapGesture.InfoText:                    if (!got_info) { // can only have one instance                        if (Debug.debugging("cspec")) {                            Debug.output("CSpecLayer|" + getName()                                    + "|handleGesture(): Requesting Info Text "                                    + action[i].itext());                        }                        fireRequestInfoLine(action[i].itext());                        sentInfoLine = true;                        got_info = true;                    }                    break;                case MapGesture.PlainText:                    if (!got_the_stuff) {                        if (Debug.debugging("cspec")) {                            Debug.output("CSpecLayer|"                                    + getName()                                    + "|handleGesture(): Requesting Plain Text "                                    + action[i].ptext());                        }                        fireRequestBrowserContent(action[i].ptext());                        got_the_stuff = true;                    }                    break;                case MapGesture.HTMLText:                    if (!got_the_stuff) {                        if (Debug.debugging("cspec")) {                            Debug.output("CSpecLayer|" + getName()                                    + "|handleGesture(): Requesting HTML Text "                                    + action[i].htext());                        }                        fireRequestBrowserContent(action[i].htext());                        got_the_stuff = true;                    }                    break;                case MapGesture.URL:                    if (!got_the_stuff) {                        if (Debug.debugging("cspec")) {                            Debug.output("CSpecLayer|" + getName()                                    + "|handleGesture(): Requesting URL "                                    + action[i].url());                        }                        fireRequestURL(action[i].url());                        got_the_stuff = true;                    }                    break;                case MapGesture.UpdatePalette:                default:                    System.err.println("CSpecLayer|" + getName()                            + "|handleGesture(): invalid ActionSeq");                    break;                }            }        } catch (org.omg.CORBA.SystemException e) {            System.err.println(getName() + "|CSpecLayer.handleGesture(): " + e);            if (showDialogs) {                postCORBAErrorMsg("CORBA Exception while gesturing on\n"                        + getName() + " specialist:\n" + e.getClass().getName());            }            return false;        } catch (OutOfMemoryError e) {            setSpecialist(null);            if (showDialogs) {                postMemoryErrorMsg("OutOfMemory while gesturing on\n"                        + getName() + " specialist.");            }            return false;        } catch (Throwable t) {            if (showDialogs) {                postException("Exception while gesturing on\n" + getName()                        + " specialist:\n" + t.getClass().getName());            }            t.printStackTrace();            return false;        }        if (updated_graphics) {            repaint();        }        return true;//consumed the gesture    }    /**     * Changes attributes of existing graphics, or adds new graphics,     * or reorders graphics.     * <p>     *      * @param updateRec com.bbn.openmap.CSpecialist.UpdateRecord[]     */    protected void updateGraphics(                                  com.bbn.openmap.CSpecialist.UpdateRecord[] updateRec) {        JGraphicList jGraphics = (JGraphicList) getList();        Projection projection = getProjection();        com.bbn.openmap.CSpecialist.UpdateGraphic upgraphic = null;        // parse updateRec (an array of UpdateRecord)        for (int i = 0; i < updateRec.length; i++) {            String gID = updateRec[i].gID; // get the graphic ID            // parse the sequence of updates to perform on the            // graphic. You need to do this because the types of            // changes that can be made to each object can be part of            // the specific object, like _GT_Bitmap (location, bits,            // height/width), or part of the _GT_Graphic            // (color/stipple changes), or _GT_ReorderGraphic, or            // whatever.            for (int j = 0; j < updateRec[i].objectUpdates.length; j++) {                upgraphic = updateRec[i].objectUpdates[j];                // determine the type of graphic update                switch (upgraphic.discriminator().value()) {                case com.bbn.openmap.CSpecialist.GraphicPackage.GraphicType._GT_Graphic:                    JObjectHolder graphic = (JObjectHolder) jGraphics.getOMGraphicWithId(gID);                    if (graphic != null) {                        graphic.update(upgraphic.gf_update());                        ((OMGraphic) graphic).regenerate(projection);                    }                    break;                case com.bbn.openmap.CSpecialist.GraphicPackage.GraphicType._GT_Bitmap:                    JBitmap bitmap = (JBitmap) jGraphics.getOMGraphicWithId(gID);                    if (bitmap != null) {                        bitmap.update(upgraphic.bf_update());                        bitmap.regenerate(projection);                    }                    break;                case com.bbn.openmap.CSpecialist.GraphicPackage.GraphicType._GT_Text:                    JText text = (JText) jGraphics.getOMGraphicWithId(gID);                    if (text != null) {                        text.update(upgraphic.tf_update());                        text.regenerate(projection);                    }                    break;                case com.bbn.openmap.CSpecialist.GraphicPackage.GraphicType._GT_Poly:                    JPoly poly = (JPoly) jGraphics.getOMGraphicWithId(gID);                    if (poly != null) {                        poly.update(upgraphic.pf_update());                        poly.regenerate(projection);                    }                    break;                case com.bbn.openmap.CSpecialist.GraphicPackage.GraphicType._GT_Line:                    JLine line = (JLine) jGraphics.getOMGraphicWithId(gID);                    if (line != null) {                        line.update(upgraphic.lf_update());                        line.regenerate(projection);                    }                    break;                case com.bbn.openmap.CSpecialist.GraphicPackage.GraphicType._GT_Rectangle:                    JRect rect = (JRect) jGraphics.getOMGraphicWithId(gID);                    if (rect != null) {                        rect.update(upgraphic.rf_update());                        rect.regenerate(projection);                    }                    break;                case com.bbn.openmap.CSpecialist.GraphicPackage.GraphicType._GT_Raster:                    JRaster raster = (JRaster) jGraphics.getOMGraphicWithId(gID);                    if (raster != null) {                        raster.update(upgraphic.rasf_update());                        raster.regenerate(projection);                    }                    break;                case com.bbn.openmap.CSpecialist.GraphicPackage.GraphicType._GT_Circle:                    JCircle circ = (JCircle) jGraphics.getOMGraphicWithId(gID);                    if (circ != null) {                        circ.update(upgraphic.cf_update());                        circ.regenerate(projection);                    }                    break;                case com.bbn.openmap.CSpecialist.GraphicPackage.GraphicType._GT_UnitSymbol:                    JUnit unitsymbol = (JUnit) jGraphics.getOMGraphicWithId(gID);                    if (unitsymbol != null) {                        unitsymbol.update(upgraphic.usf_update());                        unitsymbol.regenerate(projection);                    }                    break;                // Uncomment when implemented!!!!                case com.bbn.openmap.CSpecialist.GraphicPackage.GraphicType._GT_2525Symbol:                case com.bbn.openmap.CSpecialist.GraphicPackage.GraphicType._GT_ForceArrow:                case com.bbn.openmap.CSpecialist.GraphicPackage.GraphicType._GT_NewGraphic:                case com.bbn.openmap.CSpecialist.GraphicPackage.GraphicType._GT_ReorderGraphic:                    System.err.println("CSpecLayer|"                            + getName()                            + "|updateGraphics: Graphics Update Type not implemented.");                    break;//HACK - unimplemented                // unknown update                default:                    System.err.println("CSpecLayer|" + getName()                            + "|updateGraphics: ignoring weird update");                    break;                }            }        }    }    /**     * Check if layer will show error dialogs.     *      * @return boolean     */    public boolean getShowDialogs() {        return showDialogs;    }    /**     * Set showDialogs behavior.     *      * @param show show dialog popups?     */    public void setShowDialogs(boolean show) {        showDialogs = show;    }    /**     *       */    protected void postMemoryErrorMsg(String msg) {        fireRequestMessage(new InfoDisplayEvent(this, msg));    }    /**     *       */    protected void postCORBAErrorMsg(String msg) {        fireRequestMessage(new InfoDisplayEvent(this, msg));    }    /**     *       */    protected void postException(String msg) {        fireRequestMessage(new InfoDisplayEvent(this, msg));    }    /**     * Free up memory after being removed from the Map     */    public void removed(java.awt.Container cont) {        if (Debug.debugging("cspec")) {            Debug.output(getName()                    + "CSpecLayer.removed(): Nullifying graphics");        }        if (specialist != null) {            specialist.signoff(clientID);        }        setSpecialist(null);    }}

⌨️ 快捷键说明

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