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

📄 overviewmaphandler.java

📁 OpenMap是一个基于JavaBeansTM的开发工具包。利用OpenMap你就能够快速构建用于访问legacy数据库的应用程序与applets。OpenMap提供了允许用户查看和操作地理空间信息的
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
// **********************************************************************
//
// <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.3 $
// $Date: 2006/08/09 21:01:23 $
// $Author: dietrick $
//
// **********************************************************************

package com.bbn.openmap.gui;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Insets;
import java.awt.Paint;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.Serializable;
import java.net.URL;
import java.util.Iterator;
import java.util.Properties;
import java.util.Vector;

import javax.swing.ImageIcon;
import javax.swing.JButton;

import com.bbn.openmap.BufferedMapBean;
import com.bbn.openmap.Environment;
import com.bbn.openmap.LatLonPoint;
import com.bbn.openmap.Layer;
import com.bbn.openmap.LayerHandler;
import com.bbn.openmap.MapBean;
import com.bbn.openmap.MapHandler;
import com.bbn.openmap.PropertyConsumer;
import com.bbn.openmap.event.DefaultOverviewMouseMode;
import com.bbn.openmap.event.LayerEvent;
import com.bbn.openmap.event.MapMouseMode;
import com.bbn.openmap.event.OverviewMapStatusListener;
import com.bbn.openmap.event.ProjectionEvent;
import com.bbn.openmap.event.ProjectionListener;
import com.bbn.openmap.event.ProjectionSupport;
import com.bbn.openmap.layer.OverviewMapAreaLayer;
import com.bbn.openmap.proj.Length;
import com.bbn.openmap.proj.Mercator;
import com.bbn.openmap.proj.Proj;
import com.bbn.openmap.proj.ProjMath;
import com.bbn.openmap.proj.Projection;
import com.bbn.openmap.proj.ProjectionFactory;
import com.bbn.openmap.util.ComponentFactory;
import com.bbn.openmap.util.Debug;
import com.bbn.openmap.util.PropUtils;

/**
 * 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=100f
 *   # Set the Unit of Measure for the overviewMinScale property
 *   # Omission of  overviewMinScaleUom indicates that overviewMinScale
 *   # is an projection map scale instead of a distance.
 *   overviewMapHandler.overviewMinScaleUom=km
 * 
 *   # '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 MinScaleUomProperty = "overviewMinScaleUom";
    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;
    public final static Length defaultMinScaleUom = null;

    /** 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 minimum scale unit of measure to use for the window. Use during
     * initialization to compute a projection scale from a distance.
     */
    protected Length minScaleUom;

    /** 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);
        // Create this when we need it.        // setWindowSupport(new WindowSupport(this, new WindowSupport.Dlg(null,        // "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

⌨️ 快捷键说明

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