/*
 *    GeoTools - The Open Source Java GIS Toolkit
 *    http://geotools.org
 *
 *    (C) 2002-2008, Open Source Geospatial Foundation (OSGeo)
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License as published by the Free Software Foundation;
 *    version 2.1 of the License.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 */

package org.geotools.swing.tool;

import java.awt.Cursor;
import java.awt.Point;
import java.awt.Toolkit;
import javax.swing.ImageIcon;
import org.geotools.swing.JMapPane;
import org.geotools.swing.event.MapMouseEvent;
import org.geotools.swing.locale.LocaleUtils;

/**
 * A cursor tool to pan the map pane display.
 *
 * @author Michael Bedward
 * @since 2.6
 * @version $Id$
 */
public class PanTool extends CursorTool {

    /** Tool name */
    public static final String TOOL_NAME = LocaleUtils.getValue("CursorTool", "Pan");

    /** Tool tip text */
    public static final String TOOL_TIP = LocaleUtils.getValue("CursorTool", "PanTooltip");

    /** Cursor */
    public static final String CURSOR_IMAGE = "/org/geotools/swing/icons/mActionPan.png";

    /** Cursor hotspot coordinates */
    public static final Point CURSOR_HOTSPOT = new Point(15, 15);

    /** Icon for the control */
    public static final String ICON_IMAGE = "/org/geotools/swing/icons/mActionPan.png";

    private Cursor cursor;

    private Point panePos;
    boolean panning;

    /** Constructor */
    public PanTool() {
        Toolkit tk = Toolkit.getDefaultToolkit();
        ImageIcon imgIcon = new ImageIcon(getClass().getResource(CURSOR_IMAGE));
        cursor = tk.createCustomCursor(imgIcon.getImage(), CURSOR_HOTSPOT, TOOL_NAME);

        panning = false;
    }

    /**
     * Respond to a mouse button press event from the map mapPane. This may signal the start of a
     * mouse drag. Records the event's window position.
     *
     * @param ev the mouse event
     */
    @Override
    public void onMousePressed(MapMouseEvent ev) {
        panePos = ev.getPoint();
        panning = true;
    }

    /**
     * Respond to a mouse dragged event. Calls {@link org.geotools.swing.MapPane#moveImage()}
     *
     * @param ev the mouse event
     */
    @Override
    public void onMouseDragged(MapMouseEvent ev) {
        if (panning) {
            Point pos = ev.getPoint();
            if (!pos.equals(panePos)) {
                ((JMapPane) getMapPane()).moveImage(pos.x - panePos.x, pos.y - panePos.y);
                panePos = pos;
            }
        }
    }

    /**
     * If this button release is the end of a mouse dragged event, requests the map mapPane to
     * repaint the display
     *
     * @param ev the mouse event
     */
    @Override
    public void onMouseReleased(MapMouseEvent ev) {
        panning = false;
    }

    /** Get the mouse cursor for this tool */
    @Override
    public Cursor getCursor() {
        return cursor;
    }

    /**
     * Returns false to indicate that this tool does not draw a box on the map display when the
     * mouse is being dragged
     */
    @Override
    public boolean drawDragBox() {
        return false;
    }
}

@@ -781,44 +781,8 @@
 on;%0A
-import org.geotools.swing.JMapPane;%0A
 impo
@@ -2639,20 +2639,8 @@
     
- ((JMapPane)
  get
@@ -2648,17 +2648,16 @@
 apPane()
-)
 .moveIma

Remove unneeded JMapPane cast (#2223)