source: josm/src/org/openstreetmap/josm/actions/DebugAction.java@ 1

Last change on this file since 1 was 1, checked in by imi, 21 years ago

wiki 19:37, 27. Sep 2005

File size: 2.1 KB
Line 
1package org.openstreetmap.josm.actions;
2
3import java.awt.BorderLayout;
4import java.awt.Color;
5import java.awt.Graphics;
6import java.awt.event.KeyEvent;
7import java.awt.event.MouseEvent;
8import java.awt.event.MouseListener;
9import java.awt.event.MouseMotionListener;
10
11import javax.swing.JLabel;
12
13import org.openstreetmap.josm.data.GeoPoint;
14import org.openstreetmap.josm.gui.MapFrame;
15import org.openstreetmap.josm.gui.MapView;
16
17/**
18 * To debug zone information
19 *
20 * @author imi
21 */
22public class DebugAction extends MapMode implements MouseMotionListener, MouseListener {
23
24 private JLabel label = new JLabel();
25
26 public DebugAction(MapFrame mapFrame) {
27 super("Debug Zones", "images/debug.png", KeyEvent.VK_D, mapFrame);
28 }
29
30 public void registerListener(MapView mapView) {
31 mapView.addMouseMotionListener(this);
32 mapView.addMouseListener(this);
33 mapFrame.add(label, BorderLayout.SOUTH);
34 }
35
36 public void unregisterListener(MapView mapView) {
37 mapView.removeMouseMotionListener(this);
38 mapView.removeMouseListener(this);
39 mapFrame.remove(label);
40 }
41
42 public void mouseDragged(MouseEvent e) {
43 }
44
45 public void mouseMoved(MouseEvent e) {
46 double lon = ((double)e.getX()/mapFrame.mapView.getWidth()*360) - 180;
47 double lat = 90 - (double)e.getY()/mapFrame.mapView.getHeight() * 180;
48 GeoPoint p = new GeoPoint(lat, lon);
49 mapFrame.mapView.getProjection().latlon2xy(p);
50 label.setText("x="+e.getX()+" y="+e.getY()+" lat="+p.lat+" lon="+p.lon+" N="+p.y+" E="+p.x);
51
52 GeoPoint mousePoint = mapFrame.mapView.getPoint(e.getX(), e.getY(), false);
53 GeoPoint center = mapFrame.mapView.getCenter();
54 double scale = mapFrame.mapView.getScale();
55 int xscr = (int)Math.round((mousePoint.x-center.x) / scale + mapFrame.mapView.getWidth()/2);
56 int yscr = (int)Math.round((center.y-mousePoint.y) / scale + mapFrame.mapView.getHeight()/2);
57 Graphics g = mapFrame.mapView.getGraphics();
58 g.setColor(Color.CYAN);
59 g.drawArc(xscr, yscr, 4,4,0,360);
60 }
61
62 public void mouseClicked(MouseEvent e) {
63 }
64
65 public void mousePressed(MouseEvent e) {
66 }
67
68 public void mouseReleased(MouseEvent e) {
69 }
70
71 public void mouseEntered(MouseEvent e) {
72 }
73
74 public void mouseExited(MouseEvent e) {
75 }
76
77}
Note: See TracBrowser for help on using the repository browser.