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

📄 omdrawingtool.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
// **********************************************************************//// <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/tools/drawing/OMDrawingTool.java,v $// $RCSfile: OMDrawingTool.java,v $// $Revision: 1.25.2.6 $// $Date: 2005/08/10 22:45:11 $// $Author: dietrick $//// **********************************************************************package com.bbn.openmap.tools.drawing;import java.awt.Component;import java.awt.Cursor;import java.awt.Frame;import java.awt.Graphics;import java.awt.Rectangle;import java.awt.Shape;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.MouseEvent;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import java.io.Serializable;import java.util.Hashtable;import java.util.Iterator;import java.util.Properties;import java.util.Set;import java.util.Vector;import javax.swing.BorderFactory;import javax.swing.JComponent;import javax.swing.JMenuItem;import javax.swing.JPopupMenu;import javax.swing.JSeparator;import com.bbn.openmap.Environment;import com.bbn.openmap.I18n;import com.bbn.openmap.InformationDelegator;import com.bbn.openmap.MapBean;import com.bbn.openmap.MapHandler;import com.bbn.openmap.MouseDelegator;import com.bbn.openmap.event.MapMouseMode;import com.bbn.openmap.event.PaintListener;import com.bbn.openmap.event.ProjectionEvent;import com.bbn.openmap.event.ProjectionListener;import com.bbn.openmap.gui.OMToolComponent;import com.bbn.openmap.gui.WindowSupport;import com.bbn.openmap.omGraphics.DrawingAttributes;import com.bbn.openmap.omGraphics.EditableOMGraphic;import com.bbn.openmap.omGraphics.EditableOMGraphicList;import com.bbn.openmap.omGraphics.GraphicAttributes;import com.bbn.openmap.omGraphics.OMAction;import com.bbn.openmap.omGraphics.OMGraphic;import com.bbn.openmap.omGraphics.OMGraphicConstants;import com.bbn.openmap.omGraphics.OMGraphicList;import com.bbn.openmap.omGraphics.event.EOMGEvent;import com.bbn.openmap.omGraphics.event.EOMGListener;import com.bbn.openmap.omGraphics.event.SelectionListener;import com.bbn.openmap.omGraphics.event.SelectionProvider;import com.bbn.openmap.omGraphics.event.SelectionSupport;import com.bbn.openmap.proj.Projection;import com.bbn.openmap.util.Debug;import com.bbn.openmap.util.PropUtils;/** * The OMDrawingTool implements the DrawingTool interface, and can be * used to adjust the drawing parameters of OMGraphics. It is * basically a manager for directing MouseEvents and MouseMotionEvents * from a Component to a EditableOMGraphic. The EditableOMGraphic is * responsible for interpreting the events and making the adjustments * to the OMGraphic it has wrapped within. The OMDrawingTool also * tries to keep the presentation of the OMGraphic up to date, by * managing the repaints of the Component to include the graphic being * modified. * <P> *  * The OMDrawingTool is also a com.bbn.openmap.gui.Tool, which allows * it to appear in the OpenMap toolbar. The OMDrawingTool keeps track * of whether it is a tool, and appears accordingly: * <P> *  * If the OMDrawingTool is being used as a tool (getUseAsTool() == * true), then it will set itself to be visible. If you are putting an * OMDrawingTool in the OpenMap application and you want the * color/line/graphic options to be visible in the toolbar, use the * itTool property for the OMDrawingTool in the properties file. If * you are using your own OMDrawingTool, in your EditorLayerTool for * instance, you should set useAsTool(true) programmatically to get * the visiblity of the tool to appear. There is a property to tell * the OMDrawingTool to be visible when it is inactive, and that flag * is true by default. You can set that property (visibleWhenInactive) * to change this behavior. *  * If the OMDrawingTool is not being used as a tool, it can be brought * up in a window. This window can be brought up with a right click or * control-click on the object being edited. * <P> *  * If the OMGraphic being edited doesn't want to have the * OMDrawingTool visible, it won't be. Neither the tool nor the option * to bring the window up won't be displayed with a right/control * click. * <P> *  * The OMDrawingTool uses a behavior mask to give control over how it * behaves. You can control if the attribute palette appears, if a * popup gui appears by default when the editing is complete, or * appear when the alt+mouse key or right mouse key is pressed. You * should set this mask if you are not sure about the values that * other components may have set on the OMDrawingTool. * <P> *  * The OMDrawingTool uses EditToolLoaders to determine what * EditableOMGraphic can be used for a particular class name or * OMGraphic type. If a loader for an OMGraphic type is not found, * then that OMGraphic type won't be handled, and the tool will react * to a create() or edit() call with a null object pointer. If a * loader is found, and the OMgraphic can be edited or modified, then * the create() or edit() methods will return a pointer to the * OMGraphic being modified. * <P> *  * The GUI for the OMDrawingTool is multi-layered. The OMDrawingTool * contains a GraphicsAttributes object, which is an extension of the * GraphicAttributes object. The GraphicAttributes GUI within the tool * lets you change the colors, line width and line dash pattern of the * current OMGraphic. The GraphicAttributes conttribution to the GUI * is not yet implemented, but will let you change the render type and * line type of the OMGraphic. Finally, the EditableOMGraphic is given * an opportunity to change and set parameters of the OMGraphic that * is knows about - for instance, the EditableOMLine object will soon * provide an interface to set arrowheads on the lines, as well as set * the amount of arc a line has (it's currently not implemented). * <P> */public class OMDrawingTool extends OMToolComponent implements DrawingTool,        Serializable, PropertyChangeListener, ProjectionListener, EOMGListener,        PaintListener, SelectionProvider {    I18n i18n = Environment.getI18n();    /**     * A GraphicAttributes object that describes the current coloring     * parameters for the current graphic.     */    protected GraphicAttributes graphicAttributes = GraphicAttributes.getGADefaultClone();    /** The current graphic being modified. */    protected EditableOMGraphic currentEditable;    /**     * The MouseDelegator to use to get mouse events directed to the     * DrawingTool.     */    protected MouseDelegator mouseDelegator;    /**     * A placeholder for the last mouse mode active before the drawing     * tool took over.     */    protected MapMouseMode formerMouseMode = null;    /**     * The JComponent the drawing tool is servicing, usually the     * MapBean.     */    protected JComponent canvas;    /**     * The objects that know how to create a EditableOMGraphic for a     * particular class name or OMGraphic.     */    protected Hashtable loaders = new Hashtable();    /**     * The ordered list of EditToolLoaders, for notification.     * Preservers order, no duplicates.     */    protected Vector rawLoaders = new Vector();    /**     * The MouseMode used for the drawing tool.     */    protected OMDrawingToolMouseMode dtmm;    /**     * The component to notify when the drawing tool is finished.     */    protected DrawingToolRequestor requestor = null;    /** The current projection. */    protected Projection projection = null;    /**     * A support object to handle telling listeners that the drawing     * tool is in the process of editing an object, hence making it     * selected.     */    protected SelectionSupport selectionSupport = null;    /**     * A behavior mask to show the GUI for the OMDrawingTool. Since     * the OMDrawingTool is a com.bbn.openmap.gui.Tool object, it will     * only appear on the tool panel if it has been added to it, and     * if it is being used as a tool.     */    public final static int SHOW_GUI_BEHAVIOR_MASK = 1 << 0; // + 1    /**     * A behavior mask to add a menu item to the popup that will allow     * the GUI to appear. If the OMDrawingTool is not being used as a     * tool and this is set along with USE_POPUP_BEHAVIOR_MASK or     * ALT_POPUP_BEHAVIOR_MASK, then the OMDrawingTool will appear in     * a window when the <B>Change Appearance </B> option is selected     * in the popup menu.     */    public final static int GUI_VIA_POPUP_BEHAVIOR_MASK = 1 << 1; // + 2    /**     * Flag to tell the OMDrawingTool to display a popup when     * gesturing/modifications appear to be over. Was the default     * action of the tool, but was moved to only happening when the     * ctrl key or right mouse button is pressed. You can force the     * old behavior by setting this.     */    public final static int USE_POPUP_BEHAVIOR_MASK = 1 << 2; // + 4    /**     * Allow a GUI popup to appear over the map when the     * gesturing/modifications appear to be over, and when the ctrl     * key or right mouse button is pressed.     */    public final static int ALT_POPUP_BEHAVIOR_MASK = 1 << 3; // + 8    /**     * Set the flag for the behavior that will tell the OMDrawingTool     * to *NOT* add the OMDrawingToolMouseMode to the MouseDelegator     * as the active mouse mode when activated. Should be called     * before create/edit is called, and then you have to make sure     * that you provide MouseEvents to the OMDrawingToolMouseMode or     * EditableOMGraphic in order to modify the OMGraphic. Don't call     * this if you have already started using the tool, the tool won't     * do anything if anything else is currently being modified.     */    public final static int PASSIVE_MOUSE_EVENT_BEHAVIOR_MASK = 1 << 4; // + 16    /**     * This behavior is used internally, when the OMDrawingTool should     * be told to clean up as soon as it is safe.     */    public final static int DEACTIVATE_ASAP_BEHAVIOR_MASK = 1 << 5; // + 32    /**     * A convenience value that tells the OMDrawingTool to show the     * GUI if it is a tool, or to only display the popup with the ctrl     * key or right mouse button if it isn't. A combination of     * SHOW_GUI, GUI_VIA_POPUP and ALT_POPUP.     */    public final static int DEFAULT_BEHAVIOR_MASK = 11;    /**     * A convenience value that tells the OMDrawingTool to not show     * the GUI, but show the popup with the alt key, and the popup has     * the ability to delete the OMGraphic. A combination of     * GUI_VIA_POPUP and ALT_POPUP.     */    public final static int QUICK_CHANGE_BEHAVIOR_MASK = 10;    /**     * A integer that is looked at, bitwise, to determine different     * behaviors.     */    protected int behaviorMask = DEFAULT_BEHAVIOR_MASK;    /**     * Used for property change notifications.     */    public final static String LoadersProperty = "OMDrawingTool.loaders";    /**     * Debug flag turned on when <B>drawingtool </B> debug flag     * enabled.     */    protected boolean DEBUG = false;    /**     * A handle to the InformationDelegator to use for status     * messages.     */    protected InformationDelegator informationDelegator = null;    /**     * A Vector of Classes that can be handled by the OMDrawingTool.     * Constructed the first time canEdit() is called after an     * EditToolLoader is added or removed.     */    protected Vector possibleEditableClasses = null;    /**     * Just a helper flag to reduce work caused by unnecessary     * deactivate calls. Set internally in activate() and     * deactivate().     */    protected boolean activated = false;    /**     * Tell the drawing tool to be invisible when it is inactive. True     * by default.     */    protected boolean visibleWhenInactive = true;    /**     * The property, visibleWhenIactive, to set to false if you want     * that behavior.     */    public final static String VisibleWhenInactiveProperty = "visibleWhenInactive";    /**     * Flag to tell tool to reset the GUI when it is deactivated. The     * only time you would want this to be false (true is default) is     * when you are creating many objects of the same type, and don't     * want the gui to keep going back and forth between the default     * and special settings. Usually set to in the drawingComplete     * method of an EditorTool. Reset to true when showPalette is     * called.     */    protected boolean resetGUIWhenDeactivated = true;    /**     * Create a OpenMap Drawing Tool.     */    public OMDrawingTool() {        super();        setBorder(BorderFactory.createEmptyBorder());        DEBUG = Debug.debugging("drawingtool");        selectionSupport = new SelectionSupport(this);        setAttributes(new GraphicAttributes());        setMouseMode(createMouseMode());        // Shouldn't assume that the drawing tool is a tool. This can        // be set in the properties if it should be. Otherwise, the        // default action is to appear on a right click called from        // the GUI.        setUseAsTool(false);    }    /**     * Create the mouse mode used with the drawing tool. Called in the     * default empty constructor, returns a OMDrawingToolMouseMode by     * default.     */    protected OMDrawingToolMouseMode createMouseMode() {        return new OMDrawingToolMouseMode(this);    }    /**     * 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.

⌨️ 快捷键说明

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