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

📄 layerhandler.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        if (bc != null && layer.getAddToBeanContext()) {            bc.add(layer);        }        setLayers(newLayers);    }    /**     * Add a layer to a certain position in the layer array. If the     * position is 0 or less, the layer is put up front (on top). If     * the position is greater thatn the length of the current array,     * the layer is put at the end, (on the bottom).     *      * @param layer the layer to add.     * @param position the array index to place it.     * @param addedLayerTurnedOn turn the layer on.     * @deprecated the layer will be turned on if its visibility is     *             true.     */    public void addLayer(Layer layer, int position, boolean addedLayerTurnedOn) {        layer.setVisible(addedLayerTurnedOn);        addLayer(layer, position);    }    /**     * Remove a layer from the list of potentials.     *      * @param layer to remove.     */    public void removeLayer(Layer layer) {        if (layer != null && layer.isRemovable()) {            int index = -1;            for (int i = 0; i < allLayers.length; i++) {                if (layer == allLayers[i]) {                    index = i;                    break;                }            }            // If the layer is actually there...            if (index != -1) {                removeLayer(allLayers, index);            }        } else {            if (layer != null) {                Debug.error("LayerHandler: received command to remove "                        + layer.getName()                        + ", which has been designated as *NOT* removeable");                throw new com.bbn.openmap.util.HandleError("LayerHandler commanded to delete a layer ("                        + layer.getName() + ") that is not removeable");            }        }    }    /**     * Remove a layer from the list of potentials.     *      * @param index of layer in the layer array. Top-most is first.     */    public void removeLayer(int index) {        if (index >= 0 && index < allLayers.length) {            removeLayer(allLayers, index);        }    }    public boolean hasLayer(Layer l) {        Layer[] layers = allLayers;        for (int i = 0; i < layers.length; i++) {            if (layers[i] == l) {                return true;            }        }        return false;    }    /**     * Remove all the layers (that are marked as removeable).     */    public void removeAll() {        BeanContext bc = getBeanContext();        Layer[] oldLayers = allLayers;        Vector nonRemoveableLayers = null;        for (int i = 0; i < oldLayers.length; i++) {            Layer layer = oldLayers[i];            if (layer.isRemovable()) {                turnLayerOn(false, layer);                layer.clearListeners();                if (bc != null) {                    // Remove the layer from the BeanContext                    bc.remove(layer);                }                oldLayers[i] = null;            } else {                if (nonRemoveableLayers == null) {                    nonRemoveableLayers = new Vector(oldLayers.length);                }                nonRemoveableLayers.add(layer);            }        }        if (nonRemoveableLayers != null) {            allLayers = new Layer[nonRemoveableLayers.size()];            allLayers = (Layer[]) nonRemoveableLayers.toArray(allLayers);        } else {            allLayers = new Layer[0];        }        setLayers(allLayers);        // I know this is bad but it seems to work, forcing the        // memory from old, deleted layers to be freed. With such a        // drastic method call as removeAll, this should be OK.        System.gc();    }    /**     * The version that does the work. The other two functions do     * sanity checks. Calls setLayers(), and removes the layer from     * the BeanContext.     *      * @param currentLayers the current layers handled in the     *        LayersMenu.     * @param index the validated index of the layer to remove.     */    protected void removeLayer(Layer[] currentLayers, int index) {        Layer rLayer = currentLayers[index];        if (!rLayer.isRemovable()) {            Debug.error("LayerHandler: received command to remove "                    + rLayer.getName()                    + ", which has been designated as *NOT* removeable");            return;        }        rLayer.setVisible(false);        Layer[] newLayers = new Layer[currentLayers.length - 1];        System.arraycopy(currentLayers, 0, newLayers, 0, index);        System.arraycopy(currentLayers,                index + 1,                newLayers,                index,                currentLayers.length - index - 1);        // Remove the layer to the BeanContext, if it wants to be.        BeanContext bc = getBeanContext();        if (bc != null) {            bc.remove(rLayer);        }        turnLayerOn(false, rLayer);        rLayer.clearListeners();        rLayer = null;        // Shouldn't call this, but it's the only thing that seems to        // make it work...        if (Debug.debugging("helpgc")) {            System.gc();        }        setLayers(newLayers);    }    /**     * Take a layer that the LayersMenu knows about, that may or may     * not be a part of the map, and change its visibility by     * adding/removing it from the MapBean.     *      * @param setting true to add layer to the map.     * @param index the index of the layer to turn on/off.     * @return true of index represented a layer, false if not or if     *         something went wrong.     */    public boolean turnLayerOn(boolean setting, int index) {        try {            turnLayerOn(setting, allLayers[index]);            return true;        } catch (ArrayIndexOutOfBoundsException aoobe) {            // Do nothing...        } catch (NullPointerException npe) {            // Do nothing...        }        return false;    }    /**     * Take a layer that the LayersMenu knows about, that may or may     * not be a part of the map, and change its visibility by     * adding/removing it from the MapBean. If the layer is not found,     * it's added and the visibility depends on the setting parameter.     *      * @param setting true to add layer to the map.     * @param layer the layer to turn on.     * @return true if the layer was found, false if not or if     *         something went wrong.     */    public boolean turnLayerOn(boolean setting, Layer layer) {        if ((setting && !layer.isVisible()) || (!setting && layer.isVisible())) {            if (Debug.debugging("layerhandler")) {                Debug.output("LayerHandler: turning " + layer.getName()                        + (setting ? " on" : " off"));            }            layer.setVisible(setting);            getListeners().pushLayerEvent(LayerEvent.REPLACE, getMapLayers());            return true;        }        return false;    }    /**     * Called from childrenAdded(), when a new component is added to     * the BeanContext, and from setBeanContext() when the     * LayerHandler is initially added to the BeanContext. This method     * takes the iterator provided when those methods are called, and     * looks for the objects that the LayerHandler is interested in,     * namely, the MapBean, the PropertyHandler, or any other     * LayerListeners. The LayerHandler handles multiple     * LayerListeners, and if one is found, it is added to the     * LayerListener list. If a PropertyHandler is found, then init()     * is called, effectively resetting the layers held by the     * LayerHandler.     *      * @param someObj an Object being added to the MapHandler/BeanContext.     */    public void findAndInit(Object someObj) {        if (someObj instanceof com.bbn.openmap.event.LayerListener) {            Debug.message("layerhandler", "LayerHandler found a LayerListener.");            addLayerListener((LayerListener) someObj);        }        if (someObj instanceof Layer) {            if (Debug.debugging("layerhandler")) {                Debug.output("LayerHandler found a Layer |"                        + ((Layer) someObj).getName() + "|");            }            if (!hasLayer((Layer) someObj)) {                addLayer((Layer) someObj, 0);            }        }        if (someObj instanceof PropertyHandler) {            // Used to notify the PropertyHandler of used property            // prefix names.            setPropertyHandler((PropertyHandler) someObj);        }    }    /**     * A BeanContextMembershipListener interface method, which is     * called when new objects are removed from the BeanContext. If a     * LayerListener or Layer is found on this list, it is removed     * from the list of LayerListeners.     *      * @param someObj an Object being removed from the MapHandler/BeanContext.     */    public void findAndUndo(Object someObj) {        if (someObj instanceof com.bbn.openmap.event.LayerListener) {            Debug.message("layerhandler",                    "LayerListener object is being removed");            removeLayerListener((LayerListener) someObj);        }        if (someObj instanceof Layer) {            removeLayer((Layer) someObj);        }        if (someObj instanceof PropertyHandler                && someObj == getPropertyHandler()) {            setPropertyHandler(null);        }    }    /**     * Add layers to the BeanContext, if they want to be. Since the     * BeanContext is a Collection, it doesn't matter if a layer is     * already there because duplicates aren't allowed.     *      * @param layers layers to add, if they want to be.     */    public void addLayersToBeanContext(Layer[] layers) {        BeanContext bc = getBeanContext();        if (bc == null || layers == null) {            return;        }        for (int i = 0; i < layers.length; i++) {            if (layers[i].getAddToBeanContext()) {                bc.add(layers[i]);            }        }    }    /**     * Called when the LayerHandler is added to a BeanContext. This     * method calls findAndInit() to hook up with any objects that may     * already be added to the BeanContext. A BeanContextChild method.     *      * @param in_bc BeanContext.     */    public void setBeanContext(BeanContext in_bc) throws PropertyVetoException {        if (in_bc != null) {            if (Debug.debugging("layerhandler")) {                Debug.output("LayerHandler.setBeanContext()");            }            in_bc.addBeanContextMembershipListener(this);            beanContextChildSupport.setBeanContext(in_bc);            // findAndInit should be called after the layers and            // plugins are added to the MapHandler, so they can find            // the components they need before they get added to the            // map (if they are to be added at startup).            addLayersToBeanContext(getLayers());            // Calling this here may (will) cause the MapBean to get            // loaded with its initial layers, since it is a            // LayerListener.            findAndInit(in_bc.iterator());        }    }    public void setSynchronousThreading(boolean s) {        getListeners().setSynchronous(s);    }    public boolean isSynchronousThreading() {        return getListeners().isSynchronous();    }    public Properties getProperties(Properties props) {        props = super.getProperties(props);        props.put(PropUtils.getScopedPropertyPrefix(this)                + SynchronousThreadingProperty,                Boolean.toString(getListeners().isSynchronous()));        return props;    }    public Properties getPropertyInfo(Properties props) {        props = super.getPropertyInfo(props);        String internString = i18n.get(LayerHandler.class,                SynchronousThreadingProperty,                I18n.TOOLTIP,                "Launch new threads to do work.");        props.put(SynchronousThreadingProperty, internString);        internString = i18n.get(LayerHandler.class,                SynchronousThreadingProperty,                "Synchronous Threading");        props.put(SynchronousThreadingProperty + LabelEditorProperty,                internString);        props.put(SynchronousThreadingProperty + EditorProperty,                "com.bbn.openmap.util.propertyEditor.YesNoPropertyEditor");        return props;    }}

⌨️ 快捷键说明

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