📄 drawingeditortool.java
字号:
// **********************************************************************// // <copyright>// // BBN Technologies// 10 Moulton Street// Cambridge, MA 02138// (617) 873-8000// // Copyright (C) BBNT Solutions LLC. All rights reserved.// // </copyright>// **********************************************************************// // $Source: /cvs/distapps/openmap/src/openmap/com/bbn/openmap/layer/editor/DrawingEditorTool.java,v $// $RCSfile: DrawingEditorTool.java,v $// $Revision: 1.8.2.1 $// $Date: 2004/10/14 18:27:05 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.layer.editor;import java.awt.Container;import java.awt.event.MouseEvent;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import java.util.ArrayList;import java.util.Hashtable;import java.util.Iterator;import java.util.Properties;import java.util.Vector;import javax.swing.ButtonGroup;import javax.swing.ImageIcon;import javax.swing.JToggleButton;import javax.swing.JToolBar;import com.bbn.openmap.MapBean;import com.bbn.openmap.InformationDelegator;import com.bbn.openmap.MouseDelegator;import com.bbn.openmap.PropertyConsumer;import com.bbn.openmap.event.MapMouseMode;import com.bbn.openmap.gui.GridBagToolBar;import com.bbn.openmap.gui.OMGraphicDeleteTool;import com.bbn.openmap.omGraphics.DrawingAttributes;import com.bbn.openmap.omGraphics.GraphicAttributes;import com.bbn.openmap.omGraphics.OMAction;import com.bbn.openmap.omGraphics.OMGraphic;import com.bbn.openmap.tools.drawing.DrawingToolRequestor;import com.bbn.openmap.tools.drawing.EditToolLoader;import com.bbn.openmap.tools.drawing.OMCircleLoader;import com.bbn.openmap.tools.drawing.OMDistanceLoader;import com.bbn.openmap.tools.drawing.OMDrawingTool;import com.bbn.openmap.tools.drawing.OMDrawingToolMouseMode;import com.bbn.openmap.tools.drawing.OMLineLoader;import com.bbn.openmap.tools.drawing.OMPointLoader;import com.bbn.openmap.tools.drawing.OMPolyLoader;import com.bbn.openmap.tools.drawing.OMRectLoader;import com.bbn.openmap.util.ComponentFactory;import com.bbn.openmap.util.Debug;import com.bbn.openmap.util.PropUtils;/** * The DrawingEditorTool is a EditorTool for the EditorLayer that will * use a custom OMDrawingTool to create OMGraphics as needed by the * EditorTool. This is a class that lets you define which * EditToolLoaders the internal OMDrawingTool will use for its own, * targeted use. These definitions are specified in the properties for * the EditorLayer using this tool. This class provides the * OMDrawingTool and all the button mechanisms organized for smooth * behavior integrated with the regular OpenMap mouse modes. * * Properties for an EditorLayer using the DrawingEditorTool: * * <pre> * * * # Layer declaration, dtlayer has to go in openmap.layers property * dtlayer.class=com.bbn.openmap.layer.editor.EditorLayer * # GUI name for layer, will also be the ID of the 'hidden' mouse mode used for tool. * dtlayer.prettyName=Drawing Layer * # List of other MouseModes to respond to for the layer, when *not* in editing mode. * dtlayer.mouseModes=Gestures * # Editor Tool to use with layer * dtlayer.editor=com.bbn.openmap.layer.editor.DrawingEditorTool * # This tool lets you hide the drawing attribute controls (lines, * # colors) for the different objects. Default is true. * dtlayer.showAttributes=false * * # List of EditToolLoaders to use in DrawingEditorTool * dtlayer.loaders=polys points lines * # EditToolLoader class to use for the polys * dtlayer.polys.class=com.bbn.openmap.tools.drawing.OMPolyLoader * # Set the DrawingAttributes class to use for polys * dtlayer.polys.attributesClass=com.bbn.openmap.omGraphics.DrawingAttributes * # Polys have specific line color, defaults for other settings. * dtlayer.polys.lineColor=FFFF0000 * * # EditToolLoader classes for points and lines, they get rendered * # with whatever color was set last for the DrawingEditorTool. * dtlayer.points.class=com.bbn.openmap.tools.drawing.OMPointLoader * dtlayer.lines.class=com.bbn.openmap.tools.drawing.OMLineLoader * */public class DrawingEditorTool extends AbstractEditorTool implements ActionListener, PropertyChangeListener, PropertyConsumer { /** * OMDrawingTool handling OMGraphic modifications and creations. */ protected OMDrawingTool drawingTool = null; /** * A handler on the OMDrawingToolMouseMode that the OMDrawingTool * is using, for convenience. If this handle is not null, then * that's an internal signal for this EditorTool to know that it's * active and interpreting MouseEvents. If this is null, and the * EditorTool wants events, that's a signal to create a new * OMGraphic (see mousePressed). */ protected OMDrawingToolMouseMode omdtmm = null; /** * The class name of the next thing to create. Used as a signal to * this EditorTool that when the next appropriate MouseEvent comes * in, this "thing" should be created. */ protected String thingToCreate = null; /** * The ButtonGroup to use for the face. */ protected ButtonGroup bg = null; /** * The button that unpicks all the rest of the tool buttons. It is * kept invisible, but a member of all the other button's * ButtonGroup. When selected, all of the other buttons are * deselected. */ protected JToggleButton unpickBtn = null; protected GraphicAttributes ga = null; /** * The MouseDelegator that is controlling the MouseModes. We need * to keep track of what's going on so we can adjust our tools * accordingly. */ protected MouseDelegator mouseDelegator; /** * The ArrayList containing the EditToolLoaders for the drawing * tool. */ protected ArrayList loaderList = new ArrayList(); public final static String RESET_CMD = "RESET_CMD"; /** * Property prefix for PropertyConsumer interface. */ protected String propertyPrefix; /** * Hashtable that holds default DrawingAttributes for different * loaders. */ protected Hashtable drawingAttributesTable; protected boolean showAttributes = true; public final static String ShowAttributesProperty = "showAttributes"; public final static String LoaderProperty = "loaders"; public final static String AttributesClassProperty = "attributesClass"; public final static String DefaultDrawingAttributesClass = "com.bbn.openmap.omGraphics.DrawingAttributes"; /** * The general constructor that can be called from subclasses to * initialize the drawing tool and interface. All that is left to * do for subclasses is to add EditToolLoaders to the * DrawingEditorTool subclass. */ public DrawingEditorTool(EditorLayer layer) { super(layer); drawingAttributesTable = new Hashtable(); initDrawingTool(); // Ensures that the drawing tool used by super classes fits // the OMGraphics created by the EditorTool layer.setDrawingTool(drawingTool); } /** * Method called in the AbstractDrawingEditorTool constructor. */ public void initDrawingTool() { drawingTool = createDrawingTool(); drawingTool.setUseAsTool(true); // prevents popup menu use. drawingTool.getMouseMode().setVisible(false); ga = drawingTool.getAttributes(); ga.setRenderType(OMGraphic.RENDERTYPE_LATLON); ga.setLineType(OMGraphic.LINETYPE_GREATCIRCLE); } protected OMDrawingTool createDrawingTool() { return new OMDrawingTool(); } public void addEditToolLoader(EditToolLoader loader) { loaderList.add(loader); drawingTool.addLoader(loader); } public void removeEditToolLoader(EditToolLoader loader) { loaderList.remove(loader); drawingTool.removeLoader(loader); } public void clearEditToolLoaders() { loaderList.clear(); drawingTool.setLoaders(null); } /** * Add the default (line, poly, rectangle, circle/range rings, * point) capabilities to the tool. */ public void initDefaultDrawingToolLoaders() { addEditToolLoader(new OMDistanceLoader()); addEditToolLoader(new OMLineLoader()); addEditToolLoader(new OMPolyLoader()); addEditToolLoader(new OMRectLoader()); addEditToolLoader(new OMCircleLoader()); addEditToolLoader(new OMPointLoader()); } /** * The main method for getting the tool ready to create something. * When called, it sets the thingToCreate from the command, calls * setWantEvents(true), which calls resetForNewGraphic(). */ protected void setWantsEvents(String command) { if (Debug.debugging("editortool")) { Debug.output("DET.setWantsEvents(" + command + ")"); } // Has to be called first thingToCreate = command; setWantsEvents(true); } /** * The EditorTool method, with the added bonus of resetting the * tool if it doesn't want events. */ public void setWantsEvents(boolean value) { super.setWantsEvents(value); if (!value) { thingToCreate = null; } if (drawingTool != null && drawingTool.isActivated()) { drawingTool.resetGUIWhenDeactivated(true); drawingTool.deactivate(); } resetForNewGraphic(); if (drawingTool != null) { drawingTool.setVisible(showAttributes);// Just to make // sure... } } /** * Called by findAndInit(Iterator) so subclasses can find objects, * too. */ public void findAndInit(Object someObj) { super.findAndInit(someObj); if (someObj instanceof MapBean || someObj instanceof InformationDelegator) { drawingTool.findAndInit(someObj); } if (someObj instanceof MouseDelegator) { setMouseDelegator((MouseDelegator) someObj); // I think we want to handle this differently. The // EditorToolLayer should get the Gestures MouseMode to // act as a proxy for the drawing tool mouse mode when a // tool is not being used. drawingTool.findAndInit(someObj); } if (someObj instanceof OMGraphicDeleteTool) { ((OMGraphicDeleteTool) someObj).findAndInit(getDrawingTool()); } } public void findAndUndo(Object someObj) { super.findAndUndo(someObj); if (someObj == mouseDelegator) { setMouseDelegator(null); } if (someObj instanceof MapBean || someObj instanceof InformationDelegator) { drawingTool.findAndUndo(someObj); } if (someObj instanceof OMGraphicDeleteTool) { ((OMGraphicDeleteTool) someObj).findAndUndo(getDrawingTool()); } } /** * When a graphic is complete, the drawing tool gets ready to make * another. */ public void drawingComplete(OMGraphic omg, OMAction action) { // Watch out, gets called when drawingTool.deactivate() gets // called, so you can get in a loop if you try to do too much // here with regard to setting up the next OMGraphic to // create. if (thingToCreate != null) { drawingTool.resetGUIWhenDeactivated(false); } omdtmm = null; } /** * Called when the Tool should be reset to draw a new graphic. * Currently sets the OMDrawingToolMouseMode to null, which is a * signal to the DrawingEditorTool that if an appropriate * MouseEvent is provided, that the DrawingTool should be * configured to create a new OMGraphic. If the * OMDrawingToolMouseMode is not null, then the MouseEvent is just * given to it. */ public void resetForNewGraphic() { // if thingToCreate is null, then omdtmm will be set to null // and the drawingTool deactivated. If thingToCreate is not // null, omdtmm will be ready to receive mouse events for // editing the new OMGraphic. omdtmm = activateDrawingTool(thingToCreate); } /** * Does everything to make the DrawingEditorTool go to sleep, and * disable all buttons. */ public void totalReset() { // Need to check if the tool wants events before just // deactivating the drawing tool - that can mess up a edit // session that is unrelated to the tool but still related to // the DrawingToolLayer. if (wantsEvents()) { setWantsEvents(false); if (unpickBtn != null) { unpickBtn.doClick(); } } } /** * Set the OMDrawingTool to use. It's created internally, though. */ public void setDrawingTool(OMDrawingTool omdt) { drawingTool = omdt; } /** * Get the OMDrawingTool to use with this DrawingEditorTool. */ public OMDrawingTool getDrawingTool() { return drawingTool; } /** * actionPerformed - Handle the mouse clicks on the button(s) */ public void actionPerformed(ActionEvent e) { String command = e.getActionCommand(); if (Debug.debugging("editortool")) { Debug.output("DET.actionPerformed(" + command + ")"); } if (command == RESET_CMD) { setWantsEvents(false); } else if (command != thingToCreate) { EditorLayer elayer = (EditorLayer) getLayer(); elayer.releaseProxyMouseMode(); if (thingToCreate == null && mouseDelegator != null) { mouseDelegator.setActiveMouseModeWithID(elayer.getMouseMode() .getID()); } // Calling with command will set 'thingToCreate' and // resetForNewGraphic setWantsEvents(command); } } /** * Method to set up the drawing tool with default behavior in * order to create a new OMGraphic. Will try to deactivate the * OMDrawingTool if it thinks it's busy. *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -