1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.plugins.measurement;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.Cursor;
|
---|
7 | import java.awt.event.MouseEvent;
|
---|
8 |
|
---|
9 | import javax.swing.JOptionPane;
|
---|
10 |
|
---|
11 | import org.openstreetmap.josm.actions.mapmode.MapMode;
|
---|
12 | import org.openstreetmap.josm.data.osm.Node;
|
---|
13 | import org.openstreetmap.josm.gui.MainApplication;
|
---|
14 |
|
---|
15 | public class MeasurementMode extends MapMode {
|
---|
16 |
|
---|
17 | private static final long serialVersionUID = 3853830673475744263L;
|
---|
18 |
|
---|
19 | public MeasurementMode(String name, String desc) {
|
---|
20 | super(name, "measurement", desc, Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
|
---|
21 | putValue("toolbar", "measurement");
|
---|
22 | }
|
---|
23 |
|
---|
24 | @Override
|
---|
25 | public void enterMode() {
|
---|
26 | super.enterMode();
|
---|
27 | MainApplication.getMap().mapView.addMouseListener(this);
|
---|
28 | }
|
---|
29 |
|
---|
30 | @Override
|
---|
31 | public void exitMode() {
|
---|
32 | super.exitMode();
|
---|
33 | MainApplication.getMap().mapView.removeMouseListener(this);
|
---|
34 | }
|
---|
35 |
|
---|
36 | /**
|
---|
37 | * If user clicked with the left button, add a node at the current mouse
|
---|
38 | * position.
|
---|
39 | *
|
---|
40 | * If in nodesegment mode, add the node to the line segment by splitting the
|
---|
41 | * segment. The new created segment will be inserted in every way the segment
|
---|
42 | * was part of.
|
---|
43 | */
|
---|
44 | @Override
|
---|
45 | public void mouseClicked(MouseEvent e) {
|
---|
46 | if (e.getButton() == MouseEvent.BUTTON3) {
|
---|
47 | MeasurementPlugin.getCurrentLayer().removeLastPoint();
|
---|
48 | } else if (e.getButton() == MouseEvent.BUTTON1) {
|
---|
49 | Node coor = new Node(MainApplication.getMap().mapView.getEastNorth(e.getX(), e.getY()));
|
---|
50 | if (coor.isOutSideWorld()) {
|
---|
51 | JOptionPane.showMessageDialog(MainApplication.getMainFrame(),tr("Can not draw outside of the world."));
|
---|
52 | return;
|
---|
53 | }
|
---|
54 | MeasurementPlugin.getCurrentLayer().mouseClicked(e);
|
---|
55 | }
|
---|
56 | }
|
---|
57 | }
|
---|