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

📄 esriplugin.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            parent.add(list);            list = parent;        }        return list;    }    /*     * Reads the contents of the SHX and SHP files. The SHX file will     * be read first by utilizing the ShapeIndex.open method. This     * method will return a list of offsets, which the     * AbstractSupport.open method will use to iterate through the     * contents of the SHP file. @param sho The url of the SHP file     * @param shx The url of the SHX file @return A new     * EsriGraphicList, null if something went badly.     */    public EsriGraphicList getGeometry(URL shp, URL shx) {        return EsriGraphicList.getEsriGraphicList(shp,                shx,                getDrawingAttributes(),                getModel());    }    /**     * Returns the associated table model for this layer     *      * @return The associated table model for this layer     */    public DbfTableModel getModel() {        return _model;    }    /**     * Returns whether this layer is of type 0 (point), 3 (polyline),     * or 5(polygon)     *      * @return An int representing the type of layer, as specified in     *         Esri's shape file format specification     */    public int getType() {        return _type;    }    /**     * Filters the DbfTableModel given a SQL like string     *      * @param query A SQL like string to filter the DbfTableModel     */    public void query(String query) {    // to be implemented    }    /**     * Sets the DbfTableModel     *      * @param model The DbfModel to set for this layer     */    public void setModel(DbfTableModel model) {        if (_model != null) {            _model = model;            _list.putAttribute(DBF_ATTRIBUTE, model);        }    }    /**     * Sets the properties for the <code>Layer</code>.     *      * @param prefix the token to prefix the property names     * @param properties the <code>Properties</code> object     */    public void setProperties(String prefix, Properties properties) {        super.setProperties(prefix, properties);        drawingAttributes.setProperties(prefix, properties);        // This fixes a hole that was exposed when the PlugIn had the        // files set directly, and then had properties set for drawing        // attributes later.        if (_list != null) {            if (_model != null) {                DrawingAttributesUtility.setDrawingAttributes(_list,                        _model,                        drawingAttributes);            } else {                drawingAttributes.setTo(_list);            }        }        prefix = PropUtils.getScopedPropertyPrefix(prefix);        shp = properties.getProperty(prefix + PARAM_SHP);        shx = properties.getProperty(prefix + PARAM_SHX);        dbf = properties.getProperty(prefix + PARAM_DBF);        // try {        // setName("testing");        // _list = getGeometry(new URL(shp), new URL(shx));        // _model = getDbfTableModel(new URL(dbf));        // } catch(Exception exception) {        // System.out.println(exception);        // }    }    public Properties getProperties(Properties props) {        props = super.getProperties(props);        String prefix = PropUtils.getScopedPropertyPrefix(this);        props.put(prefix + PARAM_SHP, PropUtils.unnull(shp));        props.put(prefix + PARAM_SHX, PropUtils.unnull(shx));        props.put(prefix + PARAM_DBF, PropUtils.unnull(dbf));        // Need to make sure they line up.        drawingAttributes.setPropertyPrefix(getPropertyPrefix());        drawingAttributes.getProperties(props);        return props;    }    public Properties getPropertyInfo(Properties props) {        props = super.getPropertyInfo(props);        props.put(initPropertiesProperty, PARAM_SHP + " " + PARAM_DBF + " "                + PARAM_SHX + drawingAttributes.getInitPropertiesOrder() + " "                + Layer.AddToBeanContextProperty);        props.put(PARAM_SHP, "Location of a shape (.shp) file (path or URL)");        props.put(PARAM_SHX,                "Location of a index file (.shx) for the shape file (path or URL, optional)");        props.put(PARAM_DBF,                "Location of a database file (.dbf) for the shape file (path or URL, optional)");        props.put(PARAM_SHP + ScopedEditorProperty,                "com.bbn.openmap.util.propertyEditor.FDUPropertyEditor");        props.put(PARAM_DBF + ScopedEditorProperty,                "com.bbn.openmap.util.propertyEditor.FDUPropertyEditor");        props.put(PARAM_SHX + ScopedEditorProperty,                "com.bbn.openmap.util.propertyEditor.FDUPropertyEditor");        drawingAttributes.getPropertyInfo(props);        return props;    }    public Component getGUI() {        JPanel holder = new JPanel(new BorderLayout());        JPanel daGUI = (JPanel) drawingAttributes.getGUI();        holder.add(daGUI, BorderLayout.CENTER);        JPanel btnPanel = new JPanel(new GridLayout(3, 1));        JButton redrawSelected = new JButton("Set Colors for Selected");        btnPanel.add(redrawSelected);        JButton redrawAll = new JButton("Set Colors For All");        btnPanel.add(redrawAll);        JButton tableTrigger = new JButton("Show Data Table");        btnPanel.add(tableTrigger);        holder.add(btnPanel, BorderLayout.SOUTH);        redrawSelected.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent e) {                if (!(graphicIndex < 0)) {                    OMGraphic omg = getEsriGraphicList().getOMGraphicAt(graphicIndex);                    repaintGraphics(omg);                }            }        });        redrawAll.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent e) {                repaintGraphics(getEsriGraphicList());            }        });        tableTrigger.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent ae) {                showTable();            }        });        return holder;    }    /**     * Sets the drawing attributes to those of a particular OMGraphic.     */    public void setDrawingAttributes(OMGraphic omg) {        if (drawingAttributes != null && omg != null) {            drawingAttributes.setFrom(omg);        }    }    /**     * Repaints the currently selected OMGraphic or the OMGraphicList     * to the current DrawingAttributes     *      * @param omg the OMGraphic to repaint     */    private void repaintGraphics(OMGraphic omg) {        drawingAttributes.setTo(omg);        repaint();    }    protected JTable table = null;    protected ListSelectionModel lsm = null;    /**     * Needs to be called before displaying the DbfTableModel.     */    public JTable getTable() {        if (table == null) {            lsm = new DefaultListSelectionModel();            table = new JTable();            table.setModel(getModel());            table.setSelectionModel(lsm);            table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);            lsm.addListSelectionListener(new ListSelectionListener() {                public void valueChanged(ListSelectionEvent e) {                    // Ignore extra messages.                    if (e.getValueIsAdjusting()) {                        return;                    }                    ListSelectionModel lsm2 = (ListSelectionModel) e.getSource();                    if (lsm2.isSelectionEmpty()) {                        // no rows are selected                    } else {                        int index = lsm2.getMinSelectionIndex();                        selectGraphic(index);                        getComponent().repaint();                    }                }            });        }        return table;    }    /**     * Mark a graphic as selected on the map.     *      * @param index the index, from 0, of the graphic on the list.     */    public void selectGraphic(int index) {        EsriGraphicList list = getEsriGraphicList();        list.deselectAll();        // Clear out the selected graphics list        selectedGraphics.clear();        selectGraphic(list.getOMGraphicAt(index));        graphicIndex = index;        list.regenerate(proj);    }    /**     * Mark the graphic as selected, and generate if necessary.     */    public void selectGraphic(OMGraphic graphic) {        if (graphic != null) {            graphic.select();            graphic.regenerate(proj);            // Set the selected OMGraphic on the selected list.            selectedGraphics.add(graphic);        }    }    /**     * Given a graphic, highlight its entry in the table.     */    public void selectEntry(OMGraphic graphic) {        // Object obj = graphic.getAppObject();        if (lsm == null) {            getTable();        }        lsm.setSelectionInterval(graphicIndex, graphicIndex);        // scroll to the appropriate row in the table        getTable().scrollRectToVisible(getTable().getCellRect(graphicIndex,                0,                true));        // if (obj != null) {        // if (obj instanceof Integer) {        // int index = ((Integer)obj).intValue();        // lsm.setSelectionInterval(index-1, index-1);        // getTable().scrollRectToVisible(getTable().getCellRect(index,        // 0, true));        // }        // } else {        // lsm.clearSelection();        // }    }    /**     * Show the table in its own frame.     */    public void showTable() {        if (tableFrame == null) {            String tableTitle = (this.name != null) ? this.name : "";            tableFrame = new JFrame(tableTitle + " Shape Data Attributes");            JScrollPane pane = new JScrollPane(getTable(), JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);            tableFrame.getContentPane().add(pane, BorderLayout.CENTER);            tableFrame.setSize(400, 300);        }        tableFrame.setVisible(true);        tableFrame.toFront();    }    /**     * Handle a mouse click on the map.     */    public boolean mouseClicked(MouseEvent e) {        EsriGraphicList list = getEsriGraphicList();        boolean ret = false;        graphicIndex = -1;        if (list != null) {            OMGraphic omg = list.selectClosest(e.getX(), e.getY(), 4);            if (omg != null) {                // graphicIndex has to be set before selectEntry                // called.                graphicIndex = ((Integer) omg.getAttribute(SHAPE_INDEX_ATTRIBUTE)).intValue() - 1;                selectEntry(omg);                ret = true;            } else {                if (lsm == null)                    getTable();                lsm.clearSelection();                list.deselect();                selectedGraphics.clear();                repaint();            }        }        return ret;    }    protected Layer parentLayer = null;    /**     * Handle mouse moved events (Used for firing tool tip     * descriptions over graphics)     */    public boolean mouseMoved(MouseEvent e) {        EsriGraphicList list = getEsriGraphicList();        boolean ret = false;        if (list != null) {            OMGraphic omg = list.findClosest(e.getX(), e.getY(), 4);            if (omg != null) {                int index;                Integer I = ((Integer) omg.getAttribute(SHAPE_INDEX_ATTRIBUTE));                if (I != null) {                    index = I.intValue() - 1;                } else {                    index = list.indexOf(omg);                }                if (parentLayer == null) {                    Component comp = getComponent();                    if (comp != null && comp instanceof Layer) {                        parentLayer = (Layer) comp;                    }                }                if (parentLayer != null) {                    parentLayer.fireRequestToolTip(getDescription(index));                }                ret = true;            } else if (parentLayer != null) {                parentLayer.fireHideToolTip();            }        }        return ret;    }    /**     * Builds a description in HTML for a tool tip for the specified     * OMGraphic     *      * @param index the index of the graphic in the table     */    public String getDescription(int index) {        Vector v = new Vector();        String description = "";        v.add("<HTML><BODY>");        for (int i = 0; i < getTable().getColumnCount(); i++) {            try {                String column = getTable().getColumnName(i);                String value = (String) (getTable().getValueAt(index, i) + "");                v.add((i == 0 ? "<b>" : "<BR><b>") + column + ":</b> " + value);            } catch (NullPointerException npe) {            } catch (IndexOutOfBoundsException obe) {            }        }        v.add("</BODY></HTML>");        for (int i = 0; i < v.size(); i++) {            description += (String) (v.elementAt(i));        }        return description;    }    protected JPanel daGUI = null;    protected JFrame tableFrame = null;    /** This marks the index of the OMGraphic that is "selected" */    protected int graphicIndex = -1;    /**     * DataBoundsInformer interface.     */    public DataBounds getDataBounds() {        DataBounds box = null;        if (_list == null) {            _list = getEsriGraphicList();        }        if (_list != null) {            float[] extents = _list.getExtents();            box = new DataBounds((double) extents[1], (double) extents[0], (double) extents[3], (double) extents[2]);        }        return box;    }}

⌨️ 快捷键说明

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