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

📄 drawingtoollayer.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            c.gridx = GridBagConstraints.REMAINDER;            gridbag.setConstraints(jcb, c);            box.add(jcb);            JPanel goPanel = new JPanel();            gridbag.setConstraints(goPanel, c);            box.add(goPanel);                        interString = i18n.get(DrawingToolLayer.class, "OK", "OK");            JButton button = new JButton(interString);            interString = i18n.get(DrawingToolLayer.class, "OK", I18n.TOOLTIP, "Do action and dismiss window.");            button.setToolTipText(interString);            button.addActionListener(new ActionListener() {                public void actionPerformed(ActionEvent event) {                    doIt();                    hidePalette();                }            });            goPanel.add(button);                        interString = i18n.get(DrawingToolLayer.class, "Apply", "Apply");            button = new JButton(interString);            interString = i18n.get(DrawingToolLayer.class, "Apply", I18n.TOOLTIP, "Do action and leave window up.");            button.setToolTipText(interString);            button.addActionListener(new ActionListener() {                public void actionPerformed(ActionEvent event) {                    doIt();                }            });            goPanel.add(button);                        interString = i18n.get(DrawingToolLayer.class, "Cancel", "Cancel");            button = new JButton(interString);            interString = i18n.get(DrawingToolLayer.class, "Cancel", I18n.TOOLTIP, "Do nothing and dismiss window.");            button.setToolTipText(interString);            button.addActionListener(new ActionListener() {                public void actionPerformed(ActionEvent event) {                    hidePalette();                }            });            goPanel.add(button);        }        return box;    }    protected void doIt() {        if (jcb != null) {            ((javax.swing.Action) jcb.getSelectedItem()).actionPerformed(null);        }    }    /**     * You can override this class if you want to provide more, fewer     * or different actions to the user.     *      * @return Vector of Actions     */    protected Vector getActions() {        Vector actions = new Vector();        actions.add(new AbstractAction() {            public void actionPerformed(ActionEvent e) {                saveOMGraphics();            }            public String toString() {                return i18n.get(DrawingToolLayer.class, "SAVE_MAP", "Save map");            }        });        actions.add(new AbstractAction() {            public void actionPerformed(ActionEvent e) {                OMGraphicList list = getList();                if (list != null) {                    EsriShapeExport ese = new EsriShapeExport(list, getProjection(), null);                    ese.export();                } else {                    String message = i18n.get(DrawingToolLayer.class,                            "SHAPE_ERROR_MESSAGE",                            "There's nothing on the map for this layer to save.");                    fireRequestMessage(message);                }            }            public String toString() {                return i18n.get(DrawingToolLayer.class,                        "SHAPE_SAVE_MAP",                        "Save map as Shape file(s)");            }        });        actions.add(new AbstractAction() {            public void actionPerformed(ActionEvent e) {                setList(load());                doPrepare();            }            public String toString() {                return i18n.get(DrawingToolLayer.class,                        "RELOAD",                        "Re-load map from file");            }        });        actions.add(new AbstractAction() {            public void actionPerformed(ActionEvent e) {                Inspector inspector = new Inspector();                inspector.inspectPropertyConsumer(DrawingToolLayer.this);            }            public String toString() {                return i18n.get(DrawingToolLayer.class,                        "PREFERENCES",                        "Change preferences");            }        });          return actions;    }    /**     * Get the current OMGraphicList and save it out to the file named     * in this class. If that's null, the user will be asked for one.     *       */    public void saveOMGraphics() {        if (fileName == null) {            fileName = FileUtils.getFilePathToSaveFromUser(i18n.get(DrawingToolLayer.class,                    "CHOOSE_SAVE",                    "Choose file to use to save layer:"));        }        if (fileName != null) {            OMGraphicList list = getList();            if (list != null) {                try {                    FileOutputStream fos = new FileOutputStream(new File(fileName));                    ObjectOutputStream oos = new ObjectOutputStream(fos);                    oos.writeObject(list);                    oos.close();                } catch (FileNotFoundException e) {                    e.printStackTrace();                } catch (IOException e) {                    e.printStackTrace();                }            }        }    }    /**     * Load the data from the file set in this layer.     *      * @return OMGraphicList loaded from fileName.     */    public OMGraphicList load() {        OMGraphicList list = null;        if (fileName != null) {            try {                URL url = PropUtils.getResourceOrFileOrURL(fileName);                if (url != null) {                    ObjectInputStream ois = new ObjectInputStream(url.openStream());                    list = (OMGraphicList) ois.readObject();                    ois.close();                    return list;                }            } catch (FileNotFoundException e) {                if (DTL_DEBUG) {                    e.printStackTrace();                }            } catch (StreamCorruptedException sce) {                sce.printStackTrace();                fireRequestMessage(i18n.get(DrawingToolLayer.class,                        "LOAD_ERROR",                        "The file doesn't appear to be a valid map file"));            } catch (IOException e) {                if (DTL_DEBUG) {                    e.printStackTrace();                }            } catch (ClassNotFoundException e) {                if (DTL_DEBUG) {                    e.printStackTrace();                }            } catch (ClassCastException cce) {                if (DTL_DEBUG) {                    cce.printStackTrace();                }            }        }        // Something went wrong, we don't want to overwrite something        // that might potentially be something else if a save is        // called for later.        fileName = null;        return new OMGraphicList();    }    /**     * A flag to provide a tooltip over OMGraphics to click to edit.     */    public void setShowHints(boolean show) {        showHints = show;    }    public boolean getShowHints() {        return showHints;    }    /**     * 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, in addition to getInfoText() and     * getToolTipTextFor()     */    public boolean isHighlightable(OMGraphic omg) {        return showHints;    }    /**     * Query that an OMGraphic is selectable.     */    public boolean isSelectable(OMGraphic omg) {        DrawingTool dt = getDrawingTool();        return (shouldEdit(omg) && dt != null && dt.canEdit(omg.getClass()));    }    String editInstruction = i18n.get(DrawingToolLayer.class,            "CLICK_TO_EDIT",            "Click to edit.");    /**     * 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 editInstruction;        } else {            return null;        }    }    /**     * Query for what tooltip to display for an OMGraphic when the     * mouse is over it.     */    public String getToolTipTextFor(OMGraphic omgr) {        OMDrawingTool dt = getDrawingTool();        if (shouldEdit(omgr) && dt.canEdit(omgr.getClass())                && !dt.isActivated()) {            return editInstruction;        } else {            return null;        }    }    /**     * GestureResponsePolicy method.     */    public void select(OMGraphicList omgl) {        super.select(omgl);        if (omgl != null && omgl.size() > 0) {            if (omgl.size() == 1) {                edit(omgl.getOMGraphicAt(0));            } else {                edit(omgl);            }        }    }    public void edit(OMGraphic omg) {        OMDrawingTool dt = getDrawingTool();        if (dt != null && dt.canEdit(omg.getClass())) {            //          if (dt.isEditing(omg)) {            //              dt.deselect(omg);            //              return;            //          }            dt.resetBehaviorMask();            MapMouseMode omdtmm = dt.getMouseMode();            if (!omdtmm.isVisible()) {                dt.setMask(OMDrawingTool.PASSIVE_MOUSE_EVENT_BEHAVIOR_MASK);            }            MapMouseInterpreter mmi = (MapMouseInterpreter) getMapMouseListener();            MouseEvent mevent = null;            if (mmi != null) {                mevent = mmi.getCurrentMouseEvent();            }            if (omg.isSelected()) {                omg.deselect();            }            if (dt.select(omg, this, mevent)) {                // OK, means we're editing - let's lock up the                // MouseMode                if (DTL_DEBUG) {                    Debug.output("DTL: starting edit of OMGraphic...");                }                // Check to see if the DrawingToolMouseMode wants to                // be invisible. If it does, ask the current                // active MouseMode to be the proxy for it...                if (!omdtmm.isVisible() && mevent instanceof MapMouseEvent) {                    MapMouseMode mmm = ((MapMouseEvent) mevent).getMapMouseMode();                    if (mmm.actAsProxyFor(omdtmm,                            MapMouseSupport.PROXY_DISTRIB_MOUSE_MOVED                                    & MapMouseSupport.PROXY_DISTRIB_MOUSE_DRAGGED)) {                        if (DTL_DEBUG) {                            Debug.output("DTL: Setting " + mmm.getID()                                    + " as proxy for drawing tool");                        }                        setProxyMouseMode(mmm);                    } else {                        // WHOA, couldn't get proxy lock - bail                        if (DTL_DEBUG) {                            Debug.output("DTL: couldn't get proxy lock on "                                    + mmm.getID()                                    + " deactivating internal drawing tool");                        }                        dt.deactivate();                    }                } else {                    if (DTL_DEBUG) {                        Debug.output("DTL: MouseMode wants to be visible("                                + (omdtmm.isVisible())                                + "), or MouseEvent is not a MapMouseEvent("                                + !(mevent instanceof MapMouseEvent) + ")");                    }                }            } else {                if (DTL_DEBUG) {                    Debug.output("DTL.edit: dt.select returns false, avoiding modification over "                            + omg.getClass().getName());                }            }        }    }    public String getFileName() {        return fileName;    }    public void setSFileName(String serializedFile) {        this.fileName = serializedFile;    }}

⌨️ 快捷键说明

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