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

📄 propertyhandler.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
            }        }        Vector componentList = PropUtils.parseSpacedMarkers(properties.getProperty(componentProperty));        if (Debug.debugging("propertiesdetail")) {            Debug.output("PropertyHandler: creating components from "                    + componentList);        }        fireProgressUpdate(ProgressEvent.START,                "OpenMap - Creating Components",                0,                100);        Vector components = ComponentFactory.create(componentList,                properties,                (updateProgress ? getProgressSupport() : null),                true);        size = components.size();        for (i = 0; i < size; i++) {            Object obj = (Object) components.elementAt(i);            try {                if (obj instanceof String) {                    Debug.error("PropertyHandler finding out that the " + obj                            + " wasn't created");                    continue;                }                mapHandler.add(obj);                String markerName = ((String) componentList.elementAt(i)).intern();                prefixLibrarian.put(markerName, obj);                addUsedPrefix(markerName);            } catch (MultipleSoloMapComponentException msmce) {                Debug.error("PropertyHandler.createComponents(): "                        + "tried to add multiple components of the same "                        + "type when only one is allowed! - " + msmce);            }        }        fireProgressUpdate(ProgressEvent.DONE,                "Created all components, ready...",                size,                size);        removeProgressListener(plg);    }    /**     * Creates a Properties object containing the current settings as     * defined by OpenMap components held by the MapHandler. If the     * MapHandler contains a PropertyHandler, that property handler     * will be consulted for properties for different objects in case     * those objects don't know how to provide their settings     * correctly.     *      * @param mapHandler MapHandler containing components to use for     *        Properties.     * @param ps PrintStream to write properties to, may be null if     *        you just want the Properties object that is returned.     * @return Properties object containing everything written (or     *         that would have been written, if the PrintStream is     *         null) to PrintStream.     */    public static Properties createOpenMapProperties(MapHandler mapHandler,                                                     PrintStream ps) {        Properties createdProperties = new Properties();        // First, get all the components in the MapHandler. Create        // the openmap.components list, with the .class properties        // listing all the class names. Ignore the layers for now,        // and if the class is a PropertyConsumer, get its properties        // too.        if (mapHandler == null) {            Debug.error("PropertyHandler.createOpenMapProperties: can't create properties with null MapHandler");            return null;        }        Iterator it = mapHandler.iterator();        Object someObj;        Debug.message("properties",                "PropertyHandler: Looking for Objects in mapHandler");        MapBean mapBean = null;        LayerHandler layerHandler = null;        PropertyHandler propertyHandler = null;        InformationDelegator infoDelegator = null;        Vector otherComponents = new Vector();        while (it.hasNext()) {            someObj = it.next();            Debug.message("properties", "PropertyHandler found "                    + someObj.getClass().getName());            if (someObj instanceof MapBean) {                mapBean = (MapBean) someObj;            } else if (someObj instanceof LayerHandler) {                layerHandler = (LayerHandler) someObj;            } else if (someObj instanceof Layer || someObj instanceof PlugIn) {                // do nothing, layerhandler will handle            } else if (someObj instanceof PropertyHandler) {                propertyHandler = (PropertyHandler) someObj;                if (infoDelegator != null) {                    propertyHandler.addProgressListener(infoDelegator);                }            } else if (someObj instanceof InformationDelegator) {                infoDelegator = (InformationDelegator) someObj;                if (propertyHandler != null) {                    propertyHandler.addProgressListener((ProgressListener) someObj);                }            } else {                // Add the rest to a component vector thingy.                otherComponents.add(someObj);            }        }        // if the MapBean and/or the LayerHandler are null, what's the        // point?        if (mapBean == null || layerHandler == null) {            Debug.error("PropertyHandler: no MapBean(" + mapBean                    + ") or LayerHandler(" + layerHandler                    + ") to use to write properties");            return null;        }        // First, print the Map parameters...        ps.println("######  OpenMap properties file ######");        ps.println("## Refer to original openmap.properties file\n## for instructions on how to modify this file.");        ps.println("######################################");        printMapProperties(mapBean, ps, createdProperties);        printComponentProperties(otherComponents,                propertyHandler,                ps,                createdProperties);        printLayerProperties(layerHandler,                propertyHandler,                ps,                createdProperties);        if (Debug.debugging("properties") && createdProperties != null) {            System.out.println(createdProperties);        }        return createdProperties;    }    /**     * A simple helper method that writes key-value pairs to a print     * stream or Properties, whatever is not null.     */    protected static void printProperties(String key, String value,                                          PrintStream ps,                                          Properties createdProperties) {        if (ps != null) {            ps.println(key + "=" + value);        }        if (createdProperties != null) {            createdProperties.put(key, value);        }    }    /**     * A helper function to createOpenMapProperties that gets the     * current properties of the MapBean and prints them out to the     * PrintStream and the provided Properties object.     *      * @param mapBean MapBean to get parameters from.     * @param ps PrintStream to write properties to, may be null.     * @param createdProperties Properties object to store properties     *        in, may be null.     */    protected static void printMapProperties(MapBean mapBean, PrintStream ps,                                             Properties createdProperties) {        // warning...hackish...        com.bbn.openmap.proj.Proj proj = mapBean.projection;        ps.println("\n### OpenMap initial Map Settings ###");        LatLonPoint llp = proj.getCenter();        printProperties(Environment.Latitude,                Float.toString(llp.getLatitude()),                ps,                createdProperties);        printProperties(Environment.Longitude,                Float.toString(llp.getLongitude()),                ps,                createdProperties);        printProperties(Environment.Scale,                Float.toString(proj.getScale()),                ps,                createdProperties);        printProperties(Environment.Projection,                proj.getName(),                ps,                createdProperties);        printProperties(Environment.BackgroundColor,                Integer.toHexString(mapBean.getBackground().getRGB()),                ps,                createdProperties);        // Height and Width are in the OpenMapFrame properties, or        // whatever other component contains everything.    }    /**     * A helper function to createOpenMapProperties that gets the     * current properties of the given components and prints them out     * to the PrintStream and the provided Properties object.     *      * @param components Vector of components to get parameters from.     * @param ph PropertyHandler that may have properties to use as a     *        foundation for the properties for the components. If the     *        component can't provide properties reflecting its     *        settings, the property handler will be consulted for     *        properties it knows about for that component.     * @param ps PrintStream to write properties to, may be null.     * @param createdProperties Properties object to store properties     *        in, may be null.     */    protected static void printComponentProperties(Vector components,                                                   PropertyHandler ph,                                                   PrintStream ps,                                                   Properties createdProperties) {        // this section looks at the components and trys to create        // the openmap.components list and then write out all the        // properties for them.        // Since order is important to the look of the application, we        // need to do work here to maintain the current loaded order        // of the application components. Until then, just swipe the        // openmap.components property to get the list of current        // components.        boolean buildConfiguredApplication = true;        boolean componentListBuilt = false;        Object someObj;        int numComponents = 0;        String markerName;        StringBuffer componentMarkerString = new StringBuffer(PropertyHandler.componentProperty                + "=");        StringBuffer componentPropsString = new StringBuffer();        if (ph != null && buildConfiguredApplication) {            Properties phProps = ph.getProperties();            // Ahh, phProps'l never be null, right?            // Let's build them from the current properties file.            componentMarkerString.append(phProps.getProperty(PropertyHandler.componentProperty));            Vector componentList = PropUtils.parseSpacedMarkers(phProps.getProperty(componentProperty));            for (int i = 0; i < componentList.size(); i++) {                String markerNameClass = (String) componentList.elementAt(i)                        + ".class";                componentPropsString.append(markerNameClass + "="                        + phProps.get(markerNameClass) + "\n");                if (createdProperties != null) {                    createdProperties.put(markerNameClass,                            phProps.get(markerNameClass));                }            }            componentListBuilt = true;        }        // We're still going through the objects, but only adding the        // .class properties if the list wasn't built above.        // Otherwise, the components will be checked to see of they        // are PropertyConsumers, in order to get their properties        // written to the file.        Properties componentProperties = new Properties();        Enumeration comps = components.elements();        while (comps.hasMoreElements()) {            someObj = comps.nextElement();            if (someObj instanceof PropertyConsumer) {                Debug.message("properties", "Getting Property Info for"                        + someObj.getClass().getName());                PropertyConsumer pc = (PropertyConsumer) someObj;                componentProperties.clear();                markerName = pc.getPropertyPrefix();                if (ph != null && markerName != null                        && !markerName.equals("openmap")) {                    // Gets the properties for the prefix that the                    // property handler was set with. This should                    // handle components that aren't good                    // PropertyConsumers.                    componentProperties = ph.getProperties(markerName);                } else {                    componentProperties.clear();                }                if (!componentListBuilt) {                    if (markerName != null) {                        componentMarkerString.append(" " + markerName);                    } else {                        markerName = "component" + (numComponents++);                        componentMarkerString.append(" " + markerName);                        pc.setPropertyPrefix(markerName);                    }                    componentPropsString.append(markerName + ".class="                            + someObj.getClass().getName() + "\n");                    if (createdProperties != null) {                        createdProperties.put(markerName, someObj.getClass()                                .getName());                    }                }                pc.getProperties(componentProperties);                TreeMap orderedProperties = new TreeMap(componentProperties);                if (componentProperties.size() > 0) {                    componentPropsString.append("####\n");                    for (Iterator keys = orderedProperties.keySet().iterator(); keys.hasNext();) {                        String key = (String) keys.next();                        String value = componentProperties.getProperty(key);                        if (value != null) {                            componentPropsString.append(key + "=" + value                                    + "\n");                        }                        if (createdProperties != null && value != null) {                            createdProperties.put(key, value);                        }                    }                }            } else if (!componentListBuilt) {                markerName = "component" + (numComponents++);                componentMarkerString.append(" " + markerName);                componentPropsString.append(markerName + ".class="                        + someObj.getClass().getName() + "\n");                if (createdProperties != null) {                    createdProperties.put(markerName, someObj.getClass()                            .getName());                }            }        }        if (ps != null) {            ps.println("\n\n### OpenMap Components ###");            ps.println(componentMarkerString.toString());            ps.println("\n### OpenMap Component Properties ###");            // list created, add the actual component properties            ps.println(componentPropsString.toString());            ps.println("### End Component Properties ###");        }        if (createdProperties != null) {            createdProperties.put(PropertyHandler.componentProperty,                    componentMarkerString.substring(PropertyHandler.componentProperty.length() + 1));        }    }    /**     * A helper function to createOpenMapProperties that gets the     * current properties of the layers in the LayerHandler and prints     * them out to the PrintStream and the provided Properties object.     *      * @param layerHandler LayerHandler to get layers from.     * @param ph PropertyHandler that may have properties to use as a     *        foundation for the properties for the components. If the     *        component can't provide properties reflecting its     *        settings, the property handler will be consulted for     *        properties it knows about for that component.     * @param ps PrintStream to write properties to, may be null.     * @param createdProperties Properties object to store properties     *        in, may be null.     */    protected static void printLayerProperties(LayerHandler layerHandler,                                               PropertyHandler ph,                                               PrintStream ps,                                               Properties createdProperties) {        // Keep track of the LayerHandler. Use it to get the layers,        // which can be used to get all the marker names for the        // openmap.layers property. The visible layers go to the        // openmap.startUpLayers property. Then, cycle through all        // the layers to get their properties, since they all are        // PropertyConsumers.        String markerName;

⌨️ 快捷键说明

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