omdrawingtool.java

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

JAVA
1,751
字号
     *         create it.     */    public OMGraphic create(String classname, DrawingToolRequestor requestor) {        return create(classname, null, requestor);    }    /**     * Create a new OMGraphic, encased in a new EditableOMGraphic that can     * modify it. If a loader cannot be found that can handle a graphic with the     * given classname, this method will return a null object. If you aren't     * sure of the behavior mask set in the tool, and you want a particular     * behavior, set it before calling this method.     *      * @param classname the classname of the graphic to create.     * @param ga GraphicAttributes object that contains more information about     *        the type of line to be created.     * @param requestor the Component that is requesting the OMGraphic. The     *        requestor gets notified when the user is finished with the     *        DrawingTool and the graphic is ready.     * @return OMGraphic of the classname given, null if the DrawingTool can't     *         create it.     */    public OMGraphic create(String classname, GraphicAttributes ga,                            DrawingToolRequestor requestor) {        return create(classname, ga, requestor, isMask(SHOW_GUI_BEHAVIOR_MASK));    }    /**     * Create a new OMGraphic, encased in a new EditableOMGraphic that can     * modify it. If a loader cannot be found that can handle a graphic with the     * given classname, this method will return a null object. This method gives     * you the option of supressing the GUI for the EditableOMGraphic. If you     * aren't sure of the behavior mask set in the tool, and you want a     * particular behavior, set it before calling this method.     *      * @param classname the classname of the graphic to create.     * @param ga GraphicAttributes object that contains more information about     *        the type of line to be created.     * @param requestor the Component that is requesting the OMGraphic. The     *        requestor gets notified when the user is finished with the     *        DrawingTool and the graphic is ready.     * @param showGUI set to true (default) if a GUI showing attribute controls     *        should be displayed. The behaviorMask will be adjusted     *        accordingly.     * @return OMGraphic of the classname given, null if the DrawingTool can't     *         create it.     */    public OMGraphic create(String classname, GraphicAttributes ga,                            DrawingToolRequestor requestor, boolean showGUI) {        if (getCurrentEditable() != null) {            if (DEBUG) {                Debug.output("OMDrawingTool.edit(): can't create " + classname                        + ", drawing tool busy with another graphic.");            }            return null;        }        if (DEBUG) {            Debug.output("OMDrawingTool.create(" + classname + ")");        }        if (showGUI) {            if (DEBUG)                Debug.output("OMDrawingTool.create(): showing GUI per request");            setMask(SHOW_GUI_BEHAVIOR_MASK);        } else {            if (DEBUG)                Debug.output("OMDrawingTool.create(): NOT showing GUI per request");            unsetMask(SHOW_GUI_BEHAVIOR_MASK);        }        EditableOMGraphic eomg = getEditableGraphic(classname, ga);        if (eomg == null || eomg.getGraphic() == null) {            return null;        }        setAttributes(ga);        eomg.setShowGUI(isMask(SHOW_GUI_BEHAVIOR_MASK));        eomg.setActionMask(OMGraphic.ADD_GRAPHIC_MASK);        return edit(eomg, requestor);    }    /**     * Given an OMGraphic, wrap it in the applicable EditableOMGraphic, allow     * the user to make modifications, and then call     * requestor.drawingComplete(). If you aren't sure of the behavior mask set     * in the tool, and you want a particular behavior, set it before calling     * this method.     *      * @param g OMGraphic to modify     * @param requestor the Component that is requesting the OMGraphic. The     *        requestor gets notified when the user is finished with the     *        DrawingTool and the graphic is ready.     * @return OMGraphic being modified, null if the OMDrawingTool can't figure     *         out what to use for the modifications.     */    public OMGraphic edit(OMGraphic g, DrawingToolRequestor requestor) {        return edit(g, requestor, g.getShowEditablePalette());    }    /**     * Given an OMGraphic, wrap it in the applicable EditableOMGraphic, allow     * the user to make modifications, and then call     * requestor.drawingComplete(). This methods gives you the option to supress     * the GUI from the EditableOMGraphic. If you aren't sure of the behavior     * mask set in the tool, and you want a particular behavior, set it before     * calling this method.     *      * @param g OMGraphic to modify     * @param requestor the Component that is requesting the OMGraphic. The     *        requestor gets notified when the user is finished with the     *        DrawingTool and the graphic is ready.     * @param showGUI set to true (default) if a GUI showing attribute controls     *        should be displayed. The behaviorMask will be adjusted     *        accordingly.     * @return OMGraphic being modified, null if the OMDrawingTool can't figure     *         out what to use for the modifications.     */    public OMGraphic edit(OMGraphic g, DrawingToolRequestor requestor,                          boolean showGUI) {        if (g == null) {            if (DEBUG) {                Debug.output("OMDrawingTool.edit(): can't edit null OMGraphic.");            }            return null;        }        if (getCurrentEditable() != null) {            if (DEBUG) {                Debug.output("OMDrawingTool.edit(): can't edit "                        + g.getClass().getName()                        + ", drawing tool busy with another graphic.");            }            return null;        }        this.requestor = requestor;        if (showGUI) {            if (DEBUG)                Debug.output("OMDrawingTool.edit(): showing GUI per request");            setMask(SHOW_GUI_BEHAVIOR_MASK);        } else {            if (DEBUG)                Debug.output("OMDrawingTool.edit(): NOT showing GUI per request");            unsetMask(SHOW_GUI_BEHAVIOR_MASK);        }        EditableOMGraphic eomg = getEditableGraphic(g);        if (eomg != null) {            eomg.setShowGUI(isMask(SHOW_GUI_BEHAVIOR_MASK));            eomg.setActionMask(OMGraphic.UPDATE_GRAPHIC_MASK);            return edit(eomg, requestor);        }        return null;    }    /**     * Given an EditableOMGraphic, use it to make modifications, and then call     * requestor.drawingComplete(). The requestor is responsible for setting up     * the correct initial state of the EditableOMGraphic. The requestor will be     * given the action mask that is set in the EditableOMGraphic at this point,     * if no other external modifications to it are made. If you aren't sure of     * the behavior mask set in the tool, and you want a particular behavior,     * set it before calling this method.     *      * This method is called by other edit methods.     *      * @param eomg OMGraphic to modify     * @param requestor the Component that is requesting the OMGraphic. The     *        requestor gets notified when the user is finished with the     *        DrawingTool and the graphic is ready.     * @return OMGraphic being modified contained within the EditableOMGraphic.     */    public OMGraphic edit(EditableOMGraphic eomg, DrawingToolRequestor requestor) {        if (setCurrentEditable(eomg)) {            // resetGUI() for current EOMG doesn't need to be called            // here, it's called later from activate            if (DEBUG) {                Debug.output("OMDrawingTool.edit success");            }            this.requestor = requestor;            if (currentEditable != null) {                graphicAttributes.setFrom(currentEditable.getGraphic());                activate();                // Check currentEditable in case activating caused                // something strange to happen, most likely with                // activating the MouseModes.                if (currentEditable != null) {                    return currentEditable.getGraphic();                }            }        }        if (DEBUG) {            Debug.output("OMDrawingTool.edit(): can't edit "                    + eomg.getClass().getName()                    + ", drawing tool busy with another graphic.");        }        return null;    }    /**     * A slightly different edit method, where the EditableOMGraphic is put     * directly into edit mode, and the mouse events immediately start making     * modifications to the OMGraphic. The palette is not shown, but if you set     * the GUI_VIA_POPUP_BEHAVIOR_MASK on the OMDrawingTool, the option to bring     * up the drawing tool palette will be presented to the user. If you aren't     * sure of the behavior mask set in the tool, and you want a particular     * behavior, set it before calling this method.     *      * @param g OMGraphic to modify     * @param requestor the Component that is requesting the OMGraphic. The     *        requestor gets notified when the user is finished with the     *        DrawingTool and the graphic is ready.     * @param e MouseEvent to use to start editing with.     * @return OMGraphic being modified.     */    public OMGraphic edit(OMGraphic g, DrawingToolRequestor requestor,                          MouseEvent e) {        OMGraphic ret = null;        if (getCurrentEditable() == null) {            EditableOMGraphic eomg = getEditableGraphic(g);            if (eomg != null) {                ret = edit(eomg, requestor, e);            }        }        return ret;    }    /**     * A slightly different edit method, where the EditableOMGraphic is put     * directly into edit mode, and the mouse events immediately start making     * modifications to the OMGraphic. If you aren't sure of the behavior mask     * set in the tool, and you want a particular behavior, set it before     * calling this method.     *      * @param eomg EditableOMGraphic to modify     * @param requestor the Component that is requesting the OMGraphic. The     *        requestor gets notified when the user is finished with the     *        DrawingTool and the graphic is ready.     * @param e MouseEvent to use to start editing with.     * @return OMGraphic being modified contained within the EditableOMGraphic.     */    public OMGraphic edit(EditableOMGraphic eomg,                          DrawingToolRequestor requestor, MouseEvent e) {        OMGraphic ret = null;        if (eomg != null) {            eomg.setActionMask(OMGraphic.UPDATE_GRAPHIC_MASK);            ret = edit(eomg, requestor);            if (ret != null) {                currentEditable.handleInitialMouseEvent(e);            }        }        return ret;    }    /**     * Returns true of the OMGraphic is being edited, or is on an     * EditableOMGraphicList being manipulated.     */    public boolean isEditing(OMGraphic omg) {        boolean ret = false;        EditableOMGraphic eomg = getCurrentEditable();        if (eomg != null                && eomg.getGraphic() == omg                || (eomg instanceof EditableOMGraphicList && ((OMGraphicList) ((EditableOMGraphicList) eomg).getGraphic()).contains(omg))) {            ret = true;        }        return ret;    }    public void deselect(OMGraphic omg) {        if (DEBUG) {            Debug.output("OMDrawingTool.deselect()");        }        if (getCurrentEditable() != null) {            if (currentEditable.getGraphic() == omg) {                deactivate();            } else {                if (currentEditable instanceof EditableOMGraphicList) {                    ((EditableOMGraphicList) currentEditable).remove(omg);                    canvas.repaint();                }            }        }    }    /**     * @return true if the OMDrawingTool is editing where it wasn't before.     */    public boolean select(OMGraphic omg, DrawingToolRequestor req, MouseEvent e) {        if (DEBUG) {            Debug.output("OMDrawingTool.select()");        }        OMGraphic ret = null;        boolean currentlyEditing = (getCurrentEditable() != null);        if (currentlyEditing) {            boolean repaintCanvas = true;            if (!(currentEditable instanceof EditableOMGraphicList)) {                if (DEBUG) {                    Debug.output("OMDrawingTool.select:  already working on OMGraphic, creating an EditableOMGraphicList for selection mode");                }                EditableOMGraphicList eomgl = new EditableOMGraphicList(new OMGraphicList());                eomgl.setProjection(getProjection());                DrawingToolRequestorList rl = new DrawingToolRequestorList();                // Add what's current to the requestor list                rl.add(currentEditable.getGraphic(), requestor);                // then add the current editable to the eomgl                eomgl.add(currentEditable);                currentEditable.removeEOMGListener(this);                // tell selectionlisteners to disregard the current                // thing.                setCurrentEditable(null);                // reset the requestor to the requestor list                requestor = rl;                // now reactivate with the eomgl                setCurrentEditable(eomgl);                if (DEBUG) {                    EditableOMGraphic ce = getCurrentEditable();                    Debug.output("OMDrawingTool: current editable is: "                            + (ce == null ? "null" : ce.getClass().getName()));                }                // Activate the list to make sure the listeners are                // set up

⌨️ 快捷键说明

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