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

📄 propertyhandler.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        String layerMarkerStringKey = Environment.OpenMapPrefix + "."                + LayerHandler.layersProperty;        StringBuffer layerMarkerString = new StringBuffer(layerMarkerStringKey                + "=");        String startUpLayerMarkerStringKey = Environment.OpenMapPrefix + "."                + LayerHandler.startUpLayersProperty;        StringBuffer startUpLayerMarkerString = new StringBuffer(startUpLayerMarkerStringKey                + "=");        StringBuffer layerPropertiesString = new StringBuffer();        Properties layerProperties = new Properties();        Layer[] layers = layerHandler.getLayers();        int numLayers = 0;        for (int i = 0; i < layers.length; i++) {            markerName = layers[i].getPropertyPrefix();            if (markerName == null) {                markerName = "layer" + (numLayers++);                layers[i].setPropertyPrefix(markerName);            }            if (ph != null) {                // Gets the properties for the prefix that the                // property handler was set with. This should                // handle components that aren't good                // PropertyConsumers.                layerProperties = ph.getProperties(markerName);            } else {                layerProperties.clear();            }            layerMarkerString.append(" " + markerName);            if (layers[i].isVisible()) {                startUpLayerMarkerString.append(" " + markerName);            }            layers[i].getProperties(layerProperties);            layerPropertiesString.append("### -" + markerName                    + "- layer properties\n");            TreeMap orderedProperties = new TreeMap(layerProperties);            for (Iterator keys = orderedProperties.keySet().iterator(); keys.hasNext();) {                String key = (String) keys.next();                // Could add .replace("\\", "/") to the end of this                // line to prevent \\ from appearing in the properties                // file.                String value = layerProperties.getProperty(key);                if (value != null) {                    layerPropertiesString.append(key + "=" + value + "\n");                }                if (createdProperties != null && value != null) {                    createdProperties.put(key, value);                }            }            layerPropertiesString.append("### end of -" + markerName                    + "- properties\n\n");        }        if (ps != null) {            ps.println("\n### OpenMap Layers ###");            ps.println(layerMarkerString.toString());            ps.println(startUpLayerMarkerString.toString());            ps.println(layerPropertiesString.toString());        }        if (createdProperties != null) {            createdProperties.put(layerMarkerStringKey,                    layerMarkerString.substring(layerMarkerStringKey.length() + 1));            createdProperties.put(startUpLayerMarkerStringKey,                    startUpLayerMarkerString.substring(startUpLayerMarkerStringKey.length() + 1));        }    }    /**     * Given a MapHandler and a Java Properties object, the     * LayerHandler will be cleared of it's current layers, and     * reloaded with the layers in the properties. The MapBean will be     * set to the projection settings listed in the properties.     */    public void loadProjectionAndLayers(MapHandler mapHandler, Properties props) {        MapBean mapBean = (MapBean) mapHandler.get("com.bbn.openmap.MapBean");        LayerHandler layerHandler = (LayerHandler) mapHandler.get("com.bbn.openmap.LayerHandler");        // InformationDelegator id = (InformationDelegator)        // mapHandler.get("com.bbn.openmap.InformationDelegator");        // if (id != null) {        // id.requestCursor(new Cursor(Cursor.WAIT_CURSOR));        // }        if (layerHandler != null) {            layerHandler.removeAll();            layerHandler.init(Environment.OpenMapPrefix, props);        } else {            Debug.error("Can't load new layers - can't find LayerHandler");        }        if (mapBean != null) {            mapBean.setProjection(ProjectionFactory.getDefaultProjectionFromEnvironment(mapBean.getWidth(),                    mapBean.getHeight()));        } else {            Debug.error("Can't load new projection - can't find MapBean");        }        // if (id != null) {        // id.requestCursor(null);        // }    }    /**     * If you are creating a new object, it's important to get a     * unique prefix for its properties. This function takes a prefix     * string and checks it against all others it knows about. If     * there is a conflict, it adds a number to the end until it     * becomes unique. This prefix will be logged by the     * PropertyHandler as a name given out, so duplicate instances of     * that string will not be given out later. It doesn't, however,     * log that name in the prefixLibrarian. That only occurs when the     * object is programmatically registered with the prefixLibrarian     * or when the PropertyHandler finds that object in the MapHandler     * (and even then that object must be a PropertyConsumer to be     * registered this way).     */    public String getUniquePrefix(String prefix) {        prefix = prefix.replace(' ', '_');        if (!addUsedPrefix(prefix)) {            int count = 2;            String nextTry = prefix + (count);            while (!addUsedPrefix(nextTry)) {                nextTry = prefix + (++count);            }            return nextTry;        } else {            return prefix;        }    }    /**     * Changes ' ' characters to '_', and then tries to add it to the     * used prefix list. Returns true if successful.     */    public boolean addUsedPrefix(String prefix) {        prefix = prefix.replace(' ', '_');        return usedPrefixes.add(prefix.intern());    }    /**     * Changes ' ' characters to '_', and then tries to remove it to     * the used prefix list. Returns true if successful.     */    public boolean removeUsedPrefix(String prefix) {        prefix = prefix.replace(' ', '_');        return usedPrefixes.remove(prefix.intern());    }    /**     * Add a ProgressListener that will display build progress.     */    public void addProgressListener(ProgressListener list) {        getProgressSupport().addProgressListener(list);    }    /**     * Remove a ProgressListener that displayed build progress.     */    public void removeProgressListener(ProgressListener list) {        getProgressSupport().removeProgressListener(list);    }    /**     * Clear all progress listeners.     */    public void clearProgressListeners() {        getProgressSupport().removeAll();    }    /**     * Get progress support if needed.     */    protected ProgressSupport getProgressSupport() {        if (progressSupport == null) {            progressSupport = new ProgressSupport(this);        }        return progressSupport;    }    /**     * Fire an build update to progress listeners.     *      * @param frameNumber the current frame count     * @param totalFrames the total number of frames.     */    protected void fireProgressUpdate(int type, String task, int frameNumber,                                      int totalFrames) {        if (updateProgress) {            getProgressSupport().fireUpdate(type,                    task,                    totalFrames,                    frameNumber);        } else if (type == ProgressEvent.DONE) {            // At least turn off progress listeners if they are up.            getProgressSupport().fireUpdate(ProgressEvent.DONE,                    task,                    totalFrames,                    frameNumber);        }    }    /**     * Set a flag that will trigger the PropertyHandler to fire     * progress events when it is going through the creation process.     */    public void setUpdateProgress(boolean set) {        updateProgress = set;    }    public boolean getUpdateProgress() {        return updateProgress;    }    // Property Functions:    // ///////////////////    /**     * Remove an existing property if it exists.     *      * @return true if a property was actually removed.     */    public boolean removeProperty(String property) {        return getProperties().remove(property) != null;    }    /**     * Add (or overwrite) a property to the current properties     */    public void addProperty(String property, String value) {        getProperties().setProperty(property, value);    }    /**     * Add in the properties from the given URL. Any existing     * properties will be overwritten except for openmap.components,     * openmap.layers and openmap.startUpLayers which will be     * appended.     */    public void addProperties(URL urlToProperties) {        addProperties(fetchProperties(urlToProperties));    }    /**     * Add in the properties from the given source, which can be a     * resorce, file or URL. Any existing properties will be     * overwritten except for openmap.components, openmap.layers and     * openmap.startUpLayers which will be appended.     *      * @throws MalformedURLException if propFile doesn't resolve     *         properly.     */    public void addProperties(String propFile) throws MalformedURLException {        addProperties(fetchProperties(PropUtils.getResourceOrFileOrURL(propFile)));    }    /**     * Add in the properties from the given Properties object. Any     * existing properties will be overwritten except for     * openmap.components, openmap.layers and openmap.startUpLayers     * where values will be prepended to any existing lists.     */    public void addProperties(Properties p) {        String[] specialProps = new String[] {                Environment.OpenMapPrefix + "." + LayerHandler.layersProperty,                Environment.OpenMapPrefix + "."                        + LayerHandler.startUpLayersProperty, componentProperty };        Properties tmp = new Properties();        tmp.putAll(p);        for (int i = 0; i < specialProps.length; i++) {            prependProperty(specialProps[i], tmp);            tmp.remove(specialProps[i]);        }        getProperties().putAll(tmp);    }    /**     * remove a marker from a space delimated set of properties.     */    public void removeMarker(String property, String marker) {        // Requires jdk 1.4        // StringBuffer sb =        // new StringBuffer(getProperties().getProperty(property,        // ""));        // int idx = sb.indexOf(marker);        // jdk 1.3 version        String propertyString = getProperties().getProperty(property, "");        int idx = propertyString.indexOf(marker);        if (idx != -1) {            StringBuffer sb = new StringBuffer(propertyString);            sb.delete(idx, idx + marker.length());            getProperties().setProperty(property, sb.toString());        }    }    /**     * Append the given property into the current properties     */    public void appendProperty(String property, Properties src) {        appendProperty(property, src.getProperty(property, ""));    }    /**     * Append the given property into the current properties     */    public void appendProperty(String property, String value) {        String curVal = getProperties().getProperty(property, "");        getProperties().setProperty(property, curVal + " " + value);    }    /**     * Prepend the given property into the current properties     */    public void prependProperty(String property, Properties src) {        prependProperty(property, src.getProperty(property, ""));    }    /**     * Prepend the given property into the current properties     */    public void prependProperty(String property, String value) {        String curVal = getProperties().getProperty(property, "");        getProperties().setProperty(property, value + " " + curVal);    }    /**     * Load a Properties object from the classpath. The method always     * returns a <code>Properties</code> object. If there was an     * error loading the properties from <code>propsURL</code>, an     * empty <code>Properties</code> object is returned.     *      * @param propsURL the URL of the properties to be loaded     * @return the loaded properties, or an empty Properties object if     *         there was an error.     */    public static Properties fetchProperties(URL propsURL) {        if (Debug.debugging("properties")) {            Debug.output("PropertyHandler.getProperties(" + propsURL + ")");        }        Properties p = new Properties();        if (propsURL != null) {            try {                InputStream is = propsURL.openStream();                p.load(is);                is.close();            } catch (IOException e) {                Debug.error("PropertyHandler.getProperties(): "                        + "Exception reading map properties at " + propsURL                        + ": " + e);            }        }        return p;    }    /**     * All the PropertyHandler does with the MapHandler is look for     * PropertyConsumers and register their prefixes with the     * prefixLibarian.     */    public void findAndInit(Object obj) {        if (obj instanceof PropertyConsumer) {            String prefix = ((PropertyConsumer) obj).getPropertyPrefix();            if (prefix != null) {                getPrefixLibrarian().put(prefix, obj);            }        }    }    public void findAndUndo(Object obj) {        if (obj instanceof PropertyConsumer) {            String prefix = ((PropertyConsumer) obj).getPropertyPrefix();            if (prefix != null) {                getPrefixLibrarian().remove(prefix);            }        }    }}

⌨️ 快捷键说明

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