📄 overviewmaphandler.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/gui/OverviewMapHandler.java,v $// $RCSfile: OverviewMapHandler.java,v $// $Revision: 1.11.2.1 $// $Date: 2004/10/14 18:26:54 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.gui;import com.bbn.openmap.*;import com.bbn.openmap.event.*;import com.bbn.openmap.layer.OverviewMapAreaLayer;import com.bbn.openmap.proj.*;import com.bbn.openmap.util.*;import java.awt.*;import java.awt.event.*;import java.beans.*;import java.io.Serializable;import java.net.URL;import java.util.*;import javax.swing.*;/** * The OverviewMapHandler contains a MapBean that contains a * projection that reflects another MapBean's projection. It manages * the two MapBeans and the differences in the projections betwen * them. The OverviewMapHandler can have a projection type independent * of that of the source MapBean (the MapBean that the * OverviewMapHandler's MapBean is paying attention to). It also * contains a scale factor, which is a multiplier to use against the * scale of the source MapBean's scale. * <P> * * The OverviewMapHandler MapBean can also be used to control the * source MapBean's projection center and scale. The source MapBean * just needs to be added to the OverviewMapHandler by * OverviewMapHandler.addControlledMap(MapBean). * <P> * * The OverviewMapHandler needs to be added to the source MapBean as a * ProjectionListener. Then, the overview MapBean can be added to the * ContentPane of a Component by calling * Component.setContentPane(OverviewMapHandler.getMap()); The * OverviewMapHandler Should also be added as a ComponentListener to * the Component. * <P> * * After the first projectionChanged() call is received, the * OverviewMapHandler knows about the source MapBean. Since the * OverviewMapHandler is a ComponentListener and will therefore find * out when it's parent is hidden, it will disengage and engage itself * from the source MapBean as it's visibility changes. * <P> * * To get the overview map to appear in the OpenMap application, add * the following properties to your openmap.properties file: * * <pre> * * * # First, add overviewMapHandler to the openmap.components marker name list. Then, add: * * overviewMapHandler.class=com.bbn.opemap.gui.OverviewMapHandler * overviewMapHandler.overviewLayers=overviewLayer * overviewMapHandler.overviewScaleFactor=10f * overviewMapHandler.overviewMinScale=10000000f * * # 'overviewStatusLayer' is a marker name for any attributes you may * # want to pass to the overviewStatusLayer instance, in addition to * # being used to define the class to use for that special layer. * overviewMapHandler.overviewStatusLayer.class=com.bbn.openmap.layer.OverviewMapAreaLayer * # Properties can be passed to the overview status layer by listing * # them with the OverviewMapHandler prefix. * * # Set the line color for the coverage box outline... * # overviewMapHandler.lineColor=FFFF0000 * * # A sample overview map layer * overviewLayer.class=com.bbn.openmap.layer.shape.ShapeLayer * overviewLayer.prettyName=Overview * overviewLayer.shapeFile=/home/dietrick/dev/openmap/share/dcwpo-browse.shp * overviewLayer.spatialIndex=/home/dietrick/dev/openmap/share/dcwpo-browse.ssx * overviewLayer.lineColor=ff000000 * overviewLayer.fillColor=ffbdde83 * * * </pre> * * <p> * * If layers are not added to the overview map, then it won't show up * in the application. */public class OverviewMapHandler extends OMToolComponent implements ProjectionListener, Serializable, PropertyConsumer, PropertyChangeListener, ComponentListener { public final static String OverviewMapHandlerLayerProperty = "overviewLayers"; public final static String ScaleFactorProperty = "overviewScaleFactor"; public final static String ProjectionTypeProperty = "overviewProjectionType"; public final static String MinScaleProperty = "overviewMinScale"; public final static String StatusLayerProperty = "overviewStatusLayer"; public final static String ControlSourceMapProperty = "overviewControlSourceMap"; public final static String BackgroundSlaveProperty = "backgroundSlave"; public final static float defaultScaleFactor = 20f; public final static float defaultMinScale = 500000f; /** The multiplier to apply to the scale of the project received. */ protected float scaleFactor; /** * The minimum scale to use for the window. If it gets too small * with a general type layer, it won't be any use. */ protected float minScale; /** The map of the overview panel. */ protected transient MapBean map; /** * The source MapBean to show the overview of. Gets set when the * first projectionChanged() gets called. Also used to disconnect * from the MapBean when the component that this * OverviewMapHandler is listening to is hidden, and to connect to * the MapBean when the component is shown. */ protected transient MapBean sourceMap; /** The projection of the overview map bean. */ protected transient Proj projection; /** * A layer that can be set to constantly be on the top of the map. * If the status layer is also a OverviewMapStatusListener, it * also receives the source map projection when that changes, * which gives it the capability to draw stuff based on that. */ protected Layer statusLayer; /** * The support to send the source MapBean setCenter and setScale * commands if a controlled map is added - usually the source map * bean. */ protected transient ControlledMapSupport listener; /** The mouse mode to use for the overview map. */ protected MapMouseMode mmm; /** * The thing listening for a request to bring up a JFrame or * JInternalFrame. */ protected ActionListener overviewFrameActionListener = null; /** Indicates if OverviewMap should be controlling sourceMap. */ protected boolean controlSourceMap = true; /** Default Frame title for OverviewMapHandler */ public static final String defaultFrameTitle = "Overview Map"; /** String The Frame Title */ protected String frameTitle = defaultFrameTitle; /** Default key for Tool */ public static final String defaultKey = "overviewmaphandler"; /** * Flag to change the background color to whatever the source * map's is changed to. True byt default. */ protected boolean backgroundSlave = true; public final static int INITIAL_WIDTH = 200; public final static int INITIAL_HEIGHT = 100; /** * Default constructor. make sure init(someProperties) is called * before you attempt to use this object */ public OverviewMapHandler() { super(); setKey(defaultKey); setLayout(new BorderLayout()); createOverviewMap(); // Set up a default... projection = createStartingProjection(null); addComponentListener(this); setWindowSupport(new WindowSupport(this, "Overview Map")); } /** * Create an OverviewMapHandler with properties that do not * contain a prefix. * * @param props properties object. */ public OverviewMapHandler(Properties props) throws Exception { this(null, props); } /** * Create an OverviewMapHandler with properties that do contain a * prefix. * * @param prefix the prefix for all the properties that apply to * the OverviewMapHandler. * @param props properties object. */ public OverviewMapHandler(String prefix, Properties props) throws Exception { this(); setProperties(prefix, props); } /** * Create an OverviewMapHandler for given MapBean. * * @param srcMap srcMapBean * @param prefix the prefix to place in front of each property - * i.e., so that each property will be under * prefix.propertyName. The period between the two will be * added. * @param props properties object. */ public OverviewMapHandler(MapBean srcMap, String prefix, Properties props) throws Exception { this(prefix, props); setSourceMap(srcMap); } /** * Create the MapBean used for the overview map, and suppress the * copyright message at the same time. */ protected void createOverviewMap() { // We don't need another copyright message, right? MapBean.suppressCopyright = true; map = new BufferedMapBean(); this.add(map, BorderLayout.CENTER); } /** * Initialize based on properties, which will not have a prefix. * * @deprecated use setProperties(props). */ public void init(Properties props) throws Exception { setProperties(null, props); } /** * Initialize an OverviewMapHandler with properties that do * contain a prefix. * * @param prefix the prefix to place in front of each property - * i.e., so that each property will be under * prefix.propertyName. The period between the two will be * added. * @param props properties object. * @deprecated use setProperties(prefix, props). */ public void init(String prefix, Properties props) throws Exception { setProperties(prefix, props); } /** * Sets the properties for the <code>Layer</code>. This allows * <code>Layer</code> s to get a richer set of parameters than * the <code>setArgs</code> method. Part of the PropertyConsumer * interface. Layers which override this method should do * something like: <code><pre> * public void setProperties(String prefix, Properties props) { * super.setProperties(prefix, props); * // do local stuff * } * </pre></code> If the addToBeanContext property is not defined, it is * set to false here. * * @param prefix the token to prefix the property names * @param props the <code>Properties</code> object */ public void setProperties(String prefix, java.util.Properties props) { propertyPrefix = prefix; prefix = PropUtils.getScopedPropertyPrefix(prefix); Vector overviewLayers; overviewLayers = PropUtils.parseSpacedMarkers(props.getProperty(prefix + OverviewMapHandlerLayerProperty)); if (overviewLayers.size() == 0) { Debug.message("overview", "OverviewMapHandler: created without layers!"); } scaleFactor = PropUtils.floatFromProperties(props, prefix + ScaleFactorProperty, defaultScaleFactor); minScale = PropUtils.floatFromProperties(props, prefix + MinScaleProperty, defaultMinScale); backgroundSlave = PropUtils.booleanFromProperties(props, prefix + BackgroundSlaveProperty, backgroundSlave); setControlSourceMap(PropUtils.booleanFromProperties(props, prefix + ControlSourceMapProperty, controlSourceMap)); String statusLayerName = props.getProperty(prefix + StatusLayerProperty + ".class"); if (statusLayerName != null) { statusLayer = (Layer) ComponentFactory.create(statusLayerName, prefix + StatusLayerProperty, props); if (statusLayer == null) { Debug.error("OverviewMapHandler.setProperties: status layer not set."); } } else { statusLayer = new OverviewMapAreaLayer();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -