| 1 | package org.openstreetmap.josm.actions;
|
|---|
| 2 |
|
|---|
| 3 | import java.awt.BorderLayout;
|
|---|
| 4 | import java.awt.Color;
|
|---|
| 5 | import java.awt.Graphics;
|
|---|
| 6 | import java.awt.event.KeyEvent;
|
|---|
| 7 | import java.awt.event.MouseEvent;
|
|---|
| 8 | import java.awt.event.MouseListener;
|
|---|
| 9 | import java.awt.event.MouseMotionListener;
|
|---|
| 10 |
|
|---|
| 11 | import javax.swing.JLabel;
|
|---|
| 12 |
|
|---|
| 13 | import org.openstreetmap.josm.data.GeoPoint;
|
|---|
| 14 | import org.openstreetmap.josm.gui.MapFrame;
|
|---|
| 15 | import org.openstreetmap.josm.gui.MapView;
|
|---|
| 16 |
|
|---|
| 17 | /**
|
|---|
| 18 | * To debug zone information
|
|---|
| 19 | *
|
|---|
| 20 | * @author imi
|
|---|
| 21 | */
|
|---|
| 22 | public 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 | }
|
|---|