propertyhandler.java
来自「OpenMap是一个基于JavaBeansTM的开发工具包。利用OpenMap你」· Java 代码 · 共 1,648 行 · 第 1/5 页
JAVA
1,648 行
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; String componentProperty = ph.getPropertyPrefix() + PropertyHandler.componentProperty; StringBuffer componentMarkerString = new StringBuffer(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(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; 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"); }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?