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

📄 defaultdndcatcher.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            while (keys.hasMoreElements()) {                layer_name = keys.nextElement().toString();                omlayer = (OMGraphicHandlerLayer) layers.get(layer_name);                if (omlayer.isVisible()) {                    JMenuItem menuItem = new JMenuItem(layer_name);                    menuItem.setHorizontalTextPosition(SwingConstants.CENTER);                    menuItem.setBorder(compoundborder);                    menuItem.addActionListener(this);                    popup.add(menuItem);                }            }            popup.addSeparator();        }        JMenuItem menuItem = new JMenuItem("CANCEL");        menuItem.setForeground(Color.red);        menuItem.setHorizontalTextPosition(SwingConstants.CENTER);        menuItem.setBorder(compoundborder);        popup.add(menuItem);        popup.setPreferredSize(new Dimension(150, (popup.getComponentCount() + 1) * 25));        //        // Show a popup menu of available drop targets.        //        popup.show(((DropTarget) dtde.getSource()).getComponent(),                dropLocation.x,                dropLocation.y);    }    /**     * Gets the location where the drop action occured.     */    private Point extractDropLocation(DropTargetDropEvent dtde) {        if (dtde == null) {            Debug.message("defaultdndcatcher",                    "ERROR> BDnDC::getTransferData(): dropEvent is null");            return null;        }        return dtde.getLocation();    }    /**     * Gets the object that is passed in transferable in     * DropTargetDropEvent.     */    private Object extractTransferData(DropTargetDropEvent dtde) {        if (dtde == null) {            Debug.message("defaultdndcatcher",                    "ERROR> DefaultDnDCatcher::getTransferData(): dropEvent is null");            return null;        }        Transferable tr = dtde.getTransferable();        try {            return tr.getTransferData(DefaultTransferableObject.OBJECT_FLAVOR);        } catch (Exception e) {            e.printStackTrace();            return null;        }    }    /**     * Called when an object should be evaluated by the     * DefaultDnDCatcher to see if it is needed.     */    public void findAndInit(Object someObj) {        if (someObj instanceof MouseDelegator)            md = (MouseDelegator) someObj;        if (someObj instanceof MapBean) {            ((MapBean) someObj).addProjectionListener(this);            setProjection(((MapBean) someObj).getProjection().makeClone());        }        if (someObj instanceof LayerHandler) {            LayerHandler lh = (LayerHandler) someObj;            lh.addLayerListener(this);            setLayers(lh.getLayers());        }    }    /**     * Eventually gets called when the DefaultDnDCatcher is added to     * the BeanContext, and when other objects are added to the     * BeanContext anytime after that. The DefaultDnDCatcher looks for     * LayerHandler to get OMGraphicHandlerLayer layers to manage Drag     * and Drop events for. If a MapBean is added to the BeanContext     * while another already is in use, the second MapBean will take     * the place of the first.     *      * @param it iterator to use to go through the new objects in the     *        BeanContext.     */    public void findAndInit(Iterator it) {        while (it.hasNext()) {            findAndInit(it.next());        }    }    /**     * Called by childrenRemoved.     */    public void findAndUndo(Object someObj) {}    public void firePropertyChange(String property, Object oldObj, Object newObj) {        pcSupport.firePropertyChange(property, oldObj, newObj);    }    /**     * Report a vetoable property update to any registered listeners.     * If anyone vetos the change, then fire a new event reverting     * everyone to the old value and then rethrow the     * PropertyVetoException.     * <P>     *      * No event is fired if old and new are equal and non-null.     * <P>     *      * @param name The programmatic name of the property that is about     *        to change     *      * @param oldValue The old value of the property     * @param newValue - The new value of the property     *      * @throws PropertyVetoException if the recipient wishes the     *         property change to be rolled back.     */    public void fireVetoableChange(String name, Object oldValue, Object newValue)            throws PropertyVetoException {        beanContextChildSupport.fireVetoableChange(name, oldValue, newValue);    }    /**     * @return the current BeanContext associated with the JavaBean     */    public java.beans.beancontext.BeanContext getBeanContext() {        return beanContextChildSupport.getBeanContext();    }    /**     * Gets current projection.     */    public Projection getProjection() {        return proj;    }    /**     * The mouseDragged event gets interpreted as     * DragGestureRecognized when startDrag boolean is true. After the     * first mouseDragged event, set startDrag to false.     *       */    public void mouseDragged(MouseEvent e) {        Debug.message("defaultdndcatcher", "mouseDragged, startDrag="                + startDrag);        if (startDrag) {            startDrag = false;            if (md.getActiveMouseMode() instanceof SelectMouseMode) {                appendEvent(e);                setComponent((Component) e.getSource());                fireDragGestureRecognized(DnDConstants.ACTION_MOVE,                        ((MouseEvent) getTriggerEvent()).getPoint());            }        }    }    /**     * On mouseReleased, set startDrag to true in order to enable     * dragging.     */    public void mouseReleased(MouseEvent e) {        startDrag = true;    }    /**     * Invoked when there has been a fundamental change to the Map.     * <p>     * Layers are expected to recompute their graphics (if this makes     * sense), and then <code>repaint()</code> themselves.     *      * @param e ProjectionEvent     */    public void projectionChanged(ProjectionEvent e) {        setProjection(e);    }    /**     * This method gets called when a bound property is changed.     *      * @param evt A PropertyChangeEvent object describing the event     *        source and the property that has changed.     */    public void propertyChange(java.beans.PropertyChangeEvent evt) {}    /**     * remove a property change listener to this bean child     */    public void removePropertyChangeListener(                                             String name,                                             java.beans.PropertyChangeListener pcl) {}    /**     * remove a vetoable change listener to this child     */    public void removeVetoableChangeListener(                                             String name,                                             java.beans.VetoableChangeListener vcl) {}    /**     * A change in the value of the nesting BeanContext property of     * this BeanContextChild may be vetoed by throwing the appropriate     * exception.     *      * @param in_bc the new BeanContext for this object     */    public void setBeanContext(BeanContext in_bc) throws PropertyVetoException {        if (in_bc != null) {            in_bc.addBeanContextMembershipListener(this);            beanContextChildSupport.setBeanContext(in_bc);            findAndInit(in_bc.iterator());        }    }    /**     * DefaultDnDCatcher adds itself to each layer as the     * DropTargetListener. This is needed in order to capture drop     * events from any layer on the map, and then apply the events to     * the applicable layers.     */    public void setLayers(Layer[] allLayers) {        // remove old layers list        layers.clear();        for (int i = 0; i < allLayers.length; i++) {            // create a new drop target            /* dropTarget = */new DropTarget(allLayers[i], DnDConstants.ACTION_MOVE, this);            if (allLayers[i] instanceof OMGraphicHandlerLayer) {                Debug.message("DnDCatcher", "Layers changed");                // keep a reference to potential drop target                layers.put(allLayers[i].getName(), allLayers[i]);            }        }    }    /**     * The method is invoked when there is a change in layers property     * in the LayerHandler.     */    public void setLayers(LayerEvent evt) {        if (evt.getType() == LayerEvent.ALL) {            setLayers(evt.getLayers());        }    }    /**     * This method lets you take the ProjectionEvent received from the     * MapBean, and lets you know if you should do something with it.     * MUST to be called in the projectionChanged() method of your     * layer, if you want to refer to the projection later. If this     * methods returns null, you probably just want to call repaint()     * if your layer.paint() method is ready to paint what it should.     *      * @param projEvent the ProjectionEvent from the     *        ProjectionListener method.     * @return The new Projection if it is different from the one we     *         already have, null if is the same as the current one.     */    public Projection setProjection(ProjectionEvent projEvent) {        Projection newProjection = projEvent.getProjection();        if (!newProjection.equals(getProjection())) {            Projection clone = newProjection.makeClone();            setProjection(clone);            return clone;        } else {            return null;        }    }    /**     * Sets the current projection.     */    public void setProjection(Projection projection) {        proj = projection;    }    /**     * Invoked on dragGestureRecognized in the     * ComponentDragGestureListener class.     *       */    public void startDragAction(DragGestureEvent dge, DragSourceListener dsl) {        // create a Transferable object here.        // Create a location object that can be dropped on a layer.        // dragSource.startDrag(dge,        // getCursor(DragSource.DefaultMoveDrop), new        // DefaultTransferableObject(new BasicLocation()), dsl);        // SinkGraphic is a singleton object used as sample. No action        // on a layer will be done at drop.        dragSource.startDrag(dge,                getCursor(DragSource.DefaultMoveDrop),                new DefaultTransferableObject(SinkGraphic.getSharedInstance()),                dsl);    }}

⌨️ 快捷键说明

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