linklayer.java

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

JAVA
1,315
字号
            }            OMGraphic gug = gu.graphic;            OMGraphic reactionGraphic = null;            int reactionGraphicIndex = Link.UNKNOWN;            if (LinkUtil.isMask(gu.action, UPDATE_ADD_GRAPHIC_MASK)) {                if (Debug.debugging("link")) {                    Debug.output("LinkLayer.handleLinkActionList: adding graphic, id:"                            + gu.id);                }                if (gug != null) {                    gug.generate(proj);                    graphics.add(gug);                    reactionGraphic = gug;                } else {                    Debug.message("link",                            "LinkLayer.handleLinkActionList: trying to add null OMGraphic, id: "                                    + gu.id);                }            } else if (gu.id != null) {                reactionGraphicIndex = graphics.getOMGraphicIndexWithId(gu.id);                if (reactionGraphicIndex == Link.UNKNOWN) {                    // Must be an addition/new graphic                    if (LinkUtil.isMask(gu.action, UPDATE_ADD_GRAPHIC_MASK)) {                        // If gu.graphic is null, this will throw an                        // exception                        if (Debug.debugging("link")) {                            Debug.output("LinkLayer.handleLinkActionList: adding graphic "                                    + gu.id);                        }                        if (gug != null) {                            gug.generate(proj);                            graphics.add(gug);                            reactionGraphic = gug;                        } else {                            Debug.message("link",                                    "LinkLayer.handleLinkActionList: trying to add null OMGraphic, id: "                                            + gu.id);                        }                    } else {                        gu.action = 0; // No action...                        Debug.error("LinkLayer.handleLinkActionList: Gesture Response on an unknown graphic.");                    }                } else if (LinkUtil.isMask(gu.action, UPDATE_GRAPHIC_MASK)) {                    if (gug != null) {                        gug.generate(proj);                        reactionGraphic = gug;                    } else {                        Debug.message("link",                                "LinkLayer.handleLinkActionList: trying to update null OMGraphic, id: "                                        + gu.id);                    }                } else {                    reactionGraphic = graphics.getOMGraphicWithId(gu.id);                }            } else {                Debug.error("LinkLayer.handleLinkActionList:  null ID for graphic");            }            // Now, perform the appropriate action on the graphic...            // Delete a graphic... If you do this, nothing else            // gets done on the graphic...            if (LinkUtil.isMask(gu.action, MODIFY_DELETE_GRAPHIC_MASK)) {                Debug.message("link", "LinkLayer: deleting graphic");                graphics.removeOMGraphicAt(reactionGraphicIndex);            } else {                // For properties updating, or graphic replacement                if (LinkUtil.isMask(gu.action, UPDATE_GRAPHIC_MASK)) {                    Debug.message("link", "LinkLayer: updating graphic");                    graphics.setOMGraphicAt(reactionGraphic,                            reactionGraphicIndex);                }                // For graphic selection and deselection                if (LinkUtil.isMask(gu.action, MODIFY_SELECT_GRAPHIC_MASK)) {                    Debug.message("link", "LinkLayer: selecting graphic");                    reactionGraphic.select();                } else if (LinkUtil.isMask(gu.action,                        MODIFY_DESELECT_GRAPHIC_MASK)) {                    Debug.message("link", "LinkLayer: deselecting graphic");                    reactionGraphic.deselect();                }                // Now, raising or lowering the graphic...                if (LinkUtil.isMask(gu.action, MODIFY_RAISE_GRAPHIC_MASK)) {                    Debug.message("link", "LinkLayer: raising graphic");                    graphics.moveIndexedToTop(reactionGraphicIndex);                } else if (LinkUtil.isMask(gu.action, MODIFY_LOWER_GRAPHIC_MASK)) {                    Debug.message("link", "LinkLayer: lowering graphic");                    graphics.moveIndexedToBottom(reactionGraphicIndex);                }            } // else if not deleting it...        } // while        if (lal.getNeedMapUpdate()) {            updateMap(lal.getMapProperties());            lal.setNeedMapUpdate(false);            needRepaint = false;        }        if (needRepaint) {            repaint();        }    }    public void handleLinkActionRequest(LinkActionRequest lar) {        Debug.message("link", "LinkLayer.handleLinkActionRequest()");        if (lar != null) {            setGestureDescriptor(lar.getDescriptor());        }    }    /**     * Looks at a properties object, and checks for the pre-defined messaging     * attributes. Then, the information delegator is called to handle their     * display.     *      * @param props LinkProperties containing messages.     */    public void handleMessages(LinkProperties props) {        String value = props.getProperty(LPC_INFO);        if (value != null)            fireRequestInfoLine(value);        value = props.getProperty(LPC_URL);        if (value != null) {            fireRequestURL(value);        } else {            value = props.getProperty(LPC_HTML);            if (value != null)                fireRequestBrowserContent(value);        }        value = props.getProperty(LPC_MESSAGE);        if (value != null)            fireRequestMessage(value);    }    // ----------------------------------------------------------------------    // MapMouseListener interface implementation    // ----------------------------------------------------------------------    /** Return the MapMouseListener for the layer. */    public synchronized MapMouseListener getMapMouseListener() {        return this;    }    /**     * Return the strings identifying the Mouse Modes that the MapMouseListener     * wants to receive gestures from.     */    public String[] getMouseModeServiceList() {        String[] services = { SelectMouseMode.modeID };        return services;    }    public boolean mousePressed(MouseEvent e) {        if (LinkUtil.isMask(getGestureDescriptor(), MOUSE_PRESSED_MASK)) {            return handleGesture(MOUSE_PRESSED_MASK, e);        }        return false;    }    public boolean mouseReleased(MouseEvent e) {        if (LinkUtil.isMask(getGestureDescriptor(), MOUSE_RELEASED_MASK)) {            return handleGesture(MOUSE_RELEASED_MASK, e);        }        return false;    }    public boolean mouseClicked(MouseEvent e) {        if (LinkUtil.isMask(getGestureDescriptor(), MOUSE_CLICKED_MASK)) {            return handleGesture(MOUSE_CLICKED_MASK, e);        }        return false;    }    public void mouseEntered(MouseEvent e) {        if (LinkUtil.isMask(getGestureDescriptor(), MOUSE_ENTERED_MASK)) {            handleGesture(MOUSE_ENTERED_MASK, e);        }    }    public void mouseExited(MouseEvent e) {        if (LinkUtil.isMask(getGestureDescriptor(), MOUSE_EXITED_MASK)) {            handleGesture(MOUSE_EXITED_MASK, e);        }    }    public boolean mouseDragged(MouseEvent e) {        if (LinkUtil.isMask(getGestureDescriptor(), MOUSE_DRAGGED_MASK)) {            return handleGesture(MOUSE_DRAGGED_MASK, e);        }        return false;    }    public boolean mouseMoved(MouseEvent e) {        if (LinkUtil.isMask(getGestureDescriptor(), MOUSE_MOVED_MASK)) {            return handleGesture(MOUSE_MOVED_MASK, e);        }        return false;    }    public void mouseMoved() {        if (LinkUtil.isMask(getGestureDescriptor(), MOUSE_MOVED_MASK)) {            handleGesture(MOUSE_MOVED_MASK, null);        }    }    /**     * Given a graphic and the type of gesture caught, react to it based on the     * properties object located in the Graphic. The default behavior here is     * that if the gesture is a MouseMoved, select the graphic, and if there is     * an info line, show it. If the gesture is a MouseRelease, display the info     * line, and also check the following, in this order: url and then html. If     * there is a message property, the message is sent in a pop-up window.     *      * @param graphic the graphic to check out.     * @param descriptor the type of gesture.     * @param e mouse event, to get location.     * @return true if the server still needs to be told - per descriptor bit     *         11.     */    protected boolean graphicGestureReaction(OMGraphic graphic, int descriptor,                                             MouseEvent e) {        LinkProperties props = (LinkProperties) graphic.getAppObject();        // Mouse clicked        boolean mc = LinkUtil.isMask(descriptor, MOUSE_CLICKED_MASK);        // Mouse released        boolean mr = LinkUtil.isMask(descriptor, MOUSE_RELEASED_MASK);        // Mouse moved        boolean mm = LinkUtil.isMask(descriptor, MOUSE_MOVED_MASK);        // server inform        boolean si = LinkUtil.isMask(getGestureDescriptor(),                SERVER_NOTIFICATION_MASK);        boolean ret = true;        if (mr || mc) {            String url = props.getProperty(LPC_URL);            if (url != null) {                if (Debug.debugging("link")) {                    System.out.println("LinkLayer:graphicGestureReaction: displaying url: "                            + url);                }                fireRequestURL(url);                ret = si;            } else {                String html = props.getProperty(LPC_HTML);                if (html != null) {                    fireRequestBrowserContent(html);                    ret = si;                }            }            // Just reuse url instead of declaring another string            // object            url = props.getProperty(LPC_MESSAGE);            if (url != null) {                fireRequestMessage(url);                ret = si;            }        }        if (mr || mm || mc) {            String info = props.getProperty(LPC_INFO);            if (info != null) {                if (Debug.debugging("link")) {                    System.out.println("LinkLayer:graphicGestureReaction: displaying info line: "                            + info);                }                fireRequestInfoLine(info);                ret = si;            }        }        return ret;    }    /**     * Send the query, act on the response, and tell the caller if the gesture     * was consumed. The Link actually gets a copy of the layer to handle     * communication with the InformationDelegator. The GraphicUpdates are     * handled in this method - the graphics list is modified.     *      * @param descriptor a masked integer telling the type of gesture.     * @param e the MouseEvent.     * @return true if the event was consumed.     */    protected boolean handleGesture(int descriptor, MouseEvent e) {        Debug.message("link", "LinkLayer: handleGesture:");        try {            LinkOMGraphicList graphics = getGraphicList(); // Get old            // list            OMGraphic gesGraphic = null;            if (graphics == null) {                // Nothing to search on - this condition occurs when                // the layer is already busy getting new graphics as a                // result of a changed projection.                // It also occurs when the layer does not have any graphics                // in it.                Debug.message("link", "LinkLayer: null graphics list.");            } else {                if (e == null) {                    graphics.deselectAll();                    return false;                }                // Find out if a graphic is closeby...                // int gesGraphicIndex = graphics.findIndexOfClosest(e.getX(),                // e.getY(),                // distanceLimit);                // We need to do this to deselect everything else too.                gesGraphic = graphics.selectClosest(e.getX(),                        e.getY(),                        distanceLimit);            }            String id = null;            // If there was a graphic, set the mask to indicate that,            // and keep track of the graphic and the list index of the            // graphic for the response. If a graphic modify command

⌨️ 快捷键说明

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