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

📄 demolayer.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                    OMRect rect = (OMRect) getDrawingTool().create("com.bbn.openmap.omGraphics.OMRect",                            fga,                            layer,                            false);                    if (rect != null) {                        rect.setAppObject(externalKey);                    } else {                        Debug.error("DemoLayer: Drawing tool can't create OMRect");                    }                } else {                    Debug.output("DemoLayer can't find a drawing tool");                }            }        });        box.add(button);        button = new JButton("Reset filter");        button.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent event) {                resetFiltering();                repaint();            }        });        box.add(button);        // button = new JButton("Create XY Rect");        // button.addActionListener(new ActionListener() {        // public void actionPerformed(ActionEvent event) {        // DrawingTool dt = getDrawingTool();        // GraphicAttributes ga = new GraphicAttributes();        // ga.setRenderType(OMGraphic.RENDERTYPE_XY);        // if (dt != null) {        // OMRect rect = (OMRect)        // getDrawingTool().create("com.bbn.openmap.omGraphics.OMRect",        // ga, layer);        // if (rect != null) {        // getList().add(rect);        // } else {        // Debug.error("DemoLayer: Drawing tool can't create OMRect");        // }        // } else {        // Debug.output("DemoLayer can't find a drawing tool");        // }        // }        // });        // box.add(button);        // button = new JButton("Create Offset Rect");        // button.addActionListener(new ActionListener() {        // public void actionPerformed(ActionEvent event) {        // DrawingTool dt = getDrawingTool();        // GraphicAttributes ga = new GraphicAttributes();        // ga.setRenderType(OMGraphic.RENDERTYPE_OFFSET);        // ga.setFillPaint(Color.red);        // if (dt != null) {        // OMRect rect = (OMRect)        // getDrawingTool().create("com.bbn.openmap.omGraphics.OMRect",        // ga, layer);        // if (rect != null) {        // getList().add(rect);        // } else {        // Debug.error("DemoLayer: Drawing tool can't create OMRect");        // }        // } else {        // Debug.output("DemoLayer can't find a drawing tool");        // }        // }        // });        // box.add(button);        // button = new JButton("Create RangeRings");        // button.addActionListener(new ActionListener() {        // public void actionPerformed(ActionEvent event) {        // DrawingTool dt = getDrawingTool();        // GraphicAttributes ga = new GraphicAttributes();        // ga.setLinePaint(Color.yellow);        // if (dt != null) {        // OMRangeRings rr = (OMRangeRings)        // getDrawingTool().create("com.bbn.openmap.omGraphics.OMRangeRings",        // ga, layer);        // if (rr != null) {        // // rr.setInterval(25, Length.MILE);        // } else {        // Debug.error("DemoLayer: Drawing tool can't create        // OMRangeRings");        // }        // } else {        // Debug.output("DemoLayer can't find a drawing tool");        // }        // }        // });        // box.add(button);        // button = new JButton("Create XY Poly");        // button.addActionListener(new ActionListener() {        // public void actionPerformed(ActionEvent event) {        // DrawingTool dt = getDrawingTool();        // GraphicAttributes ga = new GraphicAttributes();        // ga.setRenderType(OMGraphic.RENDERTYPE_XY);        // ga.setLinePaint(Color.red);        // ga.setFillPaint(Color.red);        // if (dt != null) {        // OMPoly point = (OMPoly)        // getDrawingTool().create("com.bbn.openmap.omGraphics.OMPoly",        // ga, layer);        // if (point != null) {        // } else {        // Debug.error("DemoLayer: Drawing tool can't create OMPoly");        // }        // } else {        // Debug.output("DemoLayer can't find a drawing tool");        // }        // }        // });        // box.add(button);        // button = new JButton("Create LatLon Labeled Poly");        // button.addActionListener(new ActionListener() {        // public void actionPerformed(ActionEvent event) {        // DrawingTool dt = getDrawingTool();        // GraphicAttributes ga = new GraphicAttributes();        // ga.setRenderType(OMGraphic.RENDERTYPE_LATLON);        // ga.setLinePaint(Color.green);        // ga.setFillPaint(Color.green);        // if (dt != null) {        // LabeledOMPoly point = (LabeledOMPoly)        // getDrawingTool().create("com.bbn.openmap.omGraphics.labeled.LabeledOMPoly",        // ga, layer);        // if (point != null) {        // // point.setOval(true);        // // point.setRadius(8);        // point.setText("Active Testing");        // } else {        // Debug.error("DemoLayer: Drawing tool can't create OMPoly");        // }        // } else {        // Debug.output("DemoLayer can't find a drawing tool");        // }        // }        // });        // box.add(button);        // button = new JButton("Create LatLon Offset Poly");        // button.addActionListener(new ActionListener() {        // public void actionPerformed(ActionEvent event) {        // DrawingTool dt = getDrawingTool();        // GraphicAttributes ga = new GraphicAttributes();        // ga.setRenderType(OMGraphic.RENDERTYPE_OFFSET);        // ga.setLinePaint(Color.green);        // ga.setFillPaint(Color.green);        // if (dt != null) {        // OMPoly point = (OMPoly)        // getDrawingTool().create("com.bbn.openmap.omGraphics.OMPoly",        // ga, layer);        // if (point != null) {        // // rr.setInterval(25, Length.MILE);        // } else {        // Debug.error("DemoLayer: Drawing tool can't create OMPoly");        // }        // } else {        // Debug.output("DemoLayer can't find a drawing tool");        // }        // }        // });        // box.add(button);        gridbag.setConstraints(box, c);        panel.add(box);        return panel;    }    public DrawingTool getDrawingTool() {        // Usually set in the findAndInit() method.        return drawingTool;    }    public void setDrawingTool(DrawingTool dt) {        // Called by the findAndInit method.        drawingTool = dt;    }    /**     * Called when the DrawingTool is complete, providing the layer     * with the modified OMGraphic.     */    public void drawingComplete(OMGraphic omg, OMAction action) {        Debug.message("demo", "DemoLayer: DrawingTool complete");        Object obj = omg.getAppObject();        if (obj != null && (obj == internalKey || obj == externalKey)                && !action.isMask(OMGraphicConstants.DELETE_GRAPHIC_MASK)) {            java.awt.Shape filterShape = omg.getShape();            OMGraphicList filteredList = filter(filterShape,                    (omg.getAppObject() == internalKey));            if (Debug.debugging("demo")) {                Debug.output("DemoLayer filter: "                        + filteredList.getDescription());            }        } else {            if (!doAction(omg, action)) {                // null OMGraphicList on failure, should only occur if                // OMGraphic is added to layer before it's ever been                // on the map.                setList(new OMGraphicList());                doAction(omg, action);            }        }        repaint();    }    /**     * Called when a component that is needed, and not available with     * an appropriate interator from the BeanContext. This lets this     * object hook up with what it needs. For Layers, this method     * doesn't do anything by default. If you need your layer to get     * ahold of another object, then you can use the Iterator to go     * through the objects to look for the one you need.     */    public void findAndInit(Object someObj) {        if (someObj instanceof DrawingTool) {            Debug.message("demo", "DemoLayer: found a drawing tool");            setDrawingTool((DrawingTool) someObj);        }        if (someObj instanceof SymbolReferenceLibrary) {            setSymbolReferenceLibrary((SymbolReferenceLibrary) someObj);        }    }    /**     * Set the MilStd2525 SymbolReferenceLibrary object used to create     * symbols.     *      * @param library     */    public void setSymbolReferenceLibrary(SymbolReferenceLibrary library) {        srl = library;    }    public SymbolReferenceLibrary getSymbolReferenceLibrary() {        return srl;    }    /**     * BeanContextMembershipListener method. Called when a new object     * is removed from the BeanContext of this object. For the Layer,     * this method doesn't do anything. If your layer does something     * with the childrenAdded method, or findAndInit, you should take     * steps in this method to unhook the layer from the object used     * in those methods.     */    public void findAndUndo(Object someObj) {        if (someObj instanceof DrawingTool) {            if (getDrawingTool() == (DrawingTool) someObj) {                setDrawingTool(null);            }        }    }    /**     * Query that an OMGraphic can be highlighted when the mouse moves     * over it. If the answer is true, then highlight with this     * OMGraphics will be called.     */    public boolean isHighlightable(OMGraphic omg) {        return true;    }    /**     * Query that an OMGraphic is selectable.     */    public boolean isSelectable(OMGraphic omg) {        DrawingTool dt = getDrawingTool();        return (dt != null && dt.canEdit(omg.getClass()));    }    /**     * Query for what text should be placed over the information bar     * when the mouse is over a particular OMGraphic.     */    public String getInfoText(OMGraphic omg) {        DrawingTool dt = getDrawingTool();        if (dt != null && dt.canEdit(omg.getClass())) {            return "Click to edit graphic.";        } else {            return null;        }    }    /**     * Query for what tooltip to display for an OMGraphic when the     * mouse is over it.     */    public String getToolTipTextFor(OMGraphic omg) {        Object tt = omg.getAttribute(OMGraphic.TOOLTIP);        if (tt instanceof String) {            return (String) tt;        }                return "Demo Layer Object";    }    /**     * Called if isSelectable(OMGraphic) was true, so the list has the     * OMGraphic. A list is used in case underlying code is written to     * handle more than one OMGraphic being selected at a time.     */    public void select(OMGraphicList list) {        if (list != null && list.size() > 0) {            OMGraphic omg = list.getOMGraphicAt(0);            DrawingTool dt = getDrawingTool();            if (dt != null && dt.canEdit(omg.getClass())) {                dt.setBehaviorMask(OMDrawingTool.QUICK_CHANGE_BEHAVIOR_MASK);                if (dt.edit(omg, this) == null) {                    // Shouldn't see this because we checked, but ...                    fireRequestInfoLine("Can't figure out how to modify this object.");                }            }        }    }    public List getItemsForMapMenu(MapMouseEvent me) {        List l = new ArrayList();        l.add(new JMenuItem("When"));        l.add(new JMenuItem("Where"));        l.add(new JMenuItem("How"));        return l;    }    public List getItemsForOMGraphicMenu(OMGraphic omg) {        List l = new ArrayList();        l.add(new JMenuItem("Which"));        l.add(new JMenuItem("Why"));        return l;    }}

⌨️ 快捷键说明

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