spatialindexhandler.java

来自「OpenMap是一个基于JavaBeansTM的开发工具包。利用OpenMap你」· Java 代码 · 共 517 行 · 第 1/2 页

JAVA
517
字号
// **********************************************************************// // <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/shape/SpatialIndexHandler.java,v $// $RCSfile: SpatialIndexHandler.java,v $// $Revision: 1.5.2.5 $// $Date: 2007/06/21 21:41:40 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.layer.shape;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.IOException;import java.net.MalformedURLException;import java.net.URL;import java.util.Iterator;import java.util.Properties;import javax.swing.BorderFactory;import javax.swing.ImageIcon;import javax.swing.JCheckBox;import javax.swing.JComponent;import javax.swing.JPanel;import com.bbn.openmap.Environment;import com.bbn.openmap.I18n;import com.bbn.openmap.Layer;import com.bbn.openmap.PropertyConsumer;import com.bbn.openmap.dataAccess.shape.DbfHandler;import com.bbn.openmap.io.FormatException;import com.bbn.openmap.layer.shape.SpatialIndex.Entry;import com.bbn.openmap.omGraphics.DrawingAttributes;import com.bbn.openmap.omGraphics.OMGraphic;import com.bbn.openmap.omGraphics.OMGraphicList;import com.bbn.openmap.proj.Projection;import com.bbn.openmap.proj.coords.GeoCoordTransformation;import com.bbn.openmap.util.ComponentFactory;import com.bbn.openmap.util.Debug;import com.bbn.openmap.util.PropUtils;/** * The SpatialIndexHandler keeps track of all the stuff dealing with a * particular shape file - file names, colors, etc. You can ask it to create * OMGraphics based on a bounding box, and make adjustments to it through its * GUI. */public class SpatialIndexHandler implements PropertyConsumer {    protected SpatialIndex spatialIndex;    protected String shapeFileName = null;    protected String spatialIndexFileName = null;    protected String imageURLString = null;    protected GeoCoordTransformation coordTranslator;    protected String prettyName = null;    protected DrawingAttributes drawingAttributes;    protected boolean enabled = true;    protected boolean buffered = false;    protected String propertyPrefix;    public final static String EnabledProperty = "enabled";    public final static String BufferedProperty = "buffered";    // for internationalization    protected I18n i18n = Environment.getI18n();    public SpatialIndexHandler() {}    public SpatialIndexHandler(String prefix, Properties props) {        setProperties(prefix, props);    }    public String toString() {        StringBuffer sb = new StringBuffer();        sb.append("For " + prettyName + ":\n");        sb.append("  Shape file name: " + shapeFileName + "\n");        sb.append("  Spatal index file name: " + spatialIndexFileName + "\n");        sb.append("  image URL: " + imageURLString + "\n");        sb.append("  drawing attributes: " + drawingAttributes + "\n");        return sb.toString();    }    /**     * Get the GUI that controls the attributes of the handler.     */    public JComponent getGUI() {        JPanel stuff = new JPanel();        stuff.setBorder(BorderFactory.createRaisedBevelBorder());        // stuff.add(new JLabel(prettyName));        stuff.add(drawingAttributes.getGUI());        JPanel checks = new JPanel(new GridLayout(0, 1));        JCheckBox enableButton = new JCheckBox(i18n.get(SpatialIndexHandler.class,                "enableButton",                "Show"));        enableButton.setSelected(enabled);        enableButton.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent ae) {                JCheckBox jcb = (JCheckBox) ae.getSource();                enabled = jcb.isSelected();            }        });        checks.add(enableButton);        JCheckBox bufferButton = new JCheckBox(i18n.get(SpatialIndexHandler.class,                "bufferButton",                "Buffer"));        bufferButton.setSelected(buffered);        bufferButton.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent ae) {                JCheckBox jcb = (JCheckBox) ae.getSource();                buffered = jcb.isSelected();            }        });        checks.add(bufferButton);        stuff.add(checks);        return stuff;    }    /** Property Consumer method. */    public void setPropertyPrefix(String prefix) {        propertyPrefix = prefix;    }    /** Property Consumer method. */    public String getPropertyPrefix() {        return propertyPrefix;    }    /** Property Consumer method. */    public void setProperties(Properties props) {        setProperties(null, props);    }    /** Property Consumer method. */    public void setProperties(String prefix, Properties props) {        setPropertyPrefix(prefix);        String realPrefix = PropUtils.getScopedPropertyPrefix(this);        prettyName = props.getProperty(realPrefix + Layer.PrettyNameProperty);        shapeFileName = props.getProperty(realPrefix                + ShapeLayer.shapeFileProperty);        spatialIndexFileName = props.getProperty(realPrefix                + ShapeLayer.spatialIndexProperty);        if (shapeFileName != null && !shapeFileName.equals("")) {            if (spatialIndexFileName != null                    && !spatialIndexFileName.equals("")) {                spatialIndex = SpatialIndex.locateAndSetShapeData(shapeFileName,                        spatialIndexFileName);            } else {                spatialIndex = SpatialIndex.locateAndSetShapeData(shapeFileName);            }            imageURLString = props.getProperty(realPrefix                    + ShapeLayer.pointImageURLProperty);            try {                if (imageURLString != null && !imageURLString.equals("")) {                    URL imageURL = PropUtils.getResourceOrFileOrURL(this,                            imageURLString);                    ImageIcon imageIcon = new ImageIcon(imageURL);                    spatialIndex.setPointIcon(imageIcon);                }            } catch (MalformedURLException murle) {                Debug.error("MultiShapeLayer.setProperties(" + realPrefix                        + ": point image URL not so good: \n\t"                        + imageURLString);            } catch (NullPointerException npe) {                // May happen if not connected to the internet.                Debug.error("Can't access icon image: \n" + imageURLString);            }        } else {            Debug.error(realPrefix                    + ": One of the following properties was null or empty:");            Debug.error("\t" + realPrefix + ShapeLayer.shapeFileProperty);            Debug.error("\t" + realPrefix + ShapeLayer.spatialIndexProperty);        }        props.put(ShapeLayer.spatialIndexProperty,                "Location of Spatial Index file - .ssx (File, URL or relative file path).");        drawingAttributes = new DrawingAttributes(realPrefix, props);        enabled = PropUtils.booleanFromProperties(props, realPrefix                + EnabledProperty, enabled);        buffered = PropUtils.booleanFromProperties(props, realPrefix                + BufferedProperty, buffered);        String transClassName = props.getProperty(realPrefix                + ShapeLayer.TransformProperty);        if (transClassName != null) {            try {                coordTranslator = (GeoCoordTransformation) ComponentFactory.create(transClassName,                        realPrefix + ShapeLayer.TransformProperty,                        props);            } catch (ClassCastException cce) {            }        }    }    /** Property Consumer method. */    public Properties getProperties(Properties props) {        if (props == null) {            props = new Properties();        }        String prefix = PropUtils.getScopedPropertyPrefix(this);        props.put(prefix + ShapeLayer.shapeFileProperty,                (shapeFileName == null ? "" : shapeFileName));        props.put(prefix + ShapeLayer.spatialIndexProperty,                (spatialIndexFileName == null ? "" : spatialIndexFileName));        props.put(prefix + ShapeLayer.pointImageURLProperty,                (imageURLString == null ? "" : imageURLString));        if (drawingAttributes != null) {            drawingAttributes.getProperties(props);        } else {            DrawingAttributes da = (DrawingAttributes) DrawingAttributes.DEFAULT.clone();            da.setPropertyPrefix(prefix);            da.getProperties(props);        }        props.put(prefix + EnabledProperty, new Boolean(enabled).toString());        props.put(prefix + BufferedProperty, new Boolean(buffered).toString());        if (spatialIndex != null) {            DbfHandler dbfh = spatialIndex.getDbf();            if (dbfh != null) {                dbfh.getProperties(props);            }        }        return props;    }    /** Property Consumer method. */    public Properties getPropertyInfo(Properties props) {        if (props == null) {            props = new Properties();        }        String interString;        // those strings are already internationalized in ShapeLayer.        // So only thing to do is use        // keys and values from there.The main question is: what about

⌨️ 快捷键说明

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