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

📄 mapbean.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            debugmsg("changeLayers() - firing change");        firePropertyChange(LayersProperty, currentLayers, newLayers);        // Tell the new layers that they have been added        for (int i = 0; i < addedLayers.size(); i++) {            ((Layer) addedLayers.elementAt(i)).added(this);        }        addedLayers.removeAllElements();        currentLayers = newLayers;    }    //------------------------------------------------------------    // ProjectionListener interface    //------------------------------------------------------------    /**     * ProjectionListener interface method. Should not be called     * directly.     *      * @param e ProjectionEvent     */    public void projectionChanged(ProjectionEvent e) {        Projection newProj = e.getProjection();        if (!projection.equals(newProj)) {            setProjection(newProj);        }    }    /**     * Set the Mouse cursor over the MapBean component.     *      * @param newCursor Cursor     */    public void setCursor(Cursor newCursor) {        firePropertyChange(CursorProperty, this.getCursor(), newCursor);        super.setCursor(newCursor);    }    /**     * In addition to adding the PropertyChangeListener as the     * JComponent method does, this method also provides the listener     * with the initial version of the Layer and Cursor properties.     */    public void addPropertyChangeListener(PropertyChangeListener pcl) {        super.addPropertyChangeListener(pcl);        pcl.propertyChange(new PropertyChangeEvent(this, LayersProperty, currentLayers, currentLayers));        pcl.propertyChange(new PropertyChangeEvent(this, CursorProperty, this.getCursor(), this.getCursor()));        pcl.propertyChange(new PropertyChangeEvent(this, BackgroundProperty, this.getBckgrnd(), this.getBckgrnd()));    }    protected final void debugmsg(String msg) {        Debug.output(this.toString()                + (DEBUG_TIMESTAMP ? (" [" + System.currentTimeMillis() + "]")                        : "")                + (DEBUG_THREAD ? (" [" + Thread.currentThread() + "]") : "")                + ": " + msg);    }    /**     * Same as JComponent.paint(), except if there are no children     * (Layers), the projection still paints the background and the     * border is painted.     */    public void paint(Graphics g) {        if (getComponentCount() == 0 && projection != null) {            drawProjectionBackground(g);            paintBorder(g);        } else {            super.paint(g);        }    }    /**     * Convenience method to test if Graphics is Graphics2D object,     * and to try to do the right thing.     */    protected void drawProjectionBackground(Graphics g) {        if (g instanceof Graphics2D) {            projection.drawBackground((Graphics2D) g, getBckgrnd());        } else {            g.setColor(getBackground());            projection.drawBackground(g);        }    }    /**     * Same as JComponent.paintChildren() except any PaintListeners     * are notified and the border is painted over the children.     */    public void paintChildren(Graphics g) {        paintChildren(g, null);    }    /**     * Same as paintChildren, but allows you to set a clipping area to     * paint. Be careful with this, because if the clipping area is     * set while some layer decides to paint itself, that layer may     * not have all it's objects painted.     */    public void paintChildren(Graphics g, Rectangle clip) {        g = getMapBeanRepaintPolicy().modifyGraphicsForPainting(g);        if (clip != null) {            g.setClip(clip);        } else {            // Had to do this to make the DrawingTool happy, or            // anything else swing-like that wanted to be around or on            // top of the MapBean.            g.setClip(0, 0, getWidth(), getHeight());        }        drawProjectionBackground(g);        super.paintChildren(g);        // Take care of the PaintListeners...        if (painters != null) {            painters.paint(g);        }        // border gets overwritten accidentally, so redraw it now        paintBorder(g);    }    /**     * Method that provides an option of whether or not to draw the     * border when painting. Usually called from another object trying     * to control the Map appearance when events are flying around.     */    public void paintChildrenWithBorder(Graphics g, boolean drawBorder) {        drawProjectionBackground(g);        if (drawBorder) {            paintChildren(g);        } else {            super.paintChildren(g);        }    }    /**     * Add a PaintListener.     *      * @param l PaintListener     */    public synchronized void addPaintListener(PaintListener l) {        if (painters == null) {            painters = new PaintListenerSupport(this);        }        painters.addPaintListener(l);    }    /**     * Remove a PaintListener.     *      * @param l PaintListener     */    public synchronized void removePaintListener(PaintListener l) {        if (painters == null) {            return;        }        painters.removePaintListener(l);        // Should we get rid of the support if there are no painters?        // The support will get created when a listener is added.        if (painters.size() == 0) {            painters = null;        }    }    //------------------------------------------------------------    // LayerListener interface    //------------------------------------------------------------    /**     * 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) {            // Don't care about these at all...            return;        }        // @HACK is this cool?:        if (layers == null) {            System.err.println("MapBean.setLayers(): layers is null!");            return;        }        boolean oldChange = getDoContainerChange();        setDoContainerChange(false);        // use LayerEvent.REPLACE when you want to remove all current        // layers        // add a new set        if (type == LayerEvent.REPLACE) {            if (Debug.debugging("mapbean")) {                debugmsg("Replacing all layers");            }            removeAll();            for (int i = 0; i < layers.length; i++) {                // @HACK is this cool?:                if (layers[i] == null) {                    System.err.println("MapBean.setLayers(): layer " + i                            + " is null");                    continue;                }                if (Debug.debugging("mapbean")) {                    debugmsg("Adding layer[" + i + "]= " + layers[i].getName());                }                add(layers[i]);                layers[i].setVisible(true);            }        }        // use LayerEvent.ADD when adding and/or reshuffling layers        else if (type == LayerEvent.ADD) {            if (Debug.debugging("mapbean")) {                debugmsg("Adding new layers");            }            for (int i = 0; i < layers.length; i++) {                if (Debug.debugging("mapbean")) {                    debugmsg("Adding layer[" + i + "]= " + layers[i].getName());                }                add(layers[i]);                layers[i].setVisible(true);            }        }        // use LayerEvent.REMOVE when you want to delete layers from        // the map        else if (type == LayerEvent.REMOVE) {            if (Debug.debugging("mapbean")) {                debugmsg("Removing layers");            }            for (int i = 0; i < layers.length; i++) {                if (Debug.debugging("mapbean")) {                    debugmsg("Removing layer[" + i + "]= "                            + layers[i].getName());                }                remove(layers[i]);            }        }        if (!layerRemovalDelayed) {            purgeAndNotifyRemovedLayers();        }        setDoContainerChange(oldChange);        repaint();        revalidate();    }    /**     * A call to try and get the MapBean to reduce flashing by     * controlling when repaints happen, waiting for lower layers to     * call for a repaint(), too. Calls shouldForwardRepaint(Layer),     * which acts as a policy for whether to forward the repaint up     * the Swing tree.     */    public void repaint(Layer layer) {        //      Debug.output(layer.getName() + " - wants a repaint()");        getMapBeanRepaintPolicy().repaint(layer);    }    /**     * Set the MapBeanRepaintPolicy used by the MapBean. This policy     * can be used to pace/filter layer repaint() requests.     */    public void setMapBeanRepaintPolicy(MapBeanRepaintPolicy mbrp) {        repaintPolicy = mbrp;    }    /**     * Get the MapBeanRepaintPolicy used by the MapBean. This policy     * can be used to pace/filter layer repaint() requests. If no     * policy has been set, a StandardMapBeanRepaintPolicy will be     * created, which simply forwards all requests.     */    public MapBeanRepaintPolicy getMapBeanRepaintPolicy() {        if (repaintPolicy == null) {            repaintPolicy = new StandardMapBeanRepaintPolicy(this);        }        return repaintPolicy;    }    /**     * Convenience function to get the LatLonPoint representing a     * screen location from a MouseEvent. Returns null if the event is     * null, or if the projection is not set in the MapBean. Allocates     * new LatLonPoint with coordinates.     */    public LatLonPoint getCoordinates(MouseEvent event) {        return getCoordinates(event, null);    }    /**     * Convenience function to get the LatLonPoint representing a     * screen location from a MouseEvent. Returns null if the event is     * null, or if the projection is not set in the MapBean. Save on     * memory allocation by sending in the LatLonPoint to fill.     */    public LatLonPoint getCoordinates(MouseEvent event, LatLonPoint llp) {        Projection proj = getProjection();        if (proj == null || event == null) {            return null;        }        if (llp == null) {            return proj.inverse(event.getX(), event.getY());        } else {            return proj.inverse(event.getX(), event.getY(), llp);        }    }    /**     * Interface-like method to query if the MapBean is buffered, so     * you can control behavior better. Allows the removal of specific     * instance-like quieries for, say, BufferedMapBean, when all you     * really want to know is if you have the data is buffered, and if     * so, should be buffer be cleared. For the MapBean, always false.     */    public boolean isBuffered() {        return false;    }    /**     * Interface-like method to set a buffer dirty, if there is one.     * In MapBean, there isn't.     *      * @param value boolean     */    public void setBufferDirty(boolean value) {}    /**     * Checks whether the image buffer should be repainted.     *      * @return boolean whether the layer buffer is dirty. Always true     *         for MapBean, because a paint is always gonna need to     *         happen.     */    public boolean isBufferDirty() {        return true;    }    /**     * If true (default) layers are held when they are removed, and     * then released and notified of removal when the projection     * changes. This saves the layers from releasing resources if the     * layer is simply being toggled on/off for different map views.     */    public void setLayerRemovalDelayed(boolean set) {        layerRemovalDelayed = set;    }    /**     * Return the flag for delayed layer removal.     */    public boolean isLayerRemovalDelayed() {        return layerRemovalDelayed;    }    /**     * Go through the layers, and for all of them that have the     * autoPalette variable turned on, show their palettes.     */    public void showLayerPalettes() {        Component[] comps = this.getComponents();        for (int i = 0; i < comps.length; i++) {            // they have to be layers            if (((Layer) comps[i]).autoPalette) {                ((Layer) comps[i]).showPalette();            }        }    }    /**     * Turn off all layer palettes.     */    public void hideLayerPalettes() {        Component[] comps = this.getComponents();        for (int i = 0; i < comps.length; i++) {            // they have to be layers            ((Layer) comps[i]).hidePalette();        }    }}

⌨️ 快捷键说明

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