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

📄 mousedelegator.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            if (med.equals(mouseModes.elementAt(i))) {                med.removeAllMapMouseListeners();                mouseModes.removeElementAt(i);            }            // Set the first mode to the active one, if deleting the            // active one.            else if (needToAdjustActiveMode) {                setActive(med);                needToAdjustActiveMode = false;            }        }        firePropertyChange(MouseModesProperty, null, mouseModes);    }    /**     * Removes a particular MapMouseMode from the MouseMode list, with     * the ID given.     *      * @param id the ID of the MapMouseMode that should be removed     */    public void removeMouseMode(String id) {        for (int i = 0; i < mouseModes.size(); i++) {            MapMouseMode med = (MapMouseMode) mouseModes.elementAt(i);            if (id.equals(med.getID())) {                removeMouseMode(med);                break;            }        }    }    /**     * Sets the three default OpenMap mouse modes. These modes are:     * NavMouseMode (Map Navigation), the SelectMouseMode (MouseEvents     * go to Layers), and NullMouseMode (MouseEvents are ignored).     */    public void setDefaultMouseModes() {        MapMouseMode[] modes = new MapMouseMode[3];        modes[0] = new NavMouseMode(true);        modes[1] = new SelectMouseMode(true);        modes[2] = new NullMouseMode();        setMouseModes(modes);    }    /**     * PropertyChangeListenter Interface method.     *      * @param evt PropertyChangeEvent     */    public void propertyChange(PropertyChangeEvent evt) {        String property = evt.getPropertyName();        if (property == MapBean.LayersProperty) {            // make a safe copy of the layers that are part of the            // MapBean            Layer[] layers = (Layer[]) evt.getNewValue();            currentLayers = new Layer[layers.length];            System.arraycopy(layers, 0, currentLayers, 0, layers.length);            setupMouseModesWithLayers(currentLayers);        }    }    /**     * Does the work putting the layers given on each mouse mode's     * list of layers to notify if it becomes active.     */    public void setupMouseModesWithLayers(Layer[] layers) {        for (int j = 0; j < mouseModes.size(); j++) {            // Clear out the old listeners first            MapMouseMode mmm = (MapMouseMode) mouseModes.elementAt(j);            setupMouseModeWithLayers(mmm, layers);        }    }    /**     * Gives a MapMouseMode access to a Layer[], and it will find the     * layers that want to listen to it and will forward events to     * them if it is added to the MapBean as a MouseListener or a     * MouseMotionListener.     *      * @param mmm MapMouseMode     * @param layers Layer[]     */    public void setupMouseModeWithLayers(MapMouseMode mmm, Layer[] layers) {        mmm.removeAllMapMouseListeners();        for (int i = 0; i < layers.length; i++) {            // Add the listeners from each layer to the mouse mode.            MapMouseListener tempmml = null;            if (layers[i] != null) {                tempmml = layers[i].getMapMouseListener();            }            if (tempmml == null) {                continue;            }            String[] services = tempmml.getMouseModeServiceList();            if (services != null) {                for (int k = 0; k < services.length; k++) {                    if (mmm.getID().equals(services[k])) {                        mmm.addMapMouseListener(tempmml);                        if (Debug.debugging("mousemode")) {                            Debug.output("MouseDelegator.setupMouseModeWithLayers():"                                    + " layer = "                                    + layers[i].getName()                                    + " service = " + mmm.getID());                        }                        break;                    }                }            }        }    }    /**     * Set the active MapMouseMode. This sets the MapMouseMode of the     * associated MapBean.     *      * @param mm MapMouseMode     */    public void setActive(MapMouseMode mm) {        if (activeMouseMode != null) {            setInactive(activeMouseMode);        }        activeMouseMode = mm;        if (map != null && activeMouseMode != null) {            if (Debug.debugging("mousemode")) {                Debug.output("MouseDelegator.setActive(): " + mm.getID());            }            map.addMouseListener(mm);            map.addMouseMotionListener(mm);            map.addMouseWheelListener(mm);            map.addPaintListener(mm);            map.setCursor(activeMouseMode.getModeCursor());            if (mm instanceof ProjectionListener) {                map.addProjectionListener((ProjectionListener) mm);            }            activeMouseMode.setActive(true);        }    }    /**     * Deactivate the MapMouseMode.     *      * @param mm MapMouseMode.     */    public void setInactive(MapMouseMode mm) {        if (map != null) {            map.removeMouseListener(mm);            map.removeMouseMotionListener(mm);            map.removeMouseWheelListener(mm);            map.removePaintListener(mm);            // should set map's cursor to some default value??            if (mm instanceof ProjectionListener) {                map.removeProjectionListener((ProjectionListener) mm);            }        }        if (activeMouseMode == mm) {            activeMouseMode = null;        }        if (mm != null) {            mm.setActive(false);        }    }    /**     * Eventually gets called when the MouseDelegator is added to the     * BeanContext, and when other objects are added to the     * BeanContext anytime after that. The MouseDelegator looks for a     * MapBean to manage MouseEvents for, and MouseModes to use to     * manage those events. If a MapBean is added to the BeanContext     * while another already is in use, the second MapBean will take     * the place of the first.     *      * @param it iterator to use to go through the new objects in the     *        BeanContext.     */    public void findAndInit(Iterator it) {        while (it.hasNext()) {            findAndInit(it.next());        }    }    /**     * Called when an object should be evaluated by the MouseDelegator     * to see if it is needed.     */    public void findAndInit(Object someObj) {        if (someObj instanceof MapBean) {            Debug.message("mousedelegator", "MouseDelegator found a map.");            setMap((MapBean) someObj);        }        if (someObj instanceof MapMouseMode) {            Debug.message("mousedelegator",                    "MouseDelegator found a MapMouseMode.");            addMouseMode((MapMouseMode) someObj);        }    }    /**     * BeanContextMembershipListener method. Called when new objects     * are added to the parent BeanContext.     *      * @param bcme event that contains an iterator that can be used to     *        go through the new objects.     */    public void childrenAdded(BeanContextMembershipEvent bcme) {        findAndInit(bcme.iterator());    }    /**     * BeanContextMembershipListener method. Called when objects have     * been removed from the parent BeanContext. The MouseDelegator     * looks for the MapBean it is managing MouseEvents for, and any     * MouseModes that may be removed.     *      * @param bcme event that contains an iterator that can be used to     *        go through the removed objects.     */    public void childrenRemoved(BeanContextMembershipEvent bcme) {        Iterator it = bcme.iterator();        while (it.hasNext()) {            findAndUndo(it.next());        }    }    /**     * Called by childrenRemoved.     */    public void findAndUndo(Object someObj) {        if (someObj instanceof MapBean) {            if (getMap() == (MapBean) someObj) {                Debug.message("mousedelegator",                        "MouseDelegator: removing the map.");                setMap(null);            }        }        if (someObj instanceof MapMouseMode) {            Debug.message("mousedelegator",                    "MouseDelegator: removing a MapMouseMode.");            removeMouseMode((MapMouseMode) someObj);        }    }    /** Method for BeanContextChild interface. */    public BeanContext getBeanContext() {        return beanContextChildSupport.getBeanContext();    }    /** Method for BeanContextChild interface. */    public void setBeanContext(BeanContext in_bc) throws PropertyVetoException {        if (in_bc != null) {            in_bc.addBeanContextMembershipListener(this);            beanContextChildSupport.setBeanContext(in_bc);            findAndInit(in_bc.iterator());        }    }    /** Method for BeanContextChild interface. */    public void addPropertyChangeListener(String propertyName,                                          PropertyChangeListener in_pcl) {        pcSupport.addPropertyChangeListener(propertyName, in_pcl);    }    /** Method for BeanContextChild interface. */    public void removePropertyChangeListener(String propertyName,                                             PropertyChangeListener in_pcl) {        pcSupport.removePropertyChangeListener(propertyName, in_pcl);    }    public void addPropertyChangeListener(PropertyChangeListener listener) {        // This function is why we don't use the        // BeanContextChildSupport PropertyChangeSupport object.        pcSupport.addPropertyChangeListener(listener);    }    public void removePropertyChangeListener(PropertyChangeListener listener) {        // This function is why we don't use the        // BeanContextChildSupport PropertyChangeSupport object.        pcSupport.removePropertyChangeListener(listener);    }    public void firePropertyChange(String property, Object oldObj, Object newObj) {        pcSupport.firePropertyChange(property, oldObj, newObj);    }    /** Method for BeanContextChild interface. */    public void addVetoableChangeListener(String propertyName,                                          VetoableChangeListener in_vcl) {        beanContextChildSupport.addVetoableChangeListener(propertyName, in_vcl);    }    /** Method for BeanContextChild interface. */    public void removeVetoableChangeListener(String propertyName,                                             VetoableChangeListener in_vcl) {        beanContextChildSupport.removeVetoableChangeListener(propertyName,                in_vcl);    }    /**     * Report a vetoable property update to any registered listeners.     * If anyone vetos the change, then fire a new event reverting     * everyone to the old value and then rethrow the     * PropertyVetoException.     * <P>     *      * No event is fired if old and new are equal and non-null.     * <P>     *      * @param name The programmatic name of the property that is about     *        to change     *      * @param oldValue The old value of the property     * @param newValue - The new value of the property     *      * @throws PropertyVetoException if the recipient wishes the     *         property change to be rolled back.     */    public void fireVetoableChange(String name, Object oldValue, Object newValue)            throws PropertyVetoException {        beanContextChildSupport.fireVetoableChange(name, oldValue, newValue);    }}

⌨️ 快捷键说明

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