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

📄 abstractmousemode.java

📁 OpenMap是一个基于JavaBeansTM的开发工具包。利用OpenMap你就能够快速构建用于访问legacy数据库的应用程序与applets。OpenMap提供了允许用户查看和操作地理空间信息的
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
// **********************************************************************// // <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/event/AbstractMouseMode.java,v $// $RCSfile: AbstractMouseMode.java,v $// $Revision: 1.7.2.5 $// $Date: 2007/04/05 21:24:20 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.event;import java.awt.Cursor;import java.awt.event.MouseEvent;import java.awt.event.MouseWheelEvent;import java.io.Serializable;import java.lang.reflect.Field;import java.net.MalformedURLException;import java.text.DecimalFormat;import java.util.Properties;import javax.swing.Icon;import javax.swing.ImageIcon;import com.bbn.openmap.I18n;import com.bbn.openmap.Layer;import com.bbn.openmap.MapBean;import com.bbn.openmap.OMComponent;import com.bbn.openmap.util.PropUtils;import com.bbn.openmap.util.propertyEditor.OptionPropertyEditor;/** * Base class of the MouseModes. It takes care of the administrative aspects of * being a mouse mode, but does not respond to MouseEvents. * <p> * The ID and pretty name can be set in the properties file. *  * <pre> *  *     *    # Name that layers use to get events from this mode *    mousemode.id=ID *    # Tooltip and Menu name for mode *    mousemode.prettyName=Display Name *    *     *    *   * </pre> *  * This class delegates much of the work of managing its listeners to a * MapMouseSupport object. *  * @see MapMouseSupport */public class AbstractMouseMode extends OMComponent implements MapMouseMode,        Serializable {    /**     * The identifier for the mode, which is also the name that will be used in     * a used interface describing the mode to a user.     */    protected String ID = null;    /**     * The object used to handle the listeners and to pass out the event to the     * layers interesed in it.     */    protected MapMouseSupport mouseSupport;    /**     * The cursor that appears on the map when this Mouse Mode is active.     */    protected Cursor cursor = Cursor.getDefaultCursor();    /**     * The Icon that can be used in a GUI. Can be null. The class will look for     * a resource gif file that has the same ID string - Navigation.gif for the     * NavMouseMode, for instance.     */    protected transient Icon guiIcon = null;    public transient DecimalFormat df = new DecimalFormat("0.###");    protected transient boolean visible = true;    protected String prettyName;    protected String iconName;    protected boolean zoomWhenMouseWheelUp = ZOOM_IN;    /**     * Zoom direction in when mouse wheel rotated up.     */    public static final boolean ZOOM_IN = true;    /**     * Zoom direction out when mouse wheel rotated up.     */    public static final boolean ZOOM_OUT = false;    /**     * The MouseModeID to use for a particular instance of a MapMouseMode. If     * not set, the default mouse mode ID of the MapMouseMode will be used.     */    public static final String IDProperty = "id";    /**     * The String to use for a key lookup in a Properties object to find the     * name to use in a GUI relating to this Mouse Mode.     */    public static final String PrettyNameProperty = "prettyName";    /**     * The java.awt.Cursor id that should be used for the mouse mode.     *      * @see java.awt.Cursor     */    public static final String CursorIDProperty = "cursorID";    /**     * A property that lets you specify the resource to use for the icon for the     * MouseMode.     */    public static final String IconProperty = "icon";    /**     * A property that lets you specify if the mode zooms in or out when the     * mouse wheel is rotated up. Appropriate values are ZOOM_IN or ZOOM_OUT.     */    public static final String MouseWheelZoomProperty = "mouseWheelUp";    /**     * Construct an AbstractMouseMode. Default constructor, allocates the mouse     * support object.     */    public AbstractMouseMode() {        this("Unnamed Mode", true);    }    /**     * Construct an AbstractMouseMode.     *      * @param name the ID of the mode.     * @param shouldConsumeEvents if true, events are propagated to the first     *        MapMouseListener that successfully processes the event, if false,     *        events are propagated to all MapMouseListeners     */    public AbstractMouseMode(String name, boolean shouldConsumeEvents) {        mouseSupport = new MapMouseSupport(this, shouldConsumeEvents);        ID = name;        setIconName(name + ".gif");    }    /**     * Internal callback method that lets subclasses override a class to use as     * a resource point for icon image retrieval.     *      * @return Class that has icon image file next to it in classpath.     */    protected Class getClassToUseForIconRetrieval() {        return getClass();    }    /**     * Sets the GUI icon based on the name of the resource provided. The     * resource will be checked against the classpath, and if it isn't found,     * the mouse mode will be asked for the class to use for icon retrieval.     *      * @param iName     */    public void setIconName(String iName) {        iconName = iName;        java.net.URL url = null;        try {            url = PropUtils.getResourceOrFileOrURL(iName);        } catch (MalformedURLException murle) {        }        if (url == null) {            url = getClassToUseForIconRetrieval().getResource(iconName);        }        if (url != null) {            guiIcon = new ImageIcon(url);        }    }    public String getIconName() {        return iconName;    }    /**     * Returns the id (mode name).     *      * @return String ID     */    public String getID() {        return ID;    }    /**     * Set the id (mode name).     *      * @param id string that identifies the delegate.     */    public void setID(String id) {        ID = id;    }    public void setPrettyName(String pn) {        prettyName = pn;    }    /**     * Return a pretty name, suitable for the GUI. If set, is independent of the     * mode ID. If not set, is the same as the mode ID.     */    public String getPrettyName() {        if (prettyName == null) {            return i18n.get(this.getClass(), PrettyNameProperty, ID);        } else {            return prettyName;        }    }    /**     * Gets the mouse cursor recommended for use when this mouse mode is active.     *      * @return Cursor the mouse cursor recommended for use when this mouse mode     *         is active.     */    public Cursor getModeCursor() {        return cursor;    }    /**     * Sets the cursor that is recommended for use on the map when this mouse     * mode is active.     *      * @param curs the cursor that is recommended for use on the map when this     *        mouse mode is active.     */    public void setModeCursor(Cursor curs) {        cursor = curs;    }    /**     * Sets the cursor that is recommended for use on the map when this mouse     * mode is active.     *      * @param cursorID the cursor ID member variable string, i.e. DEFAULT_CURSOR     * @see java.awt.Cursor     */    public void setModeCursor(String cursorID) {        if (cursorID != null) {            try {                int cid = java.awt.Cursor.class.getField(cursorID).getInt(null);                setModeCursor(Cursor.getPredefinedCursor(cid));            } catch (NoSuchFieldException nsfe) {            } catch (IllegalAccessException iae) {            }        }    }    /**     * Gets the Icon to represent the Mouse Mode in a GUI. May be null.     */    public Icon getGUIIcon() {        return guiIcon;    }    /**     * Set the icon that should be used for this Mouse Mode in a GUI.     */    public void setGUIIcon(Icon icon) {        guiIcon = icon;    }    /**     * Sets how the delegate passes out events. If the value passed in is true,     * the delegate will only pass the event to the first listener that can     * respond to the event. If false, the delegate will pass the event on to     * all its listeners.     *      * @param value true for limited distribution.     */    public void setConsumeEvents(boolean value) {        mouseSupport.setConsumeEvents(value);    }    /**     * Returns how the delegate (and it's mouse support) is set up to distribute     * events.     *      * @return true if only one listner gets to act on an event.     */    public boolean isConsumeEvents() {        return mouseSupport.isConsumeEvents();    }    public boolean isZoomWhenMouseWheelUp() {        return zoomWhenMouseWheelUp;    }    public void setZoomWhenMouseWheelUp(boolean zoomWhenMouseWheelUp) {        this.zoomWhenMouseWheelUp = zoomWhenMouseWheelUp;    }    /**     * Add a MapMouseListener to the MouseMode. The listener will then get     * events from the delegator if the delegator is active.     *      * @param l the MapMouseListener to add.     */    public void addMapMouseListener(MapMouseListener l) {        mouseSupport.addMapMouseListener(l);    }    /**     * Remove a MapMouseListener from the MouseMode.     *      * @param l the MapMouseListener to remove.     */    public void removeMapMouseListener(MapMouseListener l) {        mouseSupport.removeMapMouseListener(l);    }    /**     * Remove all MapMouseListeners from the mode.     */    public void removeAllMapMouseListeners() {        mouseSupport.removeAllMapMouseListeners();    }

⌨️ 快捷键说明

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