Ticket #3165: emulate.txt

File emulate.txt, 6.6 KB (added by dmuecke, 15 years ago)
Line 
1Index: src/org/openstreetmap/gui/jmapviewer/DefaultMapController.java
2===================================================================
3--- src/org/openstreetmap/gui/jmapviewer/DefaultMapController.java (revision 16919)
4+++ src/org/openstreetmap/gui/jmapviewer/DefaultMapController.java (working copy)
5@@ -9,6 +9,9 @@
6 import java.awt.event.MouseWheelEvent;
7 import java.awt.event.MouseWheelListener;
8
9+import org.openstreetmap.josm.Main;
10+import org.openstreetmap.josm.tools.PlatformHookOsx;
11+
12 /**
13 * Default map controller which implements map moving by pressing the right
14 * mouse button and zooming by double click or by mouse wheel.
15@@ -17,11 +20,12 @@
16 *
17 */
18 public class DefaultMapController extends JMapController implements MouseListener, MouseMotionListener,
19- MouseWheelListener {
20+MouseWheelListener {
21
22 private static final int MOUSE_BUTTONS_MASK = MouseEvent.BUTTON3_DOWN_MASK | MouseEvent.BUTTON1_DOWN_MASK
23- | MouseEvent.BUTTON2_DOWN_MASK;
24+ | MouseEvent.BUTTON2_DOWN_MASK;
25
26+ private static final int MAC_MOUSE_BUTTON3_MASK = MouseEvent.CTRL_DOWN_MASK | MouseEvent.BUTTON1_DOWN_MASK;
27 public DefaultMapController(JMapViewer map) {
28 super(map);
29 }
30@@ -54,27 +58,29 @@
31 }
32
33 public void mouseClicked(MouseEvent e) {
34- if (doubleClickZoomEnabled && e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1)
35+ if (doubleClickZoomEnabled && e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) {
36 map.zoomIn(e.getPoint());
37+ }
38 }
39
40 public void mousePressed(MouseEvent e) {
41- if (e.getButton() == movementMouseButton) {
42+ if (e.getButton() == movementMouseButton || isPlatformOsx() && e.getModifiersEx() == MAC_MOUSE_BUTTON3_MASK) {
43 lastDragPoint = null;
44 isMoving = true;
45 }
46 }
47
48 public void mouseReleased(MouseEvent e) {
49- if (e.getButton() == movementMouseButton) {
50+ if (e.getButton() == movementMouseButton || isPlatformOsx() && e.getButton() == MouseEvent.BUTTON1) {
51 lastDragPoint = null;
52 isMoving = false;
53 }
54 }
55
56 public void mouseWheelMoved(MouseWheelEvent e) {
57- if (wheelZoomEnabled)
58+ if (wheelZoomEnabled) {
59 map.setZoom(map.getZoom() - e.getWheelRotation(), e.getPoint());
60+ }
61 }
62
63 public boolean isMovementEnabled() {
64@@ -145,6 +151,33 @@
65 }
66
67 public void mouseMoved(MouseEvent e) {
68+ // Mac OSX simulates with ctrl + mouse 1 the second mouse button hence no dragging events get fired.
69+ //
70+ if (isPlatformOsx()) {
71+ if (!movementEnabled || !isMoving)
72+ return;
73+ // Is only the selected mouse button pressed?
74+ if (e.getModifiersEx() == MouseEvent.CTRL_DOWN_MASK) {
75+ Point p = e.getPoint();
76+ if (lastDragPoint != null) {
77+ int diffx = lastDragPoint.x - p.x;
78+ int diffy = lastDragPoint.y - p.y;
79+ map.moveMap(diffx, diffy);
80+ }
81+ lastDragPoint = p;
82+ }
83+
84+ }
85+
86+ }
87+
88+ /**
89+ * Replies true if we are currently running on OSX
90+ *
91+ * @return true if we are currently running on OSX
92+ */
93+ public static boolean isPlatformOsx() {
94+ return Main.platform != null && Main.platform instanceof PlatformHookOsx;
95 }
96
97 }
98Index: src/org/openstreetmap/josm/gui/MapMover.java
99===================================================================
100--- src/org/openstreetmap/josm/gui/MapMover.java (revision 1936)
101+++ src/org/openstreetmap/josm/gui/MapMover.java (working copy)
102@@ -1,6 +1,8 @@
103 // License: GPL. Copyright 2007 by Immanuel Scholz and others
104 package org.openstreetmap.josm.gui;
105
106+import static org.openstreetmap.josm.tools.I18n.tr;
107+
108 import java.awt.Cursor;
109 import java.awt.Point;
110 import java.awt.event.ActionEvent;
111@@ -14,10 +16,11 @@
112 import javax.swing.AbstractAction;
113 import javax.swing.JComponent;
114 import javax.swing.JPanel;
115-import org.openstreetmap.josm.tools.Shortcut;
116-import static org.openstreetmap.josm.tools.I18n.tr;
117
118+import org.openstreetmap.josm.Main;
119 import org.openstreetmap.josm.data.coor.EastNorth;
120+import org.openstreetmap.josm.tools.PlatformHookOsx;
121+import org.openstreetmap.josm.tools.Shortcut;
122
123 /**
124 * Enables moving of the map by holding down the right mouse button and drag
125@@ -134,16 +141,23 @@
126 */
127 @Override public void mousePressed(MouseEvent e) {
128 int offMask = MouseEvent.BUTTON1_DOWN_MASK | MouseEvent.BUTTON2_DOWN_MASK;
129- if (e.getButton() == MouseEvent.BUTTON3 && (e.getModifiersEx() & offMask) == 0)
130+ int macMouseMask = MouseEvent.CTRL_DOWN_MASK | MouseEvent.BUTTON1_DOWN_MASK;
131+ if (e.getButton() == MouseEvent.BUTTON3 && (e.getModifiersEx() & offMask) == 0) {
132 startMovement(e);
133+ } else if (isPlatformOsx() && e.getModifiersEx() == macMouseMask) {
134+ startMovement(e);
135+ }
136 }
137
138 /**
139 * Change the cursor back to it's pre-move cursor.
140 */
141 @Override public void mouseReleased(MouseEvent e) {
142- if (e.getButton() == MouseEvent.BUTTON3)
143+ if (e.getButton() == MouseEvent.BUTTON3) {
144+ endMovement();
145+ } else if (isPlatformOsx() && e.getButton() == MouseEvent.BUTTON1) {
146 endMovement();
147+ }
148 }
149
150 /**
151@@ -184,7 +199,35 @@
152 }
153
154 /**
155- * Does nothing. Only to satisfy MouseMotionListener
156+ * Emulates dragging on Mac OSX
157+ */
158+ public void mouseMoved(MouseEvent e) {
159+ if (!movementInPlace)
160+ return;
161+ // Mac OSX simulates with ctrl + mouse 1 the second mouse button hence no dragging events get fired.
162+ // Is only the selected mouse button pressed?
163+ if (isPlatformOsx()) {
164+ if (e.getModifiersEx() == MouseEvent.CTRL_DOWN_MASK) {
165+ if (mousePosMove == null) {
166+ startMovement(e);
167+ }
168+ EastNorth center = nc.getCenter();
169+ EastNorth mouseCenter = nc.getEastNorth(e.getX(), e.getY());
170+ nc.zoomTo(new EastNorth(mousePosMove.east() + center.east() - mouseCenter.east(), mousePosMove.north()
171+ + center.north() - mouseCenter.north()));
172+ } else {
173+ endMovement();
174+ }
175+ }
176+ }
177+
178+ /**
179+ * Replies true if we are currently running on OSX
180+ *
181+ * @return true if we are currently running on OSX
182 */
183- public void mouseMoved(MouseEvent e) {}
184+ public static boolean isPlatformOsx() {
185+ return Main.platform != null && Main.platform instanceof PlatformHookOsx;
186+ }
187+
188 }