📄 layerhandler.java
字号:
// **********************************************************************// // <copyright>// // BBN Technologies// 10 Moulton Street// Cambridge, MA 02138// (617) 873-8000// // Copyright (C) BBNT Solutions LLC. All rights reserved.// // </copyright>// **********************************************************************// // $Source: /cvs/distapps/openmap/src/openmap/com/bbn/openmap/LayerHandler.java,v $// $RCSfile: LayerHandler.java,v $// $Revision: 1.7.2.7 $// $Date: 2005/08/11 21:03:12 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap;import java.beans.PropertyVetoException;import java.beans.beancontext.BeanContext;import java.io.Serializable;import java.util.Properties;import java.util.Vector;import com.bbn.openmap.event.LayerEvent;import com.bbn.openmap.event.LayerListener;import com.bbn.openmap.event.LayerSupport;import com.bbn.openmap.plugin.PlugIn;import com.bbn.openmap.plugin.PlugInLayer;import com.bbn.openmap.util.ComponentFactory;import com.bbn.openmap.util.Debug;import com.bbn.openmap.util.PropUtils;/** * The LayerHandler is a component that keeps track of all Layers for * the MapBean, whether or not they are currently part of the map or * not. It is able to dynamically add and remove layers from the list * of available layers. Whether a layer is added to the MapBean * depends on the visibility setting of the layer. If * Layer.isVisible() is true, the layer will be added to the MapBean. * There are methods within the LayerHandler that let you change the * visibility setting of a layer. * <P> * * The LayerHandler is able to take a Properties object, and create * layers that are defined within it. The key property is "layers", * which may or may not have a prefix for it. If that property does * have a prefix (prefix.layers, i.e. openmap.layers), then that * prefix has to be known and passed in to the contructor or init * method. This layers property should fit the general openmap marker * list paradigm, where the marker names are listed in a space * separated list, and then each marker name is used as a prefix for * the properties for a particular layer. As a minimum, each layer * needs to have the class and prettyName properties defined. The * class property should define the class name to use for the layer, * and the prettyName property needs to be a name for the layer to be * used in the GUI. Any other property that the particular layer can * use should be listed in the Properties, with the applicable marker * name as a prefix. Each layer should have its available properties * defined in its documentation. For example: * <P> * * <pre> * * * * * * * * * * * * * * * openmap.layers=marker1 marker2 (etc) * marker1.class=com.bbn.openmap.layer.GraticuleLayer * marker1.prettyName=Graticule Layer * # false is default * marker1.addToBeanContext=false * * marker2.class=com.bbn.openmap.layer.shape.ShapeLayer * marker2.prettyName=Political Boundaries * marker2.shapeFile=pathToShapeFile * marker2.spatialIndex=pathToSpatialIndexFile * marker2.lineColor=FFFFFFFF * marker2.fillColor=FFFF0000 * * * * * * * * * * * * * * * </pre> * * <P> * * The LayerHandler is a SoloMapComponent, which means that for a * particular map, there should only be one of them. When a * LayerHandler is added to a BeanContext, it will look for a MapBean * to connect to itself as a LayerListener so that the MapBean will * receive LayerEvents - this is the mechanism that adds and removes * layers on the map. If more than one MapBean is added to the * BeanContext, then the last MapBean added will be added as a * LayerListener, with any prior MapBeans added as a LayerListener * removed from the LayerHandler. The MapHandler controls the behavior * of multiple SoloMapComponent addition to the BeanContext. */public class LayerHandler extends OMComponent implements SoloMapComponent, Serializable { /** * Property for space separated layers. If a prefix is needed, * just use the methods that let you use the prefix - don't worry * about the period, it will be added automatically. */ public static final String layersProperty = "layers"; /** * Property for space separated layers to be displayed at startup. * If a prefix is needed, just use the methods that let you use * the prefix - don't worry about the period, it will be added * automatically. */ public static final String startUpLayersProperty = "startUpLayers"; /** * Flag to set synchronous threading on the LayerHandler, telling * it to react to layer order changes and layer visibility * requests within the calling thread. By default, this action is * true. Setting it to false may eliminate pauses in GUI reactions * by offloading work done by layers being added to the MapBean, * but there have been reports that the asynchronous nature of the * threading queue may be causing an unexpected state in layer * order and/or availability under certain intense layer * management conditions (created by automated processes, for * example). */ public static final String SynchronousThreadingProperty = "synchronousThreading"; /** * The object holding on to all LayerListeners interested in the * layer arrangement and availability. Not expected to be null. */ protected transient LayerSupport listeners = new LayerSupport(this); /** * The list of all layers, even the ones that are not part of the * map. */ protected Layer[] allLayers = new Layer[0]; /** * This handle is only here to keep it appraised of layer prefix * names. */ protected PropertyHandler propertyHandler; /** * If you use this constructor, the LayerHandler expects that the * layers will be created and added later, either by addLayer() or * init(). */ public LayerHandler() {} /** * Start the LayerHandler, and have it create all the layers as * defined in a properties file. * * @param props properties as defined in an openmap.properties * file. */ public LayerHandler(Properties props) { init(null, props); } /** * Start the LayerHandler, and have it create all the layers as * defined in a properties file. * * @param prefix the prefix for the layers and startUpLayers * properties, as if they are listed as prefix.layers, and * prefix.startUpLayers. * @param props properties as defined in an openmap.propertites * file. */ public LayerHandler(String prefix, Properties props) { init(prefix, props); } /** * Start the LayerHandler with configured layers. */ public LayerHandler(Layer[] layers) { init(layers); } /** * Extension of the OMComponent. If the LayerHandler is created by * the ComponentFactory (via the PropertyHandler), this method * will be called automatically. For the OpenMap applications, * this method is rigged to handle the openmap.layers property by * calling init("openmap", props). If you are using the * LayerHandler in a different setting, then you might want to * just call init() directly, or extend this class and have * setProperties do what you want. */ public void setProperties(String prefix, Properties props) { init(Environment.OpenMapPrefix, props); } /** * Initialize the LayerHandler by having it construct it's layers * from a properties object. The properties should be created from * an openmap.properties file. * * @param prefix the prefix to use for the layers and * startUpLayers properties. * @param props properties as defined in an openmap.properties * file. */ public void init(String prefix, Properties props) { init(getLayers(prefix, props)); getListeners().setSynchronous(PropUtils.booleanFromProperties(props, PropUtils.getScopedPropertyPrefix(prefix) + SynchronousThreadingProperty, getListeners().isSynchronous())); } /** * Initialize the LayerHandler by having it construct it's layers * from a URL containing an openmap.properties file. * * @param url a url for a properties file. */ public void init(java.net.URL url) { init(null, url); } /** * Initialize the LayerHandler by having it construct it's layers * from a URL containing an openmap.properties file. * * @param prefix the prefix to use for the layers and * startUpLayers properties. * @param url a url for a properties file. */ public void init(String prefix, java.net.URL url) { try { java.io.InputStream in = url.openStream(); Properties props = new Properties(); props.load(in); init(getLayers(prefix, props)); } catch (java.net.MalformedURLException murle) { Debug.error("LayerHandler.init(URL): " + url + " is not a valid URL"); } catch (java.io.IOException e) { Debug.error("LayerHandler.init(URL): Caught an IOException"); } } /** * Initialize from an array of layers. This will cause the * LayerListeners, if they exist, to update themselves with the * current list of layers. * * @param layers the initial array of layers. */ public void init(Layer[] layers) { setLayers(layers); } public void setPropertyHandler(PropertyHandler ph) { propertyHandler = ph; } public PropertyHandler getPropertyHandler() { return propertyHandler; } /** * This is the method that gets used to parse the layer properties * from an openmap.properties file, where the layer marker names * are listed under a layers property, and each layer is then * represented by a marker.class property, and a maker.prettyName * property. * * @param p properties containing layers property, the * startupLayers property listing the layers to make * visible immediately, and the layer properties as well. * @return Layer[] of layers created from the properties. */ protected Layer[] getLayers(Properties p) { return getLayers(null, p); } /** * This is the method that gets used to parse the layer properties * from an openmap.properties file, where the layer marker names * are listed under a prefix.layers property, and each layer is * then represented by a marker.class property, and a * maker.prettyName property. * * @param prefix the prefix to use to use for the layer list * (layers) property and the startUpLayers property. If it * is not null, this will cause the method to looke for * prefix.layers and prefix.startUpLayers. * @param p the properties to build the layers from. * @return Layer[] */ protected Layer[] getLayers(String prefix, Properties p) { Debug.message("layerhandler", "LayerHandler: Getting new layers from properties..."); // First, load the layer marker names into a vector for later // use Vector startuplayers; Vector layersValue; prefix = PropUtils.getScopedPropertyPrefix(prefix); startuplayers = PropUtils.parseSpacedMarkers(p.getProperty(prefix + startUpLayersProperty)); layersValue = PropUtils.parseSpacedMarkers(p.getProperty(prefix + layersProperty)); if (startuplayers.isEmpty()) { Debug.message("layerhandler", "LayerHandler: No layers on startup list"); } if (layersValue.isEmpty()) { Debug.error("LayerHandler.getLayers(): No property \"" + layersProperty + "\" found in properties."); return new Layer[0]; } else { if (Debug.debugging("layerhandler")) { Debug.output("LayerHandler: Layer markers found = " + layersValue); } } Layer[] layers = getLayers(layersValue, startuplayers, p); // You don't want to do this, it sets up a cycle... // addLayersToBeanContext(layers); // loadLayers(null); return layers;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -