Index: src/org/openstreetmap/gui/jmapviewer/DefaultMapController.java =================================================================== --- src/org/openstreetmap/gui/jmapviewer/DefaultMapController.java (revision 16919) +++ src/org/openstreetmap/gui/jmapviewer/DefaultMapController.java (working copy) @@ -9,6 +9,9 @@ import java.awt.event.MouseWheelEvent; import java.awt.event.MouseWheelListener; +import org.openstreetmap.josm.Main; +import org.openstreetmap.josm.tools.PlatformHookOsx; + /** * Default map controller which implements map moving by pressing the right * mouse button and zooming by double click or by mouse wheel. @@ -17,11 +20,12 @@ * */ public class DefaultMapController extends JMapController implements MouseListener, MouseMotionListener, - MouseWheelListener { +MouseWheelListener { private static final int MOUSE_BUTTONS_MASK = MouseEvent.BUTTON3_DOWN_MASK | MouseEvent.BUTTON1_DOWN_MASK - | MouseEvent.BUTTON2_DOWN_MASK; + | MouseEvent.BUTTON2_DOWN_MASK; + private static final int MAC_MOUSE_BUTTON3_MASK = MouseEvent.CTRL_DOWN_MASK | MouseEvent.BUTTON1_DOWN_MASK; public DefaultMapController(JMapViewer map) { super(map); } @@ -54,27 +58,29 @@ } public void mouseClicked(MouseEvent e) { - if (doubleClickZoomEnabled && e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) + if (doubleClickZoomEnabled && e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) { map.zoomIn(e.getPoint()); + } } public void mousePressed(MouseEvent e) { - if (e.getButton() == movementMouseButton) { + if (e.getButton() == movementMouseButton || isPlatformOsx() && e.getModifiersEx() == MAC_MOUSE_BUTTON3_MASK) { lastDragPoint = null; isMoving = true; } } public void mouseReleased(MouseEvent e) { - if (e.getButton() == movementMouseButton) { + if (e.getButton() == movementMouseButton || isPlatformOsx() && e.getButton() == MouseEvent.BUTTON1) { lastDragPoint = null; isMoving = false; } } public void mouseWheelMoved(MouseWheelEvent e) { - if (wheelZoomEnabled) + if (wheelZoomEnabled) { map.setZoom(map.getZoom() - e.getWheelRotation(), e.getPoint()); + } } public boolean isMovementEnabled() { @@ -145,6 +151,33 @@ } public void mouseMoved(MouseEvent e) { + // Mac OSX simulates with ctrl + mouse 1 the second mouse button hence no dragging events get fired. + // + if (isPlatformOsx()) { + if (!movementEnabled || !isMoving) + return; + // Is only the selected mouse button pressed? + if (e.getModifiersEx() == MouseEvent.CTRL_DOWN_MASK) { + Point p = e.getPoint(); + if (lastDragPoint != null) { + int diffx = lastDragPoint.x - p.x; + int diffy = lastDragPoint.y - p.y; + map.moveMap(diffx, diffy); + } + lastDragPoint = p; + } + + } + + } + + /** + * Replies true if we are currently running on OSX + * + * @return true if we are currently running on OSX + */ + public static boolean isPlatformOsx() { + return Main.platform != null && Main.platform instanceof PlatformHookOsx; } } Index: src/org/openstreetmap/josm/gui/MapMover.java =================================================================== --- src/org/openstreetmap/josm/gui/MapMover.java (revision 1936) +++ src/org/openstreetmap/josm/gui/MapMover.java (working copy) @@ -1,6 +1,8 @@ // License: GPL. Copyright 2007 by Immanuel Scholz and others package org.openstreetmap.josm.gui; +import static org.openstreetmap.josm.tools.I18n.tr; + import java.awt.Cursor; import java.awt.Point; import java.awt.event.ActionEvent; @@ -14,10 +16,11 @@ import javax.swing.AbstractAction; import javax.swing.JComponent; import javax.swing.JPanel; -import org.openstreetmap.josm.tools.Shortcut; -import static org.openstreetmap.josm.tools.I18n.tr; +import org.openstreetmap.josm.Main; import org.openstreetmap.josm.data.coor.EastNorth; +import org.openstreetmap.josm.tools.PlatformHookOsx; +import org.openstreetmap.josm.tools.Shortcut; /** * Enables moving of the map by holding down the right mouse button and drag @@ -134,16 +141,23 @@ */ @Override public void mousePressed(MouseEvent e) { int offMask = MouseEvent.BUTTON1_DOWN_MASK | MouseEvent.BUTTON2_DOWN_MASK; - if (e.getButton() == MouseEvent.BUTTON3 && (e.getModifiersEx() & offMask) == 0) + int macMouseMask = MouseEvent.CTRL_DOWN_MASK | MouseEvent.BUTTON1_DOWN_MASK; + if (e.getButton() == MouseEvent.BUTTON3 && (e.getModifiersEx() & offMask) == 0) { startMovement(e); + } else if (isPlatformOsx() && e.getModifiersEx() == macMouseMask) { + startMovement(e); + } } /** * Change the cursor back to it's pre-move cursor. */ @Override public void mouseReleased(MouseEvent e) { - if (e.getButton() == MouseEvent.BUTTON3) + if (e.getButton() == MouseEvent.BUTTON3) { + endMovement(); + } else if (isPlatformOsx() && e.getButton() == MouseEvent.BUTTON1) { endMovement(); + } } /** @@ -184,7 +199,35 @@ } /** - * Does nothing. Only to satisfy MouseMotionListener + * Emulates dragging on Mac OSX + */ + public void mouseMoved(MouseEvent e) { + if (!movementInPlace) + return; + // Mac OSX simulates with ctrl + mouse 1 the second mouse button hence no dragging events get fired. + // Is only the selected mouse button pressed? + if (isPlatformOsx()) { + if (e.getModifiersEx() == MouseEvent.CTRL_DOWN_MASK) { + if (mousePosMove == null) { + startMovement(e); + } + EastNorth center = nc.getCenter(); + EastNorth mouseCenter = nc.getEastNorth(e.getX(), e.getY()); + nc.zoomTo(new EastNorth(mousePosMove.east() + center.east() - mouseCenter.east(), mousePosMove.north() + + center.north() - mouseCenter.north())); + } else { + endMovement(); + } + } + } + + /** + * Replies true if we are currently running on OSX + * + * @return true if we are currently running on OSX */ - public void mouseMoved(MouseEvent e) {} + public static boolean isPlatformOsx() { + return Main.platform != null && Main.platform instanceof PlatformHookOsx; + } + }