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

📄 informationdelegator.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/InformationDelegator.java,v $// $RCSfile: InformationDelegator.java,v $// $Revision: 1.10.2.6 $// $Date: 2005/05/24 18:38:25 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap;import java.awt.Cursor;import java.awt.Font;import java.awt.Frame;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.Insets;import java.awt.event.MouseEvent;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import java.net.URL;import java.util.ArrayList;import java.util.Properties;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JProgressBar;import javax.swing.SwingConstants;import javax.swing.ToolTipManager;import com.bbn.openmap.event.InfoDisplayEvent;import com.bbn.openmap.event.InfoDisplayListener;import com.bbn.openmap.event.MapMouseMode;import com.bbn.openmap.event.ProgressEvent;import com.bbn.openmap.event.ProgressListener;import com.bbn.openmap.gui.MapPanelChild;import com.bbn.openmap.gui.OMComponentPanel;import com.bbn.openmap.gui.StatusLightPanel;import com.bbn.openmap.util.Debug;import com.bbn.openmap.util.PropUtils;import com.bbn.openmap.util.WebBrowser;/** * The InformationDelegator manages the display of information * requested by Layers and other map components. It can bring up a web * browser to display web pages and files, and pop up a message window * to provide status information to the user. It also has a visible * status window that contains a layer status indicator, and an * information line that can display short messages. * <p> * InformationDelegators are added to layers, and the layer fires * events through the InfoDisplayListener interface. The * InformationDelegator has a method called listenToLayers() that lets * you give it an array of layers, and it adds itself as a * InfoDisplayListener to those layers. * <p> * The InformationDelegator lets you alter its behavior with property * settings: *  * <pre> *  *   # Make the status lights buttons that bring up layer palettes. *   infoDelegator.triggers=true *   # Show the layer status lights. *   infoDelegator.showLights=true *   # Show the information text line *   infoDelegator.showInfoLine=true *   * </pre> */public class InformationDelegator extends OMComponentPanel implements        InfoDisplayListener, PropertyChangeListener, ProgressListener,        MapPanelChild {    protected JLabel infoLineHolder;    protected JLabel infoLineHolder2;    protected WebBrowser browser;    protected StatusLightPanel statusBar;    protected JProgressBar progressBar;    protected MapBean map;    protected ToolTipManager ttmanager;    protected String propertyPrefix;    private String fudgeString = " ";    /**     * Used to remember what the MouseModeCursor is, which is the base     * cursor setting for the MapBean. The gesture modes set this     * cursor, and it gets used when the currentMapBeanCursor is null.     */    protected Cursor fallbackMapBeanCursor = Cursor.getDefaultCursor();    /**     * Used to remember any cursor that may bave been requested by a     * layer. This is usually null, unless a layer has requested a     * cursor. The MapBean gesture modes set the fallbackMapBeanCursor     * instead.     */    protected Cursor currentMapBeanCursor = null;    protected boolean waitingForLayers = false;    protected boolean showWaitCursor = false;    /**     * Flag to show the status lights.     */    protected boolean showLights = true;    public final static String ShowLightsProperty = "showLights";    /**     * Flaf to show the information line.     */    protected boolean showInfoLine = true;    public final static String ShowInfoLineProperty = "showInfoLine";    public final static int MAP_OBJECT_INFO_LINE = 0; // Default    public final static int COORDINATE_INFO_LINE = 1;    protected ArrayList infoLineOrganizer = new ArrayList();    public InformationDelegator() {        super();        initInfoWidgets();    }    /**     * If you want to subclass the InformationDelegator and have it     * handle messages differently, you can override this method to     * set the widgets you want.     */    public void initInfoWidgets() {        Debug.message("info", "InformationDelegator.initInfoWidgets");        GridBagLayout gridbag = new GridBagLayout();        GridBagConstraints c = new GridBagConstraints();        setFont(new Font("Helvetica", Font.PLAIN, 9));        setLayout(gridbag);        progressBar = new JProgressBar();        gridbag.setConstraints(progressBar, c);        add(progressBar);        progressBar.setVisible(false);        JPanel infoLinePanel = new JPanel();        c.weightx = 1;        c.anchor = GridBagConstraints.WEST;        c.fill = GridBagConstraints.HORIZONTAL;        gridbag.setConstraints(infoLinePanel, c);        GridBagLayout gridbag2 = new GridBagLayout();        GridBagConstraints c2 = new GridBagConstraints();        infoLinePanel.setLayout(gridbag2);        infoLineHolder = new JLabel(fudgeString);        c2.weightx = 1;        c2.fill = GridBagConstraints.HORIZONTAL;        c2.anchor = GridBagConstraints.WEST;        c2.insets = new Insets(3, 10, 3, 10);        gridbag2.setConstraints(infoLineHolder, c2);        infoLinePanel.add(infoLineHolder);        infoLineHolder2 = new JLabel(fudgeString, SwingConstants.RIGHT);        c2.weightx = 0;        c2.anchor = GridBagConstraints.EAST;        gridbag2.setConstraints(infoLineHolder2, c2);        infoLinePanel.add(infoLineHolder2);        addInfoLine(COORDINATE_INFO_LINE, infoLineHolder);        addInfoLine(MAP_OBJECT_INFO_LINE, infoLineHolder2);        add(infoLinePanel);        infoLinePanel.setVisible(showInfoLine);        c.weightx = 0;        c.anchor = GridBagConstraints.EAST;        statusBar = new StatusLightPanel();        gridbag.setConstraints(statusBar, c);        add(statusBar);        statusBar.setVisible(showLights);    }    /**     * Set the MapBean so that when the mouse mode changes, the cursor     * can change. This gets called from findAndInit if a MapHandler     * is involved with the application.     */    public void setMap(MapBean map) {        if (this.map != null) {            this.map.removePropertyChangeListener(this);        }        this.map = map;        if (map != null) {            map.addPropertyChangeListener(this);            fallbackMapBeanCursor = map.getCursor();        }    }    /**     * Listen for changes to the active mouse mode and for any changes     * to the list of available mouse modes. If the active mouse mode     * is "gestures", then the lat lon updates to the status line are     * deactivated.     */    public void propertyChange(PropertyChangeEvent evt) {        String propName = evt.getPropertyName();        if (propName == MapBean.CursorProperty) {            fallbackMapBeanCursor = ((Cursor) evt.getNewValue());        } else {            if (propName == MouseDelegator.ActiveModeProperty) {                MapMouseMode mmm = (MapMouseMode) evt.getNewValue();                setResetCursor(mmm.getModeCursor());            } else if (propName == MapBean.LayersProperty) {                resetForLayers((Layer[]) evt.getNewValue(),                        (Layer[]) evt.getOldValue());            } else if (propName != MapBean.ProjectionProperty) {                // For stuff we don't care about, just return from                // here. Otherwise, reset the GUI below...                return;            }            // Clear out all the information lines, resetting the GUI            setAllLabels(fudgeString);        }        initToolTip();    }    /**     * Set the InformationDelegator on Layers. Usually called because     * the layers changed on the map, and we need to add the     * InformationDelegator as an InfoDisplayListener for the new     * layers, and remove it from the old layers.     */    public void resetForLayers(Layer[] connectToLayers, Layer[] removeFromLayers) {        int i = 0;        if (removeFromLayers != null && removeFromLayers.length != 0) {            int removeLength = removeFromLayers.length;            for (i = 0; i < removeLength; i++) {                removeFromLayers[i].removeInfoDisplayListener(this);            }        }        if (connectToLayers != null && connectToLayers.length != 0) {            int removeLength = connectToLayers.length;            for (i = 0; i < removeLength; i++) {                connectToLayers[i].addInfoDisplayListener(this);            }        }    }    /**     * Receive a ProgressEvent, and use it if possible.     */    public void updateProgress(ProgressEvent evt) {        if (progressBar != null) {            int type = evt.getType();            if (type == ProgressEvent.START || type == ProgressEvent.UPDATE) {                progressBar.setVisible(true);                progressBar.setValue(evt.getPercentComplete());                setLabel(evt.getTaskDescription());            } else {                progressBar.setVisible(false);            }        }    }    public void addInfoLine(int refIndex, JLabel iLine) {        try {            infoLineOrganizer.set(refIndex, iLine);        } catch (IndexOutOfBoundsException ioobe) {            while (refIndex > 0 && infoLineOrganizer.size() <= refIndex + 1) {                infoLineOrganizer.add(iLine);            }        }    }    public void removeInfoLine(int refIndex) {        try {            infoLineOrganizer.set(refIndex, null);        } catch (IndexOutOfBoundsException iiobe) {        }    }    /**     * Set the information line label.     *      * @param str String     */    public void setLabel(String str) {        setLabel(str, MAP_OBJECT_INFO_LINE);    }    public void setAllLabels(String str) {        for (int i = 0; i < infoLineOrganizer.size(); i++) {            setLabel(str, i);        }    }    /**     * Set the information line label.     *      * @param str String     * @param infoLineDesignator the designator used to specify which     *        information line to use to display the string.     */    public void setLabel(String str, int infoLineDesignator) {        JLabel iLine;        try {            iLine = (JLabel) infoLineOrganizer.get(infoLineDesignator);        } catch (IndexOutOfBoundsException ioobe) {            // This should be OK.            iLine = (JLabel) infoLineOrganizer.get(MAP_OBJECT_INFO_LINE);        }        if (iLine != null) {            iLine.setText(str);        }    }    /**     * The method that updates the InformationDelegator display window     * with the correct layer representation. A status light reset     * method.     */    protected void setStatusBar() {        statusBar.reset();    }    public void initBrowser() {        setBrowser(new WebBrowser());    }    public void setBrowser(WebBrowser wb) {        browser = wb;        browser.setInfoDelegator(this);    }    public WebBrowser getBrowser() {        if (browser == null) {            initBrowser();        }        return browser;    }    /**     * Callback method.     */    public void checkBrowser() {        if (browser != null)            browser.exitValue();    }    /**     * Try to display a URL in a web browser.     */    public void displayURL(String url) {        MapHandler mh = (MapHandler) getBeanContext();        Frame frame = null;        if (mh != null) {            frame = (Frame) mh.get(java.awt.Frame.class);        }        try {            com.bbn.openmap.gui.MiniBrowser.display(frame, new URL(url));        } catch (java.net.MalformedURLException murle) {            Debug.error("InformationDelegator can't launch " + url);        }        //      WebBrowser wb = getBrowser();        //      if (wb != null) {        //          wb.launch(url);        //      }    }

⌨️ 快捷键说明

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