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

📄 overviewmaphandler.java

📁 OpenMap是一个基于JavaBeansTM的开发工具包。利用OpenMap你就能够快速构建用于访问legacy数据库的应用程序与applets。OpenMap提供了允许用户查看和操作地理空间信息的
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            map.addMouseListener(mmm);
            map.addMouseMotionListener(mmm);
        }
    }

    /**
     * Disconnects the mouse mode from the overview map.
     */
    public void deactivateMouseMode() {
        if (mmm != null) {
            map.removeMouseListener(mmm);
            map.removeMouseMotionListener(mmm);
        }
    }

    /**
     * Add a controlled MapBean to the OverviewMapHandler. Use this method to
     * add another MapBean to the overview map in order to have its projection
     * controlled by the overview panel. If the overview panel is clicked on,
     * the listening MapBean will be recentered. If a box is drawn with a mouse
     * drag, the scale of the controlled map will be modified.
     * 
     * @param l MapBean.
     */
    public void addControlledMap(MapBean l) {
        if (l != null) {
            if (listener == null) {
                listener = new ControlledMapSupport(map);
                // If nobody has been listening don't draw anything.
                // Since someone is now being controlled, we'll do the
                // drawing.
                activateMouseMode();
            }
            listener.addProjectionListener(l);
        }
    }

    /**
     * Remove a controlled MapBean from the OverviewMapHandler.
     * 
     * @param l a MapBean.
     */
    public void removeControlledMap(MapBean l) {
        if (listener != null) {
            listener.removeProjectionListener(l);

            if (listener.size() == 0) {
                deactivateMouseMode();
            }
        }
    }

    /**
     * Get the overview MapBean.
     * 
     * @return overview MapBean.
     */
    public MapBean getMap() {
        return map;
    }

    /**
     * Set the overview MapBean.
     */
    public void setMap(MapBean map) {
        if (map != null) {
            // get rid of any other MapBean that may have been added
            // to the JPanel.
            this.remove(map);
        }
        this.map = map;
        this.add(map, BorderLayout.CENTER);
    }

    /**
     * Get the ControlledMapSupport, which usually contains the source map.
     */
    public ControlledMapSupport getControlledMapListeners() {
        return listener;
    }

    /**
     * Set the ControlledMapSupport, which usually contains the source map.
     */
    public void setControlledMapListeners(ControlledMapSupport list) {
        listener = list;
    }

    /**
     * Get the status layer, which is always drawn on top of the other layers,
     * and maintained separately from other layers.
     */
    public Layer getStatusLayer() {
        return statusLayer;
    }

    /**
     * Get the status layer, which is always drawn on top of the other layers,
     * and maintained separately from other layers. If the layer is also an
     * OverviewMapStatusListener, it will receive source map projection changes,
     * so it can draw stuff on itself representing what's going on the source
     * map.
     */
    public void setStatusLayer(Layer layer) {
        statusLayer = layer;
    }

    /**
     * Set the scale factor to use between the source MapBean and the overview
     * MapBean. It's a direct multiplier, so the overview MapBean can actually
     * be a magnified map, too. The overview map scale = source MapBean scale *
     * scaleFactor.
     * 
     * @param setting scale factor
     */
    public void setScaleFactor(float setting) {
        scaleFactor = setting;
    }

    /**
     * Get the scale factor used for the overview MapBean.
     */
    public float getScaleFactor() {
        return scaleFactor;
    }

    /**
     * Set the projection of the overview MapBean. Lets you set the type,
     * really. The scale and center will be reset when a projection event is
     * received.
     */
    public void setProjection(Proj proj) {
        projection = proj;
    }

    /**
     * Get the current projection of the overview MapBean.
     */
    public Proj getProjection() {
        return projection;
    }

    /**
     * Set the minimum scale to use for the overview map. If this is set too
     * small with a very general map layer, it won't be of any use, really, if
     * it gets really zoomed in.
     * 
     * @param setting the scale setting - 1:setting
     */
    public void setMinScale(float setting) {
        if (setting > 0) {
            minScale = setting;
        }
    }

    /**
     * Set the minimum scale to use for the overview map. If this is set too
     * small with a very general map layer, it won't be of any use, really, if
     * it gets really zoomed in.
     * 
     * @param setting the scale setting - 1:setting
     */
    public void setMinScale(float width, Length uom) {
        if (width > 0) {
            Projection p = map.getProjection();

            // This is really not the radius but the half width.
            float radius = ProjMath.radToDeg(uom.toRadians(width)) / 2;

            LatLonPoint left = (LatLonPoint) p.getCenter().clone();
            LatLonPoint right = (LatLonPoint) p.getCenter().clone();
            left.setLongitude(left.getLongitude() - radius);
            right.setLongitude(right.getLongitude() + radius);

            minScale = ProjMath.getScale(left, right, p);
        }

    }

    public float getMinScale() {
        return minScale;
    }

    /**
     * Invoked when component has been shown. This component should be the
     * component that contains the OverviewMapHandler.
     */
    public void componentShown(ComponentEvent e) {
        if (sourceMap != null) {
            sourceMap.addProjectionListener(this);
        }
    }

    /**
     * Invoked when component has been hidden. This component should be the
     * component that contains the OverviewMapHandler.
     */
    public void componentHidden(ComponentEvent e) {
        if (sourceMap != null) {
            sourceMap.removeProjectionListener(this);
        }
    }

    public void componentResized(ComponentEvent e) {}

    public void componentMoved(ComponentEvent e) {}

    /**
     * Return an ActionListener that will bring up an independent window with an
     * Overview Map.
     * 
     * @return ActionListener that brings up a Window when an actionPerformed is
     *         called.
     */
    public ActionListener getOverviewFrameActionListener() {
        return new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                WindowSupport ws = getWindowSupport();

                MapHandler mh = (MapHandler) getBeanContext();                Frame frame = null;                if (mh != null) {                    frame = (Frame) mh.get(java.awt.Frame.class);                }                if (ws == null) {                    ws = new WindowSupport(OverviewMapHandler.this, new WindowSupport.Dlg(frame, "Overview Map"));                    setWindowSupport(ws);                }                int w = INITIAL_WIDTH;
                int h = INITIAL_HEIGHT;
                Dimension dim = ws.getComponentSize();
                if (map != null && dim != null) {
                    w = (int) dim.getWidth();
                    h = (int) dim.getHeight();
                }

                ws.displayInWindow(frame, -1, -1, w, h);                }
        };
    }

    /** Tool interface method. */
    public Container getFace() {
        JButton b = null;
        if (getUseAsTool()) {
            URL url = getClass().getResource("overview.gif");
            b = new JButton(new ImageIcon(url, frameTitle));
            b.setToolTipText(frameTitle);
            b.setMargin(new Insets(0, 0, 0, 0));
            b.addActionListener(getOverviewFrameActionListener());
            b.setBorderPainted(false);
        }
        return b;
    }

    /**
     * Called when the OverviewMapHandler is added to the BeanContext, and
     * whenever an object is added to the BeanContext after that. The
     * OverviewMapHandler looks for a MapBean to use as a source map, and for a
     * PropertiesHandler object to use to load itself with layers and other
     * properties. If a source MapBean is already set and another MapBean is
     * found, the last MapBean will be used as the source MapBean. Every time a
     * PropertyHandler is found, the OverviewMapHandler will reinitialize
     * itself.
     * 
     * @param someObj the object being added to the BeanContext
     */
    public void findAndInit(Object someObj) {
        if (someObj instanceof com.bbn.openmap.MapBean) {
            Debug.message("overview",
                    "OverviewMapHandler found a MapBean object");
            setSourceMap((MapBean) someObj);
        }
    }

    /**
     */
    public void findAndUndo(Object someObj) {
        if (someObj instanceof MapBean) {
            if (getSourceMap() == (MapBean) someObj) {
                Debug.message("overview",
                        "OverviewMapHandler: removing source MapBean");
                setSourceMap(null);
            }
        }
    }

    /**
     * Support for directing the setCenter and setScale calls to any MapBeans
     * that care to be listening.
     */
    public class ControlledMapSupport extends ProjectionSupport {

        /**
         * Construct a ControlledMapSupport.
         */
        public ControlledMapSupport() {
            super();
        }

        /**
         * Construct a ControlledMapSupport.
         * 
         * @param aSource source Object
         */
        public ControlledMapSupport(Object aSource) {
            super(aSource);
        }

        /**
         * Set the center coordinates on all registered listeners.
         * 
         * @param llp the new centerpoint
         */
        public void setCenter(LatLonPoint llp) {
            for (Iterator it = iterator(); it.hasNext();) {
                ((MapBean) it.next()).setCenter(llp);
            }
        }

        /**
         * Set the scale on all registered listeners.
         * 
         * @param scale the new scale
         */
        public void setScale(float scale) {
            for (Iterator it = iterator(); it.hasNext();) {
                ((MapBean) it.next()).setScale(scale);
            }
        }
    }

    /**
     * PropertyChangeListener method, to listen for the source map's background
     * changes. Act on if necessary.
     */
    public void propertyChange(PropertyChangeEvent pce) {
        if (pce.getPropertyName() == MapBean.BackgroundProperty
                && backgroundSlave) {
            map.setBckgrnd((Paint) pce.getNewValue());
        }
    }
}

⌨️ 快捷键说明

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