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

📄 mousedelegator.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 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/MouseDelegator.java,v $// $RCSfile: MouseDelegator.java,v $// $Revision: 1.3.2.4 $// $Date: 2005/12/16 13:56:28 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import java.beans.PropertyChangeSupport;import java.beans.PropertyVetoException;import java.beans.VetoableChangeListener;import java.beans.beancontext.BeanContext;import java.beans.beancontext.BeanContextChild;import java.beans.beancontext.BeanContextChildSupport;import java.beans.beancontext.BeanContextMembershipEvent;import java.beans.beancontext.BeanContextMembershipListener;import java.util.Iterator;import java.util.Vector;import com.bbn.openmap.event.MapMouseListener;import com.bbn.openmap.event.MapMouseMode;import com.bbn.openmap.event.NavMouseMode;import com.bbn.openmap.event.NullMouseMode;import com.bbn.openmap.event.ProjectionListener;import com.bbn.openmap.event.SelectMouseMode;import com.bbn.openmap.util.Debug;/** * The MouseDelegator manages the MapMouseModes that handle * MouseEvents on the map. There should only be one MouseDelegator * within a MapHandler. *  * @see com.bbn.openmap.event.MapMouseMode * @see com.bbn.openmap.event.AbstractMouseMode * @see com.bbn.openmap.event.NavMouseMode * @see com.bbn.openmap.event.SelectMouseMode */public class MouseDelegator implements PropertyChangeListener,        java.io.Serializable, BeanContextChild, BeanContextMembershipListener,        SoloMapComponent {    public final static transient String ActiveModeProperty = "NewActiveMouseMode";    public final static transient String MouseModesProperty = "NewListOfMouseModes";    /**     * The active MapMouseMode.     */    protected transient MapMouseMode activeMouseMode = null;    /**     * The registered MapMouseModes.     */    protected transient Vector mouseModes = new Vector(0);    /**     * The MapBean.     */    protected transient MapBean map;    /**     * Need to keep a safe copy of the current layers that are part of     * the MapBean in case a MouseMode gets added before the MapBean     * is set in the MouseDelegator. Without this, you can get into a     * situation where new MapMouseModes don't know about layers until     * the MouseDelegator receives a property change event from the     * MapBean.     */    protected Layer[] currentLayers = null;    /**     * PropertyChangeSupport for handling listeners.     */    protected PropertyChangeSupport pcSupport = new PropertyChangeSupport(this);    /**     * BeanContextChildSupport object provides helper functions for     * BeanContextChild interface.     */    protected BeanContextChildSupport beanContextChildSupport = new BeanContextChildSupport(this);    /**     * Construct a MouseDelegator with an associated MapBean.     *      * @param map MapBean     */    public MouseDelegator(MapBean map) {        setMap(map);    }    /**     * Construct a MouseDelegator without an associated MapBean. You     * will need to set the MapBean via <code>setMap()</code>.     *      * @see #setMap     */    public MouseDelegator() {        this(null);    }    /**     * Set the associated MapBean.     *      * @param mapbean MapBean     */    public void setMap(MapBean mapbean) {        if (map != null) {            map.removePropertyChangeListener(this);            setInactive(activeMouseMode);        }        map = mapbean;        if (map != null) {            map.addPropertyChangeListener(this);            setActive(activeMouseMode);        }    }    /**     * Get the associated MapBean.     *      * @return MapBean     */    public MapBean getMap() {        return map;    }    //----------------------------------------------------------------------    //    // Mouse Event handling support    //    //----------------------------------------------------------------------    /**     * Returns the ID string for the active Mouse Mode.     *      * @return String ID of the active mouse mode.     */    public String getActiveMouseModeID() {        if (activeMouseMode != null)            return activeMouseMode.getID();        else            return null;    }    /**     * Sets the mouse mode to the mode with the same ID string. If     * none of the MouseEventDelagates have a matching ID string, the     * mode is not changed. <br>     * The map mouse cursor is set to the recommended cursor retrieved     * from the active mouseMode.     *      * @param MouseModeID the string ID of the mode to set active.     */    public void setActiveMouseModeWithID(String MouseModeID) {        if (MouseModeID == null) {            Debug.error("MouseDelegator:setActiveMouseModeWithID() - null value");            return;        }        MapMouseMode oldActive = activeMouseMode;        setInactive(activeMouseMode);        for (int i = 0; i < mouseModes.size(); i++) {            MapMouseMode med = (MapMouseMode) mouseModes.elementAt(i);            if (MouseModeID.equals(med.getID())) {                setActive(med);                if (Debug.debugging("mousemode")) {                    Debug.output("MouseDelegator.setActiveMouseModeWithID() setting new mode to mode "                            + i + " " + med.getID());                }                break;            }        }        firePropertyChange(ActiveModeProperty, oldActive, activeMouseMode);    }    /**     * Returns the mouse mode delegate that is active at the moment.     *      * @return MapMouseMode the active mouse mode     */    public MapMouseMode getActiveMouseMode() {        return activeMouseMode;    }    /**     * Sets the active mouse mode. If the MapMouseMode is not a member     * of the current mouse modes, it is added to the list. <br>     * The map mouse cursor is set to the recommended cursor retrieved     * from the active mouseMode.     *      * @param aMed a MapMouseMode to make active.     */    public void setActiveMouseMode(MapMouseMode aMed) {        if (aMed == null) {            Debug.error("MouseDelegator:setActiveMouseMode() - null value");            return;        }        MapMouseMode oldActive = activeMouseMode;        boolean isAlreadyAMode = false;        for (int i = 0; i < mouseModes.size(); i++) {            MapMouseMode med = (MapMouseMode) mouseModes.elementAt(i);            // Need to go through the modes, turn off the other active            // mode, and turn on this one.            if (aMed.getID().equals(med.getID())) {                isAlreadyAMode = true;            }        }        if (!isAlreadyAMode) {            addMouseMode(aMed);        }        setActive(aMed);        firePropertyChange(ActiveModeProperty, oldActive, activeMouseMode);    }    /**     * Returns an array of MapMouseModes that are available to the     * MapBean.     *      * @return an array of MapMouseModes.     */    public MapMouseMode[] getMouseModes() {        int nMouseModes = mouseModes.size();        if (nMouseModes == 0)            return (new MapMouseMode[0]);        MapMouseMode[] result = new MapMouseMode[nMouseModes];        for (int i = 0; i < nMouseModes; i++) {            result[i] = (MapMouseMode) mouseModes.elementAt(i);        }        return result;    }    /**     * Used to set the mouseModes available to the MapBean. The     * Delegator drops all references to any mouseModes it knew about     * previously. It also sets the index of the array to be the     * active mouse mode. <br>     * The map mouse cursor is set to the recommended cursor retrieved     * from the active mouseMode.     *      * @param meds an array of MapMouseModes     * @param activeIndex which mouse mode to make active     */    public void setMouseModes(MapMouseMode[] meds, int activeIndex) {        mouseModes.removeAllElements();        MapMouseMode oldActive = activeMouseMode;        for (int i = 0; i < meds.length; i++) {            mouseModes.addElement(meds[i]);            if (i == activeIndex) { // activate the right mode                setActive(meds[i]);            }        }        firePropertyChange(MouseModesProperty, null, mouseModes);        firePropertyChange(ActiveModeProperty, oldActive, activeMouseMode);    }    /**     * Used to set the mouseModes available to the MapBean. The     * MapBean drops all references to any mouseModes it knew about     * previously. The meds[0] mode is made active, by default.     *      * @param meds an array of MapMouseModes     */    public void setMouseModes(MapMouseMode[] meds) {        setMouseModes(meds, 0);    }    /**     * Adds a MapMouseMode to the MouseMode list. Does not make it the     * active mode.     *      * @param med the MouseEvent Delegate to add.     */    public void addMouseMode(MapMouseMode med) {        if (med != null) {            mouseModes.addElement(med);            //  All of the MouseModes will think they are active, but            //  the Delegator will only pass events to the one it            //  thinks is...            if (mouseModes.size() == 1) {                setActive(med);            }            if (currentLayers != null) {                setupMouseModeWithLayers(med, currentLayers);            }            firePropertyChange(MouseModesProperty, null, mouseModes);        }    }    /**     * Removes a particular MapMouseMode from the MouseMode list.     *      * @param med the MapMouseMode that should be removed.     */    public void removeMouseMode(MapMouseMode med) {        boolean needToAdjustActiveMode = false;        if (med.equals(activeMouseMode)) {            needToAdjustActiveMode = true;            setInactive(med);        }        for (int i = 0; i < mouseModes.size(); i++) {

⌨️ 快捷键说明

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