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

📄 basicmappanel.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
// **********************************************************************// // <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/BasicMapPanel.java,v $// $RCSfile: BasicMapPanel.java,v $// $Revision: 1.11.2.6 $// $Date: 2004/10/14 18:26:51 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.gui;import java.awt.BorderLayout;import java.awt.Component;import java.awt.Dimension;import java.awt.LayoutManager;import java.awt.Toolkit;import java.net.URL;import java.util.Properties;import java.util.Collection;import javax.swing.JMenu;import javax.swing.JMenuBar;import javax.swing.border.BevelBorder;import javax.swing.border.Border;import com.bbn.openmap.BufferedLayerMapBean;import com.bbn.openmap.Environment;import com.bbn.openmap.MapBean;import com.bbn.openmap.MapHandler;import com.bbn.openmap.MultipleSoloMapComponentException;import com.bbn.openmap.PropertyHandler;import com.bbn.openmap.gui.menu.MenuList;import com.bbn.openmap.proj.Projection;import com.bbn.openmap.proj.ProjectionFactory;import com.bbn.openmap.util.Debug;/** * The BasicMapPanel is a MapPanel and OMComponentPanel that is the * heart of the OpenMap application framework. It can be used in a * application or applet. The Panel has a BorderLayout, and creates a * MapBean for its center area. It creates a MapHandler to use to hold * all of its OpenMap components, and uses the PropertyHandler given * to it in its constructor to create and configure all of the * application components. The best way to add components to the * MapPanel is to get the MapHandler from it and add components to * that. The BasicMapPanel also adds itself to its MapHandler, so when * the PropertyHandler adds MapPanelChildren components to the * MapHandler, the BasicMapPanel is able to find them via the * findAndInit method. By default, the BasicMapPanel looks for * MapPanelChildren and asks them for where they would prefer to be * located (BorderLayout.NORTH, BorderLayout.SOUTH, BorderLayout.EAST, * BorderLayout.WEST). If you extend this component, though, other * components could be found via that same findAndInit method. */public class BasicMapPanel extends OMComponentPanel implements MapPanel {    protected MapHandler mapHandler;    protected MapBean mapBean;    protected PropertyHandler propertyHandler;    protected MenuList menuList;    /**     * Creates an empty MapPanel that creates its own empty     * PropertyHandler. The MapPanel will contain a MapBean, a     * MapHandler, and a PropertyHandler with no properties. The     * constructor to use to create a blank map framework to add     * components to.     */    public BasicMapPanel() {        this(new PropertyHandler(new Properties()), false);    }    /**     * Create a MapPanel with the option of delaying the search for     * properties until the <code>create()</code> call is made.     *      * @param delayCreation true to let the MapPanel know that the     *        artful programmer will call <code>create()</code>     */    public BasicMapPanel(boolean delayCreation) {        this(null, delayCreation);    }    /**     * Create a MapPanel that configures itself with the properties     * contained in the PropertyHandler provided. If the     * PropertyHandler is null, a new one will be created.     */    public BasicMapPanel(PropertyHandler propertyHandler) {        this(propertyHandler, false);    }    /**     * Create a MapPanel that configures itself with properties     * contained in the PropertyHandler provided, and with the option     * of delaying the search for properties until the     * <code>create()</code> call is made.     *      * @param delayCreation true to let the MapPanel know that the     *        artful programmer will call <code>create()</code>     */    public BasicMapPanel(PropertyHandler propertyHandler, boolean delayCreation) {        setPropertyHandler(propertyHandler);        if (!delayCreation) {            create();        }    }    /**     * The method that triggers setLayout() and createComponents() to     * be called. If you've told the BasicMapPanel to delay creation,     * you should call this method to trigger the PropertyHandler to     * create components based on the contents of its properties.     */    public void create() {        setLayout(createLayoutManager());        createComponents();    }    /**     * The constructor calls this method that sets the LayoutManager     * for this MapPanel. It returns a BorderLayout by default, but     * this method can be overridden to change how the MapPanel places     * components. If you change what this method returns, you should     * also change how components are added in the findAndInit()     * method.     */    protected LayoutManager createLayoutManager() {        return new BorderLayout();    }    /**     * Position the map bean in this panel according to the layout     * manger. Defaults to BorderLayout.CENTER.     */    protected void addMapBeanToPanel(MapBean map) {        add(map, BorderLayout.CENTER);    }    /**     * The constructor calls this method that creates the MapHandler     * and MapBean, and then tells the PropertyHandler to create the     * components described in its properties. This method calls     * getMapHandler() and getMapBean(). If the PropertyHandler is not     * null, it will be called to created components based on its     * properties, and those components will be added to the     * MapHandler in this MapPanel.     */    protected void createComponents() {        // Make this call first to load the properties into        // Environment, before the MapBean gets created.        PropertyHandler ph = getPropertyHandler();        // Make sure the MapBean is created and added to the        // MapHandler.        MapBean mb = getMapBean();        MapHandler mh = getMapHandler();        mh.add(this);        ph.createComponents(getMapHandler());        // At this point, check the MapHandler to see if a        // ProjectionFactory has been added. If it hasn't, create one        // with the default ProjectionLoaders. We might want to        // remove this at some point, but not having it here will        // catch some people by suprise when 4.6.1 comes out.        Object obj = mh.get(com.bbn.openmap.proj.ProjectionFactory.class);        if (obj == null) {            Debug.message("basic",                    "BasicMapPanel adding ProjectionFactory and projections to MapHandler since there are none to be found.");            mh.add(ProjectionFactory.loadDefaultProjections());        }        // Environment will only get loaded after the property file is        // read.        mb.setProjection(ProjectionFactory.getDefaultProjectionFromEnvironment());        mb.setBckgrnd(Environment.getCustomBackgroundColor());    }    /**     * MapPanel method. Get the MapBean used for the MapPanel. If the     * MapBean is null, calls createMapBean() which will create a     * BufferedLayerMapBean and add it to the MapHandler via a     * setMapBean call. If you want something different, override this     * method.     */    public MapBean getMapBean() {        if (mapBean == null) {            setMapBean(BasicMapPanel.createMapBean());        }        return mapBean;    }    /**     * Set the map bean used in this map panel, replace the map bean     * in the MapHandler if there isn't already one, or if the policy     * allows replacement. The MapHandler will be created if it     * doesn't exist via a getMapHandler() method call.     *      * @throws MultipleSoloMapComponentException if there is already a     *         map bean in the map handler and the policy is to reject     *         duplicates (since the MapBean is a SoloMapComponent).     */    public void setMapBean(MapBean bean) {        if (bean == null && mapBean != null) {            // remove the current MapBean from the application...            getMapHandler().remove(mapBean);        }        mapBean = bean;        if (mapBean != null) {            getMapHandler().add(mapBean);            addMapBeanToPanel(mapBean);        }    }    /**     * Get the PropertyHandler containing properties used to configure     * the panel, creating it if it doesn't exist.     */    public PropertyHandler getPropertyHandler() {        if (propertyHandler == null) {            setPropertyHandler(new PropertyHandler());        }        return propertyHandler;    }    /**     * Set the PropertyHandler containing the properties used to     * configure this panel. Adds the PropertyHandler to the     * MapHandler. If the MapHandler isn't set at this point, it will     * be created via a getMapHandler() call.     */    public void setPropertyHandler(PropertyHandler handler) {        propertyHandler = handler;        if (handler != null) {            getMapHandler().add(handler);        }    }    /**     * MapPanel method. Get the MapHandler used for the MapPanel.     * Creates a standard MapHandler if it hasn't been created yet.     */    public MapHandler getMapHandler() {        if (mapHandler == null) {            mapHandler = new MapHandler();        }        return mapHandler;    }    /**     * MapPanel method. Get a JMenuBar containing menus created from     * properties.

⌨️ 快捷键说明

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