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

📄 mapbean.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 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/MapBean.java,v $// $RCSfile: MapBean.java,v $// $Revision: 1.11.2.12 $// $Date: 2006/02/02 03:17:49 $// $Author: bmackiew $// // **********************************************************************package com.bbn.openmap;import java.awt.Color;import java.awt.Component;import java.awt.Cursor;import java.awt.Dimension;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.Insets;import java.awt.LayoutManager;import java.awt.Paint;import java.awt.Rectangle;import java.awt.event.ComponentEvent;import java.awt.event.ComponentListener;import java.awt.event.ContainerEvent;import java.awt.event.ContainerListener;import java.awt.event.MouseEvent;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import java.util.Vector;import javax.swing.JComponent;import javax.swing.OverlayLayout;import com.bbn.openmap.event.CenterEvent;import com.bbn.openmap.event.CenterListener;import com.bbn.openmap.event.LayerEvent;import com.bbn.openmap.event.LayerListener;import com.bbn.openmap.event.PaintListener;import com.bbn.openmap.event.PaintListenerSupport;import com.bbn.openmap.event.PanEvent;import com.bbn.openmap.event.PanListener;import com.bbn.openmap.event.ProjectionEvent;import com.bbn.openmap.event.ProjectionListener;import com.bbn.openmap.event.ProjectionSupport;import com.bbn.openmap.event.ZoomEvent;import com.bbn.openmap.event.ZoomListener;import com.bbn.openmap.proj.Mercator;import com.bbn.openmap.proj.Proj;import com.bbn.openmap.proj.Projection;import com.bbn.openmap.proj.ProjectionFactory;import com.bbn.openmap.util.Debug;import com.bbn.openmap.LatLonPoint;/** * The MapBean is the main component of the OpenMap Development Kit. * It is a Java Bean that manages and displays a map. A map is * comprised of a projection and a list of layers, and this class has * methods that allow you to control the projection parameters and to * add and remove layers. Layers that are part of the map receive * dynamic notifications of changes to the underlying view and * projection. * <p> * Most of the methods in the MapBean are called from the Java AWT and * Swing code. These methods make the MapBean a good "Swing citizen" * to its parent components, and you should not need to invoke them. * In general there are only two reasons to call MapBean methods: * controlling the projection, and adding or removing layers. * <p> * When controlling the MapBean projection, simply call the method * that applies - setCenter, pan, zoom, etc. NOTE: If you are setting * more than one parameter of the projection, it's more efficient to * getProjection(), directly set the parameters of the projection * object, and then call setProjection() with the modified projection. * That way, each ProjectionListener of the MapBean (each layer) will * only receive one projectionChanged() method call, as opposed to * receiving one for each projection adjustment. * <p> * To add or remove layers, use the add() and remove() methods that * the MapBean inherits from java.awt.Container. The add() method can * be called with an integer that indicates its desired position in * the layer list. * <P> * Changing the default clipping area may cause some Layers to not be * drawn completely, depending on what the clipping area is set to and * when the layer is trying to get itself painted. When manually * adjusting clipping area, make sure that when restricted clipping is * over that a full repaint occurs if there is a chance that another * layer may be trying to paint itself. *  * @see Layer */public class MapBean extends JComponent implements ComponentListener,        ContainerListener, ProjectionListener, PanListener, ZoomListener,        LayerListener, CenterListener, SoloMapComponent {    public static final String LayersProperty = "MapBean.layers";    public static final String CursorProperty = "MapBean.cursor";    public static final String BackgroundProperty = "MapBean.background";    public static final String ProjectionProperty = "MapBean.projection";    /**     * OpenMap title.     */    public static final String title = "OpenMap(tm)";    /**     * OpenMap version.     */    public static final String version = "4.6.3";    /**     * Suppress the copyright message on initialization. But remember,     * the OpenMap License says you can't do this!     */    public static boolean suppressCopyright = false;    private static final boolean DEBUG_TIMESTAMP = false;    private static final boolean DEBUG_THREAD = true;    private static final String copyrightNotice = "OpenMap(tm) Version "            + version + "\r\n"            + "  Copyright (C) BBNT Solutions LLC.  All rights reserved.\r\n"            + "  See http://openmap.bbn.com/ for details.\r\n";    public final static float DEFAULT_CENTER_LAT = 0.0f;    public final static float DEFAULT_CENTER_LON = 0.0f;    //zoomed all the way out    public final static float DEFAULT_SCALE = Float.MAX_VALUE;    public final static int DEFAULT_WIDTH = 640;    public final static int DEFAULT_HEIGHT = 480;    protected int minHeight = 100;    protected int minWidth = 100;    protected Proj projection = new Mercator(new LatLonPoint(DEFAULT_CENTER_LAT, DEFAULT_CENTER_LON), DEFAULT_SCALE, DEFAULT_WIDTH, DEFAULT_HEIGHT);    protected ProjectionSupport projectionSupport;    /**     * Layers that are removed from the MapBean are held until the     * next projection change. When the projection changes, they are     * notified that they have been removed from the map. This list is     * kept so that toggling a layer on and off won't cause them to     * get rid of their resources, in case the user is just creating     * different views of the map.     */    protected Vector removedLayers = new Vector(0);    /**     * Some users may want the layers deleted immediately when they     * are removed from the map. This flag controls that. The default     * behavior is to hold a reference to a layer and actually release     * it when the projection changes (default = true). Set to false     * if you want the MapBean to tell a Layer it has been removed     * immediately when it happens.     */    protected boolean layerRemovalDelayed = true;    /**     * This vector is to let the layers know when they have been added     * to the map.     */    protected Vector addedLayers = new Vector(0);    /**     * The PaintListeners want to know when the map has been     * repainted.     */    protected PaintListenerSupport painters = null;    /**     * The background color for this particular MapBean. If null, the     * setting for the projection, which in turn is set in the     * Environment class, will be used.     */    protected Paint background = null;    /**     * The MapBeanRepaintPolicy to use to handler/filter/pace layer     * repaint() requests. If not set, a StandardMapBeanRepaintPolicy     * will be used, which forwards repaint requests to Swing     * normally.     */    protected MapBeanRepaintPolicy repaintPolicy = null;    public final static Color DEFAULT_BACKGROUND_COLOR = new Color(191, 239, 255);    /**     * Return the OpenMap Copyright message.     *      * @return String Copyright     */    public static String getCopyrightMessage() {        return copyrightNotice;    }    /**     * Construct a MapBean.     */    public MapBean() {        if (Debug.debugging("mapbean")) {            debugmsg("MapBean()");        }        if (!suppressCopyright) {            Debug.output(copyrightNotice);        }        background = DEFAULT_BACKGROUND_COLOR;        // Don't need one for every MapBean, just the first one.        suppressCopyright = true;        super.setLayout(new OverlayLayout(this));        projectionSupport = new ProjectionSupport(this);        addComponentListener(this);        addContainerListener(this);        //----------------------------------------        // In a builder tool it seems that the OverlayLayout        // makes the MapBean fail to resize. And since it has        // no children by default, it has no size. So I add        // a null Layer here to give it a default size.        //----------------------------------------        if (java.beans.Beans.isDesignTime()) {            add(new Layer() {                public void projectionChanged(ProjectionEvent e) {}                public Dimension getPreferredSize() {                    return new Dimension(100, 100);                }            });        }        setPreferredSize(new Dimension(projection.getWidth(), projection.getHeight()));    }    /**     * Return a stringified representation of the MapBean.     *      * @return String     */    public String toString() {        return getClass().getName() + "@" + Integer.toHexString(hashCode());    }    /*----------------------------------------------------------------------     * Window System overrides     *----------------------------------------------------------------------*/    /**     * Adds additional constraints on possible children components.     * The new component must be a Layer. This method included as a     * good container citizen, and should not be called directly. Use     * the add() methods inherited from java.awt.Container instead.     *      * @param comp Component     * @param constraints Object     * @param index int location     */    protected final void addImpl(Component comp, Object constraints, int index) {        if (comp instanceof Layer) {            super.addImpl(comp, constraints, index);        } else {            throw new IllegalArgumentException("only Layers can be added to a MapBean");        }    }    /**     * Prevents changing the LayoutManager. Don't let anyone change     * the LayoutManager! This is called by the parent component and     * should not be called directly.     */    public final void setLayout(LayoutManager mgr) {        throw new IllegalArgumentException("cannot change layout of Map");    }    /**     * Return the minimum size of the MapBean window. Included here to     * be a good citizen.     */    public Dimension getMinimumSize() {        return new Dimension(minWidth, minHeight);    }    /**     * Set the minimum size of the MapBean window. Included here to be     * a good citizen.     */    public void setMinimumSize(Dimension dim) {        minWidth = (int) dim.getWidth();        minHeight = (int) dim.getHeight();    }    /**     * Get the Insets of the MapBean. This returns 0-length Insets.     * <p>     * This makes sure that there will be no +x,+y offset when drawing     * graphics. This is ok since any borders around the MapBean will     * get drawn afterwards on top.     *      * @return Insets 0-length Insets     */    public final Insets getInsets() {        return insets;    }    private final transient static Insets insets = new Insets(0, 0, 0, 0);    /*----------------------------------------------------------------------     * ComponentListener implementation     *----------------------------------------------------------------------*/    /**     * ComponentListener interface method. Should not be called     * directly. Invoked when component has been resized, and kicks     * off a projection change.     *      * @param e ComponentEvent     */    public void componentResized(ComponentEvent e) {        if (Debug.debugging("mapbean")) {            debugmsg("Size changed: " + getWidth() + " x " + getHeight());        }        projection.setWidth(getWidth());        projection.setHeight(getHeight());        fireProjectionChanged();    }    /**     * ComponentListener interface method. Should not be called     * directly. Invoked when component has been moved.     *      * @param e ComponentEvent     */    public void componentMoved(ComponentEvent e) {}    /**     * ComponentListener interface method. Should not be called     * directly. Invoked when component has been shown.     *      * @param e ComponentEvent     */    public void componentShown(ComponentEvent e) {}    /**     * ComponentListener interface method. Should not be called     * directly. Invoked when component has been hidden.     *      * @param e ComponentEvent     */    public void componentHidden(ComponentEvent e) {}    /*----------------------------------------------------------------------     *      *----------------------------------------------------------------------*/    /**     * Add a ProjectionListener to the MapBean. You do not need to     * call this method to add layers as ProjectionListeners. This     * method is called for the layer when it is added to the MapBean.     * Use this method for other objects that you want to know about     * the MapBean's projection.     *      * @param l ProjectionListener     */    public synchronized void addProjectionListener(ProjectionListener l) {        projectionSupport.addProjectionListener(l);        // Assume that it wants the current projection        l.projectionChanged(new ProjectionEvent(this, getProjection()));    }    /**     * Remove a ProjectionListener from the MapBean. You do not need     * to call this method to remove layers that are     * ProjectionListeners. This method is called for the layer when     * it is removed from the MapBean. Use this method for other     * objects that you want to remove from receiving projection

⌨️ 快捷键说明

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