📄 omdrawingtool.java
字号:
* <P> * * To create different types of graphics, the * OMDrawingToolMouseMode can be used, to attach to a layer to * make it a drawing layer. The Loaders can be queried to get * their trigger graphics so you can load the drawing tool with a * particular loader to create a particular graphic. But here, we * just deal with the actual controls over the particular graphic * loaded and being modified. * <P> * * @return this. */ public Component getGUI() { if (!resetGUIWhenDeactivated) return this; removeAll(); Component eomgc = null; graphicAttributes.setLineMenuAdditions(null); if (currentEditable != null) { // GUI specific to a particular EditableOMGraphic type. eomgc = currentEditable.getGUI(graphicAttributes); if (eomgc != null) { add(eomgc); } } // Basic, generic GUI if eomgc wasn't set. if (eomgc == null) { add(graphicAttributes.getGUI()); } revalidate(); return this; } public void setInformationDelegator(InformationDelegator id) { informationDelegator = id; } public InformationDelegator getInformationDelegator() { return informationDelegator; } /** * Put the message in a display line that the OMDrawingTool is * using. */ public void setRemarks(String message) { if (informationDelegator != null) { informationDelegator.displayInfoLine(message, InformationDelegator.MAP_OBJECT_INFO_LINE); } } /** * Convenience function to tell if the OMDrawingTool is currently * working on an OMGraphic. */ public boolean isActivated() { return activated; } /** * Turn the OMDrawingTool on, attaching it to the MouseDelegator * or the canvas component it is assigned to. Also brings up the * drawing palette. Called automatically from the create/edit * methods. */ protected synchronized void activate() { activate(true); } /** * Turn the OMDrawingTool on with the caveaut that the * OMDrawingTool may be active already, and that a complete hookup * may not be needed. If a complete hookup is needed, this methid * will attach the OMDrawingTool to the MouseDelegator or the * canvas component it is assigned to and display the drawing * palette. Called automatically from the create/edit methods for * complete hookup. Partial hookup is called from select() * methods. */ protected synchronized void activate(boolean completeHookup) { activated = true; if (DEBUG) Debug.output("OMDrawingTool: activate()"); if (currentEditable != null && graphicAttributes != null) { // For partial hookups, for select() we don't need this. if (completeHookup) { graphicAttributes.setTo(currentEditable.getGraphic()); currentEditable.getGraphic().setVisible(false); } currentEditable.addEOMGListener(this); } if (!isMask(PASSIVE_MOUSE_EVENT_BEHAVIOR_MASK) && completeHookup) { if (mouseDelegator != null) { if (Debug.debugging("drawingtooldetail")) { Debug.output("OMDrawingTool.activate() mousemode connecting to MouseDelegator"); } formerMouseMode = mouseDelegator.getActiveMouseMode(); mouseDelegator.setActiveMouseMode(dtmm); } else if (canvas != null) { // If a MouseDelegator is not being used, go directly // to // the MapBean. if (Debug.debugging("drawingtooldetail")) { Debug.output("OMDrawingTool.activate() mousemode connecting directly to canvas"); } canvas.addMouseListener(dtmm); canvas.addMouseMotionListener(dtmm); } else { Debug.error("Drawing Tool can't find a map to work with"); } } // The Drawing tool is added as a projection listener so that // it can properly update the current graphic if the map // projection changes during graphic creation/edit. if (canvas != null) { if (canvas instanceof MapBean && completeHookup) { ((MapBean) canvas).addPaintListener(this); ((MapBean) canvas).addProjectionListener(this); } // Gets the graphic highlighted on the map, if needed. canvas.repaint(); } if (completeHookup) { // Show the gui. showPalette(); } } /** * Turn the drawing tool off, disconnecting it from the * MouseDelegator or canvas component, and removing the palette. * Called automatically from the mouse mode an GUI when * appropriate, although you can force a cleanup if needed by * calling this method. Calling this version of deactivate() just * uses the action mask stored in the EditableOMGraphic, which * knows if the graphic is being updated or created. */ public void deactivate() { int actionMask = 0; if (currentEditable != null) { actionMask = currentEditable.getActionMask(); } deactivate(actionMask); } /** * Turn the drawing tool off, disconnecting it from the * MouseDelegator or canvas component, and removing the palette. * This version can called when you want to control what action is * taken by the receiver. * * @param actionToDoWithOMGraphic a masked int from * OMGraphicConstants that describes an OMAction to take on * the current editable. * @see com.bbn.openmap.omGraphics.OMGraphicConstants */ public synchronized void deactivate(int actionToDoWithOMGraphic) { if (DEBUG) { Debug.output("OMDrawingTool: deactivate(" + (activated ? "while active" : "while inactive") + ")"); } // Don't waste effort; if (!activated) return; if (!isMask(PASSIVE_MOUSE_EVENT_BEHAVIOR_MASK)) { if (mouseDelegator != null) { mouseDelegator.setActiveMouseMode(formerMouseMode); mouseDelegator.removeMouseMode(dtmm); } else if (canvas != null) { // If a MouseDelegator is not being used, go directly // to // the canvas. canvas.removeMouseListener(dtmm); canvas.removeMouseMotionListener(dtmm); } } if (canvas != null) { if (canvas instanceof MapBean) { ((MapBean) canvas).removeProjectionListener(this); ((MapBean) canvas).removePaintListener(this); } } OMGraphic g = null; if (currentEditable != null) { if (!(currentEditable.getStateMachine().getState() instanceof com.bbn.openmap.omGraphics.editable.GraphicUndefinedState)) { g = currentEditable.getGraphic(); } currentEditable.removeEOMGListener(this); } // //////////////////////////////// // Clean up, then notify listener setCurrentEditable(null); // hide the gui while currentEditable is null, so it resets to // the default. hidePalette(); unsetMask(DEACTIVATE_ASAP_BEHAVIOR_MASK); popup = null; activated = false; // End cleanup // //////////////////////////////// if (g != null && requestor != null) { g.setVisible(true); OMAction action = new OMAction(); action.setMask(actionToDoWithOMGraphic); generateOMGraphic(g); notifyListener(g, action); } // By putting this here, it gives the listener the slight // opportunity to not have the gui reset right away. This // opportunity gives an editor tool a smoother runtime when // duplicate objects are being created one after another, and // you don't want all the GUI reconfiguring to happen when it // will just go back to the same thing in a second. getGUI(); } /** * If the projection is not null, generate the OMGraphic. */ protected void generateOMGraphic(OMGraphic g) { if (g != null && g.getNeedToRegenerate()) { Projection proj = getProjection(); if (proj != null) { g.generate(proj); } else if (DEBUG) { Debug.output("OMDrawingTool: graphic needs generation: " + g.getNeedToRegenerate()); } } } /** * Notify the listener of an action to a graphic. * * @param graphic the graphic being created/modified * @param action the OMAction telling the listener what to do with * the graphic. */ public void notifyListener(OMGraphic graphic, OMAction action) { if (requestor != null) { if (DEBUG) Debug.output("OMDrawingTool: notifying requestor, graphic with action"); requestor.drawingComplete(graphic, action); } // in case the requestor is a layer that is not visible if (canvas != null) { canvas.repaint(); } } /** * ProjectionListener method. Helps if the currentEditable is set. */ public void projectionChanged(ProjectionEvent e) { setProjection((Projection) e.getProjection().makeClone()); } /** * Set the current projection. Tells the currentEditable what it * is too. */ public void setProjection(Projection proj) { projection = proj; if (currentEditable != null) { currentEditable.setProjection(projection); } } /** * Get the current projection, if one has been provided. If one * has not been provided, then the canvas is checked to see if it * is a MapBean. If it is, then that projection is returned. If * that doesn't work, it will finally return null. */ public Projection getProjection() { if (projection == null && canvas instanceof MapBean) { projection = ((MapBean) canvas).getProjection(); } return projection; } /** * Set the GraphicAttributes object used to fill the OMGraphic * java.awt.Graphics parameters. */ public void setAttributes(GraphicAttributes da) { if (graphicAttributes != null) { graphicAttributes.getPropertyChangeSupport() .removePropertyChangeListener(this); } if (da == null) { graphicAttributes = GraphicAttributes.DEFAULT; } else { graphicAttributes = da; } graphicAttributes.getPropertyChangeSupport() .addPropertyChangeListener(this); if (currentEditable != null) { graphicAttributes.setTo(currentEditable.getGraphic()); } } /** * Get the DrawingAttributes driving the parameters of the current * graphic. */ public GraphicAttributes getAttributes() { return graphicAttributes; } /** * PaintListener interface. We want to know when the canvas is * repainted. * * @param g the Graphics to draw into. */ public void listenerPaint(Graphics g) { // Call repaintRender here because if the graphic is in the // middle of being moved, we'll draw it in the mouse event // thread. Otherwise, it gets set in the image for the // background, which looks bad. if (currentEditable != null) { // do g.create() to prevent Stroke remnants from affecting // the Border of the canvas. currentEditable.repaintRender(g.create()); } } /** * Set the MouseDelegator used to receive mouse events. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -