[OSM-dev] Patches from a Applet addict

Claudomiro Nascimento Jr. claudomiro at gmail.com
Sat Mar 17 15:34:27 GMT 2007


Hi,

First, thanks for Steve and all people involved in bringing the yahoo
imagery to the project. I mapped almost 1000km of highways here in Brazil
in the  last two months and that would be impossible if we had to wait for
enough GPS track logs.

To improve the editing pace I have added to the code a few shortcuts:

    * keys [1], [2], [3] mapped to select the editing modes "Node",
"Segment" and "Move Node"
    * dragging with the Right button "pans" the view ("Move" mode)
    * Mouse Wheel Up/Down zoom In/Out the view (and recenter the view on the
mouse cursor position).

enjoy


Index:
C:/prog/workspace/osm-applet-topatch/src/org/openstreetmap/processing/OsmApplet.java
===================================================================
---
C:/prog/workspace/osm-applet-topatch/src/org/openstreetmap/processing/OsmApplet.java
(revision 2269)
+++
C:/prog/workspace/osm-applet-topatch/src/org/openstreetmap/processing/OsmApplet.java
(working copy)
@@ -75,6 +75,7 @@

 import java.awt.EventQueue;
 import java.awt.Image;
+import java.awt.event.MouseWheelListener;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
@@ -451,6 +452,22 @@
             }
         });

+        addMouseWheelListener(new MouseWheelListener() {
+            public void mouseWheelMoved(java.awt.event.MouseWheelEvent e) {
+                int notches = e.getWheelRotation();
+                if (notches < 0) {
+                    tiles.recenter(e.getX(), e.getY());
+                    tiles.zoomin();
+                    updatelinks();
+                } else {
+                    tiles.recenter(e.getX(), e.getY());
+                    tiles.zoomout();
+                    updatelinks();
+                }
+            };
+        });
+
+
     setStatus(BROWSEABLE);
         noLoop();
         redraw();
@@ -999,12 +1016,19 @@
   public void mouseDragged() {
     //debug("dragging mouse...");
     if (getStatus() != NOT_READY) {
-      modeManager.mouseDragged();
+        if(mouseButton == RIGHT) {
+            moveMode.mouseDragged();
+        } else {
+              modeManager.mouseDragged();
+        }
     }
     //debug("mouse dragged.");
   }

   public void mousePressed() {
+    if(mouseButton == RIGHT) {
+        moveMode.mousePressed();
+    } else {
     if (abortable && isOverMapGetAbort()) {
       osm.abortMapGet();
     }
@@ -1012,18 +1036,47 @@
     if (getStatus() != NOT_READY)
       modeManager.mousePressed();
   }
+  }

   public void mouseReleased() {
+    if(mouseButton == RIGHT) {
+        moveMode.mouseReleased();
+    } else {
     mouseDown = false;
     if (getStatus() != NOT_READY) {
       modeManager.mouseReleased();
     }
   }
+  }

   public void keyPressed() {
     // print("keyPressed!");
     if (getStatus() != NOT_READY) {
       switch (key) {
+        case '1': // nodeMode Shortcut
+            if (modeManager.getCurrentMode() != null) {
+                modeManager.getCurrentMode().unset();
+            }
+            modeManager.setCurrentMode(nodeMode);
+            modeManager.getCurrentMode().set();
+            redraw();
+            break;
+          case '2': // lineMode Shortcut
+            if (modeManager.getCurrentMode() != null) {
+                modeManager.getCurrentMode().unset();
+            }
+            modeManager.setCurrentMode(lineMode);
+            modeManager.getCurrentMode().set();
+            redraw();
+            break;
+          case '3': // nodeMoveMode Shortcut
+            if (modeManager.getCurrentMode() != null) {
+                modeManager.getCurrentMode().unset();
+            }
+            modeManager.setCurrentMode(nodeMoveMode);
+            modeManager.getCurrentMode().set();
+            redraw();
+            break;
         case '[':
           lastmove = System.currentTimeMillis();
           tiles.zoomin();
Index:
C:/prog/workspace/osm-applet-topatch/src/org/openstreetmap/client/Tile.java
===================================================================
---
C:/prog/workspace/osm-applet-topatch/src/org/openstreetmap/client/Tile.java
(revision 2269)
+++
C:/prog/workspace/osm-applet-topatch/src/org/openstreetmap/client/Tile.java
(working copy)
@@ -297,6 +297,12 @@
     applet.redraw();
   } // drag

+  public void recenter(int x, int y) {
+      long dx = x - windowWidth / 2;
+      long dy = windowHeight / 2 - y;
+      drag((int) dx, (int) dy);
+  }
+
   public void startDrag() {
     skippedx = skippedy = 0;
   }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/dev/attachments/20070317/11458b3f/attachment.html>


More information about the dev mailing list