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

📄 bufferedlayer.java

📁 OpenMap是一个基于JavaBeansTM的开发工具包。利用OpenMap你就能够快速构建用于访问legacy数据库的应用程序与applets。OpenMap提供了允许用户查看和操作地理空间信息的
💻 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/layer/BufferedLayer.java,v $// $RCSfile: BufferedLayer.java,v $// $Revision: 1.5.2.6 $// $Date: 2007/06/21 21:41:37 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.layer;import java.awt.BorderLayout;import java.awt.Color;import java.awt.Component;import java.awt.Graphics;import java.awt.Image;import java.awt.Paint;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.ComponentEvent;import java.awt.image.BufferedImage;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import java.beans.PropertyVetoException;import java.beans.beancontext.BeanContext;import java.util.Properties;import java.util.Vector;import javax.swing.BoxLayout;import javax.swing.JCheckBox;import javax.swing.JPanel;import javax.swing.JTabbedPane;import com.bbn.openmap.BufferedMapBean;import com.bbn.openmap.Layer;import com.bbn.openmap.LayerHandler;import com.bbn.openmap.MapBean;import com.bbn.openmap.omGraphics.OMColor;import com.bbn.openmap.proj.Projection;import com.bbn.openmap.util.Debug;import com.bbn.openmap.util.PropUtils;/** * A BufferedLayer is a layer that buffers a group of layers into an image. When * this layer repaints, the image gets rendered. This layer can be used to group * a set of layers into one, and was designed with the idea that it is a * background layer where a more animated layer would be on top of it. * <P> *  * This layer contains a MapBean, and any layer that gets added to it simply * gets added to the MapBean. When a layer needs to redraw itself, it can act * normally, and the BufferedLayer will get updated as needed. If the MapBean is * a BufferedMapBean (which it is by default), then the layers will get buffered * into an image. * <P> *  * There are some special considerations to think about when using this layer if * the background is at all transparent. The image buffer will need to be * recreated at certain times in order to prevent leftover images from the * previous paintings. When the background is set for the layer, the * transparency is tested if the background is a Color and the * setHasTransparentBackground() method is called accordingly. If a different * Paint object is set in the BufferedLayer, it's up to you to set this * variable. This causes a new image to be created every time a new projection * is provided to the layer. If the layers added to this BufferedLayer are * active, meaning that their content could change between projection changes, * you should set the hasActiveLayers flag to true. this causes a new image * buffer to be created every time a layer repaints itself. Again, this is only * important if the background color of the layer is transparent. * <P> *  * The BufferedLayer can be configured in the openmap.properties file: *  * <pre> *  *  *  bufLayer.class=com.bbn.openmap.layer.BufferedLayer *  bufLayer.prettyName=My Layer Group *  bufLayer.layers=layer1 layer2 layer3 *  bufLayer.visibleLayers=layer1 layer3 *  bufLayer.hasActiveLayers=false *  *   * </pre> *  * layer1, layer2, etc should be defined as any other openmap layer. */public class BufferedLayer extends Layer implements PropertyChangeListener {    public final static String LayersProperty = "layers";    public final static String VisibleLayersProperty = "visibleLayers";    public final static String HasActiveLayersProperty = "hasActiveLayers";    /**     * Used to recreate the buffer on every repaint() call made by every layer.     * Makes for a lot of image buffer creation. If the layers may call     * repaint() and change what they present between projection changes, then     * this needs to be set to true. Otherwise, the old graphics will still be     * visible. This only needs to be set if the background is at all     * transparent. If the background of the internal MapBean is opaque, set     * this to false, which is the default.     */    protected boolean hasActiveLayers = false;    /**     * Used to tell the BufferedLayer that the background is transparent. Will     * cause a new image buffer to be created when the projection changes, in     * order to cover up what was already there. This is set to true but     * default, since the internal MapBean color is set to OMColor.clear.     */    protected boolean hasTransparentBackground = true;    /**     * The MapBean used as the group organized. If this is a BufferedMapBean,     * the layer will provide a buffered image.     */    MapBean mapBean;    public BufferedLayer() {        this.setLayout(new BorderLayout());        // Adds the mapbean to the layer        MapBean mb = new BLMapBean(this);        // Add it the layer properly...        setMapBean(mb);    }    public void setProperties(String prefix, Properties props) {        super.setProperties(prefix, props);        prefix = PropUtils.getScopedPropertyPrefix(prefix);        hasActiveLayers = PropUtils.booleanFromProperties(props, prefix                + HasActiveLayersProperty, hasActiveLayers);        Vector layersValue = PropUtils.parseSpacedMarkers(props.getProperty(prefix                + LayersProperty));        Vector startuplayers = PropUtils.parseSpacedMarkers(props.getProperty(prefix                + VisibleLayersProperty));        Layer[] layers = LayerHandler.getLayers(layersValue,                startuplayers,                props);        for (int i = 0; i < layers.length; i++) {            mapBean.add(layers[i]);        }    }    public Properties getProperties(Properties props) {        props = super.getProperties(props);        String prefix = PropUtils.getScopedPropertyPrefix(this);        StringBuffer layersListProperty = new StringBuffer();        StringBuffer startupLayersListProperty = new StringBuffer();        Component[] comps = mapBean.getComponents();        for (int i = 0; i < comps.length; i++) {            // they have to be layers            Layer layer = (Layer) comps[i];            String lPrefix = layer.getPropertyPrefix();            boolean unsetPrefix = false;            if (lPrefix == null) {                lPrefix = "layer" + i;                // I think we need to do this, in order to get proper                // scoping in the properties. We'll unset it later...                layer.setPropertyPrefix(lPrefix);                unsetPrefix = true;            }            layersListProperty.append(" " + lPrefix);            if (layer.isVisible()) {                startupLayersListProperty.append(" " + lPrefix);            }            Debug.output("BufferedLayer: getting properties for "                    + layer.getName() + " "                    + layer.getProperties(new Properties()));            layer.getProperties(props);            if (unsetPrefix) {                layer.setPropertyPrefix(null);            }        }        props.put(prefix + LayersProperty, layersListProperty.toString());        props.put(prefix + VisibleLayersProperty,                startupLayersListProperty.toString());        props.put(prefix + HasActiveLayersProperty,                new Boolean(hasActiveLayers).toString());        return props;    }    /**     * Not really implemented, because the mechanism for providing a set of     * properties that let you add a variable number of new objects as children     * to this one.     */    public Properties getPropertyInfo(Properties props) {        props = super.getPropertyInfo(props);        return props;    }    /**     * If true, will cause a new image buffer to be recreated for every     * layer.repaint() call. Should only be set to true if the background is at     * all transparent, and if the layers could change between projection     * changes.     */    public void setHasActiveLayers(boolean value) {        hasActiveLayers = value;    }    public boolean getHasActiveLayers() {        return hasActiveLayers;    }    /**     * If true, will create a new image buffer when the projection changes.     * Should be set to true if the background has any transparency.     */    public void setHasTransparentBackground(boolean value) {        hasTransparentBackground = value;    }    public boolean getHasTransparentBackground() {        return hasTransparentBackground;    }    /**     * Remove all layers from the group.     */    public void clearLayers() {        Component[] layers = getLayers();        if (layers != null && layers.length > 0) {            for (int i = 0; i < layers.length; i++) {                removeLayer((Layer) layers[i]);            }        }        resetPalette();    }    /**     * Method for BeanContextChild interface. Gets an iterator from the     * BeanContext to call findAndInit() over. Sets BeanContext on sub-layers.     */    public void setBeanContext(BeanContext in_bc) throws PropertyVetoException {        super.setBeanContext(in_bc);        Component[] layers = getLayers();        if (layers != null && layers.length > 0) {            for (int i = 0; i < layers.length; i++) {                ((Layer) layers[i]).setBeanContext(in_bc);            }        }    }    /**     * Add a layer to the group. Sets the BeanContext on the added layer.     */    public void addLayer(Layer layer) {        mapBean.add(layer);        try {            layer.setBeanContext(getBeanContext());        } catch (PropertyVetoException nve) {        }        resetPalette();    }    /**     * Remove the layer from group.     */    public void removeLayer(Layer layer) {        mapBean.remove(layer);        resetPalette();    }    /**     * Return if there is at least one layer assigned to the group.     */    public boolean hasLayers() {        return (mapBean.getComponentCount() > 0);

⌨️ 快捷键说明

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