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

📄 drawingeditortool.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * @param ttc thingToCreate, classname of thing to create     * @return OMDrawingToolMouseMode of DrawingTool if all goes well,     *         null if the drawing tool can't create the new thingy.     */    protected OMDrawingToolMouseMode activateDrawingTool(String ttc) {        if (drawingTool != null && ttc != null) {            // If there is a pre-defined set of DrawingAttributes for            // a particular OMGraphic, set those attributes in the            // GraphicAttributes used in the OMDrawingTool.            DrawingAttributes da = (DrawingAttributes) drawingAttributesTable.get(ttc);            if (da != null) {                da.setTo(ga);            }            if (Debug.debugging("editortool")) {                Debug.output("DrawingEditorTool.activateDrawingTool(" + ttc                        + ")");            }            drawingTool.setMask(OMDrawingTool.PASSIVE_MOUSE_EVENT_BEHAVIOR_MASK);            if (drawingTool.create(ttc,                    ga,                    (DrawingToolRequestor) getLayer(),                    true) == null) {                // Something bad happened, might as well try to clean                // up.                if (Debug.debugging("editortool")) {                    Debug.output("DrawingEditorTool.activateDrawingTool() failed, cleaning up...");                }                drawingTool.deactivate();                return null;            }            return drawingTool.getMouseMode();        } else {            if (Debug.debugging("editortool")) {                Debug.output("DrawingEditorTool.activateDrawingTool(" + ttc                        + ") with drawing tool = " + drawingTool);            }        }        return null;    }    ////////////////////////    // Mouse Listener events    ////////////////////////    /**     * Invoked when a mouse button has been pressed on a component.     *      * @param e MouseEvent     * @return false     */    public boolean mousePressed(MouseEvent e) {        if (wantsEvents()) {            if (omdtmm != null) {                omdtmm.mousePressed(e);            }            return consumeEvents;        } else {            return super.mousePressed(e);        }    }    /**     * Invoked when a mouse button has been released on a component.     *      * @param e MouseEvent     * @return false     */    public boolean mouseReleased(MouseEvent e) {        if (wantsEvents()) {            if (omdtmm != null) {                omdtmm.mouseReleased(e);                return true;            } else {                return false;            }        } else {            return super.mouseReleased(e);        }    }    /**     * Invoked when the mouse has been clicked on a component.     *      * @param e MouseEvent     * @return false     */    public boolean mouseClicked(MouseEvent e) {        if (wantsEvents()) {            if (omdtmm != null) {                omdtmm.mouseClicked(e);                return consumeEvents;            } else {                return false;            }        } else {            return super.mouseClicked(e);        }    }    /**     * Invoked when the mouse enters a component.     *      * @param e MouseEvent     */    public void mouseEntered(MouseEvent e) {        if (wantsEvents()) {            if (omdtmm != null) {                omdtmm.mouseEntered(e);            }        } else {            super.mouseEntered(e);        }    }    /**     * Invoked when the mouse exits a component.     *      * @param e MouseEvent     */    public void mouseExited(MouseEvent e) {        if (wantsEvents()) {            if (omdtmm != null) {                omdtmm.mouseExited(e);            }        } else {            super.mouseExited(e);        }    }    ///////////////////////////////    // Mouse Motion Listener events    ///////////////////////////////    /**     * Invoked when a mouse button is pressed on a component and then     * dragged. The listener will receive these events if it     *      * @param e MouseEvent     * @return false     */    public boolean mouseDragged(MouseEvent e) {        if (wantsEvents()) {            if (omdtmm != null) {                omdtmm.mouseDragged(e);                return consumeEvents;            } else {                return false;            }        } else {            return super.mouseDragged(e);        }    }    /**     * Invoked when the mouse button has been moved on a component     * (with no buttons down).     *      * @param e MouseEvent     * @return false     */    public boolean mouseMoved(MouseEvent e) {        if (wantsEvents()) {            if (omdtmm != null) {                omdtmm.mouseMoved(e);                return consumeEvents;            } else if (thingToCreate != null) {                // This is needed to reinitialize the drawing tool to                // create another OMGraphic after the same one was                // just completed. drawingComplete just nulls out                // omdtmm so that the drawing tool can finish                // deactivating. The first mouseMoved event should                // get the next OMGraphic ready.                omdtmm = activateDrawingTool(thingToCreate);                return consumeEvents;            } else {                return false;            }        } else {            return super.mouseMoved(e);        }    }    ///////////////////////////////    // Tool interface methods    ///////////////////////////////    public void setVisible(boolean value) {        super.setVisible(value);        if (!value) {            totalReset();        }    }    /**     * The tool's interface. This is added to the tool bar.     *      * @return String The key for this tool.     */    public Container getFace() {        if (face == null) {            JToolBar faceTB = new GridBagToolBar();            if (bg == null) {                bg = new ButtonGroup();            }            fillFaceToolBar(faceTB, bg);            unpickBtn = new JToggleButton("", false);            unpickBtn.setActionCommand(RESET_CMD);            unpickBtn.addActionListener(this);            unpickBtn.setVisible(false);            bg.add(unpickBtn);            faceTB.add(unpickBtn);            if (drawingTool != null && showAttributes) {                faceTB.add(drawingTool);                drawingTool.showPalette();            }            face = faceTB;            face.setVisible(visible);        }        return face;    }    /**     * Fill the Face's toolbar with buttons     */    protected void fillFaceToolBar(JToolBar faceTB, ButtonGroup bg) {        Iterator it = loaderList.iterator();        while (it.hasNext()) {            EditToolLoader loader = (EditToolLoader) it.next();            String[] classnames = loader.getEditableClasses();            for (int i = 0; i < classnames.length; i++) {                ImageIcon icon = loader.getIcon(classnames[i]);                JToggleButton btn = new JToggleButton(icon, false);                btn.setToolTipText(loader.getPrettyName(classnames[i]));                btn.setActionCommand(classnames[i]);                btn.addActionListener(this);                bg.add(btn);                faceTB.add(btn);            }        }    }    /**     * Set the MouseDelegator used to hold the different MouseModes     * available to the map.     */    public void setMouseDelegator(MouseDelegator md) {        if (mouseDelegator != null) {            mouseDelegator.removePropertyChangeListener(this);        }        mouseDelegator = md;        EditorLayer el = (EditorLayer) getLayer();        if (el != null) {            mouseDelegator.addMouseMode(el.getMouseMode());        }        if (mouseDelegator == null) {            return;        }        mouseDelegator.addPropertyChangeListener(this);    }    /**     * Get the MouseDelegator used to control mouse gestures over the     * map.     */    public MouseDelegator getMouseDelegator() {        return mouseDelegator;    }    /**     * Listen for changes to the active mouse mode and for any changes     * to the list of available mouse modes     */    public void propertyChange(PropertyChangeEvent evt) {        if (evt.getPropertyName() == MouseDelegator.ActiveModeProperty) {            /*             * If the mouse mode changes, we want to reset ourselves             * to be ready to just adjust what's on our layer.             */            String mmID = ((MapMouseMode) evt.getNewValue()).getID();            if (Debug.debugging("editortool")) {                Debug.output("DET.propertyChange: mousemode changed to " + mmID);            }            if (mmID != ((EditorLayer) getLayer()).getMouseMode().getID()) {                totalReset();            }            drawingTool.showPalette(); // Reset to basic parameters        }    }    public void setPropertyPrefix(String prefix) {        propertyPrefix = prefix;    }    public String getPropertyPrefix() {        return propertyPrefix;    }    public void setProperties(Properties props) {        setProperties(null, props);    }    public void setProperties(String prefix, Properties props) {        setPropertyPrefix(prefix);        prefix = PropUtils.getScopedPropertyPrefix(prefix);        showAttributes = PropUtils.booleanFromProperties(props, prefix                + ShowAttributesProperty, showAttributes);        String loaderListString = props.getProperty(prefix + LoaderProperty);        if (loaderListString != null) {            Vector loaderVector = PropUtils.parseSpacedMarkers(loaderListString);            Iterator it = loaderVector.iterator();            while (it.hasNext()) {                String loaderPropertyPrefix = PropUtils.getScopedPropertyPrefix(prefix                        + (String) it.next());                String loaderClassString = props.getProperty(loaderPropertyPrefix                        + "class");                String loaderAttributeClass = props.getProperty(loaderPropertyPrefix                        + AttributesClassProperty);                if (loaderClassString != null) {                    Object obj = ComponentFactory.create(loaderClassString,                            loaderPropertyPrefix,                            props);                    if (obj != null && obj instanceof EditToolLoader) {                        EditToolLoader loader = (EditToolLoader) obj;                        if (Debug.debugging("editortool")) {                            Debug.output("DrawingEditorTool: adding "                                    + loaderClassString);                        }                        addEditToolLoader(loader);                        if (loaderAttributeClass != null) {                            if (Debug.debugging("editortool")) {                                Debug.output("DrawingEditorTool: getting attributes for "                                        + loaderAttributeClass);                            }                            Object daObject = ComponentFactory.create(loaderAttributeClass,                                    loaderPropertyPrefix,                                    props);                            if (daObject != null                                    && daObject instanceof DrawingAttributes) {                                if (Debug.debugging("editortool")) {                                    Debug.output("DrawingEditorTool: attributes from "                                            + loaderAttributeClass);                                }                                String[] classnames = loader.getEditableClasses();                                for (int i = 0; i < classnames.length; i++) {                                    drawingAttributesTable.put(classnames[i],                                            daObject);                                }                            } else {                                if (Debug.debugging("editortool")) {                                    Debug.output("DrawingEditorTool: attributes not an instance of DrawingAttributes");                                }                            }                        } else {                            if (Debug.debugging("editortool")) {                                Debug.output("DrawingEditorTool: attributes not defined for "                                        + loaderClassString);                            }                        }                    }                } else {                    Debug.output("DrawingEditorTool.setProperties:  no loader class provided for "                            + loaderPropertyPrefix);                }            }        } else {            Debug.output("DrawingEditorTool.setProperties: no loaders set in properties");        }    }    public Properties getProperties(Properties props) {        if (props == null) {            props = new Properties();        }        return props;    }    public Properties getPropertyInfo(Properties props) {        if (props == null) {            props = new Properties();        }        return props;    }}

⌨️ 快捷键说明

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