Changeset 16939 in osm for applications/viewer


Ignore:
Timestamp:
2009-08-09T18:09:03+02:00 (15 years ago)
Author:
guggis
Message:

applied #3165: patch by dmuecke: moving map on a macbook withouth external mouse

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/DefaultMapController.java

    r14053 r16939  
    1010import java.awt.event.MouseWheelListener;
    1111
     12import org.openstreetmap.josm.Main;
     13import org.openstreetmap.josm.tools.PlatformHookOsx;
     14
    1215/**
    1316 * Default map controller which implements map moving by pressing the right
     
    1821 */
    1922public class DefaultMapController extends JMapController implements MouseListener, MouseMotionListener,
    20         MouseWheelListener {
     23MouseWheelListener {
    2124
    2225    private static final int MOUSE_BUTTONS_MASK = MouseEvent.BUTTON3_DOWN_MASK | MouseEvent.BUTTON1_DOWN_MASK
    23             | MouseEvent.BUTTON2_DOWN_MASK;
     26    | MouseEvent.BUTTON2_DOWN_MASK;
    2427
     28    private static final int MAC_MOUSE_BUTTON3_MASK = MouseEvent.CTRL_DOWN_MASK | MouseEvent.BUTTON1_DOWN_MASK;
    2529    public DefaultMapController(JMapViewer map) {
    2630        super(map);
     
    5559
    5660    public void mouseClicked(MouseEvent e) {
    57         if (doubleClickZoomEnabled && e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1)
     61        if (doubleClickZoomEnabled && e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) {
    5862            map.zoomIn(e.getPoint());
     63        }
    5964    }
    6065
    6166    public void mousePressed(MouseEvent e) {
    62         if (e.getButton() == movementMouseButton) {
     67        if (e.getButton() == movementMouseButton || isPlatformOsx() && e.getModifiersEx() == MAC_MOUSE_BUTTON3_MASK) {
    6368            lastDragPoint = null;
    6469            isMoving = true;
     
    6772
    6873    public void mouseReleased(MouseEvent e) {
    69         if (e.getButton() == movementMouseButton) {
     74        if (e.getButton() == movementMouseButton || isPlatformOsx() && e.getButton() == MouseEvent.BUTTON1) {
    7075            lastDragPoint = null;
    7176            isMoving = false;
     
    7479
    7580    public void mouseWheelMoved(MouseWheelEvent e) {
    76         if (wheelZoomEnabled)
     81        if (wheelZoomEnabled) {
    7782            map.setZoom(map.getZoom() - e.getWheelRotation(), e.getPoint());
     83        }
    7884    }
    7985
     
    146152
    147153    public void mouseMoved(MouseEvent e) {
     154        // Mac OSX simulates with  ctrl + mouse 1  the second mouse button hence no dragging events get fired.
     155        //
     156        if (isPlatformOsx()) {
     157            if (!movementEnabled || !isMoving)
     158                return;
     159            // Is only the selected mouse button pressed?
     160            if (e.getModifiersEx() == MouseEvent.CTRL_DOWN_MASK) {
     161                Point p = e.getPoint();
     162                if (lastDragPoint != null) {
     163                    int diffx = lastDragPoint.x - p.x;
     164                    int diffy = lastDragPoint.y - p.y;
     165                    map.moveMap(diffx, diffy);
     166                }
     167                lastDragPoint = p;
     168            }
     169
     170        }
     171
     172    }
     173
     174    /**
     175     * Replies true if we are currently running on OSX
     176     *
     177     * @return true if we are currently running on OSX
     178     */
     179    public static boolean isPlatformOsx() {
     180        return Main.platform != null && Main.platform instanceof PlatformHookOsx;
    148181    }
    149182
Note: See TracChangeset for help on using the changeset viewer.