1 | package org.openstreetmap.josm.actions.mapmode;
|
---|
2 |
|
---|
3 | import java.awt.BorderLayout;
|
---|
4 | import java.awt.Color;
|
---|
5 | import java.awt.Graphics;
|
---|
6 | import java.awt.Point;
|
---|
7 | import java.awt.Rectangle;
|
---|
8 | import java.awt.event.KeyEvent;
|
---|
9 | import java.awt.event.MouseEvent;
|
---|
10 |
|
---|
11 | import javax.swing.JLabel;
|
---|
12 |
|
---|
13 | import org.openstreetmap.josm.data.osm.LineSegment;
|
---|
14 | import org.openstreetmap.josm.data.osm.Track;
|
---|
15 | import org.openstreetmap.josm.gui.MapFrame;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * To debug zone information
|
---|
19 | *
|
---|
20 | * @author imi
|
---|
21 | */
|
---|
22 | public class DebugAction extends MapMode {
|
---|
23 |
|
---|
24 | private JLabel label = new JLabel();
|
---|
25 |
|
---|
26 | public DebugAction(MapFrame mapFrame) {
|
---|
27 | super("Debug Zones", "debug", "Debug only. Just ignore.", KeyEvent.VK_D, mapFrame);
|
---|
28 | }
|
---|
29 |
|
---|
30 | @Override
|
---|
31 | public void registerListener() {
|
---|
32 | super.registerListener();
|
---|
33 | mv.addMouseMotionListener(this);
|
---|
34 | mv.addMouseListener(this);
|
---|
35 | mapFrame.add(label, BorderLayout.SOUTH);
|
---|
36 | }
|
---|
37 |
|
---|
38 | @Override
|
---|
39 | public void unregisterListener() {
|
---|
40 | super.unregisterListener();
|
---|
41 | mv.removeMouseMotionListener(this);
|
---|
42 | mv.removeMouseListener(this);
|
---|
43 | mapFrame.remove(label);
|
---|
44 | }
|
---|
45 |
|
---|
46 | @Override
|
---|
47 | public void mouseClicked(MouseEvent e) {
|
---|
48 | Graphics g = mapFrame.mapView.getGraphics();
|
---|
49 | g.setColor(Color.WHITE);
|
---|
50 | for (Track t :mapFrame.mapView.dataSet.tracks)
|
---|
51 | for (LineSegment ls : t.segments) {
|
---|
52 | Point A = mapFrame.mapView.getScreenPoint(ls.start.coor);
|
---|
53 | Point B = mapFrame.mapView.getScreenPoint(ls.end.coor);
|
---|
54 | Point C = e.getPoint();
|
---|
55 | Rectangle r = new Rectangle(A.x, A.y, B.x-A.x, B.y-A.y);
|
---|
56 | double dist = perpendicularDistSq(B.distanceSq(C), A.distanceSq(C), A.distanceSq(B));
|
---|
57 | g.drawString(""+dist, (int)r.getCenterX(), (int)r.getCenterY());
|
---|
58 | }
|
---|
59 | }
|
---|
60 |
|
---|
61 | private double perpendicularDistSq(double a, double b, double c) {
|
---|
62 | return a-(a-b+c)*(a-b+c)/4/c;
|
---|
63 | }
|
---|
64 | }
|
---|