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

📄 layersmenu.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/LayersMenu.java,v $// $RCSfile: LayersMenu.java,v $// $Revision: 1.7.2.3 $// $Date: 2006/01/13 22:48:58 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.gui;import java.awt.Component;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.ComponentEvent;import java.awt.event.ComponentListener;import java.beans.PropertyVetoException;import java.io.Serializable;import javax.swing.JCheckBoxMenuItem;import javax.swing.JMenuItem;import javax.swing.JSeparator;import com.bbn.openmap.Layer;import com.bbn.openmap.LayerHandler;import com.bbn.openmap.event.LayerEvent;import com.bbn.openmap.event.LayerListener;import com.bbn.openmap.util.Debug;/** * The LayersMenu is a JMenu which is a list of the layers of the map. This * LayersMenu expects to work with a LayerHandler containing all the possible * layers that may be added to the map. This list defaults to being checkbuttons * which add and remove the named layer to/from the Map. You can also use an * instance of this object to show/hide layer palettes. * <P> *  * This object is interested in contacting a LayerHandler to find out all the * layers available, and optionally, a LayersPanel in order to provide a menu * item that will call up the GUI for the LayersPanel. If this LayersMenu is a * member of a BeanContext, it expects that only one of each of these objects * will be added, but if more than one per type is added, the last one added to * be BeanContext will be the one hooked up to this LayersMenu. */public class LayersMenu extends AbstractOpenMapMenu implements Serializable,        LayerListener {    /**     * Static value to set this menu to control layer visibility.     */    public static final transient int LAYERS_ON_OFF = 1;    /**     * Static value to set this menu to control layer palette visibility.     */    public static final transient int PALETTES_ON_OFF = 2;    /**     * The flag setting the behavior of the menu, whether it controls the layers     * or the layers palettes.     */    protected int menuType = -1;    /**     * The LayerHandler to listen to for layers available for the map.     */    protected transient LayerHandler layerHandler;    /**     * Used by the BeanContext methods to insure that the component we     * disconnect the edit button from is the same one being removed from the     * BeanContext.     */    protected transient LayersPanel layersPanel;    /** A button on the bottom of the menu to bring up the layersPanel. */    protected transient JMenuItem edit = null;    /** The default edit button title. */    public final static String defaultEditLayersButtonTitle = "Edit Layers...";    /** The actual edit button title. */    protected transient String editLayersButtonTitle = defaultEditLayersButtonTitle;    /** The menu item to add a layer to the map. */    protected transient JMenuItem add = null;    /** The default add button title. */    protected transient String addLayersButtonTitle = "Add Layers...";    /**     * Construct LayersMenu.     */    public LayersMenu() {        this(null);    }    /**     * Construct LayersMenu.     *      * @param lHandler the handler for the layer     */    public LayersMenu(LayerHandler lHandler) {        this(lHandler, "Layers", LAYERS_ON_OFF);    }    /**     * Construct LayersMenu.     *      * @param lHandler the handler for the layer     * @param menuName the name of the menu     * @param menuType either LAYERS_ON_OFF, or PALETTES_ON_OFF     */    public LayersMenu(LayerHandler lHandler, String menuName, int menuType) {        super();        this.menuType = menuType;        setText(menuName);        setMnemonic('L');// HMMMM        layerHandler = lHandler;        // Layers will be turned on by something else initially.        if (layerHandler != null) {            setLayers(layerHandler.getLayers());        }    }    /**     * Set the LayerHandler that the LayersPanel listens to. If the LayerHandler     * is not null, the LayersMenu will be added to the LayerHandler     * LayerListener list, and the LayersMenu will receive a LayerEvent with the     * current layers.     * <P>     *      * If there is a LayerHandler that is already being listened to, then the     * LayersPanel will remove itself from current LayerHandler as a     * LayerListener, before adding itself to the new LayerHandler.     * <P>     *      * Lastly, if the LayerHandler passed in is null, the LayersPanel will     * disconnect itself from any LayerHandler currently held, and reset itself     * with no layers.     *      * @param lh the LayerHandler containing the layers.     */    public void setLayerHandler(LayerHandler lh) {        if (layerHandler != null) {            layerHandler.removeLayerListener(this);        }        layerHandler = lh;        if (layerHandler != null) {            layerHandler.addLayerListener(this);        } else {            setLayers(new Layer[0]);        }    }    /**     * Get the LayerHandler that the LayersPanel listens to.     */    public LayerHandler getLayerHandler() {        return layerHandler;    }    /**     * Set the LayersPanel privately to keep track of what object is being used     * from the BeanContext.     */    protected void setLayersPanel(LayersPanel lp) {        layersPanel = lp;    }    /**     * Get the LayersPanel, privately held to keep track of what object is being     * used from the BeanContext.     */    protected LayersPanel getLayersPanel() {        return layersPanel;    }    /**     * Return the title of the menu option to call up LayersPanel.     */    public void setEditLayersButtonTitle(String buttonTitle) {        editLayersButtonTitle = buttonTitle;    }    /**     * Return the title of the menu option to call up LayersPanel.     */    public String getEditLayersButtonTitle() {        return editLayersButtonTitle;    }    /**     * Set the edit menu item that tiggers the LayersPanel action listener.     * Assumes that it's already wired up.     */    public void setEdit(JMenuItem e) {        edit = e;        // This actually adds the edit button to the bottom of the        // LayerMenu when the menu is reconstructed.        if (getLayerHandler() != null) {            setLayers(getLayerHandler().getLayers());        }    }    /**     * Set the add menu item.     */    public void setAdd(JMenuItem a) {        add = a;        if (getLayerHandler() != null) {            setLayers(getLayerHandler().getLayers());        }    }    /**     * Get the edit menu item that tiggers the LayersPanel action listener.     */    public JMenuItem getEdit() {        return edit;    }    /**     * LayerListener interface method. A list of layers will be added, removed,     * or replaced based on on the type of LayerEvent.     *      * @param evt a LayerEvent     */    public void setLayers(LayerEvent evt) {        Layer[] layers = evt.getLayers();        int type = evt.getType();        if (type == LayerEvent.ALL) {            setLayers(layers);        }    }    /**     * Set the layers that are on the menu. Calls setLayers(layers, true);     *      * @param inLayers the array of layers.     */    public void setLayers(Layer[] inLayers) {        removeAll();        // Set everything up for the new layers        if (inLayers == null) {            if (Debug.debugging("layersmenu")) {                Debug.error("LayersMenu.setLayers(): Layers are null.");            }        } else {            for (int i = 0; i < inLayers.length; i++) {                LayerCheckBoxMenuItem cbs = new LayerCheckBoxMenuItem(inLayers[i]);                add(cbs);            }        }        if (edit != null) {            add(new JSeparator());            add(edit);        }        if (add != null) {            add(add);        }    }    /**     * Remove all the components from the menu. Also calls cleanup() on all the     * LayerCheckBoxMenuItems, so they can remove themselves from their layers.     */    public void removeAll() {

⌨️ 快捷键说明

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